util/dictionary: refactor and make more sound

This commit is contained in:
meh
2015-09-08 18:26:29 +02:00
parent 620958d684
commit f2fb08e491
16 changed files with 297 additions and 179 deletions

View File

@ -3,7 +3,7 @@ use std::ptr;
use ffi::*;
use libc::{c_int, c_uint};
use ::{media, Stream, StreamMut, Dictionary};
use ::{media, Stream, StreamMut, DictionaryRef};
pub struct Context {
ptr: *mut AVFormatContext,
@ -60,9 +60,9 @@ impl Context {
}
}
pub fn metadata(&self) -> Dictionary {
pub fn metadata(&self) -> DictionaryRef {
unsafe {
Dictionary::wrap((*self.as_ptr()).metadata)
DictionaryRef::wrap((*self.as_ptr()).metadata)
}
}
}

View File

@ -39,12 +39,12 @@ impl Output {
pub fn write_header_with(&mut self, options: Dictionary) -> Result<(), Error> {
unsafe {
let mut opts = options.take();
let status = avformat_write_header(self.as_mut_ptr(), &mut opts);
let mut opts = options.disown();
let res = avformat_write_header(self.as_mut_ptr(), &mut opts);
Dictionary::own(opts);
match status {
match res {
0 => Ok(()),
e => Err(Error::from(e)),
}

View File

@ -100,14 +100,16 @@ pub fn open_with<P: AsRef<Path>>(path: &P, format: &Format, options: Dictionary)
unsafe {
let mut ps = ptr::null_mut();
let path = from_path(path);
let mut opts = options.take();
let mut opts = options.disown();
match format {
&Format::Input(ref format) => {
match avformat_open_input(&mut ps, path.as_ptr(), format.as_ptr(), &mut opts) {
0 => {
Dictionary::own(opts);
let res = avformat_open_input(&mut ps, path.as_ptr(), format.as_ptr(), &mut opts);
Dictionary::own(opts);
match res {
0 => {
match avformat_find_stream_info(ps, ptr::null_mut()) {
0 => Ok(Context::Input(context::Input::wrap(ps))),
e => Err(Error::from(e)),
@ -156,12 +158,13 @@ pub fn input_with<P: AsRef<Path>>(path: &P, options: Dictionary) -> Result<conte
unsafe {
let mut ps = ptr::null_mut();
let path = from_path(path);
let mut opts = options.take();
let mut opts = options.disown();
let res = avformat_open_input(&mut ps, path.as_ptr(), ptr::null_mut(), &mut opts);
match avformat_open_input(&mut ps, path.as_ptr(), ptr::null_mut(), &mut opts) {
Dictionary::own(opts);
match res {
0 => {
Dictionary::own(opts);
match avformat_find_stream_info(ps, ptr::null_mut()) {
0 => Ok(context::Input::wrap(ps)),
e => Err(Error::from(e))