X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-realmedia%2Fsrc%2Fcodecs%2Frv60.rs;h=3f4ec9e263a20ade54db810397c844e3f6973265;hb=d649acc93b38f43bd7d7b36d7f89a44ad1493ad1;hp=5574cb43d4bcd539c406c5c37e1fae672ec1d819;hpb=b7c882c1ce6f86c07c2340751200e3a060942826;p=nihav.git diff --git a/nihav-realmedia/src/codecs/rv60.rs b/nihav-realmedia/src/codecs/rv60.rs index 5574cb4..3f4ec9e 100644 --- a/nihav-realmedia/src/codecs/rv60.rs +++ b/nihav-realmedia/src/codecs/rv60.rs @@ -41,6 +41,7 @@ const RV60_FRAME_TYPES: [FrameType; 4] = [ FrameType::I, FrameType::P, FrameType const MAX_IMODE: u8 = 34; #[derive(Clone,Copy,Debug)] +#[allow(dead_code)] struct FrameHeader { profile: u8, ftype: FrameType, @@ -48,7 +49,9 @@ struct FrameHeader { osvquant: u8, ts: u32, width: usize, + awidth: usize, height: usize, + aheight: usize, two_f_refs: bool, qp_off_type: u8, deblock: bool, @@ -77,6 +80,8 @@ impl FrameHeader { let width = ((br.read(11)? as usize) + 1) * 4; let height = ((br.read(11)? as usize) + 0) * 4; validate!(height > 0); + let awidth = (width + 15) & !15; + let aheight = (height + 15) & !15; let _some_flag = br.read_bool()?; let two_f_refs; if ftype == FrameType::I { @@ -109,8 +114,8 @@ impl FrameHeader { } Ok(FrameHeader { - profile, ftype, qp, osvquant, ts, width, height, two_f_refs, qp_off_type, - deblock, deblock_chroma, + profile, ftype, qp, osvquant, ts, width, height, awidth, aheight, + two_f_refs, qp_off_type, deblock, deblock_chroma, }) } fn parse_slice_sizes(&self, br: &mut BitReader, sizes: &mut Vec) -> DecoderResult<()> { @@ -123,7 +128,7 @@ impl FrameHeader { signs.push(sign); } validate!(signs[0]); - sizes.truncate(0); + sizes.clear(); let mut sum = 0; let first_size = br.read(nbits)? as usize; validate!(first_size > 0); @@ -305,16 +310,10 @@ impl PUType { } } fn has_hor_split(self) -> bool { - match self { - PUType::N2Hor | PUType::N4Hor | PUType::N34Hor | PUType::Quarters => true, - _ => false, - } + matches!(self, PUType::N2Hor | PUType::N4Hor | PUType::N34Hor | PUType::Quarters) } fn has_ver_split(self) -> bool { - match self { - PUType::N2Ver | PUType::N4Ver | PUType::N34Ver | PUType::Quarters => true, - _ => false, - } + matches!(self, PUType::N2Ver | PUType::N4Ver | PUType::N34Ver | PUType::Quarters) } } @@ -367,22 +366,13 @@ impl MVRef { } } fn is_ref0(self) -> bool { - match self { - MVRef::Ref0 | MVRef::Ref0AndBRef => true, - _ => false, - } + matches!(self, MVRef::Ref0 | MVRef::Ref0AndBRef) } fn is_fwd(self) -> bool { - match self { - MVRef::Ref0 | MVRef::Ref1 | MVRef::Ref0AndBRef => true, - _ => false, - } + matches!(self, MVRef::Ref0 | MVRef::Ref1 | MVRef::Ref0AndBRef) } fn is_bwd(self) -> bool { - match self { - MVRef::BRef | MVRef::Ref0AndBRef => true, - _ => false, - } + matches!(self, MVRef::BRef | MVRef::Ref0AndBRef) } } @@ -691,7 +681,7 @@ impl RealVideo60Decoder { let cu_w = hdr.get_width_cu(); let dqp = hdr.read_line_qp_offset(&mut br)?; let qps = (hdr.qp as i8) + dqp; - validate!((qps >= 0) && (qps < 32)); + validate!((0..32).contains(&qps)); let qp = qps as u8; self.qp = qp; self.sel_qp = match hdr.osvquant { @@ -730,10 +720,10 @@ println!(" left {} bits", br.left()); } #[allow(clippy::cognitive_complexity)] fn decode_cb_tree(&mut self, buf: &mut NASimpleVideoFrame, hdr: &FrameHeader, br: &mut BitReader, xpos: usize, ypos: usize, log_size: u8) -> DecoderResult<()> { - if (xpos >= hdr.width) || (ypos >= hdr.height) { return Ok(()); } + if (xpos >= hdr.awidth) || (ypos >= hdr.aheight) { return Ok(()); } let size = 1 << log_size; - let split = (xpos + size > hdr.width) || (ypos + size > hdr.height) || (size > 8 && br.read_bool()?); + let split = (xpos + size > hdr.awidth) || (ypos + size > hdr.aheight) || (size > 8 && br.read_bool()?); self.cu_splits.push(split); if split { let hsize = size >> 1; @@ -764,9 +754,9 @@ println!(" left {} bits", br.left()); let dstride = buf.stride[comp]; let soff = buf.offset[comp]; let off = soff + (xpos >> 1) + (ypos >> 1) * dstride; - let mut dst = &mut buf.data; + let dst = &mut buf.data; self.populate_ipred(hdr, dst, soff, dstride, 0, 0, size >> 1, false); - self.ipred.pred_angle(&mut dst, off, dstride, size >> 1, itype as usize, false); + self.ipred.pred_angle(dst, off, dstride, size >> 1, itype as usize, false); } }, _ => { @@ -865,8 +855,8 @@ println!(" left {} bits", br.left()); self.dsp.transform4x4(&mut self.y_coeffs[i * 16..][..16]); let dstride = buf.stride[0]; let off = xpos + x * 4 + (ypos + y * 4) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.y_coeffs[i*16..][..16], 4); + let dst = &mut buf.data; + self.dsp.add_block(dst, off, dstride, &self.y_coeffs[i*16..][..16], 4); } } } @@ -879,15 +869,15 @@ println!(" left {} bits", br.left()); self.dsp.transform4x4(&mut self.u_coeffs[i * 16..][..16]); let dstride = buf.stride[1]; let off = buf.offset[1] + xoff + yoff * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.u_coeffs[i * 16..][..16], 4); + let dst = &mut buf.data; + self.dsp.add_block(dst, off, dstride, &self.u_coeffs[i * 16..][..16], 4); } if ((cbp16 >> (20 + i)) & 1) != 0 { self.dsp.transform4x4(&mut self.v_coeffs[i * 16..][..16]); let dstride = buf.stride[2]; let off = buf.offset[2] + xoff + yoff * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.v_coeffs[i * 16..][..16], 4); + let dst = &mut buf.data; + self.dsp.add_block(dst, off, dstride, &self.v_coeffs[i * 16..][..16], 4); } } } @@ -904,10 +894,10 @@ println!(" left {} bits", br.left()); if split_i4x4 { let dstride = buf.stride[0]; let off = xpos + xoff + (ypos + yoff) * dstride; - let mut dst = &mut buf.data; + let dst = &mut buf.data; self.populate_ipred(hdr, dst, 0, dstride, xoff, yoff, 4, true); let itype = self.blk_info[self.blk_pos + (i & 1) + (i >> 1) * self.blk_stride].imode; - self.ipred.pred_angle(&mut dst, off, dstride, 4, itype as usize, false); + self.ipred.pred_angle(dst, off, dstride, 4, itype as usize, false); } if ((cbp8 >> i) & 1) != 0 { let blk = &mut self.y_coeffs[i * 16..][..16]; @@ -915,8 +905,7 @@ println!(" left {} bits", br.left()); let dstride = buf.stride[0]; let soff = buf.offset[0]; let off = soff + xpos + xoff + (ypos + yoff) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, blk, 4); + self.dsp.add_block(buf.data, off, dstride, blk, 4); } } if ((cbp8 >> 4) & 1) != 0 { @@ -924,16 +913,14 @@ println!(" left {} bits", br.left()); let dstride = buf.stride[1]; let soff = buf.offset[1]; let off = soff + (xpos >> 1) + (ypos >> 1) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.u_coeffs, 4); + self.dsp.add_block(buf.data, off, dstride, &self.u_coeffs, 4); } if ((cbp8 >> 5) & 1) != 0 { self.dsp.transform4x4(&mut self.v_coeffs); let dstride = buf.stride[2]; let soff = buf.offset[2]; let off = soff + (xpos >> 1) + (ypos >> 1) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.v_coeffs, 4); + self.dsp.add_block(buf.data, off, dstride, &self.v_coeffs, 4); } } }, @@ -947,24 +934,21 @@ println!(" left {} bits", br.left()); self.dsp.transform8x8(&mut self.y_coeffs); let dstride = buf.stride[0]; let off = xpos + ypos * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.y_coeffs, 8); + self.dsp.add_block(buf.data, off, dstride, &self.y_coeffs, 8); } if ((cbp8 >> 4) & 1) != 0 { self.dsp.transform4x4(&mut self.u_coeffs); let dstride = buf.stride[1]; let soff = buf.offset[1]; let off = soff + (xpos >> 1) + (ypos >> 1) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.u_coeffs, 4); + self.dsp.add_block(buf.data, off, dstride, &self.u_coeffs, 4); } if ((cbp8 >> 5) & 1) != 0 { self.dsp.transform4x4(&mut self.v_coeffs); let dstride = buf.stride[2]; let soff = buf.offset[2]; let off = soff + (xpos >> 1) + (ypos >> 1) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.v_coeffs, 4); + self.dsp.add_block(buf.data, off, dstride, &self.v_coeffs, 4); } } }, @@ -989,24 +973,21 @@ println!(" left {} bits", br.left()); self.dsp.transform16x16(&mut self.y_coeffs); let dstride = buf.stride[0]; let off = xpos + x * 16 + (ypos + y * 16) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.y_coeffs, 16); + self.dsp.add_block(buf.data, off, dstride, &self.y_coeffs, 16); } if ((super_cbp >> 16) & 0xF) != 0 { self.dsp.transform8x8(&mut self.u_coeffs); let dstride = buf.stride[1]; let soff = buf.offset[1]; let off = soff + (xpos >> 1) + x * 8 + ((ypos >> 1) + y * 8) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.u_coeffs, 8); + self.dsp.add_block(buf.data, off, dstride, &self.u_coeffs, 8); } if ((super_cbp >> 20) & 0xF) != 0 { self.dsp.transform8x8(&mut self.v_coeffs); let dstride = buf.stride[2]; let soff = buf.offset[2]; let off = soff + (xpos >> 1) + x * 8 + ((ypos >> 1) + y * 8) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.v_coeffs, 8); + self.dsp.add_block(buf.data, off, dstride, &self.v_coeffs, 8); } } } @@ -1506,10 +1487,10 @@ println!("???"); self.pu_stride = cu_w << 3; self.pu_info.resize(self.pu_stride * (cu_h << 3), PUInfo::default()); self.blk_stride = cu_w << 4; - self.blk_info.truncate(0); + self.blk_info.clear(); self.blk_info.resize(self.blk_stride * (cu_h << 4), BlockInfo::default()); if hdr.deblock { - self.dblk.reinit(hdr.width, hdr.height); + self.dblk.reinit(hdr.awidth, hdr.aheight); } let mut off = hsize + ((br.tell() >> 3) as usize); let mut dframe = NASimpleVideoFrame::from_video_buf(&mut buf).unwrap(); @@ -1598,20 +1579,21 @@ mod test { let mut dec_reg = RegisteredDecoders::new(); realmedia_register_all_decoders(&mut dec_reg); + // sample from a private collection test_decoding("realmedia", "realvideo6", "assets/RV/RV60.rmhd", Some(1000), &dmx_reg, &dec_reg, ExpectedTestResult::MD5Frames(vec![ [0x2b1f1807, 0x09edef33, 0x0e6c78c1, 0x3b3c8179], - [0xea406850, 0x400802b8, 0xac106fb6, 0xe1e2e766], + [0x9b8feb58, 0x161b1b44, 0xbca532e5, 0xcb4ac211], [0x2b1f1807, 0x09edef33, 0x0e6c78c1, 0x3b3c8179], - [0xb04e2626, 0x976e16f5, 0xc41a7a78, 0x2d8765da], - [0xf4f30d97, 0x7f2876eb, 0x265ffad4, 0x3542a7c4], - [0xa5082524, 0x38a86952, 0x35bf1fee, 0xfc830d3f], - [0x75eab1a2, 0x62e2222f, 0xe96a20d9, 0x652140b4], - [0x7590fa49, 0x78c83490, 0x239eeff9, 0x64282ac7], - [0x70b19e9f, 0x66c1f866, 0xb8d7142a, 0xf3e424b2], - [0xc2934123, 0x3bf72fc4, 0x12d8d123, 0x1f39525b], - [0x13344919, 0xecd01190, 0x2f69079b, 0xbf4d7026], - [0xcefb3284, 0xa9b36d4d, 0xf1aa6752, 0xaae17d44], - [0x57f01275, 0xf8e883ea, 0x4865752e, 0xc760a777]])); + [0x5dc8b7d1, 0xef6e6840, 0x7b634afb, 0x645711a3], + [0x64e802be, 0xd80dc046, 0x98309de0, 0xe9f2ee48], + [0x64d1fa65, 0xfe30eccf, 0x08e07dd5, 0xb7f079ec], + [0xfae26181, 0x63e190ec, 0xfa0ae49c, 0x095abb3c], + [0xc6491458, 0xf3a1e979, 0x6f4e64ab, 0xe77046cb], + [0x4ec5e66d, 0x5a99a40d, 0x871b16ab, 0xf63b2890], + [0x2d22683b, 0x4022a36b, 0xdfcd3259, 0xa7f43f77], + [0xff6a1c72, 0x2dd8b7ca, 0xe3f2f575, 0x2d7aa001], + [0xf95f1898, 0x1660a50d, 0x2b36aacc, 0x921b5402], + [0x8115fafe, 0x39ac33b2, 0x9d65b3cc, 0x5ec452fe]])); } }