| 1 | pub mod decoder; |
| 2 | pub use self::decoder::Decoder; |
| 3 | |
| 4 | pub mod video; |
| 5 | pub use self::video::Video; |
| 6 | |
| 7 | pub mod audio; |
| 8 | pub use self::audio::Audio; |
| 9 | |
| 10 | pub mod subtitle; |
| 11 | pub use self::subtitle::Subtitle; |
| 12 | |
| 13 | pub mod slice; |
| 14 | |
| 15 | pub mod conceal; |
| 16 | pub use self::conceal::Conceal; |
| 17 | |
| 18 | pub mod check; |
| 19 | pub use self::check::Check; |
| 20 | |
| 21 | pub mod opened; |
| 22 | pub use self::opened::Opened; |
| 23 | |
| 24 | use std::ffi::CString; |
| 25 | |
| 26 | use codec::Context; |
| 27 | use codec::Id; |
| 28 | use ffi::*; |
| 29 | use Codec; |
| 30 | |
| 31 | pub fn new() -> Decoder { |
| 32 | Context::new().decoder() |
| 33 | } |
| 34 | |
| 35 | pub fn find(id: Id) -> Option<Codec> { |
| 36 | unsafe { |
| 37 | // We get a clippy warning in 4.4 but not in 5.0 and newer, so we allow that cast to not complicate the code |
| 38 | #[allow (clippy::unnecessary_cast)] |
| 39 | let ptr: *mut {unknown} = avcodec_find_decoder(id.into()) as *mut AVCodec; |
| 40 | |
| 41 | if ptr.is_null() { |
| 42 | None |
| 43 | } else { |
| 44 | Some(Codec::wrap(ptr)) |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | pub fn find_by_name(name: &str) -> Option<Codec> { |
| 50 | unsafe { |
| 51 | let name: CString = CString::new(name).unwrap(); |
| 52 | #[allow (clippy::unnecessary_cast)] |
| 53 | let ptr: *mut {unknown} = avcodec_find_decoder_by_name(name.as_ptr()) as *mut AVCodec; |
| 54 | |
| 55 | if ptr.is_null() { |
| 56 | None |
| 57 | } else { |
| 58 | Some(Codec::wrap(ptr)) |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |