patinas-hub — Architecture & Capabilities
patinas-hub is the hub/cloud/DC role. It terminates the transport from proxies, subscribes to one or more streams, and exposes the stream to downstream consumers (SDK clients, bridges, future fanout).
When built with the rtsp-io feature, it can also receive RTSP (act as an RTSP client pulling from a camera) and serve RTSP (act as an RTSP server for VMS/clients).
Process-level composition (what’s “inside”)
At runtime the patinas-hub process typically includes:
- CLI / orchestration:
apps/patinas-hub- Parses flags, loads config, starts metrics server, spawns the role.
- Optional “hub-side observability” behind build feature + runtime flag.
- Role runtime:
crates/patinas-role-hub- Connects using
PatinasClient::connect_with_backoff(...). - Runs:
- a stats tick loop (exports connection/queue/rtt metrics)
- a subscribe loop (receives frames; exports counters/histograms)
- Connects using
- SDK client:
crates/patinas-sdk- Provides
resubscribe_with_backoff()and transport handle access.
- Provides
- Transport adapters: based on
hub.addrscheme:inproc://...(in-process; tests/dev)udp://...(mock network)quic://.../quinn://...(real network transport; feature-gated elsewhere)
- Metrics server:
crates/patinas-adapters-metrics - Config adapter:
crates/patinas-adapters-config - (Optional) Engine:
crates/patinas-role-engine(feature-gated:engine) - (Optional) RTSP client + server:
crates/patinas-adapters-rtsp(app feature:rtsp-io) - (Optional) Observability:
- Compile-time: hub role has
feature = "observability" - App feature:
hub-observabilitydrives local store/export wiring and ONVIF warmup helpers
- Compile-time: hub role has
Data path (hub)
1) Transport termination and subscription
- The hub connects via
PatinasClient::connect_with_backoff(...). - The subscribe loop uses
resubscribe_with_backoff()and then consumes frames from a stream.
1b) RTSP receive + RTSP serve (optional, inside hub process)
When built with --features rtsp-io and run with --rtsp-io, the hub may:
- Receive RTSP: connect to
rtsp.source.*and pullEncodedFramevalues via the pure-Rust RTSP client (patinas-adapters-rtsp,rtsp-rustdefault; the GStreamer backend sits behindrtsp-gst). - Serve RTSP: start an RTSP server from
rtsp.sink.*and inject frames via appsrc.
Current wiring is intentionally simple:
- frames pulled from
rtsp.sourceare forwarded intortsp.sink(drop-on-full queue policy). - this is app-level wiring so the core hub role stays transport-focused and testable without RTSP dependencies.
2) Optional engine stage (jitter)
When built with feature = "engine" and enabled in config/flags:
- If
jitter_enabled=true, the hub callsengine.process_egress(frames, now_ms)before counting playout.
Note: this is intended for smoothing; avoid enabling jitter on multiple hops.
3) Metrics and timestamps
Per frame, the hub exports:
patinas_receive_total{role="hub",stream_id="..."}patinas_playout_total{role="hub",stream_id="..."}patinas_frame_interarrival_ms{stream_id="..."}patinas_e2e_latency_ms{stream_id="..."}
E2E latency here is currently computed as:
now_ms - frame.pts_ms
That assumes proxy PTS is comparable to hub wallclock (reasonable only if clocks are close, or if PTS is “send time”).
Multi-stream support
The hub role supports multi-stream configuration in node config (node.toml) via:
hub.streams = [{ addr, stream_id }, ...]
The standalone hub config loader currently builds a single stream runtime from hub.addr / hub.stream_id.
Control plane & operability
Health + metrics
- Endpoints:
/healthz,/metrics(default bind127.0.0.1:9641) - Net stats: exported via
NetStatsExporter(connected, send queue depth, RTT, bytes in flight, etc.)
Configuration sources
- Config file:
--config hub.toml - Env overrides:
PATINAS_SECTION_KEY(seedocs/config/REFERENCE.md)
Common config keys used by hub:
hub.addr(bind/listen target; scheme selects transport)hub.stream_idresilience.retry_max_gap_ms(used for backoff cap in current hub role)tls.ca_pem,tls.cert_pem,tls.key_pem(for QUIC/mTLS)
Hub-side observability (optional)
There are two layers:
- Role-level observability (
feature = "observability"): emits bounded “facts” by polling transport + tracking active streams. - App-level wiring (
feature = "hub-observability"): creates a local bounded store and can export a JSONL session on shutdown.
This is a good direction for production readiness because:
- it’s bounded (retention max events)
- it is opt-in (build feature + runtime flag)
Hub-focused critique (what to tighten)
Config surface vs actual behavior
In the hub role’s from_config_file(...), some “resilience” knobs are currently set to fixed defaults in code (with comments that hub-side resilience is future work). That can surprise operators because hub.toml advertises [resilience] keys.
Recommendation:
- Either fully honor hub-side
[resilience]config, or remove/relocate those keys fromhub.tomluntil they’re implemented.
E2E latency semantics
now_ms - pts_ms is only meaningful if PTS is “ingest wallclock” and clocks are aligned. On real devices, clock skew and drift are normal.
Recommendation:
- Define PTS semantics explicitly (e.g., capture-time vs send-time).
- Add a “proxy->hub clock offset” metric (or embed a send timestamp) to make E2E latency meaningful.
Capabilities checklist (current)
- Transport termination: inproc / UDP mock / QUIC (feature-gated) via
PatinasClient - Subscription: yes (
resubscribe_with_backoff) - Metrics: Prometheus
/metrics+/healthz - Multi-stream: supported via
node.toml; single stream viahub.toml - Observability: opt-in (feature gated)
- RTSP receive + serve: supported when built with
rtsp-ioand run with--rtsp-io(usesrtsp.source.*+rtsp.sink.*)- ONVIF/RTSP Digest auth: supported when configured via
rtsp.sink.onvif_realm+rtsp.sink.username/password.
- ONVIF/RTSP Digest auth: supported when configured via