]>
Commit | Line | Data |
---|---|---|
77d06de2 KS |
1 | #[cfg(feature="decoder_indeo2")] |
2 | pub mod indeo2; | |
3 | ||
77d06de2 | 4 | use frame::*; |
88c03b61 KS |
5 | use std::rc::Rc; |
6 | use std::cell::RefCell; | |
77d06de2 KS |
7 | use io::byteio::ByteIOError; |
8 | use io::bitreader::BitReaderError; | |
9 | use io::codebook::CodebookError; | |
10 | ||
11 | #[derive(Debug,Clone,Copy,PartialEq)] | |
12 | #[allow(dead_code)] | |
13 | pub enum DecoderError { | |
14 | InvalidData, | |
15 | ShortData, | |
16 | MissingReference, | |
17 | NotImplemented, | |
18 | Bug, | |
19 | } | |
20 | ||
21 | type DecoderResult<T> = Result<T, DecoderError>; | |
22 | ||
23 | impl From<ByteIOError> for DecoderError { | |
24 | fn from(_: ByteIOError) -> Self { DecoderError::ShortData } | |
25 | } | |
26 | ||
27 | impl From<BitReaderError> for DecoderError { | |
28 | fn from(e: BitReaderError) -> Self { | |
29 | match e { | |
30 | BitReaderError::BitstreamEnd => DecoderError::ShortData, | |
31 | _ => DecoderError::InvalidData, | |
32 | } | |
33 | } | |
34 | } | |
35 | ||
36 | impl From<CodebookError> for DecoderError { | |
37 | fn from(_: CodebookError) -> Self { DecoderError::InvalidData } | |
38 | } | |
39 | ||
88c03b61 KS |
40 | #[allow(dead_code)] |
41 | struct HAMShuffler { | |
22cb00db | 42 | lastframe: Option<NAVideoBuffer<u8>>, |
88c03b61 KS |
43 | } |
44 | ||
45 | impl HAMShuffler { | |
46 | #[allow(dead_code)] | |
47 | fn new() -> Self { HAMShuffler { lastframe: None } } | |
48 | #[allow(dead_code)] | |
49 | fn clear(&mut self) { self.lastframe = None; } | |
50 | #[allow(dead_code)] | |
22cb00db KS |
51 | fn add_frame(&mut self, buf: NAVideoBuffer<u8>) { |
52 | self.lastframe = Some(buf); | |
88c03b61 KS |
53 | } |
54 | #[allow(dead_code)] | |
22cb00db | 55 | fn clone_ref(&mut self) -> Option<NAVideoBuffer<u8>> { |
3bd541c8 | 56 | if let Some(ref mut frm) = self.lastframe { |
22cb00db | 57 | let newfrm = frm.copy_buffer(); |
3bd541c8 KS |
58 | *frm = newfrm.clone(); |
59 | Some(newfrm) | |
5c253468 KS |
60 | } else { |
61 | None | |
62 | } | |
88c03b61 KS |
63 | } |
64 | #[allow(dead_code)] | |
22cb00db | 65 | fn get_output_frame(&mut self) -> Option<NAVideoBuffer<u8>> { |
88c03b61 KS |
66 | match self.lastframe { |
67 | Some(ref frm) => Some(frm.clone()), | |
68 | None => None, | |
69 | } | |
70 | } | |
71 | } | |
72 | ||
77d06de2 KS |
73 | pub trait NADecoder { |
74 | fn init(&mut self, info: Rc<NACodecInfo>) -> DecoderResult<()>; | |
88c03b61 | 75 | fn decode(&mut self, pkt: &NAPacket) -> DecoderResult<NAFrameRef>; |
77d06de2 KS |
76 | } |
77 | ||
70259941 | 78 | #[derive(Clone,Copy)] |
2a4130ba | 79 | pub struct DecoderInfo { |
70259941 KS |
80 | name: &'static str, |
81 | get_decoder: fn () -> Box<NADecoder>, | |
82 | } | |
83 | ||
2a4130ba | 84 | const DECODERS: &[DecoderInfo] = &[ |
70259941 | 85 | #[cfg(feature="decoder_indeo2")] |
2a4130ba | 86 | DecoderInfo { name: "indeo2", get_decoder: indeo2::get_decoder }, |
70259941 KS |
87 | ]; |
88 | ||
89 | pub fn find_decoder(name: &str) -> Option<fn () -> Box<NADecoder>> { | |
90 | for &dec in DECODERS { | |
91 | if dec.name == name { | |
92 | return Some(dec.get_decoder); | |
93 | } | |
94 | } | |
95 | None | |
96 | } |