# canalplus/rx-player architecture

> Architecture diagram of the GitHub repository canalplus/rx-player, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/canalplus/rx-player
- Repository: https://github.com/canalplus/rx-player

## Overview

##### Main Components Overview

The system should be divided into these major components:

**Core Components:**
- Media Playback Engine
- Transport Layer
- Manifest Parsers
- Segment Processing
- DRM/EME Handler
- Adaptive Streaming Logic
- Text Track Processing

**Supporting Components:**
- Feature Management
- Configuration System
- Event System
- Worker Infrastructure

##### Component Relationships

**a. Input Flow:**
- Content URL/Config -> Feature Detection -> Manifest Parser -> Transport Layer ->
- Segment Processing -> Media Source Extensions -> Video Element

**b. Control Flow:**
- Player API -> Core Controller -> Feature-specific Controllers ->
- Individual Components

**c. Adaptive Streaming Flow:**
- Network Analyzer -> Bandwidth Estimator -> Quality Selection ->
- Segment Scheduler

##### Specific Implementation Details

Technical elements:

**a. Supported Formats:**
- DASH
- Microsoft Smooth Streaming
- DirectFile (MP4/WebM)
- Text Formats (TTML, WebVTT, SAMI, SRT)

**b. Browser APIs Integration:**
- Media Source Extensions
- Encrypted Media Extensions
- WebAssembly (for MPD parsing)

**c. Performance Optimizations:**
- Worker-based Processing
- Memory Management
- Segment Caching

- Blue: Core Media Processing
- Green: Transport/Network
- Yellow: DRM/Security
- Purple: Text/Subtitle Processing
- Gray: Supporting Infrastructure

- Rectangles: Major Components
- Hexagons: Entry Points/APIs

##### Key Interactions to Highlight

**a. Content Loading:**
- Manifest Parsing
- Initial Segment Loading
- DRM Initialization
- Track Selection

**b. Playback Control:**
- Adaptive Bitrate Switching
- Buffer Management
- Error Handling
- Event Dispatching

**c. Feature Integration:**
- Plugin System
- Custom Transport
- DRM Configuration
- Text Track Rendering

##### Implementation Notes

- Modular architecture allowing feature toggling
- Multiple transport protocol support
- Extensive configuration options
- Error handling and recovery paths
- Performance optimization points
- Memory management strategies

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Input Layer"
        Input["Content URL/Config"]
        FD["Feature Detection"]:::feature
    end

    subgraph "Core Processing"
        MPE["Media Playback Engine"]:::core
        TP["Transport Layer"]:::transport
        MP["Manifest Parsers"]:::core
        SP["Segment Processing"]:::core
        DRM["DRM/EME Handler"]:::security
        ASL["Adaptive Streaming Logic"]:::core
        TTP["Text Track Processing"]:::text
    end

    subgraph "Browser Integration"
        MSE["Media Source Extensions"]:::browser
        EME["Encrypted Media Extensions"]:::browser
        WASM["WebAssembly"]:::browser
        VE["Video Element"]:::browser
    end

    subgraph "Supporting Systems"
        FM["Feature Management"]:::support
        CS["Configuration System"]:::support
        ES["Event System"]:::support
        WI["Worker Infrastructure"]:::support
        PO["Playback Observer"]:::support
        TM["Track Management"]:::support
    end

    subgraph "Adaptive Streaming Components"
        NA["Network Analyzer"]:::network
        BE["Bandwidth Estimator"]:::network
        QS["Quality Selection"]:::network
        SS["Segment Scheduler"]:::network
    end

    %% Main Flow
    Input --> FD
    FD --> MP
    MP --> TP
    TP --> SP
    SP --> MSE
    MSE --> VE

    %% DRM Flow
    SP --> DRM
    DRM --> EME
    EME --> VE

    %% Adaptive Streaming Flow
    NA --> BE
    BE --> QS
    QS --> SS
    SS --> TP

    %% Supporting Systems Integration
    FM --> MPE
    CS --> MPE
    ES --> MPE
    WI --> SP
    PO --> VE
    TM --> MPE

    %% Text Processing
    TTP --> VE

    %% Click Events
    click MPE "https://github.com/canalplus/rx-player/tree/dev/src/core/main/"
    click TP "https://github.com/canalplus/rx-player/tree/dev/src/transports/"
    click MP "https://github.com/canalplus/rx-player/tree/dev/src/parsers/manifest/"
    click SP "https://github.com/canalplus/rx-player/tree/dev/src/core/segment_sinks/"
    click DRM "https://github.com/canalplus/rx-player/tree/dev/src/main_thread/decrypt/"
    click ASL "https://github.com/canalplus/rx-player/tree/dev/src/core/adaptive/"
    click TTP "https://github.com/canalplus/rx-player/tree/dev/src/main_thread/text_displayer/"
    click FM "https://github.com/canalplus/rx-player/tree/dev/src/features/"
    click CS "https://github.com/canalplus/rx-player/blob/dev/src/config.ts"
    click ES "https://github.com/canalplus/rx-player/blob/dev/src/utils/event_emitter.ts"
    click WI "https://github.com/canalplus/rx-player/tree/dev/src/core/main/worker/"
    click MSE "https://github.com/canalplus/rx-player/tree/dev/src/mse/"
    click PO "https://github.com/canalplus/rx-player/tree/dev/src/playback_observer/"
    click TM "https://github.com/canalplus/rx-player/tree/dev/src/main_thread/tracks_store/"

    %% Styling
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef transport fill:#4CAF50,stroke:#2E7D32,color:white
    classDef security fill:#FFC107,stroke:#FFA000,color:black
    classDef text fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef support fill:#90A4AE,stroke:#546E7A,color:white
    classDef browser fill:#FF5722,stroke:#E64A19,color:white
    classDef network fill:#00BCD4,stroke:#0097A7,color:white
    classDef feature fill:#795548,stroke:#5D4037,color:white

    %% Legend
    subgraph Legend
        L1["Core Processing"]:::core
        L2["Transport/Network"]:::transport
        L3["Security/DRM"]:::security
        L4["Text Processing"]:::text
        L5["Support Systems"]:::support
        L6["Browser APIs"]:::browser
        L7["Network Analysis"]:::network
        L8["Feature Management"]:::feature
    end
```
