From 534a5b60b896020c2113a29436333e4b1ec83334 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Sat, 17 Dec 2022 11:45:15 +0100 Subject: [PATCH 1/1] core/demuxer: add functions for creating demuxers with options --- nihav-core/src/demuxers/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/nihav-core/src/demuxers/mod.rs b/nihav-core/src/demuxers/mod.rs index 23f27fb..181f88a 100644 --- a/nihav-core/src/demuxers/mod.rs +++ b/nihav-core/src/demuxers/mod.rs @@ -471,6 +471,16 @@ pub fn create_demuxer<'a>(dmxcr: &dyn DemuxerCreator, br: &'a mut ByteReader<'a> Ok(Demuxer::new(dmx, strmgr, seek_idx)) } +/// Creates demuxer for a provided bytestream with options applied right after its creation. +pub fn create_demuxer_with_options<'a>(dmxcr: &dyn DemuxerCreator, br: &'a mut ByteReader<'a>, opts: &[NAOption]) -> DemuxerResult> { + let mut dmx = dmxcr.new_demuxer(br); + dmx.set_options(opts); + let mut strmgr = StreamManager::new(); + let mut seek_idx = SeekIndex::new(); + dmx.open(&mut strmgr, &mut seek_idx)?; + Ok(Demuxer::new(dmx, strmgr, seek_idx)) +} + /// List of registered demuxers. #[derive(Default)] pub struct RegisteredDemuxers { @@ -637,6 +647,16 @@ pub fn create_raw_demuxer<'a>(dmxcr: &dyn RawDemuxerCreator, br: &'a mut ByteRea Ok(RawDemuxer::new(dmx, strmgr, seek_idx)) } +/// Creates raw data demuxer for a provided bytestream with options applied right after its creation. +pub fn create_raw_demuxer_with_options<'a>(dmxcr: &dyn RawDemuxerCreator, br: &'a mut ByteReader<'a>, opts: &[NAOption]) -> DemuxerResult> { + let mut dmx = dmxcr.new_demuxer(br); + dmx.set_options(opts); + let mut strmgr = StreamManager::new(); + let mut seek_idx = SeekIndex::new(); + dmx.open(&mut strmgr, &mut seek_idx)?; + Ok(RawDemuxer::new(dmx, strmgr, seek_idx)) +} + /// List of registered demuxers. #[derive(Default)] pub struct RegisteredRawDemuxers { -- 2.39.5