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 * Contact gstreamer-devel@lists.sourceforge.net if your license should be
86 * GPL: http://www.gnu.org/copyleft/gpl.html
87 * LGPL: http://www.gnu.org/copyleft/lesser.html
88 * QPL: http://www.trolltech.com/licenses/qpl.html
89 * MPL: http://www.opensource.org/licenses/mozilla1.1.php
90 * MIT/X11: http://www.opensource.org/licenses/mit-license.php
91 * 3-clause BSD: http://www.opensource.org/licenses/bsd-license.php
93 static const gchar valid_licenses[] = "LGPL\000" /* GNU Lesser General Public License */
94 "GPL\000" /* GNU General Public License */
95 "QPL\000" /* Trolltech Qt Public License */
96 "GPL/QPL\000" /* Combi-license of GPL + QPL */
97 "MPL\000" /* MPL 1.1 license */
98 "BSD\000" /* 3-clause BSD license */
99 "MIT/X11\000" /* MIT/X11 license */
100 "Proprietary\000" /* Proprietary license */
101 GST_LICENSE_UNKNOWN; /* some other license */
103 static const guint8 valid_licenses_idx[] = { 0, 5, 9, 13, 21, 25, 29, 37, 49 };
105 static GstPlugin *gst_plugin_register_func (GstPlugin * plugin,
106 const GstPluginDesc * desc, gpointer user_data);
107 static void gst_plugin_desc_copy (GstPluginDesc * dest,
108 const GstPluginDesc * src);
110 static void gst_plugin_ext_dep_free (GstPluginDep * dep);
112 G_DEFINE_TYPE (GstPlugin, gst_plugin, GST_TYPE_OBJECT);
115 gst_plugin_init (GstPlugin * plugin)
118 G_TYPE_INSTANCE_GET_PRIVATE (plugin, GST_TYPE_PLUGIN, GstPluginPrivate);
122 gst_plugin_finalize (GObject * object)
124 GstPlugin *plugin = GST_PLUGIN_CAST (object);
126 GST_DEBUG ("finalizing plugin %" GST_PTR_FORMAT, plugin);
128 /* FIXME: make registry add a weak ref instead */
130 GstRegistry *registry = gst_registry_get ();
132 for (g = registry->plugins; g; g = g->next) {
133 if (g->data == (gpointer) plugin) {
134 g_warning ("removing plugin that is still in registry");
139 g_free (plugin->filename);
140 g_free (plugin->basename);
142 g_list_foreach (plugin->priv->deps, (GFunc) gst_plugin_ext_dep_free, NULL);
143 g_list_free (plugin->priv->deps);
144 plugin->priv->deps = NULL;
146 if (plugin->priv->cache_data) {
147 gst_structure_free (plugin->priv->cache_data);
150 G_OBJECT_CLASS (gst_plugin_parent_class)->finalize (object);
154 gst_plugin_class_init (GstPluginClass * klass)
156 G_OBJECT_CLASS (klass)->finalize = gst_plugin_finalize;
158 g_type_class_add_private (klass, sizeof (GstPluginPrivate));
162 gst_plugin_error_quark (void)
164 static GQuark quark = 0;
167 quark = g_quark_from_static_string ("gst_plugin_error");
172 * gst_plugin_register_static:
173 * @major_version: the major version number of the GStreamer core that the
174 * plugin was compiled for, you can just use GST_VERSION_MAJOR here
175 * @minor_version: the minor version number of the GStreamer core that the
176 * plugin was compiled for, you can just use GST_VERSION_MINOR here
177 * @name: a unique name of the plugin (ideally prefixed with an application- or
178 * library-specific namespace prefix in order to avoid name conflicts in
179 * case a similar plugin with the same name ever gets added to GStreamer)
180 * @description: description of the plugin
181 * @init_func: (scope call): pointer to the init function of this plugin.
182 * @version: version string of the plugin
183 * @license: effective license of plugin. Must be one of the approved licenses
184 * (see #GstPluginDesc above) or the plugin will not be registered.
185 * @source: source module plugin belongs to
186 * @package: shipped package plugin belongs to
187 * @origin: URL to provider of plugin
189 * Registers a static plugin, ie. a plugin which is private to an application
190 * or library and contained within the application or library (as opposed to
191 * being shipped as a separate module file).
193 * You must make sure that GStreamer has been initialised (with gst_init() or
194 * via gst_init_get_option_group()) before calling this function.
196 * Returns: %TRUE if the plugin was registered correctly, otherwise %FALSE.
199 gst_plugin_register_static (gint major_version, gint minor_version,
200 const gchar * name, const gchar * description, GstPluginInitFunc init_func,
201 const gchar * version, const gchar * license, const gchar * source,
202 const gchar * package, const gchar * origin)
204 GstPluginDesc desc = { major_version, minor_version, name, description,
205 init_func, version, license, source, package, origin, NULL,
208 gboolean res = FALSE;
210 g_return_val_if_fail (name != NULL, FALSE);
211 g_return_val_if_fail (description != NULL, FALSE);
212 g_return_val_if_fail (init_func != NULL, FALSE);
213 g_return_val_if_fail (version != NULL, FALSE);
214 g_return_val_if_fail (license != NULL, FALSE);
215 g_return_val_if_fail (source != NULL, FALSE);
216 g_return_val_if_fail (package != NULL, FALSE);
217 g_return_val_if_fail (origin != NULL, FALSE);
219 /* make sure gst_init() has been called */
220 g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
222 GST_LOG ("attempting to load static plugin \"%s\" now...", name);
223 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
224 if (gst_plugin_register_func (plugin, &desc, NULL) != NULL) {
225 GST_INFO ("registered static plugin \"%s\"", name);
226 res = gst_registry_add_plugin (gst_registry_get (), plugin);
227 GST_INFO ("added static plugin \"%s\", result: %d", name, res);
233 * gst_plugin_register_static_full:
234 * @major_version: the major version number of the GStreamer core that the
235 * plugin was compiled for, you can just use GST_VERSION_MAJOR here
236 * @minor_version: the minor version number of the GStreamer core that the
237 * plugin was compiled for, you can just use GST_VERSION_MINOR here
238 * @name: a unique name of the plugin (ideally prefixed with an application- or
239 * library-specific namespace prefix in order to avoid name conflicts in
240 * case a similar plugin with the same name ever gets added to GStreamer)
241 * @description: description of the plugin
242 * @init_full_func: (scope call): pointer to the init function with user data
244 * @version: version string of the plugin
245 * @license: effective license of plugin. Must be one of the approved licenses
246 * (see #GstPluginDesc above) or the plugin will not be registered.
247 * @source: source module plugin belongs to
248 * @package: shipped package plugin belongs to
249 * @origin: URL to provider of plugin
250 * @user_data: gpointer to user data
252 * Registers a static plugin, ie. a plugin which is private to an application
253 * or library and contained within the application or library (as opposed to
254 * being shipped as a separate module file) with a #GstPluginInitFullFunc
255 * which allows user data to be passed to the callback function (useful
258 * You must make sure that GStreamer has been initialised (with gst_init() or
259 * via gst_init_get_option_group()) before calling this function.
261 * Returns: %TRUE if the plugin was registered correctly, otherwise %FALSE.
264 gst_plugin_register_static_full (gint major_version, gint minor_version,
265 const gchar * name, const gchar * description,
266 GstPluginInitFullFunc init_full_func, const gchar * version,
267 const gchar * license, const gchar * source, const gchar * package,
268 const gchar * origin, gpointer user_data)
270 GstPluginDesc desc = { major_version, minor_version, name, description,
271 (GstPluginInitFunc) init_full_func, version, license, source, package,
275 gboolean res = FALSE;
277 g_return_val_if_fail (name != NULL, FALSE);
278 g_return_val_if_fail (description != NULL, FALSE);
279 g_return_val_if_fail (init_full_func != NULL, FALSE);
280 g_return_val_if_fail (version != NULL, FALSE);
281 g_return_val_if_fail (license != NULL, FALSE);
282 g_return_val_if_fail (source != NULL, FALSE);
283 g_return_val_if_fail (package != NULL, FALSE);
284 g_return_val_if_fail (origin != NULL, FALSE);
286 /* make sure gst_init() has been called */
287 g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
289 GST_LOG ("attempting to load static plugin \"%s\" now...", name);
290 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
291 if (gst_plugin_register_func (plugin, &desc, user_data) != NULL) {
292 GST_INFO ("registered static plugin \"%s\"", name);
293 res = gst_registry_add_plugin (gst_registry_get (), plugin);
294 GST_INFO ("added static plugin \"%s\", result: %d", name, res);
300 _priv_gst_plugin_initialize (void)
302 const gchar *whitelist;
305 _gst_plugin_inited = TRUE;
307 whitelist = g_getenv ("GST_PLUGIN_LOADING_WHITELIST");
308 if (whitelist != NULL && *whitelist != '\0') {
309 _plugin_loading_whitelist = g_strsplit (whitelist,
310 G_SEARCHPATH_SEPARATOR_S, -1);
311 for (i = 0; _plugin_loading_whitelist[i] != NULL; ++i) {
312 GST_INFO ("plugins whitelist entry: %s", _plugin_loading_whitelist[i]);
316 /* now register all static plugins */
317 GST_INFO ("registering %u static plugins", _num_static_plugins);
318 for (i = 0; i < _num_static_plugins; ++i) {
319 gst_plugin_register_static (_static_plugins[i].major_version,
320 _static_plugins[i].minor_version, _static_plugins[i].name,
321 _static_plugins[i].description, _static_plugins[i].plugin_init,
322 _static_plugins[i].version, _static_plugins[i].license,
323 _static_plugins[i].source, _static_plugins[i].package,
324 _static_plugins[i].origin);
327 if (_static_plugins) {
328 free (_static_plugins);
329 _static_plugins = NULL;
330 _num_static_plugins = 0;
334 /* Whitelist entry format:
336 * plugin1,plugin2@pathprefix or
337 * plugin1,plugin2@* or just
339 * source-package@pathprefix or
340 * source-package@* or just
343 * ie. the bit before the path will be checked against both the plugin
344 * name and the plugin's source package name, to keep the format simple.
347 gst_plugin_desc_matches_whitelist_entry (GstPluginDesc * desc,
348 const gchar * filename, const gchar * pattern)
351 gboolean ret = FALSE;
354 GST_LOG ("Whitelist pattern '%s', plugin: %s of %s@%s", pattern, desc->name,
355 desc->source, GST_STR_NULL (filename));
357 /* do we have a path prefix? */
358 sep = strchr (pattern, '@');
359 if (sep != NULL && strcmp (sep, "@*") != 0 && strcmp (sep, "@") != 0) {
360 /* paths are not canonicalised or treated with realpath() here. This
361 * should be good enough for our use case, since we just use the paths
362 * autotools uses, and those will be constructed from the same prefix. */
363 if (filename != NULL && !g_str_has_prefix (filename, sep + 1))
366 GST_LOG ("%s matches path prefix %s", GST_STR_NULL (filename), sep + 1);
370 name = g_strndup (pattern, (gsize) (sep - pattern));
372 name = g_strdup (pattern);
376 if (!g_ascii_isalnum (*name)) {
377 GST_WARNING ("Invalid whitelist pattern: %s", pattern);
381 /* now check plugin names / source package name */
382 if (strchr (name, ',') == NULL) {
383 /* only a single name: either a plugin name or the source package name */
384 ret = (strcmp (desc->source, name) == 0 || strcmp (desc->name, name) == 0);
388 /* multiple names: assume these are plugin names */
389 names = g_strsplit (name, ",", -1);
390 for (n = names; n != NULL && *n != NULL; ++n) {
392 if (strcmp (desc->name, *n) == 0) {
400 GST_LOG ("plugin / source package name match: %d", ret);
409 priv_gst_plugin_desc_is_whitelisted (GstPluginDesc * desc,
410 const gchar * filename)
414 if (_plugin_loading_whitelist == NULL)
417 for (entry = _plugin_loading_whitelist; *entry != NULL; ++entry) {
418 if (gst_plugin_desc_matches_whitelist_entry (desc, filename, *entry)) {
419 GST_LOG ("Plugin %s is in whitelist", filename);
424 GST_LOG ("Plugin %s (package %s, file %s) not in whitelist", desc->name,
425 desc->source, filename);
430 priv_gst_plugin_loading_have_whitelist (void)
432 return (_plugin_loading_whitelist != NULL);
436 priv_gst_plugin_loading_get_whitelist_hash (void)
440 if (_plugin_loading_whitelist != NULL) {
443 for (w = _plugin_loading_whitelist; *w != NULL; ++w)
444 hash = (hash << 1) ^ g_str_hash (*w);
450 /* this function could be extended to check if the plugin license matches the
451 * applications license (would require the app to register its license somehow).
452 * We'll wait for someone who's interested in it to code it :)
455 gst_plugin_check_license (const gchar * license)
459 for (i = 0; i < G_N_ELEMENTS (valid_licenses_idx); ++i) {
460 if (strcmp (license, valid_licenses + valid_licenses_idx[i]) == 0)
467 gst_plugin_check_version (gint major, gint minor)
469 /* return NULL if the major and minor version numbers are not compatible */
471 if (major != GST_VERSION_MAJOR || minor > GST_VERSION_MINOR)
478 gst_plugin_register_func (GstPlugin * plugin, const GstPluginDesc * desc,
481 if (!gst_plugin_check_version (desc->major_version, desc->minor_version)) {
483 GST_WARNING ("plugin \"%s\" has incompatible version, not loading",
484 GST_STR_NULL (plugin->filename));
488 if (!desc->license || !desc->description || !desc->source ||
489 !desc->package || !desc->origin) {
491 GST_WARNING ("plugin \"%s\" has incorrect GstPluginDesc, not loading",
492 GST_STR_NULL (plugin->filename));
496 if (!gst_plugin_check_license (desc->license)) {
498 GST_WARNING ("plugin \"%s\" has invalid license \"%s\", not loading",
499 GST_STR_NULL (plugin->filename), desc->license);
504 GST_LOG ("plugin \"%s\" looks good", GST_STR_NULL (plugin->filename));
506 gst_plugin_desc_copy (&plugin->desc, desc);
508 /* make resident so we're really sure it never gets unloaded again.
509 * Theoretically this is not needed, but practically it doesn't hurt.
510 * And we're rather safe than sorry. */
512 g_module_make_resident (plugin->module);
515 if (!(((GstPluginInitFullFunc) (desc->plugin_init)) (plugin, user_data))) {
517 GST_WARNING ("plugin \"%s\" failed to initialise",
518 GST_STR_NULL (plugin->filename));
522 if (!((desc->plugin_init) (plugin))) {
524 GST_WARNING ("plugin \"%s\" failed to initialise",
525 GST_STR_NULL (plugin->filename));
531 GST_LOG ("plugin \"%s\" initialised", GST_STR_NULL (plugin->filename));
536 #ifdef HAVE_SIGACTION
537 static struct sigaction oldaction;
538 static gboolean _gst_plugin_fault_handler_is_setup = FALSE;
541 * _gst_plugin_fault_handler_restore:
542 * segfault handler restorer
545 _gst_plugin_fault_handler_restore (void)
547 if (!_gst_plugin_fault_handler_is_setup)
550 _gst_plugin_fault_handler_is_setup = FALSE;
552 sigaction (SIGSEGV, &oldaction, NULL);
556 * _gst_plugin_fault_handler_sighandler:
557 * segfault handler implementation
560 _gst_plugin_fault_handler_sighandler (int signum)
562 /* We need to restore the fault handler or we'll keep getting it */
563 _gst_plugin_fault_handler_restore ();
567 g_print ("\nERROR: ");
568 g_print ("Caught a segmentation fault while loading plugin file:\n");
569 g_print ("%s\n\n", _gst_plugin_fault_handler_filename);
570 g_print ("Please either:\n");
571 g_print ("- remove it and restart.\n");
573 ("- run with --gst-disable-segtrap --gst-disable-registry-fork and debug.\n");
577 g_print ("Caught unhandled signal on plugin loading\n");
583 * _gst_plugin_fault_handler_setup:
584 * sets up the segfault handler
587 _gst_plugin_fault_handler_setup (void)
589 struct sigaction action;
591 /* if asked to leave segfaults alone, just return */
592 if (!gst_segtrap_is_enabled ())
595 if (_gst_plugin_fault_handler_is_setup)
598 _gst_plugin_fault_handler_is_setup = TRUE;
600 memset (&action, 0, sizeof (action));
601 action.sa_handler = _gst_plugin_fault_handler_sighandler;
603 sigaction (SIGSEGV, &action, &oldaction);
605 #else /* !HAVE_SIGACTION */
607 _gst_plugin_fault_handler_restore (void)
612 _gst_plugin_fault_handler_setup (void)
615 #endif /* HAVE_SIGACTION */
617 /* g_time_val_from_iso8601() doesn't do quite what we want */
619 check_release_datetime (const gchar * date_time)
623 /* we require YYYY-MM-DD or YYYY-MM-DDTHH:MMZ format */
624 if (!g_ascii_isdigit (*date_time))
627 val = g_ascii_strtoull (date_time, (gchar **) & date_time, 10);
628 if (val < 2000 || val > 2100 || *date_time != '-')
631 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
632 if (val == 0 || val > 12 || *date_time != '-')
635 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
636 if (val == 0 || val > 32)
639 /* end of string or date/time separator + HH:MMZ */
640 if (*date_time == 'T' || *date_time == ' ') {
641 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
642 if (val > 24 || *date_time != ':')
645 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
646 if (val > 59 || *date_time != 'Z')
652 return (*date_time == '\0');
655 static GMutex gst_plugin_loading_mutex;
657 #define CHECK_PLUGIN_DESC_FIELD(desc,field,fn) \
658 if (G_UNLIKELY ((desc)->field == NULL || *(desc)->field == '\0')) { \
659 g_warning ("Plugin description for '%s' has no valid %s field", fn, G_STRINGIFY (field)); \
660 g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, \
661 "Plugin %s has invalid plugin description field '%s'", \
662 filename, G_STRINGIFY (field)); \
667 * gst_plugin_load_file:
668 * @filename: the plugin filename to load
669 * @error: pointer to a %NULL-valued GError
671 * Loads the given plugin and refs it. Caller needs to unref after use.
673 * Returns: (transfer full): a reference to the existing loaded GstPlugin, a
674 * reference to the newly-loaded GstPlugin, or %NULL if an error occurred.
677 gst_plugin_load_file (const gchar * filename, GError ** error)
684 GStatBuf file_status;
685 GstRegistry *registry;
686 gboolean new_plugin = TRUE;
689 g_return_val_if_fail (filename != NULL, NULL);
691 registry = gst_registry_get ();
692 g_mutex_lock (&gst_plugin_loading_mutex);
694 plugin = gst_registry_lookup (registry, filename);
696 if (plugin->module) {
698 g_mutex_unlock (&gst_plugin_loading_mutex);
701 /* load plugin and update fields */
706 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "attempt to load plugin \"%s\"",
709 if (!g_module_supported ()) {
710 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "module loading not supported");
713 GST_PLUGIN_ERROR_MODULE, "Dynamic loading not supported");
717 if (g_stat (filename, &file_status)) {
718 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "problem accessing file");
721 GST_PLUGIN_ERROR_MODULE, "Problem accessing file %s: %s", filename,
726 flags = G_MODULE_BIND_LOCAL;
727 /* libgstpython.so is the gst-python plugin loader. It needs to be loaded with
728 * G_MODULE_BIND_LAZY.
730 * Ideally there should be a generic way for plugins to specify that they
731 * need to be loaded with _LAZY.
733 if (strstr (filename, "libgstpython"))
734 flags |= G_MODULE_BIND_LAZY;
736 module = g_module_open (filename, flags);
737 if (module == NULL) {
738 GST_CAT_WARNING (GST_CAT_PLUGIN_LOADING, "module_open failed: %s",
741 GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "Opening module failed: %s",
743 /* If we failed to open the shared object, then it's probably because a
744 * plugin is linked against the wrong libraries. Print out an easy-to-see
745 * message in this case. */
746 g_warning ("Failed to load plugin '%s': %s", filename, g_module_error ());
750 ret = g_module_symbol (module, "gst_plugin_desc", &ptr);
752 GST_DEBUG ("Could not find plugin entry point in \"%s\"", filename);
755 GST_PLUGIN_ERROR_MODULE,
756 "File \"%s\" is not a GStreamer plugin", filename);
757 g_module_close (module);
761 desc = (GstPluginDesc *) ptr;
763 if (priv_gst_plugin_loading_have_whitelist () &&
764 !priv_gst_plugin_desc_is_whitelisted (desc, filename)) {
765 GST_INFO ("Whitelist specified and plugin not in whitelist, not loading: "
766 "name=%s, package=%s, file=%s", desc->name, desc->source, filename);
767 g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE,
768 "Not loading plugin file \"%s\", not in whitelist", filename);
769 g_module_close (module);
774 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
775 plugin->file_mtime = file_status.st_mtime;
776 plugin->file_size = file_status.st_size;
777 plugin->filename = g_strdup (filename);
778 plugin->basename = g_path_get_basename (filename);
781 plugin->module = module;
782 plugin->orig_desc = desc;
785 /* check plugin description: complain about bad values and fail */
786 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, name, filename);
787 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, description, filename);
788 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, version, filename);
789 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, license, filename);
790 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, source, filename);
791 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, package, filename);
792 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, origin, filename);
794 if (plugin->orig_desc->name != NULL && plugin->orig_desc->name[0] == '"') {
795 g_warning ("Invalid plugin name '%s' - fix your GST_PLUGIN_DEFINE "
796 "(remove quotes around plugin name)", plugin->orig_desc->name);
799 if (plugin->orig_desc->release_datetime != NULL &&
800 !check_release_datetime (plugin->orig_desc->release_datetime)) {
801 GST_ERROR ("GstPluginDesc for '%s' has invalid datetime '%s'",
802 filename, plugin->orig_desc->release_datetime);
803 plugin->orig_desc->release_datetime = NULL;
807 GST_LOG ("Plugin %p for file \"%s\" prepared, calling entry function...",
810 /* this is where we load the actual .so, so let's trap SIGSEGV */
811 _gst_plugin_fault_handler_setup ();
812 _gst_plugin_fault_handler_filename = plugin->filename;
814 GST_LOG ("Plugin %p for file \"%s\" prepared, registering...",
817 if (!gst_plugin_register_func (plugin, plugin->orig_desc, NULL)) {
818 /* remove signal handler */
819 _gst_plugin_fault_handler_restore ();
820 GST_DEBUG ("gst_plugin_register_func failed for plugin \"%s\"", filename);
824 GST_PLUGIN_ERROR_MODULE,
825 "File \"%s\" appears to be a GStreamer plugin, but it failed to initialize",
830 /* remove signal handler */
831 _gst_plugin_fault_handler_restore ();
832 _gst_plugin_fault_handler_filename = NULL;
833 GST_INFO ("plugin \"%s\" loaded", plugin->filename);
836 gst_object_ref (plugin);
837 gst_registry_add_plugin (gst_registry_get (), plugin);
840 g_mutex_unlock (&gst_plugin_loading_mutex);
846 gst_object_unref (plugin);
847 g_mutex_unlock (&gst_plugin_loading_mutex);
853 gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src)
855 dest->major_version = src->major_version;
856 dest->minor_version = src->minor_version;
857 dest->name = g_intern_string (src->name);
858 dest->description = g_intern_string (src->description);
859 dest->plugin_init = src->plugin_init;
860 dest->version = g_intern_string (src->version);
861 dest->license = g_intern_string (src->license);
862 dest->source = g_intern_string (src->source);
863 dest->package = g_intern_string (src->package);
864 dest->origin = g_intern_string (src->origin);
865 dest->release_datetime = g_intern_string (src->release_datetime);
869 * gst_plugin_get_name:
870 * @plugin: plugin to get the name of
872 * Get the short name of the plugin
874 * Returns: the name of the plugin
877 gst_plugin_get_name (GstPlugin * plugin)
879 g_return_val_if_fail (plugin != NULL, NULL);
881 return plugin->desc.name;
885 * gst_plugin_get_description:
886 * @plugin: plugin to get long name of
888 * Get the long descriptive name of the plugin
890 * Returns: the long name of the plugin
893 gst_plugin_get_description (GstPlugin * plugin)
895 g_return_val_if_fail (plugin != NULL, NULL);
897 return plugin->desc.description;
901 * gst_plugin_get_filename:
902 * @plugin: plugin to get the filename of
904 * get the filename of the plugin
906 * Returns: the filename of the plugin
909 gst_plugin_get_filename (GstPlugin * plugin)
911 g_return_val_if_fail (plugin != NULL, NULL);
913 return plugin->filename;
917 * gst_plugin_get_version:
918 * @plugin: plugin to get the version of
920 * get the version of the plugin
922 * Returns: the version of the plugin
925 gst_plugin_get_version (GstPlugin * plugin)
927 g_return_val_if_fail (plugin != NULL, NULL);
929 return plugin->desc.version;
933 * gst_plugin_get_license:
934 * @plugin: plugin to get the license of
936 * get the license of the plugin
938 * Returns: the license of the plugin
941 gst_plugin_get_license (GstPlugin * plugin)
943 g_return_val_if_fail (plugin != NULL, NULL);
945 return plugin->desc.license;
949 * gst_plugin_get_source:
950 * @plugin: plugin to get the source of
952 * get the source module the plugin belongs to.
954 * Returns: the source of the plugin
957 gst_plugin_get_source (GstPlugin * plugin)
959 g_return_val_if_fail (plugin != NULL, NULL);
961 return plugin->desc.source;
965 * gst_plugin_get_package:
966 * @plugin: plugin to get the package of
968 * get the package the plugin belongs to.
970 * Returns: the package of the plugin
973 gst_plugin_get_package (GstPlugin * plugin)
975 g_return_val_if_fail (plugin != NULL, NULL);
977 return plugin->desc.package;
981 * gst_plugin_get_origin:
982 * @plugin: plugin to get the origin of
984 * get the URL where the plugin comes from
986 * Returns: the origin of the plugin
989 gst_plugin_get_origin (GstPlugin * plugin)
991 g_return_val_if_fail (plugin != NULL, NULL);
993 return plugin->desc.origin;
997 * gst_plugin_get_release_date_string:
998 * @plugin: plugin to get the release date of
1000 * Get the release date (and possibly time) in form of a string, if available.
1002 * For normal GStreamer plugin releases this will usually just be a date in
1003 * the form of "YYYY-MM-DD", while pre-releases and builds from git may contain
1004 * a time component after the date as well, in which case the string will be
1005 * formatted like "YYYY-MM-DDTHH:MMZ" (e.g. "2012-04-30T09:30Z").
1007 * There may be plugins that do not have a valid release date set on them.
1009 * Returns: (nullable): the date string of the plugin, or %NULL if not
1013 gst_plugin_get_release_date_string (GstPlugin * plugin)
1015 g_return_val_if_fail (plugin != NULL, NULL);
1017 return plugin->desc.release_datetime;
1021 * gst_plugin_is_loaded:
1022 * @plugin: plugin to query
1024 * queries if the plugin is loaded into memory
1026 * Returns: %TRUE is loaded, %FALSE otherwise
1029 gst_plugin_is_loaded (GstPlugin * plugin)
1031 g_return_val_if_fail (plugin != NULL, FALSE);
1033 return (plugin->module != NULL || plugin->filename == NULL);
1037 * gst_plugin_get_cache_data:
1040 * Gets the plugin specific data cache. If it is %NULL there is no cached data
1041 * stored. This is the case when the registry is getting rebuilt.
1043 * Returns: (transfer none) (nullable): The cached data as a
1044 * #GstStructure or %NULL.
1046 const GstStructure *
1047 gst_plugin_get_cache_data (GstPlugin * plugin)
1049 g_return_val_if_fail (GST_IS_PLUGIN (plugin), NULL);
1051 return plugin->priv->cache_data;
1055 * gst_plugin_set_cache_data:
1057 * @cache_data: (transfer full): a structure containing the data to cache
1059 * Adds plugin specific data to cache. Passes the ownership of the structure to
1062 * The cache is flushed every time the registry is rebuilt.
1065 gst_plugin_set_cache_data (GstPlugin * plugin, GstStructure * cache_data)
1067 g_return_if_fail (GST_IS_PLUGIN (plugin));
1068 g_return_if_fail (GST_IS_STRUCTURE (cache_data));
1070 if (plugin->priv->cache_data) {
1071 gst_structure_free (plugin->priv->cache_data);
1073 plugin->priv->cache_data = cache_data;
1078 * gst_plugin_feature_list:
1079 * @plugin: plugin to query
1080 * @filter: the filter to use
1081 * @first: only return first match
1082 * @user_data: user data passed to the filter function
1084 * Runs a filter against all plugin features and returns a GList with
1085 * the results. If the first flag is set, only the first match is
1086 * returned (as a list with a single object).
1088 * Returns: a GList of features, g_list_free after use.
1091 gst_plugin_feature_filter (GstPlugin * plugin,
1092 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
1097 list = gst_filter_run (plugin->features, (GstFilterFunc) filter, first,
1099 for (g = list; g; g = g->next) {
1100 gst_object_ref (plugin);
1108 GstPluginFeatureFilter filter;
1116 _feature_filter (GstPlugin * plugin, gpointer user_data)
1119 FeatureFilterData *data = (FeatureFilterData *) user_data;
1121 result = gst_plugin_feature_filter (plugin, data->filter, data->first,
1124 data->result = g_list_concat (data->result, result);
1131 * gst_plugin_list_feature_filter:
1132 * @list: a #GList of plugins to query
1133 * @filter: the filter function to use
1134 * @first: only return first match
1135 * @user_data: user data passed to the filter function
1137 * Runs a filter against all plugin features of the plugins in the given
1138 * list and returns a GList with the results.
1139 * If the first flag is set, only the first match is
1140 * returned (as a list with a single object).
1142 * Returns: a GList of features, g_list_free after use.
1145 gst_plugin_list_feature_filter (GList * list,
1146 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
1148 FeatureFilterData data;
1151 data.filter = filter;
1153 data.user_data = user_data;
1156 result = gst_filter_run (list, (GstFilterFunc) _feature_filter, first, &data);
1157 g_list_free (result);
1163 * gst_plugin_find_feature:
1164 * @plugin: plugin to get the feature from
1165 * @name: The name of the feature to find
1166 * @type: The type of the feature to find
1168 * Find a feature of the given name and type in the given plugin.
1170 * Returns: a GstPluginFeature or %NULL if the feature was not found.
1173 gst_plugin_find_feature (GstPlugin * plugin, const gchar * name, GType type)
1176 GstPluginFeature *result = NULL;
1177 GstTypeNameData data;
1179 g_return_val_if_fail (name != NULL, NULL);
1184 walk = gst_filter_run (plugin->features,
1185 (GstFilterFunc) gst_plugin_feature_type_name_filter, TRUE, &data);
1188 result = GST_PLUGIN_FEATURE (walk->data);
1190 gst_object_ref (result);
1191 gst_plugin_feature_list_free (walk);
1200 gst_plugin_feature_name_filter (GstPluginFeature * feature, const gchar * name)
1202 return !strcmp (name, GST_PLUGIN_FEATURE_NAME (feature));
1208 * gst_plugin_find_feature_by_name:
1209 * @plugin: plugin to get the feature from
1210 * @name: The name of the feature to find
1212 * Find a feature of the given name in the given plugin.
1214 * Returns: a GstPluginFeature or %NULL if the feature was not found.
1217 gst_plugin_find_feature_by_name (GstPlugin * plugin, const gchar * name)
1220 GstPluginFeature *result = NULL;
1222 g_return_val_if_fail (name != NULL, NULL);
1224 walk = gst_filter_run (plugin->features,
1225 (GstFilterFunc) gst_plugin_feature_name_filter, TRUE, (void *) name);
1228 result = GST_PLUGIN_FEATURE (walk->data);
1230 gst_object_ref (result);
1231 gst_plugin_feature_list_free (walk);
1239 * gst_plugin_load_by_name:
1240 * @name: name of plugin to load
1242 * Load the named plugin. Refs the plugin.
1244 * Returns: (transfer full): a reference to a loaded plugin, or %NULL on error.
1247 gst_plugin_load_by_name (const gchar * name)
1249 GstPlugin *plugin, *newplugin;
1250 GError *error = NULL;
1252 GST_DEBUG ("looking up plugin %s in default registry", name);
1253 plugin = gst_registry_find_plugin (gst_registry_get (), name);
1255 GST_DEBUG ("loading plugin %s from file %s", name, plugin->filename);
1256 newplugin = gst_plugin_load_file (plugin->filename, &error);
1257 gst_object_unref (plugin);
1260 GST_WARNING ("load_plugin error: %s", error->message);
1261 g_error_free (error);
1264 /* newplugin was reffed by load_file */
1268 GST_DEBUG ("Could not find plugin %s in registry", name);
1274 * @plugin: (transfer none): plugin to load
1276 * Loads @plugin. Note that the *return value* is the loaded plugin; @plugin is
1277 * untouched. The normal use pattern of this function goes like this:
1280 * GstPlugin *loaded_plugin;
1281 * loaded_plugin = gst_plugin_load (plugin);
1282 * // presumably, we're no longer interested in the potentially-unloaded plugin
1283 * gst_object_unref (plugin);
1284 * plugin = loaded_plugin;
1287 * Returns: (transfer full): a reference to a loaded plugin, or %NULL on error.
1290 gst_plugin_load (GstPlugin * plugin)
1292 GError *error = NULL;
1293 GstPlugin *newplugin;
1295 if (gst_plugin_is_loaded (plugin)) {
1299 if (!(newplugin = gst_plugin_load_file (plugin->filename, &error)))
1306 GST_WARNING ("load_plugin error: %s", error->message);
1307 g_error_free (error);
1313 * gst_plugin_list_free:
1314 * @list: (transfer full) (element-type Gst.Plugin): list of #GstPlugin
1316 * Unrefs each member of @list, then frees the list.
1319 gst_plugin_list_free (GList * list)
1323 for (g = list; g; g = g->next) {
1324 gst_object_unref (GST_PLUGIN_CAST (g->data));
1329 /* ===== plugin dependencies ===== */
1332 * ENV + xyz where ENV can contain multiple values separated by SEPARATOR
1333 * xyz may be "" (if ENV contains path to file rather than dir)
1334 * ENV + *xyz same as above, but xyz acts as suffix filter
1335 * ENV + xyz* same as above, but xyz acts as prefix filter (is this needed?)
1336 * ENV + *xyz* same as above, but xyz acts as strstr filter (is this needed?)
1338 * same as above, with additional paths hard-coded at compile-time:
1339 * - only check paths + ... if ENV is not set or yields not paths
1340 * - always check paths + ... in addition to ENV
1342 * When user specifies set of environment variables, he/she may also use e.g.
1343 * "HOME/.mystuff/plugins", and we'll expand the content of $HOME with the
1347 /* we store in registry:
1350 * - environment variables (array of strings)
1351 * - last hash of env variable contents (uint) (so we can avoid doing stats
1352 * if one of the env vars has changed; premature optimisation galore)
1353 * - hard-coded paths (array of strings)
1354 * - xyz filename/suffix/prefix strings (array of strings)
1356 * - last hash of file/dir stats (int)
1358 * (= struct GstPluginDep)
1362 gst_plugin_ext_dep_get_env_vars_hash (GstPlugin * plugin, GstPluginDep * dep)
1367 /* there's no deeper logic to what we do here; all we want to know (when
1368 * checking if the plugin needs to be rescanned) is whether the content of
1369 * one of the environment variables in the list is different from when it
1370 * was last scanned */
1372 for (e = dep->env_vars; e != NULL && *e != NULL; ++e) {
1376 /* order matters: "val",NULL needs to yield a different hash than
1377 * NULL,"val", so do a shift here whether the var is set or not */
1380 /* want environment variable at beginning of string */
1381 if (!g_ascii_isalnum (**e)) {
1382 GST_WARNING_OBJECT (plugin, "string prefix is not a valid environment "
1383 "variable string: %s", *e);
1387 /* user is allowed to specify e.g. "HOME/.pitivi/plugins" */
1388 g_strlcpy (env_var, *e, sizeof (env_var));
1389 g_strdelimit (env_var, "/\\", '\0');
1391 if ((val = g_getenv (env_var)))
1392 hash += g_str_hash (val);
1399 _priv_plugin_deps_env_vars_changed (GstPlugin * plugin)
1403 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1404 GstPluginDep *dep = l->data;
1406 if (dep->env_hash != gst_plugin_ext_dep_get_env_vars_hash (plugin, dep))
1414 gst_plugin_ext_dep_extract_env_vars_paths (GstPlugin * plugin,
1415 GstPluginDep * dep, GQueue * paths)
1419 for (evars = dep->env_vars; evars != NULL && *evars != NULL; ++evars) {
1423 /* want environment variable at beginning of string */
1424 if (!g_ascii_isalnum (**evars)) {
1425 GST_WARNING_OBJECT (plugin, "string prefix is not a valid environment "
1426 "variable string: %s", *evars);
1430 /* user is allowed to specify e.g. "HOME/.pitivi/plugins", which we want to
1431 * split into the env_var name component and the path component */
1432 components = g_strsplit_set (*evars, "/\\", 2);
1433 g_assert (components != NULL);
1435 e = g_getenv (components[0]);
1436 GST_LOG_OBJECT (plugin, "expanding %s = '%s' (path suffix: %s)",
1437 components[0], GST_STR_NULL (e), GST_STR_NULL (components[1]));
1439 if (components[1] != NULL) {
1440 g_strdelimit (components[1], "/\\", G_DIR_SEPARATOR);
1443 if (e != NULL && *e != '\0') {
1447 arr = g_strsplit (e, G_SEARCHPATH_SEPARATOR_S, -1);
1449 for (i = 0; arr != NULL && arr[i] != NULL; ++i) {
1452 if (!g_path_is_absolute (arr[i])) {
1453 GST_INFO_OBJECT (plugin, "ignoring environment variable content '%s'"
1454 ": either not an absolute path or not a path at all", arr[i]);
1458 if (components[1] != NULL) {
1459 full_path = g_build_filename (arr[i], components[1], NULL);
1461 full_path = g_strdup (arr[i]);
1464 if (!g_queue_find_custom (paths, full_path, (GCompareFunc) strcmp)) {
1465 GST_LOG_OBJECT (plugin, "path: '%s'", full_path);
1466 g_queue_push_tail (paths, full_path);
1469 GST_LOG_OBJECT (plugin, "path: '%s' (duplicate,ignoring)", full_path);
1477 g_strfreev (components);
1480 GST_LOG_OBJECT (plugin, "Extracted %d paths from environment", paths->length);
1484 gst_plugin_ext_dep_get_hash_from_stat_entry (GStatBuf * s)
1486 if (!(s->st_mode & (S_IFDIR | S_IFREG)))
1489 /* completely random formula */
1490 return ((s->st_size << 3) + (s->st_mtime << 5)) ^ s->st_ctime;
1494 gst_plugin_ext_dep_direntry_matches (GstPlugin * plugin, const gchar * entry,
1495 const gchar ** filenames, GstPluginDependencyFlags flags)
1497 /* no filenames specified, match all entries for now (could probably
1498 * optimise by just taking the dir stat hash or so) */
1499 if (filenames == NULL || *filenames == NULL || **filenames == '\0')
1502 while (*filenames != NULL) {
1504 if (((flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX)) &&
1505 g_str_has_suffix (entry, *filenames)) {
1507 /* else it's an exact match that's needed */
1508 } else if (strcmp (entry, *filenames) == 0) {
1511 GST_LOG ("%s does not match %s, flags=0x%04x", entry, *filenames, flags);
1518 gst_plugin_ext_dep_scan_dir_and_match_names (GstPlugin * plugin,
1519 const gchar * path, const gchar ** filenames,
1520 GstPluginDependencyFlags flags, int depth)
1523 gboolean recurse_dirs;
1528 recurse_dirs = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
1530 dir = g_dir_open (path, 0, &err);
1532 GST_DEBUG_OBJECT (plugin, "g_dir_open(%s) failed: %s", path, err->message);
1537 /* FIXME: we're assuming here that we always get the directory entries in
1538 * the same order, and not in a random order */
1539 while ((entry = g_dir_read_name (dir))) {
1540 gboolean have_match;
1546 gst_plugin_ext_dep_direntry_matches (plugin, entry, filenames, flags);
1548 /* avoid the stat if possible */
1549 if (!have_match && !recurse_dirs)
1552 full_path = g_build_filename (path, entry, NULL);
1553 if (g_stat (full_path, &s) < 0) {
1554 fhash = (guint) - 1;
1555 GST_LOG_OBJECT (plugin, "stat: %s (error: %s)", full_path,
1556 g_strerror (errno));
1557 } else if (have_match) {
1558 fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
1559 GST_LOG_OBJECT (plugin, "stat: %s (result: %u)", full_path, fhash);
1560 } else if ((s.st_mode & (S_IFDIR))) {
1561 fhash = gst_plugin_ext_dep_scan_dir_and_match_names (plugin, full_path,
1562 filenames, flags, depth + 1);
1564 /* it's not a name match, we want to recurse, but it's not a directory */
1569 hash = (hash + fhash) << 1;
1578 gst_plugin_ext_dep_scan_path_with_filenames (GstPlugin * plugin,
1579 const gchar * path, const gchar ** filenames,
1580 GstPluginDependencyFlags flags)
1582 const gchar *empty_filenames[] = { "", NULL };
1583 gboolean recurse_into_dirs, partial_names;
1586 /* to avoid special-casing below (FIXME?) */
1587 if (filenames == NULL || *filenames == NULL)
1588 filenames = empty_filenames;
1590 recurse_into_dirs = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
1591 partial_names = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX);
1593 /* if we can construct the exact paths to check with the data we have, just
1594 * stat them one by one; this is more efficient than opening the directory
1595 * and going through each entry to see if it matches one of our filenames. */
1596 if (!recurse_into_dirs && !partial_names) {
1597 for (i = 0; filenames[i] != NULL; ++i) {
1602 full_path = g_build_filename (path, filenames[i], NULL);
1603 if (g_stat (full_path, &s) < 0) {
1604 fhash = (guint) - 1;
1605 GST_LOG_OBJECT (plugin, "stat: %s (error: %s)", full_path,
1606 g_strerror (errno));
1608 fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
1609 GST_LOG_OBJECT (plugin, "stat: %s (result: %08x)", full_path, fhash);
1611 hash = (hash + fhash) << 1;
1615 hash = gst_plugin_ext_dep_scan_dir_and_match_names (plugin, path,
1616 filenames, flags, 0);
1623 gst_plugin_ext_dep_get_stat_hash (GstPlugin * plugin, GstPluginDep * dep)
1625 gboolean paths_are_default_only;
1626 GQueue scan_paths = G_QUEUE_INIT;
1627 guint scan_hash = 0;
1630 GST_LOG_OBJECT (plugin, "start");
1632 paths_are_default_only =
1633 dep->flags & GST_PLUGIN_DEPENDENCY_FLAG_PATHS_ARE_DEFAULT_ONLY;
1635 gst_plugin_ext_dep_extract_env_vars_paths (plugin, dep, &scan_paths);
1637 if (g_queue_is_empty (&scan_paths) || !paths_are_default_only) {
1640 for (paths = dep->paths; paths != NULL && *paths != NULL; ++paths) {
1641 const gchar *path = *paths;
1643 if (!g_queue_find_custom (&scan_paths, path, (GCompareFunc) strcmp)) {
1644 GST_LOG_OBJECT (plugin, "path: '%s'", path);
1645 g_queue_push_tail (&scan_paths, g_strdup (path));
1647 GST_LOG_OBJECT (plugin, "path: '%s' (duplicate, ignoring)", path);
1652 while ((path = g_queue_pop_head (&scan_paths))) {
1653 scan_hash += gst_plugin_ext_dep_scan_path_with_filenames (plugin, path,
1654 (const gchar **) dep->names, dep->flags);
1655 scan_hash = scan_hash << 1;
1659 GST_LOG_OBJECT (plugin, "done, scan_hash: %08x", scan_hash);
1664 _priv_plugin_deps_files_changed (GstPlugin * plugin)
1668 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1669 GstPluginDep *dep = l->data;
1671 if (dep->stat_hash != gst_plugin_ext_dep_get_stat_hash (plugin, dep))
1679 gst_plugin_ext_dep_free (GstPluginDep * dep)
1681 g_strfreev (dep->env_vars);
1682 g_strfreev (dep->paths);
1683 g_strfreev (dep->names);
1684 g_slice_free (GstPluginDep, dep);
1688 gst_plugin_ext_dep_strv_equal (gchar ** arr1, gchar ** arr2)
1692 if (arr1 == NULL || arr2 == NULL)
1694 for (; *arr1 != NULL && *arr2 != NULL; ++arr1, ++arr2) {
1695 if (strcmp (*arr1, *arr2) != 0)
1698 return (*arr1 == *arr2);
1702 gst_plugin_ext_dep_equals (GstPluginDep * dep, const gchar ** env_vars,
1703 const gchar ** paths, const gchar ** names, GstPluginDependencyFlags flags)
1705 if (dep->flags != flags)
1708 return gst_plugin_ext_dep_strv_equal (dep->env_vars, (gchar **) env_vars) &&
1709 gst_plugin_ext_dep_strv_equal (dep->paths, (gchar **) paths) &&
1710 gst_plugin_ext_dep_strv_equal (dep->names, (gchar **) names);
1714 * gst_plugin_add_dependency:
1715 * @plugin: a #GstPlugin
1716 * @env_vars: (allow-none): %NULL-terminated array of environment variables affecting the
1717 * feature set of the plugin (e.g. an environment variable containing
1718 * paths where to look for additional modules/plugins of a library),
1719 * or %NULL. Environment variable names may be followed by a path component
1720 * which will be added to the content of the environment variable, e.g.
1721 * "HOME/.mystuff/plugins".
1722 * @paths: (allow-none): %NULL-terminated array of directories/paths where dependent files
1724 * @names: (allow-none): %NULL-terminated array of file names (or file name suffixes,
1725 * depending on @flags) to be used in combination with the paths from
1726 * @paths and/or the paths extracted from the environment variables in
1727 * @env_vars, or %NULL.
1728 * @flags: optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
1730 * Make GStreamer aware of external dependencies which affect the feature
1731 * set of this plugin (ie. the elements or typefinders associated with it).
1733 * GStreamer will re-inspect plugins with external dependencies whenever any
1734 * of the external dependencies change. This is useful for plugins which wrap
1735 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
1736 * library and makes visualisations available as GStreamer elements, or a
1737 * codec loader which exposes elements and/or caps dependent on what external
1738 * codec libraries are currently installed.
1741 gst_plugin_add_dependency (GstPlugin * plugin, const gchar ** env_vars,
1742 const gchar ** paths, const gchar ** names, GstPluginDependencyFlags flags)
1747 g_return_if_fail (GST_IS_PLUGIN (plugin));
1749 if ((env_vars == NULL || env_vars[0] == NULL) &&
1750 (paths == NULL || paths[0] == NULL)) {
1751 GST_DEBUG_OBJECT (plugin,
1752 "plugin registered empty dependency set. Ignoring");
1756 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1757 if (gst_plugin_ext_dep_equals (l->data, env_vars, paths, names, flags)) {
1758 GST_LOG_OBJECT (plugin, "dependency already registered");
1763 dep = g_slice_new (GstPluginDep);
1765 dep->env_vars = g_strdupv ((gchar **) env_vars);
1766 dep->paths = g_strdupv ((gchar **) paths);
1767 dep->names = g_strdupv ((gchar **) names);
1770 dep->env_hash = gst_plugin_ext_dep_get_env_vars_hash (plugin, dep);
1771 dep->stat_hash = gst_plugin_ext_dep_get_stat_hash (plugin, dep);
1773 plugin->priv->deps = g_list_append (plugin->priv->deps, dep);
1775 GST_DEBUG_OBJECT (plugin, "added dependency:");
1776 for (; env_vars != NULL && *env_vars != NULL; ++env_vars)
1777 GST_DEBUG_OBJECT (plugin, " evar: %s", *env_vars);
1778 for (; paths != NULL && *paths != NULL; ++paths)
1779 GST_DEBUG_OBJECT (plugin, " path: %s", *paths);
1780 for (; names != NULL && *names != NULL; ++names)
1781 GST_DEBUG_OBJECT (plugin, " name: %s", *names);
1785 * gst_plugin_add_dependency_simple:
1786 * @plugin: the #GstPlugin
1787 * @env_vars: (allow-none): one or more environment variables (separated by ':', ';' or ','),
1788 * or %NULL. Environment variable names may be followed by a path component
1789 * which will be added to the content of the environment variable, e.g.
1790 * "HOME/.mystuff/plugins:MYSTUFF_PLUGINS_PATH"
1791 * @paths: (allow-none): one ore more directory paths (separated by ':' or ';' or ','),
1792 * or %NULL. Example: "/usr/lib/mystuff/plugins"
1793 * @names: (allow-none): one or more file names or file name suffixes (separated by commas),
1795 * @flags: optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
1797 * Make GStreamer aware of external dependencies which affect the feature
1798 * set of this plugin (ie. the elements or typefinders associated with it).
1800 * GStreamer will re-inspect plugins with external dependencies whenever any
1801 * of the external dependencies change. This is useful for plugins which wrap
1802 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
1803 * library and makes visualisations available as GStreamer elements, or a
1804 * codec loader which exposes elements and/or caps dependent on what external
1805 * codec libraries are currently installed.
1807 * Convenience wrapper function for gst_plugin_add_dependency() which
1808 * takes simple strings as arguments instead of string arrays, with multiple
1809 * arguments separated by predefined delimiters (see above).
1812 gst_plugin_add_dependency_simple (GstPlugin * plugin,
1813 const gchar * env_vars, const gchar * paths, const gchar * names,
1814 GstPluginDependencyFlags flags)
1816 gchar **a_evars = NULL;
1817 gchar **a_paths = NULL;
1818 gchar **a_names = NULL;
1821 a_evars = g_strsplit_set (env_vars, ":;,", -1);
1823 a_paths = g_strsplit_set (paths, ":;,", -1);
1825 a_names = g_strsplit_set (names, ",", -1);
1827 gst_plugin_add_dependency (plugin, (const gchar **) a_evars,
1828 (const gchar **) a_paths, (const gchar **) a_names, flags);
1831 g_strfreev (a_evars);
1833 g_strfreev (a_paths);
1835 g_strfreev (a_names);