let dst = adata.get_data_mut().unwrap();
for blk in pktbuf.chunks_exact(self.block_len) {
- let mut mr = MemoryReader::new_read(blk);
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(blk);
if self.is_dk3 {
let _typeid = br.read_byte()?;
let _version = br.read_byte()?;
for i in 1..hdr_size {
hdr[i - 1] = src[i] ^ src[i + 1];
}
- let mut mr = MemoryReader::new_read(&hdr[0..hdr_size-1]);
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(&hdr[0..hdr_size-1]);
let tm1type = br.read_byte()? as usize;
let delta_set = br.read_byte()? as usize;
}
let mut dbuf = Vec::with_capacity(4);
- let mut gw = GrowableMemoryWriter::new_write(&mut dbuf);
- let mut bw = ByteWriter::new(&mut gw);
+ let mut bw = GrowableMemoryWriter::new_write(&mut dbuf);
self.tm1type = match (self.is16, self.block_mode) {
(true, BlockMode::FourByFour) => 2,
const TM2_ESCAPE: usize = 0x80000000;
-impl<'a> ReadLenEsc for ByteReader<'a> {
+impl<T: ?Sized + ByteIO> ReadLenEsc for T {
fn read_len_esc(&mut self) -> DecoderResult<usize> {
let len = self.read_u32le()? as usize;
if len == TM2_ESCAPE {
}
impl TM2Stream {
- fn read_header(&mut self, src: &[u8], br: &mut ByteReader) -> DecoderResult<()> {
+ fn read_header(&mut self, src: &[u8], br: &mut dyn ByteIO) -> DecoderResult<()> {
self.tokens.clear();
self.pos = 0;
fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
let src = pkt.get_buffer();
validate!(src.len() >= 40 + (TM2StreamType::Num as usize) * 4 + 4);
- let mut mr = MemoryReader::new_read(&src);
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(&src);
let magic = br.read_u32be()?;
validate!(magic == 0x100 || magic == 0x101);
}
impl Deltas {
- fn reset(&mut self, br: &mut ByteReader) -> DecoderResult<()> {
+ fn reset(&mut self, br: &mut dyn ByteIO) -> DecoderResult<()> {
let b = br.read_byte()? as usize;
self.vq_idx = b;
self.vq_pos = 0;
Ok(())
}
- fn get_val(&mut self, br: &mut ByteReader) -> DecoderResult<u8> {
+ fn get_val(&mut self, br: &mut dyn ByteIO) -> DecoderResult<u8> {
if self.vq_idx > self.codebook.len() { return Err(DecoderError::ShortData); }
let ret = self.codebook[self.vq_idx][self.vq_pos];
self.vq_pos += 1;
-1 - hval
}
}
- fn get_int(&mut self, br: &mut ByteReader) -> DecoderResult<i16> {
+ fn get_int(&mut self, br: &mut dyn ByteIO) -> DecoderResult<i16> {
let b = self.get_val(br)?;
if b != self.vq_esc - 1 {
return Ok(Self::remap(u16::from(b)));
}
Ok(Self::remap(val))
}
- fn get_dy(&mut self, br: &mut ByteReader) -> DecoderResult<i16> {
+ fn get_dy(&mut self, br: &mut dyn ByteIO) -> DecoderResult<i16> {
let b = self.get_val(br)?;
Ok(self.tabs[1][b as usize])
}
- fn get_dc(&mut self, br: &mut ByteReader) -> DecoderResult<i16> {
+ fn get_dc(&mut self, br: &mut dyn ByteIO) -> DecoderResult<i16> {
let b = self.get_val(br)?;
Ok(self.tabs[0][b as usize])
}
fn parse_init(&mut self, version: u8) -> DecoderResult<()> {
self.version = version;
- let mut mr = MemoryReader::new_read(&self.dec_buf);
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(&self.dec_buf);
if version > 4 {
let _smth = br.read_u32be()?;
}
Ok(())
}
fn parse_tabs(&mut self) -> DecoderResult<()> {
- let mut mr = MemoryReader::new_read(&self.dec_buf);
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(&self.dec_buf);
let idx = br.read_byte()? as usize;
validate!(idx < self.deltas.tabs.len());
Ok(())
}
fn parse_cb_desc(&mut self, version: u8) -> DecoderResult<()> {
- let mut mr = MemoryReader::new_read(&self.dec_buf);
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(&self.dec_buf);
if version == 0x0A {
self.deltas.vq_esc = br.read_byte()?;
#[allow(clippy::cognitive_complexity)]
#[allow(clippy::identity_op)]
fn decode_frame(&mut self, src: &[u8]) -> DecoderResult<()> {
- let mut mr = MemoryReader::new_read(src);
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(src);
self.deltas.reset(&mut br)?;
let bw = self.width / 8;
fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
let src = pkt.get_buffer();
validate!(src.len() > 8);
- let mut mr = MemoryReader::new_read(&src);
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(&src);
let mut dec = Decryptor::default();
let mut initialised = false;
let buf = frm.get_buffer();
if let Some(ref vbuf) = buf.get_vbuf() {
let mut dbuf = Vec::with_capacity(4);
- let mut gw = GrowableMemoryWriter::new_write(&mut dbuf);
- let mut bw = ByteWriter::new(&mut gw);
+ let mut bw = GrowableMemoryWriter::new_write(&mut dbuf);
bw.write_byte(0)?; // header size
bw.write_byte(17)?;
fn write_zero_run(&mut self, val: usize, probs: &[u8; 14]) -> EncoderResult<()>;
}
-impl<'a, 'b> EncoderTrait for BoolEncoder<'a, 'b> {
+impl<'a> EncoderTrait for BoolEncoder<'a> {
fn write_cat(&mut self, cat: i8, tree: &[TokenSeq<i8>], tok_probs: &[u8], val_probs: &[u8; 11]) -> EncoderResult<()> {
for entry in tree.iter() {
if entry.val == cat {
pub const MAX_EOB_RUN: usize = 63 + 10;
-pub struct HuffEncoder<'a, 'b> {
- bw: &'a mut ByteWriter<'b>,
+pub struct HuffEncoder<'a> {
+ bw: &'a mut dyn ByteIO,
bitbuf: u32,
bits: u8,
}
-impl<'a, 'b> HuffEncoder<'a, 'b> {
- pub fn new(bw: &'a mut ByteWriter<'b>) -> Self {
+impl<'a> HuffEncoder<'a> {
+ pub fn new(bw: &'a mut dyn ByteIO) -> Self {
Self {
bitbuf: 0,
bits: 0,
const VERSION_VP61: u8 = VERSION_VP60 + 1;
-enum VP6Writer<'a, 'b> {
- BoolCoder(BoolEncoder<'a, 'b>),
- Huffman(HuffEncoder<'a, 'b>),
+enum VP6Writer<'a> {
+ BoolCoder(BoolEncoder<'a>),
+ Huffman(HuffEncoder<'a>),
}
#[derive(Default)]
}
}
}
- fn encode_intra(&mut self, bw: &mut ByteWriter, quant: usize) -> EncoderResult<bool> {
+ fn encode_intra(&mut self, bw: &mut dyn ByteIO, quant: usize) -> EncoderResult<bool> {
self.models.reset(false);
self.models.reset_mbtype_models();
self.stats.reset();
self.encode_coeffs(writer)?;
Ok(true)
}
- fn encode_inter(&mut self, bw: &mut ByteWriter, quant: usize) -> EncoderResult<bool> {
+ fn encode_inter(&mut self, bw: &mut dyn ByteIO, quant: usize) -> EncoderResult<bool> {
self.stats.reset();
let multistream = self.huffman || self.version != VERSION_VP60;
Ok(golden_frame)
}
- fn write_inter_frame(&mut self, bw: &mut ByteWriter, quant: usize, multistream: bool, loop_filter: bool, golden_frame: bool) -> EncoderResult<()> {
+ fn write_inter_frame(&mut self, bw: &mut dyn ByteIO, quant: usize, multistream: bool, loop_filter: bool, golden_frame: bool) -> EncoderResult<()> {
self.estimate_blocks(false);
self.stats.generate(&mut self.models, false);
Ok(())
}
- fn encode_inter_fast(&mut self, bw: &mut ByteWriter, quant: usize) -> EncoderResult<bool> {
+ fn encode_inter_fast(&mut self, bw: &mut dyn ByteIO, quant: usize) -> EncoderResult<bool> {
self.stats.reset();
let multistream = self.huffman || self.version != VERSION_VP60;
let buf = frm.get_buffer();
if let Some(ref vbuf) = buf.get_vbuf() {
let mut dbuf = Vec::with_capacity(4);
- let mut gw = GrowableMemoryWriter::new_write(&mut dbuf);
- let mut bw = ByteWriter::new(&mut gw);
+ let mut bw = GrowableMemoryWriter::new_write(&mut dbuf);
// todo integrate with rate control
let is_intra = (self.frmcount == 0) || self.decide_encoding();
fn encode_mb_type(&mut self, is_intra: bool, mb_type: &MBType, models: &VP7Models) -> EncoderResult<()>;
}
-impl<'a, 'b> VP7BoolEncoder for BoolEncoder<'a, 'b> {
+impl<'a> VP7BoolEncoder for BoolEncoder<'a> {
fn put_byte(&mut self, val: u8) -> EncoderResult<()> {
self.put_bits(u32::from(val), 8)
}
self.fenc.load_frame(vbuf);
let mut dbuf = Vec::with_capacity(4);
- let mut gw = GrowableMemoryWriter::new_write(&mut dbuf);
- let mut bw = ByteWriter::new(&mut gw);
+ let mut bw = GrowableMemoryWriter::new_write(&mut dbuf);
let is_intra = self.frmcount == 0;
let golden_frame = is_intra;
};
}
-pub struct BoolEncoder<'a, 'b> {
- bw: &'a mut ByteWriter<'b>,
+pub struct BoolEncoder<'a> {
+ bw: &'a mut dyn ByteIO,
val: u32,
range: u32,
bits: u8,
run: usize,
}
-impl<'a, 'b> BoolEncoder<'a, 'b> {
- pub fn new(bw: &'a mut ByteWriter<'b>) -> Self {
+impl<'a> BoolEncoder<'a> {
+ pub fn new(bw: &'a mut dyn ByteIO) -> Self {
Self {
bw,
val: 0,
use nihav_core::demuxers::*;
struct IVFDemuxer<'a> {
- src: &'a mut ByteReader<'a>,
+ src: &'a mut dyn ByteIO,
nframes: u32,
frameno: u32,
}
impl<'a> IVFDemuxer<'a> {
- fn new(src: &'a mut ByteReader<'a>) -> Self {
+ fn new(src: &'a mut dyn ByteIO) -> Self {
IVFDemuxer {
src,
nframes: 0,
pub struct IVFDemuxerCreator { }
impl DemuxerCreator for IVFDemuxerCreator {
- fn new_demuxer<'a>(&self, br: &'a mut ByteReader<'a>) -> Box<dyn DemuxCore<'a> + 'a> {
+ fn new_demuxer<'a>(&self, br: &'a mut dyn ByteIO) -> Box<dyn DemuxCore<'a> + 'a> {
Box::new(IVFDemuxer::new(br))
}
fn get_name(&self) -> &'static str { "dkivf" }
fn test_ivf_demux() {
// sample is from the official VP8 test bitstream set
let mut file = File::open("assets/Duck/VP8/vp80-00-comprehensive-001.ivf").unwrap();
- let mut fr = FileReader::new_read(&mut file);
- let mut br = ByteReader::new(&mut fr);
+ let mut br = FileReader::new_read(&mut file);
let mut dmx = IVFDemuxer::new(&mut br);
let mut sm = StreamManager::new();
let mut si = SeekIndex::new();