From 9846eb99c6b67d9a78753ba3e16d40daef8501f2 Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Fri, 3 Jul 2020 17:14:16 -0500 Subject: [PATCH] Autoformat --- src/config.rs | 16 ++++++++++++---- src/gst.rs | 2 +- src/main.rs | 33 ++++++++++++++++++++------------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/config.rs b/src/config.rs index 576ea99..0a230c4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,9 +1,9 @@ +use regex::Regex; use serde::Deserialize; +use std::clone::Clone; 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(); @@ -35,11 +35,19 @@ pub struct CameraConfig { pub timeout: Option, - #[validate(regex(path = "RE_STREAM_FORM", message = "Incorrect stream format", code = "format"))] + #[validate(regex( + path = "RE_STREAM_FORM", + message = "Incorrect stream format", + code = "format" + ))] #[serde(default = "default_format")] pub format: String, - #[validate(regex(path = "RE_STREAM_SRC", message = "Incorrect stream source", code = "stream"))] + #[validate(regex( + path = "RE_STREAM_SRC", + message = "Incorrect stream source", + code = "stream" + ))] #[serde(default = "default_stream")] pub stream: String, } diff --git a/src/gst.rs b/src/gst.rs index 6c23509..a070d5e 100644 --- a/src/gst.rs +++ b/src/gst.rs @@ -21,7 +21,7 @@ pub struct RtspServer { pub enum StreamFormat { H264, H265, - Custom(String) + Custom(String), } impl RtspServer { diff --git a/src/main.rs b/src/main.rs index 66c44d2..12394d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ -#[macro_use] extern crate validator_derive; -#[macro_use] extern crate lazy_static; +#[macro_use] +extern crate validator_derive; +#[macro_use] +extern crate lazy_static; use env_logger::Env; use err_derive::Error; @@ -54,15 +56,15 @@ fn main() -> Result<(), Error> { crossbeam::scope(|s| { for camera in config.cameras { let stream_format = match &*camera.format { - "h264"|"H264" => StreamFormat::H264, - "h265"|"H265" => StreamFormat::H265, - custom_format @ _ => StreamFormat::Custom(custom_format.to_string()) + "h264" | "H264" => StreamFormat::H264, + "h265" | "H265" => StreamFormat::H265, + custom_format @ _ => StreamFormat::Custom(custom_format.to_string()), }; // The substream always seems to be H264, even on B800 cameras let substream_format = match &*camera.format { - "h264"|"H264"|"h265"|"H265" => StreamFormat::H264, - custom_format @ _ => StreamFormat::Custom(custom_format.to_string()) + "h264" | "H264" | "h265" | "H265" => StreamFormat::H264, + custom_format @ _ => StreamFormat::Custom(custom_format.to_string()), }; // Let subthreads share the camera object; in principle I think they could share @@ -72,10 +74,7 @@ fn main() -> Result<(), Error> { // Set up each main and substream according to all the RTSP mount paths we support if arc_cam.stream == "both" || arc_cam.stream == "mainStream" { - let paths = &[ - &arc_cam.name, - &*format!("{}/mainStream", arc_cam.name), - ]; + let paths = &[&arc_cam.name, &*format!("{}/mainStream", arc_cam.name)]; let mut output = rtsp.add_stream(paths, &stream_format).unwrap(); let main_camera = arc_cam.clone(); s.spawn(move |_| camera_loop(&*main_camera, "mainStream", &mut output)); @@ -95,7 +94,11 @@ fn main() -> Result<(), Error> { Ok(()) } -fn camera_loop(camera_config: &CameraConfig, stream_name: &str, output: &mut MaybeAppSrc) -> Result { +fn camera_loop( + camera_config: &CameraConfig, + stream_name: &str, + output: &mut MaybeAppSrc, +) -> Result { let min_backoff = Duration::from_secs(1); let max_backoff = Duration::from_secs(15); let mut current_backoff = min_backoff; @@ -133,7 +136,11 @@ struct CameraErr { err: neolink::Error, } -fn camera_main(camera_config: &CameraConfig, stream_name: &str, output: &mut dyn Write) -> Result { +fn camera_main( + camera_config: &CameraConfig, + stream_name: &str, + output: &mut dyn Write, +) -> Result { let mut connected = false; (|| { let mut camera = BcCamera::new_with_addr(camera_config.camera_addr)?;