X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-duck%2Fsrc%2Fcodecs%2Fvp56.rs;h=03bd9fc9b052ec4c9730ca185a3855251d74e93c;hb=138b7d0a1f3baeac9427f194fd9a3f83abb22651;hp=54c84a040a80157331fc7e4ec0effbf19df905d8;hpb=3584b223ce417fe167dc90cb9a40e173f34823c0;p=nihav.git diff --git a/nihav-duck/src/codecs/vp56.rs b/nihav-duck/src/codecs/vp56.rs index 54c84a0..03bd9fc 100644 --- a/nihav-duck/src/codecs/vp56.rs +++ b/nihav-duck/src/codecs/vp56.rs @@ -1,4 +1,5 @@ use nihav_core::codecs::*; +use nihav_core::data::GenericCache; use nihav_core::io::bitreader::*; use super::vpcommon::*; @@ -295,44 +296,6 @@ impl FrameState { } } -pub struct GenericCache { - pub height: usize, - pub stride: usize, - pub xpos: usize, - pub data: Vec, - pub default: T, -} - -impl GenericCache { - fn new(height: usize, stride: usize, default: T) -> Self { - let mut ret = Self { - stride, - height, - xpos: 0, - data: Vec::with_capacity((height + 1) * stride), - default, - }; - ret.reset(); - ret - } - fn full_size(&self) -> usize { self.stride * (self.height + 1) } - fn reset(&mut self) { - self.data.truncate(0); - let size = self.full_size(); - self.data.resize(size, self.default); - self.xpos = self.stride + 1; - } - fn update_row(&mut self) { - for i in 0..self.stride { - self.data[i] = self.data[self.height * self.stride + i]; - } - self.data.truncate(self.stride); - let size = self.full_size(); - self.data.resize(size, self.default); - self.xpos = self.stride + 1; - } -} - pub struct VP56Decoder { version: u8, has_alpha: bool, @@ -381,17 +344,7 @@ fn map_mb_type(mbtype: VPMBType) -> usize { } } -pub const VP56_COEF_BASE: [i16; 6] = [ 5, 7, 11, 19, 35, 67 ]; pub fn expand_token_bc(bc: &mut BoolCoder, val_probs: &[u8; 11], token: u8, version: u8) -> i16 { - const COEF_ADD_PROBS: [[u8; 12]; 6] = [ - [ 159, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], - [ 165, 145, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], - [ 173, 148, 140, 128, 0, 0, 0, 0, 0, 0, 0, 0 ], - [ 176, 155, 140, 135, 128, 0, 0, 0, 0, 0, 0, 0 ], - [ 180, 157, 141, 134, 130, 128, 0, 0, 0, 0, 0, 0 ], - [ 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129, 128 ], - ]; - let mut sign = false; let level; if token < TOKEN_LARGE { @@ -409,7 +362,7 @@ pub fn expand_token_bc(bc: &mut BoolCoder, val_probs: &[u8; 11], token: u8, vers sign = bc.read_bool(); } let mut add = 0i16; - let add_probs = &COEF_ADD_PROBS[cat]; + let add_probs = &VP56_COEF_ADD_PROBS[cat]; for prob in add_probs.iter() { if *prob == 128 { break; } add = (add << 1) | (bc.read_prob(*prob) as i16); @@ -475,6 +428,9 @@ impl VP56Decoder { self.set_dimensions(vinfo.get_width(), vinfo.get_height()); Ok(()) } + pub fn flush(&mut self) { + self.shuf.clear(); + } pub fn decode_frame(&mut self, supp: &mut NADecoderSupport, src: &[u8], br: &mut dyn VP56Parser) -> DecoderResult<(NABufferType, FrameType)> { let aoffset; let mut bc; @@ -514,6 +470,10 @@ impl VP56Decoder { if hdr.is_intra { self.shuf.clear(); + } else { + if !self.shuf.has_refs() { + return Err(DecoderError::MissingReference); + } } let mut cr;