let mut buf: Vec<u8> = Vec::with_capacity(size);
if buf.capacity() < size { return Err(DemuxerError::MemoryError); }
buf.resize(size, 0);
- let res = self.read_buf(buf.as_mut_slice());
- if let Err(_) = res { return Err(DemuxerError::IOError); }
+ self.read_buf(buf.as_mut_slice())?;
let pkt = NAPacket::new(str, ts, kf, buf);
Ok(pkt)
}
fn fill_packet(&mut self, pkt: &mut NAPacket) -> DemuxerResult<()> {
let mut refbuf = pkt.get_buffer();
let buf = refbuf.as_mut().unwrap();
- let res = self.read_buf(buf.as_mut_slice());
- if let Err(_) = res { return Err(DemuxerError::IOError); }
+ self.read_buf(buf.as_mut_slice())?;
Ok(())
}
}
+#[derive(Default)]
pub struct StreamManager {
streams: Vec<NAStreamRef>,
ignored: Vec<bool>,
}
pub struct StreamIter<'a> {
- streams: &'a Vec<NAStreamRef>,
+ streams: &'a [NAStreamRef],
pos: usize,
}
impl<'a> StreamIter<'a> {
- pub fn new(streams: &'a Vec<NAStreamRef>) -> Self {
- StreamIter { streams: streams, pos: 0 }
+ pub fn new(streams: &'a [NAStreamRef]) -> Self {
+ StreamIter { streams, pos: 0 }
}
}
}
pub struct Demuxer<'a> {
- dmx: Box<DemuxCore<'a> + 'a>,
+ dmx: Box<dyn DemuxCore<'a> + 'a>,
streams: StreamManager,
}
impl<'a> Demuxer<'a> {
- fn new(dmx: Box<DemuxCore<'a> + 'a>, str: StreamManager) -> Self {
+ fn new(dmx: Box<dyn DemuxCore<'a> + 'a>, str: StreamManager) -> Self {
Demuxer {
- dmx: dmx,
+ dmx,
streams: str,
}
}
///The structure used to create demuxers.
pub trait DemuxerCreator {
/// Create new demuxer instance that will use `ByteReader` source as an input.
- fn new_demuxer<'a>(&self, br: &'a mut ByteReader<'a>) -> Box<DemuxCore<'a> + 'a>;
+ fn new_demuxer<'a>(&self, br: &'a mut ByteReader<'a>) -> Box<dyn DemuxCore<'a> + 'a>;
/// Get the name of current demuxer creator.
fn get_name(&self) -> &'static str;
}
Ok(Demuxer::new(dmx, str))
}
+#[derive(Default)]
pub struct RegisteredDemuxers {
dmxs: Vec<&'static DemuxerCreator>,
}