element: element property special convert for enum and flags

In element_property, add special case enum and flags
property to use a better value such as nick or the
proper u32 flags
This commit is contained in:
Stéphane Cerveau 2024-01-03 13:06:30 +01:00
parent bed8d6a58e
commit a6f03db8f6

View file

@ -156,13 +156,24 @@ impl ElementInfo {
} }
pub fn element_property(element: &gst::Element, property_name: &str) -> anyhow::Result<String> { pub fn element_property(element: &gst::Element, property_name: &str) -> anyhow::Result<String> {
let value = element let value = element.property_value(property_name);
.property_value(property_name) if value.type_().is_a(glib::Type::ENUM) {
.transform::<String>() let value = value.get::<&glib::EnumValue>().unwrap().nick().to_string();
.expect("Unable to transform to string") Ok(value)
.get::<String>() } else if value.type_().is_a(glib::Type::FLAGS) {
.unwrap_or_default(); let value = value.get::<Vec<&glib::FlagsValue>>().unwrap();
Ok(value) let flags = value.iter().copied().fold(0, |acc, val| acc | val.value());
Ok(flags.to_string())
} else {
let value = value
.transform::<String>()
.expect("Unable to transform to string")
.get::<String>()
.unwrap_or_default()
.to_lowercase();
Ok(value)
}
} }
pub fn element_property_by_feature_name( pub fn element_property_by_feature_name(
@ -181,7 +192,7 @@ impl ElementInfo {
element: &gst::Element, element: &gst::Element,
) -> anyhow::Result<HashMap<String, glib::ParamSpec>> { ) -> anyhow::Result<HashMap<String, glib::ParamSpec>> {
let mut properties_list = HashMap::new(); let mut properties_list = HashMap::new();
let params = element.class().list_properties(); let params = element.list_properties();
for param in params.iter() { for param in params.iter() {
GPS_INFO!("Property_name {}", param.name()); GPS_INFO!("Property_name {}", param.name());