dahua_camera_rtsp/lib.rs
1//! RTSP ingest, per-camera supervision, and frame fan-out.
2//!
3//! This is the video path, moved out of the pre-split `camera-service` crate
4//! unchanged. Eight simultaneous Dahua cameras stream to a browser for roughly
5//! 10% of one CPU because nothing here decodes: H.264 access units are handed
6//! to subscribers as-is and rewrapped into fMP4 fragments, so the *client's*
7//! hardware decoder does the work.
8//!
9//! Decoding to JPEG exists behind the `decode` feature, runs on its own OS
10//! thread, and starts only while something is consuming it.
11//!
12//! # The seven invariants
13//!
14//! These are performance and correctness requirements, not style preferences.
15//! Each is documented at the module that enforces it. **Do not "simplify" any
16//! of them** — each corresponds to a specific failure that will otherwise
17//! happen in a vehicle.
18//!
19//! 1. **No CPU work on the tokio runtime.** Decode and encode run on a
20//! dedicated OS thread — [`decoder`].
21//! 2. **Bounded broadcast with IDR resync.** A slow consumer is dropped
22//! forward and rejoins at a random-access point, never applying
23//! backpressure — [`frame_router`].
24//! 3. **`watch` for latest-value consumers.** Status, parameters and the JPEG
25//! lane deliver the newest value, not a backlog — [`frame_router`].
26//! 4. **Lazy work.** No RTSP traffic until something subscribes —
27//! [`supervisor`].
28//! 5. **Panic isolation.** One camera's panic never reaches another —
29//! [`supervisor`].
30//! 6. **Stall watchdog.** A silent session is torn down in bounded time —
31//! [`session`].
32//! 7. **`Bytes` for frame data.** Fan-out costs refcount bumps, not copies —
33//! [`dahua_camera_core::frame`].
34//!
35//! # Supervision is shared
36//!
37//! [`supervisor`] holds the *only* supervision loop in the workspace. Event
38//! subscription, health polling and every other long-lived connection run on
39//! it too, so they all inherit the same backoff, stall watchdog and panic
40//! isolation. Video and non-video links reconnect independently: an
41//! event-stream failure never disturbs video, and vice versa.
42//!
43//! # Features
44//!
45//! - `decode` — the H.264 → JPEG lane. Off by default.
46
47#![warn(missing_docs)]
48
49pub mod camera_service;
50pub mod frame_router;
51pub mod ports;
52pub mod rtsp;
53pub mod session;
54pub mod supervisor;
55pub mod testing;
56pub mod video;
57
58#[cfg(feature = "decode")]
59pub mod decoder;
60
61pub use camera_service::{Camera, CameraService, ServiceDeps};
62pub use frame_router::{FrameEvent, FrameRouter, Subscription, BUS_CAPACITY};
63pub use rtsp::{RtspSourceFactory, RtspVideoSource};
64pub use supervisor::RestartPolicy;
65pub use video::Fmp4Muxer;