gstreamer: Add Value::deserialize_with_pspec() from 1.20

This commit is contained in:
Sebastian Dröge 2021-08-17 08:47:26 +03:00
parent c5c9fd81e4
commit 43bfd1ae85

View file

@ -840,6 +840,13 @@ pub trait GstValueExt: Sized {
s: T,
type_: glib::Type,
) -> Result<glib::Value, glib::BoolError>;
#[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
#[doc(alias = "gst_value_deserialize_with_pspec")]
fn deserialize_with_pspec<'a, T: Into<&'a str>>(
s: T,
pspec: &glib::ParamSpec,
) -> Result<glib::Value, glib::BoolError>;
}
impl GstValueExt for glib::Value {
@ -1000,6 +1007,31 @@ impl GstValueExt for glib::Value {
}
}
}
#[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
fn deserialize_with_pspec<'a, T: Into<&'a str>>(
s: T,
pspec: &glib::ParamSpec,
) -> Result<glib::Value, glib::BoolError> {
assert_initialized_main_thread!();
let s = s.into();
unsafe {
let mut value = glib::Value::from_type(pspec.value_type());
let ret: bool = from_glib(ffi::gst_value_deserialize_with_pspec(
value.to_glib_none_mut().0,
s.to_glib_none().0,
pspec.to_glib_none().0,
));
if ret {
Ok(value)
} else {
Err(glib::bool_error!("Failed to deserialize value"))
}
}
}
}
#[cfg(test)]