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 *const 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 *const *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 GMutex gst_plugin_loading_mutex;
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_mutex_lock (&gst_plugin_loading_mutex);
697 plugin = gst_registry_lookup (registry, filename);
699 if (plugin->module) {
701 g_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_mutex_unlock (&gst_plugin_loading_mutex);
845 gst_object_unref (plugin);
846 g_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_release_date_string:
997 * @plugin: plugin to get the release date of
999 * Get the release date (and possibly time) in form of a string, if available.
1001 * For normal GStreamer plugin releases this will usually just be a date in
1002 * the form of "YYYY-MM-DD", while pre-releases and builds from git may contain
1003 * a time component after the date as well, in which case the string will be
1004 * formatted like "YYYY-MM-DDTHH:MMZ" (e.g. "2012-04-30T09:30Z").
1006 * There may be plugins that do not have a valid release date set on them.
1008 * Returns: the date string of the plugin, or %NULL if not available.
1011 gst_plugin_get_release_date_string (GstPlugin * plugin)
1013 g_return_val_if_fail (plugin != NULL, NULL);
1015 return plugin->desc.release_datetime;
1019 * gst_plugin_is_loaded:
1020 * @plugin: plugin to query
1022 * queries if the plugin is loaded into memory
1024 * Returns: TRUE is loaded, FALSE otherwise
1027 gst_plugin_is_loaded (GstPlugin * plugin)
1029 g_return_val_if_fail (plugin != NULL, FALSE);
1031 return (plugin->module != NULL || plugin->filename == NULL);
1035 * gst_plugin_get_cache_data:
1038 * Gets the plugin specific data cache. If it is %NULL there is no cached data
1039 * stored. This is the case when the registry is getting rebuilt.
1041 * Returns: (transfer none): The cached data as a #GstStructure or %NULL.
1045 const GstStructure *
1046 gst_plugin_get_cache_data (GstPlugin * plugin)
1048 g_return_val_if_fail (GST_IS_PLUGIN (plugin), NULL);
1050 return plugin->priv->cache_data;
1054 * gst_plugin_set_cache_data:
1056 * @cache_data: (transfer full): a structure containing the data to cache
1058 * Adds plugin specific data to cache. Passes the ownership of the structure to
1061 * The cache is flushed every time the registry is rebuilt.
1066 gst_plugin_set_cache_data (GstPlugin * plugin, GstStructure * cache_data)
1068 g_return_if_fail (GST_IS_PLUGIN (plugin));
1069 g_return_if_fail (GST_IS_STRUCTURE (cache_data));
1071 if (plugin->priv->cache_data) {
1072 gst_structure_free (plugin->priv->cache_data);
1074 plugin->priv->cache_data = cache_data;
1079 * gst_plugin_feature_list:
1080 * @plugin: plugin to query
1081 * @filter: the filter to use
1082 * @first: only return first match
1083 * @user_data: user data passed to the filter function
1085 * Runs a filter against all plugin features and returns a GList with
1086 * the results. If the first flag is set, only the first match is
1087 * returned (as a list with a single object).
1089 * Returns: a GList of features, g_list_free after use.
1092 gst_plugin_feature_filter (GstPlugin * plugin,
1093 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
1098 list = gst_filter_run (plugin->features, (GstFilterFunc) filter, first,
1100 for (g = list; g; g = g->next) {
1101 gst_object_ref (plugin);
1109 GstPluginFeatureFilter filter;
1117 _feature_filter (GstPlugin * plugin, gpointer user_data)
1120 FeatureFilterData *data = (FeatureFilterData *) user_data;
1122 result = gst_plugin_feature_filter (plugin, data->filter, data->first,
1125 data->result = g_list_concat (data->result, result);
1132 * gst_plugin_list_feature_filter:
1133 * @list: a #GList of plugins to query
1134 * @filter: the filter function to use
1135 * @first: only return first match
1136 * @user_data: user data passed to the filter function
1138 * Runs a filter against all plugin features of the plugins in the given
1139 * list and returns a GList with the results.
1140 * If the first flag is set, only the first match is
1141 * returned (as a list with a single object).
1143 * Returns: a GList of features, g_list_free after use.
1146 gst_plugin_list_feature_filter (GList * list,
1147 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
1149 FeatureFilterData data;
1152 data.filter = filter;
1154 data.user_data = user_data;
1157 result = gst_filter_run (list, (GstFilterFunc) _feature_filter, first, &data);
1158 g_list_free (result);
1165 * gst_plugin_name_filter:
1166 * @plugin: the plugin to check
1167 * @name: the name of the plugin
1169 * A standard filter that returns TRUE when the plugin is of the
1172 * Returns: TRUE if the plugin is of the given name.
1175 gst_plugin_name_filter (GstPlugin * plugin, const gchar * name)
1177 return (plugin->desc.name && !strcmp (plugin->desc.name, name));
1182 * gst_plugin_find_feature:
1183 * @plugin: plugin to get the feature from
1184 * @name: The name of the feature to find
1185 * @type: The type of the feature to find
1187 * Find a feature of the given name and type in the given plugin.
1189 * Returns: a GstPluginFeature or NULL if the feature was not found.
1192 gst_plugin_find_feature (GstPlugin * plugin, const gchar * name, GType type)
1195 GstPluginFeature *result = NULL;
1196 GstTypeNameData data;
1198 g_return_val_if_fail (name != NULL, NULL);
1203 walk = gst_filter_run (plugin->features,
1204 (GstFilterFunc) gst_plugin_feature_type_name_filter, TRUE, &data);
1207 result = GST_PLUGIN_FEATURE (walk->data);
1209 gst_object_ref (result);
1210 gst_plugin_feature_list_free (walk);
1219 gst_plugin_feature_name_filter (GstPluginFeature * feature, const gchar * name)
1221 return !strcmp (name, GST_PLUGIN_FEATURE_NAME (feature));
1227 * gst_plugin_find_feature_by_name:
1228 * @plugin: plugin to get the feature from
1229 * @name: The name of the feature to find
1231 * Find a feature of the given name in the given plugin.
1233 * Returns: a GstPluginFeature or NULL if the feature was not found.
1236 gst_plugin_find_feature_by_name (GstPlugin * plugin, const gchar * name)
1239 GstPluginFeature *result = NULL;
1241 g_return_val_if_fail (name != NULL, NULL);
1243 walk = gst_filter_run (plugin->features,
1244 (GstFilterFunc) gst_plugin_feature_name_filter, TRUE, (void *) name);
1247 result = GST_PLUGIN_FEATURE (walk->data);
1249 gst_object_ref (result);
1250 gst_plugin_feature_list_free (walk);
1258 * gst_plugin_load_by_name:
1259 * @name: name of plugin to load
1261 * Load the named plugin. Refs the plugin.
1263 * Returns: (transfer full): a reference to a loaded plugin, or NULL on error.
1266 gst_plugin_load_by_name (const gchar * name)
1268 GstPlugin *plugin, *newplugin;
1269 GError *error = NULL;
1271 GST_DEBUG ("looking up plugin %s in default registry", name);
1272 plugin = gst_registry_find_plugin (gst_registry_get (), name);
1274 GST_DEBUG ("loading plugin %s from file %s", name, plugin->filename);
1275 newplugin = gst_plugin_load_file (plugin->filename, &error);
1276 gst_object_unref (plugin);
1279 GST_WARNING ("load_plugin error: %s", error->message);
1280 g_error_free (error);
1283 /* newplugin was reffed by load_file */
1287 GST_DEBUG ("Could not find plugin %s in registry", name);
1293 * @plugin: (transfer none): plugin to load
1295 * Loads @plugin. Note that the *return value* is the loaded plugin; @plugin is
1296 * untouched. The normal use pattern of this function goes like this:
1299 * GstPlugin *loaded_plugin;
1300 * loaded_plugin = gst_plugin_load (plugin);
1301 * // presumably, we're no longer interested in the potentially-unloaded plugin
1302 * gst_object_unref (plugin);
1303 * plugin = loaded_plugin;
1306 * Returns: (transfer full): a reference to a loaded plugin, or NULL on error.
1309 gst_plugin_load (GstPlugin * plugin)
1311 GError *error = NULL;
1312 GstPlugin *newplugin;
1314 if (gst_plugin_is_loaded (plugin)) {
1318 if (!(newplugin = gst_plugin_load_file (plugin->filename, &error)))
1325 GST_WARNING ("load_plugin error: %s", error->message);
1326 g_error_free (error);
1332 * gst_plugin_list_free:
1333 * @list: (transfer full) (element-type Gst.Plugin): list of #GstPlugin
1335 * Unrefs each member of @list, then frees the list.
1338 gst_plugin_list_free (GList * list)
1342 for (g = list; g; g = g->next) {
1343 gst_object_unref (GST_PLUGIN_CAST (g->data));
1348 /* ===== plugin dependencies ===== */
1351 * ENV + xyz where ENV can contain multiple values separated by SEPARATOR
1352 * xyz may be "" (if ENV contains path to file rather than dir)
1353 * ENV + *xyz same as above, but xyz acts as suffix filter
1354 * ENV + xyz* same as above, but xyz acts as prefix filter (is this needed?)
1355 * ENV + *xyz* same as above, but xyz acts as strstr filter (is this needed?)
1357 * same as above, with additional paths hard-coded at compile-time:
1358 * - only check paths + ... if ENV is not set or yields not paths
1359 * - always check paths + ... in addition to ENV
1361 * When user specifies set of environment variables, he/she may also use e.g.
1362 * "HOME/.mystuff/plugins", and we'll expand the content of $HOME with the
1366 /* we store in registry:
1369 * - environment variables (array of strings)
1370 * - last hash of env variable contents (uint) (so we can avoid doing stats
1371 * if one of the env vars has changed; premature optimisation galore)
1372 * - hard-coded paths (array of strings)
1373 * - xyz filename/suffix/prefix strings (array of strings)
1375 * - last hash of file/dir stats (int)
1377 * (= struct GstPluginDep)
1381 gst_plugin_ext_dep_get_env_vars_hash (GstPlugin * plugin, GstPluginDep * dep)
1386 /* there's no deeper logic to what we do here; all we want to know (when
1387 * checking if the plugin needs to be rescanned) is whether the content of
1388 * one of the environment variables in the list is different from when it
1389 * was last scanned */
1391 for (e = dep->env_vars; e != NULL && *e != NULL; ++e) {
1395 /* order matters: "val",NULL needs to yield a different hash than
1396 * NULL,"val", so do a shift here whether the var is set or not */
1399 /* want environment variable at beginning of string */
1400 if (!g_ascii_isalnum (**e)) {
1401 GST_WARNING_OBJECT (plugin, "string prefix is not a valid environment "
1402 "variable string: %s", *e);
1406 /* user is allowed to specify e.g. "HOME/.pitivi/plugins" */
1407 g_strlcpy (env_var, *e, sizeof (env_var));
1408 g_strdelimit (env_var, "/\\", '\0');
1410 if ((val = g_getenv (env_var)))
1411 hash += g_str_hash (val);
1418 _priv_plugin_deps_env_vars_changed (GstPlugin * plugin)
1422 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1423 GstPluginDep *dep = l->data;
1425 if (dep->env_hash != gst_plugin_ext_dep_get_env_vars_hash (plugin, dep))
1433 gst_plugin_ext_dep_extract_env_vars_paths (GstPlugin * plugin,
1434 GstPluginDep * dep, GQueue * paths)
1438 for (evars = dep->env_vars; evars != NULL && *evars != NULL; ++evars) {
1442 /* want environment variable at beginning of string */
1443 if (!g_ascii_isalnum (**evars)) {
1444 GST_WARNING_OBJECT (plugin, "string prefix is not a valid environment "
1445 "variable string: %s", *evars);
1449 /* user is allowed to specify e.g. "HOME/.pitivi/plugins", which we want to
1450 * split into the env_var name component and the path component */
1451 components = g_strsplit_set (*evars, "/\\", 2);
1452 g_assert (components != NULL);
1454 e = g_getenv (components[0]);
1455 GST_LOG_OBJECT (plugin, "expanding %s = '%s' (path suffix: %s)",
1456 components[0], GST_STR_NULL (e), GST_STR_NULL (components[1]));
1458 if (components[1] != NULL) {
1459 g_strdelimit (components[1], "/\\", G_DIR_SEPARATOR);
1462 if (e != NULL && *e != '\0') {
1466 arr = g_strsplit (e, G_SEARCHPATH_SEPARATOR_S, -1);
1468 for (i = 0; arr != NULL && arr[i] != NULL; ++i) {
1471 if (!g_path_is_absolute (arr[i])) {
1472 GST_INFO_OBJECT (plugin, "ignoring environment variable content '%s'"
1473 ": either not an absolute path or not a path at all", arr[i]);
1477 if (components[1] != NULL) {
1478 full_path = g_build_filename (arr[i], components[1], NULL);
1480 full_path = g_strdup (arr[i]);
1483 if (!g_queue_find_custom (paths, full_path, (GCompareFunc) strcmp)) {
1484 GST_LOG_OBJECT (plugin, "path: '%s'", full_path);
1485 g_queue_push_tail (paths, full_path);
1488 GST_LOG_OBJECT (plugin, "path: '%s' (duplicate,ignoring)", full_path);
1496 g_strfreev (components);
1499 GST_LOG_OBJECT (plugin, "Extracted %d paths from environment", paths->length);
1503 gst_plugin_ext_dep_get_hash_from_stat_entry (GStatBuf * s)
1505 if (!(s->st_mode & (S_IFDIR | S_IFREG)))
1508 /* completely random formula */
1509 return ((s->st_size << 3) + (s->st_mtime << 5)) ^ s->st_ctime;
1513 gst_plugin_ext_dep_direntry_matches (GstPlugin * plugin, const gchar * entry,
1514 const gchar ** filenames, GstPluginDependencyFlags flags)
1516 /* no filenames specified, match all entries for now (could probably
1517 * optimise by just taking the dir stat hash or so) */
1518 if (filenames == NULL || *filenames == NULL || **filenames == '\0')
1521 while (*filenames != NULL) {
1523 if (((flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX)) &&
1524 g_str_has_suffix (entry, *filenames)) {
1526 /* else it's an exact match that's needed */
1527 } else if (strcmp (entry, *filenames) == 0) {
1530 GST_LOG ("%s does not match %s, flags=0x%04x", entry, *filenames, flags);
1537 gst_plugin_ext_dep_scan_dir_and_match_names (GstPlugin * plugin,
1538 const gchar * path, const gchar ** filenames,
1539 GstPluginDependencyFlags flags, int depth)
1542 gboolean recurse_dirs;
1547 recurse_dirs = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
1549 dir = g_dir_open (path, 0, &err);
1551 GST_DEBUG_OBJECT (plugin, "g_dir_open(%s) failed: %s", path, err->message);
1556 /* FIXME: we're assuming here that we always get the directory entries in
1557 * the same order, and not in a random order */
1558 while ((entry = g_dir_read_name (dir))) {
1559 gboolean have_match;
1565 gst_plugin_ext_dep_direntry_matches (plugin, entry, filenames, flags);
1567 /* avoid the stat if possible */
1568 if (!have_match && !recurse_dirs)
1571 full_path = g_build_filename (path, entry, NULL);
1572 if (g_stat (full_path, &s) < 0) {
1573 fhash = (guint) - 1;
1574 GST_LOG_OBJECT (plugin, "stat: %s (error: %s)", full_path,
1575 g_strerror (errno));
1576 } else if (have_match) {
1577 fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
1578 GST_LOG_OBJECT (plugin, "stat: %s (result: %u)", full_path, fhash);
1579 } else if ((s.st_mode & (S_IFDIR))) {
1580 fhash = gst_plugin_ext_dep_scan_dir_and_match_names (plugin, full_path,
1581 filenames, flags, depth + 1);
1583 /* it's not a name match, we want to recurse, but it's not a directory */
1588 hash = (hash + fhash) << 1;
1597 gst_plugin_ext_dep_scan_path_with_filenames (GstPlugin * plugin,
1598 const gchar * path, const gchar ** filenames,
1599 GstPluginDependencyFlags flags)
1601 const gchar *empty_filenames[] = { "", NULL };
1602 gboolean recurse_into_dirs, partial_names;
1605 /* to avoid special-casing below (FIXME?) */
1606 if (filenames == NULL || *filenames == NULL)
1607 filenames = empty_filenames;
1609 recurse_into_dirs = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
1610 partial_names = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX);
1612 /* if we can construct the exact paths to check with the data we have, just
1613 * stat them one by one; this is more efficient than opening the directory
1614 * and going through each entry to see if it matches one of our filenames. */
1615 if (!recurse_into_dirs && !partial_names) {
1616 for (i = 0; filenames[i] != NULL; ++i) {
1621 full_path = g_build_filename (path, filenames[i], NULL);
1622 if (g_stat (full_path, &s) < 0) {
1623 fhash = (guint) - 1;
1624 GST_LOG_OBJECT (plugin, "stat: %s (error: %s)", full_path,
1625 g_strerror (errno));
1627 fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
1628 GST_LOG_OBJECT (plugin, "stat: %s (result: %08x)", full_path, fhash);
1630 hash = (hash + fhash) << 1;
1634 hash = gst_plugin_ext_dep_scan_dir_and_match_names (plugin, path,
1635 filenames, flags, 0);
1642 gst_plugin_ext_dep_get_stat_hash (GstPlugin * plugin, GstPluginDep * dep)
1644 gboolean paths_are_default_only;
1645 GQueue scan_paths = G_QUEUE_INIT;
1646 guint scan_hash = 0;
1649 GST_LOG_OBJECT (plugin, "start");
1651 paths_are_default_only =
1652 dep->flags & GST_PLUGIN_DEPENDENCY_FLAG_PATHS_ARE_DEFAULT_ONLY;
1654 gst_plugin_ext_dep_extract_env_vars_paths (plugin, dep, &scan_paths);
1656 if (g_queue_is_empty (&scan_paths) || !paths_are_default_only) {
1659 for (paths = dep->paths; paths != NULL && *paths != NULL; ++paths) {
1660 const gchar *path = *paths;
1662 if (!g_queue_find_custom (&scan_paths, path, (GCompareFunc) strcmp)) {
1663 GST_LOG_OBJECT (plugin, "path: '%s'", path);
1664 g_queue_push_tail (&scan_paths, g_strdup (path));
1666 GST_LOG_OBJECT (plugin, "path: '%s' (duplicate, ignoring)", path);
1671 while ((path = g_queue_pop_head (&scan_paths))) {
1672 scan_hash += gst_plugin_ext_dep_scan_path_with_filenames (plugin, path,
1673 (const gchar **) dep->names, dep->flags);
1674 scan_hash = scan_hash << 1;
1678 GST_LOG_OBJECT (plugin, "done, scan_hash: %08x", scan_hash);
1683 _priv_plugin_deps_files_changed (GstPlugin * plugin)
1687 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1688 GstPluginDep *dep = l->data;
1690 if (dep->stat_hash != gst_plugin_ext_dep_get_stat_hash (plugin, dep))
1698 gst_plugin_ext_dep_free (GstPluginDep * dep)
1700 g_strfreev (dep->env_vars);
1701 g_strfreev (dep->paths);
1702 g_strfreev (dep->names);
1703 g_slice_free (GstPluginDep, dep);
1707 gst_plugin_ext_dep_strv_equal (gchar ** arr1, gchar ** arr2)
1711 if (arr1 == NULL || arr2 == NULL)
1713 for (; *arr1 != NULL && *arr2 != NULL; ++arr1, ++arr2) {
1714 if (strcmp (*arr1, *arr2) != 0)
1717 return (*arr1 == *arr2);
1721 gst_plugin_ext_dep_equals (GstPluginDep * dep, const gchar ** env_vars,
1722 const gchar ** paths, const gchar ** names, GstPluginDependencyFlags flags)
1724 if (dep->flags != flags)
1727 return gst_plugin_ext_dep_strv_equal (dep->env_vars, (gchar **) env_vars) &&
1728 gst_plugin_ext_dep_strv_equal (dep->paths, (gchar **) paths) &&
1729 gst_plugin_ext_dep_strv_equal (dep->names, (gchar **) names);
1733 * gst_plugin_add_dependency:
1734 * @plugin: a #GstPlugin
1735 * @env_vars: NULL-terminated array of environment variables affecting the
1736 * feature set of the plugin (e.g. an environment variable containing
1737 * paths where to look for additional modules/plugins of a library),
1738 * or NULL. Environment variable names may be followed by a path component
1739 * which will be added to the content of the environment variable, e.g.
1740 * "HOME/.mystuff/plugins".
1741 * @paths: NULL-terminated array of directories/paths where dependent files
1743 * @names: NULL-terminated array of file names (or file name suffixes,
1744 * depending on @flags) to be used in combination with the paths from
1745 * @paths and/or the paths extracted from the environment variables in
1746 * @env_vars, or NULL.
1747 * @flags: optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
1749 * Make GStreamer aware of external dependencies which affect the feature
1750 * set of this plugin (ie. the elements or typefinders associated with it).
1752 * GStreamer will re-inspect plugins with external dependencies whenever any
1753 * of the external dependencies change. This is useful for plugins which wrap
1754 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
1755 * library and makes visualisations available as GStreamer elements, or a
1756 * codec loader which exposes elements and/or caps dependent on what external
1757 * codec libraries are currently installed.
1762 gst_plugin_add_dependency (GstPlugin * plugin, const gchar ** env_vars,
1763 const gchar ** paths, const gchar ** names, GstPluginDependencyFlags flags)
1768 g_return_if_fail (GST_IS_PLUGIN (plugin));
1770 if ((env_vars == NULL || env_vars[0] == NULL) &&
1771 (paths == NULL || paths[0] == NULL)) {
1772 GST_DEBUG_OBJECT (plugin,
1773 "plugin registered empty dependency set. Ignoring");
1777 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1778 if (gst_plugin_ext_dep_equals (l->data, env_vars, paths, names, flags)) {
1779 GST_LOG_OBJECT (plugin, "dependency already registered");
1784 dep = g_slice_new (GstPluginDep);
1786 dep->env_vars = g_strdupv ((gchar **) env_vars);
1787 dep->paths = g_strdupv ((gchar **) paths);
1788 dep->names = g_strdupv ((gchar **) names);
1791 dep->env_hash = gst_plugin_ext_dep_get_env_vars_hash (plugin, dep);
1792 dep->stat_hash = gst_plugin_ext_dep_get_stat_hash (plugin, dep);
1794 plugin->priv->deps = g_list_append (plugin->priv->deps, dep);
1796 GST_DEBUG_OBJECT (plugin, "added dependency:");
1797 for (; env_vars != NULL && *env_vars != NULL; ++env_vars)
1798 GST_DEBUG_OBJECT (plugin, " evar: %s", *env_vars);
1799 for (; paths != NULL && *paths != NULL; ++paths)
1800 GST_DEBUG_OBJECT (plugin, " path: %s", *paths);
1801 for (; names != NULL && *names != NULL; ++names)
1802 GST_DEBUG_OBJECT (plugin, " name: %s", *names);
1806 * gst_plugin_add_dependency_simple:
1807 * @plugin: the #GstPlugin
1808 * @env_vars: one or more environment variables (separated by ':', ';' or ','),
1809 * or NULL. Environment variable names may be followed by a path component
1810 * which will be added to the content of the environment variable, e.g.
1811 * "HOME/.mystuff/plugins:MYSTUFF_PLUGINS_PATH"
1812 * @paths: one ore more directory paths (separated by ':' or ';' or ','),
1813 * or NULL. Example: "/usr/lib/mystuff/plugins"
1814 * @names: one or more file names or file name suffixes (separated by commas),
1816 * @flags: optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
1818 * Make GStreamer aware of external dependencies which affect the feature
1819 * set of this plugin (ie. the elements or typefinders associated with it).
1821 * GStreamer will re-inspect plugins with external dependencies whenever any
1822 * of the external dependencies change. This is useful for plugins which wrap
1823 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
1824 * library and makes visualisations available as GStreamer elements, or a
1825 * codec loader which exposes elements and/or caps dependent on what external
1826 * codec libraries are currently installed.
1828 * Convenience wrapper function for gst_plugin_add_dependency() which
1829 * takes simple strings as arguments instead of string arrays, with multiple
1830 * arguments separated by predefined delimiters (see above).
1835 gst_plugin_add_dependency_simple (GstPlugin * plugin,
1836 const gchar * env_vars, const gchar * paths, const gchar * names,
1837 GstPluginDependencyFlags flags)
1839 gchar **a_evars = NULL;
1840 gchar **a_paths = NULL;
1841 gchar **a_names = NULL;
1844 a_evars = g_strsplit_set (env_vars, ":;,", -1);
1846 a_paths = g_strsplit_set (paths, ":;,", -1);
1848 a_names = g_strsplit_set (names, ",", -1);
1850 gst_plugin_add_dependency (plugin, (const gchar **) a_evars,
1851 (const gchar **) a_paths, (const gchar **) a_names, flags);
1854 g_strfreev (a_evars);
1856 g_strfreev (a_paths);
1858 g_strfreev (a_names);