2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstplugin.c: Plugin subsystem for loading elements, types, and libs
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
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 automatically 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 * Please file a bug to request any additional license be added.
85 * GPL: http://www.gnu.org/copyleft/gpl.html
86 * LGPL: http://www.gnu.org/copyleft/lesser.html
87 * QPL: http://www.trolltech.com/licenses/qpl.html
88 * MPL: http://www.opensource.org/licenses/mozilla1.1.php
89 * MIT/X11: http://www.opensource.org/licenses/mit-license.php
90 * 3-clause BSD: http://www.opensource.org/licenses/bsd-license.php
92 static const gchar valid_licenses[] = "LGPL\000" /* GNU Lesser General Public License */
93 "GPL\000" /* GNU General Public License */
94 "QPL\000" /* Trolltech Qt Public License */
95 "GPL/QPL\000" /* Combi-license of GPL + QPL */
96 "MPL\000" /* MPL 1.1 license */
97 "BSD\000" /* 3-clause BSD license */
98 "MIT/X11\000" /* MIT/X11 license */
99 "Proprietary\000" /* Proprietary license */
100 GST_LICENSE_UNKNOWN; /* some other license */
102 static const guint8 valid_licenses_idx[] = { 0, 5, 9, 13, 21, 25, 29, 37, 49 };
104 static GstPlugin *gst_plugin_register_func (GstPlugin * plugin,
105 const GstPluginDesc * desc, gpointer user_data);
106 static void gst_plugin_desc_copy (GstPluginDesc * dest,
107 const GstPluginDesc * src);
109 static void gst_plugin_ext_dep_free (GstPluginDep * dep);
111 G_DEFINE_TYPE (GstPlugin, gst_plugin, GST_TYPE_OBJECT);
114 gst_plugin_init (GstPlugin * plugin)
117 G_TYPE_INSTANCE_GET_PRIVATE (plugin, GST_TYPE_PLUGIN, GstPluginPrivate);
121 gst_plugin_finalize (GObject * object)
123 GstPlugin *plugin = GST_PLUGIN_CAST (object);
125 GST_DEBUG ("finalizing plugin %" GST_PTR_FORMAT, plugin);
127 /* FIXME: make registry add a weak ref instead */
129 GstRegistry *registry = gst_registry_get ();
131 for (g = registry->plugins; g; g = g->next) {
132 if (g->data == (gpointer) plugin) {
133 g_warning ("removing plugin that is still in registry");
138 g_free (plugin->filename);
139 g_free (plugin->basename);
141 g_list_foreach (plugin->priv->deps, (GFunc) gst_plugin_ext_dep_free, NULL);
142 g_list_free (plugin->priv->deps);
143 plugin->priv->deps = NULL;
145 if (plugin->priv->cache_data) {
146 gst_structure_free (plugin->priv->cache_data);
149 G_OBJECT_CLASS (gst_plugin_parent_class)->finalize (object);
153 gst_plugin_class_init (GstPluginClass * klass)
155 G_OBJECT_CLASS (klass)->finalize = gst_plugin_finalize;
157 g_type_class_add_private (klass, sizeof (GstPluginPrivate));
161 gst_plugin_error_quark (void)
163 static GQuark quark = 0;
166 quark = g_quark_from_static_string ("gst_plugin_error");
171 * gst_plugin_register_static:
172 * @major_version: the major version number of the GStreamer core that the
173 * plugin was compiled for, you can just use GST_VERSION_MAJOR here
174 * @minor_version: the minor version number of the GStreamer core that the
175 * plugin was compiled for, you can just use GST_VERSION_MINOR here
176 * @name: a unique name of the plugin (ideally prefixed with an application- or
177 * library-specific namespace prefix in order to avoid name conflicts in
178 * case a similar plugin with the same name ever gets added to GStreamer)
179 * @description: description of the plugin
180 * @init_func: (scope call): pointer to the init function of this plugin.
181 * @version: version string of the plugin
182 * @license: effective license of plugin. Must be one of the approved licenses
183 * (see #GstPluginDesc above) or the plugin will not be registered.
184 * @source: source module plugin belongs to
185 * @package: shipped package plugin belongs to
186 * @origin: URL to provider of plugin
188 * Registers a static plugin, ie. a plugin which is private to an application
189 * or library and contained within the application or library (as opposed to
190 * being shipped as a separate module file).
192 * You must make sure that GStreamer has been initialised (with gst_init() or
193 * via gst_init_get_option_group()) before calling this function.
195 * Returns: %TRUE if the plugin was registered correctly, otherwise %FALSE.
198 gst_plugin_register_static (gint major_version, gint minor_version,
199 const gchar * name, const gchar * description, GstPluginInitFunc init_func,
200 const gchar * version, const gchar * license, const gchar * source,
201 const gchar * package, const gchar * origin)
203 GstPluginDesc desc = { major_version, minor_version, name, description,
204 init_func, version, license, source, package, origin, NULL,
207 gboolean res = FALSE;
209 g_return_val_if_fail (name != NULL, FALSE);
210 g_return_val_if_fail (description != NULL, FALSE);
211 g_return_val_if_fail (init_func != NULL, FALSE);
212 g_return_val_if_fail (version != NULL, FALSE);
213 g_return_val_if_fail (license != NULL, FALSE);
214 g_return_val_if_fail (source != NULL, FALSE);
215 g_return_val_if_fail (package != NULL, FALSE);
216 g_return_val_if_fail (origin != NULL, FALSE);
218 /* make sure gst_init() has been called */
219 g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
221 GST_LOG ("attempting to load static plugin \"%s\" now...", name);
222 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
223 if (gst_plugin_register_func (plugin, &desc, NULL) != NULL) {
224 GST_INFO ("registered static plugin \"%s\"", name);
225 res = gst_registry_add_plugin (gst_registry_get (), plugin);
226 GST_INFO ("added static plugin \"%s\", result: %d", name, res);
232 * gst_plugin_register_static_full:
233 * @major_version: the major version number of the GStreamer core that the
234 * plugin was compiled for, you can just use GST_VERSION_MAJOR here
235 * @minor_version: the minor version number of the GStreamer core that the
236 * plugin was compiled for, you can just use GST_VERSION_MINOR here
237 * @name: a unique name of the plugin (ideally prefixed with an application- or
238 * library-specific namespace prefix in order to avoid name conflicts in
239 * case a similar plugin with the same name ever gets added to GStreamer)
240 * @description: description of the plugin
241 * @init_full_func: (scope call): pointer to the init function with user data
243 * @version: version string of the plugin
244 * @license: effective license of plugin. Must be one of the approved licenses
245 * (see #GstPluginDesc above) or the plugin will not be registered.
246 * @source: source module plugin belongs to
247 * @package: shipped package plugin belongs to
248 * @origin: URL to provider of plugin
249 * @user_data: gpointer to user data
251 * Registers a static plugin, ie. a plugin which is private to an application
252 * or library and contained within the application or library (as opposed to
253 * being shipped as a separate module file) with a #GstPluginInitFullFunc
254 * which allows user data to be passed to the callback function (useful
257 * You must make sure that GStreamer has been initialised (with gst_init() or
258 * via gst_init_get_option_group()) before calling this function.
260 * Returns: %TRUE if the plugin was registered correctly, otherwise %FALSE.
263 gst_plugin_register_static_full (gint major_version, gint minor_version,
264 const gchar * name, const gchar * description,
265 GstPluginInitFullFunc init_full_func, const gchar * version,
266 const gchar * license, const gchar * source, const gchar * package,
267 const gchar * origin, gpointer user_data)
269 GstPluginDesc desc = { major_version, minor_version, name, description,
270 (GstPluginInitFunc) init_full_func, version, license, source, package,
274 gboolean res = FALSE;
276 g_return_val_if_fail (name != NULL, FALSE);
277 g_return_val_if_fail (description != NULL, FALSE);
278 g_return_val_if_fail (init_full_func != NULL, FALSE);
279 g_return_val_if_fail (version != NULL, FALSE);
280 g_return_val_if_fail (license != NULL, FALSE);
281 g_return_val_if_fail (source != NULL, FALSE);
282 g_return_val_if_fail (package != NULL, FALSE);
283 g_return_val_if_fail (origin != NULL, FALSE);
285 /* make sure gst_init() has been called */
286 g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
288 GST_LOG ("attempting to load static plugin \"%s\" now...", name);
289 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
290 if (gst_plugin_register_func (plugin, &desc, user_data) != NULL) {
291 GST_INFO ("registered static plugin \"%s\"", name);
292 res = gst_registry_add_plugin (gst_registry_get (), plugin);
293 GST_INFO ("added static plugin \"%s\", result: %d", name, res);
299 _priv_gst_plugin_initialize (void)
301 const gchar *whitelist;
304 _gst_plugin_inited = TRUE;
306 whitelist = g_getenv ("GST_PLUGIN_LOADING_WHITELIST");
307 if (whitelist != NULL && *whitelist != '\0') {
308 _plugin_loading_whitelist = g_strsplit (whitelist,
309 G_SEARCHPATH_SEPARATOR_S, -1);
310 for (i = 0; _plugin_loading_whitelist[i] != NULL; ++i) {
311 GST_INFO ("plugins whitelist entry: %s", _plugin_loading_whitelist[i]);
315 /* now register all static plugins */
316 GST_INFO ("registering %u static plugins", _num_static_plugins);
317 for (i = 0; i < _num_static_plugins; ++i) {
318 gst_plugin_register_static (_static_plugins[i].major_version,
319 _static_plugins[i].minor_version, _static_plugins[i].name,
320 _static_plugins[i].description, _static_plugins[i].plugin_init,
321 _static_plugins[i].version, _static_plugins[i].license,
322 _static_plugins[i].source, _static_plugins[i].package,
323 _static_plugins[i].origin);
326 if (_static_plugins) {
327 free (_static_plugins);
328 _static_plugins = NULL;
329 _num_static_plugins = 0;
333 /* Whitelist entry format:
335 * plugin1,plugin2@pathprefix or
336 * plugin1,plugin2@* or just
338 * source-package@pathprefix or
339 * source-package@* or just
342 * ie. the bit before the path will be checked against both the plugin
343 * name and the plugin's source package name, to keep the format simple.
346 gst_plugin_desc_matches_whitelist_entry (GstPluginDesc * desc,
347 const gchar * filename, const gchar * pattern)
350 gboolean ret = FALSE;
353 GST_LOG ("Whitelist pattern '%s', plugin: %s of %s@%s", pattern, desc->name,
354 desc->source, GST_STR_NULL (filename));
356 /* do we have a path prefix? */
357 sep = strchr (pattern, '@');
358 if (sep != NULL && strcmp (sep, "@*") != 0 && strcmp (sep, "@") != 0) {
359 /* paths are not canonicalised or treated with realpath() here. This
360 * should be good enough for our use case, since we just use the paths
361 * autotools uses, and those will be constructed from the same prefix. */
362 if (filename != NULL && !g_str_has_prefix (filename, sep + 1))
365 GST_LOG ("%s matches path prefix %s", GST_STR_NULL (filename), sep + 1);
369 name = g_strndup (pattern, (gsize) (sep - pattern));
371 name = g_strdup (pattern);
375 if (!g_ascii_isalnum (*name)) {
376 GST_WARNING ("Invalid whitelist pattern: %s", pattern);
380 /* now check plugin names / source package name */
381 if (strchr (name, ',') == NULL) {
382 /* only a single name: either a plugin name or the source package name */
383 ret = (strcmp (desc->source, name) == 0 || strcmp (desc->name, name) == 0);
387 /* multiple names: assume these are plugin names */
388 names = g_strsplit (name, ",", -1);
389 for (n = names; n != NULL && *n != NULL; ++n) {
391 if (strcmp (desc->name, *n) == 0) {
399 GST_LOG ("plugin / source package name match: %d", ret);
408 priv_gst_plugin_desc_is_whitelisted (GstPluginDesc * desc,
409 const gchar * filename)
413 if (_plugin_loading_whitelist == NULL)
416 for (entry = _plugin_loading_whitelist; *entry != NULL; ++entry) {
417 if (gst_plugin_desc_matches_whitelist_entry (desc, filename, *entry)) {
418 GST_LOG ("Plugin %s is in whitelist", filename);
423 GST_LOG ("Plugin %s (package %s, file %s) not in whitelist", desc->name,
424 desc->source, filename);
429 priv_gst_plugin_loading_have_whitelist (void)
431 return (_plugin_loading_whitelist != NULL);
435 priv_gst_plugin_loading_get_whitelist_hash (void)
439 if (_plugin_loading_whitelist != NULL) {
442 for (w = _plugin_loading_whitelist; *w != NULL; ++w)
443 hash = (hash << 1) ^ g_str_hash (*w);
449 /* this function could be extended to check if the plugin license matches the
450 * applications license (would require the app to register its license somehow).
451 * We'll wait for someone who's interested in it to code it :)
454 gst_plugin_check_license (const gchar * license)
458 for (i = 0; i < G_N_ELEMENTS (valid_licenses_idx); ++i) {
459 if (strcmp (license, valid_licenses + valid_licenses_idx[i]) == 0)
466 gst_plugin_check_version (gint major, gint minor)
468 /* return NULL if the major and minor version numbers are not compatible */
470 if (major != GST_VERSION_MAJOR || minor > GST_VERSION_MINOR)
477 gst_plugin_register_func (GstPlugin * plugin, const GstPluginDesc * desc,
480 if (!gst_plugin_check_version (desc->major_version, desc->minor_version)) {
482 GST_WARNING ("plugin \"%s\" has incompatible version "
483 "(plugin: %d.%d, gst: %d,%d), not loading",
484 GST_STR_NULL (plugin->filename), desc->major_version,
485 desc->minor_version, GST_VERSION_MAJOR, GST_VERSION_MINOR);
489 if (!desc->license || !desc->description || !desc->source ||
490 !desc->package || !desc->origin) {
492 GST_WARNING ("plugin \"%s\" has missing detail in GstPluginDesc, not "
493 "loading", GST_STR_NULL (plugin->filename));
497 if (!gst_plugin_check_license (desc->license)) {
499 GST_WARNING ("plugin \"%s\" has invalid license \"%s\", not loading",
500 GST_STR_NULL (plugin->filename), desc->license);
505 GST_LOG ("plugin \"%s\" looks good", GST_STR_NULL (plugin->filename));
507 gst_plugin_desc_copy (&plugin->desc, desc);
509 /* make resident so we're really sure it never gets unloaded again.
510 * Theoretically this is not needed, but practically it doesn't hurt.
511 * And we're rather safe than sorry. */
513 g_module_make_resident (plugin->module);
516 if (!(((GstPluginInitFullFunc) (desc->plugin_init)) (plugin, user_data))) {
518 GST_WARNING ("plugin \"%s\" failed to initialise",
519 GST_STR_NULL (plugin->filename));
523 if (!((desc->plugin_init) (plugin))) {
525 GST_WARNING ("plugin \"%s\" failed to initialise",
526 GST_STR_NULL (plugin->filename));
532 GST_LOG ("plugin \"%s\" initialised", GST_STR_NULL (plugin->filename));
537 #ifdef HAVE_SIGACTION
538 static struct sigaction oldaction;
539 static gboolean _gst_plugin_fault_handler_is_setup = FALSE;
542 * _gst_plugin_fault_handler_restore:
543 * segfault handler restorer
546 _gst_plugin_fault_handler_restore (void)
548 if (!_gst_plugin_fault_handler_is_setup)
551 _gst_plugin_fault_handler_is_setup = FALSE;
553 sigaction (SIGSEGV, &oldaction, NULL);
557 * _gst_plugin_fault_handler_sighandler:
558 * segfault handler implementation
561 _gst_plugin_fault_handler_sighandler (int signum)
563 /* We need to restore the fault handler or we'll keep getting it */
564 _gst_plugin_fault_handler_restore ();
568 g_print ("\nERROR: ");
569 g_print ("Caught a segmentation fault while loading plugin file:\n");
570 g_print ("%s\n\n", _gst_plugin_fault_handler_filename);
571 g_print ("Please either:\n");
572 g_print ("- remove it and restart.\n");
574 ("- run with --gst-disable-segtrap --gst-disable-registry-fork and debug.\n");
578 g_print ("Caught unhandled signal on plugin loading\n");
584 * _gst_plugin_fault_handler_setup:
585 * sets up the segfault handler
588 _gst_plugin_fault_handler_setup (void)
590 struct sigaction action;
592 /* if asked to leave segfaults alone, just return */
593 if (!gst_segtrap_is_enabled ())
596 if (_gst_plugin_fault_handler_is_setup)
599 _gst_plugin_fault_handler_is_setup = TRUE;
601 memset (&action, 0, sizeof (action));
602 action.sa_handler = _gst_plugin_fault_handler_sighandler;
604 sigaction (SIGSEGV, &action, &oldaction);
606 #else /* !HAVE_SIGACTION */
608 _gst_plugin_fault_handler_restore (void)
613 _gst_plugin_fault_handler_setup (void)
616 #endif /* HAVE_SIGACTION */
618 /* g_time_val_from_iso8601() doesn't do quite what we want */
620 check_release_datetime (const gchar * date_time)
624 /* we require YYYY-MM-DD or YYYY-MM-DDTHH:MMZ format */
625 if (!g_ascii_isdigit (*date_time))
628 val = g_ascii_strtoull (date_time, (gchar **) & date_time, 10);
629 if (val < 2000 || val > 2100 || *date_time != '-')
632 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
633 if (val == 0 || val > 12 || *date_time != '-')
636 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
637 if (val == 0 || val > 32)
640 /* end of string or date/time separator + HH:MMZ */
641 if (*date_time == 'T' || *date_time == ' ') {
642 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
643 if (val > 24 || *date_time != ':')
646 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
647 if (val > 59 || *date_time != 'Z')
653 return (*date_time == '\0');
656 static GMutex gst_plugin_loading_mutex;
658 #define CHECK_PLUGIN_DESC_FIELD(desc,field,fn) \
659 if (G_UNLIKELY ((desc)->field == NULL || *(desc)->field == '\0')) { \
660 g_warning ("Plugin description for '%s' has no valid %s field", fn, G_STRINGIFY (field)); \
661 g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, \
662 "Plugin %s has invalid plugin description field '%s'", \
663 filename, G_STRINGIFY (field)); \
668 * gst_plugin_load_file:
669 * @filename: the plugin filename to load
670 * @error: pointer to a %NULL-valued GError
672 * Loads the given plugin and refs it. Caller needs to unref after use.
674 * Returns: (transfer full): a reference to the existing loaded GstPlugin, a
675 * reference to the newly-loaded GstPlugin, or %NULL if an error occurred.
678 gst_plugin_load_file (const gchar * filename, GError ** error)
685 GStatBuf file_status;
686 GstRegistry *registry;
687 gboolean new_plugin = TRUE;
690 g_return_val_if_fail (filename != NULL, NULL);
692 registry = gst_registry_get ();
693 g_mutex_lock (&gst_plugin_loading_mutex);
695 plugin = gst_registry_lookup (registry, filename);
697 if (plugin->module) {
699 g_mutex_unlock (&gst_plugin_loading_mutex);
702 /* load plugin and update fields */
707 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "attempt to load plugin \"%s\"",
710 if (!g_module_supported ()) {
711 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "module loading not supported");
714 GST_PLUGIN_ERROR_MODULE, "Dynamic loading not supported");
718 if (g_stat (filename, &file_status)) {
719 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "problem accessing file");
722 GST_PLUGIN_ERROR_MODULE, "Problem accessing file %s: %s", filename,
727 flags = G_MODULE_BIND_LOCAL;
728 /* libgstpython.so is the gst-python plugin loader. It needs to be loaded with
729 * G_MODULE_BIND_LAZY.
731 * Ideally there should be a generic way for plugins to specify that they
732 * need to be loaded with _LAZY.
734 if (strstr (filename, "libgstpython"))
735 flags |= G_MODULE_BIND_LAZY;
737 module = g_module_open (filename, flags);
738 if (module == NULL) {
739 GST_CAT_WARNING (GST_CAT_PLUGIN_LOADING, "module_open failed: %s",
742 GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "Opening module failed: %s",
744 /* If we failed to open the shared object, then it's probably because a
745 * plugin is linked against the wrong libraries. Print out an easy-to-see
746 * message in this case. */
747 g_warning ("Failed to load plugin '%s': %s", filename, g_module_error ());
751 ret = g_module_symbol (module, "gst_plugin_desc", &ptr);
753 GST_DEBUG ("Could not find plugin entry point in \"%s\"", filename);
756 GST_PLUGIN_ERROR_MODULE,
757 "File \"%s\" is not a GStreamer plugin", filename);
758 g_module_close (module);
762 desc = (GstPluginDesc *) ptr;
764 if (priv_gst_plugin_loading_have_whitelist () &&
765 !priv_gst_plugin_desc_is_whitelisted (desc, filename)) {
766 GST_INFO ("Whitelist specified and plugin not in whitelist, not loading: "
767 "name=%s, package=%s, file=%s", desc->name, desc->source, filename);
768 g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE,
769 "Not loading plugin file \"%s\", not in whitelist", filename);
770 g_module_close (module);
775 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
776 plugin->file_mtime = file_status.st_mtime;
777 plugin->file_size = file_status.st_size;
778 plugin->filename = g_strdup (filename);
779 plugin->basename = g_path_get_basename (filename);
782 plugin->module = module;
783 plugin->orig_desc = desc;
786 /* check plugin description: complain about bad values and fail */
787 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, name, filename);
788 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, description, filename);
789 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, version, filename);
790 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, license, filename);
791 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, source, filename);
792 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, package, filename);
793 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, origin, filename);
795 if (plugin->orig_desc->name != NULL && plugin->orig_desc->name[0] == '"') {
796 g_warning ("Invalid plugin name '%s' - fix your GST_PLUGIN_DEFINE "
797 "(remove quotes around plugin name)", plugin->orig_desc->name);
800 if (plugin->orig_desc->release_datetime != NULL &&
801 !check_release_datetime (plugin->orig_desc->release_datetime)) {
802 GST_ERROR ("GstPluginDesc for '%s' has invalid datetime '%s'",
803 filename, plugin->orig_desc->release_datetime);
804 plugin->orig_desc->release_datetime = NULL;
808 GST_LOG ("Plugin %p for file \"%s\" prepared, calling entry function...",
811 /* this is where we load the actual .so, so let's trap SIGSEGV */
812 _gst_plugin_fault_handler_setup ();
813 _gst_plugin_fault_handler_filename = plugin->filename;
815 GST_LOG ("Plugin %p for file \"%s\" prepared, registering...",
818 if (!gst_plugin_register_func (plugin, plugin->orig_desc, NULL)) {
819 /* remove signal handler */
820 _gst_plugin_fault_handler_restore ();
821 GST_DEBUG ("gst_plugin_register_func failed for plugin \"%s\"", filename);
825 GST_PLUGIN_ERROR_MODULE,
826 "File \"%s\" appears to be a GStreamer plugin, but it failed to initialize",
831 /* remove signal handler */
832 _gst_plugin_fault_handler_restore ();
833 _gst_plugin_fault_handler_filename = NULL;
834 GST_INFO ("plugin \"%s\" loaded", plugin->filename);
837 gst_object_ref (plugin);
838 gst_registry_add_plugin (gst_registry_get (), plugin);
841 g_mutex_unlock (&gst_plugin_loading_mutex);
847 gst_object_unref (plugin);
848 g_mutex_unlock (&gst_plugin_loading_mutex);
854 gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src)
856 dest->major_version = src->major_version;
857 dest->minor_version = src->minor_version;
858 dest->name = g_intern_string (src->name);
859 dest->description = g_intern_string (src->description);
860 dest->plugin_init = src->plugin_init;
861 dest->version = g_intern_string (src->version);
862 dest->license = g_intern_string (src->license);
863 dest->source = g_intern_string (src->source);
864 dest->package = g_intern_string (src->package);
865 dest->origin = g_intern_string (src->origin);
866 dest->release_datetime = g_intern_string (src->release_datetime);
870 * gst_plugin_get_name:
871 * @plugin: plugin to get the name of
873 * Get the short name of the plugin
875 * Returns: the name of the plugin
878 gst_plugin_get_name (GstPlugin * plugin)
880 g_return_val_if_fail (plugin != NULL, NULL);
882 return plugin->desc.name;
886 * gst_plugin_get_description:
887 * @plugin: plugin to get long name of
889 * Get the long descriptive name of the plugin
891 * Returns: the long name of the plugin
894 gst_plugin_get_description (GstPlugin * plugin)
896 g_return_val_if_fail (plugin != NULL, NULL);
898 return plugin->desc.description;
902 * gst_plugin_get_filename:
903 * @plugin: plugin to get the filename of
905 * get the filename of the plugin
907 * Returns: the filename of the plugin
910 gst_plugin_get_filename (GstPlugin * plugin)
912 g_return_val_if_fail (plugin != NULL, NULL);
914 return plugin->filename;
918 * gst_plugin_get_version:
919 * @plugin: plugin to get the version of
921 * get the version of the plugin
923 * Returns: the version of the plugin
926 gst_plugin_get_version (GstPlugin * plugin)
928 g_return_val_if_fail (plugin != NULL, NULL);
930 return plugin->desc.version;
934 * gst_plugin_get_license:
935 * @plugin: plugin to get the license of
937 * get the license of the plugin
939 * Returns: the license of the plugin
942 gst_plugin_get_license (GstPlugin * plugin)
944 g_return_val_if_fail (plugin != NULL, NULL);
946 return plugin->desc.license;
950 * gst_plugin_get_source:
951 * @plugin: plugin to get the source of
953 * get the source module the plugin belongs to.
955 * Returns: the source of the plugin
958 gst_plugin_get_source (GstPlugin * plugin)
960 g_return_val_if_fail (plugin != NULL, NULL);
962 return plugin->desc.source;
966 * gst_plugin_get_package:
967 * @plugin: plugin to get the package of
969 * get the package the plugin belongs to.
971 * Returns: the package of the plugin
974 gst_plugin_get_package (GstPlugin * plugin)
976 g_return_val_if_fail (plugin != NULL, NULL);
978 return plugin->desc.package;
982 * gst_plugin_get_origin:
983 * @plugin: plugin to get the origin of
985 * get the URL where the plugin comes from
987 * Returns: the origin of the plugin
990 gst_plugin_get_origin (GstPlugin * plugin)
992 g_return_val_if_fail (plugin != NULL, NULL);
994 return plugin->desc.origin;
998 * gst_plugin_get_release_date_string:
999 * @plugin: plugin to get the release date of
1001 * Get the release date (and possibly time) in form of a string, if available.
1003 * For normal GStreamer plugin releases this will usually just be a date in
1004 * the form of "YYYY-MM-DD", while pre-releases and builds from git may contain
1005 * a time component after the date as well, in which case the string will be
1006 * formatted like "YYYY-MM-DDTHH:MMZ" (e.g. "2012-04-30T09:30Z").
1008 * There may be plugins that do not have a valid release date set on them.
1010 * Returns: (nullable): the date string of the plugin, or %NULL if not
1014 gst_plugin_get_release_date_string (GstPlugin * plugin)
1016 g_return_val_if_fail (plugin != NULL, NULL);
1018 return plugin->desc.release_datetime;
1022 * gst_plugin_is_loaded:
1023 * @plugin: plugin to query
1025 * queries if the plugin is loaded into memory
1027 * Returns: %TRUE is loaded, %FALSE otherwise
1030 gst_plugin_is_loaded (GstPlugin * plugin)
1032 g_return_val_if_fail (plugin != NULL, FALSE);
1034 return (plugin->module != NULL || plugin->filename == NULL);
1038 * gst_plugin_get_cache_data:
1041 * Gets the plugin specific data cache. If it is %NULL there is no cached data
1042 * stored. This is the case when the registry is getting rebuilt.
1044 * Returns: (transfer none) (nullable): The cached data as a
1045 * #GstStructure or %NULL.
1047 const GstStructure *
1048 gst_plugin_get_cache_data (GstPlugin * plugin)
1050 g_return_val_if_fail (GST_IS_PLUGIN (plugin), NULL);
1052 return plugin->priv->cache_data;
1056 * gst_plugin_set_cache_data:
1058 * @cache_data: (transfer full): a structure containing the data to cache
1060 * Adds plugin specific data to cache. Passes the ownership of the structure to
1063 * 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);
1164 * gst_plugin_find_feature:
1165 * @plugin: plugin to get the feature from
1166 * @name: The name of the feature to find
1167 * @type: The type of the feature to find
1169 * Find a feature of the given name and type in the given plugin.
1171 * Returns: a GstPluginFeature or %NULL if the feature was not found.
1174 gst_plugin_find_feature (GstPlugin * plugin, const gchar * name, GType type)
1177 GstPluginFeature *result = NULL;
1178 GstTypeNameData data;
1180 g_return_val_if_fail (name != NULL, NULL);
1185 walk = gst_filter_run (plugin->features,
1186 (GstFilterFunc) gst_plugin_feature_type_name_filter, TRUE, &data);
1189 result = GST_PLUGIN_FEATURE (walk->data);
1191 gst_object_ref (result);
1192 gst_plugin_feature_list_free (walk);
1201 gst_plugin_feature_name_filter (GstPluginFeature * feature, const gchar * name)
1203 return !strcmp (name, GST_PLUGIN_FEATURE_NAME (feature));
1209 * gst_plugin_find_feature_by_name:
1210 * @plugin: plugin to get the feature from
1211 * @name: The name of the feature to find
1213 * Find a feature of the given name in the given plugin.
1215 * Returns: a GstPluginFeature or %NULL if the feature was not found.
1218 gst_plugin_find_feature_by_name (GstPlugin * plugin, const gchar * name)
1221 GstPluginFeature *result = NULL;
1223 g_return_val_if_fail (name != NULL, NULL);
1225 walk = gst_filter_run (plugin->features,
1226 (GstFilterFunc) gst_plugin_feature_name_filter, TRUE, (void *) name);
1229 result = GST_PLUGIN_FEATURE (walk->data);
1231 gst_object_ref (result);
1232 gst_plugin_feature_list_free (walk);
1240 * gst_plugin_load_by_name:
1241 * @name: name of plugin to load
1243 * Load the named plugin. Refs the plugin.
1245 * Returns: (transfer full): a reference to a loaded plugin, or %NULL on error.
1248 gst_plugin_load_by_name (const gchar * name)
1250 GstPlugin *plugin, *newplugin;
1251 GError *error = NULL;
1253 GST_DEBUG ("looking up plugin %s in default registry", name);
1254 plugin = gst_registry_find_plugin (gst_registry_get (), name);
1256 GST_DEBUG ("loading plugin %s from file %s", name, plugin->filename);
1257 newplugin = gst_plugin_load_file (plugin->filename, &error);
1258 gst_object_unref (plugin);
1261 GST_WARNING ("load_plugin error: %s", error->message);
1262 g_error_free (error);
1265 /* newplugin was reffed by load_file */
1269 GST_DEBUG ("Could not find plugin %s in registry", name);
1275 * @plugin: (transfer none): plugin to load
1277 * Loads @plugin. Note that the *return value* is the loaded plugin; @plugin is
1278 * untouched. The normal use pattern of this function goes like this:
1281 * GstPlugin *loaded_plugin;
1282 * loaded_plugin = gst_plugin_load (plugin);
1283 * // presumably, we're no longer interested in the potentially-unloaded plugin
1284 * gst_object_unref (plugin);
1285 * plugin = loaded_plugin;
1288 * Returns: (transfer full): a reference to a loaded plugin, or %NULL on error.
1291 gst_plugin_load (GstPlugin * plugin)
1293 GError *error = NULL;
1294 GstPlugin *newplugin;
1296 if (gst_plugin_is_loaded (plugin)) {
1300 if (!(newplugin = gst_plugin_load_file (plugin->filename, &error)))
1307 GST_WARNING ("load_plugin error: %s", error->message);
1308 g_error_free (error);
1314 * gst_plugin_list_free:
1315 * @list: (transfer full) (element-type Gst.Plugin): list of #GstPlugin
1317 * Unrefs each member of @list, then frees the list.
1320 gst_plugin_list_free (GList * list)
1324 for (g = list; g; g = g->next) {
1325 gst_object_unref (GST_PLUGIN_CAST (g->data));
1330 /* ===== plugin dependencies ===== */
1333 * ENV + xyz where ENV can contain multiple values separated by SEPARATOR
1334 * xyz may be "" (if ENV contains path to file rather than dir)
1335 * ENV + *xyz same as above, but xyz acts as suffix filter
1336 * ENV + xyz* same as above, but xyz acts as prefix filter (is this needed?)
1337 * ENV + *xyz* same as above, but xyz acts as strstr filter (is this needed?)
1339 * same as above, with additional paths hard-coded at compile-time:
1340 * - only check paths + ... if ENV is not set or yields not paths
1341 * - always check paths + ... in addition to ENV
1343 * When user specifies set of environment variables, he/she may also use e.g.
1344 * "HOME/.mystuff/plugins", and we'll expand the content of $HOME with the
1348 /* we store in registry:
1351 * - environment variables (array of strings)
1352 * - last hash of env variable contents (uint) (so we can avoid doing stats
1353 * if one of the env vars has changed; premature optimisation galore)
1354 * - hard-coded paths (array of strings)
1355 * - xyz filename/suffix/prefix strings (array of strings)
1357 * - last hash of file/dir stats (int)
1359 * (= struct GstPluginDep)
1363 gst_plugin_ext_dep_get_env_vars_hash (GstPlugin * plugin, GstPluginDep * dep)
1368 /* there's no deeper logic to what we do here; all we want to know (when
1369 * checking if the plugin needs to be rescanned) is whether the content of
1370 * one of the environment variables in the list is different from when it
1371 * was last scanned */
1373 for (e = dep->env_vars; e != NULL && *e != NULL; ++e) {
1377 /* order matters: "val",NULL needs to yield a different hash than
1378 * NULL,"val", so do a shift here whether the var is set or not */
1381 /* want environment variable at beginning of string */
1382 if (!g_ascii_isalnum (**e)) {
1383 GST_WARNING_OBJECT (plugin, "string prefix is not a valid environment "
1384 "variable string: %s", *e);
1388 /* user is allowed to specify e.g. "HOME/.pitivi/plugins" */
1389 g_strlcpy (env_var, *e, sizeof (env_var));
1390 g_strdelimit (env_var, "/\\", '\0');
1392 if ((val = g_getenv (env_var)))
1393 hash += g_str_hash (val);
1400 _priv_plugin_deps_env_vars_changed (GstPlugin * plugin)
1404 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1405 GstPluginDep *dep = l->data;
1407 if (dep->env_hash != gst_plugin_ext_dep_get_env_vars_hash (plugin, dep))
1415 gst_plugin_ext_dep_extract_env_vars_paths (GstPlugin * plugin,
1416 GstPluginDep * dep, GQueue * paths)
1420 for (evars = dep->env_vars; evars != NULL && *evars != NULL; ++evars) {
1424 /* want environment variable at beginning of string */
1425 if (!g_ascii_isalnum (**evars)) {
1426 GST_WARNING_OBJECT (plugin, "string prefix is not a valid environment "
1427 "variable string: %s", *evars);
1431 /* user is allowed to specify e.g. "HOME/.pitivi/plugins", which we want to
1432 * split into the env_var name component and the path component */
1433 components = g_strsplit_set (*evars, "/\\", 2);
1434 g_assert (components != NULL);
1436 e = g_getenv (components[0]);
1437 GST_LOG_OBJECT (plugin, "expanding %s = '%s' (path suffix: %s)",
1438 components[0], GST_STR_NULL (e), GST_STR_NULL (components[1]));
1440 if (components[1] != NULL) {
1441 g_strdelimit (components[1], "/\\", G_DIR_SEPARATOR);
1444 if (e != NULL && *e != '\0') {
1448 arr = g_strsplit (e, G_SEARCHPATH_SEPARATOR_S, -1);
1450 for (i = 0; arr != NULL && arr[i] != NULL; ++i) {
1453 if (!g_path_is_absolute (arr[i])) {
1454 GST_INFO_OBJECT (plugin, "ignoring environment variable content '%s'"
1455 ": either not an absolute path or not a path at all", arr[i]);
1459 if (components[1] != NULL) {
1460 full_path = g_build_filename (arr[i], components[1], NULL);
1462 full_path = g_strdup (arr[i]);
1465 if (!g_queue_find_custom (paths, full_path, (GCompareFunc) strcmp)) {
1466 GST_LOG_OBJECT (plugin, "path: '%s'", full_path);
1467 g_queue_push_tail (paths, full_path);
1470 GST_LOG_OBJECT (plugin, "path: '%s' (duplicate,ignoring)", full_path);
1478 g_strfreev (components);
1481 GST_LOG_OBJECT (plugin, "Extracted %d paths from environment", paths->length);
1485 gst_plugin_ext_dep_get_hash_from_stat_entry (GStatBuf * s)
1487 if (!(s->st_mode & (S_IFDIR | S_IFREG)))
1490 /* completely random formula */
1491 return ((s->st_size << 3) + (s->st_mtime << 5)) ^ s->st_ctime;
1495 gst_plugin_ext_dep_direntry_matches (GstPlugin * plugin, const gchar * entry,
1496 const gchar ** filenames, GstPluginDependencyFlags flags)
1498 /* no filenames specified, match all entries for now (could probably
1499 * optimise by just taking the dir stat hash or so) */
1500 if (filenames == NULL || *filenames == NULL || **filenames == '\0')
1503 while (*filenames != NULL) {
1505 if (((flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX)) &&
1506 g_str_has_suffix (entry, *filenames)) {
1508 /* else it's an exact match that's needed */
1509 } else if (strcmp (entry, *filenames) == 0) {
1512 GST_LOG ("%s does not match %s, flags=0x%04x", entry, *filenames, flags);
1519 gst_plugin_ext_dep_scan_dir_and_match_names (GstPlugin * plugin,
1520 const gchar * path, const gchar ** filenames,
1521 GstPluginDependencyFlags flags, int depth)
1524 gboolean recurse_dirs;
1529 recurse_dirs = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
1531 dir = g_dir_open (path, 0, &err);
1533 GST_DEBUG_OBJECT (plugin, "g_dir_open(%s) failed: %s", path, err->message);
1538 /* FIXME: we're assuming here that we always get the directory entries in
1539 * the same order, and not in a random order */
1540 while ((entry = g_dir_read_name (dir))) {
1541 gboolean have_match;
1547 gst_plugin_ext_dep_direntry_matches (plugin, entry, filenames, flags);
1549 /* avoid the stat if possible */
1550 if (!have_match && !recurse_dirs)
1553 full_path = g_build_filename (path, entry, NULL);
1554 if (g_stat (full_path, &s) < 0) {
1555 fhash = (guint) - 1;
1556 GST_LOG_OBJECT (plugin, "stat: %s (error: %s)", full_path,
1557 g_strerror (errno));
1558 } else if (have_match) {
1559 fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
1560 GST_LOG_OBJECT (plugin, "stat: %s (result: %u)", full_path, fhash);
1561 } else if ((s.st_mode & (S_IFDIR))) {
1562 fhash = gst_plugin_ext_dep_scan_dir_and_match_names (plugin, full_path,
1563 filenames, flags, depth + 1);
1565 /* it's not a name match, we want to recurse, but it's not a directory */
1570 hash = (hash + fhash) << 1;
1579 gst_plugin_ext_dep_scan_path_with_filenames (GstPlugin * plugin,
1580 const gchar * path, const gchar ** filenames,
1581 GstPluginDependencyFlags flags)
1583 const gchar *empty_filenames[] = { "", NULL };
1584 gboolean recurse_into_dirs, partial_names;
1587 /* to avoid special-casing below (FIXME?) */
1588 if (filenames == NULL || *filenames == NULL)
1589 filenames = empty_filenames;
1591 recurse_into_dirs = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
1592 partial_names = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX);
1594 /* if we can construct the exact paths to check with the data we have, just
1595 * stat them one by one; this is more efficient than opening the directory
1596 * and going through each entry to see if it matches one of our filenames. */
1597 if (!recurse_into_dirs && !partial_names) {
1598 for (i = 0; filenames[i] != NULL; ++i) {
1603 full_path = g_build_filename (path, filenames[i], NULL);
1604 if (g_stat (full_path, &s) < 0) {
1605 fhash = (guint) - 1;
1606 GST_LOG_OBJECT (plugin, "stat: %s (error: %s)", full_path,
1607 g_strerror (errno));
1609 fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
1610 GST_LOG_OBJECT (plugin, "stat: %s (result: %08x)", full_path, fhash);
1612 hash = (hash + fhash) << 1;
1616 hash = gst_plugin_ext_dep_scan_dir_and_match_names (plugin, path,
1617 filenames, flags, 0);
1624 gst_plugin_ext_dep_get_stat_hash (GstPlugin * plugin, GstPluginDep * dep)
1626 gboolean paths_are_default_only;
1627 GQueue scan_paths = G_QUEUE_INIT;
1628 guint scan_hash = 0;
1631 GST_LOG_OBJECT (plugin, "start");
1633 paths_are_default_only =
1634 dep->flags & GST_PLUGIN_DEPENDENCY_FLAG_PATHS_ARE_DEFAULT_ONLY;
1636 gst_plugin_ext_dep_extract_env_vars_paths (plugin, dep, &scan_paths);
1638 if (g_queue_is_empty (&scan_paths) || !paths_are_default_only) {
1641 for (paths = dep->paths; paths != NULL && *paths != NULL; ++paths) {
1642 const gchar *path = *paths;
1644 if (!g_queue_find_custom (&scan_paths, path, (GCompareFunc) strcmp)) {
1645 GST_LOG_OBJECT (plugin, "path: '%s'", path);
1646 g_queue_push_tail (&scan_paths, g_strdup (path));
1648 GST_LOG_OBJECT (plugin, "path: '%s' (duplicate, ignoring)", path);
1653 while ((path = g_queue_pop_head (&scan_paths))) {
1654 scan_hash += gst_plugin_ext_dep_scan_path_with_filenames (plugin, path,
1655 (const gchar **) dep->names, dep->flags);
1656 scan_hash = scan_hash << 1;
1660 GST_LOG_OBJECT (plugin, "done, scan_hash: %08x", scan_hash);
1665 _priv_plugin_deps_files_changed (GstPlugin * plugin)
1669 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1670 GstPluginDep *dep = l->data;
1672 if (dep->stat_hash != gst_plugin_ext_dep_get_stat_hash (plugin, dep))
1680 gst_plugin_ext_dep_free (GstPluginDep * dep)
1682 g_strfreev (dep->env_vars);
1683 g_strfreev (dep->paths);
1684 g_strfreev (dep->names);
1685 g_slice_free (GstPluginDep, dep);
1689 gst_plugin_ext_dep_strv_equal (gchar ** arr1, gchar ** arr2)
1693 if (arr1 == NULL || arr2 == NULL)
1695 for (; *arr1 != NULL && *arr2 != NULL; ++arr1, ++arr2) {
1696 if (strcmp (*arr1, *arr2) != 0)
1699 return (*arr1 == *arr2);
1703 gst_plugin_ext_dep_equals (GstPluginDep * dep, const gchar ** env_vars,
1704 const gchar ** paths, const gchar ** names, GstPluginDependencyFlags flags)
1706 if (dep->flags != flags)
1709 return gst_plugin_ext_dep_strv_equal (dep->env_vars, (gchar **) env_vars) &&
1710 gst_plugin_ext_dep_strv_equal (dep->paths, (gchar **) paths) &&
1711 gst_plugin_ext_dep_strv_equal (dep->names, (gchar **) names);
1715 * gst_plugin_add_dependency:
1716 * @plugin: a #GstPlugin
1717 * @env_vars: (allow-none): %NULL-terminated array of environment variables affecting the
1718 * feature set of the plugin (e.g. an environment variable containing
1719 * paths where to look for additional modules/plugins of a library),
1720 * or %NULL. Environment variable names may be followed by a path component
1721 * which will be added to the content of the environment variable, e.g.
1722 * "HOME/.mystuff/plugins".
1723 * @paths: (allow-none): %NULL-terminated array of directories/paths where dependent files
1725 * @names: (allow-none): %NULL-terminated array of file names (or file name suffixes,
1726 * depending on @flags) to be used in combination with the paths from
1727 * @paths and/or the paths extracted from the environment variables in
1728 * @env_vars, or %NULL.
1729 * @flags: optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
1731 * Make GStreamer aware of external dependencies which affect the feature
1732 * set of this plugin (ie. the elements or typefinders associated with it).
1734 * GStreamer will re-inspect plugins with external dependencies whenever any
1735 * of the external dependencies change. This is useful for plugins which wrap
1736 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
1737 * library and makes visualisations available as GStreamer elements, or a
1738 * codec loader which exposes elements and/or caps dependent on what external
1739 * codec libraries are currently installed.
1742 gst_plugin_add_dependency (GstPlugin * plugin, const gchar ** env_vars,
1743 const gchar ** paths, const gchar ** names, GstPluginDependencyFlags flags)
1748 g_return_if_fail (GST_IS_PLUGIN (plugin));
1750 if ((env_vars == NULL || env_vars[0] == NULL) &&
1751 (paths == NULL || paths[0] == NULL)) {
1752 GST_DEBUG_OBJECT (plugin,
1753 "plugin registered empty dependency set. Ignoring");
1757 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1758 if (gst_plugin_ext_dep_equals (l->data, env_vars, paths, names, flags)) {
1759 GST_LOG_OBJECT (plugin, "dependency already registered");
1764 dep = g_slice_new (GstPluginDep);
1766 dep->env_vars = g_strdupv ((gchar **) env_vars);
1767 dep->paths = g_strdupv ((gchar **) paths);
1768 dep->names = g_strdupv ((gchar **) names);
1771 dep->env_hash = gst_plugin_ext_dep_get_env_vars_hash (plugin, dep);
1772 dep->stat_hash = gst_plugin_ext_dep_get_stat_hash (plugin, dep);
1774 plugin->priv->deps = g_list_append (plugin->priv->deps, dep);
1776 GST_DEBUG_OBJECT (plugin, "added dependency:");
1777 for (; env_vars != NULL && *env_vars != NULL; ++env_vars)
1778 GST_DEBUG_OBJECT (plugin, " evar: %s", *env_vars);
1779 for (; paths != NULL && *paths != NULL; ++paths)
1780 GST_DEBUG_OBJECT (plugin, " path: %s", *paths);
1781 for (; names != NULL && *names != NULL; ++names)
1782 GST_DEBUG_OBJECT (plugin, " name: %s", *names);
1786 * gst_plugin_add_dependency_simple:
1787 * @plugin: the #GstPlugin
1788 * @env_vars: (allow-none): one or more environment variables (separated by ':', ';' or ','),
1789 * or %NULL. Environment variable names may be followed by a path component
1790 * which will be added to the content of the environment variable, e.g.
1791 * "HOME/.mystuff/plugins:MYSTUFF_PLUGINS_PATH"
1792 * @paths: (allow-none): one ore more directory paths (separated by ':' or ';' or ','),
1793 * or %NULL. Example: "/usr/lib/mystuff/plugins"
1794 * @names: (allow-none): one or more file names or file name suffixes (separated by commas),
1796 * @flags: optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
1798 * Make GStreamer aware of external dependencies which affect the feature
1799 * set of this plugin (ie. the elements or typefinders associated with it).
1801 * GStreamer will re-inspect plugins with external dependencies whenever any
1802 * of the external dependencies change. This is useful for plugins which wrap
1803 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
1804 * library and makes visualisations available as GStreamer elements, or a
1805 * codec loader which exposes elements and/or caps dependent on what external
1806 * codec libraries are currently installed.
1808 * Convenience wrapper function for gst_plugin_add_dependency() which
1809 * takes simple strings as arguments instead of string arrays, with multiple
1810 * arguments separated by predefined delimiters (see above).
1813 gst_plugin_add_dependency_simple (GstPlugin * plugin,
1814 const gchar * env_vars, const gchar * paths, const gchar * names,
1815 GstPluginDependencyFlags flags)
1817 gchar **a_evars = NULL;
1818 gchar **a_paths = NULL;
1819 gchar **a_names = NULL;
1822 a_evars = g_strsplit_set (env_vars, ":;,", -1);
1824 a_paths = g_strsplit_set (paths, ":;,", -1);
1826 a_names = g_strsplit_set (names, ",", -1);
1828 gst_plugin_add_dependency (plugin, (const gchar **) a_evars,
1829 (const gchar **) a_paths, (const gchar **) a_names, flags);
1832 g_strfreev (a_evars);
1834 g_strfreev (a_paths);
1836 g_strfreev (a_names);