X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-realmedia%2Fsrc%2Fcodecs%2Frv3040.rs;h=bbaabdf87b738c12fe444b79067176e2b4269090;hb=6f2630992fe340ad1a122ec10c649f756e478185;hp=8da291b2d507e4facaad37c1b79b9d73dcbceae1;hpb=d6402b85e64a0d466862eb6abb48ae0eef1cef3a;p=nihav.git diff --git a/nihav-realmedia/src/codecs/rv3040.rs b/nihav-realmedia/src/codecs/rv3040.rs index 8da291b..bbaabdf 100644 --- a/nihav-realmedia/src/codecs/rv3040.rs +++ b/nihav-realmedia/src/codecs/rv3040.rs @@ -91,18 +91,13 @@ impl MBType { } } pub fn is_fwd(self) -> bool { - match self { + matches!(self, MBType::MBP16x16 | MBType::MBP16x16Mix | MBType::MBP16x8 | MBType::MBP8x16 | MBType::MBP8x8 | - MBType::MBForward => true, - _ => false, - } + MBType::MBForward) } pub fn is_bwd(self) -> bool { - match self { - MBType::MBBidir | MBType::MBBackward => true, - _ => false, - } + matches!(self, MBType::MBBidir | MBType::MBBackward) } pub fn has_mv_dir(self, fwd: bool) -> bool { match self { @@ -113,10 +108,7 @@ impl MBType { } } pub fn is_nomv(self) -> bool { - match self { - MBType::MBIntra | MBType::MBIntra16 | MBType::MBSkip | MBType::MBDirect => true, - _ => false, - } + matches!(self, MBType::MBIntra | MBType::MBIntra16 | MBType::MBSkip | MBType::MBDirect) } /*pub fn is_16x16(self) -> bool { match self { @@ -326,13 +318,13 @@ impl MVInfo { } fn reset(&mut self) { let size = self.w * self.h; - self.mv_f.truncate(0); + self.mv_f.clear(); self.mv_f.resize(size, ZERO_MV); - self.mv_b.truncate(0); + self.mv_b.clear(); self.mv_b.resize(size, ZERO_MV); - self.has_f.truncate(0); + self.has_f.clear(); self.has_f.resize(size >> 2, false); - self.has_b.truncate(0); + self.has_b.clear(); self.has_b.resize(size >> 2, false); } fn fill(&mut self, mb_x: usize, mb_y: usize, fwd: bool, mv: MV) { @@ -511,7 +503,7 @@ pub trait RV34DSP { fn parse_slice_offsets(src: &[u8], offsets: &mut Vec) -> DecoderResult<()> { let num_slices = (src[0] as usize) + 1; let ini_off = num_slices * 8 + 1; - offsets.truncate(0); + offsets.clear(); if ini_off >= src.len() { return Err(DecoderError::ShortData); } @@ -532,7 +524,7 @@ fn parse_slice_offsets(src: &[u8], offsets: &mut Vec) -> DecoderResult<() Ok(()) } -fn decode_slice_header(br: &mut BitReader, bd: &mut RV34BitstreamDecoder, slice_no: usize, slice_offs: &[usize], old_width: usize, old_height: usize) -> DecoderResult { +fn decode_slice_header(br: &mut BitReader, bd: &mut dyn RV34BitstreamDecoder, slice_no: usize, slice_offs: &[usize], old_width: usize, old_height: usize) -> DecoderResult { validate!(slice_no < slice_offs.len()); br.seek((slice_offs[slice_no] * 8) as u32)?; let mut shdr = bd.decode_slice_header(br, old_width, old_height)?; @@ -699,13 +691,13 @@ fn decode_mv(br: &mut BitReader) -> DecoderResult { Ok(MV{ x, y }) } -fn do_mc_16x16(dsp: &Box, buf: &mut NAVideoBuffer, prevbuf: &NAVideoBuffer, mb_x: usize, mb_y: usize, mv: MV, avg: bool) { +fn do_mc_16x16(dsp: &mut dyn RV34DSP, buf: &mut NAVideoBuffer, prevbuf: &NAVideoBuffer, mb_x: usize, mb_y: usize, mv: MV, avg: bool) { dsp.do_luma_mc (buf, prevbuf, mb_x * 16, mb_y * 16, mv, true, avg); dsp.do_chroma_mc(buf, prevbuf, mb_x * 8, mb_y * 8, 1, mv, true, avg); dsp.do_chroma_mc(buf, prevbuf, mb_x * 8, mb_y * 8, 2, mv, true, avg); } -fn do_mc_8x8(dsp: &Box, buf: &mut NAVideoBuffer, prevbuf: &NAVideoBuffer, mb_x: usize, xoff: usize, mb_y: usize, yoff: usize, mv: MV, avg: bool) { +fn do_mc_8x8(dsp: &mut dyn RV34DSP, buf: &mut NAVideoBuffer, prevbuf: &NAVideoBuffer, mb_x: usize, xoff: usize, mb_y: usize, yoff: usize, mv: MV, avg: bool) { dsp.do_luma_mc (buf, prevbuf, mb_x * 16 + xoff * 8, mb_y * 16 + yoff * 8, mv, false, avg); dsp.do_chroma_mc(buf, prevbuf, mb_x * 8 + xoff * 4, mb_y * 8 + yoff * 4, 1, mv, false, avg); dsp.do_chroma_mc(buf, prevbuf, mb_x * 8 + xoff * 4, mb_y * 8 + yoff * 4, 2, mv, false, avg); @@ -777,7 +769,7 @@ impl RV34Decoder { base_ts: 0, } } - fn decode_mb_header_intra(&mut self, bd: &mut RV34BitstreamDecoder, br: &mut BitReader, is_i16: bool, im: &mut IntraModeState, q: u8, has_top: bool, has_dq: bool) -> DecoderResult { + fn decode_mb_header_intra(&mut self, bd: &mut dyn RV34BitstreamDecoder, br: &mut BitReader, is_i16: bool, im: &mut IntraModeState, q: u8, has_top: bool, has_dq: bool) -> DecoderResult { if is_i16 { let imode = br.read(2)? as i8; im.fill_block(imode); @@ -793,7 +785,7 @@ impl RV34Decoder { Ok(MBInfo { mbtype: MBType::MBIntra, skip_run: 0, dquant: dq }) } } - fn decode_mb_header_inter(&mut self, bd: &mut RV34BitstreamDecoder, br: &mut BitReader, ftype: FrameType, mbtype: MBType, im: &mut IntraModeState, q: u8, has_top: bool) -> DecoderResult { + fn decode_mb_header_inter(&mut self, bd: &mut dyn RV34BitstreamDecoder, br: &mut BitReader, ftype: FrameType, mbtype: MBType, im: &mut IntraModeState, q: u8, has_top: bool) -> DecoderResult { let hdr = bd.decode_inter_mb_hdr(br, ftype, mbtype)?; validate!(hdr.mbtype != MBType::Invalid); if hdr.dquant { @@ -924,19 +916,19 @@ impl RV34Decoder { MBType::MBP16x16 | MBType::MBP16x16Mix => { if let Some(ref prevbuf) = self.ipbs.get_lastref() { let mv = self.mvi.get_mv(mb_x, mb_y, 0, 0, true); - do_mc_16x16(&self.dsp, buf, prevbuf, mb_x, mb_y, mv, false); + do_mc_16x16(self.dsp.as_mut(), buf, prevbuf, mb_x, mb_y, mv, false); } }, MBType::MBForward => { if let Some(ref fwdbuf) = self.ipbs.get_b_fwdref() { let mv = self.mvi.get_mv(mb_x, mb_y, 0, 0, true); - do_mc_16x16(&self.dsp, buf, fwdbuf, mb_x, mb_y, mv, false); + do_mc_16x16(self.dsp.as_mut(), buf, fwdbuf, mb_x, mb_y, mv, false); } }, MBType::MBBackward => { if let Some(ref bwdbuf) = self.ipbs.get_b_bwdref() { let mv = self.mvi.get_mv(mb_x, mb_y, 0, 0, false); - do_mc_16x16(&self.dsp, buf, bwdbuf, mb_x, mb_y, mv, false); + do_mc_16x16(self.dsp.as_mut(), buf, bwdbuf, mb_x, mb_y, mv, false); } }, MBType::MBP8x8 | MBType::MBP8x16 | MBType::MBP16x8 => { @@ -944,14 +936,14 @@ impl RV34Decoder { for y in 0..2 { for x in 0..2 { let mv = self.mvi.get_mv(mb_x, mb_y, x, y, true); - do_mc_8x8(&self.dsp, buf, prevbuf, mb_x, x, mb_y, y, mv, false); + do_mc_8x8(self.dsp.as_mut(), buf, prevbuf, mb_x, x, mb_y, y, mv, false); } } } }, MBType::MBSkip if !self.is_b => { if let Some(ref prevbuf) = self.ipbs.get_lastref() { - do_mc_16x16(&self.dsp, buf, prevbuf, mb_x, mb_y, ZERO_MV, false); + do_mc_16x16(self.dsp.as_mut(), buf, prevbuf, mb_x, mb_y, ZERO_MV, false); } }, MBType::MBSkip | MBType::MBDirect => { @@ -959,8 +951,8 @@ impl RV34Decoder { for y in 0..2 { for x in 0..2 { let (mv_f, mv_b) = self.ref_mvi.get_mv(mb_x, mb_y, x, y, true).scale(sstate.trd, sstate.trb); - do_mc_8x8(&self.dsp, buf, fwdbuf, mb_x, x, mb_y, y, mv_f, false); - do_mc_8x8(&self.dsp, &mut self.avg_buf, bwdbuf, mb_x, x, mb_y, y, mv_b, true); + do_mc_8x8(self.dsp.as_mut(), buf, fwdbuf, mb_x, x, mb_y, y, mv_f, false); + do_mc_8x8(self.dsp.as_mut(), &mut self.avg_buf, bwdbuf, mb_x, x, mb_y, y, mv_b, true); do_avg(&self.cdsp, buf, &self.avg_buf, mb_x, x, mb_y, y, 8, self.ratio1, self.ratio2); } } @@ -970,8 +962,8 @@ impl RV34Decoder { if let (Some(ref fwdbuf), Some(ref bwdbuf)) = (self.ipbs.get_b_fwdref(), self.ipbs.get_b_bwdref()) { let mv_f = self.mvi.get_mv(mb_x, mb_y, 0, 0, true); let mv_b = self.mvi.get_mv(mb_x, mb_y, 0, 0, false); - do_mc_16x16(&self.dsp, buf, fwdbuf, mb_x, mb_y, mv_f, false); - do_mc_16x16(&self.dsp, &mut self.avg_buf, bwdbuf, mb_x, mb_y, mv_b, true); + do_mc_16x16(self.dsp.as_mut(), buf, fwdbuf, mb_x, mb_y, mv_f, false); + do_mc_16x16(self.dsp.as_mut(), &mut self.avg_buf, bwdbuf, mb_x, mb_y, mv_b, true); do_avg(&self.cdsp, buf, &self.avg_buf, mb_x, 0, mb_y, 0, 16, self.ratio1, self.ratio2); } }, @@ -1057,7 +1049,7 @@ impl RV34Decoder { } Ok(()) } - fn fill_deblock_flags(&self, sstate: &SState, mb_pos: usize, mbinfo: &mut Vec) { + fn fill_deblock_flags(&self, sstate: &SState, mb_pos: usize, mbinfo: &mut [RV34MBInfo]) { let mbt = mbinfo[mb_pos].mbtype; let mut hmvmask = 0; let mut vmvmask = 0; @@ -1095,7 +1087,8 @@ impl RV34Decoder { } } - pub fn parse_frame(&mut self, supp: &mut NADecoderSupport, src: &[u8], bd: &mut RV34BitstreamDecoder) -> DecoderResult<(NABufferType, FrameType, u64)> { + #[allow(clippy::cognitive_complexity)] + pub fn parse_frame(&mut self, supp: &mut NADecoderSupport, src: &[u8], bd: &mut dyn RV34BitstreamDecoder) -> DecoderResult<(NABufferType, FrameType, u64)> { let mut slice_offs: Vec = Vec::new(); parse_slice_offsets(src, &mut slice_offs)?; let ini_off = slice_offs.len() * 8 + 1;