# mpromonet/v4l2rtspserver architecture

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

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

## Overview

v4l2rtspserver captures video from Video4Linux devices and optionally audio from ALSA, then exposes streams through RTSP/RTP or, when enabled, HTTP-based HLS and MPEG-DASH. The main workflow parses options, creates capture replicators, and registers unicast, multicast, or transport-stream sessions. The graph also preserves codec-specific capture, RTP session handling, and buffering. Some subsystem paths and links are based on README or SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`src/V4l2RTSPServer.cpp`](https://github.com/mpromonet/v4l2rtspserver/blob/master/src/V4l2RTSPServer.cpp) (Server orchestration), [`inc/DeviceSourceFactory.h`](https://github.com/mpromonet/v4l2rtspserver/blob/master/inc/DeviceSourceFactory.h) (Source factory), [`main.cpp`](https://github.com/mpromonet/v4l2rtspserver/blob/master/main.cpp) (Option parsing), [`src/TSServerMediaSubsession.cpp`](https://github.com/mpromonet/v4l2rtspserver/blob/master/src/TSServerMediaSubsession.cpp) (Transport stream session)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Application entry"]
  node_main["Option parsing<br/>[main.cpp]"]
end

subgraph group_capture["Capture and framing"]
  node_v4l2device["V4L2 capture"]
  node_sourcefactory["Source factory"]
  node_h26xsource["H.264/H.265 source"]
  node_h264source["H.264 source variant"]
  node_h265source["H.265 source variant"]
  node_mjpegsource["MJPEG framing"]
  node_alsacapture["ALSA capture<br/>[ALSACapture.cpp]"]
end

subgraph group_streaming["RTSP and RTP"]
  node_v4l2server["Server orchestration<br/>[V4l2RTSPServer.cpp]"]
  node_base_subsession["RTP format handling"]
  node_unicast["Unicast session"]
  node_multicast["Multicast session"]
  node_ts_session["Transport stream session"]
end

subgraph group_http["HTTP streaming"]
  node_buffer_sink["Segment buffer"]
  node_httpserver["HTTP playlists and segments<br/>[HTTPServer.cpp]"]
end

node_operator(("Operator"))
node_video_device(("Video device"))
node_audio_device(("ALSA device"))
node_rtsp_clients(("RTSP clients"))
node_http_clients(("HTTP playback clients"))

node_operator -->|"sets options"| node_main
node_main -->|"configures"| node_v4l2server
node_main -->|"requests sources"| node_sourcefactory
node_v4l2server -->|"creates video streams"| node_sourcefactory
node_sourcefactory -->|"creates source"| node_v4l2device
node_sourcefactory -->|"selects H.264"| node_h264source
node_sourcefactory -->|"selects H.265"| node_h265source
node_h264source -->|"uses framing"| node_h26xsource
node_h265source -->|"uses framing"| node_h26xsource
node_video_device -->|"provides frames"| node_v4l2device
node_audio_device -->|"provides audio"| node_alsacapture
node_v4l2server -->|"creates audio streams"| node_alsacapture
node_v4l2server -->|"registers sessions"| node_unicast
node_v4l2server -->|"registers sessions"| node_multicast
node_v4l2server -->|"registers HLS sessions"| node_ts_session
node_unicast -->|"uses format handling"| node_base_subsession
node_multicast -->|"uses format handling"| node_base_subsession
node_ts_session -->|"extends session"| node_unicast
node_ts_session -->|"uses segment buffer"| node_buffer_sink
node_v4l2server -->|"configures server"| node_httpserver
node_rtsp_clients -->|"requests RTP streams"| node_v4l2server
node_http_clients -->|"requests HLS/DASH"| node_httpserver

click node_main "https://github.com/mpromonet/v4l2rtspserver/blob/master/main.cpp"
click node_v4l2server "https://github.com/mpromonet/v4l2rtspserver/blob/master/src/V4l2RTSPServer.cpp"
click node_v4l2device "https://github.com/mpromonet/v4l2rtspserver/blob/master/src/V4L2DeviceSource.cpp"
click node_sourcefactory "https://github.com/mpromonet/v4l2rtspserver/blob/master/inc/DeviceSourceFactory.h"
click node_h26xsource "https://github.com/mpromonet/v4l2rtspserver/blob/master/src/H26x_V4l2DeviceSource.cpp"
click node_h264source "https://github.com/mpromonet/v4l2rtspserver/blob/master/src/H264_V4l2DeviceSource.cpp"
click node_h265source "https://github.com/mpromonet/v4l2rtspserver/blob/master/src/H265_V4l2DeviceSource.cpp"
click node_mjpegsource "https://github.com/mpromonet/v4l2rtspserver/blob/master/src/MJPEGVideoSource.cpp"
click node_alsacapture "https://github.com/mpromonet/v4l2rtspserver/blob/master/src/ALSACapture.cpp"
click node_base_subsession "https://github.com/mpromonet/v4l2rtspserver/blob/master/src/ServerMediaSubsession.cpp"
click node_unicast "https://github.com/mpromonet/v4l2rtspserver/blob/master/src/UnicastServerMediaSubsession.cpp"
click node_multicast "https://github.com/mpromonet/v4l2rtspserver/blob/master/src/MulticastServerMediaSubsession.cpp"
click node_ts_session "https://github.com/mpromonet/v4l2rtspserver/blob/master/src/TSServerMediaSubsession.cpp"
click node_buffer_sink "https://github.com/mpromonet/v4l2rtspserver/blob/master/src/MemoryBufferSink.cpp"
click node_httpserver "https://github.com/mpromonet/v4l2rtspserver/blob/master/src/HTTPServer.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_rtsp_clients,node_http_clients toneBlue
class node_v4l2device,node_sourcefactory,node_h26xsource,node_h264source,node_h265source,node_mjpegsource,node_alsacapture toneAmber
class node_v4l2server,node_base_subsession,node_unicast,node_multicast,node_ts_session toneMint
class node_buffer_sink,node_httpserver toneRose
class node_operator,node_video_device,node_audio_device toneIndigo
```

## Components

### Application entry

- [Option parsing](https://github.com/mpromonet/v4l2rtspserver/blob/master/main.cpp): `main.cpp`

### Capture and framing

- [V4L2 capture](https://github.com/mpromonet/v4l2rtspserver/blob/master/src/V4L2DeviceSource.cpp): `src/V4L2DeviceSource.cpp`
- [Source factory](https://github.com/mpromonet/v4l2rtspserver/blob/master/inc/DeviceSourceFactory.h): `inc/DeviceSourceFactory.h`
- [H.264/H.265 source](https://github.com/mpromonet/v4l2rtspserver/blob/master/src/H26x_V4l2DeviceSource.cpp): `src/H26x_V4l2DeviceSource.cpp`
- [H.264 source variant](https://github.com/mpromonet/v4l2rtspserver/blob/master/src/H264_V4l2DeviceSource.cpp): `src/H264_V4l2DeviceSource.cpp`
- [H.265 source variant](https://github.com/mpromonet/v4l2rtspserver/blob/master/src/H265_V4l2DeviceSource.cpp): `src/H265_V4l2DeviceSource.cpp`
- [MJPEG framing](https://github.com/mpromonet/v4l2rtspserver/blob/master/src/MJPEGVideoSource.cpp): `src/MJPEGVideoSource.cpp`
- [ALSA capture](https://github.com/mpromonet/v4l2rtspserver/blob/master/src/ALSACapture.cpp): `src/ALSACapture.cpp`

### RTSP and RTP

- [Server orchestration](https://github.com/mpromonet/v4l2rtspserver/blob/master/src/V4l2RTSPServer.cpp): `src/V4l2RTSPServer.cpp`
- [RTP format handling](https://github.com/mpromonet/v4l2rtspserver/blob/master/src/ServerMediaSubsession.cpp): `src/ServerMediaSubsession.cpp`
- [Unicast session](https://github.com/mpromonet/v4l2rtspserver/blob/master/src/UnicastServerMediaSubsession.cpp): `src/UnicastServerMediaSubsession.cpp`
- [Multicast session](https://github.com/mpromonet/v4l2rtspserver/blob/master/src/MulticastServerMediaSubsession.cpp): `src/MulticastServerMediaSubsession.cpp`
- [Transport stream session](https://github.com/mpromonet/v4l2rtspserver/blob/master/src/TSServerMediaSubsession.cpp): `src/TSServerMediaSubsession.cpp`

### HTTP streaming

- [Segment buffer](https://github.com/mpromonet/v4l2rtspserver/blob/master/src/MemoryBufferSink.cpp): `src/MemoryBufferSink.cpp`
- [HTTP playlists and segments](https://github.com/mpromonet/v4l2rtspserver/blob/master/src/HTTPServer.cpp): `src/HTTPServer.cpp`

### Other components

- **Operator**
- **Video device**
- **ALSA device**
- **RTSP clients**
- **HTTP playback clients**

## Connections

- Operator → Option parsing: sets options (evidence: `README.md`)
- Option parsing → Server orchestration: configures (evidence: `main.cpp`)
- Option parsing → Source factory: requests sources (evidence: `main.cpp`)
- Server orchestration → Source factory: creates video streams (evidence: `src/V4l2RTSPServer.cpp`)
- Source factory → V4L2 capture: creates source (evidence: `inc/DeviceSourceFactory.h`)
- Source factory → H.264 source variant: selects H.264 (evidence: `inc/DeviceSourceFactory.h`)
- Source factory → H.265 source variant: selects H.265 (evidence: `inc/DeviceSourceFactory.h`)
- H.264 source variant → H.264/H.265 source: uses framing
- H.265 source variant → H.264/H.265 source: uses framing
- Video device → V4L2 capture: provides frames (evidence: `README.md`)
- ALSA device → ALSA capture: provides audio (evidence: `README.md`)
- Server orchestration → ALSA capture: creates audio streams (evidence: `src/V4l2RTSPServer.cpp`)
- Server orchestration → Unicast session: registers sessions
- Server orchestration → Multicast session: registers sessions
- Server orchestration → Transport stream session: registers HLS sessions
- Unicast session → RTP format handling: uses format handling
- Multicast session → RTP format handling: uses format handling
- Transport stream session → Unicast session: extends session
- Transport stream session → Segment buffer: uses segment buffer
- Server orchestration → HTTP playlists and segments: configures server
- RTSP clients → Server orchestration: requests RTP streams (evidence: `README.md`)
- HTTP playback clients → HTTP playlists and segments: requests HLS/DASH (evidence: `README.md`)
