Removed unessecary public from the rtsp module
This commit is contained in:
4 files changed
+45
-39
No files matched your search
@@ -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 mut result: Vec<u8> = vec![]; // Stores the PCM byte array
|
||||
|
||||
+21
-21
@@ -12,19 +12,19 @@ lazy_static! {
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Validate, Clone)]
|
||||
pub struct Config {
|
||||
pub(crate) struct Config {
|
||||
#[validate]
|
||||
pub cameras: Vec<CameraConfig>,
|
||||
pub(crate) cameras: Vec<CameraConfig>,
|
||||
|
||||
#[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<String>,
|
||||
pub(crate) certificate: Option<String>,
|
||||
|
||||
#[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<UserConfig>,
|
||||
pub(crate) users: Vec<UserConfig>,
|
||||
}
|
||||
|
||||
#[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<String>,
|
||||
pub(crate) username: String,
|
||||
pub(crate) password: Option<String>,
|
||||
|
||||
// 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:
|
||||
pub format: Option<String>,
|
||||
pub(crate) format: Option<String>,
|
||||
|
||||
#[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<Vec<String>>,
|
||||
pub(crate) permitted_users: Option<Vec<String>>,
|
||||
|
||||
#[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"));
|
||||
|
||||
+23
-15
@@ -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<T> = std::result::Result<T, ()>;
|
||||
|
||||
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<StreamFormat>,
|
||||
audio_format: Option<StreamFormat>,
|
||||
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<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
|
||||
/// 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<AppSrc>) {
|
||||
pub(crate) fn new_with_tx() -> (Self, SyncSender<AppSrc>) {
|
||||
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();
|
||||
|
||||
@@ -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)?)?;
|
||||
|
||||
|
||||
Reference in new issue
Block a user