gstreamer/
registry.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5use crate::{ffi, Plugin, PluginFeature, Registry};
6
7impl Registry {
8    #[doc(alias = "gst_registry_update")]
9    pub fn update() -> Result<(), glib::BoolError> {
10        crate::auto::functions::update_registry()
11    }
12
13    /// Runs a filter against all features of the plugins in the registry
14    /// and returns a GList with the results.
15    /// If the first flag is set, only the first match is
16    /// returned (as a list with a single object).
17    /// ## `filter`
18    /// the filter to use
19    /// ## `first`
20    /// only return first match
21    ///
22    /// # Returns
23    ///
24    /// a `GList` of
25    ///  [`PluginFeature`][crate::PluginFeature]. Use `gst_plugin_feature_list_free()` after usage.
26    ///
27    /// MT safe.
28    #[doc(alias = "gst_registry_feature_filter")]
29    pub fn features_filtered<P: FnMut(&PluginFeature) -> bool>(
30        &self,
31        filter: P,
32        first: bool,
33    ) -> glib::List<PluginFeature> {
34        let mut filter_data: P = filter;
35        unsafe extern "C" fn filter_func<P: FnMut(&PluginFeature) -> bool>(
36            feature: *mut ffi::GstPluginFeature,
37            user_data: glib::ffi::gpointer,
38        ) -> glib::ffi::gboolean {
39            let feature = from_glib_borrow(feature);
40            let callback = user_data as *mut P;
41            let res = (*callback)(&feature);
42            res.into_glib()
43        }
44        let filter = Some(filter_func::<P> as _);
45        let super_callback0: &mut P = &mut filter_data;
46        unsafe {
47            FromGlibPtrContainer::from_glib_full(ffi::gst_registry_feature_filter(
48                self.to_glib_none().0,
49                filter,
50                first.into_glib(),
51                super_callback0 as *mut _ as *mut _,
52            ))
53        }
54    }
55
56    /// Retrieves a `GList` of [`PluginFeature`][crate::PluginFeature] of `type_`.
57    /// ## `type_`
58    /// a `GType`.
59    ///
60    /// # Returns
61    ///
62    /// a `GList` of
63    ///  [`PluginFeature`][crate::PluginFeature] of `type_`. Use `gst_plugin_feature_list_free()` after use
64    ///
65    /// MT safe.
66    #[doc(alias = "gst_registry_get_feature_list")]
67    #[doc(alias = "get_feature_list")]
68    pub fn features(&self, type_: glib::types::Type) -> glib::List<PluginFeature> {
69        unsafe {
70            FromGlibPtrContainer::from_glib_full(ffi::gst_registry_get_feature_list(
71                self.to_glib_none().0,
72                type_.into_glib(),
73            ))
74        }
75    }
76
77    /// Retrieves a `GList` of features of the plugin with name `name`.
78    /// ## `name`
79    /// a plugin name.
80    ///
81    /// # Returns
82    ///
83    /// a `GList` of
84    ///  [`PluginFeature`][crate::PluginFeature]. Use `gst_plugin_feature_list_free()` after usage.
85    #[doc(alias = "gst_registry_get_feature_list_by_plugin")]
86    #[doc(alias = "get_feature_list_by_plugin")]
87    pub fn features_by_plugin(&self, name: &str) -> glib::List<PluginFeature> {
88        unsafe {
89            FromGlibPtrContainer::from_glib_full(ffi::gst_registry_get_feature_list_by_plugin(
90                self.to_glib_none().0,
91                name.to_glib_none().0,
92            ))
93        }
94    }
95
96    /// Get a copy of all plugins registered in the given registry. The refcount
97    /// of each element in the list in incremented.
98    ///
99    /// # Returns
100    ///
101    /// a `GList` of [`Plugin`][crate::Plugin].
102    ///  Use `gst_plugin_list_free()` after usage.
103    ///
104    /// MT safe.
105    #[doc(alias = "gst_registry_get_plugin_list")]
106    #[doc(alias = "get_plugin_list")]
107    pub fn plugins(&self) -> glib::List<Plugin> {
108        unsafe {
109            FromGlibPtrContainer::from_glib_full(ffi::gst_registry_get_plugin_list(
110                self.to_glib_none().0,
111            ))
112        }
113    }
114
115    /// Runs a filter against all plugins in the registry and returns a `GList` with
116    /// the results. If the first flag is set, only the first match is
117    /// returned (as a list with a single object).
118    /// Every plugin is reffed; use `gst_plugin_list_free()` after use, which
119    /// will unref again.
120    /// ## `filter`
121    /// the filter to use
122    /// ## `first`
123    /// only return first match
124    ///
125    /// # Returns
126    ///
127    /// a `GList` of [`Plugin`][crate::Plugin].
128    ///  Use `gst_plugin_list_free()` after usage.
129    ///
130    /// MT safe.
131    #[doc(alias = "gst_registry_plugin_filter")]
132    pub fn plugins_filtered<P: FnMut(&Plugin) -> bool>(
133        &self,
134        filter: P,
135        first: bool,
136    ) -> glib::List<Plugin> {
137        let mut filter_data: P = filter;
138        unsafe extern "C" fn filter_func<P: FnMut(&Plugin) -> bool>(
139            plugin: *mut ffi::GstPlugin,
140            user_data: glib::ffi::gpointer,
141        ) -> glib::ffi::gboolean {
142            let plugin = from_glib_borrow(plugin);
143            let callback = user_data as *mut P;
144            let res = (*callback)(&plugin);
145            res.into_glib()
146        }
147        let filter = Some(filter_func::<P> as _);
148        let super_callback0: &mut P = &mut filter_data;
149        unsafe {
150            FromGlibPtrContainer::from_glib_full(ffi::gst_registry_plugin_filter(
151                self.to_glib_none().0,
152                filter,
153                first.into_glib(),
154                super_callback0 as *mut _ as *mut _,
155            ))
156        }
157    }
158}