software::resampling::Context: add get_with method (#41)
get_with allows setting additional options not covered by swr_alloc_set_opts. Signed-off-by: Zhiming Wang <i@zhimingwang.org>
This commit is contained in:

committed by
Zhiming Wang

parent
2e37fbf50d
commit
dc2a82f890
@ -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, Error> {
|
||||
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<Self, Error> {
|
||||
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)),
|
||||
|
Reference in New Issue
Block a user