const MAX_IMODE: u8 = 34;
#[derive(Clone,Copy,Debug)]
+#[allow(dead_code)]
struct FrameHeader {
profile: u8,
ftype: FrameType,
osvquant: u8,
ts: u32,
width: usize,
+ awidth: usize,
height: usize,
+ aheight: usize,
two_f_refs: bool,
qp_off_type: u8,
deblock: bool,
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 {
}
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<usize>) -> DecoderResult<()> {
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);
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6
];
const RV60_AVAIL_MASK: [u8; 64] = [
- 0, 1, 0, 3, 0, 1, 0, 7, 0, 1, 0, 3, 0, 1, 0, 0,
+ 0, 1, 0, 3, 0, 1, 0, 7, 0, 1, 0, 3, 0, 1, 0, 0xF,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}
}
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)
}
}
}
}
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)
}
}
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 {
}
Ok(())
}
+ #[allow(clippy::cognitive_complexity)]
fn decode_cb_tree(&mut self, buf: &mut NASimpleVideoFrame<u8>, 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;
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);
}
},
_ => {
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);
}
}
}
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);
}
}
}
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];
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 {
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);
}
}
},
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);
}
}
},
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);
}
}
}
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();
use nihav_core::codecs::RegisteredDecoders;
use nihav_core::demuxers::RegisteredDemuxers;
use nihav_codec_support::test::dec_video::*;
- use crate::realmedia_register_all_codecs;
+ use crate::realmedia_register_all_decoders;
use crate::realmedia_register_all_demuxers;
#[test]
fn test_rv60() {
let mut dmx_reg = RegisteredDemuxers::new();
realmedia_register_all_demuxers(&mut dmx_reg);
let mut dec_reg = RegisteredDecoders::new();
- realmedia_register_all_codecs(&mut dec_reg);
-
- test_file_decoding("realmedia", "assets/RV/RV60.rmhd", Some(4000), true, false, None/*Some("rv60")*/, &dmx_reg, &dec_reg);
-//panic!("end");
+ 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],
+ [0xc7d45c3b, 0x6a82ff3a, 0xaf49a7ea, 0x7cf9a533],
+ [0x2b1f1807, 0x09edef33, 0x0e6c78c1, 0x3b3c8179],
+ [0x3db0f7ea, 0xbbf24a80, 0x54c0dd7c, 0xbdea881a],
+ [0x24134118, 0xeece4c59, 0x3f319c04, 0xd04951fd],
+ [0xe5f1a7a5, 0x204ab47b, 0x678277b3, 0x179f3007],
+ [0x61fb5e14, 0x47cce437, 0xaeeed91f, 0x03f727aa],
+ [0x46c71f20, 0x8e6ee603, 0xb68965ee, 0xf5bf3c45],
+ [0xf87589a4, 0xd9cc9120, 0xff27a8e6, 0xc1cc1dd5],
+ [0x12ea3288, 0x810b766b, 0x9a83ac11, 0x88f9996a],
+ [0xe1a8020f, 0x972fadbb, 0x771f0f7e, 0x7a3a3e41],
+ [0xed041308, 0x3112b04e, 0xcb39b23b, 0x5f73798c],
+ [0xb0a2db76, 0x56dd7f97, 0x87e4f6d4, 0xe69ecfd8]]));
}
}