From 3d38d274c2f0c14bb6b0ad5ee864641995e2b130 Mon Sep 17 00:00:00 2001 From: meh Date: Fri, 15 May 2015 19:40:24 +0200 Subject: [PATCH] avresample: add bindings --- sys/Cargo.toml | 15 ++++---- sys/src/avresample/mod.rs | 5 +++ sys/src/avresample/resample.rs | 62 ++++++++++++++++++++++++++++++++++ sys/src/lib.rs | 5 +++ 4 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 sys/src/avresample/mod.rs create mode 100644 sys/src/avresample/resample.rs diff --git a/sys/Cargo.toml b/sys/Cargo.toml index bff6918..7ea8c03 100644 --- a/sys/Cargo.toml +++ b/sys/Cargo.toml @@ -9,11 +9,12 @@ description = "FFI bindings to FFmpeg" repository = "https://github.com/meh/rust-ffmpeg-sys" [features] -default = ["avcodec", "avdevice", "avfilter", "avformat", "postproc", "swscale"] +default = ["avcodec", "avdevice", "avfilter", "avformat", "avresample", "postproc", "swscale"] -avcodec = [] -avdevice = ["avformat"] -avfilter = [] -avformat = ["avcodec"] -postproc = [] -swscale = [] +avcodec = [] +avdevice = ["avformat"] +avfilter = [] +avformat = ["avcodec"] +avresample = [] +postproc = [] +swscale = [] diff --git a/sys/src/avresample/mod.rs b/sys/src/avresample/mod.rs new file mode 100644 index 0000000..b74e900 --- /dev/null +++ b/sys/src/avresample/mod.rs @@ -0,0 +1,5 @@ +mod resample; +pub use self::resample::*; +pub use self::resample::AVMixCoeffType::*; +pub use self::resample::AVResampleFilterType::*; +pub use self::resample::AVResampleDitherMethod::*; diff --git a/sys/src/avresample/resample.rs b/sys/src/avresample/resample.rs new file mode 100644 index 0000000..02ac90e --- /dev/null +++ b/sys/src/avresample/resample.rs @@ -0,0 +1,62 @@ +use libc::{c_void, c_char, c_int, c_uint, c_double, uint8_t, uint64_t}; +use ::avutil::{AVClass, AVMatrixEncoding, AVFrame}; + +pub const AVRESAMPLE_MAX_CHANNELS: c_int = 32; + +pub type AVAudioResampleContext = c_void; + +#[derive(Eq, PartialEq, Copy, Clone, Debug)] +#[repr(C)] +pub enum AVMixCoeffType { + AV_MIX_COEFF_TYPE_Q8, + AV_MIX_COEFF_TYPE_Q15, + AV_MIX_COEFF_TYPE_FLT, + AV_MIX_COEFF_TYPE_NB, +} + +#[derive(Eq, PartialEq, Copy, Clone, Debug)] +#[repr(C)] +pub enum AVResampleFilterType { + AV_RESAMPLE_FILTER_TYPE_CUBIC, + AV_RESAMPLE_FILTER_TYPE_BLACKMAN_NUTTALL, + AV_RESAMPLE_FILTER_TYPE_KAISER, +} + +#[derive(Eq, PartialEq, Copy, Clone, Debug)] +#[repr(C)] +pub enum AVResampleDitherMethod { + AV_RESAMPLE_DITHER_NONE, + AV_RESAMPLE_DITHER_RECTANGULAR, + AV_RESAMPLE_DITHER_TRIANGULAR, + AV_RESAMPLE_DITHER_TRIANGULAR_HP, + AV_RESAMPLE_DITHER_TRIANGULAR_NS, + AV_RESAMPLE_DITHER_NB, +} + +#[link(name = "avresample")] +extern { + pub fn avresample_version() -> c_uint; + pub fn avresample_configuration() -> *const c_char; + pub fn avresample_license() -> *const c_char; + + pub fn avresample_get_class() -> *const AVClass; + + pub fn avresample_alloc_context() -> *mut AVAudioResampleContext; + pub fn avresample_open(avr: *mut AVAudioResampleContext) -> c_int; + pub fn avresample_is_open(avr: *mut AVAudioResampleContext) -> c_int; + pub fn avresample_close(avr: *mut AVAudioResampleContext); + pub fn avresample_free(avr: *mut *mut AVAudioResampleContext); + + pub fn avresample_build_matrix(in_layout: uint64_t, out_layout: uint64_t, center_mix_level: c_double, surround_mix_level: c_double, lfe_mix_level: c_double, normalize: c_int, matrix: *mut c_double, stride: c_int, matrix_encoding: AVMatrixEncoding) -> c_int; + pub fn avresample_get_matrix(avr: *mut AVAudioResampleContext, matrix: *mut c_double, stride: c_int) -> c_int; + pub fn avresample_set_matrix(avr: *mut AVAudioResampleContext, matrix: *const c_double, stride: c_int) -> c_int; + pub fn avresample_set_channel_mapping(avr: *mut AVAudioResampleContext, channel_map: *const c_int) -> c_int; + pub fn avresample_set_compensation(avr: *mut AVAudioResampleContext, sample_delta: c_int, compensation_distance: c_int) -> c_int; + pub fn avresample_get_out_samples(avr: *mut AVAudioResampleContext, in_nb_samples: c_int) -> c_int; + pub fn avresample_convert(avr: *mut AVAudioResampleContext, output: *mut *mut uint8_t, out_plane_size: c_int, out_samples: c_int, input: *mut *mut uint8_t, in_plane_size: c_int, in_samples: c_int) -> c_int; + pub fn avresample_get_delay(avr: *mut AVAudioResampleContext) -> c_int; + pub fn avresample_available(avr: *mut AVAudioResampleContext) -> c_int; + pub fn avresample_read(avr: *mut AVAudioResampleContext, output: *mut *mut uint8_t, nb_samples: c_int) -> c_int; + pub fn avresample_convert_frame(avr: *mut AVAudioResampleContext, output: *mut AVFrame, input: *const AVFrame) -> c_int; + pub fn avresample_config(avr: *mut AVAudioResampleContext, output: *mut AVFrame, input: *const AVFrame) -> c_int; +} diff --git a/sys/src/lib.rs b/sys/src/lib.rs index 0ef205b..5a214a4 100644 --- a/sys/src/lib.rs +++ b/sys/src/lib.rs @@ -27,6 +27,11 @@ mod avfilter; #[cfg(feature = "avfilter")] pub use avfilter::*; +#[cfg(feature = "avresample")] +mod avresample; +#[cfg(feature = "avresample")] +pub use avresample::*; + #[cfg(feature = "swscale")] mod swscale; #[cfg(feature = "swscale")]