From cb27c11ed8b4e10488ecd25485b056f15e6b3017 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Fri, 12 Apr 2024 09:40:42 +0700 Subject: [PATCH] Debug logging cleanup --- .../core/src/bc_protocol/connection/bcconn.rs | 12 +++--- .../core/src/bc_protocol/connection/bcsub.rs | 17 ++------- .../src/bc_protocol/connection/udpsource.rs | 2 - crates/core/src/bc_protocol/ptz.rs | 8 ---- crates/core/src/bc_protocol/resolution.rs | 5 --- crates/core/src/bc_protocol/stream.rs | 18 +-------- crates/core/src/bcmedia/codex.rs | 4 +- src/battery/mod.rs | 1 - src/common/camthread.rs | 5 --- src/common/instance.rs | 31 +++++++-------- src/common/neocam.rs | 24 +----------- src/common/reactor.rs | 7 +--- src/common/streamthread.rs | 18 --------- src/mqtt/mod.rs | 15 -------- src/rtsp/factory.rs | 5 --- src/rtsp/mod.rs | 8 ---- src/rtsp/stream.rs | 38 ++----------------- 17 files changed, 32 insertions(+), 186 deletions(-) diff --git a/crates/core/src/bc_protocol/connection/bcconn.rs b/crates/core/src/bc_protocol/connection/bcconn.rs index 9388460..04a7b0b 100644 --- a/crates/core/src/bc_protocol/connection/bcconn.rs +++ b/crates/core/src/bc_protocol/connection/bcconn.rs @@ -178,7 +178,6 @@ impl BcConnection { pub async fn shutdown(&self) -> Result<()> { let _ = self.poll_commander.send(PollCommand::Disconnect).await; - log::debug!("BcConnection::shutdown Cancel"); self.cancel.cancel(); let mut locked_threads = self.rx_thread.write().await; while locked_threads.join_next().await.is_some() {} @@ -196,7 +195,6 @@ impl Drop for BcConnection { let mut threads = std::mem::take(&mut self.rx_thread); tokio::task::spawn(async move { let _ = poll_commander.send(PollCommand::Disconnect).await; - log::debug!("BcConnection::shutdown Cancel"); let locked_threads = threads.get_mut(); while locked_threads.join_next().await.is_some() {} log::trace!("Dropped BcConnection"); @@ -331,17 +329,19 @@ impl Poller { } let _ = sender.send(Ok(response)).await; } else { - debug!( + trace!( "Ignoring uninteresting message id {} (number: {})", - msg_id, msg_num + msg_id, + msg_num ); trace!("Contents: {:?}", response); } } (None, None) => { - debug!( + trace!( "Ignoring uninteresting message id {} (number: {})", - msg_id, msg_num + msg_id, + msg_num ); trace!("Contents: {:?}", response); } diff --git a/crates/core/src/bc_protocol/connection/bcsub.rs b/crates/core/src/bc_protocol/connection/bcsub.rs index 62340c8..8933535 100644 --- a/crates/core/src/bc_protocol/connection/bcsub.rs +++ b/crates/core/src/bc_protocol/connection/bcsub.rs @@ -79,16 +79,13 @@ impl<'a> BcSubscription<'a> { pub fn payload_stream(&'_ mut self) -> impl Stream>> + '_ { (&mut self.rx).filter_map(|x| match x { Ok(Bc { - meta: BcMeta { msg_id, .. }, + meta: BcMeta { .. }, body: BcBody::ModernMsg(ModernMsg { payload: Some(BcPayloads::Binary(data)), .. }), - }) => { - log::debug!("PayloadStream got binary data: {msg_id}"); - Some(Ok(data)) - } + }) => Some(Ok(data)), Ok(_) => None, Err(e) => Some(Err(IoError::new(ErrorKind::Other, e))), }) @@ -97,15 +94,9 @@ impl<'a> BcSubscription<'a> { pub fn bcmedia_stream(&'_ mut self, strict: bool) -> impl Stream> + '_ { let async_read = self .payload_stream() - .map(|frame| { - log::debug!("- BcMedia Payloader got packet"); - frame - }) + .map(|frame| frame) .into_async_read() .compat(); - FramedRead::new(async_read, BcMediaCodex::new(strict)).map(|frame| { - log::debug!(" - BcMedia Payloader decoded packet"); - frame - }) + FramedRead::new(async_read, BcMediaCodex::new(strict)).map(|frame| frame) } } diff --git a/crates/core/src/bc_protocol/connection/udpsource.rs b/crates/core/src/bc_protocol/connection/udpsource.rs index 2e7f49b..4a22f91 100644 --- a/crates/core/src/bc_protocol/connection/udpsource.rs +++ b/crates/core/src/bc_protocol/connection/udpsource.rs @@ -371,7 +371,6 @@ impl UdpPayloadInner { // Socket is (maybe) broken // Seems to happen with network reconnects like over // a lossy cellular network - log::debug!("Quick reconnect: Due to socket timeout"); let stream = Arc::new(tokio::time::timeout(tokio::time::Duration::from_millis(250), connect_try_port(inner.inner.get_ref().local_addr()?.port())).await.map_err(|_| Error::DroppedConnection)??); inner = tokio::time::timeout(tokio::time::Duration::from_millis(250), BcUdpSource::new_from_socket(stream, inner.addr)).await.map_err(|_| Error::DroppedConnection)??; @@ -401,7 +400,6 @@ impl UdpPayloadInner { Ok(()) } => v, }; - log::debug!("UdpPayloadInner::new SendToSocket Cancel: {:?}", result); send_cancel.cancel(); result }); diff --git a/crates/core/src/bc_protocol/ptz.rs b/crates/core/src/bc_protocol/ptz.rs index d5e979e..7ebbdc0 100644 --- a/crates/core/src/bc_protocol/ptz.rs +++ b/crates/core/src/bc_protocol/ptz.rs @@ -239,16 +239,8 @@ impl BcCamera { /// The camera will zoom to a given zoom amount. /// Not sure what the units for this are, seems to be 1000 is 1x and 2000 is 2x pub async fn zoom_to(&self, zoom_pos: u32) -> Result<()> { - log::debug!("Setting to {}", zoom_pos); let current = self.get_zoom().await?; - log::debug!( - " curr: {}, min: {}, max: {}", - current.zoom.cur_pos, - current.zoom.min_pos, - current.zoom.max_pos - ); let zoom_pos = zoom_pos.clamp(current.zoom.min_pos, current.zoom.max_pos); - log::debug!("Clamped to {}", zoom_pos); self.has_ability_rw("control").await?; let connection = self.get_connection(); diff --git a/crates/core/src/bc_protocol/resolution.rs b/crates/core/src/bc_protocol/resolution.rs index e4e493b..17e99b2 100644 --- a/crates/core/src/bc_protocol/resolution.rs +++ b/crates/core/src/bc_protocol/resolution.rs @@ -1,6 +1,5 @@ //! This is a helper module to resolve either to a UID or a SockerAddr -use log::*; use serde::{Deserialize, Serialize}; use std::{ io::Error, @@ -89,7 +88,6 @@ impl ToSocketAddrsOrUid for str { .collect::>() .into_iter()), Err(e) => { - debug!("Trying as uid"); let re = regex::Regex::new(r"^[0-9A-Za-z]+$").unwrap(); if re.is_match(self) { Ok(vec![SocketAddrOrUid::Uid( @@ -99,7 +97,6 @@ impl ToSocketAddrsOrUid for str { )] .into_iter()) } else { - debug!("Regex fails {:?} => {:?} ", re, self); Err(e) } } @@ -117,7 +114,6 @@ impl ToSocketAddrsOrUid for String { .collect::>() .into_iter()), Err(e) => { - debug!("Trying as uid"); let re = regex::Regex::new(r"^[0-9A-Za-z]+$").unwrap(); if re.is_match(self) { Ok(vec![SocketAddrOrUid::Uid( @@ -127,7 +123,6 @@ impl ToSocketAddrsOrUid for String { )] .into_iter()) } else { - debug!("Regex fails {:?} => {:?} ", re, self); Err(e) } } diff --git a/crates/core/src/bc_protocol/stream.rs b/crates/core/src/bc_protocol/stream.rs index 9572434..b4c5f2c 100644 --- a/crates/core/src/bc_protocol/stream.rs +++ b/crates/core/src/bc_protocol/stream.rs @@ -49,25 +49,17 @@ impl StreamData { pub async fn get_data(&mut self) -> Result> { if let Some(handle) = self.handle.as_mut() { if handle.is_finished() { - log::debug!("SteamData::get_data Cancel1"); self.abort_handle.cancel(); handle.await??; return Err(Error::DroppedConnection); } } else { - log::debug!("SteamData::get_data Cancel2"); self.abort_handle.cancel(); return Err(Error::DroppedConnection); } - // debug!("StreamData: Get"); match self.rx.recv().await { - Some(data) => { - // debug!("StreamData: Got"); - Ok(data) - } + Some(data) => Ok(data), None => { - // debug!("StreamData: Drop"); - log::debug!("SteamData::get_data Cancel3"); self.abort_handle.cancel(); Err(Error::DroppedConnection) } @@ -77,7 +69,6 @@ impl StreamData { /// Attempts to gracefully shutdown this will cancel the background task and send /// the Stop command to the camera pub async fn shutdown(&mut self) -> Result<()> { - log::debug!("SteamData::shutdown Cancel"); self.abort_handle.cancel(); if let Some(handle) = self.handle.take() { let _ = handle.await?; @@ -218,20 +209,15 @@ impl BcCamera { _ = abort_handle_thread.cancelled() => {}, _ = async { while let Some(bc_media) = media_sub.next().await { - // debug!("Stream: Got"); // We now have a complete interesting packet. Send it to on the callback - // debug!("Stream: Send"); if tx.send(bc_media).await.is_err() { - // debug!("Stream: Dropped"); break; // Connection dropped } - // debug!("Stream: Sent"); } } => {} } } - // debug!("Stream: Stopping"); let stop_video = Bc::new_from_xml( BcMeta { msg_id: MSG_ID_VIDEO_STOP, @@ -251,10 +237,8 @@ impl BcCamera { ..Default::default() }, ); - // debug!("Stream: Send Stop"); let mut sub_stop = connection.subscribe(MSG_ID_VIDEO_STOP, msg_num).await?; sub_stop.send(stop_video).await?; - // debug!("Stream: Sent Stop"); tokio::select! { v = async { diff --git a/crates/core/src/bcmedia/codex.rs b/crates/core/src/bcmedia/codex.rs index 4679ac0..3523c9a 100644 --- a/crates/core/src/bcmedia/codex.rs +++ b/crates/core/src/bcmedia/codex.rs @@ -53,14 +53,14 @@ impl Decoder for BcMediaCodex { match BcMedia::deserialize(src) { Ok(bc) => { if self.amount_skipped > 0 { - debug!("Amount skipped to restore stream: {}", self.amount_skipped); + trace!("Amount skipped to restore stream: {}", self.amount_skipped); self.amount_skipped = 0; } return Ok(Some(bc)); } Err(Error::NomIncomplete(_)) => { if self.amount_skipped > 0 { - debug!("Amount skipped to restore stream: {}", self.amount_skipped); + trace!("Amount skipped to restore stream: {}", self.amount_skipped); self.amount_skipped = 0; } return Ok(None); diff --git a/src/battery/mod.rs b/src/battery/mod.rs index b9e6f12..5926bd5 100644 --- a/src/battery/mod.rs +++ b/src/battery/mod.rs @@ -23,7 +23,6 @@ pub(crate) use cmdline::Opt; /// Opt is the command line options pub(crate) async fn main(opt: Opt, reactor: NeoReactor) -> Result<()> { let camera = reactor.get(&opt.camera).await?; - log::debug!("Battery: Instance aquired"); let state = camera .run_task(|cam| { diff --git a/src/common/camthread.rs b/src/common/camthread.rs index 18646e9..6f5ed49 100644 --- a/src/common/camthread.rs +++ b/src/common/camthread.rs @@ -49,11 +49,9 @@ impl NeoCamThread { // Now we wait for a disconnect tokio::select! { _ = cancel_check.cancelled() => { - log::debug!("{name}: Camera Cancelled"); AnyResult::Ok(()) } v = camera.join() => { - log::debug!("{name}: Camera Join: {:?}", v); v?; Ok(()) }, @@ -152,7 +150,6 @@ impl NeoCamThread { match result { Ok(()) => { // Normal shutdown - log::debug!("Cancel:: NeoCamThread::NormalShutdown"); self.cancel.cancel(); return Ok(()); } @@ -164,7 +161,6 @@ impl NeoCamThread { Some(neolink_core::Error::CameraLoginFail) => { // Fatal log::error!("{name}: Login credentials were not accepted"); - log::debug!("NeoCamThread::run Login Cancel"); self.cancel.cancel(); return Err(e); } @@ -184,7 +180,6 @@ impl NeoCamThread { impl Drop for NeoCamThread { fn drop(&mut self) { - log::debug!("Cancel:: NeoCamThread::drop"); self.cancel.cancel(); } } diff --git a/src/common/instance.rs b/src/common/instance.rs index 83d431f..4bde74e 100644 --- a/src/common/instance.rs +++ b/src/common/instance.rs @@ -123,7 +123,7 @@ impl NeoInstance { for _ in 0..5 { r = task(cam_ref).await; if let Err(e) = &r { - log::debug!("- Task Result: {e:?}"); + log::trace!("- Task Result: {e:?}"); } if let Err(Some(neolink_core::Error::CameraServiceUnavailable(400))) = r.as_ref().map_err(|e| e.downcast_ref::()) { // Retryable without a reconnect @@ -147,73 +147,70 @@ impl NeoInstance { Err(e) => { match e.downcast::() { Ok(neolink_core::Error::DroppedConnection) | Ok(neolink_core::Error::TimeoutDisconnected) => { - log::debug!(" - Neolink error continue"); continue; }, Ok(neolink_core::Error::TokioBcSendError) => { - log::debug!(" - Neolink Send Error continue"); continue; }, Ok(neolink_core::Error::Io(e)) => { - log::debug!(" - Neolink Std IO Error"); use std::io::ErrorKind::*; if let ConnectionReset | ConnectionAborted | BrokenPipe | TimedOut = e.kind() { // Resetable IO - log::debug!(" - Neolink Std IO Error: Continue"); + log::trace!(" - Neolink Std IO Error: Continue"); continue; } else { // Check if the inner error is the Other type and then the discomnect let is_dropped = e.get_ref().is_some_and(|e| { - log::debug!("Std IO Error: Inner: {:?}", e); + log::trace!("Std IO Error: Inner: {:?}", e); matches!(e.downcast_ref::(), Some(neolink_core::Error::DroppedConnection) | Some(neolink_core::Error::TimeoutDisconnected) ) }); if is_dropped { // Retry is a None - log::debug!(" - Neolink Std IO Error => Neolink: Continue"); + log::trace!(" - Neolink Std IO Error => Neolink: Continue"); continue; } else { - log::debug!(" - Neolink Std IO Error: Other"); + log::trace!(" - Neolink Std IO Error: Other"); Err(e.into()) } } } Ok(e) => { - log::debug!(" - Neolink Error: Other"); + log::trace!(" - Neolink Error: Other"); Err(e.into()) }, Err(e) => { // Check if it is an io error - log::debug!(" - Other Error: {:?}", e); + log::trace!(" - Other Error: {:?}", e); match e.downcast::() { Ok(e) => { - log::debug!(" - Std IO Error"); + log::trace!(" - Std IO Error"); // Check if the inner error is the Other type and then the discomnect use std::io::ErrorKind::*; if let ConnectionReset | ConnectionAborted | BrokenPipe | TimedOut = e.kind() { // Resetable IO - log::debug!(" - Std IO Error: Continue"); + log::trace!(" - Std IO Error: Continue"); continue; } else { let is_dropped = e.get_ref().is_some_and(|e| { - log::debug!("Std IO Error: Inner: {:?}", e); + log::trace!("Std IO Error: Inner: {:?}", e); matches!(e.downcast_ref::(), Some(neolink_core::Error::DroppedConnection) | Some(neolink_core::Error::TimeoutDisconnected) | Some(neolink_core::Error::TokioBcSendError) ) }); if is_dropped { // Retry is a None - log::debug!(" - Std IO Error => Neolink Error: Continue"); + log::trace!(" - Std IO Error => Neolink Error: Continue"); continue; } else { - log::debug!(" - Std IO Error: Other"); + log::trace!(" - Std IO Error: Other"); Err(e.into()) } } }, Err(e) => { - log::debug!(" - Other Error: {:?}", e); + log::trace!(" - Other Error: {:?}", e); Err(e) } } @@ -289,7 +286,7 @@ impl NeoInstance { .await { Ok(pn) => { - log::debug!("Forwarding push notification about {}", uid); + log::trace!("Forwarding push notification about {}", uid); let _ = fwatch_tx.send_replace(pn.clone()); } Err(e) => { diff --git a/src/common/neocam.rs b/src/common/neocam.rs index 85fe80b..2b05983 100644 --- a/src/common/neocam.rs +++ b/src/common/neocam.rs @@ -91,14 +91,12 @@ impl NeoCam { let thread_cancel = sender_cancel.clone(); let res = tokio::select! { _ = sender_cancel.cancelled() => { - log::debug!("Control thread Cancelled"); Result::Ok(()) }, v = async { while let Some(command) = commander_rx.next().await { match command { NeoCamCommand::HangUp => { - log::debug!("Cancel:: NeoCamCommand::HangUp"); sender_cancel.cancel(); return Result::<(), anyhow::Error>::Ok(()); } @@ -153,14 +151,12 @@ impl NeoCam { NeoCamCommand::Connect(sender) => { if !matches!(*state_tx.borrow(), NeoCamThreadState::Connected) { state_tx.send_replace(NeoCamThreadState::Connected); - log::debug!("{}: Connect On Request", thread_watch_config_rx.borrow().name); } let _ = sender.send(()); } NeoCamCommand::Disconnect(sender) => { if !matches!(*state_tx.borrow(), NeoCamThreadState::Disconnected) { state_tx.send_replace(NeoCamThreadState::Disconnected); - log::debug!("{}: Disconnect On Request", thread_watch_config_rx.borrow().name); } let _ = sender.send(()); } @@ -187,14 +183,11 @@ impl NeoCam { }, } } - log::debug!("Control thread Senders dropped"); Ok(()) } => { - log::debug!("Camera Control Thread Ended; {:?}", v); v } }; - log::debug!("Control thread terminated"); res }); @@ -216,11 +209,7 @@ impl NeoCam { me.cancel.clone(), ) .await; - me.set.spawn(async move { - let v = cam_thread.run().await; - log::debug!("Camera MAIN thread ended; {:?}", v); - v - }); + me.set.spawn(async move { cam_thread.run().await }); // This thread maintains the streams let stream_instance = instance.subscribe().await?; @@ -230,7 +219,6 @@ impl NeoCam { tokio::select! { _ = stream_cancel.cancelled() => AnyResult::Ok(()), v = stream_thread.run() => { - log::debug!("Camera Stream thread ended; {:?}", v); v }, } @@ -244,7 +232,6 @@ impl NeoCam { tokio::select! { _ = md_cancel.cancelled() => AnyResult::Ok(()), v = md_thread.run() => { - log::debug!("MD thread ended; {:?}", v); v }, } @@ -277,7 +264,6 @@ impl NeoCam { for encode in stream_info.stream_infos.iter().flat_map(|stream_info| stream_info.encode_tables.clone()) { supported_streams.push(std::format!(" {}: {}x{}", encode.name, encode.resolution.width, encode.resolution.height)); } - log::debug!("{}: Listing Camera Supported Streams\n{}", report_name, supported_streams.join("\n")); Ok(()) @@ -345,13 +331,11 @@ impl NeoCam { }, }; if r.is_err() { - log::debug!("Push notifications stopped: {:?}", r); break r; } }?; AnyResult::Ok(()) } => { - log::debug!("Push notification thread ended; {:?}", v); v }, } @@ -380,7 +364,6 @@ impl NeoCam { } } } => { - log::debug!("MD Wake Up thread ended; {:?}", v); v }, } @@ -393,7 +376,6 @@ impl NeoCam { // notifications are observed let connect_instance = instance.subscribe().await?; let connect_cancel = me.cancel.clone(); - let connect_name = config.name.clone(); me.set.spawn(async move { tokio::select!{ _ = connect_cancel.cancelled() => { @@ -418,16 +400,13 @@ impl NeoCam { permit.deactivate().await?; // Watching only from here loop { permit.aquired_users().await?; - log::debug!("{connect_name}: InUse"); connect_instance.connect().await?; permit.dropped_users().await?; - log::debug!("{connect_name}: Idle Wait"); // Wait 30s or if we hit another use then go back and wait again tokio::select! { _ = sleep(Duration::from_secs(30)) => {}, _ = permit.aquired_users() => continue, }; - log::debug!("{connect_name}: Idle"); connect_instance.disconnect().await?; } } => v, @@ -438,7 +417,6 @@ impl NeoCam { }?; AnyResult::Ok(()) } => { - log::debug!("Idle Disconnect thread ended; {:?}", v); v }, } diff --git a/src/common/reactor.rs b/src/common/reactor.rs index baf5376..c10a551 100644 --- a/src/common/reactor.rs +++ b/src/common/reactor.rs @@ -61,7 +61,6 @@ impl NeoReactor { match command { NeoReactorCommand::HangUp => { instances.clear(); - log::debug!("Cancel:: NeoReactorCommand::HangUp"); cancel2.cancel(); return Result::<(), anyhow::Error>::Ok(()); } @@ -72,11 +71,9 @@ impl NeoReactor { let new = match instances.entry(name.clone()) { Entry::Occupied(occ) => Result::Ok(Some(occ.get().subscribe().await?)), Entry::Vacant(vac) => { - log::debug!("Inserting new insance"); let current_config: Config = (*thread_config_tx.borrow()).clone(); if let Some(config) = current_config.cameras.iter().find(|cam| cam.name == name).cloned() { let cam = NeoCam::new(config, push_noti.clone()).await?; - log::debug!("New instance created"); Result::Ok(Some( vac.insert( cam, @@ -89,7 +86,6 @@ impl NeoReactor { } } }; - log::debug!("Got instance from reactor"); let _ = sender.send(new); }, NeoReactorCommand::UpdateConfig(new_conf, reply) => { @@ -129,7 +125,7 @@ impl NeoReactor { thread_config_rx.wait_for(|c| c.cameras.iter().any(|cam| cam.push_notifications)).await?; // Wait until PN are enabled let r = tokio::select!{ v = pn.run(&pn_tx, &mut pn_rx) => {v}, - _ = thread_config_rx.wait_for(|c| c.cameras.iter().all(|cam| !cam.push_notifications)) => AnyResult::Ok(()), // Wait until PN are enabled => AnyResult::Ok(()), // Quit if PN is turned off + _ = thread_config_rx.wait_for(|c| c.cameras.iter().all(|cam| !cam.push_notifications)) => AnyResult::Ok(()), // Quit if PN is turned off }; if r.is_err() { log::debug!("Issue with push notifier: {r:?}"); @@ -140,7 +136,6 @@ impl NeoReactor { } } => v, }; - log::debug!("Push notifier ended: {r:?}"); r }); diff --git a/src/common/streamthread.rs b/src/common/streamthread.rs index 1d86419..a0347ef 100644 --- a/src/common/streamthread.rs +++ b/src/common/streamthread.rs @@ -185,7 +185,6 @@ impl NeoCamStreamThread { impl Drop for NeoCamStreamThread { fn drop(&mut self) { - log::debug!("NeoCamStreamThread::drop Cancel"); self.cancel.cancel(); for stream in self.streams.values() { stream.cancel.cancel() @@ -422,7 +421,6 @@ impl StreamData { // // This should stop one branch of the select from waking the other // too often - let watchdog_print_name = print_name.clone(); tokio::task::spawn(async move { let mut check_timeout = timeout(Duration::from_secs(15), watchdog_rx.recv()).await; // Wait longer for the first feed loop { @@ -430,15 +428,12 @@ impl StreamData { Err(_) => { // Timeout // Break with Ok to trigger the restart - log::debug!("{watchdog_print_name}: Watchdog kicking the stream"); break; }, Ok(None) => { - log::debug!("{watchdog_print_name}: Watchdog dropped the stream"); break; } Ok(_) => { - // log::debug!("{print_name}: Good Doggo"); check_timeout = timeout(Duration::from_secs(10), watchdog_rx.recv()).await; } } @@ -450,12 +445,10 @@ impl StreamData { tokio::select! { v = thread_inuse.dropped_users() => { // Handles the stop and restart when no active users - log::debug!("{print_name}: Streaming STOP"); permit.deactivate().await?; v?; thread_inuse.aquired_users().await?; // Wait for new users of the stream permit.activate().await?; - log::debug!("{print_name}: Streaming START"); AnyResult::Ok(()) }, _ = watchdog_eat_rx => { @@ -470,9 +463,7 @@ impl StreamData { let aud_history = aud_history.clone(); let watchdog_tx = watchdog_tx.clone(); let fps_table = fps_table.clone(); - let print_name = print_name.clone(); - log::debug!("{print_name}: Running Stream Instance Task"); Box::pin(async move { // use std::io::Write; // let mut file = std::fs::File::create("reference.h264")?; @@ -483,11 +474,8 @@ impl StreamData { let mut prev_ts = Duration::ZERO; let mut stream_data = camera.start_video(name, 0, strict).await?; loop { - log::debug!("{print_name}: Waiting for frame"); let data = stream_data.get_data().await??; - log::debug!("{print_name}: Waiting for Watchdog"); watchdog_tx.send(()).await?; // Feed the watchdog - log::debug!("{print_name}: Got frame"); // Update the stream config with any information match &data { @@ -573,7 +561,6 @@ impl StreamData { match data { BcMedia::Iframe(BcMediaIframe{data, microseconds, ..}) => { prev_ts = Duration::from_micros(microseconds as u64); - // log::debug!("IFrame: {prev_ts:?}"); let d = StampedData{ keyframe: true, data: Arc::new(data), @@ -593,8 +580,6 @@ impl StreamData { }, BcMedia::Pframe(BcMediaPframe{data, microseconds,..}) if recieved_iframe => { prev_ts = Duration::from_micros(microseconds as u64); - // log::debug!("PFrame: {prev_ts:?}"); - // log::debug!("data: {data:02X?}"); let d = StampedData{ keyframe: false, data: Arc::new(data), @@ -611,7 +596,6 @@ impl StreamData { log::trace!("Sent Vid Frame"); } BcMedia::Aac(BcMediaAac{data, ..}) | BcMedia::Adpcm(BcMediaAdpcm{data,..}) if recieved_iframe => { - // log::debug!("Audio: {prev_ts:?}"); let d = StampedData{ keyframe: aud_keyframe, data: Arc::new(data), @@ -654,7 +638,6 @@ impl StreamData { } } => v, }; - log::debug!("{print_name}: Stream Thead Stopped: {:?}", r); r })); @@ -662,7 +645,6 @@ impl StreamData { } async fn shutdown(&mut self) -> Result<()> { - log::debug!("StreamData::shutdown Cancel"); self.cancel.cancel(); if let Some(handle) = self.handle.take() { let _ = handle.await; diff --git a/src/mqtt/mod.rs b/src/mqtt/mod.rs index 6b11343..915548e 100644 --- a/src/mqtt/mod.rs +++ b/src/mqtt/mod.rs @@ -150,7 +150,6 @@ pub(crate) async fn main(_: Opt, reactor: NeoReactor) -> Result<()> { if let Ok(()) = &r { break r } else { - log::debug!("listen_on_camera stopped: {:?}", r); continue; } } @@ -160,7 +159,6 @@ pub(crate) async fn main(_: Opt, reactor: NeoReactor) -> Result<()> { for (running_name, token) in cameras.iter() { if ! config_names.contains(running_name) { - log::debug!("Mqtt::main Cancel"); token.cancel(); } } @@ -329,7 +327,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R tokio::select!{ _ = cancel_msg.cancelled() => AnyResult::Ok(()), v = async { - // log::debug!("Got message: {msg:?}"); let res = handle_mqtt_message(msg, &mqtt_msg, &camera_msg).await; if res.is_err() { tx.send(res).await?; @@ -339,14 +336,11 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R } }); } - log::debug!("STOPPED Listening to message on {}", mqtt_msg.get_name()); AnyResult::Ok(()) } => { - log::debug!("MQTT Command Returned: {v:?}"); v }, v = rx.recv() => { - log::debug!("MQTT Task Returned: {v:?}"); v.ok_or(anyhow!("All error senders were dropped"))? }, }?; @@ -370,7 +364,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R })?; } } => { - log::debug!("CamConnection returned: {v:?}"); v }, // Handle the floodlight @@ -413,7 +406,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R AnyResult::Ok(()) } => v, }; - log::debug!("Flood light returned: {v:?}"); match v.map_err(|e| e.downcast::()) { Err(Ok(neolink_core::Error::UnintelligibleReply{..})) => futures::future::pending().await, Ok(()) => AnyResult::Ok(()), @@ -441,7 +433,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R })?; AnyResult::Ok(()) }.await; - log::debug!("Motion returned: {v:?}"); match v.map_err(|e| e.downcast::()) { Err(Ok(neolink_core::Error::UnintelligibleReply{..})) => futures::future::pending().await, Ok(()) => AnyResult::Ok(()), @@ -485,7 +476,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R } AnyResult::Ok(()) }.await; - log::debug!("Snap returned: {v:?}"); match v.map_err(|e| e.downcast::()) { Err(Ok(neolink_core::Error::UnintelligibleReply{..})) => futures::future::pending().await, Ok(()) => AnyResult::Ok(()), @@ -530,7 +520,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R } AnyResult::Ok(()) }.await; - log::debug!("Battery returned: {v:?}"); match v.map_err(|e| e.downcast::()) { Err(Ok(neolink_core::Error::UnintelligibleReply{..})) => futures::future::pending().await, Ok(()) => AnyResult::Ok(()), @@ -554,7 +543,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R prev_noti = noti; AnyResult::Ok(()) }.await; - log::debug!("PushNoti returned: {v:?}"); match v.map_err(|e| e.downcast::()) { Err(Ok(neolink_core::Error::UnintelligibleReply{..})) => futures::future::pending().await, Ok(()) => AnyResult::Ok(()), @@ -608,7 +596,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R }; }; - log::debug!("Mqtt::listen_on_camera Cancel: {r:?}"); drop(drop_cancel); r?; Ok(()) @@ -1057,10 +1044,8 @@ async fn handle_mqtt_message( .run_task(|_cam| Box::pin(async move { AnyResult::Ok(()) })) .await; - log::debug!("Wakeup counting down"); sleep(Duration::from_secs(secs * 60)).await; - log::debug!("Wakeup complete"); drop(permit); }); "OK" diff --git a/src/rtsp/factory.rs b/src/rtsp/factory.rs index bfc6c68..fb95649 100644 --- a/src/rtsp/factory.rs +++ b/src/rtsp/factory.rs @@ -114,7 +114,6 @@ fn clear_bin(bin: &Element) -> Result<()> { .dynamic_cast::() .map_err(|_| anyhow!("Media source's element should be a bin"))?; // Clear the autogenerated ones - log::debug!("Clearing old elements"); for element in bin.iterate_elements().into_iter().flatten() { bin.remove(&element)?; } @@ -158,7 +157,6 @@ fn build_unknown(bin: &Element, pattern: &str) -> Result<()> { fn build_h264(bin: &Element, stream_config: &StreamConfig) -> Result { let buffer_size = buffer_size(stream_config.bitrate); - log::debug!("buffer_size: {buffer_size}"); let bin = bin .clone() .dynamic_cast::() @@ -194,7 +192,6 @@ fn build_h264(bin: &Element, stream_config: &StreamConfig) -> Result { fn build_h265(bin: &Element, stream_config: &StreamConfig) -> Result { let buffer_size = buffer_size(stream_config.bitrate); - log::debug!("buffer_size: {buffer_size}"); let bin = bin .clone() .dynamic_cast::() @@ -229,7 +226,6 @@ fn build_h265(bin: &Element, stream_config: &StreamConfig) -> Result { fn build_aac(bin: &Element, stream_config: &StreamConfig) -> Result { let buffer_size = buffer_size(stream_config.bitrate); - log::debug!("buffer_size: {buffer_size}"); let bin = bin .clone() .dynamic_cast::() @@ -295,7 +291,6 @@ fn build_aac(bin: &Element, stream_config: &StreamConfig) -> Result { fn build_adpcm(bin: &Element, block_size: u32, stream_config: &StreamConfig) -> Result { let buffer_size = buffer_size(stream_config.bitrate); - log::debug!("buffer_size: {buffer_size}"); let bin = bin .clone() .dynamic_cast::() diff --git a/src/rtsp/mod.rs b/src/rtsp/mod.rs index 1d5bf43..88d1702 100644 --- a/src/rtsp/mod.rs +++ b/src/rtsp/mod.rs @@ -186,7 +186,6 @@ pub(crate) async fn main(_opt: Opt, reactor: NeoReactor) -> Result<()> { for (running_name, token) in cameras.iter() { if ! config_names.contains(running_name) { - log::debug!("Rtsp::main Cancel!"); token.cancel(); } } @@ -217,7 +216,6 @@ pub(crate) async fn main(_opt: Opt, reactor: NeoReactor) -> Result<()> { // Panicked or error in task // Cancel all and await terminate log::error!("Error: {e}"); - log::debug!("Rtsp::main Cancel2"); global_cancel.cancel(); rtsp.quit().await?; } @@ -291,8 +289,6 @@ async fn camera_main(camera: NeoInstance, rtsp: &NeoRtspServer) -> Result<()> { AnyResult::Ok(()) }); - log::debug!("{name}: Camera Main::Loop"); - let mut camera_config = camera.config().await?.clone(); loop { let prev_stream_config = camera_config.borrow_and_update().stream; @@ -316,7 +312,6 @@ async fn camera_main(camera: NeoInstance, rtsp: &NeoRtspServer) -> Result<()> { }, v = async { // This select handles enabling the right stream - log::debug!("{name}: Camera Main::Select Stream"); // and setting up the users let all_users = rtsp.get_users().await?.iter().filter(|a| *a != "anyone" && *a != "anonymous").cloned().collect::>(); let permitted_users: HashSet = match &prev_stream_users { @@ -340,7 +335,6 @@ async fn camera_main(camera: NeoInstance, rtsp: &NeoRtspServer) -> Result<()> { let mut supported_streams_3 = supported_streams.clone(); tokio::select! { v = async { - log::debug!("{name}: Camera Main::Select Main"); let name = camera.config().await?.borrow().name.clone(); let mut paths = vec![ format!("/{name}/main"), @@ -371,7 +365,6 @@ async fn camera_main(camera: NeoInstance, rtsp: &NeoRtspServer) -> Result<()> { stream_main(camera.stream(StreamKind::Main).await?, camera.clone(), rtsp, &permitted_users, &paths).await }, if active_streams.contains(&StreamKind::Main) => v, v = async { - log::debug!("{name}: Camera Main::Select Sub"); let name = camera.config().await?.borrow().name.clone(); let mut paths = vec![ format!("/{name}/sub"), @@ -406,7 +399,6 @@ async fn camera_main(camera: NeoInstance, rtsp: &NeoRtspServer) -> Result<()> { stream_main(camera.stream(StreamKind::Sub).await?,camera.clone(), rtsp, &permitted_users, &paths).await }, if active_streams.contains(&StreamKind::Sub) => v, v = async { - log::debug!("{name}: Camera Main::Select Extern"); let name = camera.config().await?.borrow().name.clone(); let mut paths = vec![ format!("/{name}/extern"), diff --git a/src/rtsp/stream.rs b/src/rtsp/stream.rs index 2dbd93f..ec32996 100644 --- a/src/rtsp/stream.rs +++ b/src/rtsp/stream.rs @@ -43,27 +43,18 @@ pub(super) async fn stream_main( let this_loop_cancel = CancellationToken::new(); let _drop_guard = this_loop_cancel.clone().drop_guard(); - log::debug!("{}: Activating Stream", &name); stream_instance.activate().await?; // Wait for a valid stream format to be detected - log::debug!("{}: Waiting for Valid Stream", &name); stream_instance .config - .wait_for(|config| { - log::debug!("{:?}", config); - config.vid_ready() - }) + .wait_for(|config| config.vid_ready()) .await?; - log::debug!("{}: Waiting for Valid Audio", &name); // After vid give it 1s to look for audio // Ignore timeout but check err if let Ok(v) = tokio::time::timeout( Duration::from_secs(1), - stream_instance.config.wait_for(|config| { - log::debug!("{:?}", config); - config.aud_ready() - }), + stream_instance.config.wait_for(|config| config.aud_ready()), ) .await { @@ -83,7 +74,6 @@ pub(super) async fn stream_main( let pause_affector_tx = Arc::new(pause_affector_tx); let mut set = JoinSet::>::new(); - log::debug!("{}: Creating Client Counters", &name); // Handles the on off of the stream with the client pause let client_counter = UseCounter::new().await; let client_count = client_counter.create_deactivated().await?; @@ -98,7 +88,6 @@ pub(super) async fn stream_main( tokio::select! { _ = cancel.cancelled() => AnyResult::Ok(()), v = async { - log::debug!("{}: Activating Client Pause", thread_name); loop { client_count.aquired_users().await?; log::info!("{}: Enabling Client", thread_name); @@ -130,7 +119,6 @@ pub(super) async fn stream_main( tokio::select! { _ = cancel.cancelled() => AnyResult::Ok(()), v = async { - log::debug!("{}: Activating Motion Pause", &thread_name); loop { motion .wait_for(|md| matches!(md, crate::common::MdState::Start(_))) @@ -155,7 +143,6 @@ pub(super) async fn stream_main( }); // Push notfications - log::debug!("{}: Activating Push Notification Pause", &name); let mut pn = camera.push_notifications().await?; let mut curr_pn = None; let thread_name = name.clone(); @@ -260,14 +247,12 @@ pub(super) async fn stream_main( let cancel = this_loop_cancel.clone(); let counter = client_counter.create_deactivated().await?; let mut cur_count = 0; - let thread_name = name.clone(); set.spawn(async move { tokio::select! { _ = cancel.cancelled() => AnyResult::Ok(()), v = async { loop { cur_count = *counter.get_counter().wait_for(|v| v != &cur_count).await?; - log::debug!("{thread_name}: Number of rtsp clients: {cur_count}"); } } => v, } @@ -275,7 +260,6 @@ pub(super) async fn stream_main( // This runs the actual stream. // The select will restart if the stream's config updates - log::debug!("{}: Stream Activated", &name); break tokio::select! { v = thread_stream_config.wait_for(|new_conf| new_conf != &last_stream_config) => { let v = v?; @@ -330,7 +314,6 @@ async fn stream_run( let mut set = JoinSet::new(); // Wait for new media client data to come in from the factory while let Some(mut client_data) = client_rx.recv().await { - log::debug!("New media"); // New media created let vid = client_data.vid.take().map(|data| data.app); let aud = client_data.aud.take().map(|data| data.app); @@ -429,7 +412,6 @@ async fn stream_run( let thread_vid = vid.clone(); let mut thread_client_count = client_count.subscribe(); let thread_format = stream_config.vid_format; - log::debug!("stream_config.fps: {}", stream_config.fps); // let fallback_time = Duration::from_secs(3); let framerate = Duration::from_millis(1000u64 / std::cmp::max(stream_config.fps as u64, 5u64)); @@ -459,7 +441,6 @@ async fn stream_run( }; drop(thread_client_count); let _ = thread_vid.end_of_stream(); - log::debug!("Vid Thread End: {:?}", r); r }); } @@ -489,12 +470,10 @@ async fn stream_run( }, }; let _ = thread_aud.end_of_stream(); - log::debug!("Aud Thread End: {:?}", r); r }); } } - log::debug!("Cleaning up streams"); // At this point the factory has been destroyed // Cancel any remaining threads that are trying to send data // Although it should be finished already when the appsrcs are dropped @@ -506,7 +485,6 @@ async fn stream_run( } fn check_live(app: &AppSrc) -> Result<()> { - // log::debug!("Checking Live: {:?}", app.bus()); app.bus().ok_or(anyhow!("App source is closed"))?; app.pads() .iter() @@ -518,11 +496,8 @@ fn check_live(app: &AppSrc) -> Result<()> { fn get_runtime(app: &AppSrc) -> Option { if let Some(clock) = app.clock() { if let Some(time) = clock.time() { - // log::debug!("time: {time:?}"); if let Some(base_time) = app.base_time() { - // log::debug!("base_time: {base_time:?}"); let runtime = time.saturating_sub(base_time); - // log::debug!("runtime: {runtime:?}"); return Some(Duration::from_micros(runtime.useconds())); } } @@ -560,11 +535,9 @@ fn hold_stream> + Unpin>( if let Ok(frame) = frame { if frame.keyframe { // Release - // log::debug!("Yielding: {}", held_frames.len()); for held_frame in held_frames.drain(..) { yield Ok(held_frame); } - // log::debug!("Yielded"); yield Ok(frame); } else { // Hold @@ -589,7 +562,6 @@ fn ensure_order> + Unpin>( // Buffer until keyframe and reorder let mut reorder_buffer = vec![]; while frame_buffer.last().is_some_and(|v| v.ts > frame.ts) { - log::debug!("Reorder: {:?}", frame.ts); reorder_buffer.push(frame_buffer.pop().unwrap()); } frame_buffer.push(frame); @@ -642,7 +614,7 @@ fn h264_filler(size: usize) -> Vec { buf } -/// Takes a stream and pads it with filler blocks up to 4kb in h265 format +/// Takes a stream and pads it with filler blocks up to 4kb in h265 or h264 format fn pad_vid> + Unpin>( mut stream: T, format: VidFormat, @@ -700,7 +672,6 @@ fn repeat_keyframe> + Unpin>( while let Some(frame) = stream.next().await { if let Ok(frame) = frame { if frame.keyframe { - // log::debug!("Key Frame"); let repeater = frame.clone(); yield Ok(frame); @@ -712,7 +683,6 @@ fn repeat_keyframe> + Unpin>( if let Some(frame) = v { if let Ok(frame) = frame { if was_repeating { - log::debug!("Key Frame: Resume"); was_repeating = false; } yield Ok(frame); @@ -725,7 +695,6 @@ fn repeat_keyframe> + Unpin>( _ = sleep(fallback_time) => { if !was_repeating { // This way we only print once - log::debug!("Inserting Skip Frames"); was_repeating = true; } fallback_time = frame_rate; @@ -787,7 +756,6 @@ async fn send_to_appsrc> + Unpin>( // let mut gst_buf = gstreamer::Buffer::with_size(data.data.len()).unwrap(); { let gst_buf_mut = gst_buf.get_mut().unwrap(); - // log::debug!("Setting PTS: {ts:?}, Runtime: {ts:?}"); let time = ClockTime::from_useconds(rt.as_micros() as u64); gst_buf_mut.set_dts(ClockTime::from_useconds(dts)); dts += 1;