From: Kostya Shishkov Date: Tue, 6 Aug 2024 16:09:47 +0000 (+0200) Subject: h264: koda X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=25f6045bcf6624e5175c46373c7356fd365f48e4;p=nihav.git h264: koda --- diff --git a/nihav-itu/src/codecs/h264/decoder_mt.rs b/nihav-itu/src/codecs/h264/decoder_mt.rs index cdddfec..6ffb446 100644 --- a/nihav-itu/src/codecs/h264/decoder_mt.rs +++ b/nihav-itu/src/codecs/h264/decoder_mt.rs @@ -489,6 +489,8 @@ struct H264MTDecoder { max_last_poc: u32, poc_base: u32, avg_pool: NAVideoBufferPool, + disp_w: usize, + disp_h: usize, } impl H264MTDecoder { @@ -509,6 +511,8 @@ impl H264MTDecoder { max_last_poc: 0, poc_base: 0, avg_pool: NAVideoBufferPool::new(8), + disp_w: 0, + disp_h: 0, } } fn handle_nal(&mut self, src: Vec, supp: &mut NADecoderSupport, skip_decoding: bool, user_id: u32, time: NATimeInfo) -> DecoderResult<()> { @@ -597,7 +601,12 @@ impl H264MTDecoder { } let cur_vinfo = supp.pool_u8.get_info(); - let tmp_vinfo = NAVideoInfo::new(width, height, false, YUV420_FORMAT); + let (w, h) = if ((self.disp_w + 15) & !15) == width && ((self.disp_h + 15) & !15) == height { + (self.disp_w, self.disp_h) + } else { + (width, height) + }; + let tmp_vinfo = NAVideoInfo::new(w, h, false, YUV420_FORMAT); if cur_vinfo != Some(tmp_vinfo) { supp.pool_u8.reset(); supp.pool_u8.prealloc_video(tmp_vinfo, 4)?; @@ -796,6 +805,8 @@ impl NADecoderMT for H264MTDecoder { let mut width = vinfo.get_width(); let mut height = vinfo.get_height(); + self.disp_w = width; + self.disp_h = height; if (width == 0 || height == 0) && !self.sps.is_empty() { width = self.sps[0].pic_width_in_mbs * 16; diff --git a/nihav-itu/src/codecs/h264/decoder_st.rs b/nihav-itu/src/codecs/h264/decoder_st.rs index fad0dd9..4cb4e92 100644 --- a/nihav-itu/src/codecs/h264/decoder_st.rs +++ b/nihav-itu/src/codecs/h264/decoder_st.rs @@ -9,6 +9,8 @@ struct H264Decoder { info: NACodecInfoRef, width: usize, height: usize, + disp_w: usize, + disp_h: usize, num_mbs: usize, nal_len: u8, sps: Vec>, @@ -51,6 +53,8 @@ impl H264Decoder { info: NACodecInfoRef::default(), width: 0, height: 0, + disp_w: 0, + disp_h: 0, num_mbs: 0, nal_len: 0, sps: Vec::with_capacity(1), @@ -189,7 +193,12 @@ println!("PAFF?"); if ret.is_none() { return Err(DecoderError::AllocError); } - let tmp_vinfo = NAVideoInfo::new(self.width, self.height, false, YUV420_FORMAT); + let (w, h) = if ((self.disp_w + 15) & !15) == self.width && ((self.disp_h + 15) & !15) == self.height { + (self.disp_w, self.disp_h) + } else { + (self.width, self.height) + }; + let tmp_vinfo = NAVideoInfo::new(w, h, false, YUV420_FORMAT); let mut buf = ret.unwrap(); if buf.get_info() != tmp_vinfo { supp.pool_u8.reset(); @@ -783,6 +792,8 @@ impl NADecoder for H264Decoder { self.width = vinfo.get_width(); self.height = vinfo.get_height(); + self.disp_w = self.width; + self.disp_h = self.height; if (self.width == 0 || self.height == 0) && !self.sps.is_empty() { self.width = self.sps[0].pic_width_in_mbs * 16;