Skip to main content

gstreamer/
plugin_feature.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::{
4    prelude::*,
5    translate::{FromGlibPtrFull, IntoGlib, ToGlibPtr, from_glib},
6};
7
8use crate::{PluginFeature, Rank, ffi};
9
10pub trait PluginFeatureExtManual: IsA<PluginFeature> + 'static {
11    /// Gets the rank of a plugin feature.
12    ///
13    /// # Returns
14    ///
15    /// The rank of the feature
16    #[doc(alias = "get_rank")]
17    #[doc(alias = "gst_plugin_feature_get_rank")]
18    fn rank(&self) -> Rank {
19        unsafe {
20            let rank = ffi::gst_plugin_feature_get_rank(self.as_ref().to_glib_none().0);
21            from_glib(rank as i32)
22        }
23    }
24
25    /// Specifies a rank for a plugin feature, so that autoplugging uses
26    /// the most appropriate feature.
27    /// ## `rank`
28    /// rank value - higher number means more priority rank
29    #[doc(alias = "gst_plugin_feature_set_rank")]
30    fn set_rank(&self, rank: Rank) {
31        unsafe {
32            ffi::gst_plugin_feature_set_rank(
33                self.as_ref().to_glib_none().0,
34                rank.into_glib() as u32,
35            );
36        }
37    }
38
39    ///
40    /// GstPluginFeature *loaded_feature;
41    ///
42    /// loaded_feature = gst_plugin_feature_load (feature);
43    /// // presumably, we're no longer interested in the potentially-unloaded feature
44    /// gst_object_unref (feature);
45    /// feature = loaded_feature;
46    /// ]|
47    ///
48    /// # Returns
49    ///
50    /// a reference to the loaded
51    /// feature, or [`None`] on error
52    #[doc(alias = "gst_plugin_feature_load")]
53    fn load(&self) -> Result<Self, glib::BoolError> {
54        unsafe {
55            let loaded = Option::<PluginFeature>::from_glib_full(ffi::gst_plugin_feature_load(
56                self.as_ref().to_glib_none().0,
57            ))
58            .ok_or_else(|| glib::bool_error!("Failed to load plugin feature"))?;
59            Ok(loaded.unsafe_cast())
60        }
61    }
62}
63
64impl<O: IsA<PluginFeature>> PluginFeatureExtManual for O {}
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn test_load() {
72        crate::init().unwrap();
73
74        let factory = crate::ElementFactory::find("identity").unwrap();
75        let loaded = factory.load().unwrap();
76        assert_eq!(factory.type_(), loaded.type_());
77        let _element = loaded.create().build().unwrap();
78    }
79}