core: make StreamManager accept NAStreamRef too
[nihav.git] / nihav-core / src / demuxers / mod.rs
index 1d7347b6ac9e0f5847d0abf0237d4782123c99aa..6723cf2e0fdca7f18fe889bb632ac720c5fe341b 100644 (file)
@@ -1,6 +1,7 @@
 //! Demuxer definitions.
 pub use crate::frame::*;
 pub use crate::io::byteio::*;
+pub use crate::options::*;
 
 /// A list specifying general demuxing errors.
 #[derive(Debug,Clone,Copy,PartialEq)]
@@ -30,7 +31,7 @@ pub enum DemuxerError {
 pub type DemuxerResult<T> = Result<T, DemuxerError>;
 
 /// A trait for demuxing operations.
-pub trait DemuxCore<'a> {
+pub trait DemuxCore<'a>: NAOptionHandler {
     /// Opens the input stream, reads required headers and prepares everything for packet demuxing.
     fn open(&mut self, strmgr: &mut StreamManager, seek_idx: &mut SeekIndex) -> DemuxerResult<()>;
     /// Demuxes a packet.
@@ -93,6 +94,13 @@ impl StreamManager {
         self.ignored.push(false);
         Some(stream_num)
     }
+    /// Adds a new stream from reference-counted object.
+    pub fn add_stream_ref(&mut self, stream: NAStreamRef) -> Option<usize> {
+        let stream_num = self.streams.len();
+        self.streams.push(stream);
+        self.ignored.push(false);
+        Some(stream_num)
+    }
     /// Returns stream with the requested index.
     pub fn get_stream(&self, idx: usize) -> Option<NAStreamRef> {
         if idx < self.streams.len() {
@@ -394,6 +402,18 @@ impl<'a> Demuxer<'a> {
     }
 }
 
+impl<'a> NAOptionHandler for Demuxer<'a> {
+    fn get_supported_options(&self) -> &[NAOptionDefinition] {
+        self.dmx.get_supported_options()
+    }
+    fn set_options(&mut self, options: &[NAOption]) {
+        self.dmx.set_options(options);
+    }
+    fn query_option_value(&self, name: &str) -> Option<NAValue> {
+        self.dmx.query_option_value(name)
+    }
+}
+
 impl From<ByteIOError> for DemuxerError {
     fn from(_: ByteIOError) -> Self { DemuxerError::IOError }
 }