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