gstreamer/auto/
registry.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{ffi, Object, Plugin, PluginFeature};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    /// One registry holds the metadata of a set of plugins.
17    ///
18    /// <emphasis role="bold">Design:`</emphasis>`
19    ///
20    /// The [`Registry`][crate::Registry] object is a list of plugins and some functions for dealing
21    /// with them. Each [`Plugin`][crate::Plugin] is matched 1-1 with a file on disk, and may or may
22    /// not be loaded at a given time.
23    ///
24    /// The primary source, at all times, of plugin information is each plugin file
25    /// itself. Thus, if an application wants information about a particular plugin,
26    /// or wants to search for a feature that satisfies given criteria, the primary
27    /// means of doing so is to load every plugin and look at the resulting
28    /// information that is gathered in the default registry. Clearly, this is a time
29    /// consuming process, so we cache information in the registry file. The format
30    /// and location of the cache file is internal to gstreamer.
31    ///
32    /// On startup, plugins are searched for in the plugin search path. The following
33    /// locations are checked in this order:
34    ///
35    /// * location from --gst-plugin-path commandline option.
36    /// * the GST_PLUGIN_PATH environment variable.
37    /// * the GST_PLUGIN_SYSTEM_PATH environment variable.
38    /// * default locations (if GST_PLUGIN_SYSTEM_PATH is not set).
39    ///  Those default locations are:
40    ///  `$XDG_DATA_HOME/gstreamer-$GST_API_VERSION/plugins/`
41    ///  and `$prefix/libs/gstreamer-$GST_API_VERSION/`.
42    ///  [$XDG_DATA_HOME](http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) defaults to
43    ///  `$HOME/.local/share`.
44    ///
45    /// The registry cache file is loaded from
46    /// `$XDG_CACHE_HOME/gstreamer-$GST_API_VERSION/registry-$ARCH.bin`
47    /// (where $XDG_CACHE_HOME defaults to `$HOME/.cache`) or the file listed in the `GST_REGISTRY`
48    /// env var. One reason to change the registry location is for testing.
49    ///
50    /// For each plugin that is found in the plugin search path, there could be 3
51    /// possibilities for cached information:
52    ///
53    ///  * the cache may not contain information about a given file.
54    ///  * the cache may have stale information.
55    ///  * the cache may have current information.
56    ///
57    /// In the first two cases, the plugin is loaded and the cache updated. In
58    /// addition to these cases, the cache may have entries for plugins that are not
59    /// relevant to the current process. These are marked as not available to the
60    /// current process. If the cache is updated for whatever reason, it is marked
61    /// dirty.
62    ///
63    /// A dirty cache is written out at the end of initialization. Each entry is
64    /// checked to make sure the information is minimally valid. If not, the entry is
65    /// simply dropped.
66    ///
67    /// ## Implementation notes:
68    ///
69    /// The "cache" and "registry" are different concepts and can represent
70    /// different sets of plugins. For various reasons, at init time, the cache is
71    /// stored in the default registry, and plugins not relevant to the current
72    /// process are marked with the [`PluginFlags::CACHED`][crate::PluginFlags::CACHED] bit. These plugins are
73    /// removed at the end of initialization.
74    ///
75    /// ## Signals
76    ///
77    ///
78    /// #### `feature-added`
79    ///  Signals that a feature has been added to the registry (possibly
80    /// replacing a previously-added one by the same name)
81    ///
82    ///
83    ///
84    ///
85    /// #### `plugin-added`
86    ///  Signals that a plugin has been added to the registry (possibly
87    /// replacing a previously-added one by the same name)
88    ///
89    ///
90    /// <details><summary><h4>Object</h4></summary>
91    ///
92    ///
93    /// #### `deep-notify`
94    ///  The deep notify signal is used to be notified of property changes. It is
95    /// typically attached to the toplevel bin to receive notifications from all
96    /// the elements contained in that bin.
97    ///
98    /// Detailed
99    /// </details>
100    ///
101    /// # Implements
102    ///
103    /// [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`]
104    #[doc(alias = "GstRegistry")]
105    pub struct Registry(Object<ffi::GstRegistry, ffi::GstRegistryClass>) @extends Object;
106
107    match fn {
108        type_ => || ffi::gst_registry_get_type(),
109    }
110}
111
112impl Registry {
113    /// Add the feature to the registry. The feature-added signal will be emitted.
114    ///
115    /// `feature`'s reference count will be incremented, and any floating
116    /// reference will be removed (see `gst_object_ref_sink()`)
117    /// ## `feature`
118    /// the feature to add
119    ///
120    /// # Returns
121    ///
122    /// [`true`] on success.
123    ///
124    /// MT safe.
125    #[doc(alias = "gst_registry_add_feature")]
126    pub fn add_feature(
127        &self,
128        feature: &impl IsA<PluginFeature>,
129    ) -> Result<(), glib::error::BoolError> {
130        unsafe {
131            glib::result_from_gboolean!(
132                ffi::gst_registry_add_feature(
133                    self.to_glib_none().0,
134                    feature.as_ref().to_glib_none().0
135                ),
136                "Failed to add feature"
137            )
138        }
139    }
140
141    /// Add the plugin to the registry. The plugin-added signal will be emitted.
142    ///
143    /// `plugin`'s reference count will be incremented, and any floating
144    /// reference will be removed (see `gst_object_ref_sink()`)
145    /// ## `plugin`
146    /// the plugin to add
147    ///
148    /// # Returns
149    ///
150    /// [`true`] on success.
151    ///
152    /// MT safe.
153    #[doc(alias = "gst_registry_add_plugin")]
154    pub fn add_plugin(&self, plugin: &Plugin) -> Result<(), glib::error::BoolError> {
155        unsafe {
156            glib::result_from_gboolean!(
157                ffi::gst_registry_add_plugin(self.to_glib_none().0, plugin.to_glib_none().0),
158                "Failed to add plugin"
159            )
160        }
161    }
162
163    /// Checks whether a plugin feature by the given name exists in
164    /// `self` and whether its version is at least the
165    /// version required.
166    /// ## `feature_name`
167    /// the name of the feature (e.g. "oggdemux")
168    /// ## `min_major`
169    /// the minimum major version number
170    /// ## `min_minor`
171    /// the minimum minor version number
172    /// ## `min_micro`
173    /// the minimum micro version number
174    ///
175    /// # Returns
176    ///
177    /// [`true`] if the feature could be found and the version is
178    /// the same as the required version or newer, and [`false`] otherwise.
179    #[doc(alias = "gst_registry_check_feature_version")]
180    pub fn check_feature_version(
181        &self,
182        feature_name: &str,
183        min_major: u32,
184        min_minor: u32,
185        min_micro: u32,
186    ) -> bool {
187        unsafe {
188            from_glib(ffi::gst_registry_check_feature_version(
189                self.to_glib_none().0,
190                feature_name.to_glib_none().0,
191                min_major,
192                min_minor,
193                min_micro,
194            ))
195        }
196    }
197
198    /// Find the pluginfeature with the given name and type in the registry.
199    /// ## `name`
200    /// the pluginfeature name to find
201    /// ## `type_`
202    /// the pluginfeature type to find
203    ///
204    /// # Returns
205    ///
206    /// the pluginfeature with the
207    ///  given name and type or [`None`] if the plugin was not
208    ///  found. `gst_object_unref()` after usage.
209    ///
210    /// MT safe.
211    #[doc(alias = "gst_registry_find_feature")]
212    pub fn find_feature(&self, name: &str, type_: glib::types::Type) -> Option<PluginFeature> {
213        unsafe {
214            from_glib_full(ffi::gst_registry_find_feature(
215                self.to_glib_none().0,
216                name.to_glib_none().0,
217                type_.into_glib(),
218            ))
219        }
220    }
221
222    /// Find the plugin with the given name in the registry.
223    /// The plugin will be reffed; caller is responsible for unreffing.
224    /// ## `name`
225    /// the plugin name to find
226    ///
227    /// # Returns
228    ///
229    /// the plugin with the given name
230    ///  or [`None`] if the plugin was not found. `gst_object_unref()` after
231    ///  usage.
232    ///
233    /// MT safe.
234    #[doc(alias = "gst_registry_find_plugin")]
235    pub fn find_plugin(&self, name: &str) -> Option<Plugin> {
236        unsafe {
237            from_glib_full(ffi::gst_registry_find_plugin(
238                self.to_glib_none().0,
239                name.to_glib_none().0,
240            ))
241        }
242    }
243
244    /// Returns the registry's feature list cookie. This changes
245    /// every time a feature is added or removed from the registry.
246    ///
247    /// # Returns
248    ///
249    /// the feature list cookie.
250    #[doc(alias = "gst_registry_get_feature_list_cookie")]
251    #[doc(alias = "get_feature_list_cookie")]
252    pub fn feature_list_cookie(&self) -> u32 {
253        unsafe { ffi::gst_registry_get_feature_list_cookie(self.to_glib_none().0) }
254    }
255
256    /// Look up a plugin in the given registry with the given filename.
257    /// If found, plugin is reffed.
258    /// ## `filename`
259    /// the name of the file to look up
260    ///
261    /// # Returns
262    ///
263    /// the [`Plugin`][crate::Plugin] if found, or
264    ///  [`None`] if not. `gst_object_unref()` after usage.
265    #[doc(alias = "gst_registry_lookup")]
266    pub fn lookup(&self, filename: &str) -> Option<Plugin> {
267        unsafe {
268            from_glib_full(ffi::gst_registry_lookup(
269                self.to_glib_none().0,
270                filename.to_glib_none().0,
271            ))
272        }
273    }
274
275    /// Find a [`PluginFeature`][crate::PluginFeature] with `name` in `self`.
276    /// ## `name`
277    /// a [`PluginFeature`][crate::PluginFeature] name
278    ///
279    /// # Returns
280    ///
281    /// a [`PluginFeature`][crate::PluginFeature] with its refcount incremented,
282    ///  use `gst_object_unref()` after usage.
283    ///
284    /// MT safe.
285    #[doc(alias = "gst_registry_lookup_feature")]
286    pub fn lookup_feature(&self, name: &str) -> Option<PluginFeature> {
287        unsafe {
288            from_glib_full(ffi::gst_registry_lookup_feature(
289                self.to_glib_none().0,
290                name.to_glib_none().0,
291            ))
292        }
293    }
294
295    /// Remove the feature from the registry.
296    ///
297    /// MT safe.
298    /// ## `feature`
299    /// the feature to remove
300    #[doc(alias = "gst_registry_remove_feature")]
301    pub fn remove_feature(&self, feature: &impl IsA<PluginFeature>) {
302        unsafe {
303            ffi::gst_registry_remove_feature(
304                self.to_glib_none().0,
305                feature.as_ref().to_glib_none().0,
306            );
307        }
308    }
309
310    /// Remove the plugin from the registry.
311    ///
312    /// MT safe.
313    /// ## `plugin`
314    /// the plugin to remove
315    #[doc(alias = "gst_registry_remove_plugin")]
316    pub fn remove_plugin(&self, plugin: &Plugin) {
317        unsafe {
318            ffi::gst_registry_remove_plugin(self.to_glib_none().0, plugin.to_glib_none().0);
319        }
320    }
321
322    /// Scan the given path for plugins to add to the registry. The syntax of the
323    /// path is specific to the registry.
324    /// ## `path`
325    /// the path to scan
326    ///
327    /// # Returns
328    ///
329    /// [`true`] if registry changed
330    #[doc(alias = "gst_registry_scan_path")]
331    pub fn scan_path(&self, path: impl AsRef<std::path::Path>) -> bool {
332        unsafe {
333            from_glib(ffi::gst_registry_scan_path(
334                self.to_glib_none().0,
335                path.as_ref().to_glib_none().0,
336            ))
337        }
338    }
339
340    /// Retrieves the singleton plugin registry. The caller does not own a
341    /// reference on the registry, as it is alive as long as GStreamer is
342    /// initialized.
343    ///
344    /// # Returns
345    ///
346    /// the [`Registry`][crate::Registry].
347    #[doc(alias = "gst_registry_get")]
348    pub fn get() -> Registry {
349        assert_initialized_main_thread!();
350        unsafe { from_glib_none(ffi::gst_registry_get()) }
351    }
352
353    /// Signals that a feature has been added to the registry (possibly
354    /// replacing a previously-added one by the same name)
355    /// ## `feature`
356    /// the feature that has been added
357    #[doc(alias = "feature-added")]
358    pub fn connect_feature_added<F: Fn(&Self, &PluginFeature) + Send + Sync + 'static>(
359        &self,
360        f: F,
361    ) -> SignalHandlerId {
362        unsafe extern "C" fn feature_added_trampoline<
363            F: Fn(&Registry, &PluginFeature) + Send + Sync + 'static,
364        >(
365            this: *mut ffi::GstRegistry,
366            feature: *mut ffi::GstPluginFeature,
367            f: glib::ffi::gpointer,
368        ) {
369            let f: &F = &*(f as *const F);
370            f(&from_glib_borrow(this), &from_glib_borrow(feature))
371        }
372        unsafe {
373            let f: Box_<F> = Box_::new(f);
374            connect_raw(
375                self.as_ptr() as *mut _,
376                c"feature-added".as_ptr() as *const _,
377                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
378                    feature_added_trampoline::<F> as *const (),
379                )),
380                Box_::into_raw(f),
381            )
382        }
383    }
384
385    /// Signals that a plugin has been added to the registry (possibly
386    /// replacing a previously-added one by the same name)
387    /// ## `plugin`
388    /// the plugin that has been added
389    #[doc(alias = "plugin-added")]
390    pub fn connect_plugin_added<F: Fn(&Self, &Plugin) + Send + Sync + 'static>(
391        &self,
392        f: F,
393    ) -> SignalHandlerId {
394        unsafe extern "C" fn plugin_added_trampoline<
395            F: Fn(&Registry, &Plugin) + Send + Sync + 'static,
396        >(
397            this: *mut ffi::GstRegistry,
398            plugin: *mut ffi::GstPlugin,
399            f: glib::ffi::gpointer,
400        ) {
401            let f: &F = &*(f as *const F);
402            f(&from_glib_borrow(this), &from_glib_borrow(plugin))
403        }
404        unsafe {
405            let f: Box_<F> = Box_::new(f);
406            connect_raw(
407                self.as_ptr() as *mut _,
408                c"plugin-added".as_ptr() as *const _,
409                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
410                    plugin_added_trampoline::<F> as *const (),
411                )),
412                Box_::into_raw(f),
413            )
414        }
415    }
416}
417
418unsafe impl Send for Registry {}
419unsafe impl Sync for Registry {}