audio: Add bindings for GstAudioFilter

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1168>
This commit is contained in:
Arun Raghavan 2022-12-13 11:10:05 -05:00 committed by Sebastian Dröge
parent bb90b58547
commit bd46e74386
6 changed files with 116 additions and 0 deletions

View file

@ -23,6 +23,7 @@ generate = [
"GstAudio.AudioBaseSrc", "GstAudio.AudioBaseSrc",
"GstAudio.AudioChannelPosition", "GstAudio.AudioChannelPosition",
"GstAudio.AudioDitherMethod", "GstAudio.AudioDitherMethod",
"GstAudio.AudioFilter",
"GstAudio.AudioFormatFlags", "GstAudio.AudioFormatFlags",
"GstAudio.AudioLayout", "GstAudio.AudioLayout",
"GstAudio.AudioNoiseShapingMethod", "GstAudio.AudioNoiseShapingMethod",
@ -53,6 +54,7 @@ manual = [
"GstBase.AggregatorPad", "GstBase.AggregatorPad",
"GstBase.BaseSink", "GstBase.BaseSink",
"GstBase.BaseSrc", "GstBase.BaseSrc",
"GstBase.BaseTransform",
] ]
[[object]] [[object]]

View file

@ -401,6 +401,17 @@ impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstAudioInfo> for AudioInfo
} }
} }
#[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*const ffi::GstAudioInfo> for AudioInfo {
#[inline]
unsafe fn from_glib_none(ptr: *const ffi::GstAudioInfo) -> Self {
Self(
ptr::read(ptr),
std::array::from_fn(|i| from_glib((*ptr).position[i])),
)
}
}
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*mut ffi::GstAudioInfo> for AudioInfo { impl glib::translate::FromGlibPtrNone<*mut ffi::GstAudioInfo> for AudioInfo {
#[inline] #[inline]

View file

@ -0,0 +1,20 @@
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT
glib::wrapper! {
#[doc(alias = "GstAudioFilter")]
pub struct AudioFilter(Object<ffi::GstAudioFilter, ffi::GstAudioFilterClass>) @extends gst_base::BaseTransform, gst::Element, gst::Object;
match fn {
type_ => || ffi::gst_audio_filter_get_type(),
}
}
impl AudioFilter {
pub const NONE: Option<&'static AudioFilter> = None;
}
unsafe impl Send for AudioFilter {}
unsafe impl Sync for AudioFilter {}

View file

@ -24,6 +24,9 @@ pub use self::audio_decoder::AudioDecoder;
mod audio_encoder; mod audio_encoder;
pub use self::audio_encoder::AudioEncoder; pub use self::audio_encoder::AudioEncoder;
mod audio_filter;
pub use self::audio_filter::AudioFilter;
mod audio_sink; mod audio_sink;
pub use self::audio_sink::AudioSink; pub use self::audio_sink::AudioSink;

View file

@ -0,0 +1,78 @@
// Take a look at the license at the top of the repository in the LICENSE file.
use glib::translate::*;
use gst_base::prelude::*;
use gst_base::subclass::prelude::*;
use crate::AudioFilter;
use crate::AudioInfo;
pub trait AudioFilterImpl: AudioFilterImplExt + BaseTransformImpl {
fn allowed_caps() -> &'static gst::Caps;
fn setup(&self, info: &AudioInfo) -> Result<(), gst::LoggableError> {
self.parent_setup(info)
}
}
pub trait AudioFilterImplExt: ObjectSubclass {
fn parent_setup(&self, info: &AudioInfo) -> Result<(), gst::LoggableError>;
}
impl<T: AudioFilterImpl> AudioFilterImplExt for T {
fn parent_setup(&self, info: &AudioInfo) -> Result<(), gst::LoggableError> {
unsafe {
let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioFilterClass;
(*parent_class)
.setup
.map(|f| {
gst::result_from_gboolean!(
f(
self.obj().unsafe_cast_ref::<AudioFilter>().to_glib_none().0,
info.to_glib_none().0,
),
gst::CAT_RUST,
"Parent function `setup` failed"
)
})
.unwrap_or(Ok(()))
}
}
}
unsafe impl<T: AudioFilterImpl> IsSubclassable<T> for AudioFilter {
fn class_init(klass: &mut glib::Class<Self>) {
Self::parent_class_init::<T>(klass);
let klass = klass.as_mut();
klass.setup = Some(audio_filter_setup::<T>);
unsafe {
ffi::gst_audio_filter_class_add_pad_templates(
&mut *klass,
T::allowed_caps().to_glib_none().0,
);
}
}
}
unsafe extern "C" fn audio_filter_setup<T: AudioFilterImpl>(
ptr: *mut ffi::GstAudioFilter,
info: *const ffi::GstAudioInfo,
) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();
gst::panic_to_error!(imp, false, {
match imp.setup(&from_glib_none(info)) {
Ok(()) => true,
Err(err) => {
err.log_with_imp(imp);
false
}
}
})
.into_glib()
}

View file

@ -9,6 +9,7 @@ mod audio_base_sink;
mod audio_base_src; mod audio_base_src;
mod audio_decoder; mod audio_decoder;
mod audio_encoder; mod audio_encoder;
mod audio_filter;
mod audio_sink; mod audio_sink;
mod audio_src; mod audio_src;
@ -23,6 +24,7 @@ pub mod prelude {
pub use super::audio_base_src::AudioBaseSrcImpl; pub use super::audio_base_src::AudioBaseSrcImpl;
pub use super::audio_decoder::{AudioDecoderImpl, AudioDecoderImplExt}; pub use super::audio_decoder::{AudioDecoderImpl, AudioDecoderImplExt};
pub use super::audio_encoder::{AudioEncoderImpl, AudioEncoderImplExt}; pub use super::audio_encoder::{AudioEncoderImpl, AudioEncoderImplExt};
pub use super::audio_filter::{AudioFilterImpl, AudioFilterImplExt};
pub use super::audio_sink::{AudioSinkImpl, AudioSinkImplExt}; pub use super::audio_sink::{AudioSinkImpl, AudioSinkImplExt};
pub use super::audio_src::{AudioSrcImpl, AudioSrcImplExt}; pub use super::audio_src::{AudioSrcImpl, AudioSrcImplExt};
} }