let edata = info.get_extradata().unwrap();
validate!(edata.len() >= 4);
- let mut mr = MemoryReader::new_read(&edata);
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(&edata);
match edata.len() {
10 => {
-use nihav_core::io::byteio::{ByteReader,MemoryReader};
+use nihav_core::io::byteio::{ByteIO,MemoryReader};
use nihav_core::formats::YUV420_FORMAT;
use nihav_core::codecs::*;
use nihav_codec_support::codecs::HAMShuffler;
mode: DecodeMode::Unknown,
}
}
- fn read_cb(br: &mut ByteReader, size: usize, cb: &mut [[u8; 6]; 256], is_yuv: bool) -> DecoderResult<()> {
+ fn read_cb(br: &mut dyn ByteIO, size: usize, cb: &mut [[u8; 6]; 256], is_yuv: bool) -> DecoderResult<()> {
let cb_elem = if is_yuv { 6 } else { 4 };
let cb_size = (size - 4) / cb_elem;
validate!(size - 4 == cb_size * cb_elem);
}
Ok(())
}
- fn read_cb_upd(br: &mut ByteReader, size: usize, cb: &mut [[u8; 6]; 256], is_yuv: bool) -> DecoderResult<()> {
+ fn read_cb_upd(br: &mut dyn ByteIO, size: usize, cb: &mut [[u8; 6]; 256], is_yuv: bool) -> DecoderResult<()> {
let cb_elem = if is_yuv { 6 } else { 4 };
let end = br.tell() + (size as u64) - 4;
for i in (0..256).step_by(32) {
}
#[allow(clippy::too_many_arguments)]
fn decode_strip(&mut self, src: &[u8], sno: usize, is_intra: bool, is_intra_strip: bool, xoff: usize, yoff: usize, xend: usize, yend: usize, frm: &mut NASimpleVideoFrame<u8>) -> DecoderResult<()> {
- let mut mr = MemoryReader::new_read(src);
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(src);
let mut idx_pos = 0;
let mut idx_size = 0;
let mut v1_only = false;
};
}
validate!(idx_pos != 0);
- let mut mr = MemoryReader::new_read(&src[idx_pos..][..idx_size]);
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(&src[idx_pos..][..idx_size]);
let mut x = xoff;
let mut y = yoff;
let src = pkt.get_buffer();
if src.len() <= 10 { return Err(DecoderError::ShortData); }
- let mut mr = MemoryReader::new_read(src.as_slice());
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(src.as_slice());
let flags = br.read_byte()?;
let size = br.read_u24be()? as usize;
}
}
-fn patch_size(bw: &mut ByteWriter, pos: u64) -> EncoderResult<()> {
+fn patch_size(bw: &mut dyn ByteIO, pos: u64) -> EncoderResult<()> {
let size = bw.tell() - pos;
bw.seek(SeekFrom::Current(-((size + 3) as i64)))?;
bw.write_u24be((size + 4) as u32)?;
let upd_size = cb_size * (new_cb.len() - skip_count) + (new_cb.len() + 31) / 32 * 4;
upd_size < full_size
}
- fn write_cb(bw: &mut ByteWriter, mut id: u8, new_cb: &[YUVCode], old_cb: &[YUVCode], grayscale: bool, update: bool, num_elem: usize) -> EncoderResult<()> {
+ fn write_cb(bw: &mut dyn ByteIO, mut id: u8, new_cb: &[YUVCode], old_cb: &[YUVCode], grayscale: bool, update: bool, num_elem: usize) -> EncoderResult<()> {
if grayscale {
id |= 4;
}
for e in self.v1_cur_cb[self.cur_strip].iter_mut().skip(self.v1_len) { *e = YUVCode::default(); }
for e in self.v4_cur_cb[self.cur_strip].iter_mut().skip(self.v4_len) { *e = YUVCode::default(); }
}
- fn encode_intra(&mut self, bw: &mut ByteWriter, in_frm: &NAVideoBuffer<u8>) -> EncoderResult<bool> {
+ fn encode_intra(&mut self, bw: &mut dyn ByteIO, in_frm: &NAVideoBuffer<u8>) -> EncoderResult<bool> {
let (width, height) = in_frm.get_dimensions(0);
let mut strip_h = (height / self.nstrips + 3) & !3;
if strip_h == 0 {
patch_size(bw, frame_data_pos)?;
Ok(true)
}
- fn encode_inter(&mut self, bw: &mut ByteWriter, in_frm: &NAVideoBuffer<u8>) -> EncoderResult<bool> {
+ fn encode_inter(&mut self, bw: &mut dyn ByteIO, in_frm: &NAVideoBuffer<u8>) -> EncoderResult<bool> {
let (width, height) = in_frm.get_dimensions(0);
let mut strip_h = (height / self.nstrips + 3) & !3;
if strip_h == 0 {
}
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 = if self.frmcount == 0 {
self.encode_intra(&mut bw, vbuf)?
} else {
-use nihav_core::io::byteio::{ByteReader,MemoryReader};
+use nihav_core::io::byteio::{ByteIO,MemoryReader};
use nihav_core::io::bitreader::*;
use nihav_core::io::codebook::*;
use nihav_core::formats;
if edata.len() == 0 || edata.len() < 0x60 { // no or short extradata probably comes from MOV
self.tsize = 4;
} else if !self.is_rm {
- let mut mr = MemoryReader::new_read(edata.as_slice());
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(edata.as_slice());
br.read_skip(0x5E).unwrap();
let tile_size = br.read_u32le()?;
self.tsize = tile_size.trailing_zeros() as u8;
} else {
- let mut mr = MemoryReader::new_read(edata.as_slice());
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(edata.as_slice());
br.read_skip(0x86).unwrap();
let tile_size = br.read_u32be()?;
self.tsize = tile_size.trailing_zeros() as u8;
}
}
- let mut mr = MemoryReader::new_read(&src);
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(&src);
let tag = br.read_byte()?;
validate!(tag == 0x2C);
let left = usize::from(br.read_u16le()?);
tmp: Vec::new(),
}
}
- fn compress(&mut self, writer: &mut ByteWriter, src: &[u8]) -> EncoderResult<()> {
+ fn compress(&mut self, writer: &mut dyn ByteIO, src: &[u8]) -> EncoderResult<()> {
let clr_bits: u8 = if self.level != CompressionLevel::None {
let maxclr = u16::from(src.iter().fold(0u8, |acc, &a| acc.max(a))) + 1;
let mut bits = 2;
tr_idx: None,
}
}
- fn write_dummy_frame(&mut self, bw: &mut ByteWriter) -> EncoderResult<()> {
+ fn write_dummy_frame(&mut self, bw: &mut dyn ByteIO) -> EncoderResult<()> {
let mut pix = [self.cur_frm[0]];
if let (true, Some(tr_idx)) = (self.p_trans, self.tr_idx) {
if tr_idx < pix[0] {
}
fn encode(&mut self, frm: &NAFrame) -> EncoderResult<()> {
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.tmp_buf.clear();
-use nihav_core::io::byteio::{ByteReader,MemoryReader};
+use nihav_core::io::byteio::{ByteIO,MemoryReader};
use nihav_core::io::bitreader::*;
use nihav_core::io::codebook::*;
use nihav_core::codecs::*;
self.depth = 0;
}
- fn parse_sof(&mut self, br: &mut ByteReader) -> DecoderResult<NABufferType> {
+ fn parse_sof(&mut self, br: &mut dyn ByteIO) -> DecoderResult<NABufferType> {
validate!(self.width == 0);
let len = br.read_u16be()? as usize;
if src.len() <= 4 { return Err(DecoderError::ShortData); }
let mut bufinfo = NABufferType::None;
- let mut mr = MemoryReader::new_read(&src);
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(&src);
let start_tag = br.read_u16be()?;
validate!(start_tag == 0xFFD8);
let is_be = info.format.be;
$dvec = vec![0u8; len * channels * std::mem::size_of::<$dtype>()];
- let mut mw = MemoryWriter::new_write($dvec.as_mut_slice());
- let mut bw = ByteWriter::new(&mut mw);
+ let mut bw = MemoryWriter::new_write($dvec.as_mut_slice());
for off in 0..len {
for j in 0..channels {
if is_be {
sent_pal: false,
}
}
- fn encode_intra(&mut self, bw: &mut ByteWriter, buf: NABufferType) -> EncoderResult<()> {
+ fn encode_intra(&mut self, bw: &mut dyn ByteIO, buf: NABufferType) -> EncoderResult<()> {
let mut bpp = buf_type_to_bpp(&buf);
if let NABufferType::None = buf {
Ok(())
}
- fn encode_inter(&mut self, bw: &mut ByteWriter, buf: NABufferType) -> EncoderResult<()> {
+ fn encode_inter(&mut self, bw: &mut dyn ByteIO, buf: NABufferType) -> EncoderResult<()> {
if let NABufferType::None = buf {
self.frm1.copy_from_slice(&self.frm2);
fn encode(&mut self, frm: &NAFrame) -> EncoderResult<()> {
let buf = frm.get_buffer();
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 = if self.frmcount == 0 {
self.encode_intra(&mut bw, buf)?;
true
}
struct AVIDemuxer<'a> {
- src: &'a mut ByteReader<'a>,
+ src: &'a mut dyn ByteIO,
cur_frame: Vec<u64>,
num_streams: u8,
size: usize,
}
impl<'a> AVIDemuxer<'a> {
- fn new(io: &'a mut ByteReader<'a>) -> Self {
+ fn new(io: &'a mut dyn ByteIO) -> Self {
AVIDemuxer {
cur_frame: Vec::new(),
num_streams: 0,
Ok(size)
}
-fn parse_idx1(src: &mut ByteReader, strmgr: &mut StreamManager, seek_idx: &mut SeekIndex, size: usize, movi_pos: u64, key_offs: &mut Vec<u64>) -> DemuxerResult<usize> {
+fn parse_idx1(src: &mut dyn ByteIO, strmgr: &mut StreamManager, seek_idx: &mut SeekIndex, size: usize, movi_pos: u64, key_offs: &mut Vec<u64>) -> DemuxerResult<usize> {
validate!((size & 15) == 0);
let mut tag = [0u8; 4];
let num_entries = size >> 4;
Ok(size)
}
-fn parse_iddx_data(src: &mut ByteReader, strmgr: &mut StreamManager, seek_idx: &mut SeekIndex, size: usize, movi_pos: u64, key_offs: &mut Vec<u64>) -> DemuxerResult<(usize, bool)> {
+fn parse_iddx_data(src: &mut dyn ByteIO, strmgr: &mut StreamManager, seek_idx: &mut SeekIndex, size: usize, movi_pos: u64, key_offs: &mut Vec<u64>) -> DemuxerResult<(usize, bool)> {
validate!((size & 15) == 0);
let mut tag = [0u8; 4];
let num_entries = size >> 4;
Ok((size, odd_offset))
}
-fn parse_odml_ix(src: &mut ByteReader, strmgr: &mut StreamManager, seek_idx: &mut SeekIndex, stream_no: usize, size: usize, start: u64) -> DemuxerResult<u64> {
+fn parse_odml_ix(src: &mut dyn ByteIO, strmgr: &mut StreamManager, seek_idx: &mut SeekIndex, stream_no: usize, size: usize, start: u64) -> DemuxerResult<u64> {
validate!(size >= 24);
let entry_size = src.read_u16le()? as usize;
if entry_size != 2 {
pub struct AVIDemuxerCreator { }
impl DemuxerCreator for AVIDemuxerCreator {
- 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(AVIDemuxer::new(br))
}
fn get_name(&self) -> &'static str { "avi" }
fn test_avi_demux() {
//test sample: https://samples.mplayerhq.hu/V-codecs/RT21/320x240/laser05.avi
let mut file = File::open("assets/Indeo/laser05.avi").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 = AVIDemuxer::new(&mut br);
let mut sm = StreamManager::new();
let mut si = SeekIndex::new();
use nihav_core::demuxers::*;
struct GIFDemuxer<'a> {
- src: &'a mut ByteReader<'a>,
+ src: &'a mut dyn ByteIO,
frameno: u64,
is_87: bool,
pal: Arc<[u8; 1024]>,
}
impl<'a> GIFDemuxer<'a> {
- fn new(io: &'a mut ByteReader<'a>) -> Self {
+ fn new(io: &'a mut dyn ByteIO) -> Self {
Self {
src: io,
frameno: 0,
pub struct GIFDemuxerCreator { }
impl DemuxerCreator for GIFDemuxerCreator {
- 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(GIFDemuxer::new(br))
}
fn get_name(&self) -> &'static str { "gif" }
fn test_gif_demux() {
// sample: https://samples.mplayerhq.hu/image-samples/GIF/3D.gif
let mut file = File::open("assets/Misc/3D.gif").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 = GIFDemuxer::new(&mut br);
let mut sm = StreamManager::new();
let mut si = SeekIndex::new();
fn skip64(&mut self, size: u64) -> ByteIOResult<()>;
}
-impl<'a> Skip64 for ByteReader<'a> {
+impl<T: ?Sized + ByteIO> Skip64 for T {
fn skip64(&mut self, size: u64) -> ByteIOResult<()> {
if (size as usize as u64) != size {
self.seek(SeekFrom::Current(size as i64))?;
}
}
-fn read_chunk_header(br: &mut ByteReader) -> DemuxerResult<(u32, u64)> {
+fn read_chunk_header(br: &mut dyn ByteIO) -> DemuxerResult<(u32, u64)> {
let size = br.read_u32be()?;
let ctype = br.read_u32be()?;
if size == 0 {
}
}
-fn read_palette(br: &mut ByteReader, size: u64, pal: &mut [u8; 1024]) -> DemuxerResult<u64> {
+fn read_palette(br: &mut dyn ByteIO, size: u64, pal: &mut [u8; 1024]) -> DemuxerResult<u64> {
let _seed = br.read_u32be()?;
let flags = br.read_u16be()?;
let palsize = (br.read_u16be()? as usize) + 1;
struct TrackChunkHandler {
ctype: u32,
- parse: fn(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64>,
+ parse: fn(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64>,
}
const IGNORED_CHUNKS: &[u32] = &[
}
};
(track; $name: expr, $fname: ident, $handlers: ident) => {
- fn $fname(&mut self, br: &mut ByteReader, size: u64) -> DemuxerResult<()> {
+ fn $fname(&mut self, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<()> {
self.depth += 1;
validate!(self.depth < 32);
let list_end = br.tell() + size;
}
}
-fn skip_chunk(_track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn skip_chunk(_track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
br.skip64(size)?;
Ok(size)
}
}
let len = ret.unwrap();
validate!(len == uncomp_size);
- let mut mr = MemoryReader::new_read(dbuf.as_slice());
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(dbuf.as_slice());
let (ctype, csize) = read_chunk_header(&mut br)?;
validate!(ctype == mktag!(b"moov"));
let mut ddmx = MOVDemuxer::new(&mut br);
TrackChunkHandler { ctype: mktag!(b"mdia"), parse: read_mdia },
];
-fn read_tkhd(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_tkhd(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
const KNOWN_TKHD_SIZE: u64 = 84;
validate!(size >= KNOWN_TKHD_SIZE);
let version = br.read_byte()?;
Ok(KNOWN_TKHD_SIZE)
}
-fn read_mdia(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_mdia(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
track.stream_type = StreamType::None;
track.read_mdia(br, size)?;
Ok(size)
TrackChunkHandler { ctype: mktag!(b"minf"), parse: read_minf },
];
-fn read_mdhd(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_mdhd(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
const KNOWN_MDHD_SIZE: u64 = 24;
validate!(size >= KNOWN_MDHD_SIZE);
let version = br.read_byte()?;
Ok(KNOWN_MDHD_SIZE)
}
-fn read_hdlr(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_hdlr(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
const KNOWN_HDLR_SIZE: u64 = 24;
validate!(size >= KNOWN_HDLR_SIZE);
let version = br.read_byte()?;
Ok(KNOWN_HDLR_SIZE)
}
-fn read_minf(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_minf(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
track.read_minf(br, size)?;
Ok(size)
}
TrackChunkHandler { ctype: mktag!(b"stbl"), parse: read_stbl },
];
-fn read_vmhd(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_vmhd(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
const KNOWN_VMHD_SIZE: u64 = 12;
validate!(track.stream_type == StreamType::Video);
validate!(size >= KNOWN_VMHD_SIZE);
Ok(KNOWN_VMHD_SIZE)
}
-fn read_smhd(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_smhd(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
const KNOWN_SMHD_SIZE: u64 = 8;
validate!(track.stream_type == StreamType::Audio);
validate!(size >= KNOWN_SMHD_SIZE);
Ok(KNOWN_SMHD_SIZE)
}
-fn read_gmhd(track: &mut Track, _br: &mut ByteReader, _size: u64) -> DemuxerResult<u64> {
+fn read_gmhd(track: &mut Track, _br: &mut dyn ByteIO, _size: u64) -> DemuxerResult<u64> {
validate!(track.stream_type == StreamType::Data);
Ok(0)
}
-fn read_gmin(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_gmin(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
validate!(track.stream_type == StreamType::Data);
const KNOWN_GMIN_SIZE: u64 = 16;
validate!(size >= KNOWN_GMIN_SIZE);
Ok(KNOWN_GMIN_SIZE)
}
-fn read_stbl(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_stbl(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
track.read_stbl(br, size)?;
Ok(size)
}
TrackChunkHandler { ctype: mktag!(b"ctts"), parse: read_ctts },
];
-fn parse_audio_edata(br: &mut ByteReader, start_pos: u64, size: u64) -> DemuxerResult<Option<Vec<u8>>> {
+fn parse_audio_edata(br: &mut dyn ByteIO, start_pos: u64, size: u64) -> DemuxerResult<Option<Vec<u8>>> {
let read_part = br.tell() - start_pos;
if read_part + 8 < size {
let mut buf = [0; 8];
}
#[allow(clippy::neg_cmp_op_on_partial_ord)]
-fn read_stsd(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_stsd(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
const KNOWN_STSD_SIZE: u64 = 24;
validate!(size >= KNOWN_STSD_SIZE);
let start_pos = br.tell();
Ok(read_size)
}
-fn read_stts(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_stts(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
validate!(size >= 8);
let start_pos = br.tell();
let version = br.read_byte()?;
Ok(read_size)
}
-fn read_stss(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_stss(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
let version = br.read_byte()?;
validate!(version == 0);
let _flags = br.read_u24be()?;
Ok(size)
}
-fn read_stsc(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_stsc(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
let version = br.read_byte()?;
validate!(version == 0);
let _flags = br.read_u24be()?;
Ok(size)
}
-fn read_stsz(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_stsz(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
let version = br.read_byte()?;
validate!(version == 0);
let _flags = br.read_u24be()?;
}
}
-fn read_stco(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_stco(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
let version = br.read_byte()?;
validate!(version == 0);
let _flags = br.read_u24be()?;
Ok(size)
}
-fn read_ctts(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_ctts(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
validate!(size >= 8);
let version = br.read_byte()?;
let _flags = br.read_u24be()?;
TrackChunkHandler { ctype: mktag!(b"meta"), parse: skip_chunk },
];
-fn read_tfhd(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_tfhd(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
validate!(size >= 8);
let start = br.tell();
let _version = br.read_byte()?;
Ok(br.tell() - start)
}
-fn read_trun(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
+fn read_trun(track: &mut Track, br: &mut dyn ByteIO, size: u64) -> DemuxerResult<u64> {
validate!(size >= 8);
let version = br.read_byte()?;
let flags = br.read_u24be()?;
}
struct MOVDemuxer<'a> {
- src: &'a mut ByteReader<'a>,
+ src: &'a mut dyn ByteIO,
depth: usize,
mdat_pos: u64,
mdat_size: u64,
}
}
-fn process_packet(src: &mut ByteReader, strmgr: &StreamManager, track: &mut Track, pts: NATimeInfo, offset: u64, size: usize, first: bool) -> DemuxerResult<NAPacket> {
+fn process_packet(src: &mut dyn ByteIO, strmgr: &StreamManager, track: &mut Track, pts: NATimeInfo, offset: u64, size: usize, first: bool) -> DemuxerResult<NAPacket> {
if let Some(cpts) = pts.get_pts() {
let ts = NATimeInfo::ts_to_time(cpts, 1000, pts.tb_num, pts.tb_den);
track.cur_ts = Some(ts);
}
impl<'a> MOVDemuxer<'a> {
- fn new(io: &'a mut ByteReader<'a>) -> Self {
+ fn new(io: &'a mut dyn ByteIO) -> Self {
Self::new_common(io, DemuxMode::Normal)
}
- fn new_macbinary(io: &'a mut ByteReader<'a>) -> Self {
+ fn new_macbinary(io: &'a mut dyn ByteIO) -> Self {
Self::new_common(io, DemuxMode::MacBin)
}
- fn new_resfork(io: &'a mut ByteReader<'a>) -> Self {
+ fn new_resfork(io: &'a mut dyn ByteIO) -> Self {
Self::new_common(io, DemuxMode::ResFork)
}
- fn new_common(io: &'a mut ByteReader<'a>, demux_mode: DemuxMode,) -> Self {
+ fn new_common(io: &'a mut dyn ByteIO, demux_mode: DemuxMode,) -> Self {
MOVDemuxer {
src: io,
depth: 0,
pub struct MOVDemuxerCreator { }
impl DemuxerCreator for MOVDemuxerCreator {
- 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(MOVDemuxer::new(br))
}
fn get_name(&self) -> &'static str { "mov" }
pub struct MacBinaryMOVDemuxerCreator { }
impl DemuxerCreator for MacBinaryMOVDemuxerCreator {
- 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(MOVDemuxer::new_macbinary(br))
}
fn get_name(&self) -> &'static str { "mov-macbin" }
pub struct MacResForkMOVDemuxerCreator { }
impl DemuxerCreator for MacResForkMOVDemuxerCreator {
- 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(MOVDemuxer::new_resfork(br))
}
fn get_name(&self) -> &'static str { "mov-resfork" }
fn test_mov_demux() {
// sample: https://samples.mplayerhq.hu/V-codecs/IV32/cubes.mov
let mut file = File::open("assets/Indeo/cubes.mov").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 = MOVDemuxer::new(&mut br);
let mut sm = StreamManager::new();
let mut si = SeekIndex::new();
fn test_dash_demux() {
// sample: a stream downloaded with youtube-dl
let mut file = File::open("assets/ITU/dash.m4a").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 = MOVDemuxer::new(&mut br);
let mut sm = StreamManager::new();
let mut si = SeekIndex::new();
fn test_macbinary_demux() {
// sample from King's Quest VI Macintosh edition
let mut file = File::open("assets/QT/Halfdome.bin").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 = MOVDemuxer::new_macbinary(&mut br);
let mut sm = StreamManager::new();
let mut si = SeekIndex::new();
fn test_resfork_demux() {
// sample from The Wonders of Electricity: An Adventure in Safety
let mut file = File::open("assets/QT/car.mov").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 = MOVDemuxer::new_resfork(&mut br);
let mut sm = StreamManager::new();
let mut si = SeekIndex::new();
}
struct WAVDemuxer<'a> {
- src: &'a mut ByteReader<'a>,
+ src: &'a mut dyn ByteIO,
data_pos: u64,
data_end: u64,
srate: u32,
}
impl<'a> WAVDemuxer<'a> {
- fn new(io: &'a mut ByteReader<'a>) -> Self {
+ fn new(io: &'a mut dyn ByteIO) -> Self {
WAVDemuxer {
src: io,
data_pos: 0,
pub struct WAVDemuxerCreator { }
impl DemuxerCreator for WAVDemuxerCreator {
- 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(WAVDemuxer::new(br))
}
fn get_name(&self) -> &'static str { "wav" }
fn test_wav_demux() {
// sample: https://samples.mplayerhq.hu/A-codecs/msadpcm-stereo/scatter.wav
let mut file = File::open("assets/MS/scatter.wav").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 = WAVDemuxer::new(&mut br);
let mut sm = StreamManager::new();
let mut si = SeekIndex::new();
use std::str::FromStr;
struct Y4MDemuxer<'a> {
- src: &'a mut ByteReader<'a>,
+ src: &'a mut dyn ByteIO,
width: usize,
height: usize,
frame_size: usize,
}
impl<'a> Y4MDemuxer<'a> {
- fn new(io: &'a mut ByteReader<'a>) -> Self {
+ fn new(io: &'a mut dyn ByteIO) -> Self {
Self {
src: io,
width: 0,
}
}
-fn read_token(src: &mut ByteReader) -> DemuxerResult<(bool, String)> {
+fn read_token(src: &mut dyn ByteIO) -> DemuxerResult<(bool, String)> {
let mut string = String::new();
let ws;
loop {
pub struct Y4MDemuxerCreator { }
impl DemuxerCreator for Y4MDemuxerCreator {
- 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(Y4MDemuxer::new(br))
}
fn get_name(&self) -> &'static str { "yuv4mpeg" }
fn test_y4m_demux() {
// sample: self-created with avconv
let mut file = File::open("assets/Misc/test.y4m").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 = Y4MDemuxer::new(&mut br);
let mut sm = StreamManager::new();
let mut si = SeekIndex::new();
}
struct AVIMuxer<'a> {
- bw: &'a mut ByteWriter<'a>,
+ bw: &'a mut dyn ByteIO,
index: Vec<IdxEntry>,
video_str: Option<usize>,
video_id: u32,
}
impl<'a> AVIMuxer<'a> {
- fn new(bw: &'a mut ByteWriter<'a>) -> Self {
+ fn new(bw: &'a mut dyn ByteIO) -> Self {
Self {
bw,
index: Vec::new(),
}
}
-fn patch_size(bw: &mut ByteWriter, pos: u64) -> MuxerResult<()> {
+fn patch_size(bw: &mut dyn ByteIO, pos: u64) -> MuxerResult<()> {
let size = bw.tell() - pos;
bw.seek(SeekFrom::Current(-((size + 4) as i64)))?;
bw.write_u32le(size as u32)?;
pub struct AVIMuxerCreator {}
impl MuxerCreator for AVIMuxerCreator {
- fn new_muxer<'a>(&self, bw: &'a mut ByteWriter<'a>) -> Box<dyn MuxCore<'a> + 'a> {
+ fn new_muxer<'a>(&self, bw: &'a mut dyn ByteIO) -> Box<dyn MuxCore<'a> + 'a> {
Box::new(AVIMuxer::new(bw))
}
fn get_name(&self) -> &'static str { "avi" }
use nihav_core::muxers::*;
struct GIFMuxer<'a> {
- bw: &'a mut ByteWriter<'a>,
+ bw: &'a mut dyn ByteIO,
single: bool,
gif87: bool,
pal_written: bool,
}
impl<'a> GIFMuxer<'a> {
- fn new(bw: &'a mut ByteWriter<'a>) -> Self {
+ fn new(bw: &'a mut dyn ByteIO) -> Self {
Self {
bw,
single: false,
pub struct GIFMuxerCreator {}
impl MuxerCreator for GIFMuxerCreator {
- fn new_muxer<'a>(&self, bw: &'a mut ByteWriter<'a>) -> Box<dyn MuxCore<'a> + 'a> {
+ fn new_muxer<'a>(&self, bw: &'a mut dyn ByteIO) -> Box<dyn MuxCore<'a> + 'a> {
Box::new(GIFMuxer::new(bw))
}
fn get_name(&self) -> &'static str { "gif" }
use nihav_registry::register::*;
struct WAVMuxer<'a> {
- bw: &'a mut ByteWriter<'a>,
+ bw: &'a mut dyn ByteIO,
data_pos: u64,
}
impl<'a> WAVMuxer<'a> {
- fn new(bw: &'a mut ByteWriter<'a>) -> Self {
+ fn new(bw: &'a mut dyn ByteIO) -> Self {
Self {
bw,
data_pos: 0,
}
}
-fn patch_size(bw: &mut ByteWriter, pos: u64) -> MuxerResult<()> {
+fn patch_size(bw: &mut dyn ByteIO, pos: u64) -> MuxerResult<()> {
let size = bw.tell() - pos;
bw.seek(SeekFrom::Current(-((size + 4) as i64)))?;
bw.write_u32le(size as u32)?;
pub struct WAVMuxerCreator {}
impl MuxerCreator for WAVMuxerCreator {
- fn new_muxer<'a>(&self, bw: &'a mut ByteWriter<'a>) -> Box<dyn MuxCore<'a> + 'a> {
+ fn new_muxer<'a>(&self, bw: &'a mut dyn ByteIO) -> Box<dyn MuxCore<'a> + 'a> {
Box::new(WAVMuxer::new(bw))
}
fn get_name(&self) -> &'static str { "wav" }
use nihav_core::muxers::*;
struct Y4MMuxer<'a> {
- bw: &'a mut ByteWriter<'a>,
+ bw: &'a mut dyn ByteIO,
}
impl<'a> Y4MMuxer<'a> {
- fn new(bw: &'a mut ByteWriter<'a>) -> Self {
+ fn new(bw: &'a mut dyn ByteIO) -> Self {
Self {
bw,
}
pub struct Y4MMuxerCreator {}
impl MuxerCreator for Y4MMuxerCreator {
- fn new_muxer<'a>(&self, bw: &'a mut ByteWriter<'a>) -> Box<dyn MuxCore<'a> + 'a> {
+ fn new_muxer<'a>(&self, bw: &'a mut dyn ByteIO) -> Box<dyn MuxCore<'a> + 'a> {
Box::new(Y4MMuxer::new(bw))
}
fn get_name(&self) -> &'static str { "yuv4mpeg" }