]> git.nihav.org Git - nihav.git/commitdiff
mpeg4asp: set frame reference timestamp when appropriate master
authorKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 2 Apr 2026 04:57:51 +0000 (06:57 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 2 Apr 2026 04:57:51 +0000 (06:57 +0200)
This fixes the situation with the decoder keeping updating old timestamps
after the seek instead of taking new time point into account.

nihav-mpeg/src/codecs/mpeg4asp/decoder.rs
nihav-mpeg/src/codecs/mpeg4asp/mod.rs

index 3cb7d6aecfeb5ddbf45909324f5dd637e4145683..384c739da07bbd7d00b9bd61ad06a4c4cf4059d4 100644 (file)
@@ -247,11 +247,21 @@ impl SequenceContext {
         self.qinfo = vol.quant_info.clone();
         self.vol = Some(vol);
     }
-    pub fn update_ts(&mut self, pic_info: &PicInfo) -> (u64, u64, u64) {
+    pub fn update_ts(&mut self, pic_info: &PicInfo, ref_ts: Option<u64>) -> (u64, u64, u64) {
         match pic_info.pic_type {
             FrameType::I | FrameType::P | FrameType::Skip => {
                 self.bwd_ts = self.fwd_ts;
-                if let Some(ref vol) = self.vol {
+                if pic_info.pic_type == FrameType::I && ref_ts.is_some() {
+                    let ts = ref_ts.unwrap_or(0);
+                    let time_res = u64::from(if let Some(ref vol) = self.vol { vol.time_res } else { 0 });
+                    if time_res > 0 {
+                        self.fwd_ts.base   = (ts / time_res) as u32;
+                        self.fwd_ts.offset = (ts % time_res) as u32;
+                    } else {
+                        self.fwd_ts.offset = ts as u32;
+                    }
+                    (self.fwd_ts.get_ts(time_res as u32), self.bwd_ts.get_ts(time_res as u32), 0)
+                } else if let Some(ref vol) = self.vol {
                     self.fwd_ts.base += pic_info.modulo_time_base;
                     self.fwd_ts.offset = pic_info.vop_time_increment;
                     (self.fwd_ts.get_ts(vol.time_res), self.bwd_ts.get_ts(vol.time_res), 0)
index 8008fb6595811d7c991b91460304f233daa08a1a..288d7f2d63267269c6aeae71a44f787fbaa6d9c9 100644 (file)
@@ -192,7 +192,8 @@ impl NADecoder for ASPDecoder {
                         return Err(DecoderError::NotImplemented);
                     }
                     let (cur_ts, fwd_ts, bwd_ts) = if ftype != FrameType::Skip || !self.pb_mode {
-                            self.seq.update_ts(&pic_info)
+                            let ref_pts = if self.assign_mode == AssignMode::Yes { pkt.ts.pts } else { None };
+                            self.seq.update_ts(&pic_info, ref_pts)
                         } else { (0, 0, 0) };
 
                     if ftype == FrameType::Skip {
@@ -306,6 +307,7 @@ impl NADecoder for ASPDecoder {
     }
     fn flush(&mut self) {
         self.ipbs.clear();
+        self.saved = None;
     }
 }