From: Kostya Shishkov Date: Fri, 19 May 2017 16:54:27 +0000 (+0200) Subject: structure decoders a bit too X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=70259941696929b91c6b3cbf2aeb476b2b34dda7;p=nihav.git structure decoders a bit too --- diff --git a/src/codecs/indeo2.rs b/src/codecs/indeo2.rs index 1df483f..fec0f12 100644 --- a/src/codecs/indeo2.rs +++ b/src/codecs/indeo2.rs @@ -183,14 +183,14 @@ impl CodebookDescReader for IR2CodeReader { fn len(&mut self) -> usize { INDEO2_CODE_LENGTHS.len() } } -pub struct Indeo2Decoder { +struct Indeo2Decoder { info: Rc, cb: Codebook, lastfrm: Option>, } impl Indeo2Decoder { - pub fn new() -> Self { + fn new() -> Self { let dummy_info = Rc::new(DUMMY_CODEC_INFO); let mut coderead = IR2CodeReader{}; let cb = Codebook::new(&mut coderead, CodebookMode::LSB).unwrap(); @@ -357,10 +357,15 @@ impl NADecoder for Indeo2Decoder { } } +pub fn get_decoder() -> Box { + Box::new(Indeo2Decoder::new()) +} + #[cfg(test)] mod test { - use super::*; + use codecs; use demuxers::*; + use frame::NAFrame; use io::byteio::*; use std::fs::File; use std::io::prelude::*; @@ -373,7 +378,7 @@ mod test { let mut br = ByteReader::new(&mut fr); let mut dmx = avi_dmx.new_demuxer(&mut br); dmx.open().unwrap(); - let mut dec = Indeo2Decoder::new(); + let mut dec = (codecs::find_decoder("indeo2").unwrap())();//Indeo2Decoder::new(); let mut str: u32 = 42; for i in 0..dmx.get_num_streams() { diff --git a/src/codecs/mod.rs b/src/codecs/mod.rs index 782d451..ff75af9 100644 --- a/src/codecs/mod.rs +++ b/src/codecs/mod.rs @@ -42,3 +42,22 @@ pub trait NADecoder { fn decode(&mut self, pkt: &NAPacket) -> DecoderResult>; } +#[derive(Clone,Copy)] +pub struct DemuxerInfo { + name: &'static str, + get_decoder: fn () -> Box, +} + +const DECODERS: &[DemuxerInfo] = &[ +#[cfg(feature="decoder_indeo2")] + DemuxerInfo { name: "indeo2", get_decoder: indeo2::get_decoder }, +]; + +pub fn find_decoder(name: &str) -> Option Box> { + for &dec in DECODERS { + if dec.name == name { + return Some(dec.get_decoder); + } + } + None +}