}
}
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);
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)?;
}
{
- 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)?;
} 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);
}
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)?;
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() {
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);
}
cache: u64,
bits: u8,
pos: usize,
- end: usize,
src: &'a [u8],
mode: BitReaderMode,
}
#[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 {
}
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]) {
#[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),
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;
}
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)
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);
}
}
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);
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);
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);
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);
}
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<usize> = Vec::new();
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;
}
Ok(())
}
fn read_deltas(&mut self, src: &[u8]) -> DecoderResult<usize> {
- 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));
Ok(((br.tell() + 31) >> 5) << 2)
}
fn read_huff_tree(&mut self, src: &[u8], htree: &mut HuffTree) -> DecoderResult<usize> {
- 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;
Ok(((br.tell() + 31) >> 5) << 2)
}
fn read_tokens(&mut self, src: &[u8], htree: &HuffTree, ntoks: usize) -> DecoderResult<usize> {
- 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 {
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 {
fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
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 {
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 {
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;
}
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);
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 {
}
fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
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)?;
}
fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
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);
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,
fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
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();
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);
fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
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();
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)?;
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();
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);
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);
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 {
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];
}
}
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);
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;
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();
}
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,
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());
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();
}
}
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,
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)?;
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;
}
}
fn decode_cu_line(&mut self, buf: &mut NASimpleVideoFrame<u8>, 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;
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<usize> = Vec::new();
hdr.parse_slice_sizes(&mut br, &mut slices)?;