]>
Commit | Line | Data |
---|---|---|
1 | #[cfg(feature="decoder_indeo2")] | |
2 | pub mod indeo2; | |
3 | ||
4 | use std::rc::Rc; | |
5 | use frame::*; | |
6 | use io::byteio::ByteIOError; | |
7 | use io::bitreader::BitReaderError; | |
8 | use io::codebook::CodebookError; | |
9 | ||
10 | #[derive(Debug,Clone,Copy,PartialEq)] | |
11 | #[allow(dead_code)] | |
12 | pub enum DecoderError { | |
13 | InvalidData, | |
14 | ShortData, | |
15 | MissingReference, | |
16 | NotImplemented, | |
17 | Bug, | |
18 | } | |
19 | ||
20 | type DecoderResult<T> = Result<T, DecoderError>; | |
21 | ||
22 | impl From<ByteIOError> for DecoderError { | |
23 | fn from(_: ByteIOError) -> Self { DecoderError::ShortData } | |
24 | } | |
25 | ||
26 | impl From<BitReaderError> for DecoderError { | |
27 | fn from(e: BitReaderError) -> Self { | |
28 | match e { | |
29 | BitReaderError::BitstreamEnd => DecoderError::ShortData, | |
30 | _ => DecoderError::InvalidData, | |
31 | } | |
32 | } | |
33 | } | |
34 | ||
35 | impl From<CodebookError> for DecoderError { | |
36 | fn from(_: CodebookError) -> Self { DecoderError::InvalidData } | |
37 | } | |
38 | ||
39 | pub trait NADecoder { | |
40 | fn init(&mut self, info: Rc<NACodecInfo>) -> DecoderResult<()>; | |
41 | fn decode(&mut self, pkt: &NAPacket) -> DecoderResult<Rc<NAFrame>>; | |
42 | } | |
43 | ||
44 | #[derive(Clone,Copy)] | |
45 | pub struct DecoderInfo { | |
46 | name: &'static str, | |
47 | get_decoder: fn () -> Box<NADecoder>, | |
48 | } | |
49 | ||
50 | const DECODERS: &[DecoderInfo] = &[ | |
51 | #[cfg(feature="decoder_indeo2")] | |
52 | DecoderInfo { name: "indeo2", get_decoder: indeo2::get_decoder }, | |
53 | ]; | |
54 | ||
55 | pub fn find_decoder(name: &str) -> Option<fn () -> Box<NADecoder>> { | |
56 | for &dec in DECODERS { | |
57 | if dec.name == name { | |
58 | return Some(dec.get_decoder); | |
59 | } | |
60 | } | |
61 | None | |
62 | } |