mb_pos: usize,
w: usize,
h: usize,
+ loop_filter: bool,
}
#[derive(Default)]
struct RV20BlockDSP {}
impl RV20SliceInfo {
- fn new(ftype: Type, seq: u32, qscale: u8, mb_x: usize, mb_y: usize, mb_pos: usize, w: usize, h: usize) -> Self {
- RV20SliceInfo { ftype, seq, qscale, mb_x, mb_y, mb_pos, w, h }
+ fn new(ftype: Type, seq: u32, qscale: u8, mb_x: usize, mb_y: usize, mb_pos: usize, w: usize, h: usize, loop_filter: bool) -> Self {
+ RV20SliceInfo { ftype, seq, qscale, mb_x, mb_y, mb_pos, w, h, loop_filter }
}
}
idct!(&tmp[i..], 8, &mut blk[i..], 8, 1 << 19, 20, i16);
}
}
- fn copy_blocks(&self, dst: &mut NAVideoBuffer<u8>, src: &NAVideoBuffer<u8>, xpos: usize, ypos: usize, w: usize, h: usize, mv: MV) {
- let srcx = ((mv.x >> 1) as isize) + (xpos as isize);
- let srcy = ((mv.y >> 1) as isize) + (ypos as isize);
+ fn copy_blocks(&self, dst: &mut NAVideoBuffer<u8>, src: NAVideoBufferRef<u8>, xpos: usize, ypos: usize, mv: MV) {
let mode = ((mv.x & 1) + (mv.y & 1) * 2) as usize;
+ let cmode = (if (mv.x & 3) != 0 { 1 } else { 0 }) + (if (mv.y & 3) != 0 { 2 } else { 0 });
- blockdsp::copy_blocks(dst, src, xpos, ypos, srcx, srcy, w, h, 0, 1, mode, H263_INTERP_FUNCS);
+ let mut dst = NASimpleVideoFrame::from_video_buf(dst).unwrap();
+
+ blockdsp::copy_block(&mut dst, src.clone(), 0, xpos, ypos, mv.x >> 1, mv.y >> 1, 16, 16, 0, 1, mode, H263_INTERP_FUNCS);
+ blockdsp::copy_block(&mut dst, src.clone(), 1, xpos >> 1, ypos >> 1, mv.x >> 2, mv.y >> 2, 8, 8, 0, 1, cmode, H263_INTERP_FUNCS);
+ blockdsp::copy_block(&mut dst, src, 2, xpos >> 1, ypos >> 1, mv.x >> 2, mv.y >> 2, 8, 8, 0, 1, cmode, H263_INTERP_FUNCS);
+ }
+ fn copy_blocks8x8(&self, dst: &mut NAVideoBuffer<u8>, src: NAVideoBufferRef<u8>, xpos: usize, ypos: usize, mvs: &[MV; 4]) {
+ let mut dst = NASimpleVideoFrame::from_video_buf(dst).unwrap();
+
+ for i in 0..4 {
+ let xadd = (i & 1) * 8;
+ let yadd = (i & 2) * 4;
+ let mode = ((mvs[i].x & 1) + (mvs[i].y & 1) * 2) as usize;
+
+ blockdsp::copy_block(&mut dst, src.clone(), 0, xpos + xadd, ypos + yadd, mvs[i].x >> 1, mvs[i].y >> 1, 8, 8, 0, 1, mode, H263_INTERP_FUNCS);
+ }
+
+ let sum_mv = mvs[0] + mvs[1] + mvs[2] + mvs[3];
+ let cmx = (sum_mv.x >> 3) + H263_CHROMA_ROUND[(sum_mv.x & 0xF) as usize];
+ let cmy = (sum_mv.y >> 3) + H263_CHROMA_ROUND[(sum_mv.y & 0xF) as usize];
+ let mode = ((cmx & 1) + (cmy & 1) * 2) as usize;
+ for plane in 1..3 {
+ blockdsp::copy_block(&mut dst, src.clone(), plane, xpos >> 1, ypos >> 1, cmx >> 1, cmy >> 1, 8, 8, 0, 1, mode, H263_INTERP_FUNCS);
+ }
}
- fn avg_blocks(&self, dst: &mut NAVideoBuffer<u8>, src: &NAVideoBuffer<u8>, xpos: usize, ypos: usize, w: usize, h: usize, mv: MV) {
- let srcx = ((mv.x >> 1) as isize) + (xpos as isize);
- let srcy = ((mv.y >> 1) as isize) + (ypos as isize);
+ fn avg_blocks(&self, dst: &mut NAVideoBuffer<u8>, src: NAVideoBufferRef<u8>, xpos: usize, ypos: usize, mv: MV) {
let mode = ((mv.x & 1) + (mv.y & 1) * 2) as usize;
+ let cmode = (if (mv.x & 3) != 0 { 1 } else { 0 }) + (if (mv.y & 3) != 0 { 2 } else { 0 });
+
+ let mut dst = NASimpleVideoFrame::from_video_buf(dst).unwrap();
+
+ blockdsp::copy_block(&mut dst, src.clone(), 0, xpos, ypos, mv.x >> 1, mv.y >> 1, 16, 16, 0, 1, mode, H263_INTERP_AVG_FUNCS);
+ blockdsp::copy_block(&mut dst, src.clone(), 1, xpos >> 1, ypos >> 1, mv.x >> 2, mv.y >> 2, 8, 8, 0, 1, cmode, H263_INTERP_AVG_FUNCS);
+ blockdsp::copy_block(&mut dst, src, 2, xpos >> 1, ypos >> 1, mv.x >> 2, mv.y >> 2, 8, 8, 0, 1, cmode, H263_INTERP_AVG_FUNCS);
+ }
+ fn avg_blocks8x8(&self, dst: &mut NAVideoBuffer<u8>, src: NAVideoBufferRef<u8>, xpos: usize, ypos: usize, mvs: &[MV; 4]) {
+ let mut dst = NASimpleVideoFrame::from_video_buf(dst).unwrap();
+
+ for i in 0..4 {
+ let xadd = (i & 1) * 8;
+ let yadd = (i & 2) * 4;
+ let mode = ((mvs[i].x & 1) + (mvs[i].y & 1) * 2) as usize;
+
+ blockdsp::copy_block(&mut dst, src.clone(), 0, xpos + xadd, ypos + yadd, mvs[i].x >> 1, mvs[i].y >> 1, 8, 8, 0, 1, mode, H263_INTERP_AVG_FUNCS);
+ }
- blockdsp::copy_blocks(dst, src, xpos, ypos, srcx, srcy, w, h, 0, 1, mode, H263_INTERP_AVG_FUNCS);
+ let sum_mv = mvs[0] + mvs[1] + mvs[2] + mvs[3];
+ let cmx = (sum_mv.x >> 3) + H263_CHROMA_ROUND[(sum_mv.x & 0xF) as usize];
+ let cmy = (sum_mv.y >> 3) + H263_CHROMA_ROUND[(sum_mv.y & 0xF) as usize];
+ let mode = ((cmx & 1) + (cmy & 1) * 2) as usize;
+ for plane in 1..3 {
+ blockdsp::copy_block(&mut dst, src.clone(), plane, xpos >> 1, ypos >> 1, cmx >> 1, cmy >> 1, 8, 8, 0, 1, mode, H263_INTERP_AVG_FUNCS);
+ }
}
fn filter_row(&self, buf: &mut NAVideoBuffer<u8>, mb_y: usize, mb_w: usize, cbpi: &CBPInfo) {
h263_filter_row(buf, mb_y, mb_w, cbpi)
}
}
+fn get_mb_pos_bits(mb_w: usize, mb_h: usize) -> u8 {
+ let max_pos = mb_w * mb_h - 1;
+ for i in 0..H263_MBB.len() {
+ if max_pos <= H263_MBB[i].blocks {
+ return H263_MBB[i].bits;
+ }
+ }
+ 0
+}
+
impl<'a> RealVideo20BR<'a> {
fn new(src: &'a [u8], tables: &'a Tables, width: usize, height: usize, minor_ver: u8, rpr: RPRInfo) -> Self {
let nslices = (src[0] as usize) + 1;
let soff = nslices * 8 + 1;
let mb_w = (width + 15) >> 4;
let mb_h = (height + 15) >> 4;
- let max_pos = mb_w * mb_h - 1;
- let mut mbpb = 0;
- for i in 0..H263_MBB.len() {
- if max_pos <= H263_MBB[i].blocks {
- mbpb = H263_MBB[i].bits;
- break;
- }
- }
RealVideo20BR {
br: BitReader::new(&src[soff..], BitReaderMode::BE),
tables,
h: height,
mb_w,
mb_h,
- mb_pos_bits: mbpb,
+ mb_pos_bits: get_mb_pos_bits(mb_w, mb_h),
minor_ver,
rpr,
pts: 0,
mb_count = self.mb_w * self.mb_h;
}*/
- let plusinfo = Some(PlusInfo::new(shdr.ftype == Type::I, false, false, false));
+ let plusinfo = Some(PlusInfo::new(shdr.ftype == Type::I, shdr.loop_filter, false, false));
let picinfo = PicInfo::new(shdr.w, shdr.h, shdr.ftype, MVMode::Long, false, false, shdr.qscale, shdr.seq as u16, None, plusinfo);
Ok(picinfo)
}
if self.slice_no < self.num_slices {
let pos = self.br.tell();
let shdr2 = self.read_slice_header()?;
+ validate!(shdr2.mb_pos > shdr.mb_pos);
+ validate!(shdr2.w == shdr.w && shdr2.h == shdr.h);
mb_count = shdr2.mb_pos - shdr.mb_pos;
self.br.seek(pos as u32)?;
} else {
validate!(marker == 0);
let qscale = br.read(5)? as u8;
validate!(qscale > 0);
+ let loop_filter;
if self.minor_ver >= 2 {
- br.skip(1)?; // loop filter
+ loop_filter = br.read_bool()?;
+ } else {
+ loop_filter = false;
}
let seq = if self.minor_ver <= 1 {
br.read(8)? << 8
h = self.rpr.heights[rpr - 1];
validate!((w != 0) && (h != 0));
}
+ self.mb_w = (w + 15) >> 4;
+ self.mb_h = (h + 15) >> 4;
+ self.mb_pos_bits = get_mb_pos_bits(self.mb_w, self.mb_h);
} else {
w = self.w;
h = self.h;
br.skip(5)?;
}
- Ok(RV20SliceInfo::new(ftype, seq, qscale, mb_x, mb_y, mb_pos, w, h))
+ Ok(RV20SliceInfo::new(ftype, seq, qscale, mb_x, mb_y, mb_pos, w, h, loop_filter))
}
}
self.rpr.present = false;
} else {
self.rpr.present = true;
- self.rpr.bits = ((rprb >> 1) + 1) as u8;
- for i in 4..(src.len()/2) {
- self.rpr.widths [i - 4] = (src[i * 2] as usize) * 4;
- self.rpr.heights[i - 4] = (src[i * 2 + 1] as usize) * 4;
+ self.rpr.bits = ((rprb >> 1) + 1).min(3) as u8;
+ let num_dim = ((src.len() - 8) / 2).min(self.rpr.widths.len() - 1);
+ for i in 0..num_dim {
+ self.rpr.widths [i] = (src[i * 2 + 8] as usize) * 4;
+ self.rpr.heights[i] = (src[i * 2 + 9] as usize) * 4;
}
}
Ok(())
}
}
+impl NAOptionHandler for RealVideo20Decoder {
+ fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] }
+ fn set_options(&mut self, _options: &[NAOption]) { }
+ fn query_option_value(&self, _name: &str) -> Option<NAValue> { None }
+}
+
struct MBB { blocks: usize, bits: u8 }
const H263_MBB: &[MBB; 7] = &[
MBB{ blocks: 47, bits: 6 },
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_rv20() {
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/rv20_svt_atrc_640x352_realproducer_plus_8.51.rm", /*None*/Some(3000), true, false, None/*Some("rv20")*/, &dmx_reg, &dec_reg);
-// test_file_decoding("realmedia", "assets/RV/rv20_cook_640x352_realproducer_plus_8.51.rm", /*None*/Some(1000), true, false, Some("rv20"));
+ realmedia_register_all_decoders(&mut dec_reg);
+
+ test_decoding("realmedia", "realvideo2",
+ "assets/RV/rv20_svt_atrc_640x352_realproducer_plus_8.51.rm",
+ Some(1000), &dmx_reg, &dec_reg, ExpectedTestResult::MD5Frames(vec![
+ [0x319d142d, 0x607a7c28, 0x526a2794, 0xa6e7864f],
+ [0x319d142d, 0x607a7c28, 0x526a2794, 0xa6e7864f],
+ [0x319d142d, 0x607a7c28, 0x526a2794, 0xa6e7864f],
+ [0x319d142d, 0x607a7c28, 0x526a2794, 0xa6e7864f],
+ [0x319d142d, 0x607a7c28, 0x526a2794, 0xa6e7864f],
+ [0x319d142d, 0x607a7c28, 0x526a2794, 0xa6e7864f],
+ [0x319d142d, 0x607a7c28, 0x526a2794, 0xa6e7864f],
+ [0x319d142d, 0x607a7c28, 0x526a2794, 0xa6e7864f],
+ [0x319d142d, 0x607a7c28, 0x526a2794, 0xa6e7864f],
+ [0x8ce88686, 0x03ca3bb9, 0x0d18347b, 0xccdb0bc5],
+ [0x319d142d, 0x607a7c28, 0x526a2794, 0xa6e7864f],
+ [0x319d142d, 0x607a7c28, 0x526a2794, 0xa6e7864f],
+ [0x319d142d, 0x607a7c28, 0x526a2794, 0xa6e7864f],
+ [0xa2008d4c, 0xf4684b3a, 0xecd0526c, 0xf0742a77],
+ [0x5eef6cfd, 0x4eb49f19, 0x4d760b7a, 0x741ccd0c],
+ [0x0e0529df, 0xf1cc3f03, 0x03986b0d, 0xd2033c08],
+ [0xdb9aa091, 0xf2c6345c, 0xde9deae8, 0x71f51a67],
+ [0x22c978cf, 0x6887a9ba, 0xe74c9316, 0x8cbdd29b],
+ [0x7c83c784, 0x15b20881, 0x74798f24, 0x2096573c],
+ [0x84a68aed, 0x4cfcefb1, 0x78d1b66b, 0x21b1860a],
+ [0x78ed094a, 0x8df72434, 0x58bcd64d, 0x8d725dfd]]));
}
}