1 | use super::{Sink, Source}; |
2 | use ffi::*; |
3 | use libc::c_void; |
4 | use {format, option, ChannelLayout}; |
5 | |
6 | pub struct Context { |
7 | ptr: *mut AVFilterContext, |
8 | } |
9 | |
10 | impl Context { |
11 | pub unsafe fn wrap(ptr: *mut AVFilterContext) -> Self { |
12 | Context { ptr } |
13 | } |
14 | |
15 | pub unsafe fn as_ptr(&self) -> *const AVFilterContext { |
16 | self.ptr as *const _ |
17 | } |
18 | |
19 | pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilterContext { |
20 | self.ptr |
21 | } |
22 | } |
23 | |
24 | impl Context { |
25 | pub fn source(&mut self) -> Source { |
26 | unsafe { Source::wrap(self) } |
27 | } |
28 | |
29 | pub fn sink(&mut self) -> Sink { |
30 | unsafe { Sink::wrap(self) } |
31 | } |
32 | |
33 | pub fn set_pixel_format(&mut self, value: format::Pixel) { |
34 | let _ = option::Settable::set::<AVPixelFormat>(self, "pix_fmts" , &value.into()); |
35 | } |
36 | |
37 | pub fn set_sample_format(&mut self, value: format::Sample) { |
38 | let _ = option::Settable::set::<AVSampleFormat>(self, "sample_fmts" , &value.into()); |
39 | } |
40 | |
41 | pub fn set_sample_rate(&mut self, value: u32) { |
42 | let _ = option::Settable::set(self, "sample_rates" , &i64::from(value)); |
43 | } |
44 | |
45 | pub fn set_channel_layout(&mut self, value: ChannelLayout) { |
46 | #[cfg (not(feature = "ffmpeg_7_0" ))] |
47 | { |
48 | let _ = option::Settable::set(self, "channel_layouts" , &value.bits()); |
49 | } |
50 | #[cfg (feature = "ffmpeg_7_0" )] |
51 | { |
52 | let _ = option::Settable::set_channel_layout(self, "channel_layouts" , value); |
53 | } |
54 | } |
55 | |
56 | pub fn link(&mut self, srcpad: u32, dst: &mut Self, dstpad: u32) { |
57 | unsafe { avfilter_link(self.as_mut_ptr(), srcpad, dst.as_mut_ptr(), dstpad) }; |
58 | } |
59 | } |
60 | |
61 | unsafe impl option::Target for Context { |
62 | fn as_ptr(&self) -> *const c_void { |
63 | self.ptr as *const _ |
64 | } |
65 | |
66 | fn as_mut_ptr(&mut self) -> *mut c_void { |
67 | self.ptr as *mut _ |
68 | } |
69 | } |
70 | |
71 | impl option::Settable for Context {} |
72 | |