X-Git-Url: https://git.nihav.org/?p=nihav.git;a=blobdiff_plain;f=nihav-duck%2Fsrc%2Fcodecs%2Fvp7.rs;h=2632b40283baee3f39859da1e1d2c42cb585aeaf;hp=ea423ad26145b2070bd88df7c038eea9620b9a23;hb=78fb6560c73965d834b215fb0b49505ae5443288;hpb=f712521586d85c7f6ab03c7b5b79c460f044a109 diff --git a/nihav-duck/src/codecs/vp7.rs b/nihav-duck/src/codecs/vp7.rs index ea423ad..2632b40 100644 --- a/nihav-duck/src/codecs/vp7.rs +++ b/nihav-duck/src/codecs/vp7.rs @@ -1,6 +1,7 @@ use nihav_core::codecs::*; use nihav_core::io::byteio::*; -use nihav_core::data::GenericCache; +use nihav_codec_support::codecs::{MV, ZERO_MV}; +use nihav_codec_support::data::GenericCache; use super::vpcommon::*; use super::vp7data::*; use super::vp7dsp::*; @@ -142,7 +143,7 @@ struct SBParams<'a> { qmat: &'a [i16; 16], } -fn decode_subblock<'a>(bc: &mut BoolCoder, coeffs: &mut [i16; 16], ctype: usize, pctx: u8, sbparams: &SBParams) -> u8 { +fn decode_subblock(bc: &mut BoolCoder, coeffs: &mut [i16; 16], ctype: usize, pctx: u8, sbparams: &SBParams) -> u8 { const COEF_BANDS: [usize; 16] = [ 0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7 ]; let mut has_nz = 0; @@ -200,8 +201,8 @@ struct DecoderState { force_pitch: Option, has_y2: bool, - pdc_pred_val: i16, - pdc_pred_count: usize, + pdc_pred_val: [i16; 2], + pdc_pred_count: [usize; 2], ipred_ctx_y: IPredContext, ipred_ctx_u: IPredContext, @@ -467,7 +468,7 @@ impl VP7Decoder { } Ok(()) } - fn decode_residue(&mut self, bc: &mut BoolCoder, mb_x: usize, mb_idx: usize) { + fn decode_residue(&mut self, bc: &mut BoolCoder, mb_x: usize, mb_idx: usize, use_last: bool) { let qmat_idx = if let Some(idx) = self.dstate.force_quant { (idx as usize) + 1 } else { 0 }; let mut sbparams = SBParams { scan: &DEFAULT_SCAN_ORDER, @@ -538,21 +539,23 @@ impl VP7Decoder { let y2block = &mut self.coeffs[24]; if self.mb_info[mb_idx].mb_type != VPMBType::Intra { let mut dc = y2block[0]; - let pval = self.dstate.pdc_pred_val; - if self.dstate.pdc_pred_count > 3 { + let pdc_idx = if use_last { 0 } else { 1 }; + let pval = self.dstate.pdc_pred_val[pdc_idx]; + + if self.dstate.pdc_pred_count[pdc_idx] > 3 { dc += pval; y2block[0] = dc; } if (pval == 0) || (dc == 0) || ((pval ^ dc) < 0) { - self.dstate.pdc_pred_count = 0; + self.dstate.pdc_pred_count[pdc_idx] = 0; } else if dc == pval { - self.dstate.pdc_pred_count += 1; + self.dstate.pdc_pred_count[pdc_idx] += 1; } - self.dstate.pdc_pred_val = dc; + self.dstate.pdc_pred_val[pdc_idx] = dc; } if has_ac[24] { idct4x4(y2block); - } else { + } else if y2block[0] != 0 { idct4x4_dc(y2block); } for i in 0..16 { @@ -562,7 +565,7 @@ impl VP7Decoder { for i in 0..24 { if has_ac[i] { idct4x4(&mut self.coeffs[i]); - } else { + } else if self.coeffs[i][0] != 0 { idct4x4_dc(&mut self.coeffs[i]); } } @@ -871,13 +874,14 @@ impl VP7Decoder { } } } + let tr_edge = if has_top { ydst[yoff - ystride + 15] } else { 0x80 }; for y in 0..4 { for x in 0..4 { ipred_ctx_y.has_left = has_left || x > 0; let bmode = self.ymodes[iidx + x]; let cur_yoff = yoff + x * 4; - let has_tr = has_top && ((x < 3) || ((y == 0) && (mb_y < self.mb_w - 1))); - let has_dl = ipred_ctx_y.has_left && (y < 3); + let has_tr = ipred_ctx_y.has_top && ((x < 3) || ((y == 0) && (mb_y < self.mb_w - 1))); + let has_dl = ipred_ctx_y.has_left && (x == 0) && (y < 3); ipred_ctx_y.fill(ydst, cur_yoff, ystride, if has_tr { 8 } else { 4 }, if has_dl { 8 } else { 4 }); @@ -890,6 +894,11 @@ impl VP7Decoder { tr_save[x * 4 + i] = ipred_ctx_y.top[i + 4]; } } + if (mb_x == self.mb_w - 1) && has_top && (x == 3) { + for i in 0..4 { + ipred_ctx_y.top[i + 4] = tr_edge; + } + } match bmode { PredMode::DCPred => IPred4x4::ipred_dc(ydst, cur_yoff, ystride, ipred_ctx_y), PredMode::TMPred => IPred4x4::ipred_tm(ydst, cur_yoff, ystride, ipred_ctx_y), @@ -1011,22 +1020,32 @@ impl VP7Decoder { } else { for y in 0..2 { for x in 0..2 { - let mut chroma_mv = self.mvs[iidx] + self.mvs[iidx + 1] - + self.mvs[iidx + self.mv_stride] - + self.mvs[iidx + self.mv_stride + 1]; - chroma_mv.x /= 4; - chroma_mv.y /= 4; + let mut chroma_mv = self.mvs[iidx + x * 2] + self.mvs[iidx + x * 2 + 1] + + self.mvs[iidx + x * 2 + self.mv_stride] + + self.mvs[iidx + x * 2 + self.mv_stride + 1]; + if chroma_mv.x < 0 { + chroma_mv.x += 1; + } else { + chroma_mv.x += 2; + } + if chroma_mv.y < 0 { + chroma_mv.y += 1; + } else { + chroma_mv.y += 2; + } + chroma_mv.x >>= 2; + chroma_mv.y >>= 2; if pitch_smode == 0 { - mc_block4x4(dst, uoff, ustride, mb_x * 8 + x * 4, mb_y * 8 + y * 4, + mc_block4x4(dst, uoff + x * 4, ustride, mb_x * 8 + x * 4, mb_y * 8 + y * 4, chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf); - mc_block4x4(dst, voff, vstride, mb_x * 8 + x * 4, mb_y * 8 + y * 4, + mc_block4x4(dst, voff + x * 4, vstride, mb_x * 8 + x * 4, mb_y * 8 + y * 4, chroma_mv.x, chroma_mv.y, refframe.clone(), 2, &mut mc_buf); } else { - mc_block_special(dst, uoff, ustride, mb_x * 8 + x * 4, mb_y * 8 + y * 4, + mc_block_special(dst, uoff + x * 4, ustride, mb_x * 8 + x * 4, mb_y * 8 + y * 4, chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf, 4, pitch_smode); - mc_block_special(dst, voff, vstride, mb_x * 8 + x * 4, mb_y * 8 + y * 4, + mc_block_special(dst, voff + x * 4, vstride, mb_x * 8 + x * 4, mb_y * 8 + y * 4, chroma_mv.x, chroma_mv.y, refframe.clone(), 2, &mut mc_buf, 4, pitch_smode); } @@ -1052,17 +1071,17 @@ impl VP7Decoder { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]]; - let edge_thr = (loop_str as i16) + 2; - let luma_thr = loop_str as i16; - let chroma_thr = (loop_str as i16) * 2; + let edge_thr = i16::from(loop_str) + 2; + let luma_thr = i16::from(loop_str); + let chroma_thr = i16::from(loop_str) * 2; let inner_thr = if self.dstate.loop_sharpness == 0 { - loop_str as i16 + i16::from(loop_str) } else { - let bound1 = (9 - self.dstate.loop_sharpness) as i16; + let bound1 = i16::from(9 - self.dstate.loop_sharpness); let shift = (self.dstate.loop_sharpness + 3) >> 2; - ((loop_str as i16) >> shift).min(bound1) + (i16::from(loop_str) >> shift).min(bound1) }; - let hev_thr = HIGH_EDGE_VAR_THR[if self.dstate.is_intra { 1 } else { 0 }][loop_str as usize] as i16; + let hev_thr = i16::from(HIGH_EDGE_VAR_THR[if self.dstate.is_intra { 1 } else { 0 }][loop_str as usize]); let ystride = dframe.stride[0]; let ustride = dframe.stride[1]; @@ -1107,7 +1126,7 @@ impl NADecoder for VP7Decoder { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let fmt = YUV420_FORMAT; let myvinfo = NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, fmt); - let myinfo = NACodecTypeInfo::Video(myvinfo.clone()); + let myinfo = NACodecTypeInfo::Video(myvinfo); self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); supp.pool_u8.set_dec_bufs(4); @@ -1118,6 +1137,7 @@ impl NADecoder for VP7Decoder { Err(DecoderError::InvalidData) } } + #[allow(clippy::cyclomatic_complexity)] fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { let src = pkt.get_buffer(); @@ -1141,6 +1161,7 @@ impl NADecoder for VP7Decoder { self.set_dimensions(width, height); self.dstate.reset(); + self.scan.copy_from_slice(&DEFAULT_SCAN_ORDER); } else { if !self.shuf.has_refs() { return Err(DecoderError::MissingReference); @@ -1247,8 +1268,8 @@ impl NADecoder for VP7Decoder { let mut mb_idx = 0; self.pcache.reset(); if self.dstate.is_intra || (self.dstate.version > 0) { - self.dstate.pdc_pred_val = 0; - self.dstate.pdc_pred_count = 0; + self.dstate.pdc_pred_val = [0; 2]; + self.dstate.pdc_pred_count = [0; 2]; } let mut use_last = true; for mb_y in 0..self.mb_h { @@ -1339,7 +1360,7 @@ impl NADecoder for VP7Decoder { self.mb_info[mb_idx].ymode = PredMode::Inter; self.mb_info[mb_idx].uvmode = PredMode::Inter; } - self.decode_residue(&mut bc_main, mb_x, mb_idx); + self.decode_residue(&mut bc_main, mb_x, mb_idx, use_last); match self.mb_info[mb_idx].mb_type { VPMBType::Intra => { self.recon_intra_mb(&mut dframe, mb_x, mb_y)?; @@ -1403,6 +1424,12 @@ impl NADecoder for VP7Decoder { } } +impl NAOptionHandler for VP7Decoder { + fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] } + fn set_options(&mut self, _options: &[NAOption]) { } + fn query_option_value(&self, _name: &str) -> Option { None } +} + pub fn get_decoder() -> Box { Box::new(VP7Decoder::new()) } @@ -1411,25 +1438,32 @@ pub fn get_decoder() -> Box { mod test { use nihav_core::codecs::RegisteredDecoders; use nihav_core::demuxers::RegisteredDemuxers; - use nihav_core::test::dec_video::*; - use crate::codecs::duck_register_all_codecs; - use nihav_commonfmt::demuxers::generic_register_all_demuxers; + use nihav_codec_support::test::dec_video::*; + use crate::duck_register_all_decoders; + use nihav_commonfmt::generic_register_all_demuxers; #[test] fn test_vp7() { let mut dmx_reg = RegisteredDemuxers::new(); generic_register_all_demuxers(&mut dmx_reg); let mut dec_reg = RegisteredDecoders::new(); - duck_register_all_codecs(&mut dec_reg); - - //let file = "assets/Duck/potter-40.vp7"; - //let file = "assets/Duck/potter-500.vp7"; - //let file = "assets/Duck/starsky-700.vp7"; - //let file = "assets/Duck/taking-700.vp7"; - //let file = "assets/Duck/troy-700.vp7"; - let file = "assets/Duck/interlaced_blit_pitch.avi"; - //let file = "assets/Duck/vp7.avi"; - test_file_decoding("avi", file, Some(12), true, false, None/*Some("vp7")*/, &dmx_reg, &dec_reg); + duck_register_all_decoders(&mut dec_reg); + + test_decoding("avi", "vp7", "assets/Duck/interlaced_blit_pitch.avi", Some(12), &dmx_reg, + &dec_reg, ExpectedTestResult::MD5Frames(vec![ + [0xb79fb6f8, 0xed51ac9e, 0x9e423456, 0xc0918e7f], + [0xbf8d1274, 0x83515e15, 0x8c0887de, 0xfbfd05d3], + [0x8ad00466, 0x80b6cbfb, 0x54de408e, 0x9efbc05e], + [0x144122c5, 0x6897b553, 0x93474d29, 0x1a1274ec], + [0x06ff5d07, 0x55825d38, 0x072b0a78, 0xfcb5020f], + [0xfd01591b, 0xc42113e7, 0xc5a5550f, 0xb30f3b02], + [0x155e0d6e, 0x96d75e06, 0x9bd7ce87, 0xacf868e1], + [0xfd79103a, 0x695d21d3, 0xfeacb5b4, 0x1d869d08], + [0xf4bcfeac, 0x0d2c305c, 0x11416c96, 0x626a5ef6], + [0x3579b66c, 0x0a7d7dc0, 0xe80b0395, 0xf6a70661], + [0x5773768c, 0x813442e9, 0x4dd6f793, 0xb10fe55f], + [0xcaaf0ddb, 0x65c2410e, 0x95da5bba, 0x3b90128e], + [0x74773773, 0xe1dbadeb, 0x57aaf64b, 0x9c21e3c7]])); } }