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    /// Gets the list of alternative suffixes defined for a property in a
33    /// preset. These are the bracket-enclosed parts of keys like
34    /// "bitrate[1920x1080]" or "bitrate[3840x2160`48`]".
35    /// ## `name`
36    /// preset name
37    /// ## `prop`
38    /// base property name (e.g. "bitrate")
39    ///
40    /// # Returns
41    ///
42    ///
43    ///  a [`None`]-terminated array of alternative names (e.g.
44    ///  ["1920x1080", "3840x2160`48`", ...]), or [`None`] if no
45    ///  alternatives exist. Free with `g_strfreev()`.
46    #[cfg(feature = "v1_30")]
47    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
48    #[doc(alias = "gst_preset_get_property_alternatives")]
49    #[doc(alias = "get_property_alternatives")]
50    fn property_alternatives(&self, name: &str, prop: &str) -> Result<glib::StrV, glib::BoolError> {
51        use glib::translate::*;
52        unsafe {
53            let arr = crate::ffi::gst_preset_get_property_alternatives(
54                self.as_ref().to_glib_none().0,
55                name.to_glib_none().0,
56                prop.to_glib_none().0,
57            );
58
59            if arr.is_null() {
60                Err(glib::bool_error!(
61                    "Failed get alternatives to property {prop} for the preset {name}"
62                ))
63            } else {
64                Ok(FromGlibPtrContainer::from_glib_full(arr))
65            }
66        }
67    }
68}
69
70impl<O: glib::prelude::IsA<Preset>> PresetExtManual for O {}