diff --git a/crates/rtsp/src/adpcm.rs b/crates/rtsp/src/adpcm.rs index 30b3a4a..c7d4bea 100644 --- a/crates/rtsp/src/adpcm.rs +++ b/crates/rtsp/src/adpcm.rs @@ -85,7 +85,7 @@ impl Nibble { } } -pub fn adpcm_to_pcm(bytes: &[u8]) -> Result, Error> { +pub(crate) fn adpcm_to_pcm(bytes: &[u8]) -> Result, Error> { let context = AdpcmSetup::new_ima(); let mut result: Vec = vec![]; // Stores the PCM byte array diff --git a/crates/rtsp/src/config.rs b/crates/rtsp/src/config.rs index 9942e66..176b434 100644 --- a/crates/rtsp/src/config.rs +++ b/crates/rtsp/src/config.rs @@ -12,19 +12,19 @@ lazy_static! { } #[derive(Debug, Deserialize, Validate, Clone)] -pub struct Config { +pub(crate) struct Config { #[validate] - pub cameras: Vec, + pub(crate) cameras: Vec, #[serde(rename = "bind", default = "default_bind_addr")] - pub bind_addr: String, + pub(crate) bind_addr: String, #[validate(range(min = 0, max = 65535, message = "Invalid port", code = "bind_port"))] #[serde(default = "default_bind_port")] - pub bind_port: u16, + pub(crate) bind_port: u16, #[serde(default = "default_certificate")] - pub certificate: Option, + pub(crate) certificate: Option, #[validate(regex( path = "RE_TLS_CLIENT_AUTH", @@ -32,28 +32,28 @@ pub struct Config { code = "tls_client_auth" ))] #[serde(default = "default_tls_client_auth")] - pub tls_client_auth: String, + pub(crate) tls_client_auth: String, #[validate] #[serde(default)] - pub users: Vec, + pub(crate) users: Vec, } #[derive(Debug, Deserialize, Validate, Clone)] -pub struct CameraConfig { - pub name: String, +pub(crate) struct CameraConfig { + pub(crate) name: String, #[serde(rename = "address")] - pub camera_addr: String, + pub(crate) camera_addr: String, - pub username: String, - pub password: Option, + pub(crate) username: String, + pub(crate) password: Option, // no longer used, but still here so we can warn users: - pub timeout: Option, + pub(crate) timeout: Option, // no longer used, but still here so we can warn users: - pub format: Option, + pub(crate) format: Option, #[validate(regex( path = "RE_STREAM_SRC", @@ -61,23 +61,23 @@ pub struct CameraConfig { code = "stream" ))] #[serde(default = "default_stream")] - pub stream: String, + pub(crate) stream: String, - pub permitted_users: Option>, + pub(crate) permitted_users: Option>, #[validate(range(min = 0, max = 31, message = "Invalid channel", code = "channel_id"))] #[serde(default = "default_channel_id")] - pub channel_id: u8, + pub(crate) channel_id: u8, } #[derive(Debug, Deserialize, Validate, Clone)] -pub struct UserConfig { +pub(crate) struct UserConfig { #[validate(custom = "validate_username")] #[serde(alias = "username")] - pub name: String, + pub(crate) name: String, #[serde(alias = "password")] - pub pass: String, + pub(crate) pass: String, } fn default_bind_addr() -> String { @@ -104,7 +104,7 @@ fn default_channel_id() -> u8 { 0 } -pub static RESERVED_NAMES: &[&str] = &["anyone", "anonymous"]; +pub(crate) static RESERVED_NAMES: &[&str] = &["anyone", "anonymous"]; fn validate_username(name: &str) -> Result<(), ValidationError> { if name.trim().is_empty() { return Err(ValidationError::new("username cannot be empty")); diff --git a/crates/rtsp/src/gst.rs b/crates/rtsp/src/gst.rs index e58d4a8..ca3cf62 100644 --- a/crates/rtsp/src/gst.rs +++ b/crates/rtsp/src/gst.rs @@ -1,6 +1,6 @@ //! This module provides an "RtspServer" abstraction that allows consumers of its API to feed it //! data using an ordinary std::io::Write interface. -pub use self::maybe_app_src::MaybeAppSrc; +pub(crate) use self::maybe_app_src::MaybeAppSrc; use super::adpcm::adpcm_to_pcm; use gstreamer::prelude::Cast; use gstreamer::{Bin, Structure}; @@ -23,13 +23,13 @@ use std::io::Write; type Result = std::result::Result; -pub struct RtspServer { +pub(crate) struct RtspServer { server: GstRTSPServer, } -pub struct GstOutputs { - pub audsrc: MaybeAppSrc, - pub vidsrc: MaybeAppSrc, +pub(crate) struct GstOutputs { + pub(crate) audsrc: MaybeAppSrc, + pub(crate) vidsrc: MaybeAppSrc, video_format: Option, audio_format: Option, factory: RTSPMediaFactory, @@ -55,7 +55,7 @@ impl StreamOutput for GstOutputs { } impl GstOutputs { - pub fn from_appsrcs(vidsrc: MaybeAppSrc, audsrc: MaybeAppSrc) -> GstOutputs { + pub(crate) fn from_appsrcs(vidsrc: MaybeAppSrc, audsrc: MaybeAppSrc) -> GstOutputs { let result = GstOutputs { vidsrc, audsrc, @@ -123,14 +123,14 @@ impl Default for RtspServer { } impl RtspServer { - pub fn new() -> RtspServer { + pub(crate) fn new() -> RtspServer { gstreamer::init().expect("Gstreamer should not explode"); RtspServer { server: GstRTSPServer::new(), } } - pub fn add_stream( + pub(crate) fn add_stream( &self, paths: &[&str], permitted_users: &HashSet<&str>, @@ -191,7 +191,11 @@ impl RtspServer { Ok(outputs) } - pub fn add_permitted_roles(&self, factory: &RTSPMediaFactory, permitted_roles: &HashSet<&str>) { + pub(crate) fn add_permitted_roles( + &self, + factory: &RTSPMediaFactory, + permitted_roles: &HashSet<&str>, + ) { for permitted_role in permitted_roles { factory.add_role_from_structure(&Structure::new( permitted_role, @@ -223,7 +227,7 @@ impl RtspServer { } } - pub fn set_credentials(&self, credentials: &[(&str, &str)]) -> Result<()> { + pub(crate) fn set_credentials(&self, credentials: &[(&str, &str)]) -> Result<()> { let auth = self.server.get_auth().unwrap_or_else(RTSPAuth::new); auth.set_supported_methods(RTSPAuthMethod::Basic); @@ -242,7 +246,11 @@ impl RtspServer { Ok(()) } - pub fn set_tls(&self, cert_file: &str, client_auth: TlsAuthenticationMode) -> Result<()> { + pub(crate) fn set_tls( + &self, + cert_file: &str, + client_auth: TlsAuthenticationMode, + ) -> Result<()> { debug!("Setting up TLS using {}", cert_file); let auth = self.server.get_auth().unwrap_or_else(RTSPAuth::new); @@ -256,7 +264,7 @@ impl RtspServer { Ok(()) } - pub fn run(&self, bind_addr: &str, bind_port: u16) { + pub(crate) fn run(&self, bind_addr: &str, bind_port: u16) { self.server.set_address(bind_addr); self.server.set_service(&format!("{}", bind_port)); // Attach server to default Glib context @@ -274,7 +282,7 @@ mod maybe_app_src { /// A Write implementation around AppSrc that also allows delaying the creation of the AppSrc /// until later, discarding written data until the AppSrc is provided. - pub struct MaybeAppSrc { + pub(crate) struct MaybeAppSrc { rx: Receiver, app_src: Option, } @@ -283,13 +291,13 @@ mod maybe_app_src { /// Creates a MaybeAppSrc. Also returns a Sender that you must use to provide an AppSrc as /// soon as one is available. When it is received, the MaybeAppSrc will start pushing data /// into the AppSrc when write() is called. - pub fn new_with_tx() -> (Self, SyncSender) { + pub(crate) fn new_with_tx() -> (Self, SyncSender) { let (tx, rx) = sync_channel(3); // The sender should not send very often (MaybeAppSrc { rx, app_src: None }, tx) } /// Flushes data to Gstreamer on a problem communicating with the underlying video source. - pub fn on_stream_error(&mut self) { + pub(crate) fn on_stream_error(&mut self) { if let Some(src) = self.try_get_src() { // Ignore "errors" from Gstreamer such as FLUSHING, which are not really errors. let _ = src.end_of_stream(); diff --git a/crates/rtsp/src/lib.rs b/crates/rtsp/src/lib.rs index 00ed26b..5ce39d0 100644 --- a/crates/rtsp/src/lib.rs +++ b/crates/rtsp/src/lib.rs @@ -19,8 +19,6 @@ use config::{CameraConfig, Config, UserConfig}; use errors::Error; use gst::{GstOutputs, RtspServer}; -pub struct Rtsp; - pub fn main(opt: Opt) -> Result<(), Error> { let config: Config = toml::from_str(&fs::read_to_string(opt.config)?)?;