From f3587bafe47778c9fe50f8da18331ac7747c88cc Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Wed, 11 Oct 2023 09:42:40 +0700 Subject: [PATCH] Full debug logs on tasks error messages --- src/common/instance.rs | 34 ++++++++++++++++++++++++---------- src/rtsp/stream.rs | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 53 insertions(+), 20 deletions(-) diff --git a/src/common/instance.rs b/src/common/instance.rs index a310ac1..a3010ce 100644 --- a/src/common/instance.rs +++ b/src/common/instance.rs @@ -61,12 +61,12 @@ impl NeoInstance { /// - If the camera instance is changed: Rerun the task with the new instance /// - If the camera returns a retryable error, wait for camera instance to change then rerun /// - else return the result of the function - pub(crate) async fn run_task(&self, task: F) -> Result + pub(crate) async fn run_task(&self, task: F) -> AnyResult where F: for<'a> Fn( &'a BcCamera, ) - -> std::pin::Pin> + Send + 'a>>, + -> std::pin::Pin> + Send + 'a>>, { let _permit = self.permit().await?; self.run_passive_task(task).await @@ -85,12 +85,12 @@ impl NeoInstance { /// background tasks that we want to stop during certain times like low battery /// /// The streams and MD use this - pub(crate) async fn run_passive_task(&self, task: F) -> Result + pub(crate) async fn run_passive_task(&self, task: F) -> AnyResult where F: for<'a> Fn( &'a BcCamera, ) - -> std::pin::Pin> + Send + 'a>>, + -> std::pin::Pin> + Send + 'a>>, { let mut camera_watch = self.camera_watch.clone(); let mut camera = None; @@ -116,7 +116,11 @@ impl NeoInstance { v = async { if let Some(cam) = camera.clone() { let cam_ref = cam.as_ref(); - task(cam_ref).await + let r = task(cam_ref).await; + if let Err(e) = &r { + log::debug!("- Task Result: {e:?}"); + } + r } else { unreachable!() } @@ -129,13 +133,15 @@ impl NeoInstance { match e.downcast::() { // Retry is a None Ok(neolink_core::Error::DroppedConnection) | Ok(neolink_core::Error::TimeoutDisconnected) => { + log::debug!(" - Neolink error continue"); continue; }, Ok(neolink_core::Error::Io(e)) => { - log::debug!("Std IO Error"); + 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"); continue; } else { // Check if the inner error is the Other type and then the discomnect @@ -147,23 +153,29 @@ impl NeoInstance { }); if is_dropped { // Retry is a None + log::debug!(" - Neolink Std IO Error => Neolink: Continue"); continue; } else { + log::debug!(" - Neolink Std IO Error: Other"); Err(e.into()) } } } - Ok(e) => Err(e.into()), + Ok(e) => { + log::debug!(" - Neolink Error: Other"); + Err(e.into()) + }, Err(e) => { // Check if it is an io error - log::debug!("Other Error: {:?}", e); + log::debug!(" - Other Error: {:?}", e); match e.downcast::() { Ok(e) => { - log::debug!("Std IO Error"); + log::debug!(" - 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"); continue; } else { let is_dropped = e.get_ref().is_some_and(|e| { @@ -174,14 +186,16 @@ impl NeoInstance { }); if is_dropped { // Retry is a None + log::debug!(" - Std IO Error => Neolink Error: Continue"); continue; } else { + log::debug!(" - Std IO Error: Other"); Err(e.into()) } } }, Err(e) => { - log::debug!("Other Error: {:?}", e); + log::debug!(" - Other Error: {:?}", e); Err(e) } } diff --git a/src/rtsp/stream.rs b/src/rtsp/stream.rs index 556e23f..5d1c67a 100644 --- a/src/rtsp/stream.rs +++ b/src/rtsp/stream.rs @@ -314,10 +314,19 @@ async fn stream_run( _ = thread_stream_cancel.cancelled() => AnyResult::Ok(()), v = async { // Send Initial - for data in thread_vid_history.borrow().iter() { - thread_vid_data_tx.send( - data.clone() - )?; + { + let history = thread_vid_history.borrow(); + let last_ts = history.back().map(|s| s.ts); + for data in history.iter() { + thread_vid_data_tx.send( + StampedData { + keyframe: data.keyframe, + data: data.data.clone(), + ts: last_ts.unwrap() + } + + )?; + } } // Send new @@ -345,10 +354,19 @@ async fn stream_run( _ = thread_stream_cancel.cancelled() => AnyResult::Ok(()), v = async { // Send Initial - for data in thread_aud_history.borrow().iter() { - thread_aud_data_tx.send( - data.clone() - )?; + { + let history = thread_aud_history.borrow(); + let last_ts = history.back().map(|s| s.ts); + for data in history.iter() { + thread_aud_data_tx.send( + StampedData { + keyframe: data.keyframe, + data: data.data.clone(), + ts: last_ts.unwrap() + } + + )?; + } } // Send new @@ -379,7 +397,7 @@ async fn stream_run( AnyResult::Ok(()) }, v = send_to_appsrc( - // repeat_keyframe( + repeat_keyframe( frametime_stream( hold_stream( wait_for_keyframe( @@ -387,7 +405,8 @@ async fn stream_run( ) ) ), - // Duration::from_secs(1)), + Duration::from_secs(1) + ), &thread_vid) => { v },