From 76e804ea6a832f846a168ec253e9d188d466ac55 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Mon, 30 Oct 2023 12:08:50 +0700 Subject: [PATCH] Set missed tick to skip --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- crates/core/Cargo.toml | 2 +- crates/pushnoti/Cargo.toml | 2 +- src/rtsp/stream.rs | 11 ++++++----- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a140e77..029191a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1663,7 +1663,7 @@ dependencies = [ [[package]] name = "neolink" -version = "0.6.3-rc.1" +version = "0.6.3-rc.2" dependencies = [ "anyhow", "async-stream", @@ -1701,7 +1701,7 @@ dependencies = [ [[package]] name = "neolink_core" -version = "0.6.3-rc.1" +version = "0.6.3-rc.2" dependencies = [ "aes", "assert_matches", diff --git a/Cargo.toml b/Cargo.toml index 8be680d..ff39da5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "neolink" description = "A standards-compliant bridge to Reolink IP cameras" -version = "0.6.3-rc.1" +version = "0.6.3-rc.2" authors = ["George Hilliard ", "Andrew King "] edition = "2018" license = "AGPL-3.0-or-later" @@ -31,7 +31,7 @@ heck = "0.4.1" lazy_static = "1.4.0" log = { version = "0.4.17", features = [ "release_max_level_debug" ] } md5 = "0.7.0" -neolink_core = { path = "crates/core", version = "0.6.3-rc.1" } +neolink_core = { path = "crates/core", version = "0.6.3-rc.2" } regex = "1.7.3" rumqttc = "0.22.0" serde = { version = "1.0.160", features = ["derive"] } diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index dadd303..088ee9d 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "neolink_core" description = "Core services and structure for Reolink IP cameras" -version = "0.6.3-rc.1" +version = "0.6.3-rc.2" authors = ["George Hilliard ", "Andrew King "] edition = "2018" license = "AGPL-3.0-or-later" diff --git a/crates/pushnoti/Cargo.toml b/crates/pushnoti/Cargo.toml index c5eabce..6ef1199 100644 --- a/crates/pushnoti/Cargo.toml +++ b/crates/pushnoti/Cargo.toml @@ -12,7 +12,7 @@ env_logger = "0.10.0" fcm-push-listener = "2.0.1" lazy_static = "1.4.0" log = { version = "0.4.17", features = [ "release_max_level_debug" ] } -neolink_core = { path = "../core", version = "0.6.3-rc.1" } +neolink_core = { path = "../core", version = "0.6.3-rc.2" } regex = "1.8.1" serde = "1.0.163" tokio = { version = "1.28.1", features = ["full"] } diff --git a/src/rtsp/stream.rs b/src/rtsp/stream.rs index 22ae832..1f94164 100644 --- a/src/rtsp/stream.rs +++ b/src/rtsp/stream.rs @@ -7,7 +7,7 @@ use std::sync::Arc; use tokio::{ sync::{broadcast::channel as broadcast, watch::channel as watch}, task::JoinSet, - time::{sleep, sleep_until, Duration, Instant}, + time::{interval, sleep, Duration}, }; use tokio_stream::{wrappers::BroadcastStream, Stream, StreamExt}; use tokio_util::sync::CancellationToken; @@ -584,11 +584,11 @@ fn ensure_order> + Unpin>( let mut frame_buffer: Vec = vec![]; while let Some(frame) = stream.next().await { if let Ok(frame) = frame { - if ! frame.keyframe { // 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); @@ -600,6 +600,7 @@ fn ensure_order> + Unpin>( for frame in frame_buffer.drain(..) { yield Ok(frame); } + yield(Ok(frame)); } } } @@ -613,11 +614,11 @@ fn frametime_stream> + Unpin>( expected_frame_rate: Duration, ) -> impl Stream> + Unpin { Box::pin(async_stream::stream! { - let mut last_release = Instant::now(); + let mut waiter = interval(expected_frame_rate); + waiter.set_missed_tick_behavior( tokio::time::MissedTickBehavior::Skip); while let Some(frame) = stream.next().await { if let Ok(frame) = frame { - sleep_until(last_release + expected_frame_rate).await; - last_release += expected_frame_rate; + waiter.tick().await; yield Ok(frame); } }