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.
This commit is contained in:
Stéphane Cerveau 2022-02-23 12:50:31 +01:00 committed by Stéphane Cerveau
parent 46889d86d0
commit c0220c4bdb
2 changed files with 33 additions and 15 deletions

View file

@ -132,13 +132,8 @@ impl ElementInfo {
element_type
}
pub fn element_property(element_name: &str, property_name: &str) -> anyhow::Result<String> {
let feature = ElementInfo::element_feature(element_name).expect("Unable to get feature");
let factory = feature
.downcast::<gst::ElementFactory>()
.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<String> {
let value = element
.property_value(property_name)
.transform::<String>()
@ -148,16 +143,22 @@ impl ElementInfo {
Ok(value)
}
pub fn element_properties(
pub fn element_property_by_feature_name(
element_name: &str,
) -> anyhow::Result<HashMap<String, glib::ParamSpec>> {
let mut properties_list = HashMap::new();
property_name: &str,
) -> anyhow::Result<String> {
let feature = ElementInfo::element_feature(element_name).expect("Unable to get feature");
let factory = feature
.downcast::<gst::ElementFactory>()
.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<HashMap<String, glib::ParamSpec>> {
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<HashMap<String, glib::ParamSpec>> {
let feature = ElementInfo::element_feature(element_name).expect("Unable to get feature");
let factory = feature
.downcast::<gst::ElementFactory>()
.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");

View file

@ -52,7 +52,9 @@ pub fn property_to_widget<F: Fn(String, String) + 'static>(
} 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::<bool>().unwrap_or(false));
}
} else if let Some(value) = value_as_str(param.default_value()) {
@ -81,7 +83,9 @@ pub fn property_to_widget<F: Fn(String, String) + 'static>(
} 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<F: Fn(String, String) + 'static>(
} 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::<u32>().unwrap_or(0) + 1));
}
}
@ -171,8 +177,7 @@ pub fn property_to_widget<F: Fn(String, String) + 'static>(
pub fn display_plugin_properties(app: &GPSApp, element_name: &str, node_id: u32) {
let update_properties: Rc<RefCell<HashMap<String, String>>> =
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);