Compile out GStreamer version checks if a high enough version is configured at build time

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1184>
This commit is contained in:
Sebastian Dröge 2023-01-05 18:14:54 +02:00
parent 277d63601c
commit 89326c7e7c
4 changed files with 101 additions and 61 deletions

View file

@ -277,30 +277,35 @@ impl AppSink {
#[doc(alias = "gst_app_sink_set_callbacks")] #[doc(alias = "gst_app_sink_set_callbacks")]
pub fn set_callbacks(&self, callbacks: AppSinkCallbacks) { pub fn set_callbacks(&self, callbacks: AppSinkCallbacks) {
#[cfg(not(feature = "v1_18"))]
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
#[cfg(not(feature = "v1_18"))]
static SET_ONCE_QUARK: Lazy<glib::Quark> = static SET_ONCE_QUARK: Lazy<glib::Quark> =
Lazy::new(|| glib::Quark::from_str("gstreamer-rs-app-sink-callbacks")); Lazy::new(|| glib::Quark::from_str("gstreamer-rs-app-sink-callbacks"));
unsafe { unsafe {
let sink = self.to_glib_none().0; let sink = self.to_glib_none().0;
// This is not thread-safe before 1.16.3, see #[cfg(not(feature = "v1_18"))]
// https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570 {
if gst::version() < (1, 16, 3, 0) { // This is not thread-safe before 1.16.3, see
if !glib::gobject_ffi::g_object_get_qdata( // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570
sink as *mut _, if gst::version() < (1, 16, 3, 0) {
SET_ONCE_QUARK.into_glib(), if !glib::gobject_ffi::g_object_get_qdata(
) sink as *mut _,
.is_null() SET_ONCE_QUARK.into_glib(),
{ )
panic!("AppSink callbacks can only be set once"); .is_null()
} {
panic!("AppSink callbacks can only be set once");
}
glib::gobject_ffi::g_object_set_qdata( glib::gobject_ffi::g_object_set_qdata(
sink as *mut _, sink as *mut _,
SET_ONCE_QUARK.into_glib(), SET_ONCE_QUARK.into_glib(),
1 as *mut _, 1 as *mut _,
); );
}
} }
ffi::gst_app_sink_set_callbacks( ffi::gst_app_sink_set_callbacks(
@ -1166,11 +1171,14 @@ impl AppSinkStream {
impl Drop for AppSinkStream { impl Drop for AppSinkStream {
fn drop(&mut self) { fn drop(&mut self) {
// This is not thread-safe before 1.16.3, see #[cfg(not(feature = "v1_18"))]
// https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570 {
if gst::version() >= (1, 16, 3, 0) { // This is not thread-safe before 1.16.3, see
if let Some(app_sink) = self.app_sink.upgrade() { // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570
app_sink.set_callbacks(AppSinkCallbacks::builder().build()); if gst::version() >= (1, 16, 3, 0) {
if let Some(app_sink) = self.app_sink.upgrade() {
app_sink.set_callbacks(AppSinkCallbacks::builder().build());
}
} }
} }
} }

View file

@ -222,26 +222,34 @@ impl AppSrc {
#[doc(alias = "gst_app_src_set_callbacks")] #[doc(alias = "gst_app_src_set_callbacks")]
pub fn set_callbacks(&self, callbacks: AppSrcCallbacks) { pub fn set_callbacks(&self, callbacks: AppSrcCallbacks) {
#[cfg(not(feature = "v1_18"))]
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
#[cfg(not(feature = "v1_18"))]
static SET_ONCE_QUARK: Lazy<glib::Quark> = static SET_ONCE_QUARK: Lazy<glib::Quark> =
Lazy::new(|| glib::Quark::from_str("gstreamer-rs-app-src-callbacks")); Lazy::new(|| glib::Quark::from_str("gstreamer-rs-app-src-callbacks"));
unsafe { unsafe {
let src = self.to_glib_none().0; let src = self.to_glib_none().0;
// This is not thread-safe before 1.16.3, see #[cfg(not(feature = "v1_18"))]
// https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570 {
if gst::version() < (1, 16, 3, 0) { // This is not thread-safe before 1.16.3, see
if !glib::gobject_ffi::g_object_get_qdata(src as *mut _, SET_ONCE_QUARK.into_glib()) // 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() .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( glib::gobject_ffi::g_object_set_qdata(
src as *mut _, src as *mut _,
SET_ONCE_QUARK.into_glib(), SET_ONCE_QUARK.into_glib(),
1 as *mut _, 1 as *mut _,
); );
}
} }
ffi::gst_app_src_set_callbacks( ffi::gst_app_src_set_callbacks(
@ -600,11 +608,14 @@ impl AppSrcSink {
impl Drop for AppSrcSink { impl Drop for AppSrcSink {
fn drop(&mut self) { fn drop(&mut self) {
// This is not thread-safe before 1.16.3, see #[cfg(not(feature = "v1_18"))]
// https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570 {
if gst::version() >= (1, 16, 3, 0) { // This is not thread-safe before 1.16.3, see
if let Some(app_src) = self.app_src.upgrade() { // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570
app_src.set_callbacks(AppSrcCallbacks::builder().build()); if gst::version() >= (1, 16, 3, 0) {
if let Some(app_src) = self.app_src.upgrade() {
app_src.set_callbacks(AppSrcCallbacks::builder().build());
}
} }
} }
} }

View file

@ -9,13 +9,23 @@ impl Allocator {
pub fn register(name: &str, allocator: impl IsA<Allocator>) { pub fn register(name: &str, allocator: impl IsA<Allocator>) {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
// See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3364 #[cfg(not(feature = "v1_22"))]
if crate::version() < (1, 20, 5, 0) { {
ffi::gst_allocator_register( // See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3364
name.to_glib_full(), if crate::version() < (1, 20, 5, 0) {
allocator.upcast().into_glib_ptr(), ffi::gst_allocator_register(
); name.to_glib_full(),
} else { 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( ffi::gst_allocator_register(
name.to_glib_none().0, name.to_glib_none().0,
allocator.upcast().into_glib_ptr(), allocator.upcast().into_glib_ptr(),

View file

@ -189,27 +189,35 @@ impl Bus {
where where
F: Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static, F: Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static,
{ {
#[cfg(not(feature = "v1_18"))]
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
#[cfg(not(feature = "v1_18"))]
static SET_ONCE_QUARK: Lazy<glib::Quark> = static SET_ONCE_QUARK: Lazy<glib::Quark> =
Lazy::new(|| glib::Quark::from_str("gstreamer-rs-sync-handler")); Lazy::new(|| glib::Quark::from_str("gstreamer-rs-sync-handler"));
unsafe { unsafe {
let bus = self.to_glib_none().0; let bus = self.to_glib_none().0;
// This is not thread-safe before 1.16.3, see #[cfg(not(feature = "v1_18"))]
// https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/merge_requests/416 {
if crate::version() < (1, 16, 3, 0) { // This is not thread-safe before 1.16.3, see
if !glib::gobject_ffi::g_object_get_qdata(bus as *mut _, SET_ONCE_QUARK.into_glib()) // 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() .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( glib::gobject_ffi::g_object_set_qdata(
bus as *mut _, bus as *mut _,
SET_ONCE_QUARK.into_glib(), SET_ONCE_QUARK.into_glib(),
1 as *mut _, 1 as *mut _,
); );
}
} }
ffi::gst_bus_set_sync_handler( ffi::gst_bus_set_sync_handler(
@ -222,10 +230,13 @@ impl Bus {
} }
pub fn unset_sync_handler(&self) { pub fn unset_sync_handler(&self) {
// This is not thread-safe before 1.16.3, see #[cfg(not(feature = "v1_18"))]
// https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/merge_requests/416 {
if crate::version() < (1, 16, 3, 0) { // This is not thread-safe before 1.16.3, see
return; // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/merge_requests/416
if crate::version() < (1, 16, 3, 0) {
return;
}
} }
unsafe { unsafe {