]> git.nihav.org Git - nihav.git/commitdiff
h264: koda master
authorKostya Shishkov <kostya.shishkov@gmail.com>
Tue, 6 Aug 2024 16:09:47 +0000 (18:09 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Tue, 6 Aug 2024 16:09:47 +0000 (18:09 +0200)
nihav-itu/src/codecs/h264/decoder_mt.rs
nihav-itu/src/codecs/h264/decoder_st.rs

index cdddfecb8f26213b04fa634945197e63e825d7cc..6ffb446daa84f2859cb12efa0210691a9b8c36fe 100644 (file)
@@ -489,6 +489,8 @@ struct H264MTDecoder {
     max_last_poc:   u32,
     poc_base:       u32,
     avg_pool:       NAVideoBufferPool<u8>,
+    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<u8>, 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;
index fad0dd9ac539a9276b74fa65382e79e7a050fe27..4cb4e923a193498511d7c17442c514a0e9bc3209 100644 (file)
@@ -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<Arc<SeqParameterSet>>,
@@ -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;