1use std::path::Path;
2
3use std::ffi::{CStr, CString};
4use std::ptr;
5use std::str::from_utf8_unchecked;
6
7use super::Flags;
8use ffi::*;
9use {codec, media};
10
11pub struct Output {
12 ptr: *mut AVOutputFormat,
13}
14
15impl Output {
16 pub unsafe fn wrap(ptr: *mut AVOutputFormat) -> Self {
17 Output { ptr }
18 }
19
20 pub unsafe fn as_ptr(&self) -> *const AVOutputFormat {
21 self.ptr as *const _
22 }
23
24 pub unsafe fn as_mut_ptr(&mut self) -> *mut AVOutputFormat {
25 self.ptr
26 }
27}
28
29impl Output {
30 pub fn name(&self) -> &str {
31 unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).name).to_bytes()) }
32 }
33
34 pub fn description(&self) -> &str {
35 unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).long_name).to_bytes()) }
36 }
37
38 pub fn extensions(&self) -> Vec<&str> {
39 unsafe {
40 let ptr = (*self.as_ptr()).extensions;
41
42 if ptr.is_null() {
43 Vec::new()
44 } else {
45 from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes())
46 .split(',')
47 .collect()
48 }
49 }
50 }
51
52 pub fn mime_types(&self) -> Vec<&str> {
53 unsafe {
54 let ptr = (*self.as_ptr()).mime_type;
55
56 if ptr.is_null() {
57 Vec::new()
58 } else {
59 from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes())
60 .split(',')
61 .collect()
62 }
63 }
64 }
65
66 pub fn codec<P: AsRef<Path> + ?Sized>(&self, path: &P, kind: media::Type) -> codec::Id {
67 // XXX: use to_cstring when stable
68 let path = CString::new(path.as_ref().as_os_str().to_str().unwrap()).unwrap();
69
70 unsafe {
71 codec::Id::from(av_guess_codec(
72 self.as_ptr() as *mut _,
73 ptr::null(),
74 path.as_ptr(),
75 ptr::null(),
76 kind.into(),
77 ))
78 }
79 }
80
81 pub fn flags(&self) -> Flags {
82 unsafe { Flags::from_bits_truncate((*self.as_ptr()).flags) }
83 }
84}
85