Skip to main content

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