vp3: codec outputs flipped frames
[nihav.git] / nihav-duck / src / codecs / vp3.rs
index 698d623746d1dcee1990bda9cbb655b54bdb9c5f..c363d9770f41cf230cf43769d0d7acb90a96a0fd 100644 (file)
@@ -542,55 +542,6 @@ macro_rules! fill_dc_pred {
     };
 }
 
-fn vp3_interp00(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw: usize, bh: usize)
-{
-    let mut didx = 0;
-    let mut sidx = 0;
-    for _ in 0..bh {
-        for x in 0..bw { dst[didx + x] = src[sidx + x]; }
-        didx += dstride;
-        sidx += sstride;
-    }
-}
-
-fn vp3_interp01(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw: usize, bh: usize)
-{
-    let mut didx = 0;
-    let mut sidx = 0;
-    for _ in 0..bh {
-        for x in 0..bw { dst[didx + x] = (((src[sidx + x] as u16) + (src[sidx + x + 1] as u16)) >> 1) as u8; }
-        didx += dstride;
-        sidx += sstride;
-    }
-}
-
-fn vp3_interp10(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw: usize, bh: usize)
-{
-    let mut didx = 0;
-    let mut sidx = 0;
-    for _ in 0..bh {
-        for x in 0..bw { dst[didx + x] = (((src[sidx + x] as u16) + (src[sidx + x + sstride] as u16)) >> 1) as u8; }
-        didx += dstride;
-        sidx += sstride;
-    }
-}
-
-fn vp3_interp11(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw: usize, bh: usize)
-{
-    let mut didx = 0;
-    let mut sidx = 0;
-    for _ in 0..bh {
-        for x in 0..bw {
-            dst[didx + x] = (((src[sidx + x] as u16) +
-                              (src[sidx + x + 1] as u16) +
-                              (src[sidx + x + sstride] as u16) +
-                              (src[sidx + x + sstride + 1] as u16)) >> 2) as u8;
-        }
-        didx += dstride;
-        sidx += sstride;
-    }
-}
-
 fn vp31_loop_filter_v(frm: &mut NASimpleVideoFrame<u8>, x: usize, y: usize, plane: usize, loop_str: i16) {
     let off = frm.offset[plane] + x + y * frm.stride[plane];
     vp31_loop_filter(frm.data, off, 1, frm.stride[plane], 8, loop_str);
@@ -601,8 +552,6 @@ fn vp31_loop_filter_h(frm: &mut NASimpleVideoFrame<u8>, x: usize, y: usize, plan
     vp31_loop_filter(frm.data, off, frm.stride[plane], 1, 8, loop_str);
 }
 
-pub const VP3_INTERP_FUNCS: &[blockdsp::BlkInterpFunc] = &[ vp3_interp00, vp3_interp01, vp3_interp10, vp3_interp11 ];
-
 impl VP34Decoder {
     fn new(version: u8) -> Self {
         let vt = alloc_video_buffer(NAVideoInfo::new(24, 24, false, YUV420_FORMAT), 4).unwrap();
@@ -1845,7 +1794,7 @@ impl NADecoder for VP34Decoder {
             let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), true, fmt));
             self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref();
             supp.pool_u8.set_dec_bufs(3);
-            supp.pool_u8.prealloc_video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, fmt), 4)?;
+            supp.pool_u8.prealloc_video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), true, fmt), 4)?;
 
             self.generate_block_addr();
             if self.version == 4 {
@@ -1865,6 +1814,10 @@ impl NADecoder for VP34Decoder {
         self.parse_header(&mut br)?;
         if self.is_intra {
             self.shuf.clear();
+        } else {
+            if !self.shuf.has_refs() {
+                return Err(DecoderError::MissingReference);
+            }
         }
 
         let ret = supp.pool_u8.get_free();
@@ -1890,13 +1843,16 @@ impl NADecoder for VP34Decoder {
         frm.set_frame_type(if self.is_intra { FrameType::I } else { FrameType::P });
         Ok(frm.into_ref())
     }
+    fn flush(&mut self) {
+        self.shuf.clear();
+    }
 }
 
-pub fn get_decoder_vp3() -> Box<NADecoder> {
+pub fn get_decoder_vp3() -> Box<NADecoder + Send> {
     Box::new(VP34Decoder::new(3))
 }
 
-pub fn get_decoder_vp4() -> Box<NADecoder> {
+pub fn get_decoder_vp4() -> Box<NADecoder + Send> {
     Box::new(VP34Decoder::new(4))
 }
 
@@ -2048,17 +2004,6 @@ const VP3_QMAT_INTER: &[i16; 64] = &[
     40,  48,  64,  64,  64,  96, 128, 128
 ];
 
-const ZIGZAG: [usize; 64] = [
-     0,  1,  8, 16,  9,  2,  3, 10,
-    17, 24, 32, 25, 18, 11,  4,  5,
-    12, 19, 26, 33, 40, 48, 41, 34,
-    27, 20, 13,  6,  7, 14, 21, 28,
-    35, 42, 49, 56, 57, 50, 43, 36,
-    29, 22, 15, 23, 30, 37, 44, 51,
-    58, 59, 52, 45, 38, 31, 39, 46,
-    53, 60, 61, 54, 47, 55, 62, 63
-];
-
 const VP31_DC_CODES: [[u16; 32]; 16] = [
   [
     0x002D, 0x0026, 0x0166, 0x004E, 0x02CE, 0x059E, 0x027D, 0x0008,