From 3cdd75b2447731f6b7c84e314aab441eeb75a438 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Thu, 19 Oct 2023 11:22:20 +0700 Subject: [PATCH] More debug print for stream restarts --- src/common/camthread.rs | 1 - src/common/streamthread.rs | 42 ++++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/common/camthread.rs b/src/common/camthread.rs index 0bad577..0b74898 100644 --- a/src/common/camthread.rs +++ b/src/common/camthread.rs @@ -1,4 +1,3 @@ -use anyhow::Context; use std::sync::{Arc, Weak}; use tokio::{ sync::watch::{Receiver as WatchReceiver, Sender as WatchSender}, diff --git a/src/common/streamthread.rs b/src/common/streamthread.rs index 63a81a6..34a4c0e 100644 --- a/src/common/streamthread.rs +++ b/src/common/streamthread.rs @@ -384,6 +384,8 @@ impl StreamData { let aud = me.aud.clone(); let instance = me.instance.subscribe().await?; let name = me.name; + let cam_name = instance.config().await?.borrow().name.clone(); + let print_name = format!("{cam_name}::{name}"); let strict = me.strict; let config = me.config.clone(); let thread_inuse = me.users.create_deactivated().await?; @@ -401,25 +403,35 @@ impl StreamData { tokio::select! { v = thread_inuse.dropped_users() => { // Handles the stop and restart when no active users - log::debug!("Streaming STOP"); + 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!("Streaming START"); + log::debug!("{print_name}: Streaming START"); AnyResult::Ok(()) }, v = async { - let mut check_timeout = timeout(Duration::from_secs(15), watchdog_rx.recv()).await; // Wait lonfer for the first feed + let mut check_timeout = timeout(Duration::from_secs(15), watchdog_rx.recv()).await; // Wait longer for the first feed loop { - if let Err(_)| Ok(None) = check_timeout { - // Timeout - // Reply with Ok to trigger the restart - log::debug!("Watchdog kicking the stream"); - sleep(Duration::from_secs(1)).await; - break AnyResult::Ok(()); + match check_timeout { + Err(_) => { + // Timeout + // Break with Ok to trigger the restart + log::debug!("{print_name}: Watchdog kicking the stream"); + sleep(Duration::from_secs(1)).await; + break AnyResult::Ok(()); + }, + Ok(None) => { + log::debug!("{print_name}: Watchdog dropped the stream"); + sleep(Duration::from_secs(1)).await; + break AnyResult::Ok(()); + } + Ok(_) => { + log::debug!("{print_name}: Good Doggo"); + check_timeout = timeout(Duration::from_secs(4), watchdog_rx.recv()).await; + } } - check_timeout = timeout(Duration::from_secs(4), watchdog_rx.recv()).await; } } => v, result = instance.run_passive_task(|camera| { @@ -431,7 +443,7 @@ impl StreamData { let watchdog_tx = watchdog_tx.clone(); let fps_table = fps_table.clone(); - log::debug!("Running Stream Instance Task"); + 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")?; @@ -594,15 +606,15 @@ impl StreamData { }) => { match result { Ok(AnyResult::Ok(())) => { - log::debug!("Video Stream Stopped due to no listeners"); + log::debug!("{print_name}: Video Stream Stopped due to no listeners"); break Ok(()); }, Ok(Err(e)) => { - log::debug!("Video Stream Restarting Due to Error: {:?}", e); + log::debug!("{print_name}: Video Stream Restarting Due to Error: {:?}", e); AnyResult::Ok(()) }, Err(e) => { - log::debug!("Video Stream Stopped Due to Instance Error: {:?}", e); + log::debug!("{print_name}: Video Stream Stopped Due to Instance Error: {:?}", e); break Err(e); }, } @@ -611,7 +623,7 @@ impl StreamData { } } => v, }; - log::debug!("Stream Thead Stopped: {:?}", r); + log::debug!("{print_name}: Stream Thead Stopped: {:?}", r); r }));