# avatarchik/360dashplayer architecture

> Architecture diagram of the GitHub repository avatarchik/360dashplayer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/avatarchik/360dashplayer
- Repository: https://github.com/avatarchik/360dashplayer

## Overview

Based on both the file tree and the README, the project is a demonstration tool for merging split HEVC tiles. It is written in pure JavaScript (with some TypeScript for the demo player) and works both in the browser and under NodeJS. The purpose is to allow tiled and split HEVC content—whose tiles might be fetched in different qualities based on user interaction—to be merged into a single tiled (but unsplit) segment that can be natively decoded by browsers like Edge.

##### Main Components

- User Interface & Presentation Layer:
- HTML files (index.html and demo.html) serve as entry points.
- CSS folder for styling.
- These files are responsible for presenting the video player, quality controls (grid view or button modes), and handling URL parameters (like content-index, grid-index, mode, etc.) that initialize the demo.

- Client-Side Logic & Interaction:
- The js folder contains the bulk of the JavaScript functionality.
- The demo player is central—implemented partly in TypeScript (js/demo_player.ts) and then built to demo_player.js. It handles parameter parsing, controlling the video element, monitoring playback, and managing quality changes.

- HEVC Merging Engine:
- Located inside the libs folder (specifically, hevc_merger.js). This module contains the core functions:
- The other merges the video segments for a given set of tiles.
- These operations are essential to convert the split tiled content into a format that the native decoder can handle.

- External Dependencies & Libraries:
- When running under NodeJS, the project uses packages (as seen in js/package.json and the instructions on installing NodeJS and TypeScript).

- Users load the demo page via index.html; URL hash parameters are parsed to determine content and grid selection.

- UI to the Client-Side Logic:
- JS components are responsible for reading the parameters, updating the video player, and triggering quality updates.

- Merging process:
- That this component processes multiple ArrayBuffers corresponding to the split tiles/segments (with the base track and additional tile tracks).

- External Libraries Integration:
→ ISOBoxer assists in parsing/adjusting MP4/DASH init segments.
→ Chart.js is used for on-screen demonstrations (like quality metrics or grid overlays) but is optional/auxiliary.
- A note about NodeJS usage that may influence how buffers are handled (conversion between Buffer and ArrayBuffer).

##### Architectural Patterns & Technology Stack

- Separation of Concerns:

- Modular Design:
- Each module is independent (for instance, media parameter handling in index.html, UI control logic in the demo player, and tile merging in libs/hevc_merger.js).

- Build Process:
- Build step that compiles the TypeScript file (demo_player.ts) into JavaScript (demo_player.js) using NodeJS/NPM scripts. This is essential for both development and production deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface & Presentation Layer
    subgraph "User Interface & Presentation Layer"
        A1["index.html"]:::ui
        A2["demo.html"]:::ui
        A3["css/style.css"]:::ui
    end

    %% Client-Side Logic & Interaction
    subgraph "Client-Side Logic & Interaction"
        B1["Demo Player Module (ts/js)"]:::logic
        B2["arrow-key-rotation.js"]:::logic
        B3["hide-once-playing.js"]:::logic
        B4["play-on-vrdisplayactivate-or-enter-vr.js"]:::logic
        B5["play-on-window-click.js"]:::logic
    end

    %% HEVC Merging Engine
    subgraph "HEVC Merging Engine"
        C1["HEVC Merger (merge/updateDashInit)"]:::engine
    end

    %% External Dependencies & Build Environment
    subgraph "External Dependencies & Build Environment"
        D1["External Libs: ISOBoxer&Chart.js"]:::external
        D2["NodeJS: Package Configuration"]:::external
        D3["package.json"]:::external
        D4["tsconfig.json"]:::external
    end

    %% Connections between UI and Client-Side Logic
    A1 -->|"UserInputParsing"| B1
    A2 -->|"UserInputParsing"| B1
    A3 -.->|"AppliedStyling"| B1

    %% Connections within Client-Side Helpers
    B1 -->|"initHelper"| B2
    B1 -->|"initHelper"| B3
    B1 -->|"initHelper"| B4
    B1 -->|"initHelper"| B5

    %% Connection from Client-Side Logic to HEVC Merging Engine
    B1 -->|"callsMerge"| C1

    %% External Dependencies impacting Client-Side and HEVC engine
    D2 -->|"buildProcess"| B1
    D2 -->|"BufferConversion"| C1
    B1 -.->|"uses"| D1

    %% Internal External Dependencies relationship
    D3 --> D2
    D4 --> D2

    %% Click Events
    click A1 "https://github.com/avatarchik/360dashplayer/blob/master/index.html"
    click A2 "https://github.com/avatarchik/360dashplayer/blob/master/demo.html"
    click A3 "https://github.com/avatarchik/360dashplayer/blob/master/css/style.css"
    click B1 "https://github.com/avatarchik/360dashplayer/blob/master/js/demo_player.ts"
    click B2 "https://github.com/avatarchik/360dashplayer/blob/master/js/arrow-key-rotation.js"
    click B3 "https://github.com/avatarchik/360dashplayer/blob/master/js/hide-once-playing.js"
    click B4 "https://github.com/avatarchik/360dashplayer/blob/master/js/play-on-vrdisplayactivate-or-enter-vr.js"
    click B5 "https://github.com/avatarchik/360dashplayer/blob/master/js/play-on-window-click.js"
    click C1 "https://github.com/avatarchik/360dashplayer/blob/master/libs/hevc_merger.js"
    click D3 "https://github.com/avatarchik/360dashplayer/blob/master/js/package.json"
    click D4 "https://github.com/avatarchik/360dashplayer/blob/master/js/tsconfig.json"

    %% Styling Classes
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef logic fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef engine fill:#FFA07A,stroke:#FF4500,stroke-width:2px;
    classDef external fill:#DDA0DD,stroke:#800080,stroke-width:2px;
```
