]> git.nihav.org Git - nihav-encoder.git/commitdiff
attempt to sync packets when possible
authorKostya Shishkov <kostya.shishkov@gmail.com>
Mon, 17 Mar 2025 17:51:20 +0000 (18:51 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Mon, 17 Mar 2025 17:51:20 +0000 (18:51 +0100)
src/transcoder.rs

index aef00046440266a98863db17984b46af61e99d72..f6fb29ff31ba0c83ce212d9dab8dfff1f57abe66 100644 (file)
@@ -264,7 +264,10 @@ impl OutputQueue {
     }
     pub fn get_packet(&mut self) -> Option<NAPacket> {
         if self.sync {
-            for queue in self.packets.iter() {
+            let mut all_with_time = true;
+            let mut min_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() {
@@ -278,9 +281,22 @@ impl OutputQueue {
                     }
                     return None;
                 }
+                if let Some(pts) = queue[0].ts.pts {
+                    let stream = queue[0].get_stream();
+                    let millis = NATimeInfo::ts_to_time(pts, 1000, stream.tb_num, stream.tb_den);
+                    if min_ts.is_none() || min_ts > Some(millis) {
+                        min_ts = Some(millis);
+                        min_sn = streamno;
+                    }
+                } else {
+                    all_with_time = false;
+                }
+            }
+            if all_with_time && min_ts.is_some() {
+                self.packets[min_sn].pop_front()
+            } else {
+                self.get_last_packet()
             }
-// todo return packet with minimum timestamp
-            self.get_last_packet()
         } else {
             self.get_last_packet()
         }