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., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 * @short_description: Container for features loaded from a shared object module
26 * @see_also: #GstPluginFeature, #GstElementFactory
28 * GStreamer is extensible, so #GstElement instances can be loaded at runtime.
29 * A plugin system can provide one or more of the basic
30 * <application>GStreamer</application> #GstPluginFeature subclasses.
32 * A plugin should export a symbol <symbol>gst_plugin_desc</symbol> that is a
33 * struct of type #GstPluginDesc.
34 * the plugin loader will check the version of the core library the plugin was
35 * linked against and will create a new #GstPlugin. It will then call the
36 * #GstPluginInitFunc function that was provided in the
37 * <symbol>gst_plugin_desc</symbol>.
39 * Once you have a handle to a #GstPlugin (e.g. from the #GstRegistry), you
40 * can add any object that subclasses #GstPluginFeature.
42 * Usually plugins are always automaticlly loaded so you don't need to call
43 * gst_plugin_load() explicitly to bring it into memory. There are options to
44 * statically link plugins to an app or even use GStreamer without a plugin
45 * repository in which case gst_plugin_load() can be needed to bring the plugin
53 #include "gst_private.h"
55 #include <glib/gstdio.h>
56 #include <sys/types.h>
67 #include "glib-compat-private.h"
71 #define GST_CAT_DEFAULT GST_CAT_PLUGIN_LOADING
73 static guint _num_static_plugins; /* 0 */
74 static GstPluginDesc *_static_plugins; /* NULL */
75 static gboolean _gst_plugin_inited;
76 static gchar **_plugin_loading_whitelist; /* NULL */
78 /* static variables for segfault handling of plugin loading */
79 static char *_gst_plugin_fault_handler_filename = NULL;
81 /* list of valid licenses.
82 * One of these must be specified or the plugin won't be loaded
83 * Contact gstreamer-devel@lists.sourceforge.net if your license should be
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: http://www.opensource.org/licenses/bsd-license.php
93 static const gchar *valid_licenses[] = {
94 "LGPL", /* GNU Lesser General Public License */
95 "GPL", /* GNU General Public License */
96 "QPL", /* Trolltech Qt Public License */
97 "GPL/QPL", /* Combi-license of GPL + QPL */
98 "MPL", /* MPL 1.1 license */
99 "BSD", /* 3-clause BSD license */
100 "MIT/X11", /* MIT/X11 license */
101 "Proprietary", /* Proprietary license */
102 GST_LICENSE_UNKNOWN, /* some other license */
106 static GstPlugin *gst_plugin_register_func (GstPlugin * plugin,
107 const GstPluginDesc * desc, gpointer user_data);
108 static void gst_plugin_desc_copy (GstPluginDesc * dest,
109 const GstPluginDesc * src);
111 static void gst_plugin_ext_dep_free (GstPluginDep * dep);
113 G_DEFINE_TYPE (GstPlugin, gst_plugin, GST_TYPE_OBJECT);
116 gst_plugin_init (GstPlugin * plugin)
119 G_TYPE_INSTANCE_GET_PRIVATE (plugin, GST_TYPE_PLUGIN, GstPluginPrivate);
123 gst_plugin_finalize (GObject * object)
125 GstPlugin *plugin = GST_PLUGIN_CAST (object);
126 GstRegistry *registry = gst_registry_get_default ();
129 GST_DEBUG ("finalizing plugin %" GST_PTR_FORMAT, plugin);
130 for (g = registry->plugins; g; g = g->next) {
131 if (g->data == (gpointer) plugin) {
132 g_warning ("removing plugin that is still in registry");
135 g_free (plugin->filename);
136 g_free (plugin->basename);
138 g_list_foreach (plugin->priv->deps, (GFunc) gst_plugin_ext_dep_free, NULL);
139 g_list_free (plugin->priv->deps);
140 plugin->priv->deps = NULL;
142 if (plugin->priv->cache_data) {
143 gst_structure_free (plugin->priv->cache_data);
146 G_OBJECT_CLASS (gst_plugin_parent_class)->finalize (object);
150 gst_plugin_class_init (GstPluginClass * klass)
152 G_OBJECT_CLASS (klass)->finalize = gst_plugin_finalize;
154 g_type_class_add_private (klass, sizeof (GstPluginPrivate));
158 gst_plugin_error_quark (void)
160 static GQuark quark = 0;
163 quark = g_quark_from_static_string ("gst_plugin_error");
167 #ifndef GST_REMOVE_DEPRECATED
168 #ifdef GST_DISABLE_DEPRECATED
169 void _gst_plugin_register_static (GstPluginDesc * desc);
171 /* this function can be called in the GCC constructor extension, before
172 * the _gst_plugin_initialize() was called. In that case, we store the
173 * plugin description in a list to initialize it when we open the main
175 * When the main module is known, we can register the plugin right away.
178 _gst_plugin_register_static (GstPluginDesc * desc)
180 g_return_if_fail (desc != NULL);
182 if (!_gst_plugin_inited) {
183 /* We can't use any GLib functions here, since g_thread_init hasn't been
184 * called yet, and we can't call it here either, or programs that don't
185 * guard their g_thread_init calls in main() will just abort */
186 ++_num_static_plugins;
188 realloc (_static_plugins, _num_static_plugins * sizeof (GstPluginDesc));
189 /* assume strings in the GstPluginDesc are static const or live forever */
190 _static_plugins[_num_static_plugins - 1] = *desc;
192 gst_plugin_register_static (desc->major_version, desc->minor_version,
193 desc->name, desc->description, desc->plugin_init, desc->version,
194 desc->license, desc->source, desc->package, desc->origin);
200 * gst_plugin_register_static:
201 * @major_version: the major version number of the GStreamer core that the
202 * plugin was compiled for, you can just use GST_VERSION_MAJOR here
203 * @minor_version: the minor version number of the GStreamer core that the
204 * plugin was compiled for, you can just use GST_VERSION_MINOR here
205 * @name: a unique name of the plugin (ideally prefixed with an application- or
206 * library-specific namespace prefix in order to avoid name conflicts in
207 * case a similar plugin with the same name ever gets added to GStreamer)
208 * @description: description of the plugin
209 * @init_func: (scope call): pointer to the init function of this plugin.
210 * @version: version string of the plugin
211 * @license: effective license of plugin. Must be one of the approved licenses
212 * (see #GstPluginDesc above) or the plugin will not be registered.
213 * @source: source module plugin belongs to
214 * @package: shipped package plugin belongs to
215 * @origin: URL to provider of plugin
217 * Registers a static plugin, ie. a plugin which is private to an application
218 * or library and contained within the application or library (as opposed to
219 * being shipped as a separate module file).
221 * You must make sure that GStreamer has been initialised (with gst_init() or
222 * via gst_init_get_option_group()) before calling this function.
224 * Returns: TRUE if the plugin was registered correctly, otherwise FALSE.
229 gst_plugin_register_static (gint major_version, gint minor_version,
230 const gchar * name, const gchar * description, GstPluginInitFunc init_func,
231 const gchar * version, const gchar * license, const gchar * source,
232 const gchar * package, const gchar * origin)
234 GstPluginDesc desc = { major_version, minor_version, name, description,
235 init_func, version, license, source, package, origin, NULL,
238 gboolean res = FALSE;
240 g_return_val_if_fail (name != NULL, FALSE);
241 g_return_val_if_fail (description != NULL, FALSE);
242 g_return_val_if_fail (init_func != NULL, FALSE);
243 g_return_val_if_fail (version != NULL, FALSE);
244 g_return_val_if_fail (license != NULL, FALSE);
245 g_return_val_if_fail (source != NULL, FALSE);
246 g_return_val_if_fail (package != NULL, FALSE);
247 g_return_val_if_fail (origin != NULL, FALSE);
249 /* make sure gst_init() has been called */
250 g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
252 GST_LOG ("attempting to load static plugin \"%s\" now...", name);
253 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
254 if (gst_plugin_register_func (plugin, &desc, NULL) != NULL) {
255 GST_INFO ("registered static plugin \"%s\"", name);
256 res = gst_default_registry_add_plugin (plugin);
257 GST_INFO ("added static plugin \"%s\", result: %d", name, res);
263 * gst_plugin_register_static_full:
264 * @major_version: the major version number of the GStreamer core that the
265 * plugin was compiled for, you can just use GST_VERSION_MAJOR here
266 * @minor_version: the minor version number of the GStreamer core that the
267 * plugin was compiled for, you can just use GST_VERSION_MINOR here
268 * @name: a unique name of the plugin (ideally prefixed with an application- or
269 * library-specific namespace prefix in order to avoid name conflicts in
270 * case a similar plugin with the same name ever gets added to GStreamer)
271 * @description: description of the plugin
272 * @init_full_func: (scope call): pointer to the init function with user data
274 * @version: version string of the plugin
275 * @license: effective license of plugin. Must be one of the approved licenses
276 * (see #GstPluginDesc above) or the plugin will not be registered.
277 * @source: source module plugin belongs to
278 * @package: shipped package plugin belongs to
279 * @origin: URL to provider of plugin
280 * @user_data: gpointer to user data
282 * Registers a static plugin, ie. a plugin which is private to an application
283 * or library and contained within the application or library (as opposed to
284 * being shipped as a separate module file) with a #GstPluginInitFullFunc
285 * which allows user data to be passed to the callback function (useful
288 * You must make sure that GStreamer has been initialised (with gst_init() or
289 * via gst_init_get_option_group()) before calling this function.
291 * Returns: TRUE if the plugin was registered correctly, otherwise FALSE.
297 gst_plugin_register_static_full (gint major_version, gint minor_version,
298 const gchar * name, const gchar * description,
299 GstPluginInitFullFunc init_full_func, const gchar * version,
300 const gchar * license, const gchar * source, const gchar * package,
301 const gchar * origin, gpointer user_data)
303 GstPluginDesc desc = { major_version, minor_version, name, description,
304 (GstPluginInitFunc) init_full_func, version, license, source, package,
308 gboolean res = FALSE;
310 g_return_val_if_fail (name != NULL, FALSE);
311 g_return_val_if_fail (description != NULL, FALSE);
312 g_return_val_if_fail (init_full_func != NULL, FALSE);
313 g_return_val_if_fail (version != NULL, FALSE);
314 g_return_val_if_fail (license != NULL, FALSE);
315 g_return_val_if_fail (source != NULL, FALSE);
316 g_return_val_if_fail (package != NULL, FALSE);
317 g_return_val_if_fail (origin != NULL, FALSE);
319 /* make sure gst_init() has been called */
320 g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
322 GST_LOG ("attempting to load static plugin \"%s\" now...", name);
323 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
324 if (gst_plugin_register_func (plugin, &desc, user_data) != NULL) {
325 GST_INFO ("registered static plugin \"%s\"", name);
326 res = gst_default_registry_add_plugin (plugin);
327 GST_INFO ("added static plugin \"%s\", result: %d", name, res);
333 _gst_plugin_initialize (void)
335 const gchar *whitelist;
338 _gst_plugin_inited = TRUE;
340 whitelist = g_getenv ("GST_PLUGIN_LOADING_WHITELIST");
341 if (whitelist != NULL && *whitelist != '\0') {
342 _plugin_loading_whitelist = g_strsplit (whitelist,
343 G_SEARCHPATH_SEPARATOR_S, -1);
344 for (i = 0; _plugin_loading_whitelist[i] != NULL; ++i) {
345 GST_INFO ("plugins whitelist entry: %s", _plugin_loading_whitelist[i]);
349 /* now register all static plugins */
350 GST_INFO ("registering %u static plugins", _num_static_plugins);
351 for (i = 0; i < _num_static_plugins; ++i) {
352 gst_plugin_register_static (_static_plugins[i].major_version,
353 _static_plugins[i].minor_version, _static_plugins[i].name,
354 _static_plugins[i].description, _static_plugins[i].plugin_init,
355 _static_plugins[i].version, _static_plugins[i].license,
356 _static_plugins[i].source, _static_plugins[i].package,
357 _static_plugins[i].origin);
360 if (_static_plugins) {
361 free (_static_plugins);
362 _static_plugins = NULL;
363 _num_static_plugins = 0;
367 /* Whitelist entry format:
369 * plugin1,plugin2@pathprefix or
370 * plugin1,plugin2@* or just
372 * source-package@pathprefix or
373 * source-package@* or just
376 * ie. the bit before the path will be checked against both the plugin
377 * name and the plugin's source package name, to keep the format simple.
380 gst_plugin_desc_matches_whitelist_entry (GstPluginDesc * desc,
381 const gchar * filename, const gchar * pattern)
384 gboolean ret = FALSE;
387 GST_LOG ("Whitelist pattern '%s', plugin: %s of %s@%s", pattern, desc->name,
388 desc->source, GST_STR_NULL (filename));
390 /* do we have a path prefix? */
391 sep = strchr (pattern, '@');
392 if (sep != NULL && strcmp (sep, "@*") != 0 && strcmp (sep, "@") != 0) {
393 /* paths are not canonicalised or treated with realpath() here. This
394 * should be good enough for our use case, since we just use the paths
395 * autotools uses, and those will be constructed from the same prefix. */
396 if (filename != NULL && !g_str_has_prefix (filename, sep + 1))
399 GST_LOG ("%s matches path prefix %s", GST_STR_NULL (filename), sep + 1);
403 name = g_strndup (pattern, (gsize) (sep - pattern));
405 name = g_strdup (pattern);
409 if (!g_ascii_isalnum (*name)) {
410 GST_WARNING ("Invalid whitelist pattern: %s", pattern);
414 /* now check plugin names / source package name */
415 if (strchr (name, ',') == NULL) {
416 /* only a single name: either a plugin name or the source package name */
417 ret = (strcmp (desc->source, name) == 0 || strcmp (desc->name, name) == 0);
421 /* multiple names: assume these are plugin names */
422 names = g_strsplit (name, ",", -1);
423 for (n = names; n != NULL && *n != NULL; ++n) {
425 if (strcmp (desc->name, *n) == 0) {
433 GST_LOG ("plugin / source package name match: %d", ret);
442 priv_gst_plugin_desc_is_whitelisted (GstPluginDesc * desc,
443 const gchar * filename)
447 if (_plugin_loading_whitelist == NULL)
450 for (entry = _plugin_loading_whitelist; *entry != NULL; ++entry) {
451 if (gst_plugin_desc_matches_whitelist_entry (desc, filename, *entry)) {
452 GST_LOG ("Plugin %s is in whitelist", filename);
457 GST_LOG ("Plugin %s (package %s, file %s) not in whitelist", desc->name,
458 desc->source, filename);
463 priv_gst_plugin_loading_have_whitelist (void)
465 return (_plugin_loading_whitelist != NULL);
469 priv_gst_plugin_loading_get_whitelist_hash (void)
473 if (_plugin_loading_whitelist != NULL) {
476 for (w = _plugin_loading_whitelist; *w != NULL; ++w)
477 hash = (hash << 1) ^ g_str_hash (*w);
483 /* this function could be extended to check if the plugin license matches the
484 * applications license (would require the app to register its license somehow).
485 * We'll wait for someone who's interested in it to code it :)
488 gst_plugin_check_license (const gchar * license)
490 const gchar **check_license = valid_licenses;
492 g_assert (check_license);
494 while (*check_license) {
495 if (strcmp (license, *check_license) == 0)
503 gst_plugin_check_version (gint major, gint minor)
505 /* return NULL if the major and minor version numbers are not compatible */
507 if (major != GST_VERSION_MAJOR || minor != GST_VERSION_MINOR)
514 gst_plugin_register_func (GstPlugin * plugin, const GstPluginDesc * desc,
517 if (!gst_plugin_check_version (desc->major_version, desc->minor_version)) {
519 GST_WARNING ("plugin \"%s\" has incompatible version, not loading",
524 if (!desc->license || !desc->description || !desc->source ||
525 !desc->package || !desc->origin) {
527 GST_WARNING ("plugin \"%s\" has incorrect GstPluginDesc, not loading",
532 if (!gst_plugin_check_license (desc->license)) {
534 GST_WARNING ("plugin \"%s\" has invalid license \"%s\", not loading",
535 plugin->filename, desc->license);
540 GST_LOG ("plugin \"%s\" looks good", GST_STR_NULL (plugin->filename));
542 gst_plugin_desc_copy (&plugin->desc, desc);
544 /* make resident so we're really sure it never gets unloaded again.
545 * Theoretically this is not needed, but practically it doesn't hurt.
546 * And we're rather safe than sorry. */
548 g_module_make_resident (plugin->module);
551 if (!(((GstPluginInitFullFunc) (desc->plugin_init)) (plugin, user_data))) {
553 GST_WARNING ("plugin \"%s\" failed to initialise", plugin->filename);
557 if (!((desc->plugin_init) (plugin))) {
559 GST_WARNING ("plugin \"%s\" failed to initialise", plugin->filename);
565 GST_LOG ("plugin \"%s\" initialised", GST_STR_NULL (plugin->filename));
570 #ifdef HAVE_SIGACTION
571 static struct sigaction oldaction;
572 static gboolean _gst_plugin_fault_handler_is_setup = FALSE;
575 * _gst_plugin_fault_handler_restore:
576 * segfault handler restorer
579 _gst_plugin_fault_handler_restore (void)
581 if (!_gst_plugin_fault_handler_is_setup)
584 _gst_plugin_fault_handler_is_setup = FALSE;
586 sigaction (SIGSEGV, &oldaction, NULL);
590 * _gst_plugin_fault_handler_sighandler:
591 * segfault handler implementation
594 _gst_plugin_fault_handler_sighandler (int signum)
596 /* We need to restore the fault handler or we'll keep getting it */
597 _gst_plugin_fault_handler_restore ();
601 g_print ("\nERROR: ");
602 g_print ("Caught a segmentation fault while loading plugin file:\n");
603 g_print ("%s\n\n", _gst_plugin_fault_handler_filename);
604 g_print ("Please either:\n");
605 g_print ("- remove it and restart.\n");
607 ("- run with --gst-disable-segtrap --gst-disable-registry-fork and debug.\n");
611 g_print ("Caught unhandled signal on plugin loading\n");
617 * _gst_plugin_fault_handler_setup:
618 * sets up the segfault handler
621 _gst_plugin_fault_handler_setup (void)
623 struct sigaction action;
625 /* if asked to leave segfaults alone, just return */
626 if (!gst_segtrap_is_enabled ())
629 if (_gst_plugin_fault_handler_is_setup)
632 _gst_plugin_fault_handler_is_setup = TRUE;
634 memset (&action, 0, sizeof (action));
635 action.sa_handler = _gst_plugin_fault_handler_sighandler;
637 sigaction (SIGSEGV, &action, &oldaction);
639 #else /* !HAVE_SIGACTION */
641 _gst_plugin_fault_handler_restore (void)
646 _gst_plugin_fault_handler_setup (void)
649 #endif /* HAVE_SIGACTION */
651 /* g_time_val_from_iso8601() doesn't do quite what we want */
653 check_release_datetime (const gchar * date_time)
657 /* we require YYYY-MM-DD or YYYY-MM-DDTHH:MMZ format */
658 if (!g_ascii_isdigit (*date_time))
661 val = g_ascii_strtoull (date_time, (gchar **) & date_time, 10);
662 if (val < 2000 || val > 2100 || *date_time != '-')
665 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
666 if (val == 0 || val > 12 || *date_time != '-')
669 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
670 if (val == 0 || val > 32)
673 /* end of string or date/time separator + HH:MMZ */
674 if (*date_time == 'T' || *date_time == ' ') {
675 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
676 if (val > 24 || *date_time != ':')
679 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
680 if (val > 59 || *date_time != 'Z')
686 return (*date_time == '\0');
689 static GStaticMutex gst_plugin_loading_mutex = G_STATIC_MUTEX_INIT;
691 #define CHECK_PLUGIN_DESC_FIELD(desc,field,fn) \
692 if (G_UNLIKELY ((desc)->field == NULL)) { \
693 GST_ERROR ("GstPluginDesc for '%s' has no %s", fn, G_STRINGIFY (field)); \
697 * gst_plugin_load_file:
698 * @filename: the plugin filename to load
699 * @error: pointer to a NULL-valued GError
701 * Loads the given plugin and refs it. Caller needs to unref after use.
703 * Returns: (transfer full): a reference to the existing loaded GstPlugin, a
704 * reference to the newly-loaded GstPlugin, or NULL if an error occurred.
707 gst_plugin_load_file (const gchar * filename, GError ** error)
714 GStatBuf file_status;
715 GstRegistry *registry;
716 gboolean new_plugin = TRUE;
719 g_return_val_if_fail (filename != NULL, NULL);
721 registry = gst_registry_get_default ();
722 g_static_mutex_lock (&gst_plugin_loading_mutex);
724 plugin = gst_registry_lookup (registry, filename);
726 if (plugin->module) {
728 g_static_mutex_unlock (&gst_plugin_loading_mutex);
731 /* load plugin and update fields */
736 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "attempt to load plugin \"%s\"",
739 if (g_module_supported () == FALSE) {
740 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "module loading not supported");
743 GST_PLUGIN_ERROR_MODULE, "Dynamic loading not supported");
747 if (g_stat (filename, &file_status)) {
748 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "problem accessing file");
751 GST_PLUGIN_ERROR_MODULE, "Problem accessing file %s: %s", filename,
756 flags = G_MODULE_BIND_LOCAL;
757 /* libgstpython.so is the gst-python plugin loader. It needs to be loaded with
758 * G_MODULE_BIND_LAZY.
760 * Ideally there should be a generic way for plugins to specify that they
761 * need to be loaded with _LAZY.
763 if (strstr (filename, "libgstpython"))
764 flags |= G_MODULE_BIND_LAZY;
766 module = g_module_open (filename, flags);
767 if (module == NULL) {
768 GST_CAT_WARNING (GST_CAT_PLUGIN_LOADING, "module_open failed: %s",
771 GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "Opening module failed: %s",
773 /* If we failed to open the shared object, then it's probably because a
774 * plugin is linked against the wrong libraries. Print out an easy-to-see
775 * message in this case. */
776 g_warning ("Failed to load plugin '%s': %s", filename, g_module_error ());
780 ret = g_module_symbol (module, "gst_plugin_desc", &ptr);
782 GST_DEBUG ("Could not find plugin entry point in \"%s\"", filename);
785 GST_PLUGIN_ERROR_MODULE,
786 "File \"%s\" is not a GStreamer plugin", filename);
787 g_module_close (module);
791 desc = (GstPluginDesc *) ptr;
793 if (priv_gst_plugin_loading_have_whitelist () &&
794 !priv_gst_plugin_desc_is_whitelisted (desc, filename)) {
795 GST_INFO ("Whitelist specified and plugin not in whitelist, not loading: "
796 "name=%s, package=%s, file=%s", desc->name, desc->source, filename);
797 g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE,
798 "Not loading plugin file \"%s\", not in whitelist", filename);
799 g_module_close (module);
804 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
805 plugin->file_mtime = file_status.st_mtime;
806 plugin->file_size = file_status.st_size;
807 plugin->filename = g_strdup (filename);
808 plugin->basename = g_path_get_basename (filename);
811 plugin->module = module;
812 plugin->orig_desc = desc;
815 /* check plugin description: complain about bad values but accept them, to
816 * maintain backwards compatibility (FIXME: 0.11) */
817 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, name, filename);
818 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, description, filename);
819 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, version, filename);
820 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, license, filename);
821 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, source, filename);
822 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, package, filename);
823 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, origin, filename);
825 if (plugin->orig_desc->release_datetime != NULL &&
826 !check_release_datetime (plugin->orig_desc->release_datetime)) {
827 GST_ERROR ("GstPluginDesc for '%s' has invalid datetime '%s'",
828 filename, plugin->orig_desc->release_datetime);
829 plugin->orig_desc->release_datetime = NULL;
833 GST_LOG ("Plugin %p for file \"%s\" prepared, calling entry function...",
836 /* this is where we load the actual .so, so let's trap SIGSEGV */
837 _gst_plugin_fault_handler_setup ();
838 _gst_plugin_fault_handler_filename = plugin->filename;
840 GST_LOG ("Plugin %p for file \"%s\" prepared, registering...",
843 if (!gst_plugin_register_func (plugin, plugin->orig_desc, NULL)) {
844 /* remove signal handler */
845 _gst_plugin_fault_handler_restore ();
846 GST_DEBUG ("gst_plugin_register_func failed for plugin \"%s\"", filename);
850 GST_PLUGIN_ERROR_MODULE,
851 "File \"%s\" appears to be a GStreamer plugin, but it failed to initialize",
856 /* remove signal handler */
857 _gst_plugin_fault_handler_restore ();
858 _gst_plugin_fault_handler_filename = NULL;
859 GST_INFO ("plugin \"%s\" loaded", plugin->filename);
862 gst_object_ref (plugin);
863 gst_default_registry_add_plugin (plugin);
866 g_static_mutex_unlock (&gst_plugin_loading_mutex);
872 gst_object_unref (plugin);
873 g_static_mutex_unlock (&gst_plugin_loading_mutex);
879 gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src)
881 dest->major_version = src->major_version;
882 dest->minor_version = src->minor_version;
883 dest->name = g_intern_string (src->name);
884 dest->description = g_intern_string (src->description);
885 dest->plugin_init = src->plugin_init;
886 dest->version = g_intern_string (src->version);
887 dest->license = g_intern_string (src->license);
888 dest->source = g_intern_string (src->source);
889 dest->package = g_intern_string (src->package);
890 dest->origin = g_intern_string (src->origin);
891 dest->release_datetime = g_intern_string (src->release_datetime);
895 * gst_plugin_get_name:
896 * @plugin: plugin to get the name of
898 * Get the short name of the plugin
900 * Returns: the name of the plugin
903 gst_plugin_get_name (GstPlugin * plugin)
905 g_return_val_if_fail (plugin != NULL, NULL);
907 return plugin->desc.name;
911 * gst_plugin_get_description:
912 * @plugin: plugin to get long name of
914 * Get the long descriptive name of the plugin
916 * Returns: the long name of the plugin
919 gst_plugin_get_description (GstPlugin * plugin)
921 g_return_val_if_fail (plugin != NULL, NULL);
923 return plugin->desc.description;
927 * gst_plugin_get_filename:
928 * @plugin: plugin to get the filename of
930 * get the filename of the plugin
932 * Returns: the filename of the plugin
935 gst_plugin_get_filename (GstPlugin * plugin)
937 g_return_val_if_fail (plugin != NULL, NULL);
939 return plugin->filename;
943 * gst_plugin_get_version:
944 * @plugin: plugin to get the version of
946 * get the version of the plugin
948 * Returns: the version of the plugin
951 gst_plugin_get_version (GstPlugin * plugin)
953 g_return_val_if_fail (plugin != NULL, NULL);
955 return plugin->desc.version;
959 * gst_plugin_get_license:
960 * @plugin: plugin to get the license of
962 * get the license of the plugin
964 * Returns: the license of the plugin
967 gst_plugin_get_license (GstPlugin * plugin)
969 g_return_val_if_fail (plugin != NULL, NULL);
971 return plugin->desc.license;
975 * gst_plugin_get_source:
976 * @plugin: plugin to get the source of
978 * get the source module the plugin belongs to.
980 * Returns: the source of the plugin
983 gst_plugin_get_source (GstPlugin * plugin)
985 g_return_val_if_fail (plugin != NULL, NULL);
987 return plugin->desc.source;
991 * gst_plugin_get_package:
992 * @plugin: plugin to get the package of
994 * get the package the plugin belongs to.
996 * Returns: the package of the plugin
999 gst_plugin_get_package (GstPlugin * plugin)
1001 g_return_val_if_fail (plugin != NULL, NULL);
1003 return plugin->desc.package;
1007 * gst_plugin_get_origin:
1008 * @plugin: plugin to get the origin of
1010 * get the URL where the plugin comes from
1012 * Returns: the origin of the plugin
1015 gst_plugin_get_origin (GstPlugin * plugin)
1017 g_return_val_if_fail (plugin != NULL, NULL);
1019 return plugin->desc.origin;
1023 * gst_plugin_get_module:
1024 * @plugin: plugin to query
1026 * Gets the #GModule of the plugin. If the plugin isn't loaded yet, NULL is
1029 * Returns: (transfer none): module belonging to the plugin or NULL if the
1030 * plugin isn't loaded yet.
1033 gst_plugin_get_module (GstPlugin * plugin)
1035 g_return_val_if_fail (plugin != NULL, NULL);
1037 return plugin->module;
1041 * gst_plugin_is_loaded:
1042 * @plugin: plugin to query
1044 * queries if the plugin is loaded into memory
1046 * Returns: TRUE is loaded, FALSE otherwise
1049 gst_plugin_is_loaded (GstPlugin * plugin)
1051 g_return_val_if_fail (plugin != NULL, FALSE);
1053 return (plugin->module != NULL || plugin->filename == NULL);
1057 * gst_plugin_get_cache_data:
1060 * Gets the plugin specific data cache. If it is %NULL there is no cached data
1061 * stored. This is the case when the registry is getting rebuilt.
1063 * Returns: (transfer none): The cached data as a #GstStructure or %NULL.
1067 const GstStructure *
1068 gst_plugin_get_cache_data (GstPlugin * plugin)
1070 g_return_val_if_fail (GST_IS_PLUGIN (plugin), NULL);
1072 return plugin->priv->cache_data;
1076 * gst_plugin_set_cache_data:
1078 * @cache_data: (transfer full): a structure containing the data to cache
1080 * Adds plugin specific data to cache. Passes the ownership of the structure to
1083 * The cache is flushed every time the registry is rebuilt.
1088 gst_plugin_set_cache_data (GstPlugin * plugin, GstStructure * cache_data)
1090 g_return_if_fail (GST_IS_PLUGIN (plugin));
1091 g_return_if_fail (GST_IS_STRUCTURE (cache_data));
1093 if (plugin->priv->cache_data) {
1094 gst_structure_free (plugin->priv->cache_data);
1096 plugin->priv->cache_data = cache_data;
1101 * gst_plugin_feature_list:
1102 * @plugin: plugin to query
1103 * @filter: the filter to use
1104 * @first: only return first match
1105 * @user_data: user data passed to the filter function
1107 * Runs a filter against all plugin features and returns a GList with
1108 * the results. If the first flag is set, only the first match is
1109 * returned (as a list with a single object).
1111 * Returns: a GList of features, g_list_free after use.
1114 gst_plugin_feature_filter (GstPlugin * plugin,
1115 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
1120 list = gst_filter_run (plugin->features, (GstFilterFunc) filter, first,
1122 for (g = list; g; g = g->next) {
1123 gst_object_ref (plugin);
1131 GstPluginFeatureFilter filter;
1139 _feature_filter (GstPlugin * plugin, gpointer user_data)
1142 FeatureFilterData *data = (FeatureFilterData *) user_data;
1144 result = gst_plugin_feature_filter (plugin, data->filter, data->first,
1147 data->result = g_list_concat (data->result, result);
1154 * gst_plugin_list_feature_filter:
1155 * @list: a #GList of plugins to query
1156 * @filter: the filter function to use
1157 * @first: only return first match
1158 * @user_data: user data passed to the filter function
1160 * Runs a filter against all plugin features of the plugins in the given
1161 * list and returns a GList with the results.
1162 * If the first flag is set, only the first match is
1163 * returned (as a list with a single object).
1165 * Returns: a GList of features, g_list_free after use.
1168 gst_plugin_list_feature_filter (GList * list,
1169 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
1171 FeatureFilterData data;
1174 data.filter = filter;
1176 data.user_data = user_data;
1179 result = gst_filter_run (list, (GstFilterFunc) _feature_filter, first, &data);
1180 g_list_free (result);
1187 * gst_plugin_name_filter:
1188 * @plugin: the plugin to check
1189 * @name: the name of the plugin
1191 * A standard filter that returns TRUE when the plugin is of the
1194 * Returns: TRUE if the plugin is of the given name.
1197 gst_plugin_name_filter (GstPlugin * plugin, const gchar * name)
1199 return (plugin->desc.name && !strcmp (plugin->desc.name, name));
1204 * gst_plugin_find_feature:
1205 * @plugin: plugin to get the feature from
1206 * @name: The name of the feature to find
1207 * @type: The type of the feature to find
1209 * Find a feature of the given name and type in the given plugin.
1211 * Returns: a GstPluginFeature or NULL if the feature was not found.
1214 gst_plugin_find_feature (GstPlugin * plugin, const gchar * name, GType type)
1217 GstPluginFeature *result = NULL;
1218 GstTypeNameData data;
1220 g_return_val_if_fail (name != NULL, NULL);
1225 walk = gst_filter_run (plugin->features,
1226 (GstFilterFunc) gst_plugin_feature_type_name_filter, TRUE, &data);
1229 result = GST_PLUGIN_FEATURE (walk->data);
1231 gst_object_ref (result);
1232 gst_plugin_feature_list_free (walk);
1241 gst_plugin_feature_name_filter (GstPluginFeature * feature, const gchar * name)
1243 return !strcmp (name, GST_PLUGIN_FEATURE_NAME (feature));
1249 * gst_plugin_find_feature_by_name:
1250 * @plugin: plugin to get the feature from
1251 * @name: The name of the feature to find
1253 * Find a feature of the given name in the given plugin.
1255 * Returns: a GstPluginFeature or NULL if the feature was not found.
1258 gst_plugin_find_feature_by_name (GstPlugin * plugin, const gchar * name)
1261 GstPluginFeature *result = NULL;
1263 g_return_val_if_fail (name != NULL, NULL);
1265 walk = gst_filter_run (plugin->features,
1266 (GstFilterFunc) gst_plugin_feature_name_filter, TRUE, (void *) name);
1269 result = GST_PLUGIN_FEATURE (walk->data);
1271 gst_object_ref (result);
1272 gst_plugin_feature_list_free (walk);
1280 * gst_plugin_load_by_name:
1281 * @name: name of plugin to load
1283 * Load the named plugin. Refs the plugin.
1285 * Returns: (transfer full): a reference to a loaded plugin, or NULL on error.
1288 gst_plugin_load_by_name (const gchar * name)
1290 GstPlugin *plugin, *newplugin;
1291 GError *error = NULL;
1293 GST_DEBUG ("looking up plugin %s in default registry", name);
1294 plugin = gst_registry_find_plugin (gst_registry_get_default (), name);
1296 GST_DEBUG ("loading plugin %s from file %s", name, plugin->filename);
1297 newplugin = gst_plugin_load_file (plugin->filename, &error);
1298 gst_object_unref (plugin);
1301 GST_WARNING ("load_plugin error: %s", error->message);
1302 g_error_free (error);
1305 /* newplugin was reffed by load_file */
1309 GST_DEBUG ("Could not find plugin %s in registry", name);
1315 * @plugin: (transfer none): plugin to load
1317 * Loads @plugin. Note that the *return value* is the loaded plugin; @plugin is
1318 * untouched. The normal use pattern of this function goes like this:
1321 * GstPlugin *loaded_plugin;
1322 * loaded_plugin = gst_plugin_load (plugin);
1323 * // presumably, we're no longer interested in the potentially-unloaded plugin
1324 * gst_object_unref (plugin);
1325 * plugin = loaded_plugin;
1328 * Returns: (transfer full): a reference to a loaded plugin, or NULL on error.
1331 gst_plugin_load (GstPlugin * plugin)
1333 GError *error = NULL;
1334 GstPlugin *newplugin;
1336 if (gst_plugin_is_loaded (plugin)) {
1340 if (!(newplugin = gst_plugin_load_file (plugin->filename, &error)))
1347 GST_WARNING ("load_plugin error: %s", error->message);
1348 g_error_free (error);
1354 * gst_plugin_list_free:
1355 * @list: (transfer full) (element-type Gst.Plugin): list of #GstPlugin
1357 * Unrefs each member of @list, then frees the list.
1360 gst_plugin_list_free (GList * list)
1364 for (g = list; g; g = g->next) {
1365 gst_object_unref (GST_PLUGIN_CAST (g->data));
1370 /* ===== plugin dependencies ===== */
1373 * ENV + xyz where ENV can contain multiple values separated by SEPARATOR
1374 * xyz may be "" (if ENV contains path to file rather than dir)
1375 * ENV + *xyz same as above, but xyz acts as suffix filter
1376 * ENV + xyz* same as above, but xyz acts as prefix filter (is this needed?)
1377 * ENV + *xyz* same as above, but xyz acts as strstr filter (is this needed?)
1379 * same as above, with additional paths hard-coded at compile-time:
1380 * - only check paths + ... if ENV is not set or yields not paths
1381 * - always check paths + ... in addition to ENV
1383 * When user specifies set of environment variables, he/she may also use e.g.
1384 * "HOME/.mystuff/plugins", and we'll expand the content of $HOME with the
1388 /* we store in registry:
1391 * - environment variables (array of strings)
1392 * - last hash of env variable contents (uint) (so we can avoid doing stats
1393 * if one of the env vars has changed; premature optimisation galore)
1394 * - hard-coded paths (array of strings)
1395 * - xyz filename/suffix/prefix strings (array of strings)
1397 * - last hash of file/dir stats (int)
1399 * (= struct GstPluginDep)
1403 gst_plugin_ext_dep_get_env_vars_hash (GstPlugin * plugin, GstPluginDep * dep)
1408 /* there's no deeper logic to what we do here; all we want to know (when
1409 * checking if the plugin needs to be rescanned) is whether the content of
1410 * one of the environment variables in the list is different from when it
1411 * was last scanned */
1413 for (e = dep->env_vars; e != NULL && *e != NULL; ++e) {
1417 /* order matters: "val",NULL needs to yield a different hash than
1418 * NULL,"val", so do a shift here whether the var is set or not */
1421 /* want environment variable at beginning of string */
1422 if (!g_ascii_isalnum (**e)) {
1423 GST_WARNING_OBJECT (plugin, "string prefix is not a valid environment "
1424 "variable string: %s", *e);
1428 /* user is allowed to specify e.g. "HOME/.pitivi/plugins" */
1429 g_strlcpy (env_var, *e, sizeof (env_var));
1430 g_strdelimit (env_var, "/\\", '\0');
1432 if ((val = g_getenv (env_var)))
1433 hash += g_str_hash (val);
1440 _priv_plugin_deps_env_vars_changed (GstPlugin * plugin)
1444 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1445 GstPluginDep *dep = l->data;
1447 if (dep->env_hash != gst_plugin_ext_dep_get_env_vars_hash (plugin, dep))
1455 gst_plugin_ext_dep_extract_env_vars_paths (GstPlugin * plugin,
1459 GList *paths = NULL;
1461 for (evars = dep->env_vars; evars != NULL && *evars != NULL; ++evars) {
1465 /* want environment variable at beginning of string */
1466 if (!g_ascii_isalnum (**evars)) {
1467 GST_WARNING_OBJECT (plugin, "string prefix is not a valid environment "
1468 "variable string: %s", *evars);
1472 /* user is allowed to specify e.g. "HOME/.pitivi/plugins", which we want to
1473 * split into the env_var name component and the path component */
1474 components = g_strsplit_set (*evars, "/\\", 2);
1475 g_assert (components != NULL);
1477 e = g_getenv (components[0]);
1478 GST_LOG_OBJECT (plugin, "expanding %s = '%s' (path suffix: %s)",
1479 components[0], GST_STR_NULL (e), GST_STR_NULL (components[1]));
1481 if (components[1] != NULL) {
1482 g_strdelimit (components[1], "/\\", G_DIR_SEPARATOR);
1485 if (e != NULL && *e != '\0') {
1489 arr = g_strsplit (e, G_SEARCHPATH_SEPARATOR_S, -1);
1491 for (i = 0; arr != NULL && arr[i] != NULL; ++i) {
1494 if (!g_path_is_absolute (arr[i])) {
1495 GST_INFO_OBJECT (plugin, "ignoring environment variable content '%s'"
1496 ": either not an absolute path or not a path at all", arr[i]);
1500 if (components[1] != NULL) {
1501 full_path = g_build_filename (arr[i], components[1], NULL);
1503 full_path = g_strdup (arr[i]);
1506 if (!g_list_find_custom (paths, full_path, (GCompareFunc) strcmp)) {
1507 GST_LOG_OBJECT (plugin, "path: '%s'", full_path);
1508 paths = g_list_prepend (paths, full_path);
1511 GST_LOG_OBJECT (plugin, "path: '%s' (duplicate,ignoring)", full_path);
1519 g_strfreev (components);
1522 GST_LOG_OBJECT (plugin, "Extracted %d paths from environment",
1523 g_list_length (paths));
1529 gst_plugin_ext_dep_get_hash_from_stat_entry (GStatBuf * s)
1531 if (!(s->st_mode & (S_IFDIR | S_IFREG)))
1534 /* completely random formula */
1535 return ((s->st_size << 3) + (s->st_mtime << 5)) ^ s->st_ctime;
1539 gst_plugin_ext_dep_direntry_matches (GstPlugin * plugin, const gchar * entry,
1540 const gchar ** filenames, GstPluginDependencyFlags flags)
1542 /* no filenames specified, match all entries for now (could probably
1543 * optimise by just taking the dir stat hash or so) */
1544 if (filenames == NULL || *filenames == NULL || **filenames == '\0')
1547 while (*filenames != NULL) {
1549 if (((flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX)) &&
1550 g_str_has_suffix (entry, *filenames)) {
1552 /* else it's an exact match that's needed */
1553 } else if (strcmp (entry, *filenames) == 0) {
1556 GST_LOG ("%s does not match %s, flags=0x%04x", entry, *filenames, flags);
1563 gst_plugin_ext_dep_scan_dir_and_match_names (GstPlugin * plugin,
1564 const gchar * path, const gchar ** filenames,
1565 GstPluginDependencyFlags flags, int depth)
1568 gboolean recurse_dirs;
1573 recurse_dirs = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
1575 dir = g_dir_open (path, 0, &err);
1577 GST_DEBUG_OBJECT (plugin, "g_dir_open(%s) failed: %s", path, err->message);
1582 /* FIXME: we're assuming here that we always get the directory entries in
1583 * the same order, and not in a random order */
1584 while ((entry = g_dir_read_name (dir))) {
1585 gboolean have_match;
1591 gst_plugin_ext_dep_direntry_matches (plugin, entry, filenames, flags);
1593 /* avoid the stat if possible */
1594 if (!have_match && !recurse_dirs)
1597 full_path = g_build_filename (path, entry, NULL);
1598 if (g_stat (full_path, &s) < 0) {
1599 fhash = (guint) - 1;
1600 GST_LOG_OBJECT (plugin, "stat: %s (error: %s)", full_path,
1601 g_strerror (errno));
1602 } else if (have_match) {
1603 fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
1604 GST_LOG_OBJECT (plugin, "stat: %s (result: %u)", full_path, fhash);
1605 } else if ((s.st_mode & (S_IFDIR))) {
1606 fhash = gst_plugin_ext_dep_scan_dir_and_match_names (plugin, full_path,
1607 filenames, flags, depth + 1);
1609 /* it's not a name match, we want to recurse, but it's not a directory */
1614 hash = (hash + fhash) << 1;
1623 gst_plugin_ext_dep_scan_path_with_filenames (GstPlugin * plugin,
1624 const gchar * path, const gchar ** filenames,
1625 GstPluginDependencyFlags flags)
1627 const gchar *empty_filenames[] = { "", NULL };
1628 gboolean recurse_into_dirs, partial_names;
1631 /* to avoid special-casing below (FIXME?) */
1632 if (filenames == NULL || *filenames == NULL)
1633 filenames = empty_filenames;
1635 recurse_into_dirs = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
1636 partial_names = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX);
1638 /* if we can construct the exact paths to check with the data we have, just
1639 * stat them one by one; this is more efficient than opening the directory
1640 * and going through each entry to see if it matches one of our filenames. */
1641 if (!recurse_into_dirs && !partial_names) {
1642 for (i = 0; filenames[i] != NULL; ++i) {
1647 full_path = g_build_filename (path, filenames[i], NULL);
1648 if (g_stat (full_path, &s) < 0) {
1649 fhash = (guint) - 1;
1650 GST_LOG_OBJECT (plugin, "stat: %s (error: %s)", full_path,
1651 g_strerror (errno));
1653 fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
1654 GST_LOG_OBJECT (plugin, "stat: %s (result: %08x)", full_path, fhash);
1656 hash = (hash + fhash) << 1;
1660 hash = gst_plugin_ext_dep_scan_dir_and_match_names (plugin, path,
1661 filenames, flags, 0);
1668 gst_plugin_ext_dep_get_stat_hash (GstPlugin * plugin, GstPluginDep * dep)
1670 gboolean paths_are_default_only;
1672 guint scan_hash = 0;
1674 GST_LOG_OBJECT (plugin, "start");
1676 paths_are_default_only =
1677 dep->flags & GST_PLUGIN_DEPENDENCY_FLAG_PATHS_ARE_DEFAULT_ONLY;
1679 scan_paths = gst_plugin_ext_dep_extract_env_vars_paths (plugin, dep);
1681 if (scan_paths == NULL || !paths_are_default_only) {
1684 for (paths = dep->paths; paths != NULL && *paths != NULL; ++paths) {
1685 const gchar *path = *paths;
1687 if (!g_list_find_custom (scan_paths, path, (GCompareFunc) strcmp)) {
1688 GST_LOG_OBJECT (plugin, "path: '%s'", path);
1689 scan_paths = g_list_prepend (scan_paths, g_strdup (path));
1691 GST_LOG_OBJECT (plugin, "path: '%s' (duplicate, ignoring)", path);
1696 /* not that the order really matters, but it makes debugging easier */
1697 scan_paths = g_list_reverse (scan_paths);
1699 while (scan_paths != NULL) {
1700 const gchar *path = scan_paths->data;
1702 scan_hash += gst_plugin_ext_dep_scan_path_with_filenames (plugin, path,
1703 (const gchar **) dep->names, dep->flags);
1704 scan_hash = scan_hash << 1;
1706 g_free (scan_paths->data);
1707 scan_paths = g_list_delete_link (scan_paths, scan_paths);
1710 GST_LOG_OBJECT (plugin, "done, scan_hash: %08x", scan_hash);
1715 _priv_plugin_deps_files_changed (GstPlugin * plugin)
1719 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1720 GstPluginDep *dep = l->data;
1722 if (dep->stat_hash != gst_plugin_ext_dep_get_stat_hash (plugin, dep))
1730 gst_plugin_ext_dep_free (GstPluginDep * dep)
1732 g_strfreev (dep->env_vars);
1733 g_strfreev (dep->paths);
1734 g_strfreev (dep->names);
1735 g_slice_free (GstPluginDep, dep);
1739 gst_plugin_ext_dep_strv_equal (gchar ** arr1, gchar ** arr2)
1743 if (arr1 == NULL || arr2 == NULL)
1745 for (; *arr1 != NULL && *arr2 != NULL; ++arr1, ++arr2) {
1746 if (strcmp (*arr1, *arr2) != 0)
1749 return (*arr1 == *arr2);
1753 gst_plugin_ext_dep_equals (GstPluginDep * dep, const gchar ** env_vars,
1754 const gchar ** paths, const gchar ** names, GstPluginDependencyFlags flags)
1756 if (dep->flags != flags)
1759 return gst_plugin_ext_dep_strv_equal (dep->env_vars, (gchar **) env_vars) &&
1760 gst_plugin_ext_dep_strv_equal (dep->paths, (gchar **) paths) &&
1761 gst_plugin_ext_dep_strv_equal (dep->names, (gchar **) names);
1765 * gst_plugin_add_dependency:
1766 * @plugin: a #GstPlugin
1767 * @env_vars: NULL-terminated array of environent variables affecting the
1768 * feature set of the plugin (e.g. an environment variable containing
1769 * paths where to look for additional modules/plugins of a library),
1770 * or NULL. Environment variable names may be followed by a path component
1771 * which will be added to the content of the environment variable, e.g.
1772 * "HOME/.mystuff/plugins".
1773 * @paths: NULL-terminated array of directories/paths where dependent files
1775 * @names: NULL-terminated array of file names (or file name suffixes,
1776 * depending on @flags) to be used in combination with the paths from
1777 * @paths and/or the paths extracted from the environment variables in
1778 * @env_vars, or NULL.
1779 * @flags: optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
1781 * Make GStreamer aware of external dependencies which affect the feature
1782 * set of this plugin (ie. the elements or typefinders associated with it).
1784 * GStreamer will re-inspect plugins with external dependencies whenever any
1785 * of the external dependencies change. This is useful for plugins which wrap
1786 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
1787 * library and makes visualisations available as GStreamer elements, or a
1788 * codec loader which exposes elements and/or caps dependent on what external
1789 * codec libraries are currently installed.
1794 gst_plugin_add_dependency (GstPlugin * plugin, const gchar ** env_vars,
1795 const gchar ** paths, const gchar ** names, GstPluginDependencyFlags flags)
1800 g_return_if_fail (GST_IS_PLUGIN (plugin));
1802 if ((env_vars == NULL || env_vars[0] == NULL) &&
1803 (paths == NULL || paths[0] == NULL)) {
1804 GST_DEBUG_OBJECT (plugin,
1805 "plugin registered empty dependency set. Ignoring");
1809 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1810 if (gst_plugin_ext_dep_equals (l->data, env_vars, paths, names, flags)) {
1811 GST_LOG_OBJECT (plugin, "dependency already registered");
1816 dep = g_slice_new (GstPluginDep);
1818 dep->env_vars = g_strdupv ((gchar **) env_vars);
1819 dep->paths = g_strdupv ((gchar **) paths);
1820 dep->names = g_strdupv ((gchar **) names);
1823 dep->env_hash = gst_plugin_ext_dep_get_env_vars_hash (plugin, dep);
1824 dep->stat_hash = gst_plugin_ext_dep_get_stat_hash (plugin, dep);
1826 plugin->priv->deps = g_list_append (plugin->priv->deps, dep);
1828 GST_DEBUG_OBJECT (plugin, "added dependency:");
1829 for (; env_vars != NULL && *env_vars != NULL; ++env_vars)
1830 GST_DEBUG_OBJECT (plugin, " evar: %s", *env_vars);
1831 for (; paths != NULL && *paths != NULL; ++paths)
1832 GST_DEBUG_OBJECT (plugin, " path: %s", *paths);
1833 for (; names != NULL && *names != NULL; ++names)
1834 GST_DEBUG_OBJECT (plugin, " name: %s", *names);
1838 * gst_plugin_add_dependency_simple:
1839 * @plugin: the #GstPlugin
1840 * @env_vars: one or more environent variables (separated by ':', ';' or ','),
1841 * or NULL. Environment variable names may be followed by a path component
1842 * which will be added to the content of the environment variable, e.g.
1843 * "HOME/.mystuff/plugins:MYSTUFF_PLUGINS_PATH"
1844 * @paths: one ore more directory paths (separated by ':' or ';' or ','),
1845 * or NULL. Example: "/usr/lib/mystuff/plugins"
1846 * @names: one or more file names or file name suffixes (separated by commas),
1848 * @flags: optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
1850 * Make GStreamer aware of external dependencies which affect the feature
1851 * set of this plugin (ie. the elements or typefinders associated with it).
1853 * GStreamer will re-inspect plugins with external dependencies whenever any
1854 * of the external dependencies change. This is useful for plugins which wrap
1855 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
1856 * library and makes visualisations available as GStreamer elements, or a
1857 * codec loader which exposes elements and/or caps dependent on what external
1858 * codec libraries are currently installed.
1860 * Convenience wrapper function for gst_plugin_add_dependency() which
1861 * takes simple strings as arguments instead of string arrays, with multiple
1862 * arguments separated by predefined delimiters (see above).
1867 gst_plugin_add_dependency_simple (GstPlugin * plugin,
1868 const gchar * env_vars, const gchar * paths, const gchar * names,
1869 GstPluginDependencyFlags flags)
1871 gchar **a_evars = NULL;
1872 gchar **a_paths = NULL;
1873 gchar **a_names = NULL;
1876 a_evars = g_strsplit_set (env_vars, ":;,", -1);
1878 a_paths = g_strsplit_set (paths, ":;,", -1);
1880 a_names = g_strsplit_set (names, ",", -1);
1882 gst_plugin_add_dependency (plugin, (const gchar **) a_evars,
1883 (const gchar **) a_paths, (const gchar **) a_names, flags);
1886 g_strfreev (a_evars);
1888 g_strfreev (a_paths);
1890 g_strfreev (a_names);