From 8d13f14bea71dfc5c495140e8ec5c938e610b5c4 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Wed, 1 Jul 2020 12:40:27 +0700 Subject: [PATCH] Add appropiate submounts --- src/config.rs | 9 +++++---- src/main.rs | 28 +++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index 516d8d6..230449f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,15 +1,16 @@ use serde::Deserialize; use std::net::SocketAddr; use std::time::Duration; +use std::clone::Clone; use validator::Validate; use regex::Regex; lazy_static! { static ref RE_STREAM_FORM: Regex = Regex::new(r"^([hH]26[45]|[ \t]*[!].*)$").unwrap(); - static ref RE_STREAM_SRC: Regex = Regex::new(r"^(mainStream|subStream)$").unwrap(); + static ref RE_STREAM_SRC: Regex = Regex::new(r"^(mainStream|subStream|both)$").unwrap(); } -#[derive(Debug, Deserialize, Validate)] +#[derive(Debug, Deserialize, Validate, Clone)] pub struct Config { pub cameras: Vec, @@ -21,7 +22,7 @@ pub struct Config { pub bind_port: u16, } -#[derive(Debug, Deserialize, Validate)] +#[derive(Debug, Deserialize, Validate, Clone)] pub struct CameraConfig { pub name: String, @@ -55,5 +56,5 @@ fn default_format() -> String { } fn default_stream() -> String { - "mainStream".to_string() + "both".to_string() } diff --git a/src/main.rs b/src/main.rs index 27ec0a9..9f74799 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,7 +41,7 @@ fn main() -> Result<(), Error> { ); let opt = Opt::from_args(); - let config: Config = toml::from_str(&fs::read_to_string(opt.config)?)?; + let mut config: Config = toml::from_str(&fs::read_to_string(opt.config)?)?; match config.validate() { Ok(_) => (), @@ -54,6 +54,32 @@ fn main() -> Result<(), Error> { }; } + // Setup auto sub streams, we do this by looping the cameras + // If the stream type is both we clone the config + // On one of the clones we set stream_source to "mainStream" on the other "subStream" + // We also change the mount name by appending "/mainStream" or "/subStream" + // On the original uncloned config we change the stream from "both" to "mainStream" and leave the mount name unchanged + let mut new_cam_configs = vec![]; + + for camera_config in &mut config.cameras { + if camera_config.stream == "both" { + let mut main_camera_config = camera_config.clone(); + let mut sub_camera_config = camera_config.clone(); + + camera_config.stream = "mainStream".to_string(); + + main_camera_config.stream = "mainStream".to_string(); + main_camera_config.name = format!("{}/{}", main_camera_config.name, main_camera_config.stream); + new_cam_configs.push(main_camera_config); + + sub_camera_config.stream = "subStream".to_string(); + sub_camera_config.name = format!("{}/{}", sub_camera_config.name, sub_camera_config.stream); + sub_camera_config.format = "h264".to_string(); // Assuming always H264 on subStream: TODO: Autodetect + new_cam_configs.push(sub_camera_config); + } + } + config.cameras.append(&mut new_cam_configs); + let rtsp = &RtspServer::new(); crossbeam::scope(|s| {