fn read_size(&mut self, ver: u16) -> ByteIOResult<u64>;
}
-impl<'a> ReadSize for ByteReader<'a> {
+impl<T: ?Sized + ByteIO> ReadSize for T {
fn read_size(&mut self, ver: u16) -> ByteIOResult<u64> {
match ver {
0 => Ok(u64::from(self.read_u32be()?)),
}
RMAudioStream { deint, iinfo, buf, sub_packet: 0 }
}
- fn read_apackets(&mut self, queued_packets: &mut Vec<NAPacket>, src: &mut ByteReader, stream: NAStreamRef, ts: u32, keyframe: bool, payload_size: usize) -> DemuxerResult<NAPacket> {
+ fn read_apackets(&mut self, queued_packets: &mut Vec<NAPacket>, src: &mut dyn ByteIO, stream: NAStreamRef, ts: u32, keyframe: bool, payload_size: usize) -> DemuxerResult<NAPacket> {
let ts = stream.make_ts(Some(ts as u64), None, None);
if keyframe {
}
struct RealMediaDemuxer<'a> {
- src: &'a mut ByteReader<'a>,
+ src: &'a mut dyn ByteIO,
data_pos: u64,
data_end: u64,
next_data: u64,
"unknown"
}
-fn read_14or30(src: &mut ByteReader) -> DemuxerResult<(bool, u32)> {
+fn read_14or30(src: &mut dyn ByteIO) -> DemuxerResult<(bool, u32)> {
let tmp = src.read_u16be()?;
let flag = (tmp & 0x8000) != 0;
if (tmp & 0x4000) == 0x4000 {
}
}
-fn read_video_buf(src: &mut ByteReader, stream: NAStreamRef, ts: u32, keyframe: bool, frame_size: usize) -> DemuxerResult<NAPacket> {
+fn read_video_buf(src: &mut dyn ByteIO, stream: NAStreamRef, ts: u32, keyframe: bool, frame_size: usize) -> DemuxerResult<NAPacket> {
let size = frame_size + 9;
let mut vec: Vec<u8> = vec![0; size];
//v[0] = 0; // 1 slice
Ok(NAPacket::new(stream, ts, keyframe, vec))
}
-fn read_multiple_frame(src: &mut ByteReader, stream: NAStreamRef, keyframe: bool, skip_mtype: bool) -> DemuxerResult<NAPacket> {
+fn read_multiple_frame(src: &mut dyn ByteIO, stream: NAStreamRef, keyframe: bool, skip_mtype: bool) -> DemuxerResult<NAPacket> {
if !skip_mtype {
let mtype = src.read_byte()?;
validate!(mtype == 0xC0);
impl RMDemuxCommon {
fn parse_stream_info(str_data: &mut CommonStreamData, strmgr: &mut StreamManager, stream_no: u32, edata: &[u8], duration: u32) -> DemuxerResult<bool> {
let mut is_mlti = false;
- let mut mr = MemoryReader::new_read(edata);
- let mut src = ByteReader::new(&mut mr);
+ let mut src = MemoryReader::new_read(edata);
let tag = src.read_u32be()?;
let tag2 = src.peek_u32be()?;
if tag == mktag!('.', 'r', 'a', 0xFD) {
str_data.mlti_mapper.add_substream();
{
let hdrsrc = &edata[pos..][..hdr_size];
- let mut mr = MemoryReader::new_read(hdrsrc);
- let mut hsrc = ByteReader::new(&mut mr);
+ let mut hsrc = MemoryReader::new_read(hdrsrc);
let tag = hsrc.read_u32be()?;
let tag2 = hsrc.peek_u32be()?;
}
Ok(is_mlti)
}
- fn parse_audio_stream(strmgr: &mut StreamManager, streams: &mut Vec<RMStreamType>, stream_no: u32, src: &mut ByteReader, edata_: &[u8], duration: u32) -> DemuxerResult<()> {
+ fn parse_audio_stream(strmgr: &mut StreamManager, streams: &mut Vec<RMStreamType>, stream_no: u32, src: &mut dyn ByteIO, edata_: &[u8], duration: u32) -> DemuxerResult<()> {
let ver = src.read_u16be()?;
let ainfo = match ver {
3 => {
streams.push(RMStreamType::Audio(astr));
Ok(())
}
- fn parse_video_stream(strmgr: &mut StreamManager, streams: &mut Vec<RMStreamType>, stream_no: u32, src: &mut ByteReader, edata_: &[u8], tag2: u32, duration: u32) -> DemuxerResult<()> {
+ fn parse_video_stream(strmgr: &mut StreamManager, streams: &mut Vec<RMStreamType>, stream_no: u32, src: &mut dyn ByteIO, edata_: &[u8], tag2: u32, duration: u32) -> DemuxerResult<()> {
src.read_skip(4)?;
let fcc = src.read_u32be()?;
let width = src.read_u16be()? as usize;
Ok(())
}
#[allow(clippy::too_many_arguments)]
- fn parse_packet_payload(src: &mut ByteReader, rmstream: &mut RMStreamType, stream: NAStreamRef, slice_buf: &mut Vec<u8>, queued_pkts: &mut Vec<NAPacket>, keyframe: bool, ts: u32, payload_size: usize) -> DemuxerResult<NAPacket> {
+ fn parse_packet_payload(src: &mut dyn ByteIO, rmstream: &mut RMStreamType, stream: NAStreamRef, slice_buf: &mut Vec<u8>, queued_pkts: &mut Vec<NAPacket>, keyframe: bool, ts: u32, payload_size: usize) -> DemuxerResult<NAPacket> {
match rmstream {
RMStreamType::Video(ref mut vstr) => {
fn query_option_value(&self, _name: &str) -> Option<NAValue> { None }
}
-fn read_chunk(src: &mut ByteReader) -> DemuxerResult<(u32, u32, u16)> {
+fn read_chunk(src: &mut dyn ByteIO) -> DemuxerResult<(u32, u32, u16)> {
let id = src.read_u32be()?;
if id == 0 { return Ok((0, 0, 0)); }
let size = src.read_u32be()?;
}
}
-fn skip_ra_metadata(src: &mut ByteReader) -> DemuxerResult<()> {
+fn skip_ra_metadata(src: &mut dyn ByteIO) -> DemuxerResult<()> {
let title_len = src.read_byte()? as usize;
src.read_skip(title_len)?;
let author_len = src.read_byte()? as usize;
Ok(())
}
-fn parse_aformat3(src: &mut ByteReader) -> DemuxerResult<RealAudioInfo> {
+fn parse_aformat3(src: &mut dyn ByteIO) -> DemuxerResult<RealAudioInfo> {
let start = src.tell();
let header_len = src.read_u16be()?;
validate!(header_len >= 24);
})
}
-fn parse_aformat4(src: &mut ByteReader) -> DemuxerResult<RealAudioInfo> {
+fn parse_aformat4(src: &mut dyn ByteIO) -> DemuxerResult<RealAudioInfo> {
let start = src.tell();
src.read_skip(2)?; // zeroes
let id = src.read_u32be()?;
})
}
-fn parse_aformat5(src: &mut ByteReader) -> DemuxerResult<RealAudioInfo> {
+fn parse_aformat5(src: &mut dyn ByteIO) -> DemuxerResult<RealAudioInfo> {
let start = src.tell();
src.read_skip(2)?; // zeroes
let id = src.read_u32be()?;
const KEYFRAME_FLAG: u8 = 0x02;
impl<'a> RealMediaDemuxer<'a> {
- fn new(io: &'a mut ByteReader<'a>) -> Self {
+ fn new(io: &'a mut dyn ByteIO) -> Self {
RealMediaDemuxer {
src: io,
data_pos: 0,
}
}
-fn read_string_size(src: &mut ByteReader, size: usize) -> DemuxerResult<String> {
+fn read_string_size(src: &mut dyn ByteIO, size: usize) -> DemuxerResult<String> {
let mut vec: Vec<u8> = Vec::new();
for _ in 0..size {
let c = src.read_byte()?;
}
struct RealAudioDemuxer<'a> {
- src: &'a mut ByteReader<'a>,
+ src: &'a mut dyn ByteIO,
stream: Option<RMAudioStream>,
data_start: u64,
data_end: u64,
}
impl<'a> RealAudioDemuxer<'a> {
- fn new(io: &'a mut ByteReader<'a>) -> Self {
+ fn new(io: &'a mut dyn ByteIO) -> Self {
RealAudioDemuxer {
src: io,
data_start: 0,
}
impl IVRRecord {
- fn read_string(src: &mut ByteReader) -> DemuxerResult<Vec<u8>> {
+ fn read_string(src: &mut dyn ByteIO) -> DemuxerResult<Vec<u8>> {
let len = src.read_u32be()? as usize;
let mut val = vec![0; len];
src.read_buf(val.as_mut_slice())?;
Ok(val)
}
- fn read(src: &mut ByteReader) -> DemuxerResult<Self> {
+ fn read(src: &mut dyn ByteIO) -> DemuxerResult<Self> {
let code = src.read_byte()?;
match code {
1 => {
remap_ids: Vec::new(),
}
}
- fn parse_header(&mut self, src: &mut ByteReader, strmgr: &mut StreamManager, str_data: &mut CommonStreamData) -> DemuxerResult<()> {
+ fn parse_header(&mut self, src: &mut dyn ByteIO, strmgr: &mut StreamManager, str_data: &mut CommonStreamData) -> DemuxerResult<()> {
src.seek(SeekFrom::Start(self.cur_pos))?;
let magic = src.read_u32be()?;
validate!(magic == mktag!(b".REC"));
Ok(())
}
- fn get_packet(&mut self, src: &mut ByteReader, str_data: &mut CommonStreamData, strmgr: &StreamManager, queued_pkts: &mut Vec<NAPacket>, slice_buf: &mut Vec<u8>) -> DemuxerResult<NAPacket> {
+ fn get_packet(&mut self, src: &mut dyn ByteIO, str_data: &mut CommonStreamData, strmgr: &StreamManager, queued_pkts: &mut Vec<NAPacket>, slice_buf: &mut Vec<u8>) -> DemuxerResult<NAPacket> {
src.seek(SeekFrom::Start(self.cur_pos))?;
loop {
let rec = IVRRecord::read(src)?;
}
struct RealIVRDemuxer<'a> {
- src: &'a mut ByteReader<'a>,
+ src: &'a mut dyn ByteIO,
recs: Vec<RecordDemuxer>,
cur_rec: usize,
queued_pkts: Vec<NAPacket>,
}
impl<'a> RealIVRDemuxer<'a> {
- fn new(io: &'a mut ByteReader<'a>) -> Self {
+ fn new(io: &'a mut dyn ByteIO) -> Self {
RealIVRDemuxer {
src: io,
recs: Vec::new(),
pub struct RealMediaDemuxerCreator { }
impl DemuxerCreator for RealMediaDemuxerCreator {
- 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(RealMediaDemuxer::new(br))
}
fn get_name(&self) -> &'static str { "realmedia" }
pub struct RealAudioDemuxerCreator { }
impl DemuxerCreator for RealAudioDemuxerCreator {
- 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(RealAudioDemuxer::new(br))
}
fn get_name(&self) -> &'static str { "realaudio" }
pub struct RealIVRDemuxerCreator { }
impl DemuxerCreator for RealIVRDemuxerCreator {
- 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(RealIVRDemuxer::new(br))
}
fn get_name(&self) -> &'static str { "real_ivr" }
// File::open("assets/RV/clv1_sipr_384x208_realvideo_encoder_4.0.rm").unwrap();
// File::open("assets/RV/luckynight.rmvb").unwrap();
// File::open("assets/RV/rv40_ralf.rmvb").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 = RealMediaDemuxer::new(&mut br);
let mut sm = StreamManager::new();
let mut si = SeekIndex::new();
let mut file =
// File::open("assets/RV/welcome288.ra").unwrap();
File::open("assets/RV/diemusik.ra").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 = RealAudioDemuxer::new(&mut br);
let mut sm = StreamManager::new();
let mut si = SeekIndex::new();
let mut file =
File::open("assets/RV/Opener_rm_hi.ivr").unwrap();
// File::open("assets/RV/SherwinWilliamsCommercial.ivr").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 = RealIVRDemuxer::new(&mut br);
let mut sm = StreamManager::new();
let mut si = SeekIndex::new();
fn get_packet(&mut self) -> Option<(Vec<u8>, bool)> {
if self.full {
let mut dst = Vec::with_capacity(self.frame_size);
- let mut gw = GrowableMemoryWriter::new_write(&mut dst);
- let mut bw = ByteWriter::new(&mut gw);
+ let mut bw = GrowableMemoryWriter::new_write(&mut dst);
bw.write_u16be((self.sizes.len() * 16) as u16).unwrap();
for &pkt_size in self.sizes.iter() {
bw.write_u16be(pkt_size as u16).unwrap();
}
impl RMStreamWriter for AudioStreamWriter {
- fn write_header(&mut self, bw: &mut ByteWriter, astream: &NAStream) -> MuxerResult<()> {
+ fn write_header(&mut self, bw: &mut dyn ByteIO, astream: &NAStream) -> MuxerResult<()> {
self.header_pos = bw.tell();
if self.version < 6 {
bw.write_buf(b".ra\xFD")?;
}
}
fn flush(&mut self) { self.interleave.flush() }
- fn finish(&mut self, bw: &mut ByteWriter) -> MuxerResult<()> {
+ fn finish(&mut self, bw: &mut dyn ByteIO) -> MuxerResult<()> {
let cur_pos = bw.tell();
match self.version {
3 => {
fn set_pkt_size(&mut self, _pkt_size: usize) {}
}
-fn write_audio_metadata(bw: &mut ByteWriter) -> MuxerResult<()> {
+fn write_audio_metadata(bw: &mut dyn ByteIO) -> MuxerResult<()> {
bw.write_byte(0)?; // title_string_length
bw.write_byte(0)?; // author_string_length
bw.write_byte(0)?; // copyright_string_length
Ok(())
}
-fn write_aformat3(bw: &mut ByteWriter, _stream: &NAStream, il_info: &InterleaveInfo) -> MuxerResult<()> {
+fn write_aformat3(bw: &mut dyn ByteIO, _stream: &NAStream, il_info: &InterleaveInfo) -> MuxerResult<()> {
let start = bw.tell();
bw.write_u16be(0)?; // header_bytes
bw.write_u16be(il_info.flavor as u16)?;
Ok(())
}
-fn write_aformat4(bw: &mut ByteWriter, stream: &NAStream, il_info: &InterleaveInfo) -> MuxerResult<()> {
+fn write_aformat4(bw: &mut dyn ByteIO, stream: &NAStream, il_info: &InterleaveInfo) -> MuxerResult<()> {
let info = stream.get_info().get_properties().get_audio_info().unwrap();
bw.write_u16be(0)?;
Ok(())
}
-fn write_aformat5(bw: &mut ByteWriter, stream: &NAStream, il_info: &InterleaveInfo) -> MuxerResult<()> {
+fn write_aformat5(bw: &mut dyn ByteIO, stream: &NAStream, il_info: &InterleaveInfo) -> MuxerResult<()> {
let info = stream.get_info().get_properties().get_audio_info().unwrap();
bw.write_u16be(0)?;
Ok(())
}
-fn write_lsd(bw: &mut ByteWriter, stream: &NAStream) -> MuxerResult<()> {
+fn write_lsd(bw: &mut dyn ByteIO, stream: &NAStream) -> MuxerResult<()> {
if let Some(edata) = stream.get_info().get_extradata() {
bw.write_buf(&edata)?;
}
fn patch_value(&mut self, val: u32, off: u64) -> MuxerResult<()>;
}
-impl<'a> RMWriterHelper for ByteWriter<'a> {
+impl<T: ?Sized + ByteIO> RMWriterHelper for T {
fn write_chunk(&mut self, id: &[u8], size: u32, version: u16) -> MuxerResult<()> {
self.write_buf(id)?;
self.write_u32be(size)?;
}
pub trait RMStreamWriter {
- fn write_header(&mut self, bw: &mut ByteWriter, astream: &NAStream) -> MuxerResult<()>;
+ fn write_header(&mut self, bw: &mut dyn ByteIO, astream: &NAStream) -> MuxerResult<()>;
fn queue_packet(&mut self, pkt: NAPacket, ms: u32) -> bool;
fn get_packet(&mut self) -> Option<(Vec<u8>, u32, bool)>;
fn flush(&mut self);
- fn finish(&mut self, bw: &mut ByteWriter) -> MuxerResult<()>;
+ fn finish(&mut self, bw: &mut dyn ByteIO) -> MuxerResult<()>;
fn set_pkt_size(&mut self, pkt_size: usize);
}
debug: false,
})
}
- fn write_mdpr(&mut self, bw: &mut ByteWriter, strm: &NAStream) -> MuxerResult<()> {
+ fn write_mdpr(&mut self, bw: &mut dyn ByteIO, strm: &NAStream) -> MuxerResult<()> {
self.mdpr_pos = bw.tell();
bw.write_chunk(b"MDPR", 0, 0)?;
Ok(())
}
- fn write_packet(&mut self, bw: &mut ByteWriter, pkt: NAPacket, pkt_no: &mut u32) -> MuxerResult<()> {
+ fn write_packet(&mut self, bw: &mut dyn ByteIO, pkt: NAPacket, pkt_no: &mut u32) -> MuxerResult<()> {
if let Some(pts) = pkt.get_pts() {
let (tb_num, tb_den) = pkt.get_stream().get_timebase();
let ms = NATimeInfo::ts_to_time(pts, 1000, tb_num, tb_den) as u32;
self.packetiser.queue_packet(pkt, self.cur_time);
self.write_packets(bw, pkt_no)
}
- fn write_packets(&mut self, bw: &mut ByteWriter, pkt_no: &mut u32) -> MuxerResult<()> {
+ fn write_packets(&mut self, bw: &mut dyn ByteIO, pkt_no: &mut u32) -> MuxerResult<()> {
while let Some((data, ts, first)) = self.packetiser.get_packet() {
validate!(data.len() < 65000);
if self.keyframe && first {
}
Ok(())
}
- fn finish(&mut self, bw: &mut ByteWriter, pkt_no: &mut u32) -> MuxerResult<()> {
+ fn finish(&mut self, bw: &mut dyn ByteIO, pkt_no: &mut u32) -> MuxerResult<()> {
self.packetiser.flush();
self.write_packets(bw, pkt_no)?;
}
struct RMMuxer<'a> {
- bw: &'a mut ByteWriter<'a>,
+ bw: &'a mut dyn ByteIO,
streams: Vec<RMStream>,
data_pos: u64,
num_chunks: u32,
}
impl<'a> RMMuxer<'a> {
- fn new(bw: &'a mut ByteWriter<'a>) -> Self {
+ fn new(bw: &'a mut dyn ByteIO) -> Self {
Self {
bw,
streams: Vec::new(),
}
}
-fn patch_size(bw: &mut ByteWriter, pos: u64) -> MuxerResult<()> {
+fn patch_size(bw: &mut dyn ByteIO, pos: u64) -> MuxerResult<()> {
let end = bw.tell();
bw.patch_value((end - pos) as u32, pos + 4)
}
pub struct RealMediaMuxerCreator {}
impl MuxerCreator for RealMediaMuxerCreator {
- 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(RMMuxer::new(bw))
}
fn get_name(&self) -> &'static str { "realmedia" }
}
struct RAMuxer<'a> {
- bw: &'a mut ByteWriter<'a>,
+ bw: &'a mut dyn ByteIO,
sw: Option<Box<dyn RMStreamWriter>>,
}
impl<'a> RAMuxer<'a> {
- fn new(bw: &'a mut ByteWriter<'a>) -> Self {
+ fn new(bw: &'a mut dyn ByteIO) -> Self {
Self {
bw,
sw: None,
pub struct RealAudioMuxerCreator {}
impl MuxerCreator for RealAudioMuxerCreator {
- 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(RAMuxer::new(bw))
}
fn get_name(&self) -> &'static str { "realaudio" }