From 02f4e7dad0b9aa876170cfe287dd81051bcad8c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 5 Dec 2023 11:14:44 +0200 Subject: [PATCH] gstreamer: audiofilter: Add `parent_allowed_caps()` Part-of: --- gstreamer-audio/src/subclass/audio_filter.rs | 27 ++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/gstreamer-audio/src/subclass/audio_filter.rs b/gstreamer-audio/src/subclass/audio_filter.rs index 80f445b64..322fe6d33 100644 --- a/gstreamer-audio/src/subclass/audio_filter.rs +++ b/gstreamer-audio/src/subclass/audio_filter.rs @@ -1,12 +1,14 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use glib::translate::*; +use glib::{once_cell::sync::Lazy, translate::*}; use gst_base::{prelude::*, subclass::prelude::*}; use crate::{AudioFilter, AudioInfo}; pub trait AudioFilterImpl: AudioFilterImplExt + BaseTransformImpl { - fn allowed_caps() -> &'static gst::Caps; + fn allowed_caps() -> &'static gst::Caps { + Self::parent_allowed_caps() + } fn setup(&self, info: &AudioInfo) -> Result<(), gst::LoggableError> { self.parent_setup(info) @@ -38,6 +40,27 @@ pub trait AudioFilterImplExt: sealed::Sealed + ObjectSubclass { .unwrap_or(Ok(())) } } + + fn parent_allowed_caps() -> &'static gst::Caps { + unsafe { + let data = Self::type_data(); + let parent_class = data.as_ref().parent_class() as *mut gst::ffi::GstElementClass; + + let templ = gst::ffi::gst_element_class_get_pad_template( + parent_class, + glib::gstr!("sink").to_glib_none().0, + ); + + if templ.is_null() { + static ANY_AUDIO_CAPS: Lazy = + Lazy::new(|| crate::AudioCapsBuilder::new().build()); + + return &ANY_AUDIO_CAPS; + } + + &*(&(*templ).caps as *const *mut gst::ffi::GstCaps as *const gst::Caps) + } + } } impl AudioFilterImplExt for T {}