1 | use std::ffi::CStr; |
2 | use std::marker::PhantomData; |
3 | use std::str::from_utf8_unchecked; |
4 | |
5 | use ffi::*; |
6 | use media; |
7 | |
8 | pub struct Pad<'a> { |
9 | ptr: *const AVFilterPad, |
10 | idx: isize, |
11 | |
12 | _marker: PhantomData<&'a ()>, |
13 | } |
14 | |
15 | impl<'a> Pad<'a> { |
16 | pub unsafe fn wrap(ptr: *const AVFilterPad, idx: isize) -> Self { |
17 | Pad { |
18 | ptr, |
19 | idx, |
20 | _marker: PhantomData, |
21 | } |
22 | } |
23 | |
24 | pub unsafe fn as_ptr(&self) -> *const AVFilterPad { |
25 | self.ptr |
26 | } |
27 | |
28 | pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilterPad { |
29 | self.ptr as *mut _ |
30 | } |
31 | } |
32 | |
33 | impl<'a> Pad<'a> { |
34 | pub fn name(&self) -> Option<&str> { |
35 | unsafe { |
36 | let ptr = avfilter_pad_get_name(self.ptr, self.idx as i32); |
37 | |
38 | if ptr.is_null() { |
39 | None |
40 | } else { |
41 | Some(from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes())) |
42 | } |
43 | } |
44 | } |
45 | |
46 | pub fn medium(&self) -> media::Type { |
47 | unsafe { media::Type::from(avfilter_pad_get_type(self.ptr, self.idx as i32)) } |
48 | } |
49 | } |
50 | |