Skip to main content

gstreamer/
preset.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::prelude::*;
4
5use crate::Preset;
6
7pub trait PresetExtManual: IsA<Preset> + 'static {
8    #[cfg(feature = "v1_30")]
9    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
10    #[doc(alias = "gst_preset_get_property")]
11    #[doc(alias = "get_property")]
12    fn property(&self, name: &str, prop: &str) -> Result<glib::Value, glib::BoolError> {
13        use glib::translate::*;
14        unsafe {
15            let mut value = glib::Value::uninitialized();
16            let ret = from_glib(crate::ffi::gst_preset_get_property(
17                self.as_ref().to_glib_none().0,
18                name.to_glib_none().0,
19                prop.to_glib_none().0,
20                value.to_glib_none_mut().0,
21            ));
22            if ret {
23                Ok(value)
24            } else {
25                Err(glib::bool_error!(
26                    "Failed to get {prop} for the preset {name}"
27                ))
28            }
29        }
30    }
31
32    #[cfg(feature = "v1_30")]
33    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
34    #[doc(alias = "gst_preset_get_property_alternatives")]
35    #[doc(alias = "get_property_alternatives")]
36    fn property_alternatives(&self, name: &str, prop: &str) -> Result<glib::StrV, glib::BoolError> {
37        use glib::translate::*;
38        unsafe {
39            let arr = crate::ffi::gst_preset_get_property_alternatives(
40                self.as_ref().to_glib_none().0,
41                name.to_glib_none().0,
42                prop.to_glib_none().0,
43            );
44
45            if arr.is_null() {
46                Err(glib::bool_error!(
47                    "Failed get alternatives to property {prop} for the preset {name}"
48                ))
49            } else {
50                Ok(FromGlibPtrContainer::from_glib_full(arr))
51            }
52        }
53    }
54}
55
56impl<O: glib::prelude::IsA<Preset>> PresetExtManual for O {}