X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=src%2Fdemuxers%2Fmod.rs;fp=src%2Fdemuxers%2Fmod.rs;h=6499517de33b15124bc4b1c1aa60ad02f2396e32;hb=6611650404a13bca86a311afdc314406e725897c;hp=159002495d1c93b0e2e7dbc548dd34872ba4b31d;hpb=45e794c4181f03a75a9d7dfce4bc0bf9ce94b6b0;p=nihav.git diff --git a/src/demuxers/mod.rs b/src/demuxers/mod.rs index 1590024..6499517 100644 --- a/src/demuxers/mod.rs +++ b/src/demuxers/mod.rs @@ -1,10 +1,12 @@ +#[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::*; #[derive(Debug,Clone,Copy)] @@ -74,9 +76,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()); @@ -104,6 +113,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<()>; } @@ -160,15 +171,25 @@ 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); + } +}