From 7d83984049e39bb90cf36160721b816316cd1253 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Sat, 14 Feb 2026 05:29:18 +0100 Subject: [PATCH] improve syncing somewhat --- src/transcoder.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/transcoder.rs b/src/transcoder.rs index f40092b..0d5ce71 100644 --- a/src/transcoder.rs +++ b/src/transcoder.rs @@ -305,14 +305,15 @@ impl OutputQueue { if self.sync { let mut all_with_time = true; let mut min_ts = None; + let mut max_ts = None; let mut min_sn = 0; for (streamno, queue) in self.packets.iter().enumerate() { if queue.is_empty() { if !self.had_warning && self.packets.len() > 1 { for q in self.packets.iter() { - if q.len() > 64 { + if q.len() > 1024 { self.had_warning = true; - println!("Too many packets in one of the queues, synchronisation is not possible!"); + println!("Too many packets ({}) in one of the queues, synchronisation is not possible!", q.len()); self.sync = false; break; } @@ -327,6 +328,9 @@ impl OutputQueue { min_ts = Some(millis); min_sn = streamno; } + if max_ts.is_none() || max_ts < Some(millis) { + max_ts = Some(millis); + } } else { all_with_time = false; } @@ -336,6 +340,16 @@ impl OutputQueue { self.sync = false; return self.get_last_packet(); } + if !self.had_warning { + const THR: u64 = 2000; + if let (Some(mints), Some(maxts)) = (min_ts, max_ts) { + if mints + THR < maxts { + println!("Queue times differ more than by {}s, synchronisation is not possible!", THR as f32 / 1000.0); + self.had_warning = true; + self.sync = false; + } + } + } if min_ts.is_some() { self.packets[min_sn].pop_front() } else { -- 2.39.5