diff --git a/gstreamer-app/src/app_sink.rs b/gstreamer-app/src/app_sink.rs index b81e5138a..bedb43772 100644 --- a/gstreamer-app/src/app_sink.rs +++ b/gstreamer-app/src/app_sink.rs @@ -277,30 +277,35 @@ impl AppSink { #[doc(alias = "gst_app_sink_set_callbacks")] pub fn set_callbacks(&self, callbacks: AppSinkCallbacks) { + #[cfg(not(feature = "v1_18"))] use once_cell::sync::Lazy; + #[cfg(not(feature = "v1_18"))] static SET_ONCE_QUARK: Lazy = Lazy::new(|| glib::Quark::from_str("gstreamer-rs-app-sink-callbacks")); unsafe { let sink = self.to_glib_none().0; - // This is not thread-safe before 1.16.3, see - // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570 - if gst::version() < (1, 16, 3, 0) { - if !glib::gobject_ffi::g_object_get_qdata( - sink as *mut _, - SET_ONCE_QUARK.into_glib(), - ) - .is_null() - { - panic!("AppSink callbacks can only be set once"); - } + #[cfg(not(feature = "v1_18"))] + { + // This is not thread-safe before 1.16.3, see + // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570 + if gst::version() < (1, 16, 3, 0) { + if !glib::gobject_ffi::g_object_get_qdata( + sink as *mut _, + SET_ONCE_QUARK.into_glib(), + ) + .is_null() + { + panic!("AppSink callbacks can only be set once"); + } - glib::gobject_ffi::g_object_set_qdata( - sink as *mut _, - SET_ONCE_QUARK.into_glib(), - 1 as *mut _, - ); + glib::gobject_ffi::g_object_set_qdata( + sink as *mut _, + SET_ONCE_QUARK.into_glib(), + 1 as *mut _, + ); + } } ffi::gst_app_sink_set_callbacks( @@ -1166,11 +1171,14 @@ impl AppSinkStream { impl Drop for AppSinkStream { fn drop(&mut self) { - // This is not thread-safe before 1.16.3, see - // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570 - if gst::version() >= (1, 16, 3, 0) { - if let Some(app_sink) = self.app_sink.upgrade() { - app_sink.set_callbacks(AppSinkCallbacks::builder().build()); + #[cfg(not(feature = "v1_18"))] + { + // This is not thread-safe before 1.16.3, see + // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570 + if gst::version() >= (1, 16, 3, 0) { + if let Some(app_sink) = self.app_sink.upgrade() { + app_sink.set_callbacks(AppSinkCallbacks::builder().build()); + } } } } diff --git a/gstreamer-app/src/app_src.rs b/gstreamer-app/src/app_src.rs index fd9e0fded..224bb5d64 100644 --- a/gstreamer-app/src/app_src.rs +++ b/gstreamer-app/src/app_src.rs @@ -222,26 +222,34 @@ impl AppSrc { #[doc(alias = "gst_app_src_set_callbacks")] pub fn set_callbacks(&self, callbacks: AppSrcCallbacks) { + #[cfg(not(feature = "v1_18"))] use once_cell::sync::Lazy; + #[cfg(not(feature = "v1_18"))] static SET_ONCE_QUARK: Lazy = Lazy::new(|| glib::Quark::from_str("gstreamer-rs-app-src-callbacks")); unsafe { let src = self.to_glib_none().0; - // This is not thread-safe before 1.16.3, see - // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570 - if gst::version() < (1, 16, 3, 0) { - if !glib::gobject_ffi::g_object_get_qdata(src as *mut _, SET_ONCE_QUARK.into_glib()) + #[cfg(not(feature = "v1_18"))] + { + // This is not thread-safe before 1.16.3, see + // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570 + if gst::version() < (1, 16, 3, 0) { + if !glib::gobject_ffi::g_object_get_qdata( + src as *mut _, + SET_ONCE_QUARK.into_glib(), + ) .is_null() - { - panic!("AppSrc callbacks can only be set once"); - } + { + panic!("AppSrc callbacks can only be set once"); + } - glib::gobject_ffi::g_object_set_qdata( - src as *mut _, - SET_ONCE_QUARK.into_glib(), - 1 as *mut _, - ); + glib::gobject_ffi::g_object_set_qdata( + src as *mut _, + SET_ONCE_QUARK.into_glib(), + 1 as *mut _, + ); + } } ffi::gst_app_src_set_callbacks( @@ -600,11 +608,14 @@ impl AppSrcSink { impl Drop for AppSrcSink { fn drop(&mut self) { - // This is not thread-safe before 1.16.3, see - // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570 - if gst::version() >= (1, 16, 3, 0) { - if let Some(app_src) = self.app_src.upgrade() { - app_src.set_callbacks(AppSrcCallbacks::builder().build()); + #[cfg(not(feature = "v1_18"))] + { + // This is not thread-safe before 1.16.3, see + // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570 + if gst::version() >= (1, 16, 3, 0) { + if let Some(app_src) = self.app_src.upgrade() { + app_src.set_callbacks(AppSrcCallbacks::builder().build()); + } } } } diff --git a/gstreamer/src/allocator.rs b/gstreamer/src/allocator.rs index 9be7e5eae..f8b9a126b 100644 --- a/gstreamer/src/allocator.rs +++ b/gstreamer/src/allocator.rs @@ -9,13 +9,23 @@ impl Allocator { pub fn register(name: &str, allocator: impl IsA) { skip_assert_initialized!(); unsafe { - // See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3364 - if crate::version() < (1, 20, 5, 0) { - ffi::gst_allocator_register( - name.to_glib_full(), - allocator.upcast().into_glib_ptr(), - ); - } else { + #[cfg(not(feature = "v1_22"))] + { + // See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3364 + if crate::version() < (1, 20, 5, 0) { + ffi::gst_allocator_register( + name.to_glib_full(), + allocator.upcast().into_glib_ptr(), + ); + } else { + ffi::gst_allocator_register( + name.to_glib_none().0, + allocator.upcast().into_glib_ptr(), + ); + } + } + #[cfg(feature = "v1_22")] + { ffi::gst_allocator_register( name.to_glib_none().0, allocator.upcast().into_glib_ptr(), diff --git a/gstreamer/src/bus.rs b/gstreamer/src/bus.rs index 0edca388e..18c3f86c6 100644 --- a/gstreamer/src/bus.rs +++ b/gstreamer/src/bus.rs @@ -189,27 +189,35 @@ impl Bus { where F: Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static, { + #[cfg(not(feature = "v1_18"))] use once_cell::sync::Lazy; + #[cfg(not(feature = "v1_18"))] static SET_ONCE_QUARK: Lazy = Lazy::new(|| glib::Quark::from_str("gstreamer-rs-sync-handler")); unsafe { let bus = self.to_glib_none().0; - // This is not thread-safe before 1.16.3, see - // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/merge_requests/416 - if crate::version() < (1, 16, 3, 0) { - if !glib::gobject_ffi::g_object_get_qdata(bus as *mut _, SET_ONCE_QUARK.into_glib()) + #[cfg(not(feature = "v1_18"))] + { + // This is not thread-safe before 1.16.3, see + // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/merge_requests/416 + if crate::version() < (1, 16, 3, 0) { + if !glib::gobject_ffi::g_object_get_qdata( + bus as *mut _, + SET_ONCE_QUARK.into_glib(), + ) .is_null() - { - panic!("Bus sync handler can only be set once"); - } + { + panic!("Bus sync handler can only be set once"); + } - glib::gobject_ffi::g_object_set_qdata( - bus as *mut _, - SET_ONCE_QUARK.into_glib(), - 1 as *mut _, - ); + glib::gobject_ffi::g_object_set_qdata( + bus as *mut _, + SET_ONCE_QUARK.into_glib(), + 1 as *mut _, + ); + } } ffi::gst_bus_set_sync_handler( @@ -222,10 +230,13 @@ impl Bus { } pub fn unset_sync_handler(&self) { - // This is not thread-safe before 1.16.3, see - // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/merge_requests/416 - if crate::version() < (1, 16, 3, 0) { - return; + #[cfg(not(feature = "v1_18"))] + { + // This is not thread-safe before 1.16.3, see + // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/merge_requests/416 + if crate::version() < (1, 16, 3, 0) { + return; + } } unsafe {