Expand description
§onvif-server
An ONVIF Profile S streaming-core device server library for Rust.
Implement the service traits for your camera hardware to expose a device that standard ONVIF clients (VMS, NVR, Home Assistant, Frigate, python-onvif-zeep, ONVIF Device Manager) can discover and stream from. It targets the Profile S streaming core, not every ONVIF operation — see the Operation Coverage matrix in the user guide for the exact support claims.
§ONVIF Profile S coverage
| Service | Status |
|---|---|
| Device | Supported |
| Media | Supported |
| PTZ | Supported |
| Imaging | Supported |
| Events | Supported |
§Quick start
An empty impl DeviceService for MyCamera {} compiles but faults on the first
real request — GetDeviceInformation and GetStreamUri have no working
default. This is the smallest usable device (see the minimal_device
example, and the Operation Coverage matrix in the user guide for what each
operation does by default):
use async_trait::async_trait;
use onvif_server::{DeviceInfo, DeviceService, MediaService, OnvifError, OnvifServer};
#[derive(Clone)]
struct MinimalCamera {
media_host: String,
}
#[async_trait]
impl DeviceService for MinimalCamera {
async fn get_device_information(&self) -> Result<DeviceInfo, OnvifError> {
Ok(DeviceInfo {
manufacturer: "Example Corp".into(),
model: "Minimal-1".into(),
firmware_version: "1.0.0".into(),
serial_number: "SN-0001".into(),
hardware_id: "minimal-hw-1".into(),
})
}
}
#[async_trait]
impl MediaService for MinimalCamera {
async fn get_stream_uri(&self, _profile: &str) -> Result<String, OnvifError> {
Ok(format!("rtsp://{}:8554/stream", self.media_host))
}
}
#[tokio::main]
async fn main() {
let host = "192.168.1.10";
let cam = MinimalCamera { media_host: host.into() };
OnvifServer::builder()
.port(8080)
.advertised_host(host)
.device_service(cam.clone())
.media_service(cam)
.auth("admin", "password")
.build()
.expect("build failed")
.run()
.await
.expect("server error");
}§WS-Security
Call .auth(username, password) on the builder to enable WS-Security
UsernameToken digest authentication. GetSystemDateAndTime is automatically
exempt from auth (required by ONVIF spec for clock synchronisation before
the client has valid credentials).
§WS-Discovery
Enable the optional discovery feature to have the server respond to
WS-Discovery multicast probes on 239.255.255.250:3702, making the device
auto-discoverable on the local network.
[dependencies]
onvif-server = { version = "0.1", features = ["discovery"] }Re-exports§
pub use generated::DeviceInfo;pub use generated::HostnameInformation;pub use generated::ImagingSettings;pub use generated::MediaProfile;pub use generated::NetworkInterface;pub use generated::PTZPreset;pub use generated::PTZStatusResult;pub use generated::Scope;pub use generated::ScopeDefinition;pub use generated::VideoEncoderConfiguration;pub use generated::VideoSource;pub use generated::VideoSourceConfiguration;pub use service::device::DeviceServiceHandler;pub use service::events::EventServiceHandler;pub use service::imaging::ImagingServiceHandler;pub use service::media::MediaServiceHandler;pub use service::ptz::PTZServiceHandler;pub use traits::DeviceService;pub use traits::EventService;pub use traits::ImagingService;pub use traits::MediaService;pub use traits::PTZService;
Modules§
- discovery
- WS-Discovery support. The probe-detection and response-building functions are
always compiled (pure XML, testable without sockets); the UDP multicast listener
(
run_discovery) is only compiled with thediscoveryfeature. - generated
- service
- traits
Structs§
- Embedded
Wsdl Loader - Serves bundled ONVIF WSDL and XSD files from bytes embedded at compile time.
- Onvif
Server - A built, configured ONVIF server handle.
- Onvif
Server Builder - Builder for configuring and constructing an
OnvifServer.
Enums§
- Build
Error - Error returned by
OnvifServerBuilder::buildwhen required configuration is missing. - Onvif
Error - ONVIF-specific error type that maps to SOAP faults with the ONVIF ter: namespace.
- RunError
- Error returned by
OnvifServer::run. - Wsdl
Error - Error type for WSDL parsing failures.
Constants§
- PROFILE_
TOKEN - Token for the single media profile exposed by this device. Used in GetProfiles, GetStreamUri, and all PTZ operations.
- PTZ_
CONFIG_ TOKEN - Token for the PTZ configuration attached to the media profile. Used in GetConfiguration and PTZ service move operations.
- PTZ_
NODE_ TOKEN - Token for the PTZ node describing the physical PTZ capabilities. Referenced in GetNodes and GetNode responses.
- TRANSLATION_
SPACE_ FOV - ONVIF PTZ translation space URI for field-of-view relative moves. Used as the Space field in RelativeMove PanTilt arguments.
- VIDEO_
ENCODER_ TOKEN - Token for the single video encoder configuration.
- VIDEO_
SOURCE_ TOKEN - Token for the single video source. Referenced in VideoSourceConfiguration elements.
Traits§
- Wsdl
Loader - Abstracts file/network I/O for loading WSDL files during recursive import resolution.
Functions§
- discovery_
build_ probe_ match - Build a WS-Discovery
ProbeMatchesresponse XML with a stabledevice_uuidembedded inEndpointReference/Address. - discovery_
is_ probe - Returns
truewhenmsgis a well-formed WS-DiscoveryProbemessage (SOAP body first child =Probein namespacehttp://schemas.xmlsoap.org/ws/2005/04/discovery).