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