From c0220c4bdb9aa103e9f07030f3d774225cd150f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Wed, 23 Feb 2022 12:50:31 +0100 Subject: [PATCH] element: change api to allow the use of direct gst::element Fetch the property(s) of a given GstElement or check the property from a feature name. --- src/gps/element.rs | 33 +++++++++++++++++++++++---------- src/ui/properties.rs | 15 ++++++++++----- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/gps/element.rs b/src/gps/element.rs index 29b86c2..7247fe4 100644 --- a/src/gps/element.rs +++ b/src/gps/element.rs @@ -132,13 +132,8 @@ impl ElementInfo { element_type } - pub fn element_property(element_name: &str, property_name: &str) -> anyhow::Result { - let feature = ElementInfo::element_feature(element_name).expect("Unable to get feature"); - let factory = feature - .downcast::() - .expect("Unable to get the factory from the feature"); - let element = factory.create().build()?; + pub fn element_property(element: &gst::Element, property_name: &str) -> anyhow::Result { let value = element .property_value(property_name) .transform::() @@ -148,16 +143,22 @@ impl ElementInfo { Ok(value) } - pub fn element_properties( + pub fn element_property_by_feature_name( element_name: &str, - ) -> anyhow::Result> { - let mut properties_list = HashMap::new(); + property_name: &str, + ) -> anyhow::Result { let feature = ElementInfo::element_feature(element_name).expect("Unable to get feature"); - let factory = feature .downcast::() .expect("Unable to get the factory from the feature"); let element = factory.create().build()?; + ElementInfo::element_property(&element, property_name) + } + + pub fn element_properties( + element: &gst::Element, + ) -> anyhow::Result> { + let mut properties_list = HashMap::new(); let params = element.class().list_properties(); for param in params.iter() { @@ -184,6 +185,18 @@ impl ElementInfo { Ok(properties_list) } + pub fn element_properties_by_feature_name( + element_name: &str, + ) -> anyhow::Result> { + let feature = ElementInfo::element_feature(element_name).expect("Unable to get feature"); + + let factory = feature + .downcast::() + .expect("Unable to get the factory from the feature"); + let element = factory.create().build()?; + ElementInfo::element_properties(&element) + } + pub fn element_is_uri_src_handler(element_name: &str) -> bool { let feature = ElementInfo::element_feature(element_name).expect("Unable to get feature"); diff --git a/src/ui/properties.rs b/src/ui/properties.rs index feaa490..6a47dcc 100644 --- a/src/ui/properties.rs +++ b/src/ui/properties.rs @@ -52,7 +52,9 @@ pub fn property_to_widget( } else if (param.flags() & glib::ParamFlags::READABLE) == glib::ParamFlags::READABLE || (param.flags() & glib::ParamFlags::READWRITE) == glib::ParamFlags::READWRITE { - if let Ok(value) = GPS::ElementInfo::element_property(element_name, param.name()) { + if let Ok(value) = + GPS::ElementInfo::element_property_by_feature_name(element_name, param.name()) + { check_button.set_active(value.parse::().unwrap_or(false)); } } else if let Some(value) = value_as_str(param.default_value()) { @@ -81,7 +83,9 @@ pub fn property_to_widget( } else if (param.flags() & glib::ParamFlags::READABLE) == glib::ParamFlags::READABLE || (param.flags() & glib::ParamFlags::READWRITE) == glib::ParamFlags::READWRITE { - if let Ok(value) = GPS::ElementInfo::element_property(element_name, param.name()) { + if let Ok(value) = + GPS::ElementInfo::element_property_by_feature_name(element_name, param.name()) + { entry.set_text(&value); } } else if let Some(value) = value_as_str(param.default_value()) { @@ -140,7 +144,9 @@ pub fn property_to_widget( } else if (param.flags() & glib::ParamFlags::READABLE) == glib::ParamFlags::READABLE || (param.flags() & glib::ParamFlags::READWRITE) == glib::ParamFlags::READWRITE { - if let Ok(value) = GPS::ElementInfo::element_property(element_name, param.name()) { + if let Ok(value) = + GPS::ElementInfo::element_property_by_feature_name(element_name, param.name()) + { combo.set_active(Some(value.parse::().unwrap_or(0) + 1)); } } @@ -171,8 +177,7 @@ pub fn property_to_widget( pub fn display_plugin_properties(app: &GPSApp, element_name: &str, node_id: u32) { let update_properties: Rc>> = Rc::new(RefCell::new(HashMap::new())); - let properties = GPS::ElementInfo::element_properties(element_name) - .expect("Should get the list of the properties properly"); + let properties = GPS::ElementInfo::element_properties_by_feature_name(element_name).unwrap(); let grid = gtk::Grid::new(); grid.set_column_spacing(4);