Skip to main content

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::{Plugin, PluginFeature, Registry, ffi};
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            unsafe {
40                let feature = from_glib_borrow(feature);
41                let callback = user_data as *mut P;
42                let res = (*callback)(&feature);
43                res.into_glib()
44            }
45        }
46        let filter = Some(filter_func::<P> as _);
47        let super_callback0: &mut P = &mut filter_data;
48        unsafe {
49            FromGlibPtrContainer::from_glib_full(ffi::gst_registry_feature_filter(
50                self.to_glib_none().0,
51                filter,
52                first.into_glib(),
53                super_callback0 as *mut _ as *mut _,
54            ))
55        }
56    }
57
58    /// Retrieves a `GList` of [`PluginFeature`][crate::PluginFeature] of `type_`.
59    /// ## `type_`
60    /// a `GType`.
61    ///
62    /// # Returns
63    ///
64    /// a `GList` of
65    ///  [`PluginFeature`][crate::PluginFeature] of `type_`. Use `gst_plugin_feature_list_free()` after use
66    ///
67    /// MT safe.
68    #[doc(alias = "gst_registry_get_feature_list")]
69    #[doc(alias = "get_feature_list")]
70    pub fn features(&self, type_: glib::types::Type) -> glib::List<PluginFeature> {
71        unsafe {
72            FromGlibPtrContainer::from_glib_full(ffi::gst_registry_get_feature_list(
73                self.to_glib_none().0,
74                type_.into_glib(),
75            ))
76        }
77    }
78
79    /// Retrieves a `GList` of features of the plugin with name `name`.
80    /// ## `name`
81    /// a plugin name.
82    ///
83    /// # Returns
84    ///
85    /// a `GList` of
86    ///  [`PluginFeature`][crate::PluginFeature]. Use `gst_plugin_feature_list_free()` after usage.
87    #[doc(alias = "gst_registry_get_feature_list_by_plugin")]
88    #[doc(alias = "get_feature_list_by_plugin")]
89    pub fn features_by_plugin(&self, name: &str) -> glib::List<PluginFeature> {
90        unsafe {
91            FromGlibPtrContainer::from_glib_full(ffi::gst_registry_get_feature_list_by_plugin(
92                self.to_glib_none().0,
93                name.to_glib_none().0,
94            ))
95        }
96    }
97
98    /// Get a copy of all plugins registered in the given registry. The refcount
99    /// of each element in the list in incremented.
100    ///
101    /// # Returns
102    ///
103    /// a `GList` of [`Plugin`][crate::Plugin].
104    ///  Use `gst_plugin_list_free()` after usage.
105    ///
106    /// MT safe.
107    #[doc(alias = "gst_registry_get_plugin_list")]
108    #[doc(alias = "get_plugin_list")]
109    pub fn plugins(&self) -> glib::List<Plugin> {
110        unsafe {
111            FromGlibPtrContainer::from_glib_full(ffi::gst_registry_get_plugin_list(
112                self.to_glib_none().0,
113            ))
114        }
115    }
116
117    /// Runs a filter against all plugins in the registry and returns a `GList` with
118    /// the results. If the first flag is set, only the first match is
119    /// returned (as a list with a single object).
120    /// Every plugin is reffed; use `gst_plugin_list_free()` after use, which
121    /// will unref again.
122    /// ## `filter`
123    /// the filter to use
124    /// ## `first`
125    /// only return first match
126    ///
127    /// # Returns
128    ///
129    /// a `GList` of [`Plugin`][crate::Plugin].
130    ///  Use `gst_plugin_list_free()` after usage.
131    ///
132    /// MT safe.
133    #[doc(alias = "gst_registry_plugin_filter")]
134    pub fn plugins_filtered<P: FnMut(&Plugin) -> bool>(
135        &self,
136        filter: P,
137        first: bool,
138    ) -> glib::List<Plugin> {
139        let mut filter_data: P = filter;
140        unsafe extern "C" fn filter_func<P: FnMut(&Plugin) -> bool>(
141            plugin: *mut ffi::GstPlugin,
142            user_data: glib::ffi::gpointer,
143        ) -> glib::ffi::gboolean {
144            unsafe {
145                let plugin = from_glib_borrow(plugin);
146                let callback = user_data as *mut P;
147                let res = (*callback)(&plugin);
148                res.into_glib()
149            }
150        }
151        let filter = Some(filter_func::<P> as _);
152        let super_callback0: &mut P = &mut filter_data;
153        unsafe {
154            FromGlibPtrContainer::from_glib_full(ffi::gst_registry_plugin_filter(
155                self.to_glib_none().0,
156                filter,
157                first.into_glib(),
158                super_callback0 as *mut _ as *mut _,
159            ))
160        }
161    }
162}