dahua_camera/lib.rs
1//! The Dahua camera stack — one dependency, every capability behind a flag.
2//!
3//! This is the crate consumers should depend on. It re-exports the workspace's
4//! internal crates behind the feature matrix below, and owns the two things
5//! that are inherently composition concerns: loading [`config`] and choosing
6//! adapters in [`wiring`].
7//!
8//! Advanced users may depend on an internal crate directly — `dahua-camera-rtsp`
9//! alone, say, to embed the video path with no config loader. Everyone else
10//! should stay here.
11//!
12//! # Quick start
13//!
14//! ```no_run
15//! # #[cfg(all(feature = "rtsp", feature = "server"))]
16//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
17//! use dahua_camera::config::TomlConfigStore;
18//! use dahua_camera::core::ports::ConfigStore;
19//! use dahua_camera::rtsp::CameraService;
20//! use dahua_camera::wiring;
21//! use std::path::Path;
22//!
23//! let config = TomlConfigStore::new().load(Path::new("config.toml"))?;
24//! let service = CameraService::start(&config, wiring::production());
25//!
26//! let listener = tokio::net::TcpListener::bind("127.0.0.1:8787").await?;
27//! axum::serve(listener, dahua_camera::server::router(service)).await?;
28//! # Ok(())
29//! # }
30//! ```
31//!
32//! # Feature matrix
33//!
34//! Every feature is **off by default except `rtsp`**, and every feature is
35//! **additive**: turning one on never changes what another does. With only the
36//! default enabled, this crate behaves exactly as the pre-split
37//! `camera-service` crate did — same task count, same latency, same
38//! allocations per frame.
39//!
40//! | Feature | Implies | Adds |
41//! |---|---|---|
42//! | `rtsp` *(default)* | — | RTSP ingest, supervision, fMP4 fan-out |
43//! | `decode` | `rtsp` | H.264 → JPEG for snapshots and MJPEG |
44//! | `events` | — | Event subscription (Dahua CGI, ONVIF PullPoint) |
45//! | `alarms` | `events` | Alarm lifecycle: latch, auto-clear, acknowledge |
46//! | `discovery` | — | WS-Discovery, Dahua discovery, IP-range scan |
47//! | `health` | — | Health state machine, clock drift, freeze detection |
48//! | `record` | `decode` | Recording, playback, snapshot, storage |
49//! | `opcua` | `events`, `health` | OPC UA address space |
50//! | `mqtt` | `events`, `health` | MQTT publisher |
51//! | `full` | — | Everything above |
52//! | `onvif` | — | Device, Media, Imaging, Users SOAP services |
53//! | `control` | `onvif` | Imaging, encoding, IVS rules, alarm I/O |
54//! | `server` | `rtsp` | axum HTTP + SSE + WebSocket API |
55//! | `tls` | — | HTTPS for management connections |
56//!
57//! `PERFORMANCE.md` gives the cost of each one in tasks, threads, CPU and RSS.
58//! The hard limits it records: **no feature adds more than one task per
59//! camera, none performs CPU work on the tokio runtime, and none may block,
60//! delay, or share a channel with video frames.**
61//!
62//! # Safety
63//!
64//! Camera IVS/SMD detection is an **operator aid** and is **not safety-rated**.
65//! It must not be used as an interlock, a permissive, or a condition for
66//! machine motion. Read `SAFETY.md` before using any detection this crate
67//! reports.
68//!
69//! # Security
70//!
71//! No credential is ever written to a config file, a log line, an error
72//! message, or a `Debug` output. Passwords come from the environment via
73//! `${VAR}` indirection in the config, and every type that holds one
74//! implements `Debug` by hand. See the `Security` section of `README.md`.
75
76#![warn(missing_docs)]
77#![forbid(unsafe_code)]
78
79pub mod config;
80
81#[cfg(feature = "rtsp")]
82pub mod wiring;
83
84pub use dahua_camera_core as core;
85pub use dahua_camera_http as http;
86
87#[cfg(feature = "rtsp")]
88pub use dahua_camera_rtsp as rtsp;
89
90#[cfg(feature = "events")]
91pub use dahua_camera_events as events;
92
93#[cfg(feature = "alarms")]
94pub use dahua_camera_alarms as alarms;
95
96#[cfg(feature = "health")]
97pub use dahua_camera_health as health;
98
99#[cfg(feature = "discovery")]
100pub use dahua_camera_discovery as discovery;
101
102#[cfg(feature = "record")]
103pub use dahua_camera_record as record;
104
105#[cfg(feature = "opcua")]
106pub use dahua_camera_opcua as opcua;
107
108#[cfg(feature = "mqtt")]
109pub use dahua_camera_mqtt as mqtt;
110
111#[cfg(feature = "onvif")]
112pub use dahua_camera_onvif as onvif;
113
114#[cfg(feature = "control")]
115pub use dahua_camera_control as control;
116
117#[cfg(feature = "server")]
118pub use dahua_camera_server as server;
119
120// The handful of types nearly every consumer names, lifted to the root.
121pub use dahua_camera_core::{
122 AppConfig, BoundingBox, Capability, CapabilitySet, CameraConfig, CameraError, CameraId,
123 CameraStats, CameraStatus, CodecParameters, Event, EventKind, EventState, Frame, Result,
124 Sample, ServerConfig, Severity, StreamParams,
125};
126
127#[cfg(feature = "rtsp")]
128pub use dahua_camera_rtsp::{Camera, CameraService, ServiceDeps};