ffmpeg_next/codec/decoder/
mod.rs

1pub mod decoder;
2pub use self::decoder::Decoder;
3
4pub mod video;
5pub use self::video::Video;
6
7pub mod audio;
8pub use self::audio::Audio;
9
10pub mod subtitle;
11pub use self::subtitle::Subtitle;
12
13pub mod slice;
14
15pub mod conceal;
16pub use self::conceal::Conceal;
17
18pub mod check;
19pub use self::check::Check;
20
21pub mod opened;
22pub use self::opened::Opened;
23
24use std::ffi::CString;
25
26use codec::Context;
27use codec::Id;
28use ffi::*;
29use Codec;
30
31pub fn new() -> Decoder {
32    Context::new().decoder()
33}
34
35pub 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 = 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
49pub fn find_by_name(name: &str) -> Option<Codec> {
50    unsafe {
51        let name = CString::new(name).unwrap();
52        #[allow(clippy::unnecessary_cast)]
53        let ptr = 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}