From 8bdb8ef1bd33bd14acc9555c15154295bdc075a2 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Thu, 28 Sep 2023 13:00:37 +0700 Subject: [PATCH] Add a counter for the number of clients --- src/common/usecounter.rs | 4 ++++ src/rtsp/mod.rs | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/common/usecounter.rs b/src/common/usecounter.rs index 76e6670..a1f7de0 100644 --- a/src/common/usecounter.rs +++ b/src/common/usecounter.rs @@ -140,6 +140,10 @@ impl Permit { .await?; Ok(()) } + + pub(crate) fn get_counter(&self) -> WatchReceiver { + self.value.clone() + } } impl Drop for Permit { diff --git a/src/rtsp/mod.rs b/src/rtsp/mod.rs index 1978734..b6f90bf 100644 --- a/src/rtsp/mod.rs +++ b/src/rtsp/mod.rs @@ -688,6 +688,17 @@ async fn stream_main( AnyResult::Ok(()) }); + // Task to just report the number of clients for debug purposes + let counter = client_counter.create_deactivated().await?; + let mut cur_count = 0; + let thread_name = name.clone(); + set.spawn(async move { + loop { + cur_count = *counter.get_counter().wait_for(|v| v != &cur_count).await?; + log::debug!("{thread_name}: Number of rtsp clients: {cur_count}"); + } + }); + // This runs the actual stream. // The select will restart if the stream's config updates log::debug!("{}: Stream Activated", &name);