2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstplugin.c: Plugin subsystem for loading elements, types, and libs
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
26 * @short_description: Container for features loaded from a shared object module
27 * @see_also: #GstPluginFeature, #GstElementFactory
29 * GStreamer is extensible, so #GstElement instances can be loaded at runtime.
30 * A plugin system can provide one or more of the basic
31 * <application>GStreamer</application> #GstPluginFeature subclasses.
33 * A plugin should export a symbol <symbol>gst_plugin_desc</symbol> that is a
34 * struct of type #GstPluginDesc.
35 * the plugin loader will check the version of the core library the plugin was
36 * linked against and will create a new #GstPlugin. It will then call the
37 * #GstPluginInitFunc function that was provided in the
38 * <symbol>gst_plugin_desc</symbol>.
40 * Once you have a handle to a #GstPlugin (e.g. from the #GstRegistry), you
41 * can add any object that subclasses #GstPluginFeature.
43 * Usually plugins are always automatically loaded so you don't need to call
44 * gst_plugin_load() explicitly to bring it into memory. There are options to
45 * statically link plugins to an app or even use GStreamer without a plugin
46 * repository in which case gst_plugin_load() can be needed to bring the plugin
54 #include "gst_private.h"
56 #include <glib/gstdio.h>
57 #include <sys/types.h>
68 #include "glib-compat-private.h"
72 #define GST_CAT_DEFAULT GST_CAT_PLUGIN_LOADING
74 static guint _num_static_plugins; /* 0 */
75 static GstPluginDesc *_static_plugins; /* NULL */
76 static gboolean _gst_plugin_inited;
77 static gchar **_plugin_loading_whitelist; /* NULL */
79 /* static variables for segfault handling of plugin loading */
80 static char *_gst_plugin_fault_handler_filename = NULL;
82 /* list of valid licenses.
83 * One of these must be specified or the plugin won't be loaded
84 * Please file a bug to request any additional license be added.
86 * GPL: http://www.gnu.org/copyleft/gpl.html
87 * LGPL: http://www.gnu.org/copyleft/lesser.html
88 * QPL: http://www.trolltech.com/licenses/qpl.html
89 * MPL: http://www.opensource.org/licenses/mozilla1.1.php
90 * MIT/X11: http://www.opensource.org/licenses/mit-license.php
91 * 3-clause BSD: https://opensource.org/licenses/BSD-3-Clause
92 * Zero-Clause BSD: https://opensource.org/licenses/0BSD
94 static const gchar valid_licenses[] = "LGPL\000" /* GNU Lesser General Public License */
95 "GPL\000" /* GNU General Public License */
96 "QPL\000" /* Trolltech Qt Public License */
97 "GPL/QPL\000" /* Combi-license of GPL + QPL */
98 "MPL\000" /* MPL 1.1 license */
99 "BSD\000" /* 3-clause BSD license */
100 "MIT/X11\000" /* MIT/X11 license */
101 "0BSD\000" /* Zero-Clause BSD */
102 "Proprietary\000" /* Proprietary license */
103 GST_LICENSE_UNKNOWN; /* some other license */
105 static const guint8 valid_licenses_idx[] = { 0, 5, 9, 13, 21, 25, 29, 37, 42,
109 static GstPlugin *gst_plugin_register_func (GstPlugin * plugin,
110 const GstPluginDesc * desc, gpointer user_data);
111 static void gst_plugin_desc_copy (GstPluginDesc * dest,
112 const GstPluginDesc * src);
114 static void gst_plugin_ext_dep_free (GstPluginDep * dep);
116 G_DEFINE_TYPE_WITH_PRIVATE (GstPlugin, gst_plugin, GST_TYPE_OBJECT);
119 gst_plugin_init (GstPlugin * plugin)
121 plugin->priv = gst_plugin_get_instance_private (plugin);
125 gst_plugin_finalize (GObject * object)
127 GstPlugin *plugin = GST_PLUGIN_CAST (object);
129 GST_DEBUG ("finalizing plugin %" GST_PTR_FORMAT, plugin);
131 /* FIXME: make registry add a weak ref instead */
133 GstRegistry *registry = gst_registry_get ();
135 for (g = registry->plugins; g; g = g->next) {
136 if (g->data == (gpointer) plugin) {
137 g_warning ("removing plugin that is still in registry");
142 g_free (plugin->filename);
143 g_free (plugin->basename);
145 g_list_foreach (plugin->priv->deps, (GFunc) gst_plugin_ext_dep_free, NULL);
146 g_list_free (plugin->priv->deps);
147 plugin->priv->deps = NULL;
149 if (plugin->priv->cache_data) {
150 gst_structure_free (plugin->priv->cache_data);
153 G_OBJECT_CLASS (gst_plugin_parent_class)->finalize (object);
157 gst_plugin_class_init (GstPluginClass * klass)
159 G_OBJECT_CLASS (klass)->finalize = gst_plugin_finalize;
163 gst_plugin_error_quark (void)
165 static GQuark quark = 0;
168 quark = g_quark_from_static_string ("gst_plugin_error");
173 * gst_plugin_register_static:
174 * @major_version: the major version number of the GStreamer core that the
175 * plugin was compiled for, you can just use GST_VERSION_MAJOR here
176 * @minor_version: the minor version number of the GStreamer core that the
177 * plugin was compiled for, you can just use GST_VERSION_MINOR here
178 * @name: a unique name of the plugin (ideally prefixed with an application- or
179 * library-specific namespace prefix in order to avoid name conflicts in
180 * case a similar plugin with the same name ever gets added to GStreamer)
181 * @description: description of the plugin
182 * @init_func: (scope call): pointer to the init function of this plugin.
183 * @version: version string of the plugin
184 * @license: effective license of plugin. Must be one of the approved licenses
185 * (see #GstPluginDesc above) or the plugin will not be registered.
186 * @source: source module plugin belongs to
187 * @package: shipped package plugin belongs to
188 * @origin: URL to provider of plugin
190 * Registers a static plugin, ie. a plugin which is private to an application
191 * or library and contained within the application or library (as opposed to
192 * being shipped as a separate module file).
194 * You must make sure that GStreamer has been initialised (with gst_init() or
195 * via gst_init_get_option_group()) before calling this function.
197 * Returns: %TRUE if the plugin was registered correctly, otherwise %FALSE.
200 gst_plugin_register_static (gint major_version, gint minor_version,
201 const gchar * name, const gchar * description, GstPluginInitFunc init_func,
202 const gchar * version, const gchar * license, const gchar * source,
203 const gchar * package, const gchar * origin)
205 GstPluginDesc desc = { major_version, minor_version, name, description,
206 init_func, version, license, source, package, origin, NULL,
209 gboolean res = FALSE;
211 g_return_val_if_fail (name != NULL, FALSE);
212 g_return_val_if_fail (description != NULL, FALSE);
213 g_return_val_if_fail (init_func != NULL, FALSE);
214 g_return_val_if_fail (version != NULL, FALSE);
215 g_return_val_if_fail (license != NULL, FALSE);
216 g_return_val_if_fail (source != NULL, FALSE);
217 g_return_val_if_fail (package != NULL, FALSE);
218 g_return_val_if_fail (origin != NULL, FALSE);
220 /* make sure gst_init() has been called */
221 g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
223 GST_LOG ("attempting to load static plugin \"%s\" now...", name);
224 plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
225 if (gst_plugin_register_func (plugin, &desc, NULL) != NULL) {
226 GST_INFO ("registered static plugin \"%s\"", name);
227 res = gst_registry_add_plugin (gst_registry_get (), plugin);
228 GST_INFO ("added static plugin \"%s\", result: %d", name, res);
234 * gst_plugin_register_static_full:
235 * @major_version: the major version number of the GStreamer core that the
236 * plugin was compiled for, you can just use GST_VERSION_MAJOR here
237 * @minor_version: the minor version number of the GStreamer core that the
238 * plugin was compiled for, you can just use GST_VERSION_MINOR here
239 * @name: a unique name of the plugin (ideally prefixed with an application- or
240 * library-specific namespace prefix in order to avoid name conflicts in
241 * case a similar plugin with the same name ever gets added to GStreamer)
242 * @description: description of the plugin
243 * @init_full_func: (scope call): pointer to the init function with user data
245 * @version: version string of the plugin
246 * @license: effective license of plugin. Must be one of the approved licenses
247 * (see #GstPluginDesc above) or the plugin will not be registered.
248 * @source: source module plugin belongs to
249 * @package: shipped package plugin belongs to
250 * @origin: URL to provider of plugin
251 * @user_data: gpointer to user data
253 * Registers a static plugin, ie. a plugin which is private to an application
254 * or library and contained within the application or library (as opposed to
255 * being shipped as a separate module file) with a #GstPluginInitFullFunc
256 * which allows user data to be passed to the callback function (useful
259 * You must make sure that GStreamer has been initialised (with gst_init() or
260 * via gst_init_get_option_group()) before calling this function.
262 * Returns: %TRUE if the plugin was registered correctly, otherwise %FALSE.
265 gst_plugin_register_static_full (gint major_version, gint minor_version,
266 const gchar * name, const gchar * description,
267 GstPluginInitFullFunc init_full_func, const gchar * version,
268 const gchar * license, const gchar * source, const gchar * package,
269 const gchar * origin, gpointer user_data)
271 GstPluginDesc desc = { major_version, minor_version, name, description,
272 (GstPluginInitFunc) init_full_func, version, license, source, package,
276 gboolean res = FALSE;
278 g_return_val_if_fail (name != NULL, FALSE);
279 g_return_val_if_fail (description != NULL, FALSE);
280 g_return_val_if_fail (init_full_func != NULL, FALSE);
281 g_return_val_if_fail (version != NULL, FALSE);
282 g_return_val_if_fail (license != NULL, FALSE);
283 g_return_val_if_fail (source != NULL, FALSE);
284 g_return_val_if_fail (package != NULL, FALSE);
285 g_return_val_if_fail (origin != NULL, FALSE);
287 /* make sure gst_init() has been called */
288 g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
290 GST_LOG ("attempting to load static plugin \"%s\" now...", name);
291 plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
292 if (gst_plugin_register_func (plugin, &desc, user_data) != NULL) {
293 GST_INFO ("registered static plugin \"%s\"", name);
294 res = gst_registry_add_plugin (gst_registry_get (), plugin);
295 GST_INFO ("added static plugin \"%s\", result: %d", name, res);
301 _priv_gst_plugin_initialize (void)
303 const gchar *whitelist;
306 _gst_plugin_inited = TRUE;
308 whitelist = g_getenv ("GST_PLUGIN_LOADING_WHITELIST");
309 if (whitelist != NULL && *whitelist != '\0') {
310 _plugin_loading_whitelist = g_strsplit (whitelist,
311 G_SEARCHPATH_SEPARATOR_S, -1);
312 for (i = 0; _plugin_loading_whitelist[i] != NULL; ++i) {
313 GST_INFO ("plugins whitelist entry: %s", _plugin_loading_whitelist[i]);
317 /* now register all static plugins */
318 GST_INFO ("registering %u static plugins", _num_static_plugins);
319 for (i = 0; i < _num_static_plugins; ++i) {
320 gst_plugin_register_static (_static_plugins[i].major_version,
321 _static_plugins[i].minor_version, _static_plugins[i].name,
322 _static_plugins[i].description, _static_plugins[i].plugin_init,
323 _static_plugins[i].version, _static_plugins[i].license,
324 _static_plugins[i].source, _static_plugins[i].package,
325 _static_plugins[i].origin);
328 if (_static_plugins) {
329 free (_static_plugins);
330 _static_plugins = NULL;
331 _num_static_plugins = 0;
335 /* Whitelist entry format:
337 * plugin1,plugin2@pathprefix or
338 * plugin1,plugin2@* or just
340 * source-package@pathprefix or
341 * source-package@* or just
344 * ie. the bit before the path will be checked against both the plugin
345 * name and the plugin's source package name, to keep the format simple.
348 gst_plugin_desc_matches_whitelist_entry (const GstPluginDesc * desc,
349 const gchar * filename, const gchar * pattern)
352 gboolean ret = FALSE;
355 GST_LOG ("Whitelist pattern '%s', plugin: %s of %s@%s", pattern, desc->name,
356 desc->source, GST_STR_NULL (filename));
358 /* do we have a path prefix? */
359 sep = strchr (pattern, '@');
360 if (sep != NULL && strcmp (sep, "@*") != 0 && strcmp (sep, "@") != 0) {
361 /* paths are not canonicalised or treated with realpath() here. This
362 * should be good enough for our use case, since we just use the paths
363 * autotools uses, and those will be constructed from the same prefix. */
364 if (filename != NULL && !g_str_has_prefix (filename, sep + 1))
367 GST_LOG ("%s matches path prefix %s", GST_STR_NULL (filename), sep + 1);
371 name = g_strndup (pattern, (gsize) (sep - pattern));
373 name = g_strdup (pattern);
377 if (!g_ascii_isalnum (*name)) {
378 GST_WARNING ("Invalid whitelist pattern: %s", pattern);
382 /* now check plugin names / source package name */
383 if (strchr (name, ',') == NULL) {
384 /* only a single name: either a plugin name or the source package name */
385 ret = (strcmp (desc->source, name) == 0 || strcmp (desc->name, name) == 0);
389 /* multiple names: assume these are plugin names */
390 names = g_strsplit (name, ",", -1);
391 for (n = names; n != NULL && *n != NULL; ++n) {
393 if (strcmp (desc->name, *n) == 0) {
401 GST_LOG ("plugin / source package name match: %d", ret);
410 priv_gst_plugin_desc_is_whitelisted (const GstPluginDesc * desc,
411 const gchar * filename)
415 if (_plugin_loading_whitelist == NULL)
418 for (entry = _plugin_loading_whitelist; *entry != NULL; ++entry) {
419 if (gst_plugin_desc_matches_whitelist_entry (desc, filename, *entry)) {
420 GST_LOG ("Plugin %s is in whitelist", filename);
425 GST_LOG ("Plugin %s (package %s, file %s) not in whitelist", desc->name,
426 desc->source, filename);
431 priv_gst_plugin_loading_have_whitelist (void)
433 return (_plugin_loading_whitelist != NULL);
437 priv_gst_plugin_loading_get_whitelist_hash (void)
441 if (_plugin_loading_whitelist != NULL) {
444 for (w = _plugin_loading_whitelist; *w != NULL; ++w)
445 hash ^= g_str_hash (*w);
451 /* this function could be extended to check if the plugin license matches the
452 * applications license (would require the app to register its license somehow).
453 * We'll wait for someone who's interested in it to code it :)
456 gst_plugin_check_license (const gchar * license)
460 for (i = 0; i < G_N_ELEMENTS (valid_licenses_idx); ++i) {
461 if (strcmp (license, valid_licenses + valid_licenses_idx[i]) == 0)
468 gst_plugin_check_version (gint major, gint minor)
470 /* return NULL if the major and minor version numbers are not compatible */
472 if (major != GST_VERSION_MAJOR || minor > GST_VERSION_MINOR)
479 gst_plugin_register_func (GstPlugin * plugin, const GstPluginDesc * desc,
482 if (!gst_plugin_check_version (desc->major_version, desc->minor_version)) {
484 GST_WARNING ("plugin \"%s\" has incompatible version "
485 "(plugin: %d.%d, gst: %d,%d), not loading",
486 GST_STR_NULL (plugin->filename), desc->major_version,
487 desc->minor_version, GST_VERSION_MAJOR, GST_VERSION_MINOR);
491 if (!desc->license || !desc->description || !desc->source ||
492 !desc->package || !desc->origin) {
494 GST_WARNING ("plugin \"%s\" has missing detail in GstPluginDesc, not "
495 "loading", GST_STR_NULL (plugin->filename));
499 if (!gst_plugin_check_license (desc->license)) {
501 GST_WARNING ("plugin \"%s\" has invalid license \"%s\", not loading",
502 GST_STR_NULL (plugin->filename), desc->license);
507 GST_LOG ("plugin \"%s\" looks good", GST_STR_NULL (plugin->filename));
509 gst_plugin_desc_copy (&plugin->desc, desc);
511 /* make resident so we're really sure it never gets unloaded again.
512 * Theoretically this is not needed, but practically it doesn't hurt.
513 * And we're rather safe than sorry. */
515 g_module_make_resident (plugin->module);
518 if (!(((GstPluginInitFullFunc) (desc->plugin_init)) (plugin, user_data))) {
520 GST_WARNING ("plugin \"%s\" failed to initialise",
521 GST_STR_NULL (plugin->filename));
525 if (!((desc->plugin_init) (plugin))) {
527 GST_WARNING ("plugin \"%s\" failed to initialise",
528 GST_STR_NULL (plugin->filename));
534 GST_LOG ("plugin \"%s\" initialised", GST_STR_NULL (plugin->filename));
539 #ifdef HAVE_SIGACTION
540 static struct sigaction oldaction;
541 static gboolean _gst_plugin_fault_handler_is_setup = FALSE;
544 * _gst_plugin_fault_handler_restore:
545 * segfault handler restorer
548 _gst_plugin_fault_handler_restore (void)
550 if (!_gst_plugin_fault_handler_is_setup)
553 _gst_plugin_fault_handler_is_setup = FALSE;
555 sigaction (SIGSEGV, &oldaction, NULL);
559 * _gst_plugin_fault_handler_sighandler:
560 * segfault handler implementation
563 _gst_plugin_fault_handler_sighandler (int signum)
565 /* We need to restore the fault handler or we'll keep getting it */
566 _gst_plugin_fault_handler_restore ();
570 g_print ("\nERROR: ");
571 g_print ("Caught a segmentation fault while loading plugin file:\n");
572 g_print ("%s\n\n", _gst_plugin_fault_handler_filename);
573 g_print ("Please either:\n");
574 g_print ("- remove it and restart.\n");
576 ("- run with --gst-disable-segtrap --gst-disable-registry-fork and debug.\n");
580 g_print ("Caught unhandled signal on plugin loading\n");
586 * _gst_plugin_fault_handler_setup:
587 * sets up the segfault handler
590 _gst_plugin_fault_handler_setup (void)
592 struct sigaction action;
594 /* if asked to leave segfaults alone, just return */
595 if (!gst_segtrap_is_enabled ())
598 if (_gst_plugin_fault_handler_is_setup)
601 _gst_plugin_fault_handler_is_setup = TRUE;
603 memset (&action, 0, sizeof (action));
604 action.sa_handler = _gst_plugin_fault_handler_sighandler;
606 sigaction (SIGSEGV, &action, &oldaction);
608 #else /* !HAVE_SIGACTION */
610 _gst_plugin_fault_handler_restore (void)
615 _gst_plugin_fault_handler_setup (void)
618 #endif /* HAVE_SIGACTION */
620 /* g_time_val_from_iso8601() doesn't do quite what we want */
622 check_release_datetime (const gchar * date_time)
626 /* we require YYYY-MM-DD or YYYY-MM-DDTHH:MMZ format */
627 if (!g_ascii_isdigit (*date_time))
630 val = g_ascii_strtoull (date_time, (gchar **) & date_time, 10);
631 if (val < 2000 || val > 2100 || *date_time != '-')
634 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
635 if (val == 0 || val > 12 || *date_time != '-')
638 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
639 if (val == 0 || val > 32)
642 /* end of string or date/time separator + HH:MMZ */
643 if (*date_time == 'T' || *date_time == ' ') {
644 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
645 if (val > 24 || *date_time != ':')
648 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
649 if (val > 59 || *date_time != 'Z')
655 return (*date_time == '\0');
658 static GMutex gst_plugin_loading_mutex;
660 #define CHECK_PLUGIN_DESC_FIELD(desc,field,fn) \
661 if (G_UNLIKELY ((desc)->field == NULL || *(desc)->field == '\0')) { \
662 g_warning ("Plugin description for '%s' has no valid %s field", fn, G_STRINGIFY (field)); \
663 g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, \
664 "Plugin %s has invalid plugin description field '%s'", \
665 filename, G_STRINGIFY (field)); \
670 * gst_plugin_load_file:
671 * @filename: (type filename): the plugin filename to load
672 * @error: pointer to a %NULL-valued GError
674 * Loads the given plugin and refs it. Caller needs to unref after use.
676 * Returns: (transfer full): a reference to the existing loaded GstPlugin, a
677 * reference to the newly-loaded GstPlugin, or %NULL if an error occurred.
680 gst_plugin_load_file (const gchar * filename, GError ** error)
682 return _priv_gst_plugin_load_file_for_registry (filename, NULL, error);
686 extract_symname (const char *filename)
688 gchar *bname, *name, *symname;
690 gsize prefix_len, len;
693 bname = g_path_get_basename (filename);
694 for (i = 0; bname[i]; ++i) {
699 if (g_str_has_prefix (bname, "libgst"))
701 else if (g_str_has_prefix (bname, "lib"))
703 else if (g_str_has_prefix (bname, "gst"))
706 prefix_len = 0; /* use whole name (minus suffix) as plugin name */
708 dot = g_utf8_strchr (bname, -1, '.');
710 len = dot - bname - prefix_len;
712 len = strlen (bname + prefix_len);
714 name = g_strndup (bname + prefix_len, len);
717 symname = g_strconcat ("gst_plugin_", name, "_get_desc", NULL);
723 /* Note: The return value is (transfer full) although we work with floating
724 * references here. If a new plugin instance is created, it is always sinked
725 * in the registry first and a new reference is returned
728 _priv_gst_plugin_load_file_for_registry (const gchar * filename,
729 GstRegistry * registry, GError ** error)
731 const GstPluginDesc *desc;
737 GStatBuf file_status;
738 gboolean new_plugin = TRUE;
741 g_return_val_if_fail (filename != NULL, NULL);
743 if (registry == NULL)
744 registry = gst_registry_get ();
746 g_mutex_lock (&gst_plugin_loading_mutex);
748 plugin = gst_registry_lookup (registry, filename);
750 if (plugin->module) {
752 g_mutex_unlock (&gst_plugin_loading_mutex);
755 /* load plugin and update fields */
760 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "attempt to load plugin \"%s\"",
763 if (!g_module_supported ()) {
764 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "module loading not supported");
767 GST_PLUGIN_ERROR_MODULE, "Dynamic loading not supported");
771 if (g_stat (filename, &file_status)) {
772 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "problem accessing file");
775 GST_PLUGIN_ERROR_MODULE, "Problem accessing file %s: %s", filename,
780 flags = G_MODULE_BIND_LOCAL;
781 /* libgstpython.so is the gst-python plugin loader. It needs to be loaded with
782 * G_MODULE_BIND_LAZY.
784 * Ideally there should be a generic way for plugins to specify that they
785 * need to be loaded with _LAZY.
787 if (strstr (filename, "libgstpython"))
788 flags |= G_MODULE_BIND_LAZY;
790 module = g_module_open (filename, flags);
791 if (module == NULL) {
792 GST_CAT_WARNING (GST_CAT_PLUGIN_LOADING, "module_open failed: %s",
795 GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "Opening module failed: %s",
797 /* If we failed to open the shared object, then it's probably because a
798 * plugin is linked against the wrong libraries. Print out an easy-to-see
799 * message in this case. */
800 g_warning ("Failed to load plugin '%s': %s", filename, g_module_error ());
804 symname = extract_symname (filename);
805 ret = g_module_symbol (module, symname, &ptr);
808 GstPluginDesc *(*get_desc) (void) = ptr;
811 GST_DEBUG ("Could not find symbol '%s', falling back to gst_plugin_desc",
813 ret = g_module_symbol (module, "gst_plugin_desc", &ptr);
819 GST_DEBUG ("Could not find plugin entry point in \"%s\"", filename);
822 GST_PLUGIN_ERROR_MODULE,
823 "File \"%s\" is not a GStreamer plugin", filename);
824 g_module_close (module);
828 desc = (const GstPluginDesc *) ptr;
830 if (priv_gst_plugin_loading_have_whitelist () &&
831 !priv_gst_plugin_desc_is_whitelisted (desc, filename)) {
832 GST_INFO ("Whitelist specified and plugin not in whitelist, not loading: "
833 "name=%s, package=%s, file=%s", desc->name, desc->source, filename);
834 g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE,
835 "Not loading plugin file \"%s\", not in whitelist", filename);
836 g_module_close (module);
841 plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
842 plugin->file_mtime = file_status.st_mtime;
843 plugin->file_size = file_status.st_size;
844 plugin->filename = g_strdup (filename);
845 plugin->basename = g_path_get_basename (filename);
848 plugin->module = module;
851 /* check plugin description: complain about bad values and fail */
852 CHECK_PLUGIN_DESC_FIELD (desc, name, filename);
853 CHECK_PLUGIN_DESC_FIELD (desc, description, filename);
854 CHECK_PLUGIN_DESC_FIELD (desc, version, filename);
855 CHECK_PLUGIN_DESC_FIELD (desc, license, filename);
856 CHECK_PLUGIN_DESC_FIELD (desc, source, filename);
857 CHECK_PLUGIN_DESC_FIELD (desc, package, filename);
858 CHECK_PLUGIN_DESC_FIELD (desc, origin, filename);
860 if (desc->name != NULL && desc->name[0] == '"') {
861 g_warning ("Invalid plugin name '%s' - fix your GST_PLUGIN_DEFINE "
862 "(remove quotes around plugin name)", desc->name);
865 if (desc->release_datetime != NULL &&
866 !check_release_datetime (desc->release_datetime)) {
867 g_warning ("GstPluginDesc for '%s' has invalid datetime '%s'",
868 filename, desc->release_datetime);
869 g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE,
870 "Plugin %s has invalid plugin description field 'release_datetime'",
876 GST_LOG ("Plugin %p for file \"%s\" prepared, calling entry function...",
879 /* this is where we load the actual .so, so let's trap SIGSEGV */
880 _gst_plugin_fault_handler_setup ();
881 _gst_plugin_fault_handler_filename = plugin->filename;
883 GST_LOG ("Plugin %p for file \"%s\" prepared, registering...",
886 if (!gst_plugin_register_func (plugin, desc, NULL)) {
887 /* remove signal handler */
888 _gst_plugin_fault_handler_restore ();
889 GST_DEBUG ("gst_plugin_register_func failed for plugin \"%s\"", filename);
893 GST_PLUGIN_ERROR_MODULE,
894 "File \"%s\" appears to be a GStreamer plugin, but it failed to initialize",
899 /* remove signal handler */
900 _gst_plugin_fault_handler_restore ();
901 _gst_plugin_fault_handler_filename = NULL;
902 GST_INFO ("plugin \"%s\" loaded", plugin->filename);
905 gst_object_ref (plugin);
906 gst_registry_add_plugin (registry, plugin);
909 g_mutex_unlock (&gst_plugin_loading_mutex);
915 gst_object_unref (plugin);
916 g_mutex_unlock (&gst_plugin_loading_mutex);
922 gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src)
924 dest->major_version = src->major_version;
925 dest->minor_version = src->minor_version;
926 dest->name = g_intern_string (src->name);
927 dest->description = g_intern_string (src->description);
928 dest->plugin_init = src->plugin_init;
929 dest->version = g_intern_string (src->version);
930 dest->license = g_intern_string (src->license);
931 dest->source = g_intern_string (src->source);
932 dest->package = g_intern_string (src->package);
933 dest->origin = g_intern_string (src->origin);
934 dest->release_datetime = g_intern_string (src->release_datetime);
938 * gst_plugin_get_name:
939 * @plugin: plugin to get the name of
941 * Get the short name of the plugin
943 * Returns: the name of the plugin
946 gst_plugin_get_name (GstPlugin * plugin)
948 g_return_val_if_fail (plugin != NULL, NULL);
950 return plugin->desc.name;
954 * gst_plugin_get_description:
955 * @plugin: plugin to get long name of
957 * Get the long descriptive name of the plugin
959 * Returns: the long name of the plugin
962 gst_plugin_get_description (GstPlugin * plugin)
964 g_return_val_if_fail (plugin != NULL, NULL);
966 return plugin->desc.description;
970 * gst_plugin_get_filename:
971 * @plugin: plugin to get the filename of
973 * get the filename of the plugin
975 * Returns: (type filename): the filename of the plugin
978 gst_plugin_get_filename (GstPlugin * plugin)
980 g_return_val_if_fail (plugin != NULL, NULL);
982 return plugin->filename;
986 * gst_plugin_get_version:
987 * @plugin: plugin to get the version of
989 * get the version of the plugin
991 * Returns: the version of the plugin
994 gst_plugin_get_version (GstPlugin * plugin)
996 g_return_val_if_fail (plugin != NULL, NULL);
998 return plugin->desc.version;
1002 * gst_plugin_get_license:
1003 * @plugin: plugin to get the license of
1005 * get the license of the plugin
1007 * Returns: the license of the plugin
1010 gst_plugin_get_license (GstPlugin * plugin)
1012 g_return_val_if_fail (plugin != NULL, NULL);
1014 return plugin->desc.license;
1018 * gst_plugin_get_source:
1019 * @plugin: plugin to get the source of
1021 * get the source module the plugin belongs to.
1023 * Returns: the source of the plugin
1026 gst_plugin_get_source (GstPlugin * plugin)
1028 g_return_val_if_fail (plugin != NULL, NULL);
1030 return plugin->desc.source;
1034 * gst_plugin_get_package:
1035 * @plugin: plugin to get the package of
1037 * get the package the plugin belongs to.
1039 * Returns: the package of the plugin
1042 gst_plugin_get_package (GstPlugin * plugin)
1044 g_return_val_if_fail (plugin != NULL, NULL);
1046 return plugin->desc.package;
1050 * gst_plugin_get_origin:
1051 * @plugin: plugin to get the origin of
1053 * get the URL where the plugin comes from
1055 * Returns: the origin of the plugin
1058 gst_plugin_get_origin (GstPlugin * plugin)
1060 g_return_val_if_fail (plugin != NULL, NULL);
1062 return plugin->desc.origin;
1066 * gst_plugin_get_release_date_string:
1067 * @plugin: plugin to get the release date of
1069 * Get the release date (and possibly time) in form of a string, if available.
1071 * For normal GStreamer plugin releases this will usually just be a date in
1072 * the form of "YYYY-MM-DD", while pre-releases and builds from git may contain
1073 * a time component after the date as well, in which case the string will be
1074 * formatted like "YYYY-MM-DDTHH:MMZ" (e.g. "2012-04-30T09:30Z").
1076 * There may be plugins that do not have a valid release date set on them.
1078 * Returns: (nullable): the date string of the plugin, or %NULL if not
1082 gst_plugin_get_release_date_string (GstPlugin * plugin)
1084 g_return_val_if_fail (plugin != NULL, NULL);
1086 return plugin->desc.release_datetime;
1090 * gst_plugin_is_loaded:
1091 * @plugin: plugin to query
1093 * queries if the plugin is loaded into memory
1095 * Returns: %TRUE is loaded, %FALSE otherwise
1098 gst_plugin_is_loaded (GstPlugin * plugin)
1100 g_return_val_if_fail (plugin != NULL, FALSE);
1102 return (plugin->module != NULL || plugin->filename == NULL);
1106 * gst_plugin_get_cache_data:
1109 * Gets the plugin specific data cache. If it is %NULL there is no cached data
1110 * stored. This is the case when the registry is getting rebuilt.
1112 * Returns: (transfer none) (nullable): The cached data as a
1113 * #GstStructure or %NULL.
1115 const GstStructure *
1116 gst_plugin_get_cache_data (GstPlugin * plugin)
1118 g_return_val_if_fail (GST_IS_PLUGIN (plugin), NULL);
1120 return plugin->priv->cache_data;
1124 * gst_plugin_set_cache_data:
1126 * @cache_data: (transfer full): a structure containing the data to cache
1128 * Adds plugin specific data to cache. Passes the ownership of the structure to
1131 * The cache is flushed every time the registry is rebuilt.
1134 gst_plugin_set_cache_data (GstPlugin * plugin, GstStructure * cache_data)
1136 g_return_if_fail (GST_IS_PLUGIN (plugin));
1137 g_return_if_fail (GST_IS_STRUCTURE (cache_data));
1139 if (plugin->priv->cache_data) {
1140 gst_structure_free (plugin->priv->cache_data);
1142 plugin->priv->cache_data = cache_data;
1147 * gst_plugin_feature_list:
1148 * @plugin: plugin to query
1149 * @filter: the filter to use
1150 * @first: only return first match
1151 * @user_data: user data passed to the filter function
1153 * Runs a filter against all plugin features and returns a GList with
1154 * the results. If the first flag is set, only the first match is
1155 * returned (as a list with a single object).
1157 * Returns: a GList of features, g_list_free after use.
1160 gst_plugin_feature_filter (GstPlugin * plugin,
1161 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
1166 list = gst_filter_run (plugin->features, (GstFilterFunc) filter, first,
1168 for (g = list; g; g = g->next) {
1169 gst_object_ref (plugin);
1177 GstPluginFeatureFilter filter;
1185 _feature_filter (GstPlugin * plugin, gpointer user_data)
1188 FeatureFilterData *data = (FeatureFilterData *) user_data;
1190 result = gst_plugin_feature_filter (plugin, data->filter, data->first,
1193 data->result = g_list_concat (data->result, result);
1200 * gst_plugin_list_feature_filter:
1201 * @list: a #GList of plugins to query
1202 * @filter: the filter function to use
1203 * @first: only return first match
1204 * @user_data: user data passed to the filter function
1206 * Runs a filter against all plugin features of the plugins in the given
1207 * list and returns a GList with the results.
1208 * If the first flag is set, only the first match is
1209 * returned (as a list with a single object).
1211 * Returns: a GList of features, g_list_free after use.
1214 gst_plugin_list_feature_filter (GList * list,
1215 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
1217 FeatureFilterData data;
1220 data.filter = filter;
1222 data.user_data = user_data;
1225 result = gst_filter_run (list, (GstFilterFunc) _feature_filter, first, &data);
1226 g_list_free (result);
1232 * gst_plugin_find_feature:
1233 * @plugin: plugin to get the feature from
1234 * @name: The name of the feature to find
1235 * @type: The type of the feature to find
1237 * Find a feature of the given name and type in the given plugin.
1239 * Returns: a GstPluginFeature or %NULL if the feature was not found.
1242 gst_plugin_find_feature (GstPlugin * plugin, const gchar * name, GType type)
1245 GstPluginFeature *result = NULL;
1246 GstTypeNameData data;
1248 g_return_val_if_fail (name != NULL, NULL);
1253 walk = gst_filter_run (plugin->features,
1254 (GstFilterFunc) gst_plugin_feature_type_name_filter, TRUE, &data);
1257 result = GST_PLUGIN_FEATURE (walk->data);
1259 gst_object_ref (result);
1260 gst_plugin_feature_list_free (walk);
1269 gst_plugin_feature_name_filter (GstPluginFeature * feature, const gchar * name)
1271 return !strcmp (name, GST_PLUGIN_FEATURE_NAME (feature));
1277 * gst_plugin_find_feature_by_name:
1278 * @plugin: plugin to get the feature from
1279 * @name: The name of the feature to find
1281 * Find a feature of the given name in the given plugin.
1283 * Returns: a GstPluginFeature or %NULL if the feature was not found.
1286 gst_plugin_find_feature_by_name (GstPlugin * plugin, const gchar * name)
1289 GstPluginFeature *result = NULL;
1291 g_return_val_if_fail (name != NULL, NULL);
1293 walk = gst_filter_run (plugin->features,
1294 (GstFilterFunc) gst_plugin_feature_name_filter, TRUE, (void *) name);
1297 result = GST_PLUGIN_FEATURE (walk->data);
1299 gst_object_ref (result);
1300 gst_plugin_feature_list_free (walk);
1308 * gst_plugin_load_by_name:
1309 * @name: name of plugin to load
1311 * Load the named plugin. Refs the plugin.
1313 * Returns: (transfer full) (nullable): a reference to a loaded plugin, or
1317 gst_plugin_load_by_name (const gchar * name)
1319 GstPlugin *plugin, *newplugin;
1320 GError *error = NULL;
1322 GST_DEBUG ("looking up plugin %s in default registry", name);
1323 plugin = gst_registry_find_plugin (gst_registry_get (), name);
1325 GST_DEBUG ("loading plugin %s from file %s", name, plugin->filename);
1326 newplugin = gst_plugin_load_file (plugin->filename, &error);
1327 gst_object_unref (plugin);
1330 GST_WARNING ("load_plugin error: %s", error->message);
1331 g_error_free (error);
1334 /* newplugin was reffed by load_file */
1338 GST_DEBUG ("Could not find plugin %s in registry", name);
1344 * @plugin: (transfer none): plugin to load
1346 * Loads @plugin. Note that the *return value* is the loaded plugin; @plugin is
1347 * untouched. The normal use pattern of this function goes like this:
1350 * GstPlugin *loaded_plugin;
1351 * loaded_plugin = gst_plugin_load (plugin);
1352 * // presumably, we're no longer interested in the potentially-unloaded plugin
1353 * gst_object_unref (plugin);
1354 * plugin = loaded_plugin;
1357 * Returns: (transfer full) (nullable): a reference to a loaded plugin, or
1361 gst_plugin_load (GstPlugin * plugin)
1363 GError *error = NULL;
1364 GstPlugin *newplugin;
1366 if (gst_plugin_is_loaded (plugin)) {
1367 return gst_object_ref (plugin);
1370 if (!(newplugin = gst_plugin_load_file (plugin->filename, &error)))
1377 GST_WARNING ("load_plugin error: %s", error->message);
1378 g_error_free (error);
1384 * gst_plugin_list_free:
1385 * @list: (transfer full) (element-type Gst.Plugin): list of #GstPlugin
1387 * Unrefs each member of @list, then frees the list.
1390 gst_plugin_list_free (GList * list)
1394 for (g = list; g; g = g->next) {
1395 gst_object_unref (GST_PLUGIN_CAST (g->data));
1400 /* ===== plugin dependencies ===== */
1403 * ENV + xyz where ENV can contain multiple values separated by SEPARATOR
1404 * xyz may be "" (if ENV contains path to file rather than dir)
1405 * ENV + *xyz same as above, but xyz acts as suffix filter
1406 * ENV + xyz* same as above, but xyz acts as prefix filter (is this needed?)
1407 * ENV + *xyz* same as above, but xyz acts as strstr filter (is this needed?)
1409 * same as above, with additional paths hard-coded at compile-time:
1410 * - only check paths + ... if ENV is not set or yields not paths
1411 * - always check paths + ... in addition to ENV
1413 * When user specifies set of environment variables, he/she may also use e.g.
1414 * "HOME/.mystuff/plugins", and we'll expand the content of $HOME with the
1418 /* we store in registry:
1421 * - environment variables (array of strings)
1422 * - last hash of env variable contents (uint) (so we can avoid doing stats
1423 * if one of the env vars has changed; premature optimisation galore)
1424 * - hard-coded paths (array of strings)
1425 * - xyz filename/suffix/prefix strings (array of strings)
1427 * - last hash of file/dir stats (int)
1429 * (= struct GstPluginDep)
1433 gst_plugin_ext_dep_get_env_vars_hash (GstPlugin * plugin, GstPluginDep * dep)
1438 /* there's no deeper logic to what we do here; all we want to know (when
1439 * checking if the plugin needs to be rescanned) is whether the content of
1440 * one of the environment variables in the list is different from when it
1441 * was last scanned */
1443 for (e = dep->env_vars; e != NULL && *e != NULL; ++e) {
1447 /* order matters: "val",NULL needs to yield a different hash than
1448 * NULL,"val", so do a shift here whether the var is set or not */
1451 /* want environment variable at beginning of string */
1452 if (!g_ascii_isalnum (**e)) {
1453 GST_WARNING_OBJECT (plugin, "string prefix is not a valid environment "
1454 "variable string: %s", *e);
1458 /* user is allowed to specify e.g. "HOME/.pitivi/plugins" */
1459 g_strlcpy (env_var, *e, sizeof (env_var));
1460 g_strdelimit (env_var, "/\\", '\0');
1462 if ((val = g_getenv (env_var)))
1463 hash += g_str_hash (val);
1470 _priv_plugin_deps_env_vars_changed (GstPlugin * plugin)
1474 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1475 GstPluginDep *dep = l->data;
1477 if (dep->env_hash != gst_plugin_ext_dep_get_env_vars_hash (plugin, dep))
1485 gst_plugin_ext_dep_extract_env_vars_paths (GstPlugin * plugin,
1486 GstPluginDep * dep, GQueue * paths)
1490 for (evars = dep->env_vars; evars != NULL && *evars != NULL; ++evars) {
1494 /* want environment variable at beginning of string */
1495 if (!g_ascii_isalnum (**evars)) {
1496 GST_WARNING_OBJECT (plugin, "string prefix is not a valid environment "
1497 "variable string: %s", *evars);
1501 /* user is allowed to specify e.g. "HOME/.pitivi/plugins", which we want to
1502 * split into the env_var name component and the path component */
1503 components = g_strsplit_set (*evars, "/\\", 2);
1504 g_assert (components != NULL);
1506 e = g_getenv (components[0]);
1507 GST_LOG_OBJECT (plugin, "expanding %s = '%s' (path suffix: %s)",
1508 components[0], GST_STR_NULL (e), GST_STR_NULL (components[1]));
1510 if (components[1] != NULL) {
1511 g_strdelimit (components[1], "/\\", G_DIR_SEPARATOR);
1514 if (e != NULL && *e != '\0') {
1518 arr = g_strsplit (e, G_SEARCHPATH_SEPARATOR_S, -1);
1520 for (i = 0; arr != NULL && arr[i] != NULL; ++i) {
1523 if (!g_path_is_absolute (arr[i])) {
1524 GST_INFO_OBJECT (plugin, "ignoring environment variable content '%s'"
1525 ": either not an absolute path or not a path at all", arr[i]);
1529 if (components[1] != NULL) {
1530 full_path = g_build_filename (arr[i], components[1], NULL);
1532 full_path = g_strdup (arr[i]);
1535 if (!g_queue_find_custom (paths, full_path, (GCompareFunc) strcmp)) {
1536 GST_LOG_OBJECT (plugin, "path: '%s'", full_path);
1537 g_queue_push_tail (paths, full_path);
1540 GST_LOG_OBJECT (plugin, "path: '%s' (duplicate,ignoring)", full_path);
1548 g_strfreev (components);
1551 GST_LOG_OBJECT (plugin, "Extracted %d paths from environment", paths->length);
1555 gst_plugin_ext_dep_get_hash_from_stat_entry (GStatBuf * s)
1558 if (!(s->st_mode & (S_IFDIR | S_IFREG | S_IFBLK | S_IFCHR)))
1560 /* MSVC does not have S_IFBLK */
1561 if (!(s->st_mode & (S_IFDIR | S_IFREG | S_IFCHR)))
1565 /* completely random formula */
1566 return ((s->st_size << 3) + (s->st_mtime << 5)) ^ s->st_ctime;
1570 gst_plugin_ext_dep_direntry_matches (GstPlugin * plugin, const gchar * entry,
1571 const gchar ** filenames, GstPluginDependencyFlags flags)
1573 /* no filenames specified, match all entries for now (could probably
1574 * optimise by just taking the dir stat hash or so) */
1575 if (filenames == NULL || *filenames == NULL || **filenames == '\0')
1578 while (*filenames != NULL) {
1580 if (((flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX)) &&
1581 g_str_has_suffix (entry, *filenames)) {
1583 } else if (((flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_PREFIX)) &&
1584 g_str_has_prefix (entry, *filenames)) {
1586 /* else it's an exact match that's needed */
1587 } else if (strcmp (entry, *filenames) == 0) {
1590 GST_LOG ("%s does not match %s, flags=0x%04x", entry, *filenames, flags);
1597 gst_plugin_ext_dep_scan_dir_and_match_names (GstPlugin * plugin,
1598 const gchar * path, const gchar ** filenames,
1599 GstPluginDependencyFlags flags, int depth)
1602 gboolean recurse_dirs;
1607 recurse_dirs = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
1609 dir = g_dir_open (path, 0, &err);
1611 GST_DEBUG_OBJECT (plugin, "g_dir_open(%s) failed: %s", path, err->message);
1616 /* FIXME: we're assuming here that we always get the directory entries in
1617 * the same order, and not in a random order */
1618 while ((entry = g_dir_read_name (dir))) {
1619 gboolean have_match;
1625 gst_plugin_ext_dep_direntry_matches (plugin, entry, filenames, flags);
1627 /* avoid the stat if possible */
1628 if (!have_match && !recurse_dirs)
1631 full_path = g_build_filename (path, entry, NULL);
1632 if (g_stat (full_path, &s) < 0) {
1633 fhash = (guint) - 1;
1634 GST_LOG_OBJECT (plugin, "stat: %s (error: %s)", full_path,
1635 g_strerror (errno));
1636 } else if (have_match) {
1637 fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
1638 GST_LOG_OBJECT (plugin, "stat: %s (result: %u)", full_path, fhash);
1639 } else if ((s.st_mode & (S_IFDIR))) {
1640 fhash = gst_plugin_ext_dep_scan_dir_and_match_names (plugin, full_path,
1641 filenames, flags, depth + 1);
1643 /* it's not a name match, we want to recurse, but it's not a directory */
1648 hash = hash + fhash;
1657 gst_plugin_ext_dep_scan_path_with_filenames (GstPlugin * plugin,
1658 const gchar * path, const gchar ** filenames,
1659 GstPluginDependencyFlags flags)
1661 const gchar *empty_filenames[] = { "", NULL };
1662 gboolean recurse_into_dirs, partial_names = FALSE;
1665 /* to avoid special-casing below (FIXME?) */
1666 if (filenames == NULL || *filenames == NULL)
1667 filenames = empty_filenames;
1669 recurse_into_dirs = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
1671 if ((flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX) ||
1672 (flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_PREFIX))
1673 partial_names = TRUE;
1675 /* if we can construct the exact paths to check with the data we have, just
1676 * stat them one by one; this is more efficient than opening the directory
1677 * and going through each entry to see if it matches one of our filenames. */
1678 if (!recurse_into_dirs && !partial_names) {
1679 for (i = 0; filenames[i] != NULL; ++i) {
1684 full_path = g_build_filename (path, filenames[i], NULL);
1685 if (g_stat (full_path, &s) < 0) {
1686 fhash = (guint) - 1;
1687 GST_LOG_OBJECT (plugin, "stat: %s (error: %s)", full_path,
1688 g_strerror (errno));
1690 fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
1691 GST_LOG_OBJECT (plugin, "stat: %s (result: %08x)", full_path, fhash);
1697 hash = gst_plugin_ext_dep_scan_dir_and_match_names (plugin, path,
1698 filenames, flags, 0);
1705 gst_plugin_ext_dep_get_stat_hash (GstPlugin * plugin, GstPluginDep * dep)
1707 gboolean paths_are_default_only;
1708 gboolean paths_are_relative_to_exe;
1709 GQueue scan_paths = G_QUEUE_INIT;
1710 guint scan_hash = 0;
1713 GST_LOG_OBJECT (plugin, "start");
1715 paths_are_default_only =
1716 dep->flags & GST_PLUGIN_DEPENDENCY_FLAG_PATHS_ARE_DEFAULT_ONLY;
1717 paths_are_relative_to_exe =
1718 dep->flags & GST_PLUGIN_DEPENDENCY_FLAG_PATHS_ARE_RELATIVE_TO_EXE;
1720 gst_plugin_ext_dep_extract_env_vars_paths (plugin, dep, &scan_paths);
1722 if (g_queue_is_empty (&scan_paths) || !paths_are_default_only) {
1725 for (paths = dep->paths; paths != NULL && *paths != NULL; ++paths) {
1726 const gchar *path = *paths;
1729 if (paths_are_relative_to_exe && !g_path_is_absolute (path)) {
1732 if (!_gst_executable_path) {
1733 GST_FIXME_OBJECT (plugin,
1734 "Path dependency %s relative to executable path but could not retrieve executable path",
1738 appdir = g_path_get_dirname (_gst_executable_path);
1739 full_path = g_build_filename (appdir, path, NULL);
1742 full_path = g_strdup (path);
1745 if (!g_queue_find_custom (&scan_paths, full_path, (GCompareFunc) strcmp)) {
1746 GST_LOG_OBJECT (plugin, "path: '%s'", full_path);
1747 g_queue_push_tail (&scan_paths, full_path);
1749 GST_LOG_OBJECT (plugin, "path: '%s' (duplicate, ignoring)", full_path);
1755 while ((path = g_queue_pop_head (&scan_paths))) {
1756 scan_hash += gst_plugin_ext_dep_scan_path_with_filenames (plugin, path,
1757 (const gchar **) dep->names, dep->flags);
1761 GST_LOG_OBJECT (plugin, "done, scan_hash: %08x", scan_hash);
1766 _priv_plugin_deps_files_changed (GstPlugin * plugin)
1770 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1771 GstPluginDep *dep = l->data;
1773 if (dep->stat_hash != gst_plugin_ext_dep_get_stat_hash (plugin, dep))
1781 gst_plugin_ext_dep_free (GstPluginDep * dep)
1783 g_strfreev (dep->env_vars);
1784 g_strfreev (dep->paths);
1785 g_strfreev (dep->names);
1786 g_slice_free (GstPluginDep, dep);
1790 gst_plugin_ext_dep_strv_equal (gchar ** arr1, gchar ** arr2)
1794 if (arr1 == NULL || arr2 == NULL)
1796 for (; *arr1 != NULL && *arr2 != NULL; ++arr1, ++arr2) {
1797 if (strcmp (*arr1, *arr2) != 0)
1800 return (*arr1 == *arr2);
1804 gst_plugin_ext_dep_equals (GstPluginDep * dep, const gchar ** env_vars,
1805 const gchar ** paths, const gchar ** names, GstPluginDependencyFlags flags)
1807 if (dep->flags != flags)
1810 return gst_plugin_ext_dep_strv_equal (dep->env_vars, (gchar **) env_vars) &&
1811 gst_plugin_ext_dep_strv_equal (dep->paths, (gchar **) paths) &&
1812 gst_plugin_ext_dep_strv_equal (dep->names, (gchar **) names);
1816 * gst_plugin_add_dependency:
1817 * @plugin: a #GstPlugin
1818 * @env_vars: (allow-none) (array zero-terminated=1): %NULL-terminated array of environment variables affecting the
1819 * feature set of the plugin (e.g. an environment variable containing
1820 * paths where to look for additional modules/plugins of a library),
1821 * or %NULL. Environment variable names may be followed by a path component
1822 * which will be added to the content of the environment variable, e.g.
1823 * "HOME/.mystuff/plugins".
1824 * @paths: (allow-none) (array zero-terminated=1): %NULL-terminated array of directories/paths where dependent files
1826 * @names: (allow-none) (array zero-terminated=1): %NULL-terminated array of file names (or file name suffixes,
1827 * depending on @flags) to be used in combination with the paths from
1828 * @paths and/or the paths extracted from the environment variables in
1829 * @env_vars, or %NULL.
1830 * @flags: optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
1832 * Make GStreamer aware of external dependencies which affect the feature
1833 * set of this plugin (ie. the elements or typefinders associated with it).
1835 * GStreamer will re-inspect plugins with external dependencies whenever any
1836 * of the external dependencies change. This is useful for plugins which wrap
1837 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
1838 * library and makes visualisations available as GStreamer elements, or a
1839 * codec loader which exposes elements and/or caps dependent on what external
1840 * codec libraries are currently installed.
1843 gst_plugin_add_dependency (GstPlugin * plugin, const gchar ** env_vars,
1844 const gchar ** paths, const gchar ** names, GstPluginDependencyFlags flags)
1849 g_return_if_fail (GST_IS_PLUGIN (plugin));
1851 if ((env_vars == NULL || env_vars[0] == NULL) &&
1852 (paths == NULL || paths[0] == NULL)) {
1853 GST_DEBUG_OBJECT (plugin,
1854 "plugin registered empty dependency set. Ignoring");
1858 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1859 if (gst_plugin_ext_dep_equals (l->data, env_vars, paths, names, flags)) {
1860 GST_LOG_OBJECT (plugin, "dependency already registered");
1865 dep = g_slice_new (GstPluginDep);
1867 dep->env_vars = g_strdupv ((gchar **) env_vars);
1868 dep->paths = g_strdupv ((gchar **) paths);
1869 dep->names = g_strdupv ((gchar **) names);
1872 dep->env_hash = gst_plugin_ext_dep_get_env_vars_hash (plugin, dep);
1873 dep->stat_hash = gst_plugin_ext_dep_get_stat_hash (plugin, dep);
1875 plugin->priv->deps = g_list_append (plugin->priv->deps, dep);
1877 GST_DEBUG_OBJECT (plugin, "added dependency:");
1878 for (; env_vars != NULL && *env_vars != NULL; ++env_vars)
1879 GST_DEBUG_OBJECT (plugin, " evar: %s", *env_vars);
1880 for (; paths != NULL && *paths != NULL; ++paths)
1881 GST_DEBUG_OBJECT (plugin, " path: %s", *paths);
1882 for (; names != NULL && *names != NULL; ++names)
1883 GST_DEBUG_OBJECT (plugin, " name: %s", *names);
1887 * gst_plugin_add_dependency_simple:
1888 * @plugin: the #GstPlugin
1889 * @env_vars: (allow-none): one or more environment variables (separated by ':', ';' or ','),
1890 * or %NULL. Environment variable names may be followed by a path component
1891 * which will be added to the content of the environment variable, e.g.
1892 * "HOME/.mystuff/plugins:MYSTUFF_PLUGINS_PATH"
1893 * @paths: (allow-none): one ore more directory paths (separated by ':' or ';' or ','),
1894 * or %NULL. Example: "/usr/lib/mystuff/plugins"
1895 * @names: (allow-none): one or more file names or file name suffixes (separated by commas),
1897 * @flags: optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
1899 * Make GStreamer aware of external dependencies which affect the feature
1900 * set of this plugin (ie. the elements or typefinders associated with it).
1902 * GStreamer will re-inspect plugins with external dependencies whenever any
1903 * of the external dependencies change. This is useful for plugins which wrap
1904 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
1905 * library and makes visualisations available as GStreamer elements, or a
1906 * codec loader which exposes elements and/or caps dependent on what external
1907 * codec libraries are currently installed.
1909 * Convenience wrapper function for gst_plugin_add_dependency() which
1910 * takes simple strings as arguments instead of string arrays, with multiple
1911 * arguments separated by predefined delimiters (see above).
1914 gst_plugin_add_dependency_simple (GstPlugin * plugin,
1915 const gchar * env_vars, const gchar * paths, const gchar * names,
1916 GstPluginDependencyFlags flags)
1918 gchar **a_evars = NULL;
1919 gchar **a_paths = NULL;
1920 gchar **a_names = NULL;
1923 a_evars = g_strsplit_set (env_vars, ":;,", -1);
1925 a_paths = g_strsplit_set (paths, ":;,", -1);
1927 a_names = g_strsplit_set (names, ",", -1);
1929 gst_plugin_add_dependency (plugin, (const gchar **) a_evars,
1930 (const gchar **) a_paths, (const gchar **) a_names, flags);
1933 g_strfreev (a_evars);
1935 g_strfreev (a_paths);
1937 g_strfreev (a_names);