gstreamer/auto/plugin.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
6#[cfg(feature = "v1_30")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
8use crate::Registry;
9use crate::{Object, PluginDependencyFlags, Structure, ffi};
10use glib::translate::*;
11
12glib::wrapper! {
13 /// GStreamer is extensible, so [`Element`][crate::Element] instances can be loaded at runtime.
14 /// A plugin system can provide one or more of the basic GStreamer
15 /// [`PluginFeature`][crate::PluginFeature] subclasses.
16 ///
17 /// A plugin should export a symbol `gst_plugin_desc` that is a
18 /// struct of type `GstPluginDesc`.
19 /// the plugin loader will check the version of the core library the plugin was
20 /// linked against and will create a new [`Plugin`][crate::Plugin]. It will then call the
21 /// `GstPluginInitFunc` function that was provided in the
22 /// `gst_plugin_desc`.
23 ///
24 /// Once you have a handle to a [`Plugin`][crate::Plugin] (e.g. from the [`Registry`][crate::Registry]), you
25 /// can add any object that subclasses [`PluginFeature`][crate::PluginFeature].
26 ///
27 /// Usually plugins are always automatically loaded so you don't need to call
28 /// [`load()`][Self::load()] explicitly to bring it into memory. There are options to
29 /// statically link plugins to an app or even use GStreamer without a plugin
30 /// repository in which case [`load()`][Self::load()] can be needed to bring the plugin
31 /// into memory.
32 ///
33 /// # Implements
34 ///
35 /// [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`GstObjectExtManual`][trait@crate::prelude::GstObjectExtManual]
36 #[doc(alias = "GstPlugin")]
37 pub struct Plugin(Object<ffi::GstPlugin, ffi::GstPluginClass>) @extends Object;
38
39 match fn {
40 type_ => || ffi::gst_plugin_get_type(),
41 }
42}
43
44impl Plugin {
45 /// Make GStreamer aware of external dependencies which affect the feature
46 /// set of this plugin (ie. the elements or typefinders associated with it).
47 ///
48 /// GStreamer will re-inspect plugins with external dependencies whenever any
49 /// of the external dependencies change. This is useful for plugins which wrap
50 /// other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
51 /// library and makes visualisations available as GStreamer elements, or a
52 /// codec loader which exposes elements and/or caps dependent on what external
53 /// codec libraries are currently installed.
54 ///
55 /// It is an error to register dependencies for any plugin that has been marked
56 /// as only have a static set of features via [`set_static_features_flag()`][Self::set_static_features_flag()]
57 /// ## `env_vars`
58 /// [`None`]-terminated array of environment variables affecting the
59 /// feature set of the plugin (e.g. an environment variable containing
60 /// paths where to look for additional modules/plugins of a library),
61 /// or [`None`]. Environment variable names may be followed by a path component
62 /// which will be added to the content of the environment variable, e.g.
63 /// "HOME/.mystuff/plugins".
64 /// ## `paths`
65 /// [`None`]-terminated array of directories/paths where dependent files
66 /// may be, or [`None`].
67 /// ## `names`
68 /// [`None`]-terminated array of file names (or file name suffixes,
69 /// depending on `flags`) to be used in combination with the paths from
70 /// `paths` and/or the paths extracted from the environment variables in
71 /// `env_vars`, or [`None`].
72 /// ## `flags`
73 /// optional flags, or `GST_PLUGIN_DEPENDENCY_FLAG_NONE`
74 #[doc(alias = "gst_plugin_add_dependency")]
75 pub fn add_dependency(
76 &self,
77 env_vars: &[&str],
78 paths: &[&str],
79 names: &[&str],
80 flags: PluginDependencyFlags,
81 ) {
82 unsafe {
83 ffi::gst_plugin_add_dependency(
84 self.to_glib_none().0,
85 env_vars.to_glib_none().0,
86 paths.to_glib_none().0,
87 names.to_glib_none().0,
88 flags.into_glib(),
89 );
90 }
91 }
92
93 /// Make GStreamer aware of external dependencies which affect the feature
94 /// set of this plugin (ie. the elements or typefinders associated with it).
95 ///
96 /// GStreamer will re-inspect plugins with external dependencies whenever any
97 /// of the external dependencies change. This is useful for plugins which wrap
98 /// other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
99 /// library and makes visualisations available as GStreamer elements, or a
100 /// codec loader which exposes elements and/or caps dependent on what external
101 /// codec libraries are currently installed.
102 ///
103 /// Convenience wrapper function for [`add_dependency()`][Self::add_dependency()] which
104 /// takes simple strings as arguments instead of string arrays, with multiple
105 /// arguments separated by predefined delimiters (see above).
106 ///
107 /// It is an error to register dependencies for any plugin that has been marked
108 /// as only have a static set of features via [`set_static_features_flag()`][Self::set_static_features_flag()].
109 /// ## `env_vars`
110 /// one or more environment variables (separated by ':', ';' or ','),
111 /// or [`None`]. Environment variable names may be followed by a path component
112 /// which will be added to the content of the environment variable, e.g.
113 /// "HOME/.mystuff/plugins:MYSTUFF_PLUGINS_PATH"
114 /// ## `paths`
115 /// one or more directory paths (separated by ':' or ';' or ','),
116 /// or [`None`]. Example: "/usr/lib/mystuff/plugins"
117 /// ## `names`
118 /// one or more file names or file name suffixes (separated by commas),
119 /// or [`None`]
120 /// ## `flags`
121 /// optional flags, or `GST_PLUGIN_DEPENDENCY_FLAG_NONE`
122 #[doc(alias = "gst_plugin_add_dependency_simple")]
123 pub fn add_dependency_simple(
124 &self,
125 env_vars: Option<&str>,
126 paths: Option<&str>,
127 names: Option<&str>,
128 flags: PluginDependencyFlags,
129 ) {
130 unsafe {
131 ffi::gst_plugin_add_dependency_simple(
132 self.to_glib_none().0,
133 env_vars.to_glib_none().0,
134 paths.to_glib_none().0,
135 names.to_glib_none().0,
136 flags.into_glib(),
137 );
138 }
139 }
140
141 /// ## `message`
142 /// the status error message
143 #[cfg(feature = "v1_24")]
144 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
145 #[doc(alias = "gst_plugin_add_status_error")]
146 pub fn add_status_error(&self, message: &str) {
147 unsafe {
148 ffi::gst_plugin_add_status_error(self.to_glib_none().0, message.to_glib_none().0);
149 }
150 }
151
152 /// ## `message`
153 /// the status info message
154 #[cfg(feature = "v1_24")]
155 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
156 #[doc(alias = "gst_plugin_add_status_info")]
157 pub fn add_status_info(&self, message: &str) {
158 unsafe {
159 ffi::gst_plugin_add_status_info(self.to_glib_none().0, message.to_glib_none().0);
160 }
161 }
162
163 /// ## `message`
164 /// the status warning message
165 #[cfg(feature = "v1_24")]
166 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
167 #[doc(alias = "gst_plugin_add_status_warning")]
168 pub fn add_status_warning(&self, message: &str) {
169 unsafe {
170 ffi::gst_plugin_add_status_warning(self.to_glib_none().0, message.to_glib_none().0);
171 }
172 }
173
174 /// Get the long descriptive name of the plugin
175 ///
176 /// # Returns
177 ///
178 /// the long name of the plugin
179 #[doc(alias = "gst_plugin_get_description")]
180 #[doc(alias = "get_description")]
181 pub fn description(&self) -> glib::GString {
182 unsafe { from_glib_none(ffi::gst_plugin_get_description(self.to_glib_none().0)) }
183 }
184
185 /// get the filename of the plugin
186 ///
187 /// # Returns
188 ///
189 /// the filename of the plugin
190 #[doc(alias = "gst_plugin_get_filename")]
191 #[doc(alias = "get_filename")]
192 pub fn filename(&self) -> Option<std::path::PathBuf> {
193 unsafe { from_glib_none(ffi::gst_plugin_get_filename(self.to_glib_none().0)) }
194 }
195
196 /// get the license of the plugin
197 ///
198 /// # Returns
199 ///
200 /// the license of the plugin
201 #[doc(alias = "gst_plugin_get_license")]
202 #[doc(alias = "get_license")]
203 pub fn license(&self) -> glib::GString {
204 unsafe { from_glib_none(ffi::gst_plugin_get_license(self.to_glib_none().0)) }
205 }
206
207 /// Get the short name of the plugin
208 ///
209 /// # Returns
210 ///
211 /// the name of the plugin
212 #[doc(alias = "gst_plugin_get_name")]
213 #[doc(alias = "get_name")]
214 pub fn plugin_name(&self) -> glib::GString {
215 unsafe { from_glib_none(ffi::gst_plugin_get_name(self.to_glib_none().0)) }
216 }
217
218 /// get the URL where the plugin comes from
219 ///
220 /// # Returns
221 ///
222 /// the origin of the plugin
223 #[doc(alias = "gst_plugin_get_origin")]
224 #[doc(alias = "get_origin")]
225 pub fn origin(&self) -> glib::GString {
226 unsafe { from_glib_none(ffi::gst_plugin_get_origin(self.to_glib_none().0)) }
227 }
228
229 /// get the package the plugin belongs to.
230 ///
231 /// # Returns
232 ///
233 /// the package of the plugin
234 #[doc(alias = "gst_plugin_get_package")]
235 #[doc(alias = "get_package")]
236 pub fn package(&self) -> glib::GString {
237 unsafe { from_glib_none(ffi::gst_plugin_get_package(self.to_glib_none().0)) }
238 }
239
240 /// Get the [`Registry`][crate::Registry] this plugin belongs to, for use when registering
241 /// associated [`PluginFeature`][crate::PluginFeature] during plugin registration. Usually
242 /// this is just the default registry, but may differ during pre-built
243 /// registry creation. If passed NULL, returns the default registry
244 ///
245 /// # Returns
246 ///
247 /// The [`Registry`][crate::Registry] to use for plugin feature registration
248 #[cfg(feature = "v1_30")]
249 #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
250 #[doc(alias = "gst_plugin_get_registry")]
251 #[doc(alias = "get_registry")]
252 pub fn registry(&self) -> Registry {
253 unsafe { from_glib_none(ffi::gst_plugin_get_registry(self.to_glib_none().0)) }
254 }
255
256 /// Get the release date (and possibly time) in form of a string, if available.
257 ///
258 /// For normal GStreamer plugin releases this will usually just be a date in
259 /// the form of "YYYY-MM-DD", while pre-releases and builds from git may contain
260 /// a time component after the date as well, in which case the string will be
261 /// formatted like "YYYY-MM-DDTHH:MMZ" (e.g. "2012-04-30T09:30Z").
262 ///
263 /// There may be plugins that do not have a valid release date set on them.
264 ///
265 /// # Returns
266 ///
267 /// the date string of the plugin, or [`None`] if not
268 /// available.
269 #[doc(alias = "gst_plugin_get_release_date_string")]
270 #[doc(alias = "get_release_date_string")]
271 pub fn release_date_string(&self) -> Option<glib::GString> {
272 unsafe {
273 from_glib_none(ffi::gst_plugin_get_release_date_string(
274 self.to_glib_none().0,
275 ))
276 }
277 }
278
279 /// get the source module the plugin belongs to.
280 ///
281 /// # Returns
282 ///
283 /// the source of the plugin
284 #[doc(alias = "gst_plugin_get_source")]
285 #[doc(alias = "get_source")]
286 pub fn source(&self) -> glib::GString {
287 unsafe { from_glib_none(ffi::gst_plugin_get_source(self.to_glib_none().0)) }
288 }
289
290 ///
291 /// # Returns
292 ///
293 /// an array of plugin status error messages, or NULL
294 #[cfg(feature = "v1_24")]
295 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
296 #[doc(alias = "gst_plugin_get_status_errors")]
297 #[doc(alias = "get_status_errors")]
298 pub fn status_errors(&self) -> Vec<glib::GString> {
299 unsafe {
300 FromGlibPtrContainer::from_glib_full(ffi::gst_plugin_get_status_errors(
301 self.to_glib_none().0,
302 ))
303 }
304 }
305
306 ///
307 /// # Returns
308 ///
309 /// an array of plugin status info messages, or NULL
310 #[cfg(feature = "v1_24")]
311 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
312 #[doc(alias = "gst_plugin_get_status_infos")]
313 #[doc(alias = "get_status_infos")]
314 pub fn status_infos(&self) -> Vec<glib::GString> {
315 unsafe {
316 FromGlibPtrContainer::from_glib_full(ffi::gst_plugin_get_status_infos(
317 self.to_glib_none().0,
318 ))
319 }
320 }
321
322 ///
323 /// # Returns
324 ///
325 /// an array of plugin status warning messages, or NULL
326 #[cfg(feature = "v1_24")]
327 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
328 #[doc(alias = "gst_plugin_get_status_warnings")]
329 #[doc(alias = "get_status_warnings")]
330 pub fn status_warnings(&self) -> Vec<glib::GString> {
331 unsafe {
332 FromGlibPtrContainer::from_glib_full(ffi::gst_plugin_get_status_warnings(
333 self.to_glib_none().0,
334 ))
335 }
336 }
337
338 /// get the version of the plugin
339 ///
340 /// # Returns
341 ///
342 /// the version of the plugin
343 #[doc(alias = "gst_plugin_get_version")]
344 #[doc(alias = "get_version")]
345 pub fn version(&self) -> glib::GString {
346 unsafe { from_glib_none(ffi::gst_plugin_get_version(self.to_glib_none().0)) }
347 }
348
349 /// queries if the plugin is loaded into memory
350 ///
351 /// # Returns
352 ///
353 /// [`true`] is loaded, [`false`] otherwise
354 #[doc(alias = "gst_plugin_is_loaded")]
355 pub fn is_loaded(&self) -> bool {
356 unsafe { from_glib(ffi::gst_plugin_is_loaded(self.to_glib_none().0)) }
357 }
358
359 /// Loads `self`. Note that the *return value* is the loaded plugin; `self` is
360 /// untouched. The normal use pattern of this function goes like this:
361 ///
362 ///
363 /// ```text
364 /// GstPlugin *loaded_plugin;
365 /// loaded_plugin = gst_plugin_load (plugin);
366 /// // presumably, we're no longer interested in the potentially-unloaded plugin
367 /// gst_object_unref (plugin);
368 /// plugin = loaded_plugin;
369 /// ```
370 ///
371 /// # Returns
372 ///
373 /// a reference to a loaded plugin, or
374 /// [`None`] on error.
375 #[doc(alias = "gst_plugin_load")]
376 pub fn load(&self) -> Result<Plugin, glib::BoolError> {
377 unsafe {
378 Option::<_>::from_glib_full(ffi::gst_plugin_load(self.to_glib_none().0))
379 .ok_or_else(|| glib::bool_error!("Failed to load plugin"))
380 }
381 }
382
383 /// Adds plugin specific data to cache. Passes the ownership of the structure to
384 /// the `self`.
385 ///
386 /// The cache is flushed every time the registry is rebuilt.
387 /// ## `cache_data`
388 /// a structure containing the data to cache
389 #[doc(alias = "gst_plugin_set_cache_data")]
390 pub fn set_cache_data(&self, cache_data: Structure) {
391 unsafe {
392 ffi::gst_plugin_set_cache_data(self.to_glib_none().0, cache_data.into_glib_ptr());
393 }
394 }
395
396 /// Marks this plugin as having no external dependencies, and
397 /// a static set of plugin features, rendering it suitable
398 /// for inclusion in a static build-time registry. Shipping a static
399 /// build-time registry speeds up application startup by avoiding
400 /// scanning of these plugins at run-time.
401 ///
402 /// It is an error to call this function after any [`add_dependency()`][Self::add_dependency()]
403 /// or [`add_dependency_simple()`][Self::add_dependency_simple()] call, or to call those functions
404 /// once this flag is set.
405 #[cfg(feature = "v1_30")]
406 #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
407 #[doc(alias = "gst_plugin_set_static_features_flag")]
408 pub fn set_static_features_flag(&self) {
409 unsafe {
410 ffi::gst_plugin_set_static_features_flag(self.to_glib_none().0);
411 }
412 }
413
414 /// Load the named plugin. Refs the plugin.
415 /// ## `name`
416 /// name of plugin to load
417 ///
418 /// # Returns
419 ///
420 /// a reference to a loaded plugin, or
421 /// [`None`] on error.
422 #[doc(alias = "gst_plugin_load_by_name")]
423 pub fn load_by_name(name: &str) -> Result<Plugin, glib::BoolError> {
424 assert_initialized_main_thread!();
425 unsafe {
426 Option::<_>::from_glib_full(ffi::gst_plugin_load_by_name(name.to_glib_none().0))
427 .ok_or_else(|| glib::bool_error!("Failed to load plugin"))
428 }
429 }
430
431 /// Loads the given plugin and refs it. Caller needs to unref after use.
432 /// ## `filename`
433 /// the plugin filename to load
434 ///
435 /// # Returns
436 ///
437 /// a reference to the existing loaded GstPlugin, a
438 /// reference to the newly-loaded GstPlugin, or [`None`] if an error occurred.
439 #[doc(alias = "gst_plugin_load_file")]
440 pub fn load_file(filename: impl AsRef<std::path::Path>) -> Result<Plugin, glib::Error> {
441 assert_initialized_main_thread!();
442 unsafe {
443 let mut error = std::ptr::null_mut();
444 let ret = ffi::gst_plugin_load_file(filename.as_ref().to_glib_none().0, &mut error);
445 if error.is_null() {
446 Ok(from_glib_full(ret))
447 } else {
448 Err(from_glib_full(error))
449 }
450 }
451 }
452}
453
454impl std::fmt::Display for Plugin {
455 #[inline]
456 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
457 f.write_str(&self.plugin_name())
458 }
459}
460
461unsafe impl Send for Plugin {}
462unsafe impl Sync for Plugin {}