X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=src%2Fdemuxers%2Fmod.rs;h=d4d70a2f82e66673ed8e253c19660b9a473d4500;hb=e5e85f326e9edbfdecb8e93a21834984ae201380;hp=6499517de33b15124bc4b1c1aa60ad02f2396e32;hpb=6611650404a13bca86a311afdc314406e725897c;p=nihav.git diff --git a/src/demuxers/mod.rs b/src/demuxers/mod.rs index 6499517..d4d70a2 100644 --- a/src/demuxers/mod.rs +++ b/src/demuxers/mod.rs @@ -3,101 +3,10 @@ pub mod gdv; #[cfg(feature="demuxer_avi")] pub mod avi; -use std::fmt; use std::rc::Rc; use frame::*; -use std::collections::HashMap; use io::byteio::*; -#[derive(Debug,Clone,Copy)] -#[allow(dead_code)] -pub enum StreamType { - Video, - Audio, - Subtitles, - Data, - None, -} - -impl fmt::Display for StreamType { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - StreamType::Video => write!(f, "Video"), - StreamType::Audio => write!(f, "Audio"), - StreamType::Subtitles => write!(f, "Subtitles"), - StreamType::Data => write!(f, "Data"), - StreamType::None => write!(f, "-"), - } - } -} - - -#[allow(dead_code)] -#[derive(Clone)] -pub struct NAStream { - media_type: StreamType, - id: u32, - num: usize, - info: Rc, -} - -impl NAStream { - pub fn new(mt: StreamType, id: u32, info: NACodecInfo) -> Self { - NAStream { media_type: mt, id: id, num: 0, info: Rc::new(info) } - } - pub fn get_id(&self) -> u32 { self.id } - pub fn get_num(&self) -> usize { self.num } - pub fn set_num(&mut self, num: usize) { self.num = num; } - pub fn get_info(&self) -> Rc { self.info.clone() } -} - -impl fmt::Display for NAStream { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "({}#{} - {})", self.media_type, self.id, self.info.get_properties()) - } -} - -#[allow(dead_code)] -pub struct NAPacket { - stream: Rc, - pts: Option, - dts: Option, - duration: Option, - buffer: Rc>, - keyframe: bool, -// options: HashMap>, -} - -impl NAPacket { - pub fn new(str: Rc, pts: Option, dts: Option, dur: Option, kf: bool, vec: Vec) -> Self { -// let mut vec: Vec = Vec::new(); -// vec.resize(size, 0); - NAPacket { stream: str, pts: pts, dts: dts, duration: dur, keyframe: kf, buffer: Rc::new(vec) } - } - pub fn get_stream(&self) -> Rc { self.stream.clone() } - pub fn get_pts(&self) -> Option { self.pts } - pub fn get_dts(&self) -> Option { self.dts } - pub fn get_duration(&self) -> Option { self.duration } - pub fn is_keyframe(&self) -> bool { self.keyframe } - pub fn get_buffer(&self) -> Rc> { self.buffer.clone() } -} - -impl Drop for NAPacket { - fn drop(&mut self) {} -} - -impl fmt::Display for NAPacket { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let mut foo = format!("[pkt for {} size {}", self.stream, self.buffer.len()); - if let Some(pts) = self.pts { foo = format!("{} pts {}", foo, pts); } - if let Some(dts) = self.dts { foo = format!("{} dts {}", foo, dts); } - if let Some(dur) = self.duration { foo = format!("{} duration {}", foo, dur); } - if self.keyframe { foo = format!("{} kf", foo); } - foo = foo + "]"; - write!(f, "{}", foo) - } -} - #[derive(Debug)] #[allow(dead_code)] pub enum DemuxerError { @@ -143,7 +52,7 @@ impl<'a> NAPacketReader for ByteReader<'a> { } } -pub struct Demuxer { +struct Demuxer { streams: Vec>, } @@ -163,6 +72,7 @@ impl Demuxer { None } } + #[allow(dead_code)] pub fn get_stream_by_id(&self, id: u32) -> Option> { for i in 0..self.streams.len() { if self.streams[i].get_id() == id { @@ -178,18 +88,26 @@ impl From for DemuxerError { fn from(_: ByteIOError) -> Self { DemuxerError::IOError } } -pub trait FrameFromPacket { - fn new_from_pkt(pkt: &NAPacket, info: Rc) -> NAFrame; - fn fill_timestamps(&mut self, pkt: &NAPacket); +///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 + 'a>; + /// Get the name of current demuxer creator. + fn get_name(&self) -> &'static str; } -impl FrameFromPacket for NAFrame { - fn new_from_pkt(pkt: &NAPacket, info: Rc) -> NAFrame { - NAFrame::new(pkt.pts, pkt.dts, pkt.duration, info, HashMap::new()) - } - fn fill_timestamps(&mut self, pkt: &NAPacket) { - self.set_pts(pkt.pts); - self.set_dts(pkt.dts); - self.set_duration(pkt.duration); +const DEMUXERS: &[&'static DemuxerCreator] = &[ +#[cfg(feature="demuxer_avi")] + &avi::AVIDemuxerCreator {}, +#[cfg(feature="demuxer_gdv")] + &gdv::GDVDemuxerCreator {}, +]; + +pub fn find_demuxer(name: &str) -> Option<&DemuxerCreator> { + for &dmx in DEMUXERS { + if dmx.get_name() == name { + return Some(dmx); + } } + None }