# mpromonet/webrtc-streamer architecture

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

- Interactive diagram: https://gitdiagram.com/mpromonet/webrtc-streamer
- Repository: https://github.com/mpromonet/webrtc-streamer

## Overview

##### Project Type and Core Components
This is a WebRTC media streaming application that acts as a bridge between various media sources and WebRTC clients. The main components should be organized as follows:

##### Key Architectural Elements

a. Media Source Layer:
- Video Sources (V4L2, Screen Capture, Window Capture)
- Audio Sources (ALSA, File Audio)
- Network Sources (RTSP, RTMP)
- File Sources (MKV)

b. Core Processing Layer:
- Management
- Encoding/Decoding Pipeline
- WebRTC Connection Management
- Signaling System

c. External Interface Layer:
- HTTP Server (CivetWeb)
- WebRTC Endpoints
- STUN/TURN Server Integration
- Integration Points (Janus, Jitsi)

**[Client Layer]**
**Web Browsers <-> WHEP Clients <-> Custom Web Components**
- ↓
**[HTTP/WebSocket Layer]**
**CivetWeb Server (Port 8000) <-> REST API**
- ↓
**[Core Processing]**
**PeerConnectionManager**
- ↓               ↓
**Encoders/Decoders   Capturers**
- ↓               ↓
**[Media Sources]     [Network Components]**
- V4L2              - STUN/TURN Servers
- Screen/Window     - WebRTC Data Channels
- File Sources      - RTP/RTCP
- RTSP/RTMP         - Network I/O

**[External Integrations]**
- Janus Gateway
- Jitsi
- Prometheus/Grafana Monitoring

##### Important Relationships to Highlight
- Bidirectional data flow between clients and server
- Media pipeline flow from sources through encoders to clients
- Control plane vs. Data plane separation
- Integration points with external systems

##### Implementation Details
- Port configurations (8000 for HTTP, 3478 for STUN)
- Supported protocols (WHEP, WebRTC, RTSP, RTMP)
- Media format support (H.264, VP8, etc.)
- Authentication mechanisms

##### Notes
- Version information
- Configuration parameters
- Document supported platforms (Linux, Windows, MacOS)
- Scaling capabilities
- Monitoring points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        Browser["Web Browsers"]
        WHEP["WHEP Clients"]
        WebComp["Custom Web Components"]
        Browser <--> WHEP
        WHEP <--> WebComp
    end

    subgraph HTTP["HTTP/WebSocket Layer"]
        Server["CivetWeb Server (8000)"]:::server
        API["REST API"]:::api
        Server <--> API
    end
    click Server "https://github.com/mpromonet/webrtc-streamer/blob/master/inc/HttpServerRequestHandler.h"

    subgraph Core["Core Processing Layer"]
        PCM["PeerConnection Manager"]:::core
        CapMgmt["Capture Management"]:::core
        VidProc["Video Processing Pipeline"]:::core
        EncoderFactory["Encoder Factory"]:::core
        DecoderFactory["Decoder Factory"]:::core

        PCM --> CapMgmt
        PCM --> VidProc
        PCM --> EncoderFactory
        PCM --> DecoderFactory
    end
    click PCM "https://github.com/mpromonet/webrtc-streamer/blob/master/inc/PeerConnectionManager.h"
    click CapMgmt "https://github.com/mpromonet/webrtc-streamer/blob/master/inc/CapturerFactory.h"
    click VidProc "https://github.com/mpromonet/webrtc-streamer/blob/master/inc/VideoScaler.h"
    click EncoderFactory "https://github.com/mpromonet/webrtc-streamer/blob/master/inc/VideoEncoderFactory.h"
    click DecoderFactory "https://github.com/mpromonet/webrtc-streamer/blob/master/inc/VideoDecoderFactory.h"

    subgraph Media["Media Sources Layer"]
        direction TB
        V4L2["V4L2 Source"]:::source
        Screen["Screen Capture"]:::source
        Window["Window Capture"]:::source
        RTSP["RTSP Source"]:::source
        RTMP["RTMP Source"]:::source
        FileAudio["File Audio"]:::source
        FileVideo["File Video"]:::source
        LiveAudio["Live Audio Source"]:::source
        LiveVideo["Live Video Source"]:::source
    end
    click V4L2 "https://github.com/mpromonet/webrtc-streamer/blob/master/inc/V4l2Capturer.h"
    click Screen "https://github.com/mpromonet/webrtc-streamer/blob/master/inc/screencapturer.h"
    click Window "https://github.com/mpromonet/webrtc-streamer/blob/master/inc/windowcapturer.h"
    click RTSP "https://github.com/mpromonet/webrtc-streamer/blob/master/inc/rtspvideocapturer.h"
    click RTMP "https://github.com/mpromonet/webrtc-streamer/blob/master/inc/rtmpvideosource.h"
    click FileAudio "https://github.com/mpromonet/webrtc-streamer/blob/master/inc/fileaudiocapturer.h"
    click FileVideo "https://github.com/mpromonet/webrtc-streamer/blob/master/inc/filevideocapturer.h"
    click LiveAudio "https://github.com/mpromonet/webrtc-streamer/blob/master/inc/liveaudiosource.h"
    click LiveVideo "https://github.com/mpromonet/webrtc-streamer/blob/master/inc/livevideosource.h"

    subgraph Network["Network Components"]
        STUN["STUN/TURN (3478)"]:::network
        DataChan["WebRTC Data Channels"]:::network
        RTP["RTP/RTCP"]:::network
    end

    subgraph External["External Integrations"]
        Janus["Janus Gateway"]:::external
        Jitsi["Jitsi"]:::external
        Monitoring["Prometheus/Grafana"]:::external
    end
    click Monitoring "https://github.com/mpromonet/webrtc-streamer/blob/master/prometheus/prometheus.yml"

    %% Connections
    Client --> HTTP
    HTTP --> Core
    Core --> Media
    Core --> Network
    Network --> External

    %% Styles
    classDef source fill:#90EE90
    classDef core fill:#FF6961
    classDef network fill:#FFB347
    classDef external fill:#D3D3D3
    classDef server fill:#87CEEB
    classDef api fill:#DDA0DD

    %% Legend
    subgraph Legend
        L1["Client Components"]:::server
        L2["Core Processing"]:::core
        L3["Media Sources"]:::source
        L4["Network Components"]:::network
        L5["External Systems"]:::external
        L6["API Components"]:::api
    end
```
