2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstplugin.c: Plugin subsystem for loading elements, types, and libs
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 * @short_description: Container for features loaded from a shared object module
26 * @see_also: #GstPluginFeature, #GstElementFactory
28 * GStreamer is extensible, so #GstElement instances can be loaded at runtime.
29 * A plugin system can provide one or more of the basic
30 * <application>GStreamer</application> #GstPluginFeature subclasses.
32 * A plugin should export a symbol <symbol>gst_plugin_desc</symbol> that is a
33 * struct of type #GstPluginDesc.
34 * the plugin loader will check the version of the core library the plugin was
35 * linked against and will create a new #GstPlugin. It will then call the
36 * #GstPluginInitFunc function that was provided in the
37 * <symbol>gst_plugin_desc</symbol>.
39 * Once you have a handle to a #GstPlugin (e.g. from the #GstRegistry), you
40 * can add any object that subclasses #GstPluginFeature.
42 * Usually plugins are always automaticlly loaded so you don't need to call
43 * gst_plugin_load() explicitly to bring it into memory. There are options to
44 * statically link plugins to an app or even use GStreamer without a plugin
45 * repository in which case gst_plugin_load() can be needed to bring the plugin
53 #include "gst_private.h"
55 #include <glib/gstdio.h>
56 #include <sys/types.h>
66 #include "glib-compat-private.h"
70 #define GST_CAT_DEFAULT GST_CAT_PLUGIN_LOADING
72 static guint _num_static_plugins; /* 0 */
73 static GstPluginDesc *_static_plugins; /* NULL */
74 static gboolean _gst_plugin_inited;
75 static gchar **_plugin_loading_whitelist; /* NULL */
77 /* static variables for segfault handling of plugin loading */
78 static char *_gst_plugin_fault_handler_filename = NULL;
80 /* list of valid licenses.
81 * One of these must be specified or the plugin won't be loaded
82 * Contact gstreamer-devel@lists.sourceforge.net if your license should be
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[] = {
93 "LGPL", /* GNU Lesser General Public License */
94 "GPL", /* GNU General Public License */
95 "QPL", /* Trolltech Qt Public License */
96 "GPL/QPL", /* Combi-license of GPL + QPL */
97 "MPL", /* MPL 1.1 license */
98 "BSD", /* 3-clause BSD license */
99 "MIT/X11", /* MIT/X11 license */
100 "Proprietary", /* Proprietary license */
101 GST_LICENSE_UNKNOWN, /* some other license */
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);
125 GstRegistry *registry = gst_registry_get_default ();
128 GST_DEBUG ("finalizing plugin %" GST_PTR_FORMAT, plugin);
129 for (g = registry->plugins; g; g = g->next) {
130 if (g->data == (gpointer) plugin) {
131 g_warning ("removing plugin that is still in registry");
134 g_free (plugin->filename);
135 g_free (plugin->basename);
137 g_list_foreach (plugin->priv->deps, (GFunc) gst_plugin_ext_dep_free, NULL);
138 g_list_free (plugin->priv->deps);
139 plugin->priv->deps = NULL;
141 if (plugin->priv->cache_data) {
142 gst_structure_free (plugin->priv->cache_data);
145 G_OBJECT_CLASS (gst_plugin_parent_class)->finalize (object);
149 gst_plugin_class_init (GstPluginClass * klass)
151 G_OBJECT_CLASS (klass)->finalize = gst_plugin_finalize;
153 g_type_class_add_private (klass, sizeof (GstPluginPrivate));
157 gst_plugin_error_quark (void)
159 static GQuark quark = 0;
162 quark = g_quark_from_static_string ("gst_plugin_error");
166 #ifndef GST_REMOVE_DEPRECATED
167 #ifdef GST_DISABLE_DEPRECATED
168 void _gst_plugin_register_static (GstPluginDesc * desc);
170 /* this function can be called in the GCC constructor extension, before
171 * the _gst_plugin_initialize() was called. In that case, we store the
172 * plugin description in a list to initialize it when we open the main
174 * When the main module is known, we can register the plugin right away.
177 _gst_plugin_register_static (GstPluginDesc * desc)
179 g_return_if_fail (desc != NULL);
181 if (!_gst_plugin_inited) {
182 /* We can't use any GLib functions here, since g_thread_init hasn't been
183 * called yet, and we can't call it here either, or programs that don't
184 * guard their g_thread_init calls in main() will just abort */
185 ++_num_static_plugins;
187 realloc (_static_plugins, _num_static_plugins * sizeof (GstPluginDesc));
188 /* assume strings in the GstPluginDesc are static const or live forever */
189 _static_plugins[_num_static_plugins - 1] = *desc;
191 gst_plugin_register_static (desc->major_version, desc->minor_version,
192 desc->name, desc->description, desc->plugin_init, desc->version,
193 desc->license, desc->source, desc->package, desc->origin);
199 * gst_plugin_register_static:
200 * @major_version: the major version number of the GStreamer core that the
201 * plugin was compiled for, you can just use GST_VERSION_MAJOR here
202 * @minor_version: the minor version number of the GStreamer core that the
203 * plugin was compiled for, you can just use GST_VERSION_MINOR here
204 * @name: a unique name of the plugin (ideally prefixed with an application- or
205 * library-specific namespace prefix in order to avoid name conflicts in
206 * case a similar plugin with the same name ever gets added to GStreamer)
207 * @description: description of the plugin
208 * @init_func: pointer to the init function of this plugin.
209 * @version: version string of the plugin
210 * @license: effective license of plugin. Must be one of the approved licenses
211 * (see #GstPluginDesc above) or the plugin will not be registered.
212 * @source: source module plugin belongs to
213 * @package: shipped package plugin belongs to
214 * @origin: URL to provider of plugin
216 * Registers a static plugin, ie. a plugin which is private to an application
217 * or library and contained within the application or library (as opposed to
218 * being shipped as a separate module file).
220 * You must make sure that GStreamer has been initialised (with gst_init() or
221 * via gst_init_get_option_group()) before calling this function.
223 * Returns: TRUE if the plugin was registered correctly, otherwise FALSE.
228 gst_plugin_register_static (gint major_version, gint minor_version,
229 const gchar * name, const gchar * description, GstPluginInitFunc init_func,
230 const gchar * version, const gchar * license, const gchar * source,
231 const gchar * package, const gchar * origin)
233 GstPluginDesc desc = { major_version, minor_version, name, description,
234 init_func, version, license, source, package, origin, NULL,
237 gboolean res = FALSE;
239 g_return_val_if_fail (name != NULL, FALSE);
240 g_return_val_if_fail (description != NULL, FALSE);
241 g_return_val_if_fail (init_func != NULL, FALSE);
242 g_return_val_if_fail (version != NULL, FALSE);
243 g_return_val_if_fail (license != NULL, FALSE);
244 g_return_val_if_fail (source != NULL, FALSE);
245 g_return_val_if_fail (package != NULL, FALSE);
246 g_return_val_if_fail (origin != NULL, FALSE);
248 /* make sure gst_init() has been called */
249 g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
251 GST_LOG ("attempting to load static plugin \"%s\" now...", name);
252 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
253 if (gst_plugin_register_func (plugin, &desc, NULL) != NULL) {
254 GST_INFO ("registered static plugin \"%s\"", name);
255 res = gst_default_registry_add_plugin (plugin);
256 GST_INFO ("added static plugin \"%s\", result: %d", name, res);
262 * gst_plugin_register_static_full:
263 * @major_version: the major version number of the GStreamer core that the
264 * plugin was compiled for, you can just use GST_VERSION_MAJOR here
265 * @minor_version: the minor version number of the GStreamer core that the
266 * plugin was compiled for, you can just use GST_VERSION_MINOR here
267 * @name: a unique name of the plugin (ideally prefixed with an application- or
268 * library-specific namespace prefix in order to avoid name conflicts in
269 * case a similar plugin with the same name ever gets added to GStreamer)
270 * @description: description of the plugin
271 * @init_full_func: pointer to the init function with user data of this plugin.
272 * @version: version string of the plugin
273 * @license: effective license of plugin. Must be one of the approved licenses
274 * (see #GstPluginDesc above) or the plugin will not be registered.
275 * @source: source module plugin belongs to
276 * @package: shipped package plugin belongs to
277 * @origin: URL to provider of plugin
278 * @user_data: gpointer to user data
280 * Registers a static plugin, ie. a plugin which is private to an application
281 * or library and contained within the application or library (as opposed to
282 * being shipped as a separate module file) with a #GstPluginInitFullFunc
283 * which allows user data to be passed to the callback function (useful
286 * You must make sure that GStreamer has been initialised (with gst_init() or
287 * via gst_init_get_option_group()) before calling this function.
289 * Returns: TRUE if the plugin was registered correctly, otherwise FALSE.
295 gst_plugin_register_static_full (gint major_version, gint minor_version,
296 const gchar * name, const gchar * description,
297 GstPluginInitFullFunc init_full_func, const gchar * version,
298 const gchar * license, const gchar * source, const gchar * package,
299 const gchar * origin, gpointer user_data)
301 GstPluginDesc desc = { major_version, minor_version, name, description,
302 (GstPluginInitFunc) init_full_func, version, license, source, package,
306 gboolean res = FALSE;
308 g_return_val_if_fail (name != NULL, FALSE);
309 g_return_val_if_fail (description != NULL, FALSE);
310 g_return_val_if_fail (init_full_func != NULL, FALSE);
311 g_return_val_if_fail (version != NULL, FALSE);
312 g_return_val_if_fail (license != NULL, FALSE);
313 g_return_val_if_fail (source != NULL, FALSE);
314 g_return_val_if_fail (package != NULL, FALSE);
315 g_return_val_if_fail (origin != NULL, FALSE);
317 /* make sure gst_init() has been called */
318 g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
320 GST_LOG ("attempting to load static plugin \"%s\" now...", name);
321 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
322 if (gst_plugin_register_func (plugin, &desc, user_data) != NULL) {
323 GST_INFO ("registered static plugin \"%s\"", name);
324 res = gst_default_registry_add_plugin (plugin);
325 GST_INFO ("added static plugin \"%s\", result: %d", name, res);
331 _gst_plugin_initialize (void)
333 const gchar *whitelist;
336 _gst_plugin_inited = TRUE;
338 whitelist = g_getenv ("GST_PLUGIN_LOADING_WHITELIST");
339 if (whitelist != NULL && *whitelist != '\0') {
340 _plugin_loading_whitelist = g_strsplit (whitelist,
341 G_SEARCHPATH_SEPARATOR_S, -1);
342 for (i = 0; _plugin_loading_whitelist[i] != NULL; ++i) {
343 GST_INFO ("plugins whitelist entry: %s", _plugin_loading_whitelist[i]);
347 /* now register all static plugins */
348 GST_INFO ("registering %u static plugins", _num_static_plugins);
349 for (i = 0; i < _num_static_plugins; ++i) {
350 gst_plugin_register_static (_static_plugins[i].major_version,
351 _static_plugins[i].minor_version, _static_plugins[i].name,
352 _static_plugins[i].description, _static_plugins[i].plugin_init,
353 _static_plugins[i].version, _static_plugins[i].license,
354 _static_plugins[i].source, _static_plugins[i].package,
355 _static_plugins[i].origin);
358 if (_static_plugins) {
359 free (_static_plugins);
360 _static_plugins = NULL;
361 _num_static_plugins = 0;
365 /* Whitelist entry format:
367 * plugin1,plugin2@pathprefix or
368 * plugin1,plugin2@* or just
370 * source-package@pathprefix or
371 * source-package@* or just
374 * ie. the bit before the path will be checked against both the plugin
375 * name and the plugin's source package name, to keep the format simple.
378 gst_plugin_desc_matches_whitelist_entry (GstPluginDesc * desc,
379 const gchar * filename, const gchar * pattern)
382 gboolean ret = FALSE;
385 GST_LOG ("Whitelist pattern '%s', plugin: %s of %s@%s", pattern, desc->name,
386 desc->source, GST_STR_NULL (filename));
388 /* do we have a path prefix? */
389 sep = strchr (pattern, '@');
390 if (sep != NULL && strcmp (sep, "@*") != 0 && strcmp (sep, "@") != 0) {
391 /* paths are not canonicalised or treated with realpath() here. This
392 * should be good enough for our use case, since we just use the paths
393 * autotools uses, and those will be constructed from the same prefix. */
394 if (filename != NULL && !g_str_has_prefix (filename, sep + 1))
397 GST_LOG ("%s matches path prefix %s", GST_STR_NULL (filename), sep + 1);
401 name = g_strndup (pattern, (gsize) (sep - pattern));
403 name = g_strdup (pattern);
407 if (!g_ascii_isalnum (*name)) {
408 GST_WARNING ("Invalid whitelist pattern: %s", pattern);
412 /* now check plugin names / source package name */
413 if (strchr (name, ',') == NULL) {
414 /* only a single name: either a plugin name or the source package name */
415 ret = (strcmp (desc->source, name) == 0 || strcmp (desc->name, name) == 0);
419 /* multiple names: assume these are plugin names */
420 names = g_strsplit (name, ",", -1);
421 for (n = names; n != NULL && *n != NULL; ++n) {
423 if (strcmp (desc->name, *n) == 0) {
431 GST_LOG ("plugin / source package name match: %d", ret);
440 priv_gst_plugin_desc_is_whitelisted (GstPluginDesc * desc,
441 const gchar * filename)
445 if (_plugin_loading_whitelist == NULL)
448 for (entry = _plugin_loading_whitelist; *entry != NULL; ++entry) {
449 if (gst_plugin_desc_matches_whitelist_entry (desc, filename, *entry)) {
450 GST_LOG ("Plugin %s is in whitelist", filename);
455 GST_LOG ("Plugin %s (package %s, file %s) not in whitelist", desc->name,
456 desc->source, filename);
461 priv_gst_plugin_loading_have_whitelist (void)
463 return (_plugin_loading_whitelist != NULL);
467 priv_gst_plugin_loading_get_whitelist_hash (void)
471 if (_plugin_loading_whitelist != NULL) {
474 for (w = _plugin_loading_whitelist; *w != NULL; ++w)
475 hash = (hash << 1) ^ g_str_hash (*w);
481 /* this function could be extended to check if the plugin license matches the
482 * applications license (would require the app to register its license somehow).
483 * We'll wait for someone who's interested in it to code it :)
486 gst_plugin_check_license (const gchar * license)
488 const gchar **check_license = valid_licenses;
490 g_assert (check_license);
492 while (*check_license) {
493 if (strcmp (license, *check_license) == 0)
501 gst_plugin_check_version (gint major, gint minor)
503 /* return NULL if the major and minor version numbers are not compatible */
505 if (major != GST_VERSION_MAJOR || minor != GST_VERSION_MINOR)
512 gst_plugin_register_func (GstPlugin * plugin, const GstPluginDesc * desc,
515 if (!gst_plugin_check_version (desc->major_version, desc->minor_version)) {
517 GST_WARNING ("plugin \"%s\" has incompatible version, not loading",
522 if (!desc->license || !desc->description || !desc->source ||
523 !desc->package || !desc->origin) {
525 GST_WARNING ("plugin \"%s\" has incorrect GstPluginDesc, not loading",
530 if (!gst_plugin_check_license (desc->license)) {
532 GST_WARNING ("plugin \"%s\" has invalid license \"%s\", not loading",
533 plugin->filename, desc->license);
538 GST_LOG ("plugin \"%s\" looks good", GST_STR_NULL (plugin->filename));
540 gst_plugin_desc_copy (&plugin->desc, desc);
542 /* make resident so we're really sure it never gets unloaded again.
543 * Theoretically this is not needed, but practically it doesn't hurt.
544 * And we're rather safe than sorry. */
546 g_module_make_resident (plugin->module);
549 if (!(((GstPluginInitFullFunc) (desc->plugin_init)) (plugin, user_data))) {
551 GST_WARNING ("plugin \"%s\" failed to initialise", plugin->filename);
555 if (!((desc->plugin_init) (plugin))) {
557 GST_WARNING ("plugin \"%s\" failed to initialise", plugin->filename);
563 GST_LOG ("plugin \"%s\" initialised", GST_STR_NULL (plugin->filename));
568 #ifdef HAVE_SIGACTION
569 static struct sigaction oldaction;
570 static gboolean _gst_plugin_fault_handler_is_setup = FALSE;
573 * _gst_plugin_fault_handler_restore:
574 * segfault handler restorer
577 _gst_plugin_fault_handler_restore (void)
579 if (!_gst_plugin_fault_handler_is_setup)
582 _gst_plugin_fault_handler_is_setup = FALSE;
584 sigaction (SIGSEGV, &oldaction, NULL);
588 * _gst_plugin_fault_handler_sighandler:
589 * segfault handler implementation
592 _gst_plugin_fault_handler_sighandler (int signum)
594 /* We need to restore the fault handler or we'll keep getting it */
595 _gst_plugin_fault_handler_restore ();
599 g_print ("\nERROR: ");
600 g_print ("Caught a segmentation fault while loading plugin file:\n");
601 g_print ("%s\n\n", _gst_plugin_fault_handler_filename);
602 g_print ("Please either:\n");
603 g_print ("- remove it and restart.\n");
604 g_print ("- run with --gst-disable-segtrap and debug.\n");
608 g_print ("Caught unhandled signal on plugin loading\n");
614 * _gst_plugin_fault_handler_setup:
615 * sets up the segfault handler
618 _gst_plugin_fault_handler_setup (void)
620 struct sigaction action;
622 /* if asked to leave segfaults alone, just return */
623 if (!gst_segtrap_is_enabled ())
626 if (_gst_plugin_fault_handler_is_setup)
629 _gst_plugin_fault_handler_is_setup = TRUE;
631 memset (&action, 0, sizeof (action));
632 action.sa_handler = _gst_plugin_fault_handler_sighandler;
634 sigaction (SIGSEGV, &action, &oldaction);
636 #else /* !HAVE_SIGACTION */
638 _gst_plugin_fault_handler_restore (void)
643 _gst_plugin_fault_handler_setup (void)
646 #endif /* HAVE_SIGACTION */
648 /* g_time_val_from_iso8601() doesn't do quite what we want */
650 check_release_datetime (const gchar * date_time)
654 /* we require YYYY-MM-DD or YYYY-MM-DDTHH:MMZ format */
655 if (!g_ascii_isdigit (*date_time))
658 val = g_ascii_strtoull (date_time, (gchar **) & date_time, 10);
659 if (val < 2000 || val > 2100 || *date_time != '-')
662 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
663 if (val == 0 || val > 12 || *date_time != '-')
666 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
667 if (val == 0 || val > 32)
670 /* end of string or date/time separator + HH:MMZ */
671 if (*date_time == 'T' || *date_time == ' ') {
672 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
673 if (val > 24 || *date_time != ':')
676 val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
677 if (val > 59 || *date_time != 'Z')
683 return (*date_time == '\0');
686 static GStaticMutex gst_plugin_loading_mutex = G_STATIC_MUTEX_INIT;
688 #define CHECK_PLUGIN_DESC_FIELD(desc,field,fn) \
689 if (G_UNLIKELY ((desc)->field == NULL)) { \
690 GST_ERROR ("GstPluginDesc for '%s' has no %s", fn, G_STRINGIFY (field)); \
694 * gst_plugin_load_file:
695 * @filename: the plugin filename to load
696 * @error: pointer to a NULL-valued GError
698 * Loads the given plugin and refs it. Caller needs to unref after use.
700 * Returns: a reference to the existing loaded GstPlugin, a reference to the
701 * newly-loaded GstPlugin, or NULL if an error occurred.
704 gst_plugin_load_file (const gchar * filename, GError ** error)
711 GStatBuf file_status;
712 GstRegistry *registry;
713 gboolean new_plugin = TRUE;
715 g_return_val_if_fail (filename != NULL, NULL);
717 registry = gst_registry_get_default ();
718 g_static_mutex_lock (&gst_plugin_loading_mutex);
720 plugin = gst_registry_lookup (registry, filename);
722 if (plugin->module) {
724 g_static_mutex_unlock (&gst_plugin_loading_mutex);
727 /* load plugin and update fields */
732 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "attempt to load plugin \"%s\"",
735 if (g_module_supported () == FALSE) {
736 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "module loading not supported");
739 GST_PLUGIN_ERROR_MODULE, "Dynamic loading not supported");
743 if (g_stat (filename, &file_status)) {
744 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "problem accessing file");
747 GST_PLUGIN_ERROR_MODULE, "Problem accessing file %s: %s", filename,
752 module = g_module_open (filename, G_MODULE_BIND_LOCAL);
753 if (module == NULL) {
754 GST_CAT_WARNING (GST_CAT_PLUGIN_LOADING, "module_open failed: %s",
757 GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "Opening module failed: %s",
759 /* If we failed to open the shared object, then it's probably because a
760 * plugin is linked against the wrong libraries. Print out an easy-to-see
761 * message in this case. */
762 g_warning ("Failed to load plugin '%s': %s", filename, g_module_error ());
766 ret = g_module_symbol (module, "gst_plugin_desc", &ptr);
768 GST_DEBUG ("Could not find plugin entry point in \"%s\"", filename);
771 GST_PLUGIN_ERROR_MODULE,
772 "File \"%s\" is not a GStreamer plugin", filename);
773 g_module_close (module);
777 desc = (GstPluginDesc *) ptr;
779 if (priv_gst_plugin_loading_have_whitelist () &&
780 !priv_gst_plugin_desc_is_whitelisted (desc, filename)) {
781 GST_INFO ("Whitelist specified and plugin not in whitelist, not loading: "
782 "name=%s, package=%s, file=%s", desc->name, desc->source, filename);
783 g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE,
784 "Not loading plugin file \"%s\", not in whitelist", filename);
785 g_module_close (module);
790 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
791 plugin->file_mtime = file_status.st_mtime;
792 plugin->file_size = file_status.st_size;
793 plugin->filename = g_strdup (filename);
794 plugin->basename = g_path_get_basename (filename);
797 plugin->module = module;
798 plugin->orig_desc = desc;
801 /* check plugin description: complain about bad values but accept them, to
802 * maintain backwards compatibility (FIXME: 0.11) */
803 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, name, filename);
804 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, description, filename);
805 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, version, filename);
806 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, license, filename);
807 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, source, filename);
808 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, package, filename);
809 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, origin, filename);
811 if (plugin->orig_desc->release_datetime != NULL &&
812 !check_release_datetime (plugin->orig_desc->release_datetime)) {
813 GST_ERROR ("GstPluginDesc for '%s' has invalid datetime '%s'",
814 filename, plugin->orig_desc->release_datetime);
815 plugin->orig_desc->release_datetime = NULL;
819 GST_LOG ("Plugin %p for file \"%s\" prepared, calling entry function...",
822 /* this is where we load the actual .so, so let's trap SIGSEGV */
823 _gst_plugin_fault_handler_setup ();
824 _gst_plugin_fault_handler_filename = plugin->filename;
826 GST_LOG ("Plugin %p for file \"%s\" prepared, registering...",
829 if (!gst_plugin_register_func (plugin, plugin->orig_desc, NULL)) {
830 /* remove signal handler */
831 _gst_plugin_fault_handler_restore ();
832 GST_DEBUG ("gst_plugin_register_func failed for plugin \"%s\"", filename);
836 GST_PLUGIN_ERROR_MODULE,
837 "File \"%s\" appears to be a GStreamer plugin, but it failed to initialize",
842 /* remove signal handler */
843 _gst_plugin_fault_handler_restore ();
844 _gst_plugin_fault_handler_filename = NULL;
845 GST_INFO ("plugin \"%s\" loaded", plugin->filename);
848 gst_object_ref (plugin);
849 gst_default_registry_add_plugin (plugin);
852 g_static_mutex_unlock (&gst_plugin_loading_mutex);
858 gst_object_unref (plugin);
859 g_static_mutex_unlock (&gst_plugin_loading_mutex);
865 gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src)
867 dest->major_version = src->major_version;
868 dest->minor_version = src->minor_version;
869 dest->name = g_intern_string (src->name);
870 dest->description = g_intern_string (src->description);
871 dest->plugin_init = src->plugin_init;
872 dest->version = g_intern_string (src->version);
873 dest->license = g_intern_string (src->license);
874 dest->source = g_intern_string (src->source);
875 dest->package = g_intern_string (src->package);
876 dest->origin = g_intern_string (src->origin);
877 dest->release_datetime = g_intern_string (src->release_datetime);
881 * gst_plugin_get_name:
882 * @plugin: plugin to get the name of
884 * Get the short name of the plugin
886 * Returns: the name of the plugin
889 gst_plugin_get_name (GstPlugin * plugin)
891 g_return_val_if_fail (plugin != NULL, NULL);
893 return plugin->desc.name;
897 * gst_plugin_get_description:
898 * @plugin: plugin to get long name of
900 * Get the long descriptive name of the plugin
902 * Returns: the long name of the plugin
904 G_CONST_RETURN gchar *
905 gst_plugin_get_description (GstPlugin * plugin)
907 g_return_val_if_fail (plugin != NULL, NULL);
909 return plugin->desc.description;
913 * gst_plugin_get_filename:
914 * @plugin: plugin to get the filename of
916 * get the filename of the plugin
918 * Returns: the filename of the plugin
920 G_CONST_RETURN gchar *
921 gst_plugin_get_filename (GstPlugin * plugin)
923 g_return_val_if_fail (plugin != NULL, NULL);
925 return plugin->filename;
929 * gst_plugin_get_version:
930 * @plugin: plugin to get the version of
932 * get the version of the plugin
934 * Returns: the version of the plugin
936 G_CONST_RETURN gchar *
937 gst_plugin_get_version (GstPlugin * plugin)
939 g_return_val_if_fail (plugin != NULL, NULL);
941 return plugin->desc.version;
945 * gst_plugin_get_license:
946 * @plugin: plugin to get the license of
948 * get the license of the plugin
950 * Returns: the license of the plugin
952 G_CONST_RETURN gchar *
953 gst_plugin_get_license (GstPlugin * plugin)
955 g_return_val_if_fail (plugin != NULL, NULL);
957 return plugin->desc.license;
961 * gst_plugin_get_source:
962 * @plugin: plugin to get the source of
964 * get the source module the plugin belongs to.
966 * Returns: the source of the plugin
968 G_CONST_RETURN gchar *
969 gst_plugin_get_source (GstPlugin * plugin)
971 g_return_val_if_fail (plugin != NULL, NULL);
973 return plugin->desc.source;
977 * gst_plugin_get_package:
978 * @plugin: plugin to get the package of
980 * get the package the plugin belongs to.
982 * Returns: the package of the plugin
984 G_CONST_RETURN gchar *
985 gst_plugin_get_package (GstPlugin * plugin)
987 g_return_val_if_fail (plugin != NULL, NULL);
989 return plugin->desc.package;
993 * gst_plugin_get_origin:
994 * @plugin: plugin to get the origin of
996 * get the URL where the plugin comes from
998 * Returns: the origin of the plugin
1000 G_CONST_RETURN gchar *
1001 gst_plugin_get_origin (GstPlugin * plugin)
1003 g_return_val_if_fail (plugin != NULL, NULL);
1005 return plugin->desc.origin;
1009 * gst_plugin_get_module:
1010 * @plugin: plugin to query
1012 * Gets the #GModule of the plugin. If the plugin isn't loaded yet, NULL is
1015 * Returns: module belonging to the plugin or NULL if the plugin isn't
1019 gst_plugin_get_module (GstPlugin * plugin)
1021 g_return_val_if_fail (plugin != NULL, NULL);
1023 return plugin->module;
1027 * gst_plugin_is_loaded:
1028 * @plugin: plugin to query
1030 * queries if the plugin is loaded into memory
1032 * Returns: TRUE is loaded, FALSE otherwise
1035 gst_plugin_is_loaded (GstPlugin * plugin)
1037 g_return_val_if_fail (plugin != NULL, FALSE);
1039 return (plugin->module != NULL || plugin->filename == NULL);
1043 * gst_plugin_get_cache_data:
1046 * Gets the plugin specific data cache. If it is %NULL there is no cached data
1047 * stored. This is the case when the registry is getting rebuilt.
1049 * Returns: The cached data as a #GstStructure or %NULL.
1053 G_CONST_RETURN GstStructure *
1054 gst_plugin_get_cache_data (GstPlugin * plugin)
1056 g_return_val_if_fail (GST_IS_PLUGIN (plugin), NULL);
1058 return plugin->priv->cache_data;
1062 * gst_plugin_set_cache_data:
1064 * @cache_data: a structure containing the data to cache
1066 * Adds plugin specific data to cache. Passes the ownership of the structure to
1069 * The cache is flushed every time the registry is rebuilt.
1074 gst_plugin_set_cache_data (GstPlugin * plugin, GstStructure * cache_data)
1076 g_return_if_fail (GST_IS_PLUGIN (plugin));
1077 g_return_if_fail (GST_IS_STRUCTURE (cache_data));
1079 if (plugin->priv->cache_data) {
1080 gst_structure_free (plugin->priv->cache_data);
1082 plugin->priv->cache_data = cache_data;
1087 * gst_plugin_feature_list:
1088 * @plugin: plugin to query
1089 * @filter: the filter to use
1090 * @first: only return first match
1091 * @user_data: user data passed to the filter function
1093 * Runs a filter against all plugin features and returns a GList with
1094 * the results. If the first flag is set, only the first match is
1095 * returned (as a list with a single object).
1097 * Returns: a GList of features, g_list_free after use.
1100 gst_plugin_feature_filter (GstPlugin * plugin,
1101 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
1106 list = gst_filter_run (plugin->features, (GstFilterFunc) filter, first,
1108 for (g = list; g; g = g->next) {
1109 gst_object_ref (plugin);
1117 GstPluginFeatureFilter filter;
1125 _feature_filter (GstPlugin * plugin, gpointer user_data)
1128 FeatureFilterData *data = (FeatureFilterData *) user_data;
1130 result = gst_plugin_feature_filter (plugin, data->filter, data->first,
1133 data->result = g_list_concat (data->result, result);
1140 * gst_plugin_list_feature_filter:
1141 * @list: a #GList of plugins to query
1142 * @filter: the filter function to use
1143 * @first: only return first match
1144 * @user_data: user data passed to the filter function
1146 * Runs a filter against all plugin features of the plugins in the given
1147 * list and returns a GList with the results.
1148 * If the first flag is set, only the first match is
1149 * returned (as a list with a single object).
1151 * Returns: a GList of features, g_list_free after use.
1154 gst_plugin_list_feature_filter (GList * list,
1155 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
1157 FeatureFilterData data;
1160 data.filter = filter;
1162 data.user_data = user_data;
1165 result = gst_filter_run (list, (GstFilterFunc) _feature_filter, first, &data);
1166 g_list_free (result);
1173 * gst_plugin_name_filter:
1174 * @plugin: the plugin to check
1175 * @name: the name of the plugin
1177 * A standard filter that returns TRUE when the plugin is of the
1180 * Returns: TRUE if the plugin is of the given name.
1183 gst_plugin_name_filter (GstPlugin * plugin, const gchar * name)
1185 return (plugin->desc.name && !strcmp (plugin->desc.name, name));
1190 * gst_plugin_find_feature:
1191 * @plugin: plugin to get the feature from
1192 * @name: The name of the feature to find
1193 * @type: The type of the feature to find
1195 * Find a feature of the given name and type in the given plugin.
1197 * Returns: a GstPluginFeature or NULL if the feature was not found.
1200 gst_plugin_find_feature (GstPlugin * plugin, const gchar * name, GType type)
1203 GstPluginFeature *result = NULL;
1204 GstTypeNameData data;
1206 g_return_val_if_fail (name != NULL, NULL);
1211 walk = gst_filter_run (plugin->features,
1212 (GstFilterFunc) gst_plugin_feature_type_name_filter, TRUE, &data);
1215 result = GST_PLUGIN_FEATURE (walk->data);
1217 gst_object_ref (result);
1218 gst_plugin_feature_list_free (walk);
1227 gst_plugin_feature_name_filter (GstPluginFeature * feature, const gchar * name)
1229 return !strcmp (name, GST_PLUGIN_FEATURE_NAME (feature));
1235 * gst_plugin_find_feature_by_name:
1236 * @plugin: plugin to get the feature from
1237 * @name: The name of the feature to find
1239 * Find a feature of the given name in the given plugin.
1241 * Returns: a GstPluginFeature or NULL if the feature was not found.
1244 gst_plugin_find_feature_by_name (GstPlugin * plugin, const gchar * name)
1247 GstPluginFeature *result = NULL;
1249 g_return_val_if_fail (name != NULL, NULL);
1251 walk = gst_filter_run (plugin->features,
1252 (GstFilterFunc) gst_plugin_feature_name_filter, TRUE, (void *) name);
1255 result = GST_PLUGIN_FEATURE (walk->data);
1257 gst_object_ref (result);
1258 gst_plugin_feature_list_free (walk);
1266 * gst_plugin_load_by_name:
1267 * @name: name of plugin to load
1269 * Load the named plugin. Refs the plugin.
1271 * Returns: A reference to a loaded plugin, or NULL on error.
1274 gst_plugin_load_by_name (const gchar * name)
1276 GstPlugin *plugin, *newplugin;
1277 GError *error = NULL;
1279 GST_DEBUG ("looking up plugin %s in default registry", name);
1280 plugin = gst_registry_find_plugin (gst_registry_get_default (), name);
1282 GST_DEBUG ("loading plugin %s from file %s", name, plugin->filename);
1283 newplugin = gst_plugin_load_file (plugin->filename, &error);
1284 gst_object_unref (plugin);
1287 GST_WARNING ("load_plugin error: %s", error->message);
1288 g_error_free (error);
1291 /* newplugin was reffed by load_file */
1295 GST_DEBUG ("Could not find plugin %s in registry", name);
1301 * @plugin: plugin to load
1303 * Loads @plugin. Note that the *return value* is the loaded plugin; @plugin is
1304 * untouched. The normal use pattern of this function goes like this:
1307 * GstPlugin *loaded_plugin;
1308 * loaded_plugin = gst_plugin_load (plugin);
1309 * // presumably, we're no longer interested in the potentially-unloaded plugin
1310 * gst_object_unref (plugin);
1311 * plugin = loaded_plugin;
1314 * Returns: A reference to a loaded plugin, or NULL on error.
1317 gst_plugin_load (GstPlugin * plugin)
1319 GError *error = NULL;
1320 GstPlugin *newplugin;
1322 if (gst_plugin_is_loaded (plugin)) {
1326 if (!(newplugin = gst_plugin_load_file (plugin->filename, &error)))
1333 GST_WARNING ("load_plugin error: %s", error->message);
1334 g_error_free (error);
1340 * gst_plugin_list_free:
1341 * @list: list of #GstPlugin
1343 * Unrefs each member of @list, then frees the list.
1346 gst_plugin_list_free (GList * list)
1350 for (g = list; g; g = g->next) {
1351 gst_object_unref (GST_PLUGIN_CAST (g->data));
1356 /* ===== plugin dependencies ===== */
1359 * ENV + xyz where ENV can contain multiple values separated by SEPARATOR
1360 * xyz may be "" (if ENV contains path to file rather than dir)
1361 * ENV + *xyz same as above, but xyz acts as suffix filter
1362 * ENV + xyz* same as above, but xyz acts as prefix filter (is this needed?)
1363 * ENV + *xyz* same as above, but xyz acts as strstr filter (is this needed?)
1365 * same as above, with additional paths hard-coded at compile-time:
1366 * - only check paths + ... if ENV is not set or yields not paths
1367 * - always check paths + ... in addition to ENV
1369 * When user specifies set of environment variables, he/she may also use e.g.
1370 * "HOME/.mystuff/plugins", and we'll expand the content of $HOME with the
1374 /* we store in registry:
1377 * - environment variables (array of strings)
1378 * - last hash of env variable contents (uint) (so we can avoid doing stats
1379 * if one of the env vars has changed; premature optimisation galore)
1380 * - hard-coded paths (array of strings)
1381 * - xyz filename/suffix/prefix strings (array of strings)
1383 * - last hash of file/dir stats (int)
1385 * (= struct GstPluginDep)
1389 gst_plugin_ext_dep_get_env_vars_hash (GstPlugin * plugin, GstPluginDep * dep)
1394 /* there's no deeper logic to what we do here; all we want to know (when
1395 * checking if the plugin needs to be rescanned) is whether the content of
1396 * one of the environment variables in the list is different from when it
1397 * was last scanned */
1399 for (e = dep->env_vars; e != NULL && *e != NULL; ++e) {
1403 /* order matters: "val",NULL needs to yield a different hash than
1404 * NULL,"val", so do a shift here whether the var is set or not */
1407 /* want environment variable at beginning of string */
1408 if (!g_ascii_isalnum (**e)) {
1409 GST_WARNING_OBJECT (plugin, "string prefix is not a valid environment "
1410 "variable string: %s", *e);
1414 /* user is allowed to specify e.g. "HOME/.pitivi/plugins" */
1415 g_strlcpy (env_var, *e, sizeof (env_var));
1416 g_strdelimit (env_var, "/\\", '\0');
1418 if ((val = g_getenv (env_var)))
1419 hash += g_str_hash (val);
1426 _priv_plugin_deps_env_vars_changed (GstPlugin * plugin)
1430 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1431 GstPluginDep *dep = l->data;
1433 if (dep->env_hash != gst_plugin_ext_dep_get_env_vars_hash (plugin, dep))
1441 gst_plugin_ext_dep_extract_env_vars_paths (GstPlugin * plugin,
1445 GList *paths = NULL;
1447 for (evars = dep->env_vars; evars != NULL && *evars != NULL; ++evars) {
1451 /* want environment variable at beginning of string */
1452 if (!g_ascii_isalnum (**evars)) {
1453 GST_WARNING_OBJECT (plugin, "string prefix is not a valid environment "
1454 "variable string: %s", *evars);
1458 /* user is allowed to specify e.g. "HOME/.pitivi/plugins", which we want to
1459 * split into the env_var name component and the path component */
1460 components = g_strsplit_set (*evars, "/\\", 2);
1461 g_assert (components != NULL);
1463 e = g_getenv (components[0]);
1464 GST_LOG_OBJECT (plugin, "expanding %s = '%s' (path suffix: %s)",
1465 components[0], GST_STR_NULL (e), GST_STR_NULL (components[1]));
1467 if (components[1] != NULL) {
1468 g_strdelimit (components[1], "/\\", G_DIR_SEPARATOR);
1471 if (e != NULL && *e != '\0') {
1475 arr = g_strsplit (e, G_SEARCHPATH_SEPARATOR_S, -1);
1477 for (i = 0; arr != NULL && arr[i] != NULL; ++i) {
1480 if (!g_path_is_absolute (arr[i])) {
1481 GST_INFO_OBJECT (plugin, "ignoring environment variable content '%s'"
1482 ": either not an absolute path or not a path at all", arr[i]);
1486 if (components[1] != NULL) {
1487 full_path = g_build_filename (arr[i], components[1], NULL);
1489 full_path = g_strdup (arr[i]);
1492 if (!g_list_find_custom (paths, full_path, (GCompareFunc) strcmp)) {
1493 GST_LOG_OBJECT (plugin, "path: '%s'", full_path);
1494 paths = g_list_prepend (paths, full_path);
1497 GST_LOG_OBJECT (plugin, "path: '%s' (duplicate,ignoring)", full_path);
1505 g_strfreev (components);
1508 GST_LOG_OBJECT (plugin, "Extracted %d paths from environment",
1509 g_list_length (paths));
1515 gst_plugin_ext_dep_get_hash_from_stat_entry (GStatBuf * s)
1517 if (!(s->st_mode & (S_IFDIR | S_IFREG)))
1520 /* completely random formula */
1521 return ((s->st_size << 3) + (s->st_mtime << 5)) ^ s->st_ctime;
1525 gst_plugin_ext_dep_direntry_matches (GstPlugin * plugin, const gchar * entry,
1526 const gchar ** filenames, GstPluginDependencyFlags flags)
1528 /* no filenames specified, match all entries for now (could probably
1529 * optimise by just taking the dir stat hash or so) */
1530 if (filenames == NULL || *filenames == NULL || **filenames == '\0')
1533 while (*filenames != NULL) {
1535 if (((flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX)) &&
1536 g_str_has_suffix (entry, *filenames)) {
1538 /* else it's an exact match that's needed */
1539 } else if (strcmp (entry, *filenames) == 0) {
1542 GST_LOG ("%s does not match %s, flags=0x%04x", entry, *filenames, flags);
1549 gst_plugin_ext_dep_scan_dir_and_match_names (GstPlugin * plugin,
1550 const gchar * path, const gchar ** filenames,
1551 GstPluginDependencyFlags flags, int depth)
1554 gboolean recurse_dirs;
1559 recurse_dirs = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
1561 dir = g_dir_open (path, 0, &err);
1563 GST_DEBUG_OBJECT (plugin, "g_dir_open(%s) failed: %s", path, err->message);
1568 /* FIXME: we're assuming here that we always get the directory entries in
1569 * the same order, and not in a random order */
1570 while ((entry = g_dir_read_name (dir))) {
1571 gboolean have_match;
1577 gst_plugin_ext_dep_direntry_matches (plugin, entry, filenames, flags);
1579 /* avoid the stat if possible */
1580 if (!have_match && !recurse_dirs)
1583 full_path = g_build_filename (path, entry, NULL);
1584 if (g_stat (full_path, &s) < 0) {
1585 fhash = (guint) - 1;
1586 GST_LOG_OBJECT (plugin, "stat: %s (error: %s)", full_path,
1587 g_strerror (errno));
1588 } else if (have_match) {
1589 fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
1590 GST_LOG_OBJECT (plugin, "stat: %s (result: %u)", full_path, fhash);
1591 } else if ((s.st_mode & (S_IFDIR))) {
1592 fhash = gst_plugin_ext_dep_scan_dir_and_match_names (plugin, full_path,
1593 filenames, flags, depth + 1);
1595 /* it's not a name match, we want to recurse, but it's not a directory */
1600 hash = (hash + fhash) << 1;
1609 gst_plugin_ext_dep_scan_path_with_filenames (GstPlugin * plugin,
1610 const gchar * path, const gchar ** filenames,
1611 GstPluginDependencyFlags flags)
1613 const gchar *empty_filenames[] = { "", NULL };
1614 gboolean recurse_into_dirs, partial_names;
1617 /* to avoid special-casing below (FIXME?) */
1618 if (filenames == NULL || *filenames == NULL)
1619 filenames = empty_filenames;
1621 recurse_into_dirs = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
1622 partial_names = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX);
1624 /* if we can construct the exact paths to check with the data we have, just
1625 * stat them one by one; this is more efficient than opening the directory
1626 * and going through each entry to see if it matches one of our filenames. */
1627 if (!recurse_into_dirs && !partial_names) {
1628 for (i = 0; filenames[i] != NULL; ++i) {
1633 full_path = g_build_filename (path, filenames[i], NULL);
1634 if (g_stat (full_path, &s) < 0) {
1635 fhash = (guint) - 1;
1636 GST_LOG_OBJECT (plugin, "stat: %s (error: %s)", full_path,
1637 g_strerror (errno));
1639 fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
1640 GST_LOG_OBJECT (plugin, "stat: %s (result: %08x)", full_path, fhash);
1642 hash = (hash + fhash) << 1;
1646 hash = gst_plugin_ext_dep_scan_dir_and_match_names (plugin, path,
1647 filenames, flags, 0);
1654 gst_plugin_ext_dep_get_stat_hash (GstPlugin * plugin, GstPluginDep * dep)
1656 gboolean paths_are_default_only;
1658 guint scan_hash = 0;
1660 GST_LOG_OBJECT (plugin, "start");
1662 paths_are_default_only =
1663 dep->flags & GST_PLUGIN_DEPENDENCY_FLAG_PATHS_ARE_DEFAULT_ONLY;
1665 scan_paths = gst_plugin_ext_dep_extract_env_vars_paths (plugin, dep);
1667 if (scan_paths == NULL || !paths_are_default_only) {
1670 for (paths = dep->paths; paths != NULL && *paths != NULL; ++paths) {
1671 const gchar *path = *paths;
1673 if (!g_list_find_custom (scan_paths, path, (GCompareFunc) strcmp)) {
1674 GST_LOG_OBJECT (plugin, "path: '%s'", path);
1675 scan_paths = g_list_prepend (scan_paths, g_strdup (path));
1677 GST_LOG_OBJECT (plugin, "path: '%s' (duplicate, ignoring)", path);
1682 /* not that the order really matters, but it makes debugging easier */
1683 scan_paths = g_list_reverse (scan_paths);
1685 while (scan_paths != NULL) {
1686 const gchar *path = scan_paths->data;
1688 scan_hash += gst_plugin_ext_dep_scan_path_with_filenames (plugin, path,
1689 (const gchar **) dep->names, dep->flags);
1690 scan_hash = scan_hash << 1;
1692 g_free (scan_paths->data);
1693 scan_paths = g_list_delete_link (scan_paths, scan_paths);
1696 GST_LOG_OBJECT (plugin, "done, scan_hash: %08x", scan_hash);
1701 _priv_plugin_deps_files_changed (GstPlugin * plugin)
1705 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1706 GstPluginDep *dep = l->data;
1708 if (dep->stat_hash != gst_plugin_ext_dep_get_stat_hash (plugin, dep))
1716 gst_plugin_ext_dep_free (GstPluginDep * dep)
1718 g_strfreev (dep->env_vars);
1719 g_strfreev (dep->paths);
1720 g_strfreev (dep->names);
1721 g_slice_free (GstPluginDep, dep);
1725 gst_plugin_ext_dep_strv_equal (gchar ** arr1, gchar ** arr2)
1729 if (arr1 == NULL || arr2 == NULL)
1731 for (; *arr1 != NULL && *arr2 != NULL; ++arr1, ++arr2) {
1732 if (strcmp (*arr1, *arr2) != 0)
1735 return (*arr1 == *arr2);
1739 gst_plugin_ext_dep_equals (GstPluginDep * dep, const gchar ** env_vars,
1740 const gchar ** paths, const gchar ** names, GstPluginDependencyFlags flags)
1742 if (dep->flags != flags)
1745 return gst_plugin_ext_dep_strv_equal (dep->env_vars, (gchar **) env_vars) &&
1746 gst_plugin_ext_dep_strv_equal (dep->paths, (gchar **) paths) &&
1747 gst_plugin_ext_dep_strv_equal (dep->names, (gchar **) names);
1751 * gst_plugin_add_dependency:
1752 * @plugin: a #GstPlugin
1753 * @env_vars: NULL-terminated array of environent variables affecting the
1754 * feature set of the plugin (e.g. an environment variable containing
1755 * paths where to look for additional modules/plugins of a library),
1756 * or NULL. Environment variable names may be followed by a path component
1757 * which will be added to the content of the environment variable, e.g.
1758 * "HOME/.mystuff/plugins".
1759 * @paths: NULL-terminated array of directories/paths where dependent files
1761 * @names: NULL-terminated array of file names (or file name suffixes,
1762 * depending on @flags) to be used in combination with the paths from
1763 * @paths and/or the paths extracted from the environment variables in
1764 * @env_vars, or NULL.
1765 * @flags: optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
1767 * Make GStreamer aware of external dependencies which affect the feature
1768 * set of this plugin (ie. the elements or typefinders associated with it).
1770 * GStreamer will re-inspect plugins with external dependencies whenever any
1771 * of the external dependencies change. This is useful for plugins which wrap
1772 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
1773 * library and makes visualisations available as GStreamer elements, or a
1774 * codec loader which exposes elements and/or caps dependent on what external
1775 * codec libraries are currently installed.
1780 gst_plugin_add_dependency (GstPlugin * plugin, const gchar ** env_vars,
1781 const gchar ** paths, const gchar ** names, GstPluginDependencyFlags flags)
1786 g_return_if_fail (GST_IS_PLUGIN (plugin));
1788 if ((env_vars == NULL || env_vars[0] == NULL) &&
1789 (paths == NULL || paths[0] == NULL)) {
1790 GST_DEBUG_OBJECT (plugin,
1791 "plugin registered empty dependency set. Ignoring");
1795 for (l = plugin->priv->deps; l != NULL; l = l->next) {
1796 if (gst_plugin_ext_dep_equals (l->data, env_vars, paths, names, flags)) {
1797 GST_LOG_OBJECT (plugin, "dependency already registered");
1802 dep = g_slice_new (GstPluginDep);
1804 dep->env_vars = g_strdupv ((gchar **) env_vars);
1805 dep->paths = g_strdupv ((gchar **) paths);
1806 dep->names = g_strdupv ((gchar **) names);
1809 dep->env_hash = gst_plugin_ext_dep_get_env_vars_hash (plugin, dep);
1810 dep->stat_hash = gst_plugin_ext_dep_get_stat_hash (plugin, dep);
1812 plugin->priv->deps = g_list_append (plugin->priv->deps, dep);
1814 GST_DEBUG_OBJECT (plugin, "added dependency:");
1815 for (; env_vars != NULL && *env_vars != NULL; ++env_vars)
1816 GST_DEBUG_OBJECT (plugin, " evar: %s", *env_vars);
1817 for (; paths != NULL && *paths != NULL; ++paths)
1818 GST_DEBUG_OBJECT (plugin, " path: %s", *paths);
1819 for (; names != NULL && *names != NULL; ++names)
1820 GST_DEBUG_OBJECT (plugin, " name: %s", *names);
1824 * gst_plugin_add_dependency_simple:
1825 * @plugin: the #GstPlugin
1826 * @env_vars: one or more environent variables (separated by ':', ';' or ','),
1827 * or NULL. Environment variable names may be followed by a path component
1828 * which will be added to the content of the environment variable, e.g.
1829 * "HOME/.mystuff/plugins:MYSTUFF_PLUGINS_PATH"
1830 * @paths: one ore more directory paths (separated by ':' or ';' or ','),
1831 * or NULL. Example: "/usr/lib/mystuff/plugins"
1832 * @names: one or more file names or file name suffixes (separated by commas),
1834 * @flags: optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
1836 * Make GStreamer aware of external dependencies which affect the feature
1837 * set of this plugin (ie. the elements or typefinders associated with it).
1839 * GStreamer will re-inspect plugins with external dependencies whenever any
1840 * of the external dependencies change. This is useful for plugins which wrap
1841 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
1842 * library and makes visualisations available as GStreamer elements, or a
1843 * codec loader which exposes elements and/or caps dependent on what external
1844 * codec libraries are currently installed.
1846 * Convenience wrapper function for gst_plugin_add_dependency() which
1847 * takes simple strings as arguments instead of string arrays, with multiple
1848 * arguments separated by predefined delimiters (see above).
1853 gst_plugin_add_dependency_simple (GstPlugin * plugin,
1854 const gchar * env_vars, const gchar * paths, const gchar * names,
1855 GstPluginDependencyFlags flags)
1857 gchar **a_evars = NULL;
1858 gchar **a_paths = NULL;
1859 gchar **a_names = NULL;
1862 a_evars = g_strsplit_set (env_vars, ":;,", -1);
1864 a_paths = g_strsplit_set (paths, ":;,", -1);
1866 a_names = g_strsplit_set (names, ",", -1);
1868 gst_plugin_add_dependency (plugin, (const gchar **) a_evars,
1869 (const gchar **) a_paths, (const gchar **) a_names, flags);
1872 g_strfreev (a_evars);
1874 g_strfreev (a_paths);
1876 g_strfreev (a_names);