From: Kostya Shishkov Date: Tue, 11 Feb 2020 11:31:35 +0000 (+0100) Subject: Make BitReader rely on passed slice size without the additional arguments. X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=fa90ccfb8676a917a02fbb56381f86aa1962d313;p=nihav.git Make BitReader rely on passed slice size without the additional arguments. --- diff --git a/nihav-commonfmt/src/codecs/aac.rs b/nihav-commonfmt/src/codecs/aac.rs index c2ef76a..c46366c 100644 --- a/nihav-commonfmt/src/codecs/aac.rs +++ b/nihav-commonfmt/src/codecs/aac.rs @@ -147,7 +147,7 @@ impl M4AInfo { } } fn read(&mut self, src: &[u8]) -> DecoderResult<()> { - let mut br = BitReader::new(src, src.len(), BitReaderMode::BE); + let mut br = BitReader::new(src, BitReaderMode::BE); self.otype = Self::read_object_type(&mut br)?; self.srate = Self::read_sampling_frequency(&mut br)?; validate!(self.srate > 0); @@ -1238,7 +1238,7 @@ impl NADecoder for AACDecoder { let ainfo = self.info.get_properties().get_audio_info().unwrap(); let mut abuf = alloc_audio_buffer(ainfo, self.m4ainfo.samples, self.chmap.clone())?; - let mut br = BitReader::new(&pktbuf, pktbuf.len(), BitReaderMode::BE); + let mut br = BitReader::new(&pktbuf, BitReaderMode::BE); match self.m4ainfo.otype { M4AType::LC => { self.decode_ga(&mut br, &mut abuf)?; diff --git a/nihav-commonfmt/src/codecs/atrac3.rs b/nihav-commonfmt/src/codecs/atrac3.rs index 9d416e2..efd608c 100644 --- a/nihav-commonfmt/src/codecs/atrac3.rs +++ b/nihav-commonfmt/src/codecs/atrac3.rs @@ -622,7 +622,7 @@ impl NADecoder for Atrac3Decoder { } { - let mut br = BitReader::new(self.pkt_buf.as_slice(), frame_size, BitReaderMode::BE); + let mut br = BitReader::new(&self.pkt_buf[0..frame_size], BitReaderMode::BE); let id = br.read(6)?; validate!(id == 0x28); self.ch_data[0].decode_unit(&mut br, &self.codebooks, &self.scalefactors)?; @@ -644,7 +644,7 @@ impl NADecoder for Atrac3Decoder { } else { off = frame_size / 2; } - let mut br = BitReader::new(&self.pkt_buf[off..], frame_size - off, BitReaderMode::BE); + let mut br = BitReader::new(&self.pkt_buf[off..frame_size], BitReaderMode::BE); if self.mode == Mode::JointStereo { let id = br.read(2)?; validate!(id == 0x3); diff --git a/nihav-commonfmt/src/codecs/clearvideo.rs b/nihav-commonfmt/src/codecs/clearvideo.rs index 9b5ee77..03aa36d 100644 --- a/nihav-commonfmt/src/codecs/clearvideo.rs +++ b/nihav-commonfmt/src/codecs/clearvideo.rs @@ -671,7 +671,7 @@ impl NADecoder for ClearVideoDecoder { } let is_intra = (src[off] & 2) == 2; - let mut br = BitReader::new(&src[(off + 1)..], src.len() - (off + 1), BitReaderMode::BE); + let mut br = BitReader::new(&src[(off + 1)..], BitReaderMode::BE); let vinfo = self.info.get_properties().get_video_info().unwrap(); let bufinfo = alloc_video_buffer(vinfo, self.tsize)?; diff --git a/nihav-commonfmt/src/codecs/sipro.rs b/nihav-commonfmt/src/codecs/sipro.rs index ec70bf1..22181cb 100644 --- a/nihav-commonfmt/src/codecs/sipro.rs +++ b/nihav-commonfmt/src/codecs/sipro.rs @@ -685,7 +685,7 @@ impl NADecoder for SiproDecoder { let frame_len = self.mode.subframe_len * self.mode.subframes; for (input, output) in pktbuf.chunks(frm_size).zip(dst.chunks_mut(out_frm_size)) { - let mut br = BitReader::new(input, input.len(), BitReaderMode::LE); + let mut br = BitReader::new(input, BitReaderMode::LE); for dst in output.chunks_mut(frame_len) { self.unpack_frame(&mut br)?; if self.mode_type.is16k() { diff --git a/nihav-commonfmt/src/codecs/ts102366.rs b/nihav-commonfmt/src/codecs/ts102366.rs index 4675c05..5546049 100644 --- a/nihav-commonfmt/src/codecs/ts102366.rs +++ b/nihav-commonfmt/src/codecs/ts102366.rs @@ -1171,9 +1171,9 @@ impl NADecoder for AudioDecoder { let mut br; if (pktbuf[0] == MAGIC_BYTE0) && (pktbuf[1] == MAGIC_BYTE1) { - br = BitReader::new(pktbuf.as_slice(), pktbuf.len(), BitReaderMode::BE); + br = BitReader::new(pktbuf.as_slice(), BitReaderMode::BE); } else if (pktbuf[0] == MAGIC_BYTE1) && (pktbuf[1] == MAGIC_BYTE0) { - br = BitReader::new(pktbuf.as_slice(), pktbuf.len(), BitReaderMode::LE16MSB); + br = BitReader::new(pktbuf.as_slice(), BitReaderMode::LE16MSB); } else { return Err(DecoderError::InvalidData); } diff --git a/nihav-core/src/io/bitreader.rs b/nihav-core/src/io/bitreader.rs index faa1d87..aa84155 100644 --- a/nihav-core/src/io/bitreader.rs +++ b/nihav-core/src/io/bitreader.rs @@ -22,7 +22,6 @@ pub struct BitReader<'a> { cache: u64, bits: u8, pos: usize, - end: usize, src: &'a [u8], mode: BitReaderMode, } @@ -30,9 +29,8 @@ pub struct BitReader<'a> { #[allow(clippy::identity_op)] impl<'a> BitReader<'a> { - pub fn new(src: &'a [u8], size: usize, mode: BitReaderMode) -> Self { - if src.len() < size { panic!("size is less than needed"); } - BitReader{ cache: 0, pos: 0, bits: 0, end: size, src, mode } + pub fn new(src: &'a [u8], mode: BitReaderMode) -> Self { + BitReader{ cache: 0, pos: 0, bits: 0, src, mode } } pub fn tell(&self) -> usize { @@ -40,7 +38,7 @@ impl<'a> BitReader<'a> { } pub fn left(&self) -> isize { - ((self.end as isize) - (self.pos as isize)) * 8 + (self.bits as isize) + ((self.src.len() as isize) - (self.pos as isize)) * 8 + (self.bits as isize) } fn fill32be(&mut self, src: &[u8]) { @@ -73,9 +71,9 @@ impl<'a> BitReader<'a> { #[inline(always)] fn refill(&mut self) -> BitReaderResult<()> { - if self.pos >= self.end { return Err(BitstreamEnd) } + if self.pos >= self.src.len() { return Err(BitstreamEnd) } while self.bits <= 32 { - if self.pos + 4 <= self.end { + if self.pos + 4 <= self.src.len() { let buf = &self.src[self.pos..]; match self.mode { BitReaderMode::BE => self.fill32be (buf), @@ -89,7 +87,7 @@ impl<'a> BitReader<'a> { let mut buf: [u8; 4] = [0, 0, 0, 0]; let mut newbits: u8 = 0; for out in buf.iter_mut().take(3) { - if self.pos < self.end { + if self.pos < self.src.len() { *out = self.src[self.pos]; self.pos += 1; newbits += 8; @@ -200,7 +198,7 @@ impl<'a> BitReader<'a> { } pub fn seek(&mut self, nbits: u32) -> BitReaderResult<()> { - if ((nbits + 7) >> 3) as usize > self.end { return Err(TooManyBitsRequested); } + if ((nbits + 7) >> 3) as usize > self.src.len() { return Err(TooManyBitsRequested); } self.reset_cache(); self.pos = ((nbits / 32) * 4) as usize; self.skip(nbits & 0x1F) @@ -238,14 +236,14 @@ mod test { fn br_works() { const DATA: [u8; 18] = [0b00011011; 18]; let src = &DATA; - let mut br = BitReader::new(src, src.len(), BitReaderMode::LE16MSB); + let mut br = BitReader::new(src, BitReaderMode::LE16MSB); for _ in 0..8 { assert_eq!(br.read(16).unwrap(), 0x1B1B); } const DATA2: [u8; 1] = [ 0b00011011 ]; let src = &DATA2; - let mut br = BitReader::new(src, src.len(), BitReaderMode::LE); + let mut br = BitReader::new(src, BitReaderMode::LE); assert_eq!(br.read_s(5).unwrap(), -5); } } diff --git a/nihav-core/src/io/codebook.rs b/nihav-core/src/io/codebook.rs index 4f041c6..2e4094b 100644 --- a/nihav-core/src/io/codebook.rs +++ b/nihav-core/src/io/codebook.rs @@ -348,7 +348,7 @@ mod test { FullCodebookDesc { code: 0b1110, bits: 4, sym: -42 } ); let buf = &BITS; - let mut br = BitReader::new(buf, buf.len(), BitReaderMode::BE); + let mut br = BitReader::new(buf, BitReaderMode::BE); let mut cfr = FullCodebookDescReader::new(cb_desc); let cb = Codebook::new(&mut cfr, CodebookMode::MSB).unwrap(); assert_eq!(br.read_cb(&cb).unwrap(), 16); @@ -377,7 +377,7 @@ mod test { ShortCodebookDesc { code: 0b1111110, bits: 7 }, ShortCodebookDesc { code: 0b11111111, bits: 8 } ); - let mut br2 = BitReader::new(buf, buf.len(), BitReaderMode::BE); + let mut br2 = BitReader::new(buf, BitReaderMode::BE); let mut cfr = ShortCodebookDescReader::new(scb_desc); let cb = Codebook::new(&mut cfr, CodebookMode::MSB).unwrap(); assert_eq!(br2.read_cb(&cb).unwrap(), 0); @@ -404,7 +404,7 @@ mod test { ShortCodebookDesc { code: 0b0111111, bits: 7 }, ShortCodebookDesc { code: 0b1011101111, bits: 10 } ); - let mut brl = BitReader::new(buf, buf.len(), BitReaderMode::LE); + let mut brl = BitReader::new(buf, BitReaderMode::LE); let mut cfr = ShortCodebookDescReader::new(scble_desc); let cb = Codebook::new(&mut cfr, CodebookMode::LSB).unwrap(); assert_eq!(brl.read_cb(&cb).unwrap(), 11); diff --git a/nihav-core/src/io/intcode.rs b/nihav-core/src/io/intcode.rs index a8437e8..5169b41 100644 --- a/nihav-core/src/io/intcode.rs +++ b/nihav-core/src/io/intcode.rs @@ -141,7 +141,7 @@ mod test { fn int_codes() { const GDATA: [u8; 6] = [0b000_001_01, 0b0_0110_011, 0b1_1000_100, 0b1_1010_101, 0b10_10111_1, 0b1000_0000]; let src = &GDATA; - let mut br = BitReader::new(src, src.len(), BitReaderMode::BE); + let mut br = BitReader::new(src, BitReaderMode::BE); for i in 0..11 { assert_eq!(br.read_code(UintCodeType::Golomb(5)).unwrap(), i); } diff --git a/nihav-duck/src/codecs/on2avc.rs b/nihav-duck/src/codecs/on2avc.rs index 8740389..dc229b0 100644 --- a/nihav-duck/src/codecs/on2avc.rs +++ b/nihav-duck/src/codecs/on2avc.rs @@ -1012,7 +1012,7 @@ impl NADecoder for AVCDecoder { if self.version == 500 { abuf = alloc_audio_buffer(self.ainfo, COEFFS, self.chmap.clone())?; let mut adata = abuf.get_abuf_f32().unwrap(); - let mut br = BitReader::new(src.as_slice(), src.len(), BitReaderMode::BE); + let mut br = BitReader::new(src.as_slice(), BitReaderMode::BE); self.decode_frame(&mut br, &mut adata, 0)?; } else { let mut offsets: Vec = Vec::new(); @@ -1034,7 +1034,7 @@ impl NADecoder for AVCDecoder { let mut adata = abuf.get_abuf_f32().unwrap(); let mut aoffset = 0; for (o, s) in offsets.iter().zip(sizes.iter()) { - let mut br = BitReader::new(&src[*o..], *s, BitReaderMode::BE); + let mut br = BitReader::new(&src[*o..][..*s], BitReaderMode::BE); self.decode_frame(&mut br, &mut adata, aoffset)?; aoffset += COEFFS; } diff --git a/nihav-duck/src/codecs/truemotion2.rs b/nihav-duck/src/codecs/truemotion2.rs index 469147f..0d937e0 100644 --- a/nihav-duck/src/codecs/truemotion2.rs +++ b/nihav-duck/src/codecs/truemotion2.rs @@ -149,7 +149,7 @@ impl TM2Stream { Ok(()) } fn read_deltas(&mut self, src: &[u8]) -> DecoderResult { - let mut br = BitReader::new(src, src.len(), BitReaderMode::LE32MSB); + let mut br = BitReader::new(src, BitReaderMode::LE32MSB); let coded_deltas = br.read(9)? as usize; let bits = br.read(5)? as u8; validate!((coded_deltas <= TM2_MAX_DELTAS) && (bits > 0)); @@ -168,7 +168,7 @@ impl TM2Stream { Ok(((br.tell() + 31) >> 5) << 2) } fn read_huff_tree(&mut self, src: &[u8], htree: &mut HuffTree) -> DecoderResult { - let mut br = BitReader::new(src, src.len(), BitReaderMode::LE32MSB); + let mut br = BitReader::new(src, BitReaderMode::LE32MSB); let val_bits = br.read(5)? as u8; let max_bits = br.read(5)? as u8; @@ -190,7 +190,7 @@ impl TM2Stream { Ok(((br.tell() + 31) >> 5) << 2) } fn read_tokens(&mut self, src: &[u8], htree: &HuffTree, ntoks: usize) -> DecoderResult { - let mut br = BitReader::new(src, src.len(), BitReaderMode::LE32MSB); + let mut br = BitReader::new(src, BitReaderMode::LE32MSB); if let Some(ref cb) = htree.cb { for _ in 0..ntoks { diff --git a/nihav-duck/src/codecs/truemotionrt.rs b/nihav-duck/src/codecs/truemotionrt.rs index 1aa8a29..2ea7a1b 100644 --- a/nihav-duck/src/codecs/truemotionrt.rs +++ b/nihav-duck/src/codecs/truemotionrt.rs @@ -63,7 +63,7 @@ impl NADecoder for TMRTDecoder { let bufinfo = alloc_video_buffer(myinfo, 2)?; let mut buf = bufinfo.get_vbuf().unwrap(); - let mut br = BitReader::new(&src[hdr_size..], src.len() - hdr_size, BitReaderMode::LE); + let mut br = BitReader::new(&src[hdr_size..], BitReaderMode::LE); let size = br.read(32)? as usize; validate!(size <= src.len() - hdr_size); for plane in 0..3 { diff --git a/nihav-duck/src/codecs/vp3.rs b/nihav-duck/src/codecs/vp3.rs index ccb0262..9a67388 100644 --- a/nihav-duck/src/codecs/vp3.rs +++ b/nihav-duck/src/codecs/vp3.rs @@ -1824,7 +1824,7 @@ impl NADecoder for VP34Decoder { fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { let src = pkt.get_buffer(); validate!(src.len() > 0); - let mut br = BitReader::new(&src, src.len(), BitReaderMode::BE); + let mut br = BitReader::new(&src, BitReaderMode::BE); self.parse_header(&mut br)?; if self.is_intra { diff --git a/nihav-duck/src/codecs/vp56.rs b/nihav-duck/src/codecs/vp56.rs index 3a691ed..de3a849 100644 --- a/nihav-duck/src/codecs/vp56.rs +++ b/nihav-duck/src/codecs/vp56.rs @@ -524,7 +524,7 @@ impl VP56Decoder { let bc2 = BoolCoder::new(&src[off..])?; cr = CoeffReader::Bool(bc2); } else { - let br = BitReader::new(&src[off..], aoffset - off, BitReaderMode::BE); + let br = BitReader::new(&src[off..aoffset], BitReaderMode::BE); cr = CoeffReader::Huff(br); } } else { diff --git a/nihav-duck/src/codecs/vp6.rs b/nihav-duck/src/codecs/vp6.rs index 82963fa..fdf6252 100644 --- a/nihav-duck/src/codecs/vp6.rs +++ b/nihav-duck/src/codecs/vp6.rs @@ -36,7 +36,7 @@ impl VP56Parser for VP6BR { let mut hdr = VP56Header::default(); // horrible hack to match VP6 header parsing let src = bc.src; - let mut br = BitReader::new(src, src.len(), BitReaderMode::BE); + let mut br = BitReader::new(src, BitReaderMode::BE); hdr.is_intra = !br.read_bool()?; hdr.is_golden = hdr.is_intra; diff --git a/nihav-indeo/src/codecs/imc.rs b/nihav-indeo/src/codecs/imc.rs index f8a4f28..b969a14 100644 --- a/nihav-indeo/src/codecs/imc.rs +++ b/nihav-indeo/src/codecs/imc.rs @@ -728,7 +728,7 @@ impl IMCDecoder { } fn decode_block(&mut self, data: &[u8], ch: usize, dst: &mut [f32]) -> DecoderResult<()> { - let mut br = BitReader::new(&data[BLOCK_SIZE*ch..], BLOCK_SIZE, BitReaderMode::LE16MSB); + let mut br = BitReader::new(&data[BLOCK_SIZE*ch..][..BLOCK_SIZE], BitReaderMode::LE16MSB); let hdr = br.read(9)?; validate!((hdr & 0x18) == 0); diff --git a/nihav-indeo/src/codecs/indeo2.rs b/nihav-indeo/src/codecs/indeo2.rs index 7556e6a..8126be0 100644 --- a/nihav-indeo/src/codecs/indeo2.rs +++ b/nihav-indeo/src/codecs/indeo2.rs @@ -326,7 +326,7 @@ impl NADecoder for Indeo2Decoder { if src.len() <= IR2_START { return Err(DecoderError::ShortData); } let interframe = src[18]; let tabs = src[34]; - let mut br = BitReader::new(&src[IR2_START..], src.len() - IR2_START, BitReaderMode::LE); + let mut br = BitReader::new(&src[IR2_START..], BitReaderMode::LE); let luma_tab = tabs & 3; let chroma_tab = (tabs >> 2) & 3; if interframe != 0 { diff --git a/nihav-indeo/src/codecs/indeo4.rs b/nihav-indeo/src/codecs/indeo4.rs index 7541bc1..d6bb283 100644 --- a/nihav-indeo/src/codecs/indeo4.rs +++ b/nihav-indeo/src/codecs/indeo4.rs @@ -446,7 +446,7 @@ impl NADecoder for Indeo4Decoder { } fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { let src = pkt.get_buffer(); - let mut br = BitReader::new(src.as_slice(), src.len(), BitReaderMode::LE); + let mut br = BitReader::new(src.as_slice(), BitReaderMode::LE); let mut ip = Indeo4Parser::new(); let bufinfo = self.dec.decode_frame(&mut ip, &mut br)?; diff --git a/nihav-indeo/src/codecs/indeo5.rs b/nihav-indeo/src/codecs/indeo5.rs index 045d4b7..47f2437 100644 --- a/nihav-indeo/src/codecs/indeo5.rs +++ b/nihav-indeo/src/codecs/indeo5.rs @@ -522,7 +522,7 @@ impl NADecoder for Indeo5Decoder { } fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { let src = pkt.get_buffer(); - let mut br = BitReader::new(src.as_slice(), src.len(), BitReaderMode::LE); + let mut br = BitReader::new(src.as_slice(), BitReaderMode::LE); let bufinfo = self.dec.decode_frame(&mut self.ip, &mut br)?; let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), bufinfo); diff --git a/nihav-indeo/src/codecs/intel263.rs b/nihav-indeo/src/codecs/intel263.rs index b42b5d2..3d767f9 100644 --- a/nihav-indeo/src/codecs/intel263.rs +++ b/nihav-indeo/src/codecs/intel263.rs @@ -43,7 +43,7 @@ fn check_marker<'a>(br: &mut BitReader<'a>) -> DecoderResult<()> { impl<'a> Intel263BR<'a> { fn new(src: &'a [u8], tables: &'a Tables) -> Self { Intel263BR { - br: BitReader::new(src, src.len(), BitReaderMode::BE), + br: BitReader::new(src, BitReaderMode::BE), tables, gob_no: 0, mb_w: 0, diff --git a/nihav-rad/src/codecs/bink2.rs b/nihav-rad/src/codecs/bink2.rs index 1ce05dd..9375bfa 100644 --- a/nihav-rad/src/codecs/bink2.rs +++ b/nihav-rad/src/codecs/bink2.rs @@ -1921,7 +1921,7 @@ impl NADecoder for Bink2Decoder { fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { let src = pkt.get_buffer(); - let mut br = BitReader::new(&src, src.len(), BitReaderMode::LE); + let mut br = BitReader::new(&src, BitReaderMode::LE); let mut buf; self.key_frame = pkt.is_keyframe(); diff --git a/nihav-rad/src/codecs/binkaud.rs b/nihav-rad/src/codecs/binkaud.rs index 9695ee4..48bc508 100644 --- a/nihav-rad/src/codecs/binkaud.rs +++ b/nihav-rad/src/codecs/binkaud.rs @@ -234,7 +234,7 @@ impl NADecoder for BinkAudioDecoder { if let NACodecTypeInfo::Audio(_) = info.get_properties() { let pktbuf = pkt.get_buffer(); validate!(pktbuf.len() > 1); - let mut br = BitReader::new(&pktbuf, pktbuf.len(), BitReaderMode::LE); + let mut br = BitReader::new(&pktbuf, BitReaderMode::LE); let nsamples = br.read(32)? as usize; // validate!(nsamples % self.duration == 0); diff --git a/nihav-rad/src/codecs/binkvid.rs b/nihav-rad/src/codecs/binkvid.rs index 89f9cf8..545c10e 100644 --- a/nihav-rad/src/codecs/binkvid.rs +++ b/nihav-rad/src/codecs/binkvid.rs @@ -1209,7 +1209,7 @@ impl NADecoder for BinkDecoder { fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { let src = pkt.get_buffer(); - let mut br = BitReader::new(&src, src.len(), BitReaderMode::LE); + let mut br = BitReader::new(&src, BitReaderMode::LE); let mut buf; self.key_frame = pkt.is_keyframe(); diff --git a/nihav-rad/src/codecs/smacker.rs b/nihav-rad/src/codecs/smacker.rs index c22362b..86b022c 100644 --- a/nihav-rad/src/codecs/smacker.rs +++ b/nihav-rad/src/codecs/smacker.rs @@ -413,7 +413,7 @@ impl NADecoder for SmackerVideoDecoder { let type_size = br.read_u32le()?; self.is_ver4 = (magic & 0xFF) == 0x34; - let mut br = BitReader::new(&edata[24..], edata.len() - 24, BitReaderMode::LE); + let mut br = BitReader::new(&edata[24..], BitReaderMode::LE); self.mmap_tree.decode(&mut br, mmap_size)?; self.mclr_tree.decode(&mut br, mclr_size)?; self.full_tree.decode(&mut br, full_size)?; @@ -442,7 +442,7 @@ impl NADecoder for SmackerVideoDecoder { let ftype; let bufinfo; if src.len() > PAL_SIZE { - let mut br = BitReader::new(&src[PAL_SIZE..], src.len() - PAL_SIZE, BitReaderMode::LE); + let mut br = BitReader::new(&src[PAL_SIZE..], BitReaderMode::LE); bufinfo = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 2)?; let mut buf = bufinfo.get_vbuf().unwrap(); @@ -509,7 +509,7 @@ impl NADecoder for SmackerAudioDecoder { if let NACodecTypeInfo::Audio(_) = info.get_properties() { let src = pkt.get_buffer(); validate!(src.len() > 4); - let mut br = BitReader::new(&src, src.len(), BitReaderMode::LE); + let mut br = BitReader::new(&src, BitReaderMode::LE); let unp_size = br.read(32)? as usize; if !br.read_bool()? { let mut frm = NAFrame::new_from_pkt(pkt, info.clone(), NABufferType::None); diff --git a/nihav-realmedia/src/codecs/cook.rs b/nihav-realmedia/src/codecs/cook.rs index 5d88be6..fe5ae71 100644 --- a/nihav-realmedia/src/codecs/cook.rs +++ b/nihav-realmedia/src/codecs/cook.rs @@ -302,7 +302,7 @@ impl CookChannelPair { for (i, b) in src.iter().enumerate() { buf[i] = b ^ COOK_XOR_KEY[i & 3]; } - let mut br = BitReader::new(buf, src.len(), BitReaderMode::BE); + let mut br = BitReader::new(&buf[..src.len()], BitReaderMode::BE); let num_gains = br.read_code(UintCodeType::UnaryOnes)? as usize; validate!(num_gains <= 8); diff --git a/nihav-realmedia/src/codecs/ra144.rs b/nihav-realmedia/src/codecs/ra144.rs index 394ab21..35090a6 100644 --- a/nihav-realmedia/src/codecs/ra144.rs +++ b/nihav-realmedia/src/codecs/ra144.rs @@ -267,7 +267,7 @@ impl NADecoder for RA144Decoder { let dst = adata.get_data_mut().unwrap(); for (input, output) in pktbuf.chunks(FRAME_SIZE).zip(dst.chunks_mut(NBLOCKS * BLOCKSIZE)) { - let mut br = BitReader::new(input, input.len(), BitReaderMode::BE); + let mut br = BitReader::new(input, BitReaderMode::BE); let mut lpc_refl: [i32; LPC_ORDER] = [0; LPC_ORDER]; for i in 0..LPC_ORDER { diff --git a/nihav-realmedia/src/codecs/ra288.rs b/nihav-realmedia/src/codecs/ra288.rs index 20008bb..416c64c 100644 --- a/nihav-realmedia/src/codecs/ra288.rs +++ b/nihav-realmedia/src/codecs/ra288.rs @@ -175,7 +175,7 @@ impl NADecoder for RA288Decoder { let dst = adata.get_data_mut().unwrap(); for (input, output) in pktbuf.chunks(FRAME_SIZE).zip(dst.chunks_mut(NBLOCKS * BLOCKSIZE)) { - let mut br = BitReader::new(input, input.len(), BitReaderMode::LE); + let mut br = BitReader::new(input, BitReaderMode::LE); for (i, block) in output.chunks_mut(BLOCKSIZE).enumerate() { let gain = RA288_GAIN_TAB[br.read(3)? as usize]; diff --git a/nihav-realmedia/src/codecs/ralf.rs b/nihav-realmedia/src/codecs/ralf.rs index b3cce73..c16075b 100644 --- a/nihav-realmedia/src/codecs/ralf.rs +++ b/nihav-realmedia/src/codecs/ralf.rs @@ -277,7 +277,7 @@ impl RALFDecoder { } } fn decode_block(&mut self, off: usize, size: usize, abuf: &mut NABufferType) -> DecoderResult<()> { - let mut br = BitReader::new(&self.pkt_buf[off..][..size], size, BitReaderMode::BE); + let mut br = BitReader::new(&self.pkt_buf[off..][..size], BitReaderMode::BE); let length = read_block_length(&mut br).unwrap(); validate!(length + self.sample_offset <= self.max_frame_size); @@ -428,7 +428,7 @@ impl NADecoder for RALFDecoder { validate!(src_len > table_bytes + 3); self.blocks.truncate(0); { - let mut br = BitReader::new(&self.pkt_buf[2..], table_bytes, BitReaderMode::BE); + let mut br = BitReader::new(&self.pkt_buf[2..][..table_bytes], BitReaderMode::BE); while br.tell() < table_bits { let size = br.read(13 + self.channels).unwrap() as usize; let pts; diff --git a/nihav-realmedia/src/codecs/rv10.rs b/nihav-realmedia/src/codecs/rv10.rs index 2426cd8..6a7325f 100644 --- a/nihav-realmedia/src/codecs/rv10.rs +++ b/nihav-realmedia/src/codecs/rv10.rs @@ -67,7 +67,7 @@ impl<'a> RealVideo10BR<'a> { let mut slice_offs = Vec::with_capacity(nslices); { let offs = &src[1..][..nslices * 8]; - let mut br = BitReader::new(offs, offs.len(), BitReaderMode::BE); + let mut br = BitReader::new(offs, BitReaderMode::BE); for _ in 0..nslices { br.skip(32).unwrap(); let off = br.read(32).unwrap(); @@ -76,7 +76,7 @@ impl<'a> RealVideo10BR<'a> { } let soff = nslices * 8 + 1; RealVideo10BR { - br: BitReader::new(&src[soff..], src.len() - soff, BitReaderMode::BE), + br: BitReader::new(&src[soff..], BitReaderMode::BE), tables, num_slices: nslices, slice_no: 0, @@ -425,7 +425,7 @@ println!("ver {:06X} -> {}", ver, mic_ver); self.mvmode = MVMode::UMV; } { -let mut br = BitReader::new(src, src.len(), BitReaderMode::BE); +let mut br = BitReader::new(src, BitReaderMode::BE); println!("edata:"); println!("{:08X}", br.read(32).unwrap()); println!("{:08X}", br.read(32).unwrap()); diff --git a/nihav-realmedia/src/codecs/rv20.rs b/nihav-realmedia/src/codecs/rv20.rs index 1db190f..3b79110 100644 --- a/nihav-realmedia/src/codecs/rv20.rs +++ b/nihav-realmedia/src/codecs/rv20.rs @@ -78,7 +78,7 @@ impl<'a> RealVideo20BR<'a> { let mut slice_offs = Vec::with_capacity(nslices); { let offs = &src[1..][..nslices * 8]; - let mut br = BitReader::new(offs, offs.len(), BitReaderMode::BE); + let mut br = BitReader::new(offs, BitReaderMode::BE); for _ in 0..nslices { br.skip(32).unwrap(); let off = br.read(32).unwrap(); @@ -97,7 +97,7 @@ impl<'a> RealVideo20BR<'a> { } } RealVideo20BR { - br: BitReader::new(&src[soff..], src.len() - soff, BitReaderMode::BE), + br: BitReader::new(&src[soff..], BitReaderMode::BE), tables, num_slices: nslices, slice_no: 0, diff --git a/nihav-realmedia/src/codecs/rv3040.rs b/nihav-realmedia/src/codecs/rv3040.rs index 39549eb..f3d1743 100644 --- a/nihav-realmedia/src/codecs/rv3040.rs +++ b/nihav-realmedia/src/codecs/rv3040.rs @@ -514,7 +514,7 @@ fn parse_slice_offsets(src: &[u8], offsets: &mut Vec) -> DecoderResult<() if ini_off >= src.len() { return Err(DecoderError::ShortData); } - let mut br = BitReader::new(&src[1..], ini_off - 1, BitReaderMode::BE); + let mut br = BitReader::new(&src[1..ini_off], BitReaderMode::BE); for i in 0..num_slices { br.skip(32)?; @@ -1080,7 +1080,7 @@ impl RV34Decoder { parse_slice_offsets(src, &mut slice_offs)?; let ini_off = slice_offs.len() * 8 + 1; - let mut br = BitReader::new(&src[ini_off..], src.len() - ini_off, BitReaderMode::BE); + let mut br = BitReader::new(&src[ini_off..], BitReaderMode::BE); let hdr0 = decode_slice_header(&mut br, bd, 0, slice_offs.as_slice(), self.width, self.height)?; validate!((hdr0.width != 0) && (hdr0.height != 0)); self.width = hdr0.width; diff --git a/nihav-realmedia/src/codecs/rv60.rs b/nihav-realmedia/src/codecs/rv60.rs index 9fee646..827f7e0 100644 --- a/nihav-realmedia/src/codecs/rv60.rs +++ b/nihav-realmedia/src/codecs/rv60.rs @@ -682,7 +682,7 @@ impl RealVideo60Decoder { } } fn decode_cu_line(&mut self, buf: &mut NASimpleVideoFrame, hdr: &FrameHeader, src: &[u8], cu_y: usize) -> DecoderResult<()> { - let mut br = BitReader::new(src, src.len(), BitReaderMode::BE); + 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; @@ -1439,7 +1439,7 @@ println!("???"); validate!(src.len() > 9); let hsize = (src[0] as usize) * 8 + 9; - let mut br = BitReader::new(&src[hsize..], src.len() - hsize, BitReaderMode::BE); + let mut br = BitReader::new(&src[hsize..], BitReaderMode::BE); let hdr = FrameHeader::read(&mut br)?; let mut slices: Vec = Vec::new(); hdr.parse_slice_sizes(&mut br, &mut slices)?;