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