From e146f9593be446db63349f3707d367a17effb976 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Thu, 18 Apr 2024 18:50:20 +0700 Subject: [PATCH] Reduce history buffer duration --- src/common/streamthread.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/common/streamthread.rs b/src/common/streamthread.rs index ce3656d..5c4eaa0 100644 --- a/src/common/streamthread.rs +++ b/src/common/streamthread.rs @@ -316,11 +316,11 @@ impl StreamInstance { impl StreamData { async fn new(name: StreamKind, instance: NeoInstance, strict: bool) -> Result { - const BUFFER_DURATION: Duration = Duration::from_secs(15); + const BUFFER_DURATION: Duration = Duration::from_secs(3); // At 30fps for 15s with audio is is about 900 frames - // Therefore we set this buffer to a rather large 2000 - let (vid, _) = broadcast::(2000); - let (aud, _) = broadcast::(2000); + const BUFFER_SIZE: usize = 30usize * BUFFER_DURATION.as_millis() as usize / 1000usize; + let (vid, _) = broadcast::(BUFFER_SIZE); + let (aud, _) = broadcast::(BUFFER_SIZE); let (vid_history, _) = watch::>(VecDeque::new()); let vid_history = Arc::new(vid_history); let (aud_history, _) = watch::>(VecDeque::new()); @@ -579,7 +579,7 @@ impl StreamData { let drop_time = d.ts.saturating_sub(BUFFER_DURATION); let dts = d.ts; history.push_back(d); - while history.front().is_some_and(|di| di.ts < drop_time || di.ts > dts) || history.len() > 1000 { + while history.front().is_some_and(|di| di.ts < drop_time || di.ts > dts) || history.len() > BUFFER_SIZE { history.pop_front(); } log::info!("history: {}", history.len()); @@ -602,7 +602,7 @@ impl StreamData { let drop_time = d.ts.saturating_sub(BUFFER_DURATION); let dts = d.ts; history.push_back(d); - while history.front().is_some_and(|di| di.ts < drop_time || di.ts > dts) || history.len() > 1000 { + while history.front().is_some_and(|di| di.ts < drop_time || di.ts > dts) || history.len() > BUFFER_SIZE { history.pop_front(); } }); @@ -621,7 +621,7 @@ impl StreamData { let drop_time = d.ts.saturating_sub(BUFFER_DURATION); let dts = d.ts; history.push_back(d); - while history.front().is_some_and(|di| di.ts < drop_time || di.ts > dts) || history.len() > 1000 { + while history.front().is_some_and(|di| di.ts < drop_time || di.ts > dts) || history.len() > BUFFER_SIZE { history.pop_front(); } });