1 | use std::ffi::CStr; |
2 | use std::str::from_utf8_unchecked; |
3 | |
4 | use ffi::*; |
5 | |
6 | pub struct Input { |
7 | ptr: *mut AVInputFormat, |
8 | } |
9 | |
10 | impl Input { |
11 | pub unsafe fn wrap(ptr: *mut AVInputFormat) -> Self { |
12 | Input { ptr } |
13 | } |
14 | |
15 | pub unsafe fn as_ptr(&self) -> *const AVInputFormat { |
16 | self.ptr as *const _ |
17 | } |
18 | |
19 | pub unsafe fn as_mut_ptr(&mut self) -> *mut AVInputFormat { |
20 | self.ptr |
21 | } |
22 | } |
23 | |
24 | impl Input { |
25 | pub fn name(&self) -> &str { |
26 | unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).name).to_bytes()) } |
27 | } |
28 | |
29 | pub fn description(&self) -> &str { |
30 | unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).long_name).to_bytes()) } |
31 | } |
32 | |
33 | pub fn extensions(&self) -> Vec<&str> { |
34 | unsafe { |
35 | let ptr = (*self.as_ptr()).extensions; |
36 | |
37 | if ptr.is_null() { |
38 | Vec::new() |
39 | } else { |
40 | from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()) |
41 | .split(',' ) |
42 | .collect() |
43 | } |
44 | } |
45 | } |
46 | |
47 | pub fn mime_types(&self) -> Vec<&str> { |
48 | unsafe { |
49 | let ptr = (*self.as_ptr()).mime_type; |
50 | |
51 | if ptr.is_null() { |
52 | Vec::new() |
53 | } else { |
54 | from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()) |
55 | .split(',' ) |
56 | .collect() |
57 | } |
58 | } |
59 | } |
60 | } |
61 | |