Skip to content

WebRTC & WHEP Pipeline Architecture ​

The WebRTC Pipeline (internal/webrtc/) delivers real-time, ultra-low latency (< 500ms) video streaming directly to web browsers and mobile applications without requiring proprietary plugins or transcoding.


1. WHEP (WebRTC HTTP Egress Protocol) Signaling ​

RUSEON Core implements the IETF WHEP standard at POST /stream/webrtc/whep/:id:

  • Simplicity: The browser initiates playback with a standard POST request carrying its SDP offer (Content-Type: application/sdp).
  • RESTful Response: Returns HTTP 201 Created with the SDP Answer (Content-Type: application/sdp).
  • UDP Port Multiplexing: All WebRTC peers are multiplexed over a single UDP port (8555/UDP by default) via webrtc.listen_port, eliminating wide firewall port ranges.

2. Adaptive Linux Kernel sendmmsg UDP Batching ​

To scale beyond hundreds of concurrent WebRTC viewers on a single server, RUSEON Core implements an Adaptive UDP Batching Layer (internal/webrtc/batch_linux.go):

Key Batching Mechanics: ​

  1. 64-Shard Peer Table (peerShard): Destination peer connections (netip.AddrPort) are partitioned across 64 lock-stratified hash shards, eliminating mutex contention across thousands of active clients.
  2. Zero-Latency Handshakes: Non-RTP control packets (STUN discovery, DTLS handshakes) bypass batching and are dispatched immediately.
  3. Marker Bit ($M=1$) Frame Flush: RTP packets are buffered in memory and flushed via a single sendmmsg kernel syscall immediately when the RFC 6184 Marker bit ($M=1$, indicating the end of a video frame) is encountered, or when the 32-packet batch buffer is filled.
  4. Syscall Reduction: Reduces context switches and kernel syscall overhead by 85–90% during video egress.
  5. Cross-Platform Fallback: On non-Linux systems (Windows/macOS), the batcher cleanly falls back (batch_generic.go) to standard UDP writes.

3. WebRTC DataChannels for AI Metadata ​

Each WebRTC connection establishes an SCTP DataChannel (label: "metadata"):

  • Real-time bounding boxes, classification labels, and confidence scores from downstream AI engines are broadcast as lightweight JSON payloads.
  • Delivers overlay metadata with sub-50ms latency, perfectly synchronized with incoming video frames on the browser's HTML5 Canvas layer.

4. NAT Traversal & Configuration ​

Configured in config.yaml under server.webrtc:

yaml
server:
  webrtc:
    listen_port: 8555
    nat_1_to_1_ips:
      - "203.0.113.50"
    ice_servers:
      - "stun:stun.l.google.com:19302"
    ice_transport_policy: "all" # 'all' or 'relay'

Released under the MIT License.