fn has_top_block(&self, xpos: usize, ypos: usize, dx: usize, dy: usize, size: usize) -> bool {
if (ypos + dy) == 0 { return false; }
let xpos2 = xpos + dx;
- if (xpos2 + size) > self.width { return false; }
+ if (xpos2 + size) > self.awidth { return false; }
true
}
fn has_top_right_block(&self, xpos: usize, ypos: usize, dx: usize, dy: usize, size: usize) -> bool {
if (ypos + dy) == 0 { return false; }
let xpos2 = xpos + dx;
- if (xpos2 + size * 2) > self.width { return false; }
+ if (xpos2 + size * 2) > self.awidth { return false; }
let cxpos = ((xpos + dx) & 63) >> RV60_BLOCK_LOG2[size];
let cypos = ((ypos + dy) & 63) >> RV60_BLOCK_LOG2[size];
((cypos as u8) & RV60_AVAIL_MASK[cxpos]) == 0
fn has_left_block(&self, xpos: usize, ypos: usize, dx: usize, dy: usize, size: usize) -> bool {
if (xpos + dx) == 0 { return false; }
let ypos2 = ypos + dy;
- if (ypos2 + size) > self.height { return false; }
+ if (ypos2 + size) > self.aheight { return false; }
true
}
fn has_left_down_block(&self, xpos: usize, ypos: usize, dx: usize, dy: usize, size: usize) -> bool {
if (xpos + dx) == 0 { return false; }
let ypos2 = ypos + dy;
- if (ypos2 + size * 2) > self.height { return false; }
+ if (ypos2 + size * 2) > self.aheight { return false; }
let cxpos = (!(xpos + dx) & 63) >> RV60_BLOCK_LOG2[size];
let cypos = (!(ypos + dy) & 63) >> RV60_BLOCK_LOG2[size];
((cypos as u8) & RV60_AVAIL_MASK[cxpos]) >= 1
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
];
-#[derive(Clone,Copy,PartialEq,Debug)]
+#[derive(Clone,Copy,PartialEq,Debug,Default)]
enum CUType {
+ #[default]
Intra,
InterMV,
Skip,
InterNoMV,
}
-impl Default for CUType {
- fn default() -> Self { CUType::Intra }
-}
-
const RV60_CU_TYPES: [CUType; 4] = [ CUType::Intra, CUType::InterMV, CUType::Skip, CUType::InterNoMV ];
-#[derive(Clone,Copy,PartialEq,Debug)]
+#[derive(Clone,Copy,PartialEq,Debug,Default)]
enum PUType {
+ #[default]
Full,
N2Hor,
N2Ver,
}
}
-impl Default for PUType {
- fn default() -> Self { PUType::Full }
-}
-
#[derive(Clone,Copy,Debug)]
enum IntraMode {
Index(u8),
Plane64,
}
-#[derive(Clone,Copy,PartialEq,Debug)]
+#[derive(Clone,Copy,PartialEq,Debug,Default)]
enum TransformType {
+ #[default]
None,
T4X4,
T8X8,
T16X16,
}
-impl Default for TransformType {
- fn default() -> Self { TransformType::None }
-}
-
#[derive(Clone,Copy,PartialEq,Debug)]
enum MVRef {
None,
struct PUInfo {
cu_type: CUType,
ttype: TransformType,
+ pu_type: PUType,
}
impl PUInfo {
let dval = (q << 2) | strength;
for x in 0..dsize {
self.top_str[pos + x] = dval;
+ self.top_str[pos + (dsize - 1) * self.stride + x] = dval;
}
for y in 0..dsize {
self.left_str[pos + y * self.stride] = dval;
+ self.left_str[pos + y * self.stride + dsize - 1] = dval;
}
}
fn get_pos(&self, xpos: usize, ypos: usize) -> usize {
fn get_left_strength(&self, pos: usize) -> u8 {
self.left_str[pos] & 3
}
- fn set_top_strength(&mut self, pos: usize, str: u8) {
- self.top_str[pos] |= str;
+ fn set_top_strength(&mut self, pos: usize, strength: u8) {
+ self.top_str[pos] |= strength;
}
- fn set_left_strength(&mut self, pos: usize, str: u8) {
- self.left_str[pos] |= str;
+ fn set_left_strength(&mut self, pos: usize, strength: u8) {
+ self.left_str[pos] |= strength;
}
}
fn decode_cu_line(&mut self, buf: &mut NASimpleVideoFrame<u8>, hdr: &FrameHeader, src: &[u8], cu_y: usize) -> DecoderResult<()> {
let mut br = BitReader::new(src, BitReaderMode::BE);
let cu_w = hdr.get_width_cu();
- let dqp = hdr.read_line_qp_offset(&mut br)?;
- let qps = (hdr.qp as i8) + dqp;
- validate!((0..32).contains(&qps));
- let qp = qps as u8;
- self.qp = qp;
- self.sel_qp = match hdr.osvquant {
+ for cu_x in 0..cu_w {
+ let dqp = hdr.read_line_qp_offset(&mut br)?;
+ let qps = (hdr.qp as i8) + dqp;
+ validate!((0..32).contains(&qps));
+ let qp = qps as u8;
+ self.qp = qp;
+ self.sel_qp = match hdr.osvquant {
0 => qp,
1 => {
if qp <= 25 {
},
};
- for cu_x in 0..cu_w {
self.cu_splits.clear();
self.coded_blk = [false; 64];
self.decode_cb_tree(buf, hdr, &mut br, cu_x << 6, cu_y << 6, 6)?;
cbp16 = 0;
}
if cbp16 != 0 {
- self.coded_blk[cb_pos + 0] = true;
- self.coded_blk[cb_pos + 1] = true;
- self.coded_blk[cb_pos + 8] = true;
- self.coded_blk[cb_pos + 9] = true;
rv6_decode_cu_4x4in16x16(br, &self.cbs, is_intra, self.qp, self.sel_qp, &mut self.y_coeffs, &mut self.u_coeffs, &mut self.v_coeffs, cbp16)?;
for y in 0..4 {
for x in 0..4 {
let off = xpos + x * 4 + (ypos + y * 4) * dstride;
let dst = &mut buf.data;
self.dsp.add_block(dst, off, dstride, &self.y_coeffs[i*16..][..16], 4);
+ self.coded_blk[cb_pos + (y / 2) * 8 + (x / 2)] = true;
}
}
}
let off = buf.offset[1] + xoff + yoff * dstride;
let dst = &mut buf.data;
self.dsp.add_block(dst, off, dstride, &self.u_coeffs[i * 16..][..16], 4);
+ self.coded_blk[cb_pos + y * 8 + x] = true;
}
if ((cbp16 >> (20 + i)) & 1) != 0 {
self.dsp.transform4x4(&mut self.v_coeffs[i * 16..][..16]);
let off = buf.offset[2] + xoff + yoff * dstride;
let dst = &mut buf.data;
self.dsp.add_block(dst, off, dstride, &self.v_coeffs[i * 16..][..16], 4);
+ self.coded_blk[cb_pos + y * 8 + x] = true;
}
}
}
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(dst, off, dstride, 4, itype as usize, false);
+ self.ipred.pred_angle(dst, off, dstride, 4, itype as usize, true);
}
if ((cbp8 >> i) & 1) != 0 {
let blk = &mut self.y_coeffs[i * 16..][..16];
let pu_size = size >> 3;
pui.cu_type = cbh.cu_type;
pui.ttype = cbh.ttype;
+ pui.pu_type = cbh.pu_type;
if (cbh.cu_type == CUType::Intra) && (cbh.pu_type == PUType::Quarters) { // very special case
self.pu_info[self.pu_pos] = pui;
for y in 0..2 {
skip_cand.list[i] = MVInfo { f_mv: ZERO_MV, b_mv: ZERO_MV, mvref: MVRef::Ref0 };
}
}
+ fn calc_tile_size(&self, pu_pos: usize, cu_type: CUType, log_size: u8) -> u8 {
+ match log_size {
+ 3 => 3,
+ 4 if (cu_type != CUType::Intra) && (self.pu_info[pu_pos].pu_type != PUType::Full) => 3,
+ 4 | 5 | 6 => 4,
+ _ => unreachable!(),
+ }
+ }
fn deblock_cb_tree(&mut self, buf: &mut NASimpleVideoFrame<u8>, hdr: &FrameHeader, xpos: usize, ypos: usize, log_size: u8) {
- if (xpos >= hdr.width) || (ypos >= hdr.height) { return; }
- let split = (log_size > 3) && self.cu_splits.pop().unwrap();
+ if (xpos >= hdr.awidth) || (ypos >= hdr.aheight) { return; }
+ let split = self.cu_splits.pop().unwrap();
if split {
let hsize = 1 << (log_size - 1);
self.deblock_cb_tree(buf, hdr, xpos, ypos, log_size - 1);
} else {
let pu_pos = (xpos >> 3) + (ypos >> 3) * self.pu_stride;
let cu_type = self.pu_info[pu_pos].cu_type;
- let tsize = if self.pu_info[pu_pos].ttype == TransformType::T16X16 { 4 } else { 3 };
+ let tsize = self.calc_tile_size(pu_pos, cu_type, log_size);
let ntiles = 1 << (log_size - tsize);
let dparams = RV60DeblockParams {
deblock_chroma: hdr.deblock_chroma,
- width: hdr.width,
- height: hdr.height,
+ width: hdr.awidth,
+ height: hdr.aheight,
dblkstride: self.dblk.stride,
};
for ty in 0..ntiles {
if ypos > 0 {
let top_blk_pos = blk_pos - self.blk_stride;
for i in 0..size4 {
- if self.dblk.get_top_strength(dblk_pos + i) == 0 {
+ if self.dblk.get_top_strength(dblk_pos - self.dblk.stride + i) == 0 {
if self.blk_info[blk_pos + i].mv.is_deblock_cand(&self.blk_info[top_blk_pos + i].mv) {
self.dblk.set_top_strength(dblk_pos + i, 1);
}
}
if xpos > 0 {
for i in 0..size4 {
- if self.dblk.get_left_strength(dblk_pos) == 0 {
- if self.blk_info[blk_pos + i].mv.is_deblock_cand(&self.blk_info[blk_pos + i - 1].mv) {
+ if self.dblk.get_left_strength(dblk_pos - 1) == 0 {
+ if self.blk_info[blk_pos + i * self.blk_stride].mv.is_deblock_cand(&self.blk_info[blk_pos + i * self.blk_stride - 1].mv) {
self.dblk.set_left_strength(dblk_pos, 1);
}
}
Ok(())
} else {
-println!("???");
Err(DecoderError::InvalidData)
}
}
if hdr.deblock {
self.dblk.reinit(hdr.awidth, hdr.aheight);
}
- let mut off = hsize + ((br.tell() >> 3) as usize);
+ let mut off = hsize + (br.tell() >> 3);
let mut dframe = NASimpleVideoFrame::from_video_buf(&mut buf).unwrap();
for (cu_y, size) in slices.into_iter().enumerate() {
self.decode_cu_line(&mut dframe, &hdr, &src[off..][..size], cu_y)?;
for opt_def in DECODER_OPTIONS.iter() {
if opt_def.check(option).is_ok() {
match (option.name, &option.value) {
- (FRAME_SKIP_OPTION, NAValue::String(ref str)) => {
- if let Ok(smode) = FrameSkipMode::from_str(str) {
+ (FRAME_SKIP_OPTION, NAValue::String(ref strval)) => {
+ if let Ok(smode) = FrameSkipMode::from_str(strval) {
self.skip_mode = smode;
}
},
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],
+ [0x76743a3b, 0x7dd4f196, 0x0193fe5a, 0x4f78c7cb],
[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]]));
+ [0xfee70206, 0x626f3bea, 0x7677ad4b, 0x1228f3b6],
+ [0x7156cbc2, 0xf381bcb6, 0xe86531f2, 0xb311c3ea],
+ [0x1742b5a1, 0x66252580, 0x242753de, 0x5215d732],
+ [0xd357ebda, 0x6460dba6, 0xa93eb616, 0x63ee6d60],
+ [0x4cd72275, 0x28e1e439, 0xad17dfca, 0x3fd7253f],
+ [0xe389ce4f, 0x8f0891b3, 0x88639b23, 0x21ed114f],
+ [0x5b2b2f1b, 0x17a7518b, 0x53806e6a, 0x4538bb00],
+ [0xdca03c9a, 0x1a45d80c, 0x86141211, 0x79912ed4],
+ [0x0bf66bf4, 0x46385620, 0xc6fa4796, 0xd8e16d56],
+ [0x4671a7f0, 0x46f50649, 0x268df27b, 0x70b71ab3]]));
+ }
+ #[test]
+ fn test_rv60_dqp() {
+ let mut dmx_reg = RegisteredDemuxers::new();
+ realmedia_register_all_demuxers(&mut dmx_reg);
+ let mut dec_reg = RegisteredDecoders::new();
+ realmedia_register_all_decoders(&mut dec_reg);
+
+ // sample provided by Peter Ross
+ test_decoding("realmedia", "realvideo6", "assets/RV/qp-offset-type-2.rmhd", Some(500), &dmx_reg, &dec_reg,
+ ExpectedTestResult::MD5Frames(vec![
+ [0x3dc2f19e, 0x0f8c66bd, 0x8e81ceda, 0xa1bf8f58],
+ [0xbd9c0f89, 0x67b780b0, 0xa4afe443, 0x9f17221a],
+ [0xf3e0a7ba, 0xe620ace9, 0x03857219, 0x8c3bd1fb],
+ [0xc4eedc8c, 0x81d2dd0f, 0xa6443847, 0x09c8cec9],
+ [0x565fc952, 0x4d5dc166, 0xf64b7b0d, 0x1570de50],
+ [0x0e50786a, 0xaf058ff3, 0xa3f71eba, 0x370c197a],
+ [0x1b92667b, 0x9cab9e24, 0x1bf48cb2, 0x368db124],
+ [0xefcc0ab4, 0x6efceb20, 0xb2501ee8, 0xb449b7b6],
+ [0xbbc2ca23, 0x6a7a8da2, 0xeadc1ff7, 0x2ff0a7f3],
+ [0x6d14a2b4, 0x0d2642fb, 0x78fcad10, 0xba571ec1],
+ [0xbdf889fd, 0x5f15838a, 0x8fedd13f, 0xc26a2e50],
+ [0x886f03b6, 0xc46ba7c3, 0xae6aa971, 0x90cf94b6],
+ [0x951693e7, 0xa77f68f3, 0x765990c9, 0x4a4d57fa],
+ [0x3c25f4eb, 0x5c113c41, 0x4d73f498, 0xd7e210b0]]));
}
}