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);
127 GST_DEBUG ("finalizing plugin %" GST_PTR_FORMAT, plugin);
129 /* FIXME: make registry add a weak ref instead */
131 GstRegistry *registry = gst_registry_get ();
133 for (g = registry->plugins; g; g = g->next) {
134 if (g->data == (gpointer) plugin) {
135 g_warning ("removing plugin that is still in registry");
140 g_free (plugin->filename);
141 g_free (plugin->basename);
143 g_list_foreach (plugin->priv->deps, (GFunc) gst_plugin_ext_dep_free, NULL);
144 g_list_free (plugin->priv->deps);
145 plugin->priv->deps = NULL;
147 if (plugin->priv->cache_data) {
148 gst_structure_free (plugin->priv->cache_data);
151 G_OBJECT_CLASS (gst_plugin_parent_class)->finalize (object);
155 gst_plugin_class_init (GstPluginClass * klass)
157 G_OBJECT_CLASS (klass)->finalize = gst_plugin_finalize;
159 g_type_class_add_private (klass, sizeof (GstPluginPrivate));
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.
202 gst_plugin_register_static (gint major_version, gint minor_version,
203 const gchar * name, const gchar * description, GstPluginInitFunc init_func,
204 const gchar * version, const gchar * license, const gchar * source,
205 const gchar * package, const gchar * origin)
207 GstPluginDesc desc = { major_version, minor_version, name, description,
208 init_func, version, license, source, package, origin, NULL,
211 gboolean res = FALSE;
213 g_return_val_if_fail (name != NULL, FALSE);
214 g_return_val_if_fail (description != NULL, FALSE);
215 g_return_val_if_fail (init_func != NULL, FALSE);
216 g_return_val_if_fail (version != NULL, FALSE);
217 g_return_val_if_fail (license != NULL, FALSE);
218 g_return_val_if_fail (source != NULL, FALSE);
219 g_return_val_if_fail (package != NULL, FALSE);
220 g_return_val_if_fail (origin != NULL, FALSE);
222 /* make sure gst_init() has been called */
223 g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
225 GST_LOG ("attempting to load static plugin \"%s\" now...", name);
226 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
227 if (gst_plugin_register_func (plugin, &desc, NULL) != NULL) {
228 GST_INFO ("registered static plugin \"%s\"", name);
229 res = gst_registry_add_plugin (gst_registry_get (), plugin);
230 GST_INFO ("added static plugin \"%s\", result: %d", name, res);
236 * gst_plugin_register_static_full:
237 * @major_version: the major version number of the GStreamer core that the
238 * plugin was compiled for, you can just use GST_VERSION_MAJOR here
239 * @minor_version: the minor version number of the GStreamer core that the
240 * plugin was compiled for, you can just use GST_VERSION_MINOR here
241 * @name: a unique name of the plugin (ideally prefixed with an application- or
242 * library-specific namespace prefix in order to avoid name conflicts in
243 * case a similar plugin with the same name ever gets added to GStreamer)
244 * @description: description of the plugin
245 * @init_full_func: (scope call): pointer to the init function with user data
247 * @version: version string of the plugin
248 * @license: effective license of plugin. Must be one of the approved licenses
249 * (see #GstPluginDesc above) or the plugin will not be registered.
250 * @source: source module plugin belongs to
251 * @package: shipped package plugin belongs to
252 * @origin: URL to provider of plugin
253 * @user_data: gpointer to user data
255 * Registers a static plugin, ie. a plugin which is private to an application
256 * or library and contained within the application or library (as opposed to
257 * being shipped as a separate module file) with a #GstPluginInitFullFunc
258 * which allows user data to be passed to the callback function (useful
261 * You must make sure that GStreamer has been initialised (with gst_init() or
262 * via gst_init_get_option_group()) before calling this function.
264 * Returns: TRUE if the plugin was registered correctly, otherwise FALSE.
270 gst_plugin_register_static_full (gint major_version, gint minor_version,
271 const gchar * name, const gchar * description,
272 GstPluginInitFullFunc init_full_func, const gchar * version,
273 const gchar * license, const gchar * source, const gchar * package,
274 const gchar * origin, gpointer user_data)
276 GstPluginDesc desc = { major_version, minor_version, name, description,
277 (GstPluginInitFunc) init_full_func, version, license, source, package,
281 gboolean res = FALSE;
283 g_return_val_if_fail (name != NULL, FALSE);
284 g_return_val_if_fail (description != NULL, FALSE);
285 g_return_val_if_fail (init_full_func != NULL, FALSE);
286 g_return_val_if_fail (version != NULL, FALSE);
287 g_return_val_if_fail (license != NULL, FALSE);
288 g_return_val_if_fail (source != NULL, FALSE);
289 g_return_val_if_fail (package != NULL, FALSE);
290 g_return_val_if_fail (origin != NULL, FALSE);
292 /* make sure gst_init() has been called */
293 g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
295 GST_LOG ("attempting to load static plugin \"%s\" now...", name);
296 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
297 if (gst_plugin_register_func (plugin, &desc, user_data) != NULL) {
298 GST_INFO ("registered static plugin \"%s\"", name);
299 res = gst_registry_add_plugin (gst_registry_get (), plugin);
300 GST_INFO ("added static plugin \"%s\", result: %d", name, res);
306 _priv_gst_plugin_initialize (void)
308 const gchar *whitelist;
311 _gst_plugin_inited = TRUE;
313 whitelist = g_getenv ("GST_PLUGIN_LOADING_WHITELIST");
314 if (whitelist != NULL && *whitelist != '\0') {
315 _plugin_loading_whitelist = g_strsplit (whitelist,
316 G_SEARCHPATH_SEPARATOR_S, -1);
317 for (i = 0; _plugin_loading_whitelist[i] != NULL; ++i) {
318 GST_INFO ("plugins whitelist entry: %s", _plugin_loading_whitelist[i]);
322 /* now register all static plugins */
323 GST_INFO ("registering %u static plugins", _num_static_plugins);
324 for (i = 0; i < _num_static_plugins; ++i) {
325 gst_plugin_register_static (_static_plugins[i].major_version,
326 _static_plugins[i].minor_version, _static_plugins[i].name,
327 _static_plugins[i].description, _static_plugins[i].plugin_init,
328 _static_plugins[i].version, _static_plugins[i].license,
329 _static_plugins[i].source, _static_plugins[i].package,
330 _static_plugins[i].origin);
333 if (_static_plugins) {
334 free (_static_plugins);
335 _static_plugins = NULL;
336 _num_static_plugins = 0;
340 /* Whitelist entry format:
342 * plugin1,plugin2@pathprefix or
343 * plugin1,plugin2@* or just
345 * source-package@pathprefix or
346 * source-package@* or just
349 * ie. the bit before the path will be checked against both the plugin
350 * name and the plugin's source package name, to keep the format simple.
353 gst_plugin_desc_matches_whitelist_entry (GstPluginDesc * desc,
354 const gchar * filename, const gchar * pattern)
357 gboolean ret = FALSE;
360 GST_LOG ("Whitelist pattern '%s', plugin: %s of %s@%s", pattern, desc->name,
361 desc->source, GST_STR_NULL (filename));
363 /* do we have a path prefix? */
364 sep = strchr (pattern, '@');
365 if (sep != NULL && strcmp (sep, "@*") != 0 && strcmp (sep, "@") != 0) {
366 /* paths are not canonicalised or treated with realpath() here. This
367 * should be good enough for our use case, since we just use the paths
368 * autotools uses, and those will be constructed from the same prefix. */
369 if (filename != NULL && !g_str_has_prefix (filename, sep + 1))
372 GST_LOG ("%s matches path prefix %s", GST_STR_NULL (filename), sep + 1);
376 name = g_strndup (pattern, (gsize) (sep - pattern));
378 name = g_strdup (pattern);
382 if (!g_ascii_isalnum (*name)) {
383 GST_WARNING ("Invalid whitelist pattern: %s", pattern);
387 /* now check plugin names / source package name */
388 if (strchr (name, ',') == NULL) {
389 /* only a single name: either a plugin name or the source package name */
390 ret = (strcmp (desc->source, name) == 0 || strcmp (desc->name, name) == 0);
394 /* multiple names: assume these are plugin names */
395 names = g_strsplit (name, ",", -1);
396 for (n = names; n != NULL && *n != NULL; ++n) {
398 if (strcmp (desc->name, *n) == 0) {
406 GST_LOG ("plugin / source package name match: %d", ret);
415 priv_gst_plugin_desc_is_whitelisted (GstPluginDesc * desc,
416 const gchar * filename)
420 if (_plugin_loading_whitelist == NULL)
423 for (entry = _plugin_loading_whitelist; *entry != NULL; ++entry) {
424 if (gst_plugin_desc_matches_whitelist_entry (desc, filename, *entry)) {
425 GST_LOG ("Plugin %s is in whitelist", filename);
430 GST_LOG ("Plugin %s (package %s, file %s) not in whitelist", desc->name,
431 desc->source, filename);
436 priv_gst_plugin_loading_have_whitelist (void)
438 return (_plugin_loading_whitelist != NULL);
442 priv_gst_plugin_loading_get_whitelist_hash (void)
446 if (_plugin_loading_whitelist != NULL) {
449 for (w = _plugin_loading_whitelist; *w != NULL; ++w)
450 hash = (hash << 1) ^ g_str_hash (*w);
456 /* this function could be extended to check if the plugin license matches the
457 * applications license (would require the app to register its license somehow).
458 * We'll wait for someone who's interested in it to code it :)
461 gst_plugin_check_license (const gchar * license)
463 const gchar **check_license = valid_licenses;
465 g_assert (check_license);
467 while (*check_license) {
468 if (strcmp (license, *check_license) == 0)
476 gst_plugin_check_version (gint major, gint minor)
478 /* return NULL if the major and minor version numbers are not compatible */
480 if (major != GST_VERSION_MAJOR || minor != GST_VERSION_MINOR)
487 gst_plugin_register_func (GstPlugin * plugin, const GstPluginDesc * desc,
490 if (!gst_plugin_check_version (desc->major_version, desc->minor_version)) {
492 GST_WARNING ("plugin \"%s\" has incompatible version, not loading",
497 if (!desc->license || !desc->description || !desc->source ||
498 !desc->package || !desc->origin) {
500 GST_WARNING ("plugin \"%s\" has incorrect GstPluginDesc, not loading",
505 if (!gst_plugin_check_license (desc->license)) {
507 GST_WARNING ("plugin \"%s\" has invalid license \"%s\", not loading",
508 plugin->filename, desc->license);
513 GST_LOG ("plugin \"%s\" looks good", GST_STR_NULL (plugin->filename));
515 gst_plugin_desc_copy (&plugin->desc, desc);
517 /* make resident so we're really sure it never gets unloaded again.
518 * Theoretically this is not needed, but practically it doesn't hurt.
519 * And we're rather safe than sorry. */
521 g_module_make_resident (plugin->module);
524 if (!(((GstPluginInitFullFunc) (desc->plugin_init)) (plugin, user_data))) {
526 GST_WARNING ("plugin \"%s\" failed to initialise", plugin->filename);
530 if (!((desc->plugin_init) (plugin))) {
532 GST_WARNING ("plugin \"%s\" failed to initialise", plugin->filename);
538 GST_LOG ("plugin \"%s\" initialised", GST_STR_NULL (plugin->filename));
543 #ifdef HAVE_SIGACTION
544 static struct sigaction oldaction;
545 static gboolean _gst_plugin_fault_handler_is_setup = FALSE;
548 * _gst_plugin_fault_handler_restore:
549 * segfault handler restorer
552 _gst_plugin_fault_handler_restore (void)
554 if (!_gst_plugin_fault_handler_is_setup)
557 _gst_plugin_fault_handler_is_setup = FALSE;
559 sigaction (SIGSEGV, &oldaction, NULL);
563 * _gst_plugin_fault_handler_sighandler:
564 * segfault handler implementation
567 _gst_plugin_fault_handler_sighandler (int signum)
569 /* We need to restore the fault handler or we'll keep getting it */
570 _gst_plugin_fault_handler_restore ();
574 g_print ("\nERROR: ");
575 g_print ("Caught a segmentation fault while loading plugin file:\n");
576 g_print ("%s\n\n", _gst_plugin_fault_handler_filename);
577 g_print ("Please either:\n");
578 g_print ("- remove it and restart.\n");
580 ("- run with --gst-disable-segtrap --gst-disable-registry-fork and debug.\n");
584 g_print ("Caught unhandled signal on plugin loading\n");
590 * _gst_plugin_fault_handler_setup:
591 * sets up the segfault handler
594 _gst_plugin_fault_handler_setup (void)
596 struct sigaction action;
598 /* if asked to leave segfaults alone, just return */
599 if (!gst_segtrap_is_enabled ())
602 if (_gst_plugin_fault_handler_is_setup)
605 _gst_plugin_fault_handler_is_setup = TRUE;
607 memset (&action, 0, sizeof (action));
608 action.sa_handler = _gst_plugin_fault_handler_sighandler;
610 sigaction (SIGSEGV, &action, &oldaction);
612 #else /* !HAVE_SIGACTION */
614 _gst_plugin_fault_handler_restore (void)
619 _gst_plugin_fault_handler_setup (void)
622 #endif /* HAVE_SIGACTION */
624 /* g_time_val_from_iso8601() doesn't do quite what we want */
626 check_release_datetime (const gchar * date_time)
630 /* we require YYYY-MM-DD or YYYY-MM-DDTHH:MMZ format */
631 if (!g_ascii_isdigit (*date_time))
634 val = g_ascii_strtoull (date_time, (gchar **) & date_time, 10);
635 if (val < 2000 || val > 2100 || *date_time != '-')
638 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
639 if (val == 0 || val > 12 || *date_time != '-')
642 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
643 if (val == 0 || val > 32)
646 /* end of string or date/time separator + HH:MMZ */
647 if (*date_time == 'T' || *date_time == ' ') {
648 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
649 if (val > 24 || *date_time != ':')
652 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
653 if (val > 59 || *date_time != 'Z')
659 return (*date_time == '\0');
662 static GStaticMutex gst_plugin_loading_mutex = G_STATIC_MUTEX_INIT;
664 #define CHECK_PLUGIN_DESC_FIELD(desc,field,fn) \
665 if (G_UNLIKELY ((desc)->field == NULL)) { \
666 GST_ERROR ("GstPluginDesc for '%s' has no %s", fn, G_STRINGIFY (field)); \
670 * gst_plugin_load_file:
671 * @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)
687 GStatBuf file_status;
688 GstRegistry *registry;
689 gboolean new_plugin = TRUE;
692 g_return_val_if_fail (filename != NULL, NULL);
694 registry = gst_registry_get ();
695 g_static_mutex_lock (&gst_plugin_loading_mutex);
697 plugin = gst_registry_lookup (registry, filename);
699 if (plugin->module) {
701 g_static_mutex_unlock (&gst_plugin_loading_mutex);
704 /* load plugin and update fields */
709 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "attempt to load plugin \"%s\"",
712 if (g_module_supported () == FALSE) {
713 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "module loading not supported");
716 GST_PLUGIN_ERROR_MODULE, "Dynamic loading not supported");
720 if (g_stat (filename, &file_status)) {
721 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "problem accessing file");
724 GST_PLUGIN_ERROR_MODULE, "Problem accessing file %s: %s", filename,
729 flags = G_MODULE_BIND_LOCAL;
730 /* libgstpython.so is the gst-python plugin loader. It needs to be loaded with
731 * G_MODULE_BIND_LAZY.
733 * Ideally there should be a generic way for plugins to specify that they
734 * need to be loaded with _LAZY.
736 if (strstr (filename, "libgstpython"))
737 flags |= G_MODULE_BIND_LAZY;
739 module = g_module_open (filename, flags);
740 if (module == NULL) {
741 GST_CAT_WARNING (GST_CAT_PLUGIN_LOADING, "module_open failed: %s",
744 GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "Opening module failed: %s",
746 /* If we failed to open the shared object, then it's probably because a
747 * plugin is linked against the wrong libraries. Print out an easy-to-see
748 * message in this case. */
749 g_warning ("Failed to load plugin '%s': %s", filename, g_module_error ());
753 ret = g_module_symbol (module, "gst_plugin_desc", &ptr);
755 GST_DEBUG ("Could not find plugin entry point in \"%s\"", filename);
758 GST_PLUGIN_ERROR_MODULE,
759 "File \"%s\" is not a GStreamer plugin", filename);
760 g_module_close (module);
764 desc = (GstPluginDesc *) ptr;
766 if (priv_gst_plugin_loading_have_whitelist () &&
767 !priv_gst_plugin_desc_is_whitelisted (desc, filename)) {
768 GST_INFO ("Whitelist specified and plugin not in whitelist, not loading: "
769 "name=%s, package=%s, file=%s", desc->name, desc->source, filename);
770 g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE,
771 "Not loading plugin file \"%s\", not in whitelist", filename);
772 g_module_close (module);
777 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
778 plugin->file_mtime = file_status.st_mtime;
779 plugin->file_size = file_status.st_size;
780 plugin->filename = g_strdup (filename);
781 plugin->basename = g_path_get_basename (filename);
784 plugin->module = module;
785 plugin->orig_desc = desc;
788 /* check plugin description: complain about bad values but accept them, to
789 * maintain backwards compatibility (FIXME: 0.11) */
790 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, name, filename);
791 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, description, filename);
792 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, version, filename);
793 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, license, filename);
794 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, source, filename);
795 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, package, filename);
796 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, origin, filename);
798 if (plugin->orig_desc->release_datetime != NULL &&
799 !check_release_datetime (plugin->orig_desc->release_datetime)) {
800 GST_ERROR ("GstPluginDesc for '%s' has invalid datetime '%s'",
801 filename, plugin->orig_desc->release_datetime);
802 plugin->orig_desc->release_datetime = NULL;
806 GST_LOG ("Plugin %p for file \"%s\" prepared, calling entry function...",
809 /* this is where we load the actual .so, so let's trap SIGSEGV */
810 _gst_plugin_fault_handler_setup ();
811 _gst_plugin_fault_handler_filename = plugin->filename;
813 GST_LOG ("Plugin %p for file \"%s\" prepared, registering...",
816 if (!gst_plugin_register_func (plugin, plugin->orig_desc, NULL)) {
817 /* remove signal handler */
818 _gst_plugin_fault_handler_restore ();
819 GST_DEBUG ("gst_plugin_register_func failed for plugin \"%s\"", filename);
823 GST_PLUGIN_ERROR_MODULE,
824 "File \"%s\" appears to be a GStreamer plugin, but it failed to initialize",
829 /* remove signal handler */
830 _gst_plugin_fault_handler_restore ();
831 _gst_plugin_fault_handler_filename = NULL;
832 GST_INFO ("plugin \"%s\" loaded", plugin->filename);
835 gst_object_ref (plugin);
836 gst_registry_add_plugin (gst_registry_get (), plugin);
839 g_static_mutex_unlock (&gst_plugin_loading_mutex);
845 gst_object_unref (plugin);
846 g_static_mutex_unlock (&gst_plugin_loading_mutex);
852 gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src)
854 dest->major_version = src->major_version;
855 dest->minor_version = src->minor_version;
856 dest->name = g_intern_string (src->name);
857 dest->description = g_intern_string (src->description);
858 dest->plugin_init = src->plugin_init;
859 dest->version = g_intern_string (src->version);
860 dest->license = g_intern_string (src->license);
861 dest->source = g_intern_string (src->source);
862 dest->package = g_intern_string (src->package);
863 dest->origin = g_intern_string (src->origin);
864 dest->release_datetime = g_intern_string (src->release_datetime);
868 * gst_plugin_get_name:
869 * @plugin: plugin to get the name of
871 * Get the short name of the plugin
873 * Returns: the name of the plugin
876 gst_plugin_get_name (GstPlugin * plugin)
878 g_return_val_if_fail (plugin != NULL, NULL);
880 return plugin->desc.name;
884 * gst_plugin_get_description:
885 * @plugin: plugin to get long name of
887 * Get the long descriptive name of the plugin
889 * Returns: the long name of the plugin
892 gst_plugin_get_description (GstPlugin * plugin)
894 g_return_val_if_fail (plugin != NULL, NULL);
896 return plugin->desc.description;
900 * gst_plugin_get_filename:
901 * @plugin: plugin to get the filename of
903 * get the filename of the plugin
905 * Returns: the filename of the plugin
908 gst_plugin_get_filename (GstPlugin * plugin)
910 g_return_val_if_fail (plugin != NULL, NULL);
912 return plugin->filename;
916 * gst_plugin_get_version:
917 * @plugin: plugin to get the version of
919 * get the version of the plugin
921 * Returns: the version of the plugin
924 gst_plugin_get_version (GstPlugin * plugin)
926 g_return_val_if_fail (plugin != NULL, NULL);
928 return plugin->desc.version;
932 * gst_plugin_get_license:
933 * @plugin: plugin to get the license of
935 * get the license of the plugin
937 * Returns: the license of the plugin
940 gst_plugin_get_license (GstPlugin * plugin)
942 g_return_val_if_fail (plugin != NULL, NULL);
944 return plugin->desc.license;
948 * gst_plugin_get_source:
949 * @plugin: plugin to get the source of
951 * get the source module the plugin belongs to.
953 * Returns: the source of the plugin
956 gst_plugin_get_source (GstPlugin * plugin)
958 g_return_val_if_fail (plugin != NULL, NULL);
960 return plugin->desc.source;
964 * gst_plugin_get_package:
965 * @plugin: plugin to get the package of
967 * get the package the plugin belongs to.
969 * Returns: the package of the plugin
972 gst_plugin_get_package (GstPlugin * plugin)
974 g_return_val_if_fail (plugin != NULL, NULL);
976 return plugin->desc.package;
980 * gst_plugin_get_origin:
981 * @plugin: plugin to get the origin of
983 * get the URL where the plugin comes from
985 * Returns: the origin of the plugin
988 gst_plugin_get_origin (GstPlugin * plugin)
990 g_return_val_if_fail (plugin != NULL, NULL);
992 return plugin->desc.origin;
996 * gst_plugin_get_module:
997 * @plugin: plugin to query
999 * Gets the #GModule of the plugin. If the plugin isn't loaded yet, NULL is
1002 * Returns: (transfer none): module belonging to the plugin or NULL if the
1003 * plugin isn't loaded yet.
1006 gst_plugin_get_module (GstPlugin * plugin)
1008 g_return_val_if_fail (plugin != NULL, NULL);
1010 return plugin->module;
1014 * gst_plugin_is_loaded:
1015 * @plugin: plugin to query
1017 * queries if the plugin is loaded into memory
1019 * Returns: TRUE is loaded, FALSE otherwise
1022 gst_plugin_is_loaded (GstPlugin * plugin)
1024 g_return_val_if_fail (plugin != NULL, FALSE);
1026 return (plugin->module != NULL || plugin->filename == NULL);
1030 * gst_plugin_get_cache_data:
1033 * Gets the plugin specific data cache. If it is %NULL there is no cached data
1034 * stored. This is the case when the registry is getting rebuilt.
1036 * Returns: (transfer none): The cached data as a #GstStructure or %NULL.
1040 const GstStructure *
1041 gst_plugin_get_cache_data (GstPlugin * plugin)
1043 g_return_val_if_fail (GST_IS_PLUGIN (plugin), NULL);
1045 return plugin->priv->cache_data;
1049 * gst_plugin_set_cache_data:
1051 * @cache_data: (transfer full): a structure containing the data to cache
1053 * Adds plugin specific data to cache. Passes the ownership of the structure to
1056 * The cache is flushed every time the registry is rebuilt.
1061 gst_plugin_set_cache_data (GstPlugin * plugin, GstStructure * cache_data)
1063 g_return_if_fail (GST_IS_PLUGIN (plugin));
1064 g_return_if_fail (GST_IS_STRUCTURE (cache_data));
1066 if (plugin->priv->cache_data) {
1067 gst_structure_free (plugin->priv->cache_data);
1069 plugin->priv->cache_data = cache_data;
1074 * gst_plugin_feature_list:
1075 * @plugin: plugin to query
1076 * @filter: the filter to use
1077 * @first: only return first match
1078 * @user_data: user data passed to the filter function
1080 * Runs a filter against all plugin features and returns a GList with
1081 * the results. If the first flag is set, only the first match is
1082 * returned (as a list with a single object).
1084 * Returns: a GList of features, g_list_free after use.
1087 gst_plugin_feature_filter (GstPlugin * plugin,
1088 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
1093 list = gst_filter_run (plugin->features, (GstFilterFunc) filter, first,
1095 for (g = list; g; g = g->next) {
1096 gst_object_ref (plugin);
1104 GstPluginFeatureFilter filter;
1112 _feature_filter (GstPlugin * plugin, gpointer user_data)
1115 FeatureFilterData *data = (FeatureFilterData *) user_data;
1117 result = gst_plugin_feature_filter (plugin, data->filter, data->first,
1120 data->result = g_list_concat (data->result, result);
1127 * gst_plugin_list_feature_filter:
1128 * @list: a #GList of plugins to query
1129 * @filter: the filter function to use
1130 * @first: only return first match
1131 * @user_data: user data passed to the filter function
1133 * Runs a filter against all plugin features of the plugins in the given
1134 * list and returns a GList with the results.
1135 * If the first flag is set, only the first match is
1136 * returned (as a list with a single object).
1138 * Returns: a GList of features, g_list_free after use.
1141 gst_plugin_list_feature_filter (GList * list,
1142 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
1144 FeatureFilterData data;
1147 data.filter = filter;
1149 data.user_data = user_data;
1152 result = gst_filter_run (list, (GstFilterFunc) _feature_filter, first, &data);
1153 g_list_free (result);
1160 * gst_plugin_name_filter:
1161 * @plugin: the plugin to check
1162 * @name: the name of the plugin
1164 * A standard filter that returns TRUE when the plugin is of the
1167 * Returns: TRUE if the plugin is of the given name.
1170 gst_plugin_name_filter (GstPlugin * plugin, const gchar * name)
1172 return (plugin->desc.name && !strcmp (plugin->desc.name, name));
1177 * gst_plugin_find_feature:
1178 * @plugin: plugin to get the feature from
1179 * @name: The name of the feature to find
1180 * @type: The type of the feature to find
1182 * Find a feature of the given name and type in the given plugin.
1184 * Returns: a GstPluginFeature or NULL if the feature was not found.
1187 gst_plugin_find_feature (GstPlugin * plugin, const gchar * name, GType type)
1190 GstPluginFeature *result = NULL;
1191 GstTypeNameData data;
1193 g_return_val_if_fail (name != NULL, NULL);
1198 walk = gst_filter_run (plugin->features,
1199 (GstFilterFunc) gst_plugin_feature_type_name_filter, TRUE, &data);
1202 result = GST_PLUGIN_FEATURE (walk->data);
1204 gst_object_ref (result);
1205 gst_plugin_feature_list_free (walk);
1214 gst_plugin_feature_name_filter (GstPluginFeature * feature, const gchar * name)
1216 return !strcmp (name, GST_PLUGIN_FEATURE_NAME (feature));
1222 * gst_plugin_find_feature_by_name:
1223 * @plugin: plugin to get the feature from
1224 * @name: The name of the feature to find
1226 * Find a feature of the given name in the given plugin.
1228 * Returns: a GstPluginFeature or NULL if the feature was not found.
1231 gst_plugin_find_feature_by_name (GstPlugin * plugin, const gchar * name)
1234 GstPluginFeature *result = NULL;
1236 g_return_val_if_fail (name != NULL, NULL);
1238 walk = gst_filter_run (plugin->features,
1239 (GstFilterFunc) gst_plugin_feature_name_filter, TRUE, (void *) name);
1242 result = GST_PLUGIN_FEATURE (walk->data);
1244 gst_object_ref (result);
1245 gst_plugin_feature_list_free (walk);
1253 * gst_plugin_load_by_name:
1254 * @name: name of plugin to load
1256 * Load the named plugin. Refs the plugin.
1258 * Returns: (transfer full): a reference to a loaded plugin, or NULL on error.
1261 gst_plugin_load_by_name (const gchar * name)
1263 GstPlugin *plugin, *newplugin;
1264 GError *error = NULL;
1266 GST_DEBUG ("looking up plugin %s in default registry", name);
1267 plugin = gst_registry_find_plugin (gst_registry_get (), name);
1269 GST_DEBUG ("loading plugin %s from file %s", name, plugin->filename);
1270 newplugin = gst_plugin_load_file (plugin->filename, &error);
1271 gst_object_unref (plugin);
1274 GST_WARNING ("load_plugin error: %s", error->message);
1275 g_error_free (error);
1278 /* newplugin was reffed by load_file */
1282 GST_DEBUG ("Could not find plugin %s in registry", name);
1288 * @plugin: (transfer none): plugin to load
1290 * Loads @plugin. Note that the *return value* is the loaded plugin; @plugin is
1291 * untouched. The normal use pattern of this function goes like this:
1294 * GstPlugin *loaded_plugin;
1295 * loaded_plugin = gst_plugin_load (plugin);
1296 * // presumably, we're no longer interested in the potentially-unloaded plugin
1297 * gst_object_unref (plugin);
1298 * plugin = loaded_plugin;
1301 * Returns: (transfer full): a reference to a loaded plugin, or NULL on error.
1304 gst_plugin_load (GstPlugin * plugin)
1306 GError *error = NULL;
1307 GstPlugin *newplugin;
1309 if (gst_plugin_is_loaded (plugin)) {
1313 if (!(newplugin = gst_plugin_load_file (plugin->filename, &error)))
1320 GST_WARNING ("load_plugin error: %s", error->message);
1321 g_error_free (error);
1327 * gst_plugin_list_free:
1328 * @list: (transfer full) (element-type Gst.Plugin): list of #GstPlugin
1330 * Unrefs each member of @list, then frees the list.
1333 gst_plugin_list_free (GList * list)
1337 for (g = list; g; g = g->next) {
1338 gst_object_unref (GST_PLUGIN_CAST (g->data));
1343 /* ===== plugin dependencies ===== */
1346 * ENV + xyz where ENV can contain multiple values separated by SEPARATOR
1347 * xyz may be "" (if ENV contains path to file rather than dir)
1348 * ENV + *xyz same as above, but xyz acts as suffix filter
1349 * ENV + xyz* same as above, but xyz acts as prefix filter (is this needed?)
1350 * ENV + *xyz* same as above, but xyz acts as strstr filter (is this needed?)
1352 * same as above, with additional paths hard-coded at compile-time:
1353 * - only check paths + ... if ENV is not set or yields not paths
1354 * - always check paths + ... in addition to ENV
1356 * When user specifies set of environment variables, he/she may also use e.g.
1357 * "HOME/.mystuff/plugins", and we'll expand the content of $HOME with the
1361 /* we store in registry:
1364 * - environment variables (array of strings)
1365 * - last hash of env variable contents (uint) (so we can avoid doing stats
1366 * if one of the env vars has changed; premature optimisation galore)
1367 * - hard-coded paths (array of strings)
1368 * - xyz filename/suffix/prefix strings (array of strings)
1370 * - last hash of file/dir stats (int)
1372 * (= struct GstPluginDep)
1376 gst_plugin_ext_dep_get_env_vars_hash (GstPlugin * plugin, GstPluginDep * dep)
1381 /* there's no deeper logic to what we do here; all we want to know (when
1382 * checking if the plugin needs to be rescanned) is whether the content of
1383 * one of the environment variables in the list is different from when it
1384 * was last scanned */
1386 for (e = dep->env_vars; e != NULL && *e != NULL; ++e) {
1390 /* order matters: "val",NULL needs to yield a different hash than
1391 * NULL,"val", so do a shift here whether the var is set or not */
1394 /* want environment variable at beginning of string */
1395 if (!g_ascii_isalnum (**e)) {
1396 GST_WARNING_OBJECT (plugin, "string prefix is not a valid environment "
1397 "variable string: %s", *e);
1401 /* user is allowed to specify e.g. "HOME/.pitivi/plugins" */
1402 g_strlcpy (env_var, *e, sizeof (env_var));
1403 g_strdelimit (env_var, "/\\", '\0');
1405 if ((val = g_getenv (env_var)))
1406 hash += g_str_hash (val);
1413 _priv_plugin_deps_env_vars_changed (GstPlugin * plugin)
1417 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1418 GstPluginDep *dep = l->data;
1420 if (dep->env_hash != gst_plugin_ext_dep_get_env_vars_hash (plugin, dep))
1428 gst_plugin_ext_dep_extract_env_vars_paths (GstPlugin * plugin,
1429 GstPluginDep * dep, GQueue * paths)
1433 for (evars = dep->env_vars; evars != NULL && *evars != NULL; ++evars) {
1437 /* want environment variable at beginning of string */
1438 if (!g_ascii_isalnum (**evars)) {
1439 GST_WARNING_OBJECT (plugin, "string prefix is not a valid environment "
1440 "variable string: %s", *evars);
1444 /* user is allowed to specify e.g. "HOME/.pitivi/plugins", which we want to
1445 * split into the env_var name component and the path component */
1446 components = g_strsplit_set (*evars, "/\\", 2);
1447 g_assert (components != NULL);
1449 e = g_getenv (components[0]);
1450 GST_LOG_OBJECT (plugin, "expanding %s = '%s' (path suffix: %s)",
1451 components[0], GST_STR_NULL (e), GST_STR_NULL (components[1]));
1453 if (components[1] != NULL) {
1454 g_strdelimit (components[1], "/\\", G_DIR_SEPARATOR);
1457 if (e != NULL && *e != '\0') {
1461 arr = g_strsplit (e, G_SEARCHPATH_SEPARATOR_S, -1);
1463 for (i = 0; arr != NULL && arr[i] != NULL; ++i) {
1466 if (!g_path_is_absolute (arr[i])) {
1467 GST_INFO_OBJECT (plugin, "ignoring environment variable content '%s'"
1468 ": either not an absolute path or not a path at all", arr[i]);
1472 if (components[1] != NULL) {
1473 full_path = g_build_filename (arr[i], components[1], NULL);
1475 full_path = g_strdup (arr[i]);
1478 if (!g_queue_find_custom (paths, full_path, (GCompareFunc) strcmp)) {
1479 GST_LOG_OBJECT (plugin, "path: '%s'", full_path);
1480 g_queue_push_tail (paths, full_path);
1483 GST_LOG_OBJECT (plugin, "path: '%s' (duplicate,ignoring)", full_path);
1491 g_strfreev (components);
1494 GST_LOG_OBJECT (plugin, "Extracted %d paths from environment", paths->length);
1498 gst_plugin_ext_dep_get_hash_from_stat_entry (GStatBuf * s)
1500 if (!(s->st_mode & (S_IFDIR | S_IFREG)))
1503 /* completely random formula */
1504 return ((s->st_size << 3) + (s->st_mtime << 5)) ^ s->st_ctime;
1508 gst_plugin_ext_dep_direntry_matches (GstPlugin * plugin, const gchar * entry,
1509 const gchar ** filenames, GstPluginDependencyFlags flags)
1511 /* no filenames specified, match all entries for now (could probably
1512 * optimise by just taking the dir stat hash or so) */
1513 if (filenames == NULL || *filenames == NULL || **filenames == '\0')
1516 while (*filenames != NULL) {
1518 if (((flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX)) &&
1519 g_str_has_suffix (entry, *filenames)) {
1521 /* else it's an exact match that's needed */
1522 } else if (strcmp (entry, *filenames) == 0) {
1525 GST_LOG ("%s does not match %s, flags=0x%04x", entry, *filenames, flags);
1532 gst_plugin_ext_dep_scan_dir_and_match_names (GstPlugin * plugin,
1533 const gchar * path, const gchar ** filenames,
1534 GstPluginDependencyFlags flags, int depth)
1537 gboolean recurse_dirs;
1542 recurse_dirs = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
1544 dir = g_dir_open (path, 0, &err);
1546 GST_DEBUG_OBJECT (plugin, "g_dir_open(%s) failed: %s", path, err->message);
1551 /* FIXME: we're assuming here that we always get the directory entries in
1552 * the same order, and not in a random order */
1553 while ((entry = g_dir_read_name (dir))) {
1554 gboolean have_match;
1560 gst_plugin_ext_dep_direntry_matches (plugin, entry, filenames, flags);
1562 /* avoid the stat if possible */
1563 if (!have_match && !recurse_dirs)
1566 full_path = g_build_filename (path, entry, NULL);
1567 if (g_stat (full_path, &s) < 0) {
1568 fhash = (guint) - 1;
1569 GST_LOG_OBJECT (plugin, "stat: %s (error: %s)", full_path,
1570 g_strerror (errno));
1571 } else if (have_match) {
1572 fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
1573 GST_LOG_OBJECT (plugin, "stat: %s (result: %u)", full_path, fhash);
1574 } else if ((s.st_mode & (S_IFDIR))) {
1575 fhash = gst_plugin_ext_dep_scan_dir_and_match_names (plugin, full_path,
1576 filenames, flags, depth + 1);
1578 /* it's not a name match, we want to recurse, but it's not a directory */
1583 hash = (hash + fhash) << 1;
1592 gst_plugin_ext_dep_scan_path_with_filenames (GstPlugin * plugin,
1593 const gchar * path, const gchar ** filenames,
1594 GstPluginDependencyFlags flags)
1596 const gchar *empty_filenames[] = { "", NULL };
1597 gboolean recurse_into_dirs, partial_names;
1600 /* to avoid special-casing below (FIXME?) */
1601 if (filenames == NULL || *filenames == NULL)
1602 filenames = empty_filenames;
1604 recurse_into_dirs = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
1605 partial_names = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX);
1607 /* if we can construct the exact paths to check with the data we have, just
1608 * stat them one by one; this is more efficient than opening the directory
1609 * and going through each entry to see if it matches one of our filenames. */
1610 if (!recurse_into_dirs && !partial_names) {
1611 for (i = 0; filenames[i] != NULL; ++i) {
1616 full_path = g_build_filename (path, filenames[i], NULL);
1617 if (g_stat (full_path, &s) < 0) {
1618 fhash = (guint) - 1;
1619 GST_LOG_OBJECT (plugin, "stat: %s (error: %s)", full_path,
1620 g_strerror (errno));
1622 fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
1623 GST_LOG_OBJECT (plugin, "stat: %s (result: %08x)", full_path, fhash);
1625 hash = (hash + fhash) << 1;
1629 hash = gst_plugin_ext_dep_scan_dir_and_match_names (plugin, path,
1630 filenames, flags, 0);
1637 gst_plugin_ext_dep_get_stat_hash (GstPlugin * plugin, GstPluginDep * dep)
1639 gboolean paths_are_default_only;
1640 GQueue scan_paths = G_QUEUE_INIT;
1641 guint scan_hash = 0;
1644 GST_LOG_OBJECT (plugin, "start");
1646 paths_are_default_only =
1647 dep->flags & GST_PLUGIN_DEPENDENCY_FLAG_PATHS_ARE_DEFAULT_ONLY;
1649 gst_plugin_ext_dep_extract_env_vars_paths (plugin, dep, &scan_paths);
1651 if (g_queue_is_empty (&scan_paths) || !paths_are_default_only) {
1654 for (paths = dep->paths; paths != NULL && *paths != NULL; ++paths) {
1655 const gchar *path = *paths;
1657 if (!g_queue_find_custom (&scan_paths, path, (GCompareFunc) strcmp)) {
1658 GST_LOG_OBJECT (plugin, "path: '%s'", path);
1659 g_queue_push_tail (&scan_paths, g_strdup (path));
1661 GST_LOG_OBJECT (plugin, "path: '%s' (duplicate, ignoring)", path);
1666 while ((path = g_queue_pop_head (&scan_paths))) {
1667 scan_hash += gst_plugin_ext_dep_scan_path_with_filenames (plugin, path,
1668 (const gchar **) dep->names, dep->flags);
1669 scan_hash = scan_hash << 1;
1673 GST_LOG_OBJECT (plugin, "done, scan_hash: %08x", scan_hash);
1678 _priv_plugin_deps_files_changed (GstPlugin * plugin)
1682 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1683 GstPluginDep *dep = l->data;
1685 if (dep->stat_hash != gst_plugin_ext_dep_get_stat_hash (plugin, dep))
1693 gst_plugin_ext_dep_free (GstPluginDep * dep)
1695 g_strfreev (dep->env_vars);
1696 g_strfreev (dep->paths);
1697 g_strfreev (dep->names);
1698 g_slice_free (GstPluginDep, dep);
1702 gst_plugin_ext_dep_strv_equal (gchar ** arr1, gchar ** arr2)
1706 if (arr1 == NULL || arr2 == NULL)
1708 for (; *arr1 != NULL && *arr2 != NULL; ++arr1, ++arr2) {
1709 if (strcmp (*arr1, *arr2) != 0)
1712 return (*arr1 == *arr2);
1716 gst_plugin_ext_dep_equals (GstPluginDep * dep, const gchar ** env_vars,
1717 const gchar ** paths, const gchar ** names, GstPluginDependencyFlags flags)
1719 if (dep->flags != flags)
1722 return gst_plugin_ext_dep_strv_equal (dep->env_vars, (gchar **) env_vars) &&
1723 gst_plugin_ext_dep_strv_equal (dep->paths, (gchar **) paths) &&
1724 gst_plugin_ext_dep_strv_equal (dep->names, (gchar **) names);
1728 * gst_plugin_add_dependency:
1729 * @plugin: a #GstPlugin
1730 * @env_vars: NULL-terminated array of environment variables affecting the
1731 * feature set of the plugin (e.g. an environment variable containing
1732 * paths where to look for additional modules/plugins of a library),
1733 * or NULL. Environment variable names may be followed by a path component
1734 * which will be added to the content of the environment variable, e.g.
1735 * "HOME/.mystuff/plugins".
1736 * @paths: NULL-terminated array of directories/paths where dependent files
1738 * @names: NULL-terminated array of file names (or file name suffixes,
1739 * depending on @flags) to be used in combination with the paths from
1740 * @paths and/or the paths extracted from the environment variables in
1741 * @env_vars, or NULL.
1742 * @flags: optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
1744 * Make GStreamer aware of external dependencies which affect the feature
1745 * set of this plugin (ie. the elements or typefinders associated with it).
1747 * GStreamer will re-inspect plugins with external dependencies whenever any
1748 * of the external dependencies change. This is useful for plugins which wrap
1749 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
1750 * library and makes visualisations available as GStreamer elements, or a
1751 * codec loader which exposes elements and/or caps dependent on what external
1752 * codec libraries are currently installed.
1757 gst_plugin_add_dependency (GstPlugin * plugin, const gchar ** env_vars,
1758 const gchar ** paths, const gchar ** names, GstPluginDependencyFlags flags)
1763 g_return_if_fail (GST_IS_PLUGIN (plugin));
1765 if ((env_vars == NULL || env_vars[0] == NULL) &&
1766 (paths == NULL || paths[0] == NULL)) {
1767 GST_DEBUG_OBJECT (plugin,
1768 "plugin registered empty dependency set. Ignoring");
1772 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1773 if (gst_plugin_ext_dep_equals (l->data, env_vars, paths, names, flags)) {
1774 GST_LOG_OBJECT (plugin, "dependency already registered");
1779 dep = g_slice_new (GstPluginDep);
1781 dep->env_vars = g_strdupv ((gchar **) env_vars);
1782 dep->paths = g_strdupv ((gchar **) paths);
1783 dep->names = g_strdupv ((gchar **) names);
1786 dep->env_hash = gst_plugin_ext_dep_get_env_vars_hash (plugin, dep);
1787 dep->stat_hash = gst_plugin_ext_dep_get_stat_hash (plugin, dep);
1789 plugin->priv->deps = g_list_append (plugin->priv->deps, dep);
1791 GST_DEBUG_OBJECT (plugin, "added dependency:");
1792 for (; env_vars != NULL && *env_vars != NULL; ++env_vars)
1793 GST_DEBUG_OBJECT (plugin, " evar: %s", *env_vars);
1794 for (; paths != NULL && *paths != NULL; ++paths)
1795 GST_DEBUG_OBJECT (plugin, " path: %s", *paths);
1796 for (; names != NULL && *names != NULL; ++names)
1797 GST_DEBUG_OBJECT (plugin, " name: %s", *names);
1801 * gst_plugin_add_dependency_simple:
1802 * @plugin: the #GstPlugin
1803 * @env_vars: one or more environment variables (separated by ':', ';' or ','),
1804 * or NULL. Environment variable names may be followed by a path component
1805 * which will be added to the content of the environment variable, e.g.
1806 * "HOME/.mystuff/plugins:MYSTUFF_PLUGINS_PATH"
1807 * @paths: one ore more directory paths (separated by ':' or ';' or ','),
1808 * or NULL. Example: "/usr/lib/mystuff/plugins"
1809 * @names: one or more file names or file name suffixes (separated by commas),
1811 * @flags: optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
1813 * Make GStreamer aware of external dependencies which affect the feature
1814 * set of this plugin (ie. the elements or typefinders associated with it).
1816 * GStreamer will re-inspect plugins with external dependencies whenever any
1817 * of the external dependencies change. This is useful for plugins which wrap
1818 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
1819 * library and makes visualisations available as GStreamer elements, or a
1820 * codec loader which exposes elements and/or caps dependent on what external
1821 * codec libraries are currently installed.
1823 * Convenience wrapper function for gst_plugin_add_dependency() which
1824 * takes simple strings as arguments instead of string arrays, with multiple
1825 * arguments separated by predefined delimiters (see above).
1830 gst_plugin_add_dependency_simple (GstPlugin * plugin,
1831 const gchar * env_vars, const gchar * paths, const gchar * names,
1832 GstPluginDependencyFlags flags)
1834 gchar **a_evars = NULL;
1835 gchar **a_paths = NULL;
1836 gchar **a_names = NULL;
1839 a_evars = g_strsplit_set (env_vars, ":;,", -1);
1841 a_paths = g_strsplit_set (paths, ":;,", -1);
1843 a_names = g_strsplit_set (names, ",", -1);
1845 gst_plugin_add_dependency (plugin, (const gchar **) a_evars,
1846 (const gchar **) a_paths, (const gchar **) a_names, flags);
1849 g_strfreev (a_evars);
1851 g_strfreev (a_paths);
1853 g_strfreev (a_names);