gst,base,sdp: Use specific copy/free or (un)ref instead of g_boxed

SDPMessage, FlowCombiner and ParseContext have specific functions
available to perform copying, freeing and (un)ref'ing. Calling them
directly on versions where they are supported prevents us from going
through GType machinery and locks that end up the same functions in the
end.
This commit is contained in:
Marijn Suijten 2021-01-07 20:08:36 +01:00
parent 29326ebfdd
commit 3c610e12e5
5 changed files with 37 additions and 10 deletions

View file

@ -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"]

View file

@ -8,8 +8,24 @@ glib::wrapper! {
pub struct FlowCombiner(Shared<ffi::GstFlowCombiner>);
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(),
}
}

View file

@ -24,8 +24,12 @@ glib::wrapper! {
pub struct SDPMessage(Boxed<ffi::GstSDPMessage>);
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(),
}
}

View file

@ -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"]

View file

@ -8,11 +8,15 @@ glib::wrapper! {
match fn {
copy => |ptr| {
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| {
glib::gobject_ffi::g_boxed_free(ffi::gst_parse_context_get_type(), ptr as *mut _)
},
free => |ptr| ffi::gst_parse_context_free(ptr),
get_type => || ffi::gst_parse_context_get_type(),
}
}