X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-realmedia%2Fsrc%2Fcodecs%2Frv20.rs;h=0c27181f35d903432d8e1f6769e349d06df0d400;hb=1d0cf6c3755196cd4b4e03449b20fb25a98c9a50;hp=8e4965aa471fbc6698e2e1b137c32929af64f772;hpb=39a5835c4c48e28ad5115d71a62ecf9593ceb42b;p=nihav.git diff --git a/nihav-realmedia/src/codecs/rv20.rs b/nihav-realmedia/src/codecs/rv20.rs index 8e4965a..0c27181 100644 --- a/nihav-realmedia/src/codecs/rv20.rs +++ b/nihav-realmedia/src/codecs/rv20.rs @@ -70,14 +70,15 @@ struct RV20SliceInfo { 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 } } } @@ -194,6 +195,16 @@ impl BlockDSP for RV20BlockDSP { } } +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; @@ -210,14 +221,6 @@ impl<'a> RealVideo20BR<'a> { 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, @@ -228,7 +231,7 @@ impl<'a> RealVideo20BR<'a> { 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, @@ -340,7 +343,7 @@ impl<'a> BlockDecoder for RealVideo20BR<'a> { 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) } @@ -353,6 +356,8 @@ impl<'a> BlockDecoder for RealVideo20BR<'a> { 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 { @@ -504,8 +509,11 @@ impl<'a> RealVideo20BR<'a> { 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 @@ -525,6 +533,9 @@ impl<'a> RealVideo20BR<'a> { 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; @@ -540,7 +551,7 @@ impl<'a> RealVideo20BR<'a> { 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)) } } @@ -615,10 +626,11 @@ impl NADecoder for RealVideo20Decoder { 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(()) @@ -701,12 +713,12 @@ mod test { [0x319d142d, 0x607a7c28, 0x526a2794, 0xa6e7864f], [0x319d142d, 0x607a7c28, 0x526a2794, 0xa6e7864f], [0xa2008d4c, 0xf4684b3a, 0xecd0526c, 0xf0742a77], - [0xafe0df5b, 0x29cd2418, 0x29a265c7, 0x9b4f2218], + [0xed26067a, 0x861f385e, 0x3562e478, 0x586d0cb6], [0x0e0529df, 0xf1cc3f03, 0x03986b0d, 0xd2033c08], - [0x4662b5ab, 0xaca5ca35, 0x4d089fb2, 0xc6a3df1e], + [0x9343a151, 0xc7622835, 0x9edb29c2, 0xd96928fa], [0x22c978cf, 0x6887a9ba, 0xe74c9316, 0x8cbdd29b], - [0x12d8b88f, 0x59ebe632, 0xbcfaa336, 0xadbdd9ad], - [0x0d99c67b, 0x3231302f, 0x3612b0d0, 0x38b5414d], - [0x2f65b75e, 0x1239d563, 0x832ce096, 0x568a9bc2]])); + [0x3ff51b06, 0x1460e151, 0xd8536d37, 0x31121464], + [0x2912d269, 0x01f00c4b, 0x22f714f8, 0xf81abe8b], + [0x875be308, 0x390d5b71, 0xe4108ce3, 0x1f39fed4]])); } }