2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
|
|
|
|
2022-04-03 07:46:02 +00:00
|
|
|
use crate::value::GstValueExt;
|
2021-04-26 12:15:53 +00:00
|
|
|
use glib::prelude::*;
|
2017-07-20 08:39:44 +00:00
|
|
|
|
2018-12-08 09:22:42 +00:00
|
|
|
pub trait GObjectExtManualGst: 'static {
|
2021-08-17 05:47:42 +00:00
|
|
|
#[doc(alias = "gst_util_set_object_arg")]
|
2021-11-08 10:30:06 +00:00
|
|
|
fn try_set_property_from_str(&self, name: &str, value: &str) -> Result<(), glib::BoolError>;
|
|
|
|
|
|
|
|
#[doc(alias = "gst_util_set_object_arg")]
|
|
|
|
fn set_property_from_str(&self, name: &str, value: &str);
|
2017-07-20 08:39:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<O: IsA<glib::Object>> GObjectExtManualGst for O {
|
2021-11-08 10:30:06 +00:00
|
|
|
fn try_set_property_from_str(&self, name: &str, value: &str) -> Result<(), glib::BoolError> {
|
2021-08-17 05:47:42 +00:00
|
|
|
let pspec = self.find_property(name).ok_or_else(|| {
|
|
|
|
glib::bool_error!("property '{}' of type '{}' not found", name, self.type_())
|
|
|
|
})?;
|
|
|
|
|
|
|
|
let value = {
|
|
|
|
if pspec.value_type() == crate::Structure::static_type() && value == "NULL" {
|
|
|
|
None::<crate::Structure>.to_value()
|
|
|
|
} else {
|
|
|
|
#[cfg(feature = "v1_20")]
|
|
|
|
{
|
|
|
|
glib::Value::deserialize_with_pspec(value, &pspec)?
|
|
|
|
}
|
|
|
|
#[cfg(not(feature = "v1_20"))]
|
|
|
|
{
|
|
|
|
glib::Value::deserialize(value, pspec.value_type())?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-11-06 17:09:27 +00:00
|
|
|
self.try_set_property_from_value(name, &value)
|
2021-08-17 05:47:42 +00:00
|
|
|
}
|
2021-11-08 10:30:06 +00:00
|
|
|
|
|
|
|
fn set_property_from_str(&self, name: &str, value: &str) {
|
|
|
|
self.try_set_property_from_str(name, value).unwrap()
|
|
|
|
}
|
2021-08-17 05:47:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_set_property_from_str() {
|
|
|
|
crate::init().unwrap();
|
|
|
|
|
|
|
|
let fakesink = crate::ElementFactory::make("fakesink", None).unwrap();
|
2021-11-08 10:30:06 +00:00
|
|
|
fakesink.set_property_from_str("state-error", "ready-to-paused");
|
2021-11-06 17:09:27 +00:00
|
|
|
let v = fakesink.property_value("state-error");
|
2021-11-13 09:03:52 +00:00
|
|
|
let (_klass, e) = glib::EnumValue::from_value(&v).unwrap();
|
2021-08-17 05:47:42 +00:00
|
|
|
assert_eq!(e.nick(), "ready-to-paused");
|
2017-07-20 08:39:44 +00:00
|
|
|
}
|
|
|
|
}
|