diff --git a/Cargo.toml b/Cargo.toml index 86beb93..3ba9d35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ gstreamer-app = "0.15" gstreamer-player = "0.15" gstreamer-rtsp = "0.15" gstreamer-rtsp-server = "0.15" -log = { version = "0.4", features = ["release_max_level_warn"] } +log = { version = "0.4", features = ["release_max_level_info"] } indoc = "0.3" md5 = "0.7" nom = "5.1" diff --git a/src/bc_protocol/connection.rs b/src/bc_protocol/connection.rs index eac68bb..ac2dcec 100644 --- a/src/bc_protocol/connection.rs +++ b/src/bc_protocol/connection.rs @@ -48,16 +48,14 @@ impl BcConnection { let mut context = BcContext::new(); while let Ok(_) = BcConnection::poll(&mut context, &mut conn, &mut subs) {} }); + // TODO join on drop Ok(bc_conn) } pub fn subscribe(&self, msg_id: u32) -> Result { let (tx, rx) = channel(); - { - let mut locked_subs = self.subscribers.lock().unwrap(); - locked_subs.insert(msg_id, tx); - } + self.subscribers.lock().unwrap().insert(msg_id, tx); Ok(BcSubscription { rx, conn: self, msg_id }) } @@ -90,6 +88,8 @@ impl BcConnection { impl<'a> BcSubscription<'a> { pub fn send(&self, bc: Bc) -> Result<()> { + assert!(bc.meta.msg_id == self.msg_id); + // TODO Use channel for writing, too bc.serialize(&*self.conn.connection)?; Ok(()) diff --git a/src/main.rs b/src/main.rs index 3febf66..e583313 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,12 +6,13 @@ mod config; mod cmdline; mod gst; -use backoff::{ExponentialBackoff, Operation}; +use backoff::{Error::*, ExponentialBackoff, Operation}; use bc_protocol::BcCamera; use config::{Config, CameraConfig}; use cmdline::Opt; use err_derive::Error; use gst::RtspServer; +use log::error; use std::fs; use std::time::Duration; use std::io::Write; @@ -60,8 +61,14 @@ fn camera_loop(camera_config: &CameraConfig, output: &mut dyn Write) -> Result<( }; op.retry(&mut backoff).map_err(|backoff_err| -> Error { match backoff_err { - backoff::Error::Transient(e) | - backoff::Error::Permanent(e) => e.into() + Transient(e) => { + error!("Error streaming from camera {}, will retry: {}", camera_config.name, e); + e.into() + } + Permanent(e) => { + error!("Permanent error sreaming from camera {}: {}", camera_config.name, e); + e.into() + } } }) } @@ -72,10 +79,11 @@ fn camera_main(camera_config: &CameraConfig, output: &mut dyn Write) -> Result<( println!("{}: Connecting to camera at {}", camera_config.name, camera_config.camera_addr); camera.connect()?; + // Authentication failures are permanent; we retry everything else camera.login(&camera_config.username, camera_config.password.as_deref()).map_err(|e| { match e { - bc_protocol::Error::AuthFailed => backoff::Error::Permanent(e), - _ => backoff::Error::Transient(e) + bc_protocol::Error::AuthFailed => Permanent(e), + _ => Transient(e) } })?;