1 | pub mod flag; |
2 | pub use self::flag::Flags; |
3 | |
4 | pub mod pad; |
5 | pub use self::pad::Pad; |
6 | |
7 | pub mod filter; |
8 | pub use self::filter::Filter; |
9 | |
10 | pub mod context; |
11 | pub use self::context::{Context, Sink, Source}; |
12 | |
13 | pub mod graph; |
14 | pub use self::graph::Graph; |
15 | |
16 | use std::ffi::{CStr, CString}; |
17 | use std::str::from_utf8_unchecked; |
18 | |
19 | use ffi::*; |
20 | #[cfg (not(feature = "ffmpeg_5_0" ))] |
21 | use Error; |
22 | |
23 | #[cfg (not(feature = "ffmpeg_5_0" ))] |
24 | pub fn register_all() { |
25 | unsafe { |
26 | avfilter_register_all(); |
27 | } |
28 | } |
29 | |
30 | #[cfg (not(feature = "ffmpeg_5_0" ))] |
31 | pub fn register(filter: &Filter) -> Result<(), Error> { |
32 | unsafe { |
33 | match avfilter_register(filter.as_ptr() as *mut _) { |
34 | 0 => Ok(()), |
35 | _ => Err(Error::InvalidData), |
36 | } |
37 | } |
38 | } |
39 | |
40 | pub fn version() -> u32 { |
41 | unsafe { avfilter_version() } |
42 | } |
43 | |
44 | pub fn configuration() -> &'static str { |
45 | unsafe { from_utf8_unchecked(CStr::from_ptr(avfilter_configuration()).to_bytes()) } |
46 | } |
47 | |
48 | pub fn license() -> &'static str { |
49 | unsafe { from_utf8_unchecked(CStr::from_ptr(avfilter_license()).to_bytes()) } |
50 | } |
51 | |
52 | pub fn find(name: &str) -> Option<Filter> { |
53 | unsafe { |
54 | let name: CString = CString::new(name).unwrap(); |
55 | let ptr = avfilter_get_by_name(name.as_ptr()); |
56 | |
57 | if ptr.is_null() { |
58 | None |
59 | } else { |
60 | Some(Filter::wrap(ptr as *mut _)) |
61 | } |
62 | } |
63 | } |
64 | |
65 | #[cfg (test)] |
66 | mod tests { |
67 | use super::*; |
68 | |
69 | #[test ] |
70 | fn test_paditer() { |
71 | #[cfg (not(feature = "ffmpeg_5_0" ))] |
72 | register_all(); |
73 | assert_eq!( |
74 | find("overlay" ) |
75 | .unwrap() |
76 | .inputs() |
77 | .unwrap() |
78 | .map(|input| input.name().unwrap().to_string()) |
79 | .collect::<Vec<_>>(), |
80 | vec!("main" , "overlay" ) |
81 | ); |
82 | } |
83 | } |
84 | |