mecha10-video
WebRTC-based low-latency video streaming for robotics applications.
Features
- WebRTC Streaming: H.264 video encoding with OpenH264
- Multi-client Support: Broadcast frames to multiple WebRTC connections
- Low Latency: 30-50ms glass-to-glass latency
- Zero-copy Frame Sharing: Efficient frame distribution using Arc
- Optional Diagnostics: Enable with
diagnosticsfeature flag
Architecture
┌─────────────┐
│ Source │ (Godot, Camera, etc.)
│ (Frames) │
└──────┬──────┘
│ mpsc::channel
▼
┌─────────────────────┐
│ WebRTCServer │
│ (Frame Broadcast) │
└──────┬──────────────┘
│ broadcast::channel
├─────────┬─────────┐
▼ ▼ ▼
┌────────┐ ┌────────┐ ┌────────┐
│ Conn 1 │ │ Conn 2 │ │ Conn 3 │
│ (H.264)│ │ (H.264)│ │ (H.264)│
└────┬───┘ └────┬───┘ └────┬───┘
│ │ │
▼ ▼ ▼
Browser Browser Browser
Usage
Basic Example
use ;
use start_signaling_server;
use mpsc;
use Arc;
async
With Diagnostics
Enable the diagnostics feature in your Cargo.toml:
[]
= { = "../video", = ["diagnostics"] }
Then create the server with diagnostics:
use StreamingCollector;
use Arc;
let diagnostics = new;
let webrtc_server = new.await?;
Dual-Path Publishing (CameraPublisher)
For nodes that need to publish frames to multiple destinations (e.g., WebRTC for dashboards + Redis for telemetry), use CameraPublisher:
use ;
use mpsc;
use Arc;
async
Key Features:
- Zero-copy sharing: Wraps frame data in
Arconce, shares between all destinations - Best-effort secondary: Redis/telemetry publishing is non-blocking (drops on full channel)
- Automatic diagnostics: Tracks frame sent/dropped metrics (when diagnostics feature enabled)
- Simple API: Just call
publish()with raw frame data
Performance
- Encoding: ~8-15ms per frame (160×120 @ 30 FPS)
- Latency: 30-50ms glass-to-glass
- Bitrate: 400 Kbps (configurable in source)
- Codec: H.264 (OpenH264)
- Resolution: Supports any resolution (tested with 160×120, 640×480)
- FPS: Configurable (tested with 20-30 FPS)
API Documentation
Frame Types
CameraFrame
Represents a single camera frame.
ImageFormat
Image data format.
FrameBroadcaster
Efficiently broadcasts frames to multiple subscribers.
let broadcaster = new; // capacity = 1 for minimal latency
broadcaster.broadcast?;
let mut rx = broadcaster.subscribe;
WebRTC Server
WebRTCServer
Creates and manages WebRTC connections.
// Without diagnostics
let server = new.await?;
// With diagnostics (requires "diagnostics" feature)
let server = new.await?;
// Create connection for a client
let connection = server.create_connection.await?;
WebRTCConnection
Represents a single client connection.
// Create SDP offer
let offer_sdp = connection.create_offer.await?;
// Handle SDP answer from browser
connection.handle_answer.await?;
// Add ICE candidate
connection.add_ice_candidate.await?;
// Start streaming (blocks until connection closes)
connection.run_streaming_loop.await?;
Signaling Server
start_signaling_server
Starts a WebSocket-based WebRTC signaling server.
use start_signaling_server;
let webrtc_server = new;
spawn;
Protocol:
- Endpoint:
ws://localhost:11010/webrtc - Single-connection mode (disconnects previous client when new one connects)
- Server-initiated SDP offer flow
Integration
Simulation Bridge
The simulation-bridge node uses this package for camera streaming:
use ;
// Create WebRTC server with diagnostics
let webrtc_server = new.await?;
// Start signaling server
spawn;
Edge Robot Cameras
For physical cameras on edge robots:
- Capture frames from camera driver
- Convert to
CameraFramewith RGB or JPEG format - Send to WebRTC server via mpsc channel
- Dashboard connects via WebRTC signaling server
Source of Truth
This package was extracted from simulation-bridge/src/webrtc_server.rs and simulation-bridge/src/signaling_server.rs, which are the production-tested reference implementations.
See docs/VIDEO_EXTRACTION_PLAN.md for extraction history and rationale.
Dependencies
webrtc 0.14- WebRTC implementationopenh264 0.9- Fast H.264 encoderaxum 0.7- WebSocket signaling servertokio- Async runtimeimage 0.25- JPEG decoding (minimal features)mecha10-diagnostics(optional) - Streaming metrics
License
MIT