2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2005 David A. Schleef <ds@schleef.org>
6 * gstregistry.c: handle registry
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
26 * @short_description: Abstract base class for management of #GstPlugin objects
27 * @see_also: #GstPlugin, #GstPluginFeature
29 * One registry holds the metadata of a set of plugins.
31 * <emphasis role="bold">Design:</emphasis>
33 * The #GstRegistry object is a list of plugins and some functions for dealing
34 * with them. Each #GstPlugin is matched 1-1 with a file on disk, and may or may
35 * not be loaded at a given time.
37 * The primary source, at all times, of plugin information is each plugin file
38 * itself. Thus, if an application wants information about a particular plugin,
39 * or wants to search for a feature that satisfies given criteria, the primary
40 * means of doing so is to load every plugin and look at the resulting
41 * information that is gathered in the default registry. Clearly, this is a time
42 * consuming process, so we cache information in the registry file. The format
43 * and location of the cache file is internal to gstreamer.
45 * On startup, plugins are searched for in the plugin search path. The following
46 * locations are checked in this order:
49 * <para>location from --gst-plugin-path commandline option.</para>
52 * <para>the GST_PLUGIN_PATH environment variable.</para>
55 * <para>the GST_PLUGIN_SYSTEM_PATH environment variable.</para>
58 * <para>default locations (if GST_PLUGIN_SYSTEM_PATH is not set). Those
59 * default locations are:
60 * <filename>$XDG_DATA_HOME/gstreamer-$GST_API_VERSION/plugins/</filename>
61 * and <filename>$prefix/libs/gstreamer-$GST_API_VERSION/</filename>.
62 * <ulink url="http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">
63 * <filename>$XDG_DATA_HOME</filename></ulink> defaults to
64 * <filename>$HOME/.local/share</filename>.
68 * The registry cache file is loaded from
69 * <filename>$XDG_CACHE_HOME/gstreamer-$GST_API_VERSION/registry-$ARCH.bin</filename>
71 * <ulink url="http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">
72 * <filename>$XDG_CACHE_HOME</filename></ulink> defaults to
73 * <filename>$HOME/.cache</filename>) or the file listed in the GST_REGISTRY
74 * env var. One reason to change the registry location is for testing.
76 * For each plugin that is found in the plugin search path, there could be 3
77 * possibilities for cached information:
80 * <para>the cache may not contain information about a given file.</para>
83 * <para>the cache may have stale information.</para>
86 * <para>the cache may have current information.</para>
90 * In the first two cases, the plugin is loaded and the cache updated. In
91 * addition to these cases, the cache may have entries for plugins that are not
92 * relevant to the current process. These are marked as not available to the
93 * current process. If the cache is updated for whatever reason, it is marked
96 * A dirty cache is written out at the end of initialization. Each entry is
97 * checked to make sure the information is minimally valid. If not, the entry is
100 * <emphasis role="bold">Implementation notes:</emphasis>
102 * The "cache" and "registry" are different concepts and can represent
103 * different sets of plugins. For various reasons, at init time, the cache is
104 * stored in the default registry, and plugins not relevant to the current
105 * process are marked with the %GST_PLUGIN_FLAG_CACHED bit. These plugins are
106 * removed at the end of initialization.
108 * Last reviewed on 2012-03-29 (0.11.3)
114 #include "gstconfig.h"
115 #include "gst_private.h"
117 #include <sys/types.h>
118 #include <sys/stat.h>
127 #include <glib/gstdio.h>
130 #include "gsterror.h"
131 #include "gstregistry.h"
133 #include "gstpluginloader.h"
135 #include "gst-i18n-lib.h"
138 #include "glib-compat-private.h"
142 extern HMODULE _priv_gst_dll_handle;
145 #define GST_CAT_DEFAULT GST_CAT_REGISTRY
147 struct _GstRegistryPrivate
158 /* hash to speedup _lookup_feature_locked() */
159 GHashTable *feature_hash;
160 /* hash to speedup _lookup */
161 GHashTable *basename_hash;
163 /* updated whenever the feature list changes */
165 /* speedup for searching features */
166 GList *element_factory_list;
168 GList *typefind_factory_list;
172 /* the one instance of the default registry and the mutex protecting the
174 static GMutex _gst_registry_mutex;
175 static GstRegistry *_gst_registry_default = NULL;
178 #define DEFAULT_FORK TRUE
180 /* control the behaviour of registry rebuild */
181 static gboolean _gst_enable_registry_fork = DEFAULT_FORK;
182 /* List of plugins that need preloading/reloading after scanning registry */
183 extern GSList *_priv_gst_preload_plugins;
185 #ifndef GST_DISABLE_REGISTRY
186 /*set to TRUE when registry needn't to be updated */
187 gboolean _priv_gst_disable_registry_update = FALSE;
188 extern GList *_priv_gst_plugin_paths;
190 /* Set to TRUE when the registry cache should be disabled */
191 gboolean _gst_disable_registry_cache = FALSE;
193 static gboolean __registry_reuse_plugin_scanner = TRUE;
196 /* Element signals and args */
204 static void gst_registry_finalize (GObject * object);
206 static guint gst_registry_signals[LAST_SIGNAL] = { 0 };
208 static GstPluginFeature *gst_registry_lookup_feature_locked (GstRegistry *
209 registry, const char *name);
210 static GstPlugin *gst_registry_lookup_bn_locked (GstRegistry * registry,
211 const char *basename);
213 #define gst_registry_parent_class parent_class
214 G_DEFINE_TYPE (GstRegistry, gst_registry, GST_TYPE_OBJECT);
217 gst_registry_class_init (GstRegistryClass * klass)
219 GObjectClass *gobject_class;
221 gobject_class = (GObjectClass *) klass;
223 g_type_class_add_private (klass, sizeof (GstRegistryPrivate));
226 * GstRegistry::plugin-added:
227 * @registry: the registry that emitted the signal
228 * @plugin: the plugin that has been added
230 * Signals that a plugin has been added to the registry (possibly
231 * replacing a previously-added one by the same name)
233 gst_registry_signals[PLUGIN_ADDED] =
234 g_signal_new ("plugin-added", G_TYPE_FROM_CLASS (klass),
235 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
236 G_TYPE_NONE, 1, GST_TYPE_PLUGIN);
239 * GstRegistry::feature-added:
240 * @registry: the registry that emitted the signal
241 * @feature: the feature that has been added
243 * Signals that a feature has been added to the registry (possibly
244 * replacing a previously-added one by the same name)
246 gst_registry_signals[FEATURE_ADDED] =
247 g_signal_new ("feature-added", G_TYPE_FROM_CLASS (klass),
248 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
249 G_TYPE_NONE, 1, GST_TYPE_PLUGIN_FEATURE);
251 gobject_class->finalize = gst_registry_finalize;
255 gst_registry_init (GstRegistry * registry)
258 G_TYPE_INSTANCE_GET_PRIVATE (registry, GST_TYPE_REGISTRY,
260 registry->priv->feature_hash = g_hash_table_new (g_str_hash, g_str_equal);
261 registry->priv->basename_hash = g_hash_table_new (g_str_hash, g_str_equal);
265 gst_registry_finalize (GObject * object)
267 GstRegistry *registry = GST_REGISTRY (object);
271 plugins = registry->priv->plugins;
272 registry->priv->plugins = NULL;
274 GST_DEBUG_OBJECT (registry, "registry finalize");
277 GstPlugin *plugin = p->data;
280 GST_LOG_OBJECT (registry, "removing plugin %s",
281 gst_plugin_get_name (plugin));
282 gst_object_unref (plugin);
286 g_list_free (plugins);
288 features = registry->priv->features;
289 registry->priv->features = NULL;
293 GstPluginFeature *feature = f->data;
296 GST_LOG_OBJECT (registry, "removing feature %p (%s)", feature,
297 GST_OBJECT_NAME (feature));
298 gst_object_unparent (GST_OBJECT_CAST (feature));
302 g_list_free (features);
304 g_hash_table_destroy (registry->priv->feature_hash);
305 registry->priv->feature_hash = NULL;
306 g_hash_table_destroy (registry->priv->basename_hash);
307 registry->priv->basename_hash = NULL;
309 if (registry->priv->element_factory_list) {
310 GST_DEBUG_OBJECT (registry, "Cleaning up cached element factory list");
311 gst_plugin_feature_list_free (registry->priv->element_factory_list);
314 if (registry->priv->typefind_factory_list) {
315 GST_DEBUG_OBJECT (registry, "Cleaning up cached typefind factory list");
316 gst_plugin_feature_list_free (registry->priv->typefind_factory_list);
319 G_OBJECT_CLASS (parent_class)->finalize (object);
325 * Retrieves the singleton plugin registry. The caller does not own a
326 * reference on the registry, as it is alive as long as GStreamer is
329 * Returns: (transfer none): the #GstRegistry.
332 gst_registry_get (void)
334 GstRegistry *registry;
336 g_mutex_lock (&_gst_registry_mutex);
337 if (G_UNLIKELY (!_gst_registry_default)) {
338 _gst_registry_default = g_object_newv (GST_TYPE_REGISTRY, 0, NULL);
339 gst_object_ref_sink (GST_OBJECT_CAST (_gst_registry_default));
341 registry = _gst_registry_default;
342 g_mutex_unlock (&_gst_registry_mutex);
349 * gst_registry_add_path:
350 * @registry: the registry to add the path to
351 * @path: the path to add to the registry
353 * Add the given path to the registry. The syntax of the
354 * path is specific to the registry. If the path has already been
358 gst_registry_add_path (GstRegistry * registry, const gchar * path)
360 g_return_if_fail (GST_IS_REGISTRY (registry));
361 g_return_if_fail (path != NULL);
363 if (strlen (path) == 0)
366 GST_OBJECT_LOCK (registry);
367 if (g_list_find_custom (registry->priv->paths, path, (GCompareFunc) strcmp))
370 GST_INFO ("Adding plugin path: \"%s\"", path);
371 registry->priv->paths =
372 g_list_append (registry->priv->paths, g_strdup (path));
373 GST_OBJECT_UNLOCK (registry);
379 GST_INFO ("Ignoring empty plugin path");
384 g_warning ("path %s already added to registry", path);
385 GST_OBJECT_UNLOCK (registry);
391 * gst_registry_get_path_list:
392 * @registry: the registry to get the pathlist of
394 * Get the list of paths for the given registry.
396 * Returns: (transfer container) (element-type char*): A #GList of paths as
397 * strings. g_list_free after use.
402 gst_registry_get_path_list (GstRegistry * registry)
406 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
408 GST_OBJECT_LOCK (registry);
409 /* We don't need to copy the strings, because they won't be deleted
410 * as long as the GstRegistry is around */
411 list = g_list_copy (registry->priv->paths);
412 GST_OBJECT_UNLOCK (registry);
419 * gst_registry_add_plugin:
420 * @registry: the registry to add the plugin to
421 * @plugin: (transfer full): the plugin to add
423 * Add the plugin to the registry. The plugin-added signal will be emitted.
424 * This function will sink @plugin.
426 * Returns: TRUE on success.
431 gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin)
433 GstPlugin *existing_plugin;
435 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
436 g_return_val_if_fail (GST_IS_PLUGIN (plugin), FALSE);
438 GST_OBJECT_LOCK (registry);
439 if (G_LIKELY (plugin->basename)) {
440 /* we have a basename, see if we find the plugin */
442 gst_registry_lookup_bn_locked (registry, plugin->basename);
443 if (existing_plugin) {
444 GST_DEBUG_OBJECT (registry,
445 "Replacing existing plugin \"%s\" %p with new plugin %p for filename \"%s\"",
446 GST_STR_NULL (existing_plugin->filename), existing_plugin, plugin,
447 GST_STR_NULL (plugin->filename));
448 /* If the new plugin is blacklisted and the existing one isn't cached, do not
449 * accept if it's from a different location than the existing one */
450 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED) &&
451 strcmp (plugin->filename, existing_plugin->filename)) {
452 GST_WARNING_OBJECT (registry,
453 "Not replacing plugin because new one (%s) is blacklisted but for a different location than existing one (%s)",
454 plugin->filename, existing_plugin->filename);
455 gst_object_unref (plugin);
456 GST_OBJECT_UNLOCK (registry);
459 registry->priv->plugins =
460 g_list_remove (registry->priv->plugins, existing_plugin);
461 if (G_LIKELY (existing_plugin->basename))
462 g_hash_table_remove (registry->priv->basename_hash,
463 existing_plugin->basename);
464 gst_object_unref (existing_plugin);
468 GST_DEBUG_OBJECT (registry, "adding plugin %p for filename \"%s\"",
469 plugin, GST_STR_NULL (plugin->filename));
471 registry->priv->plugins = g_list_prepend (registry->priv->plugins, plugin);
472 if (G_LIKELY (plugin->basename))
473 g_hash_table_replace (registry->priv->basename_hash, plugin->basename,
476 gst_object_ref_sink (plugin);
477 GST_OBJECT_UNLOCK (registry);
479 GST_LOG_OBJECT (registry, "emitting plugin-added for filename \"%s\"",
480 GST_STR_NULL (plugin->filename));
481 g_signal_emit (registry, gst_registry_signals[PLUGIN_ADDED], 0, plugin);
487 gst_registry_remove_features_for_plugin_unlocked (GstRegistry * registry,
492 g_return_if_fail (GST_IS_REGISTRY (registry));
493 g_return_if_fail (GST_IS_PLUGIN (plugin));
495 /* Remove all features for this plugin */
496 f = registry->priv->features;
498 GList *next = g_list_next (f);
499 GstPluginFeature *feature = f->data;
501 if (G_UNLIKELY (feature && feature->plugin == plugin)) {
502 GST_DEBUG_OBJECT (registry, "removing feature %p (%s) for plugin %p (%s)",
503 feature, gst_plugin_feature_get_name (feature), plugin,
506 registry->priv->features =
507 g_list_delete_link (registry->priv->features, f);
508 g_hash_table_remove (registry->priv->feature_hash,
509 GST_OBJECT_NAME (feature));
510 gst_object_unparent (GST_OBJECT_CAST (feature));
514 registry->priv->cookie++;
518 * gst_registry_remove_plugin:
519 * @registry: the registry to remove the plugin from
520 * @plugin: (transfer none): the plugin to remove
522 * Remove the plugin from the registry.
527 gst_registry_remove_plugin (GstRegistry * registry, GstPlugin * plugin)
529 g_return_if_fail (GST_IS_REGISTRY (registry));
530 g_return_if_fail (GST_IS_PLUGIN (plugin));
532 GST_DEBUG_OBJECT (registry, "removing plugin %p (%s)",
533 plugin, gst_plugin_get_name (plugin));
535 GST_OBJECT_LOCK (registry);
536 registry->priv->plugins = g_list_remove (registry->priv->plugins, plugin);
537 if (G_LIKELY (plugin->basename))
538 g_hash_table_remove (registry->priv->basename_hash, plugin->basename);
539 gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
540 GST_OBJECT_UNLOCK (registry);
541 gst_object_unref (plugin);
545 * gst_registry_add_feature:
546 * @registry: the registry to add the plugin to
547 * @feature: (transfer full): the feature to add
549 * Add the feature to the registry. The feature-added signal will be emitted.
550 * This function sinks @feature.
552 * Returns: TRUE on success.
557 gst_registry_add_feature (GstRegistry * registry, GstPluginFeature * feature)
559 GstPluginFeature *existing_feature;
561 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
562 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
563 g_return_val_if_fail (GST_OBJECT_NAME (feature) != NULL, FALSE);
564 g_return_val_if_fail (feature->plugin_name != NULL, FALSE);
566 GST_OBJECT_LOCK (registry);
567 existing_feature = gst_registry_lookup_feature_locked (registry,
568 GST_OBJECT_NAME (feature));
569 if (G_UNLIKELY (existing_feature)) {
570 GST_DEBUG_OBJECT (registry, "replacing existing feature %p (%s)",
571 existing_feature, GST_OBJECT_NAME (feature));
572 /* Remove the existing feature from the list now, before we insert the new
573 * one, but don't unref yet because the hash is still storing a reference to
575 registry->priv->features =
576 g_list_remove (registry->priv->features, existing_feature);
579 GST_DEBUG_OBJECT (registry, "adding feature %p (%s)", feature,
580 GST_OBJECT_NAME (feature));
582 registry->priv->features = g_list_prepend (registry->priv->features, feature);
583 g_hash_table_replace (registry->priv->feature_hash, GST_OBJECT_NAME (feature),
586 if (G_UNLIKELY (existing_feature)) {
587 /* We unref now. No need to remove the feature name from the hash table, it
588 * got replaced by the new feature */
589 gst_object_unparent (GST_OBJECT_CAST (existing_feature));
592 gst_object_set_parent (GST_OBJECT_CAST (feature), GST_OBJECT_CAST (registry));
594 registry->priv->cookie++;
595 GST_OBJECT_UNLOCK (registry);
597 GST_LOG_OBJECT (registry, "emitting feature-added for %s",
598 GST_OBJECT_NAME (feature));
599 g_signal_emit (registry, gst_registry_signals[FEATURE_ADDED], 0, feature);
605 * gst_registry_remove_feature:
606 * @registry: the registry to remove the feature from
607 * @feature: (transfer none): the feature to remove
609 * Remove the feature from the registry.
614 gst_registry_remove_feature (GstRegistry * registry, GstPluginFeature * feature)
616 g_return_if_fail (GST_IS_REGISTRY (registry));
617 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
619 GST_DEBUG_OBJECT (registry, "removing feature %p (%s)",
620 feature, gst_plugin_feature_get_name (feature));
622 GST_OBJECT_LOCK (registry);
623 registry->priv->features = g_list_remove (registry->priv->features, feature);
624 g_hash_table_remove (registry->priv->feature_hash, GST_OBJECT_NAME (feature));
625 registry->priv->cookie++;
626 GST_OBJECT_UNLOCK (registry);
628 gst_object_unparent ((GstObject *) feature);
632 * gst_registry_plugin_filter:
633 * @registry: registry to query
634 * @filter: (scope call): the filter to use
635 * @first: only return first match
636 * @user_data: (closure): user data passed to the filter function
638 * Runs a filter against all plugins in the registry and returns a #GList with
639 * the results. If the first flag is set, only the first match is
640 * returned (as a list with a single object).
641 * Every plugin is reffed; use gst_plugin_list_free() after use, which
644 * Returns: (transfer full) (element-type Gst.Plugin): a #GList of #GstPlugin.
645 * Use gst_plugin_list_free() after usage.
650 gst_registry_plugin_filter (GstRegistry * registry,
651 GstPluginFilter filter, gboolean first, gpointer user_data)
655 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
657 GST_OBJECT_LOCK (registry);
661 for (walk = registry->priv->plugins; walk != NULL; walk = walk->next) {
662 GstPlugin *plugin = walk->data;
664 if (filter == NULL || filter (plugin, user_data)) {
665 list = g_list_prepend (list, gst_object_ref (plugin));
672 GST_OBJECT_UNLOCK (registry);
684 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
685 GstTypeNameData * data)
687 g_assert (GST_IS_PLUGIN_FEATURE (feature));
689 return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
690 (data->name == NULL || !strcmp (data->name, GST_OBJECT_NAME (feature))));
693 /* returns TRUE if the list was changed
695 * Must be called with the object lock taken */
697 gst_registry_get_feature_list_or_create (GstRegistry * registry,
698 GList ** previous, guint32 * cookie, GType type)
700 gboolean res = FALSE;
701 GstRegistryPrivate *priv = registry->priv;
703 if (G_UNLIKELY (!*previous || priv->cookie != *cookie)) {
704 GstTypeNameData data;
708 gst_plugin_feature_list_free (*previous);
715 for (walk = registry->priv->features; walk != NULL; walk = walk->next) {
716 GstPluginFeature *feature = walk->data;
718 if (gst_plugin_feature_type_name_filter (feature, &data)) {
719 *previous = g_list_prepend (*previous, gst_object_ref (feature));
723 *cookie = priv->cookie;
731 type_find_factory_rank_cmp (const GstPluginFeature * fac1,
732 const GstPluginFeature * fac2)
734 if (G_LIKELY (fac1->rank != fac2->rank))
735 return fac2->rank - fac1->rank;
737 /* to make the order in which things happen more deterministic,
738 * sort by name when the ranks are the same. */
739 return strcmp (GST_OBJECT_NAME (fac1), GST_OBJECT_NAME (fac2));
743 gst_registry_get_element_factory_list (GstRegistry * registry)
747 GST_OBJECT_LOCK (registry);
749 gst_registry_get_feature_list_or_create (registry,
750 ®istry->priv->element_factory_list, ®istry->priv->efl_cookie,
751 GST_TYPE_ELEMENT_FACTORY);
753 /* Return reffed copy */
754 list = gst_plugin_feature_list_copy (registry->priv->element_factory_list);
756 GST_OBJECT_UNLOCK (registry);
762 gst_registry_get_typefind_factory_list (GstRegistry * registry)
766 GST_OBJECT_LOCK (registry);
768 if (G_UNLIKELY (gst_registry_get_feature_list_or_create (registry,
769 ®istry->priv->typefind_factory_list,
770 ®istry->priv->tfl_cookie, GST_TYPE_TYPE_FIND_FACTORY)))
771 registry->priv->typefind_factory_list =
772 g_list_sort (registry->priv->typefind_factory_list,
773 (GCompareFunc) type_find_factory_rank_cmp);
775 /* Return reffed copy */
776 list = gst_plugin_feature_list_copy (registry->priv->typefind_factory_list);
778 GST_OBJECT_UNLOCK (registry);
784 * gst_registry_feature_filter:
785 * @registry: registry to query
786 * @filter: (scope call): the filter to use
787 * @first: only return first match
788 * @user_data: (closure): user data passed to the filter function
790 * Runs a filter against all features of the plugins in the registry
791 * and returns a GList with the results.
792 * If the first flag is set, only the first match is
793 * returned (as a list with a single object).
795 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
796 * #GstPluginFeature. Use gst_plugin_feature_list_free() after usage.
801 gst_registry_feature_filter (GstRegistry * registry,
802 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
806 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
808 GST_OBJECT_LOCK (registry);
812 for (walk = registry->priv->features; walk != NULL; walk = walk->next) {
813 GstPluginFeature *feature = walk->data;
815 if (filter == NULL || filter (feature, user_data)) {
816 list = g_list_prepend (list, gst_object_ref (feature));
823 GST_OBJECT_UNLOCK (registry);
829 gst_registry_plugin_name_filter (GstPlugin * plugin, const gchar * name)
831 return (plugin->desc.name && !strcmp (plugin->desc.name, name));
835 * gst_registry_find_plugin:
836 * @registry: the registry to search
837 * @name: the plugin name to find
839 * Find the plugin with the given name in the registry.
840 * The plugin will be reffed; caller is responsible for unreffing.
842 * Returns: (transfer full): the plugin with the given name or NULL if the
843 * plugin was not found. gst_object_unref() after usage.
848 gst_registry_find_plugin (GstRegistry * registry, const gchar * name)
851 GstPlugin *result = NULL;
853 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
854 g_return_val_if_fail (name != NULL, NULL);
856 walk = gst_registry_plugin_filter (registry,
857 (GstPluginFilter) gst_registry_plugin_name_filter, TRUE, (gpointer) name);
859 result = GST_PLUGIN_CAST (walk->data);
861 gst_object_ref (result);
862 gst_plugin_list_free (walk);
869 * gst_registry_find_feature:
870 * @registry: the registry to search
871 * @name: the pluginfeature name to find
872 * @type: the pluginfeature type to find
874 * Find the pluginfeature with the given name and type in the registry.
876 * Returns: (transfer full): the pluginfeature with the given name and type
877 * or NULL if the plugin was not found. gst_object_unref() after usage.
882 gst_registry_find_feature (GstRegistry * registry, const gchar * name,
885 GstPluginFeature *feature = NULL;
887 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
888 g_return_val_if_fail (name != NULL, NULL);
889 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_PLUGIN_FEATURE), NULL);
891 feature = gst_registry_lookup_feature (registry, name);
892 if (feature && !g_type_is_a (G_TYPE_FROM_INSTANCE (feature), type)) {
893 gst_object_unref (feature);
901 * gst_registry_get_feature_list:
902 * @registry: a #GstRegistry
905 * Retrieves a #GList of #GstPluginFeature of @type.
907 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
908 * #GstPluginFeature of @type. Use gst_plugin_feature_list_free() after use
913 gst_registry_get_feature_list (GstRegistry * registry, GType type)
915 GstTypeNameData data;
917 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
918 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_PLUGIN_FEATURE), NULL);
921 if (type == GST_TYPE_ELEMENT_FACTORY)
922 return gst_registry_get_element_factory_list (registry);
923 else if (type == GST_TYPE_TYPE_FIND_FACTORY)
924 return gst_registry_get_typefind_factory_list (registry);
929 return gst_registry_feature_filter (registry,
930 (GstPluginFeatureFilter) gst_plugin_feature_type_name_filter,
935 * gst_registry_get_plugin_list:
936 * @registry: the registry to search
938 * Get a copy of all plugins registered in the given registry. The refcount
939 * of each element in the list in incremented.
941 * Returns: (transfer full) (element-type Gst.Plugin): a #GList of #GstPlugin.
942 * Use gst_plugin_list_free() after usage.
947 gst_registry_get_plugin_list (GstRegistry * registry)
952 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
954 GST_OBJECT_LOCK (registry);
955 list = g_list_copy (registry->priv->plugins);
956 for (g = list; g; g = g->next) {
957 gst_object_ref (GST_PLUGIN_CAST (g->data));
959 GST_OBJECT_UNLOCK (registry);
964 static GstPluginFeature *
965 gst_registry_lookup_feature_locked (GstRegistry * registry, const char *name)
967 return g_hash_table_lookup (registry->priv->feature_hash, name);
971 * gst_registry_lookup_feature:
972 * @registry: a #GstRegistry
973 * @name: a #GstPluginFeature name
975 * Find a #GstPluginFeature with @name in @registry.
977 * Returns: (transfer full): a #GstPluginFeature with its refcount incremented,
978 * use gst_object_unref() after usage.
983 gst_registry_lookup_feature (GstRegistry * registry, const char *name)
985 GstPluginFeature *feature;
987 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
988 g_return_val_if_fail (name != NULL, NULL);
990 GST_OBJECT_LOCK (registry);
991 feature = gst_registry_lookup_feature_locked (registry, name);
993 gst_object_ref (feature);
994 GST_OBJECT_UNLOCK (registry);
1000 gst_registry_lookup_bn_locked (GstRegistry * registry, const char *basename)
1002 return g_hash_table_lookup (registry->priv->basename_hash, basename);
1006 gst_registry_lookup_bn (GstRegistry * registry, const char *basename)
1010 GST_OBJECT_LOCK (registry);
1011 plugin = gst_registry_lookup_bn_locked (registry, basename);
1013 gst_object_ref (plugin);
1014 GST_OBJECT_UNLOCK (registry);
1020 * gst_registry_lookup:
1021 * @registry: the registry to look up in
1022 * @filename: the name of the file to look up
1024 * Look up a plugin in the given registry with the given filename.
1025 * If found, plugin is reffed.
1027 * Returns: (transfer full): the #GstPlugin if found, or NULL if not.
1028 * gst_object_unref() after usage.
1031 gst_registry_lookup (GstRegistry * registry, const char *filename)
1036 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1037 g_return_val_if_fail (filename != NULL, NULL);
1039 basename = g_path_get_basename (filename);
1040 if (G_UNLIKELY (basename == NULL))
1043 plugin = gst_registry_lookup_bn (registry, basename);
1052 REGISTRY_SCAN_HELPER_NOT_STARTED = 0,
1053 REGISTRY_SCAN_HELPER_DISABLED,
1054 REGISTRY_SCAN_HELPER_RUNNING
1055 } GstRegistryScanHelperState;
1059 GstRegistry *registry;
1060 GstRegistryScanHelperState helper_state;
1061 GstPluginLoader *helper;
1063 } GstRegistryScanContext;
1066 init_scan_context (GstRegistryScanContext * context, GstRegistry * registry)
1070 context->registry = registry;
1072 /* see if forking is enabled and set up the scan helper state accordingly */
1073 do_fork = _gst_enable_registry_fork;
1075 const gchar *fork_env;
1077 /* forking enabled, see if it is disabled with an env var */
1078 if ((fork_env = g_getenv ("GST_REGISTRY_FORK"))) {
1079 /* fork enabled for any value different from "no" */
1080 do_fork = strcmp (fork_env, "no") != 0;
1085 context->helper_state = REGISTRY_SCAN_HELPER_NOT_STARTED;
1087 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1089 context->helper = NULL;
1090 context->changed = FALSE;
1094 clear_scan_context (GstRegistryScanContext * context)
1096 if (context->helper) {
1097 context->changed |= _priv_gst_plugin_loader_funcs.destroy (context->helper);
1098 context->helper = NULL;
1103 gst_registry_scan_plugin_file (GstRegistryScanContext * context,
1104 const gchar * filename, off_t file_size, time_t file_mtime)
1106 gboolean changed = FALSE;
1107 GstPlugin *newplugin = NULL;
1110 /* Disable external plugin loader on Windows until it is ported properly. */
1111 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1115 /* Have a plugin to load - see if the scan-helper needs starting */
1116 if (context->helper_state == REGISTRY_SCAN_HELPER_NOT_STARTED) {
1117 GST_DEBUG ("Starting plugin scanner for file %s", filename);
1118 context->helper = _priv_gst_plugin_loader_funcs.create (context->registry);
1119 if (context->helper != NULL)
1120 context->helper_state = REGISTRY_SCAN_HELPER_RUNNING;
1122 GST_WARNING ("Failed starting plugin scanner. Scanning in-process");
1123 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1127 if (context->helper_state == REGISTRY_SCAN_HELPER_RUNNING) {
1128 GST_DEBUG ("Using scan-helper to load plugin %s", filename);
1129 if (!_priv_gst_plugin_loader_funcs.load (context->helper,
1130 filename, file_size, file_mtime)) {
1131 g_warning ("External plugin loader failed. This most likely means that "
1132 "the plugin loader helper binary was not found or could not be run. "
1133 "You might need to set the GST_PLUGIN_SCANNER environment variable "
1134 "if your setup is unusual. This should normally not be required "
1136 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1140 /* Check if the helper is disabled (or just got disabled above) */
1141 if (context->helper_state == REGISTRY_SCAN_HELPER_DISABLED) {
1142 /* Load plugin the old fashioned way... */
1144 /* We don't use a GError here because a failure to load some shared
1145 * objects as plugins is normal (particularly in the uninstalled case)
1147 newplugin = gst_plugin_load_file (filename, NULL);
1151 GST_DEBUG_OBJECT (context->registry, "marking new plugin %p as registered",
1153 newplugin->registered = TRUE;
1154 gst_object_unref (newplugin);
1157 #ifndef GST_DISABLE_REGISTRY
1158 if (!__registry_reuse_plugin_scanner) {
1159 clear_scan_context (context);
1160 context->helper_state = REGISTRY_SCAN_HELPER_NOT_STARTED;
1168 is_blacklisted_hidden_directory (const gchar * dirent)
1170 if (G_LIKELY (dirent[0] != '.'))
1173 /* skip the .debug directory, these contain elf files that are not
1174 * useful or worse, can crash dlopen () */
1175 if (strcmp (dirent, ".debug") == 0)
1178 /* can also skip .git and .deps dirs, those won't contain useful files.
1179 * This speeds up scanning a bit in uninstalled setups. */
1180 if (strcmp (dirent, ".git") == 0 || strcmp (dirent, ".deps") == 0)
1187 gst_registry_scan_path_level (GstRegistryScanContext * context,
1188 const gchar * path, int level)
1191 const gchar *dirent;
1194 gboolean changed = FALSE;
1196 dir = g_dir_open (path, 0, NULL);
1200 while ((dirent = g_dir_read_name (dir))) {
1201 GStatBuf file_status;
1203 filename = g_build_filename (path, dirent, NULL);
1204 if (g_stat (filename, &file_status) < 0) {
1205 /* Plugin will be removed from cache after the scan completes if it
1206 * is still marked 'cached' */
1211 if (file_status.st_mode & S_IFDIR) {
1212 if (G_UNLIKELY (is_blacklisted_hidden_directory (dirent))) {
1213 GST_TRACE_OBJECT (context->registry, "ignoring %s directory", dirent);
1217 /* FIXME 0.11: Don't recurse into directories, this behaviour
1218 * is inconsistent with other PATH environment variables
1221 GST_LOG_OBJECT (context->registry, "recursing into directory %s",
1223 changed |= gst_registry_scan_path_level (context, filename, level - 1);
1225 GST_LOG_OBJECT (context->registry, "not recursing into directory %s, "
1226 "recursion level too deep", filename);
1231 if (!(file_status.st_mode & S_IFREG)) {
1232 GST_TRACE_OBJECT (context->registry, "%s is not a regular file, ignoring",
1237 if (!g_str_has_suffix (dirent, G_MODULE_SUFFIX)
1238 #ifdef GST_EXTRA_MODULE_SUFFIX
1239 && !g_str_has_suffix (dirent, GST_EXTRA_MODULE_SUFFIX)
1242 GST_TRACE_OBJECT (context->registry,
1243 "extension is not recognized as module file, ignoring file %s",
1249 GST_LOG_OBJECT (context->registry, "file %s looks like a possible module",
1252 /* try to avoid unnecessary plugin-move pain */
1253 if (g_str_has_prefix (dirent, "libgstvalve") ||
1254 g_str_has_prefix (dirent, "libgstselector")) {
1255 GST_WARNING_OBJECT (context->registry, "ignoring old plugin %s which "
1256 "has been merged into the corelements plugin", filename);
1257 /* Plugin will be removed from cache after the scan completes if it
1258 * is still marked 'cached' */
1263 /* plug-ins are considered unique by basename; if the given name
1264 * was already seen by the registry, we ignore it */
1265 plugin = gst_registry_lookup_bn (context->registry, dirent);
1267 gboolean env_vars_changed, deps_changed = FALSE;
1269 if (plugin->registered) {
1270 GST_DEBUG_OBJECT (context->registry,
1271 "plugin already registered from path \"%s\"",
1272 GST_STR_NULL (plugin->filename));
1274 gst_object_unref (plugin);
1278 env_vars_changed = _priv_plugin_deps_env_vars_changed (plugin);
1280 /* If a file with a certain basename is seen on a different path,
1281 * update the plugin to ensure the registry cache will reflect up
1282 * to date information */
1284 if (plugin->file_mtime == file_status.st_mtime &&
1285 plugin->file_size == file_status.st_size && !env_vars_changed &&
1286 !(deps_changed = _priv_plugin_deps_files_changed (plugin)) &&
1287 !strcmp (plugin->filename, filename)) {
1288 GST_LOG_OBJECT (context->registry, "file %s cached", filename);
1289 GST_OBJECT_FLAG_UNSET (plugin, GST_PLUGIN_FLAG_CACHED);
1290 GST_LOG_OBJECT (context->registry,
1291 "marking plugin %p as registered as %s", plugin, filename);
1292 plugin->registered = TRUE;
1294 GST_INFO_OBJECT (context->registry, "cached info for %s is stale",
1296 GST_DEBUG_OBJECT (context->registry, "mtime %" G_GINT64_FORMAT " != %"
1297 G_GINT64_FORMAT " or size %" G_GINT64_FORMAT " != %"
1298 G_GINT64_FORMAT " or external dependency env_vars changed: %d or"
1299 " external dependencies changed: %d or old path %s != new path %s",
1300 (gint64) plugin->file_mtime, (gint64) file_status.st_mtime,
1301 (gint64) plugin->file_size, (gint64) file_status.st_size,
1302 env_vars_changed, deps_changed, plugin->filename, filename);
1303 gst_registry_remove_plugin (context->registry, plugin);
1304 changed |= gst_registry_scan_plugin_file (context, filename,
1305 file_status.st_size, file_status.st_mtime);
1307 gst_object_unref (plugin);
1310 GST_DEBUG_OBJECT (context->registry, "file %s not yet in registry",
1312 changed |= gst_registry_scan_plugin_file (context, filename,
1313 file_status.st_size, file_status.st_mtime);
1325 gst_registry_scan_path_internal (GstRegistryScanContext * context,
1330 GST_DEBUG_OBJECT (context->registry, "scanning path %s", path);
1331 changed = gst_registry_scan_path_level (context, path, 10);
1333 GST_DEBUG_OBJECT (context->registry, "registry changed in path %s: %d", path,
1339 * gst_registry_scan_path:
1340 * @registry: the registry to add found plugins to
1341 * @path: the path to scan
1343 * Scan the given path for plugins to add to the registry. The syntax of the
1344 * path is specific to the registry.
1346 * Returns: %TRUE if registry changed
1349 gst_registry_scan_path (GstRegistry * registry, const gchar * path)
1351 GstRegistryScanContext context;
1354 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
1355 g_return_val_if_fail (path != NULL, FALSE);
1357 init_scan_context (&context, registry);
1359 result = gst_registry_scan_path_internal (&context, path);
1361 clear_scan_context (&context);
1362 result |= context.changed;
1368 _gst_plugin_feature_filter_plugin_name (GstPluginFeature * feature,
1371 return (strcmp (feature->plugin_name, (gchar *) user_data) == 0);
1375 * gst_registry_get_feature_list_by_plugin:
1376 * @registry: a #GstRegistry.
1377 * @name: a plugin name.
1379 * Retrieves a #GList of features of the plugin with name @name.
1381 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
1382 * #GstPluginFeature. Use gst_plugin_feature_list_free() after usage.
1385 gst_registry_get_feature_list_by_plugin (GstRegistry * registry,
1388 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1389 g_return_val_if_fail (name != NULL, NULL);
1391 return gst_registry_feature_filter (registry,
1392 _gst_plugin_feature_filter_plugin_name, FALSE, (gpointer) name);
1395 /* Unref and delete the default registry */
1397 _priv_gst_registry_cleanup (void)
1399 GstRegistry *registry;
1401 g_mutex_lock (&_gst_registry_mutex);
1402 if ((registry = _gst_registry_default) != NULL) {
1403 _gst_registry_default = NULL;
1405 g_mutex_unlock (&_gst_registry_mutex);
1407 /* unref outside of the lock because we can. */
1409 gst_object_unref (registry);
1413 * gst_registry_check_feature_version:
1414 * @registry: a #GstRegistry
1415 * @feature_name: the name of the feature (e.g. "oggdemux")
1416 * @min_major: the minimum major version number
1417 * @min_minor: the minimum minor version number
1418 * @min_micro: the minimum micro version number
1420 * Checks whether a plugin feature by the given name exists in
1421 * @registry and whether its version is at least the
1424 * Returns: #TRUE if the feature could be found and the version is
1425 * the same as the required version or newer, and #FALSE otherwise.
1428 gst_registry_check_feature_version (GstRegistry * registry,
1429 const gchar * feature_name, guint min_major, guint min_minor,
1432 GstPluginFeature *feature;
1433 gboolean ret = FALSE;
1435 g_return_val_if_fail (feature_name != NULL, FALSE);
1437 GST_DEBUG ("Looking up plugin feature '%s'", feature_name);
1439 feature = gst_registry_lookup_feature (registry, feature_name);
1441 ret = gst_plugin_feature_check_version (feature, min_major, min_minor,
1443 gst_object_unref (feature);
1445 GST_DEBUG ("Could not find plugin feature '%s'", feature_name);
1452 load_plugin_func (gpointer data, gpointer user_data)
1455 const gchar *filename;
1458 filename = (const gchar *) data;
1459 GST_DEBUG ("Pre-loading plugin %s", filename);
1461 plugin = gst_plugin_load_file (filename, &err);
1464 GST_INFO ("Loaded plugin: \"%s\"", filename);
1466 gst_registry_add_plugin (gst_registry_get (), plugin);
1469 /* Report error to user, and free error */
1470 GST_ERROR ("Failed to load plugin: %s", err->message);
1473 GST_WARNING ("Failed to load plugin: \"%s\"", filename);
1478 #ifndef GST_DISABLE_REGISTRY
1479 /* Unref all plugins marked 'cached', to clear old plugins that no
1480 * longer exist. Returns TRUE if any plugins were removed */
1482 gst_registry_remove_cache_plugins (GstRegistry * registry)
1487 gboolean changed = FALSE;
1489 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
1491 GST_OBJECT_LOCK (registry);
1493 GST_DEBUG_OBJECT (registry, "removing cached plugins");
1494 g = registry->priv->plugins;
1498 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_CACHED)) {
1499 GST_DEBUG_OBJECT (registry, "removing cached plugin \"%s\"",
1500 GST_STR_NULL (plugin->filename));
1501 registry->priv->plugins = g_list_delete_link (registry->priv->plugins, g);
1502 if (G_LIKELY (plugin->basename))
1503 g_hash_table_remove (registry->priv->basename_hash, plugin->basename);
1504 gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
1505 gst_object_unref (plugin);
1511 GST_OBJECT_UNLOCK (registry);
1518 REGISTRY_SCAN_AND_UPDATE_FAILURE = 0,
1519 REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED,
1520 REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED
1521 } GstRegistryScanAndUpdateResult;
1524 * scan_and_update_registry:
1525 * @default_registry: the #GstRegistry
1526 * @registry_file: registry filename
1527 * @write_changes: write registry if it has changed?
1529 * Scans for registry changes and eventually updates the registry cache.
1531 * Return: %REGISTRY_SCAN_AND_UPDATE_FAILURE if the registry could not scanned
1532 * or updated, %REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED if the
1533 * registry is clean and %REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED if
1534 * it has been updated and the cache needs to be re-read.
1536 static GstRegistryScanAndUpdateResult
1537 scan_and_update_registry (GstRegistry * default_registry,
1538 const gchar * registry_file, gboolean write_changes, GError ** error)
1540 const gchar *plugin_path;
1541 gboolean changed = FALSE;
1543 GstRegistryScanContext context;
1545 GST_INFO ("Validating plugins from registry cache: %s", registry_file);
1547 init_scan_context (&context, default_registry);
1549 /* It sounds tempting to just compare the mtime of directories with the mtime
1550 * of the registry cache, but it does not work. It would not catch updated
1551 * plugins, which might bring more or less features.
1554 /* scan paths specified via --gst-plugin-path */
1555 GST_DEBUG ("scanning paths added via --gst-plugin-path");
1556 for (l = _priv_gst_plugin_paths; l != NULL; l = l->next) {
1557 GST_INFO ("Scanning plugin path: \"%s\"", (gchar *) l->data);
1558 changed |= gst_registry_scan_path_internal (&context, (gchar *) l->data);
1560 /* keep plugin_paths around in case a re-scan is forced later on */
1562 /* GST_PLUGIN_PATH specifies a list of directories to scan for
1563 * additional plugins. These take precedence over the system plugins */
1564 plugin_path = g_getenv ("GST_PLUGIN_PATH_1_0");
1565 if (plugin_path == NULL)
1566 plugin_path = g_getenv ("GST_PLUGIN_PATH");
1571 GST_DEBUG ("GST_PLUGIN_PATH set to %s", plugin_path);
1572 list = g_strsplit (plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
1573 for (i = 0; list[i]; i++) {
1574 changed |= gst_registry_scan_path_internal (&context, list[i]);
1578 GST_DEBUG ("GST_PLUGIN_PATH not set");
1581 /* GST_PLUGIN_SYSTEM_PATH specifies a list of plugins that are always
1582 * loaded by default. If not set, this defaults to the system-installed
1583 * path, and the plugins installed in the user's home directory */
1584 plugin_path = g_getenv ("GST_PLUGIN_SYSTEM_PATH_1_0");
1585 if (plugin_path == NULL)
1586 plugin_path = g_getenv ("GST_PLUGIN_SYSTEM_PATH");
1587 if (plugin_path == NULL) {
1590 GST_DEBUG ("GST_PLUGIN_SYSTEM_PATH not set");
1592 /* plugins in the user's home directory take precedence over
1593 * system-installed ones */
1594 home_plugins = g_build_filename (g_get_user_data_dir (),
1595 "gstreamer-" GST_API_VERSION, "plugins", NULL);
1597 GST_DEBUG ("scanning home plugins %s", home_plugins);
1598 changed |= gst_registry_scan_path_internal (&context, home_plugins);
1599 g_free (home_plugins);
1601 /* add the main (installed) library path */
1609 g_win32_get_package_installation_directory_of_module
1610 (_priv_gst_dll_handle);
1613 g_build_filename (base_dir,
1618 "gstreamer-" GST_API_VERSION,
1620 GST_DEBUG ("scanning DLL dir %s", dir);
1622 changed |= gst_registry_scan_path_internal (&context, dir);
1628 GST_DEBUG ("scanning main plugins %s", PLUGINDIR);
1629 changed |= gst_registry_scan_path_internal (&context, PLUGINDIR);
1635 GST_DEBUG ("GST_PLUGIN_SYSTEM_PATH set to %s", plugin_path);
1636 list = g_strsplit (plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
1637 for (i = 0; list[i]; i++) {
1638 changed |= gst_registry_scan_path_internal (&context, list[i]);
1643 clear_scan_context (&context);
1644 changed |= context.changed;
1646 /* Remove cached plugins so stale info is cleared. */
1647 changed |= gst_registry_remove_cache_plugins (default_registry);
1650 GST_INFO ("Registry cache has not changed");
1651 return REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED;
1654 if (!write_changes) {
1655 GST_INFO ("Registry cache changed, but writing is disabled. Not writing.");
1656 return REGISTRY_SCAN_AND_UPDATE_FAILURE;
1659 GST_INFO ("Registry cache changed. Writing new registry cache");
1660 if (!priv_gst_registry_binary_write_cache (default_registry,
1661 default_registry->priv->plugins, registry_file)) {
1662 g_set_error (error, GST_CORE_ERROR, GST_CORE_ERROR_FAILED,
1663 _("Error writing registry cache to %s: %s"),
1664 registry_file, g_strerror (errno));
1665 return REGISTRY_SCAN_AND_UPDATE_FAILURE;
1668 GST_INFO ("Registry cache written successfully");
1669 return REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED;
1673 ensure_current_registry (GError ** error)
1675 gchar *registry_file;
1676 GstRegistry *default_registry;
1677 gboolean ret = TRUE;
1678 gboolean do_update = TRUE;
1679 gboolean have_cache = TRUE;
1681 default_registry = gst_registry_get ();
1683 registry_file = g_strdup (g_getenv ("GST_REGISTRY_1_0"));
1684 if (registry_file == NULL)
1685 registry_file = g_strdup (g_getenv ("GST_REGISTRY"));
1686 if (registry_file == NULL) {
1687 registry_file = g_build_filename (g_get_user_cache_dir (),
1688 "gstreamer-" GST_API_VERSION, "registry." TARGET_CPU ".bin", NULL);
1691 if (!_gst_disable_registry_cache) {
1692 GST_INFO ("reading registry cache: %s", registry_file);
1693 have_cache = priv_gst_registry_binary_read_cache (default_registry,
1695 /* Only ever read the registry cache once, then disable it for
1696 * subsequent updates during the program lifetime */
1697 _gst_disable_registry_cache = TRUE;
1701 do_update = !_priv_gst_disable_registry_update;
1703 const gchar *update_env;
1705 if ((update_env = g_getenv ("GST_REGISTRY_UPDATE"))) {
1706 /* do update for any value different from "no" */
1707 do_update = (strcmp (update_env, "no") != 0);
1713 const gchar *reuse_env;
1715 if ((reuse_env = g_getenv ("GST_REGISTRY_REUSE_PLUGIN_SCANNER"))) {
1716 /* do reuse for any value different from "no" */
1717 __registry_reuse_plugin_scanner = (strcmp (reuse_env, "no") != 0);
1719 /* now check registry */
1720 GST_DEBUG ("Updating registry cache");
1721 scan_and_update_registry (default_registry, registry_file, TRUE, error);
1723 GST_DEBUG ("Not updating registry cache (disabled)");
1726 g_free (registry_file);
1727 GST_INFO ("registry reading and updating done, result = %d", ret);
1731 #endif /* GST_DISABLE_REGISTRY */
1734 * gst_registry_fork_is_enabled:
1736 * By default GStreamer will perform scanning and rebuilding of the
1737 * registry file using a helper child process.
1739 * Applications might want to disable this behaviour with the
1740 * gst_registry_fork_set_enabled() function, in which case new plugins
1741 * are scanned (and loaded) into the application process.
1743 * Returns: %TRUE if GStreamer will use the child helper process when
1744 * rebuilding the registry.
1747 gst_registry_fork_is_enabled (void)
1749 return _gst_enable_registry_fork;
1753 * gst_registry_fork_set_enabled:
1754 * @enabled: whether rebuilding the registry can use a temporary child helper process.
1756 * Applications might want to disable/enable spawning of a child helper process
1757 * when rebuilding the registry. See gst_registry_fork_is_enabled() for more
1761 gst_registry_fork_set_enabled (gboolean enabled)
1763 _gst_enable_registry_fork = enabled;
1767 * gst_update_registry:
1769 * Forces GStreamer to re-scan its plugin paths and update the default
1772 * Applications will almost never need to call this function, it is only
1773 * useful if the application knows new plugins have been installed (or old
1774 * ones removed) since the start of the application (or, to be precise, the
1775 * first call to gst_init()) and the application wants to make use of any
1776 * newly-installed plugins without restarting the application.
1778 * Applications should assume that the registry update is neither atomic nor
1779 * thread-safe and should therefore not have any dynamic pipelines running
1780 * (including the playbin and decodebin elements) and should also not create
1781 * any elements or access the GStreamer registry while the update is in
1784 * Note that this function may block for a significant amount of time.
1786 * Returns: %TRUE if the registry has been updated successfully (does not
1787 * imply that there were changes), otherwise %FALSE.
1790 gst_update_registry (void)
1794 #ifndef GST_DISABLE_REGISTRY
1797 res = ensure_current_registry (&err);
1799 GST_WARNING ("registry update failed: %s", err->message);
1802 GST_LOG ("registry update succeeded");
1806 GST_WARNING ("registry update failed: %s", "registry disabled");
1808 #endif /* GST_DISABLE_REGISTRY */
1810 if (_priv_gst_preload_plugins) {
1811 GST_DEBUG ("Preloading indicated plugins...");
1812 g_slist_foreach (_priv_gst_preload_plugins, load_plugin_func, NULL);
1819 * gst_registry_get_feature_list_cookie:
1820 * @registry: the registry
1822 * Returns the registry's feature list cookie. This changes
1823 * every time a feature is added or removed from the registry.
1825 * Returns: the feature list cookie.
1828 gst_registry_get_feature_list_cookie (GstRegistry * registry)
1830 g_return_val_if_fail (GST_IS_REGISTRY (registry), 0);
1832 return registry->priv->cookie;