From ebe3d72bae57db0e8dd401b444abc5718fbcb3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Thu, 10 Oct 2024 14:20:36 -0400 Subject: [PATCH] gst-pbutils: add IdStr builder setters Part-of: --- gstreamer-pbutils/src/element_properties.rs | 87 ++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/gstreamer-pbutils/src/element_properties.rs b/gstreamer-pbutils/src/element_properties.rs index b52554752..3d57e2873 100644 --- a/gstreamer-pbutils/src/element_properties.rs +++ b/gstreamer-pbutils/src/element_properties.rs @@ -183,6 +183,24 @@ impl ElementPropertiesGeneralBuilder { self } + pub fn field_value_with_static( + mut self, + property_name: impl AsRef + 'static, + value: glib::SendValue, + ) -> Self { + self.structure.set_value_with_static(property_name, value); + self + } + + pub fn field_value_with_id( + mut self, + property_name: impl AsRef, + value: glib::SendValue, + ) -> Self { + self.structure.set_value_with_id(property_name, value); + self + } + pub fn field_value_if_some(self, property_name: &str, value: Option) -> Self { if let Some(value) = value { self.field_value(property_name, value) @@ -191,6 +209,30 @@ impl ElementPropertiesGeneralBuilder { } } + pub fn field_value_with_static_if_some( + self, + property_name: impl AsRef + 'static, + value: Option, + ) -> Self { + if let Some(value) = value { + self.field_value_with_static(property_name, value) + } else { + self + } + } + + pub fn field_value_with_id_if_some( + self, + property_name: impl AsRef, + value: Option, + ) -> Self { + if let Some(value) = value { + self.field_value_with_id(property_name, value) + } else { + self + } + } + pub fn build(self) -> ElementProperties { ElementProperties(self.structure) } @@ -347,6 +389,24 @@ impl ElementPropertiesMapItemBuilder { self } + pub fn field_value_with_static( + mut self, + property_name: impl AsRef + 'static, + value: glib::SendValue, + ) -> Self { + self.structure.set_value_with_static(property_name, value); + self + } + + pub fn field_value_with_id( + mut self, + property_name: impl AsRef, + value: glib::SendValue, + ) -> Self { + self.structure.set_value_with_id(property_name, value); + self + } + pub fn field_value_if_some(self, property_name: &str, value: Option) -> Self { if let Some(value) = value { self.field_value(property_name, value) @@ -355,6 +415,30 @@ impl ElementPropertiesMapItemBuilder { } } + pub fn field_value_with_static_if_some( + self, + property_name: impl AsRef + 'static, + value: Option, + ) -> Self { + if let Some(value) = value { + self.field_value_with_static(property_name, value) + } else { + self + } + } + + pub fn field_value_with_id_if_some( + self, + property_name: impl AsRef, + value: Option, + ) -> Self { + if let Some(value) = value { + self.field_value_with_id(property_name, value) + } else { + self + } + } + pub fn build(self) -> ElementPropertiesMapItem { ElementPropertiesMapItem(self.structure) } @@ -363,6 +447,7 @@ impl ElementPropertiesMapItemBuilder { #[cfg(test)] mod test { use super::*; + use gst::idstr; #[test] fn element_properties_getters() { @@ -377,7 +462,7 @@ mod test { assert_eq!(elem_props_general.map(), None); let elem_factory_props_map = ElementPropertiesMapItem::builder("vp8enc") - .field("cq-level", 13) + .field_with_id(idstr!("cq-level"), 13) .field("resize-allowed", false) .build(); let elem_props_map = ElementProperties::builder_map()