gstreamer: Make child proxy property API more consistent with the object property API

And especially check various conditions for the property and the value.
Also add `ChildProxy::lookup()`.
This commit is contained in:
Sebastian Dröge 2021-11-19 10:45:04 +02:00
parent 7c1ed9ff4d
commit 63f6d6a7d3
3 changed files with 87 additions and 43 deletions

View file

@ -248,6 +248,9 @@ manual_traits = ["ChildProxyExtManual"]
name = "set_property"
rename = "set_child_property"
manual = true
[[object.function]]
name = "lookup"
manual = true
[[object]]
name = "Gst.ClockTime"

View file

@ -53,9 +53,6 @@ pub trait ChildProxyExt: 'static {
//#[doc(alias = "get_valist")]
//fn valist(&self, first_property_name: &str, var_args: /*Unknown conversion*//*Unimplemented*/Unsupported);
//#[doc(alias = "gst_child_proxy_lookup")]
//fn lookup(&self, name: &str, pspec: /*Ignored*/glib::ParamSpec) -> Option<glib::Object>;
//#[doc(alias = "gst_child_proxy_set")]
//fn set(&self, first_property_name: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);
@ -126,10 +123,6 @@ impl<O: IsA<ChildProxy>> ChildProxyExt for O {
// unsafe { TODO: call ffi:gst_child_proxy_get_valist() }
//}
//fn lookup(&self, name: &str, pspec: /*Ignored*/glib::ParamSpec) -> Option<glib::Object> {
// unsafe { TODO: call ffi:gst_child_proxy_lookup() }
//}
//fn set(&self, first_property_name: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
// unsafe { TODO: call ffi:gst_child_proxy_set() }
//}

View file

@ -6,62 +6,110 @@ use glib::translate::*;
use std::ptr;
pub trait ChildProxyExtManual: 'static {
#[doc(alias = "gst_child_proxy_lookup")]
fn lookup(&self, name: &str) -> Result<(glib::Object, glib::ParamSpec), glib::BoolError>;
#[doc(alias = "get_child_property")]
fn child_property(&self, name: &str) -> Option<glib::Value>;
fn set_child_property<V: glib::ToValue>(
#[doc(alias = "gst_child_proxy_get")]
fn child_property<V: for<'b> glib::value::FromValue<'b> + 'static>(&self, name: &str) -> V;
#[doc(alias = "get_child_property")]
#[doc(alias = "gst_child_proxy_get")]
fn child_property_value(&self, name: &str) -> glib::Value;
#[doc(alias = "get_child_property")]
#[doc(alias = "gst_child_proxy_get")]
fn try_child_property<V: for<'b> glib::value::FromValue<'b> + 'static>(
&self,
name: &str,
) -> Result<V, glib::BoolError>;
#[doc(alias = "get_child_property")]
#[doc(alias = "gst_child_proxy_get")]
fn try_child_property_value(&self, name: &str) -> Result<glib::Value, glib::BoolError>;
#[doc(alias = "gst_child_proxy_set")]
fn set_child_property<V: glib::ToValue>(&self, name: &str, value: V);
#[doc(alias = "gst_child_proxy_set_property")]
fn set_child_property_from_value(&self, name: &str, value: &glib::Value);
#[doc(alias = "gst_child_proxy_set")]
fn try_set_child_property<V: glib::ToValue>(
&self,
name: &str,
value: V,
) -> Result<(), glib::BoolError>;
#[doc(alias = "gst_child_proxy_set_property")]
fn try_set_child_property_from_value(
&self,
name: &str,
value: &glib::Value,
) -> Result<(), glib::BoolError>;
}
impl<O: IsA<ChildProxy>> ChildProxyExtManual for O {
fn child_property(&self, name: &str) -> Option<glib::Value> {
fn lookup(&self, name: &str) -> Result<(glib::Object, glib::ParamSpec), glib::BoolError> {
unsafe {
let found: bool = from_glib(ffi::gst_child_proxy_lookup(
let mut target = ptr::null_mut();
let mut pspec = ptr::null_mut();
let ret = from_glib(ffi::gst_child_proxy_lookup(
self.as_ref().to_glib_none().0,
name.to_glib_none().0,
ptr::null_mut(),
ptr::null_mut(),
&mut target,
&mut pspec,
));
if !found {
return None;
if ret {
Ok((from_glib_full(target), from_glib_none(pspec)))
} else {
Err(glib::bool_error!("Failed to find child property"))
}
let mut value = glib::Value::uninitialized();
ffi::gst_child_proxy_get_property(
self.as_ref().to_glib_none().0,
name.to_glib_none().0,
value.to_glib_none_mut().0,
);
Some(value)
}
}
fn set_child_property<V: glib::ToValue>(
fn child_property<V: for<'b> glib::value::FromValue<'b> + 'static>(&self, name: &str) -> V {
let (child, pspec) = self.lookup(name).unwrap();
child.property(pspec.name())
}
fn child_property_value(&self, name: &str) -> glib::Value {
let (child, pspec) = self.lookup(name).unwrap();
child.property_value(pspec.name())
}
fn try_child_property<V: for<'b> glib::value::FromValue<'b> + 'static>(
&self,
name: &str,
) -> Result<V, glib::BoolError> {
let (child, pspec) = self.lookup(name)?;
child.try_property(pspec.name())
}
fn try_child_property_value(&self, name: &str) -> Result<glib::Value, glib::BoolError> {
let (child, pspec) = self.lookup(name)?;
child.try_property_value(pspec.name())
}
fn set_child_property<V: glib::ToValue>(&self, name: &str, value: V) {
let (child, pspec) = self.lookup(name).unwrap();
child.set_property(pspec.name(), value)
}
fn set_child_property_from_value(&self, name: &str, value: &glib::Value) {
let (child, pspec) = self.lookup(name).unwrap();
child.set_property_from_value(pspec.name(), value)
}
fn try_set_child_property<V: glib::ToValue>(
&self,
name: &str,
value: V,
) -> Result<(), glib::BoolError> {
unsafe {
let found: bool = from_glib(ffi::gst_child_proxy_lookup(
self.as_ref().to_glib_none().0,
name.to_glib_none().0,
ptr::null_mut(),
ptr::null_mut(),
));
if !found {
return Err(glib::bool_error!("Child property not found"));
}
let (child, pspec) = self.lookup(name)?;
child.try_set_property(pspec.name(), value)
}
let value = value.to_value();
ffi::gst_child_proxy_set_property(
self.as_ref().to_glib_none().0,
name.to_glib_none().0,
value.to_glib_none().0,
);
Ok(())
}
fn try_set_child_property_from_value(
&self,
name: &str,
value: &glib::Value,
) -> Result<(), glib::BoolError> {
let (child, pspec) = self.lookup(name)?;
child.try_set_property_from_value(pspec.name(), value)
}
}