X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-core%2Fsrc%2Fmuxers%2Fmod.rs;h=e8334e52a83a459ab08f4bbeff0b1d57caae77a8;hb=405cec9eed5d7f58440ec8495f5cbc1f5c6fee40;hp=ba6f780081297c52b8c7e9eade5dfc7db16ada25;hpb=a92964d593be4ebf96706842c02b428d68325b8d;p=nihav.git diff --git a/nihav-core/src/muxers/mod.rs b/nihav-core/src/muxers/mod.rs index ba6f780..e8334e5 100644 --- a/nihav-core/src/muxers/mod.rs +++ b/nihav-core/src/muxers/mod.rs @@ -2,6 +2,7 @@ pub use crate::frame::*; pub use crate::io::byteio::*; pub use crate::demuxers::{StreamManager, StreamIter}; +pub use crate::options::*; /// A list specifying general muxing errors. #[derive(Debug,Clone,Copy,PartialEq)] @@ -28,12 +29,33 @@ pub enum MuxerError { /// A specialised `Result` type for muxing operations. pub type MuxerResult = Result; +/// Muxer capabilities. +#[derive(Clone,Copy,Debug,PartialEq)] +pub enum MuxerCapabilities { + /// Muxer accepts single video stream with certain codec. + /// + /// Codec name `"any"` means various codecs are supported. + SingleVideo(&'static str), + /// Muxer accepts single audio stream with certain codec. + /// + /// Codec name `"any"` means various codecs are supported. + SingleAudio(&'static str), + /// Muxer accepts single video stream and single audio stream with defined codecs. + SingleVideoAndAudio(&'static str, &'static str), + /// Muxer accepts only video streams but can mux several video streams. + OnlyVideo, + /// Muxer accepts only audio streams but can mux several video streams.. + OnlyAudio, + /// Muxer accepts variable amount of streams of any type. + Universal, +} + impl From for MuxerError { fn from(_: ByteIOError) -> Self { MuxerError::IOError } } /// A trait for muxing operations. -pub trait MuxCore<'a> { +pub trait MuxCore<'a>: NAOptionHandler { /// Prepares everything for packet muxing. fn create(&mut self, strmgr: &StreamManager) -> MuxerResult<()>; /// Queues a packet for muxing. @@ -52,10 +74,10 @@ pub struct Muxer<'a> { impl<'a> Muxer<'a> { /// Constructs a new `Muxer` instance. - fn new(mux: Box + 'a>, str: StreamManager) -> Self { + fn new(mux: Box + 'a>, strmgr: StreamManager) -> Self { Muxer { mux, - streams: str, + streams: strmgr, } } /// Returns a stream reference by its number. @@ -75,11 +97,11 @@ impl<'a> Muxer<'a> { self.streams.iter() } - /// Demuxes a new packet from the container. + /// Queues a new packet for muxing. pub fn mux_frame(&mut self, pkt: NAPacket) -> MuxerResult<()> { self.mux.mux_frame(&self.streams, pkt) } - /// Returns internal seek index. + /// Flushes the current muxing state. pub fn flush(&mut self) -> MuxerResult<()> { self.mux.flush() } @@ -89,25 +111,39 @@ impl<'a> Muxer<'a> { } } +impl<'a> NAOptionHandler for Muxer<'a> { + fn get_supported_options(&self) -> &[NAOptionDefinition] { + self.mux.get_supported_options() + } + fn set_options(&mut self, options: &[NAOption]) { + self.mux.set_options(options); + } + fn query_option_value(&self, name: &str) -> Option { + self.mux.query_option_value(name) + } +} + /// The trait for creating muxers. pub trait MuxerCreator { /// Creates new muxer instance that will use `ByteWriter` for output. fn new_muxer<'a>(&self, bw: &'a mut ByteWriter<'a>) -> Box + 'a>; /// Returns the name of current muxer creator (equal to the container name it can create). fn get_name(&self) -> &'static str; + /// Returns muxer capabilities for the current muxer. + fn get_capabilities(&self) -> MuxerCapabilities; } /// Creates muxer for a provided bytestream writer. -pub fn create_muxer<'a>(mxcr: &MuxerCreator, str: StreamManager, bw: &'a mut ByteWriter<'a>) -> MuxerResult> { +pub fn create_muxer<'a>(mxcr: &dyn MuxerCreator, strmgr: StreamManager, bw: &'a mut ByteWriter<'a>) -> MuxerResult> { let mut mux = mxcr.new_muxer(bw); - mux.create(&str)?; - Ok(Muxer::new(mux, str)) + mux.create(&strmgr)?; + Ok(Muxer::new(mux, strmgr)) } /// List of registered muxers. #[derive(Default)] pub struct RegisteredMuxers { - muxes: Vec<&'static MuxerCreator>, + muxes: Vec<&'static dyn MuxerCreator>, } impl RegisteredMuxers { @@ -116,11 +152,11 @@ impl RegisteredMuxers { Self { muxes: Vec::new() } } /// Registers a new muxer. - pub fn add_muxer(&mut self, mux: &'static MuxerCreator) { + pub fn add_muxer(&mut self, mux: &'static dyn MuxerCreator) { self.muxes.push(mux); } /// Searches for a muxer that supports requested container format. - pub fn find_muxer(&self, name: &str) -> Option<&MuxerCreator> { + pub fn find_muxer(&self, name: &str) -> Option<&dyn MuxerCreator> { for &mux in self.muxes.iter() { if mux.get_name() == name { return Some(mux); @@ -128,4 +164,8 @@ impl RegisteredMuxers { } None } + /// Provides an iterator over currently registered muxers. + pub fn iter(&self) -> std::slice::Iter<&dyn MuxerCreator> { + self.muxes.iter() + } }