X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=src%2Fdemuxers%2Fmod.rs;h=5e337a50d4311ce56f56d16c2ce91370247b3a25;hb=3f7c7cfd270b5b75917508aee6ca5877433a984d;hp=fac5c8251d43bd15a51ee152263130e957abb066;hpb=83e603fadb920a29f16a1ef2cedb9be4048dab5a;p=nihav.git diff --git a/src/demuxers/mod.rs b/src/demuxers/mod.rs index fac5c82..5e337a5 100644 --- a/src/demuxers/mod.rs +++ b/src/demuxers/mod.rs @@ -1,18 +1,27 @@ +#[cfg(feature="demuxer_gdv")] pub mod gdv; +#[cfg(feature="demuxer_avi")] +pub mod avi; use std::fmt; use std::rc::Rc; use frame::*; -//use std::collections::HashMap; +use std::collections::HashMap; use io::byteio::*; +/// Possible stream types. #[derive(Debug,Clone,Copy)] #[allow(dead_code)] pub enum StreamType { + /// video stream Video, + /// audio stream Audio, + /// subtitles Subtitles, + /// any data stream (or might be an unrecognized audio/video stream) Data, + /// nonexistent stream None, } @@ -73,9 +82,16 @@ impl NAPacket { } 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()); @@ -103,6 +119,8 @@ type DemuxerResult = Result; pub trait Demux<'a> { fn open(&mut self) -> DemuxerResult<()>; + fn get_num_streams(&self) -> usize; + fn get_stream(&self, idx: usize) -> Option>; fn get_frame(&mut self) -> DemuxerResult; fn seek(&mut self, time: u64) -> DemuxerResult<()>; } @@ -159,15 +177,49 @@ impl Demuxer { } None } + pub fn get_num_streams(&self) -> usize { self.streams.len() } } impl From for DemuxerError { fn from(_: ByteIOError) -> Self { DemuxerError::IOError } } -//impl NADemuxerBuilder { -// #[allow(unused_variables)] -// pub fn create_demuxer(name: &str, url: &str) -> DemuxerResult>> { -// unimplemented!() -// } -//} +pub trait FrameFromPacket { + fn new_from_pkt(pkt: &NAPacket, info: Rc) -> NAFrame; + fn fill_timestamps(&mut self, pkt: &NAPacket); +} + +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); + } +} + +///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; +} + +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 +}