From 2f67d8bbe5c10f600f9178aa3a7c168d38fd351f Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Wed, 8 Apr 2020 10:15:14 +0200 Subject: [PATCH] intel263: correct frame PTS in case of B-frames being present --- nihav-indeo/src/codecs/intel263.rs | 38 +++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/nihav-indeo/src/codecs/intel263.rs b/nihav-indeo/src/codecs/intel263.rs index a1f9f84..42d0380 100644 --- a/nihav-indeo/src/codecs/intel263.rs +++ b/nihav-indeo/src/codecs/intel263.rs @@ -24,6 +24,8 @@ struct Intel263Decoder { dec: H263BaseDecoder, tables: Tables, bdsp: H263BlockDSP, + lastframe: Option, + lastpts: Option, } struct Intel263BR<'a> { @@ -360,6 +362,8 @@ impl Intel263Decoder { dec: H263BaseDecoder::new(true), tables, bdsp: H263BlockDSP::new(), + lastframe: None, + lastpts: None, } } } @@ -381,28 +385,46 @@ impl NADecoder for Intel263Decoder { let src = pkt.get_buffer(); if src.len() == 8 { - let bret = self.dec.get_bframe(&self.bdsp); let buftype; - let is_skip; - if let Ok(btype) = bret { - buftype = btype; - is_skip = false; - } else { + let ftype; + if self.lastframe.is_none() { buftype = NABufferType::None; - is_skip = true; + ftype = FrameType::Skip; + } else { + let mut buf = None; + std::mem::swap(&mut self.lastframe, &mut buf); + buftype = buf.unwrap(); + ftype = FrameType::B; } let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), buftype); frm.set_keyframe(false); - frm.set_frame_type(if is_skip { FrameType::Skip } else { FrameType::B }); + frm.set_frame_type(ftype); + if self.lastpts.is_some() { + frm.set_pts(self.lastpts); + self.lastpts = None; + } return Ok(frm.into_ref()); } let mut ibr = Intel263BR::new(&src, &self.tables); let bufinfo = self.dec.parse_frame(&mut ibr, &self.bdsp)?; + let mut cur_pts = pkt.get_pts(); + if !self.dec.is_intra() { + let bret = self.dec.get_bframe(&self.bdsp); + if let Ok(b_buf) = bret { + self.lastframe = Some(b_buf); + self.lastpts = pkt.get_pts(); + if let Some(pts) = pkt.get_pts() { + cur_pts = Some(pts + 1); + } + } + } + let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), bufinfo); frm.set_keyframe(self.dec.is_intra()); frm.set_frame_type(if self.dec.is_intra() { FrameType::I } else { FrameType::P }); + frm.set_pts(cur_pts); Ok(frm.into_ref()) } fn flush(&mut self) { -- 2.39.5