]> git.nihav.org Git - nihav-encoder.git/commitdiff
improve syncing somewhat
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 14 Feb 2026 04:29:18 +0000 (05:29 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 14 Feb 2026 04:29:18 +0000 (05:29 +0100)
src/transcoder.rs

index f40092bd075d39271167079401410337f118b5b9..0d5ce71506f3bfb6d5b2f89739d847cd73860f09 100644 (file)
@@ -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 {