X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-realmedia%2Fsrc%2Fcodecs%2Frv60.rs;h=254cc372dce744ad1d8b2626c1d64f555264841c;hb=aa5efa8a68f625b21180a53c17c2cfaa79eb3500;hp=55faf037cac3ddb3b4df466de02e3b34f1fb15aa;hpb=3518aa855fa776fa96a0deca1660299611e41e96;p=nihav.git diff --git a/nihav-realmedia/src/codecs/rv60.rs b/nihav-realmedia/src/codecs/rv60.rs index 55faf03..254cc37 100644 --- a/nihav-realmedia/src/codecs/rv60.rs +++ b/nihav-realmedia/src/codecs/rv60.rs @@ -49,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, @@ -78,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 { @@ -110,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<()> { @@ -188,13 +192,13 @@ println!(" left {} / {}", br.left() >> 3, sum); 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 @@ -202,13 +206,13 @@ println!(" left {} / {}", br.left() >> 3, sum); 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 @@ -306,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) } } @@ -368,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) } } @@ -551,6 +540,7 @@ impl CBHeader { struct PUInfo { cu_type: CUType, ttype: TransformType, + pu_type: PUType, } impl PUInfo { @@ -589,9 +579,11 @@ impl DeblockInfo { 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 { @@ -692,7 +684,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 { @@ -731,10 +723,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; @@ -765,9 +757,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); } }, _ => { @@ -854,10 +846,6 @@ println!(" left {} bits", br.left()); 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 { @@ -866,8 +854,9 @@ 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); + self.coded_blk[cb_pos + (y / 2) * 8 + (x / 2)] = true; } } } @@ -880,15 +869,17 @@ 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); + 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 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); + self.coded_blk[cb_pos + y * 8 + x] = true; } } } @@ -905,10 +896,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, true); } if ((cbp8 >> i) & 1) != 0 { let blk = &mut self.y_coeffs[i * 16..][..16]; @@ -916,8 +907,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 { @@ -925,16 +915,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); } } }, @@ -948,24 +936,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); } } }, @@ -990,24 +975,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); } } } @@ -1023,6 +1005,7 @@ println!(" left {} bits", br.left()); 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 { @@ -1342,9 +1325,17 @@ println!(" left {} bits", br.left()); 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, 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); @@ -1354,12 +1345,12 @@ println!(" left {} bits", br.left()); } 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 { @@ -1389,7 +1380,7 @@ println!(" left {} bits", br.left()); 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); } @@ -1398,8 +1389,8 @@ println!(" left {} bits", br.left()); } 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); } } @@ -1510,7 +1501,7 @@ println!("???"); 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(); @@ -1603,17 +1594,17 @@ mod test { 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], + [0x76743a3b, 0x7dd4f196, 0x0193fe5a, 0x4f78c7cb], [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]])); + [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]])); } }