diff --git a/gstreamer-base/Cargo.toml b/gstreamer-base/Cargo.toml index e1fdbc42f..c07ff3e21 100644 --- a/gstreamer-base/Cargo.toml +++ b/gstreamer-base/Cargo.toml @@ -14,6 +14,7 @@ build = "build.rs" edition = "2018" [dependencies] +cfg-if = "1.0" libc = "0.2" bitflags = "1.0" ffi = { package = "gstreamer-base-sys", path = "sys", features = ["v1_8"] } @@ -27,7 +28,8 @@ gstreamer-rs-lgpl-docs = { path = "../docs", optional = true } default = [] v1_10 = ["gst/v1_10", "ffi/v1_10"] v1_12 = ["gst/v1_12", "ffi/v1_12", "v1_10"] -v1_14 = ["gst/v1_14", "ffi/v1_14", "v1_12"] +v1_12_1 = ["gst/v1_12_1", "ffi/v1_12_1", "v1_12"] +v1_14 = ["gst/v1_14", "ffi/v1_14", "v1_12_1"] v1_14_1 = ["gst/v1_14", "ffi/v1_14_1", "v1_14"] v1_16 = ["gst/v1_16", "ffi/v1_16", "v1_14_1"] v1_18 = ["gst/v1_18", "ffi/v1_18", "v1_16"] diff --git a/gstreamer-base/src/flow_combiner.rs b/gstreamer-base/src/flow_combiner.rs index 873853651..2a7aea635 100644 --- a/gstreamer-base/src/flow_combiner.rs +++ b/gstreamer-base/src/flow_combiner.rs @@ -8,8 +8,24 @@ glib::wrapper! { pub struct FlowCombiner(Shared); match fn { - ref => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::gst_flow_combiner_get_type(), ptr as *mut _), - unref => |ptr| glib::gobject_ffi::g_boxed_free(ffi::gst_flow_combiner_get_type(), ptr as *mut _), + ref => |ptr| { + // cfg_if emits code in blocks (curly braces) and `ref` handling inserts a + // trailing semicolon to void an optionally returned value. The linter + // requests the resulting { ..ref() }; to be simplified making it unsuitable. + #[cfg(feature = "v1_12_1")] + ffi::gst_flow_combiner_ref(ptr); + #[cfg(not(feature = "v1_12_1"))] + glib::gobject_ffi::g_boxed_copy(ffi::gst_flow_combiner_get_type(), ptr as *mut _); + }, + unref => |ptr| { + cfg_if::cfg_if! { + if #[cfg(feature = "v1_12_1")] { + ffi::gst_flow_combiner_unref(ptr) + } else { + glib::gobject_ffi::g_boxed_free(ffi::gst_flow_combiner_get_type(), ptr as *mut _) + } + } + }, get_type => || ffi::gst_flow_combiner_get_type(), } } diff --git a/gstreamer-sdp/src/sdp_message.rs b/gstreamer-sdp/src/sdp_message.rs index d06595f27..e2cee49a4 100644 --- a/gstreamer-sdp/src/sdp_message.rs +++ b/gstreamer-sdp/src/sdp_message.rs @@ -24,8 +24,12 @@ glib::wrapper! { pub struct SDPMessage(Boxed); match fn { - copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::gst_sdp_message_get_type(), ptr as *mut _) as *mut ffi::GstSDPMessage, - free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::gst_sdp_message_get_type(), ptr as *mut _), + copy => |ptr| { + let mut copy = std::ptr::null_mut(); + assert_eq!(ffi::gst_sdp_message_copy(ptr, &mut copy), ffi::GST_SDP_OK); + copy + }, + free => |ptr| assert_eq!(ffi::gst_sdp_message_free(ptr), ffi::GST_SDP_OK), get_type => || ffi::gst_sdp_message_get_type(), } } diff --git a/gstreamer/Cargo.toml b/gstreamer/Cargo.toml index 46712a691..d191dd83e 100644 --- a/gstreamer/Cargo.toml +++ b/gstreamer/Cargo.toml @@ -44,7 +44,8 @@ futures-executor = "0.3.1" default = [] v1_10 = ["ffi/v1_10"] v1_12 = ["ffi/v1_12", "v1_10"] -v1_14 = ["ffi/v1_14", "v1_12"] +v1_12_1 = ["ffi/v1_12_1", "v1_12"] +v1_14 = ["ffi/v1_14", "v1_12_1"] v1_16 = ["ffi/v1_16", "v1_14"] v1_18 = ["ffi/v1_18", "v1_16"] v1_20 = ["ffi/v1_20", "v1_18"] diff --git a/gstreamer/src/parse_context.rs b/gstreamer/src/parse_context.rs index b79009d94..fb75fa7f0 100644 --- a/gstreamer/src/parse_context.rs +++ b/gstreamer/src/parse_context.rs @@ -8,11 +8,15 @@ glib::wrapper! { match fn { copy => |ptr| { - glib::gobject_ffi::g_boxed_copy(ffi::gst_parse_context_get_type(), ptr as *mut _) as *mut ffi::GstParseContext - }, - free => |ptr| { - glib::gobject_ffi::g_boxed_free(ffi::gst_parse_context_get_type(), ptr as *mut _) + cfg_if::cfg_if! { + if #[cfg(feature = "v1_12_1")] { + ffi::gst_parse_context_copy(ptr) + } else { + glib::gobject_ffi::g_boxed_copy(ffi::gst_parse_context_get_type(), ptr as *mut _) as *mut ffi::GstParseContext + } + } }, + free => |ptr| ffi::gst_parse_context_free(ptr), get_type => || ffi::gst_parse_context_get_type(), } }