diff --git a/src/software/resampling/context.rs b/src/software/resampling/context.rs index 9b390db..47c7b5a 100644 --- a/src/software/resampling/context.rs +++ b/src/software/resampling/context.rs @@ -3,7 +3,9 @@ use std::ptr; use super::Delay; use ffi::*; use libc::c_int; +use std::ffi::c_void; use util::format; +use Dictionary; use {frame, ChannelLayout, Error}; #[derive(Eq, PartialEq, Copy, Clone)] @@ -43,6 +45,27 @@ impl Context { dst_format: format::Sample, dst_channel_layout: ChannelLayout, dst_rate: u32, + ) -> Result { + Self::get_with( + src_format, + src_channel_layout, + src_rate, + dst_format, + dst_channel_layout, + dst_rate, + Dictionary::new(), + ) + } + + /// Create a resampler with the given definitions and custom options dictionary. + pub fn get_with( + src_format: format::Sample, + src_channel_layout: ChannelLayout, + src_rate: u32, + dst_format: format::Sample, + dst_channel_layout: ChannelLayout, + dst_rate: u32, + options: Dictionary, ) -> Result { unsafe { let ptr = swr_alloc_set_opts( @@ -57,6 +80,14 @@ impl Context { ptr::null_mut(), ); + let mut opts = options.disown(); + let res = av_opt_set_dict(ptr as *mut c_void, &mut opts); + Dictionary::own(opts); + + if res != 0 { + return Err(Error::from(res)); + } + if !ptr.is_null() { match swr_init(ptr) { e if e < 0 => Err(Error::from(e)),