From 43bfd1ae85e18af442b3d2c87a88c83b315f796a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 17 Aug 2021 08:47:26 +0300 Subject: [PATCH] gstreamer: Add Value::deserialize_with_pspec() from 1.20 --- gstreamer/src/value.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/gstreamer/src/value.rs b/gstreamer/src/value.rs index 5316998e0..358c915ad 100644 --- a/gstreamer/src/value.rs +++ b/gstreamer/src/value.rs @@ -840,6 +840,13 @@ pub trait GstValueExt: Sized { s: T, type_: glib::Type, ) -> Result; + #[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; } 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 { + 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)]