Removed unessecary public from the rtsp module

This commit is contained in:
QuantumEntangledAndy committed 2021-07-31 18:35:17 +07:00
1 parent ca5a598274
commit 4a773886ae
4 files changed
+45 -39

No files matched your search

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