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>~/.gstreamer-$GST_API_VERSION/plugins/</filename>
61 * and <filename>$prefix/libs/gstreamer-$GST_API_VERSION/</filename>.
65 * The registry cache file is loaded from
66 * <filename>~/.gstreamer-$GST_API_VERSION/registry-$ARCH.bin</filename> or the
67 * file listed in the GST_REGISTRY env var. One reason to change the registry
68 * location is for testing.
70 * For each plugin that is found in the plugin search path, there could be 3
71 * possibilities for cached information:
74 * <para>the cache may not contain information about a given file.</para>
77 * <para>the cache may have stale information.</para>
80 * <para>the cache may have current information.</para>
84 * In the first two cases, the plugin is loaded and the cache updated. In
85 * addition to these cases, the cache may have entries for plugins that are not
86 * relevant to the current process. These are marked as not available to the
87 * current process. If the cache is updated for whatever reason, it is marked
90 * A dirty cache is written out at the end of initialization. Each entry is
91 * checked to make sure the information is minimally valid. If not, the entry is
94 * <emphasis role="bold">Implementation notes:</emphasis>
96 * The "cache" and "registry" are different concepts and can represent
97 * different sets of plugins. For various reasons, at init time, the cache is
98 * stored in the default registry, and plugins not relevant to the current
99 * process are marked with the %GST_PLUGIN_FLAG_CACHED bit. These plugins are
100 * removed at the end of initialization.
102 * Last reviewed on 2012-03-29 (0.11.3)
108 #include "gstconfig.h"
109 #include "gst_private.h"
111 #include <sys/types.h>
112 #include <sys/stat.h>
121 #include <glib/gstdio.h>
124 #include "gsterror.h"
125 #include "gstregistry.h"
127 #include "gstpluginloader.h"
129 #include "gst-i18n-lib.h"
132 #include "glib-compat-private.h"
136 extern HMODULE _priv_gst_dll_handle;
139 #define GST_CAT_DEFAULT GST_CAT_REGISTRY
141 struct _GstRegistryPrivate
152 /* hash to speedup _lookup_feature_locked() */
153 GHashTable *feature_hash;
154 /* hash to speedup _lookup */
155 GHashTable *basename_hash;
157 /* updated whenever the feature list changes */
159 /* speedup for searching features */
160 GList *element_factory_list;
162 GList *typefind_factory_list;
166 /* the one instance of the default registry and the mutex protecting the
168 static GMutex _gst_registry_mutex;
169 static GstRegistry *_gst_registry_default = NULL;
172 #define DEFAULT_FORK TRUE
174 /* control the behaviour of registry rebuild */
175 static gboolean _gst_enable_registry_fork = DEFAULT_FORK;
176 /* List of plugins that need preloading/reloading after scanning registry */
177 extern GSList *_priv_gst_preload_plugins;
179 #ifndef GST_DISABLE_REGISTRY
180 /*set to TRUE when registry needn't to be updated */
181 gboolean _priv_gst_disable_registry_update = FALSE;
182 extern GList *_priv_gst_plugin_paths;
184 /* Set to TRUE when the registry cache should be disabled */
185 gboolean _gst_disable_registry_cache = FALSE;
187 static gboolean __registry_reuse_plugin_scanner = TRUE;
190 /* Element signals and args */
198 static void gst_registry_finalize (GObject * object);
200 static guint gst_registry_signals[LAST_SIGNAL] = { 0 };
202 static GstPluginFeature *gst_registry_lookup_feature_locked (GstRegistry *
203 registry, const char *name);
204 static GstPlugin *gst_registry_lookup_bn_locked (GstRegistry * registry,
205 const char *basename);
207 #define gst_registry_parent_class parent_class
208 G_DEFINE_TYPE (GstRegistry, gst_registry, GST_TYPE_OBJECT);
211 gst_registry_class_init (GstRegistryClass * klass)
213 GObjectClass *gobject_class;
215 gobject_class = (GObjectClass *) klass;
217 g_type_class_add_private (klass, sizeof (GstRegistryPrivate));
220 * GstRegistry::plugin-added:
221 * @registry: the registry that emitted the signal
222 * @plugin: the plugin that has been added
224 * Signals that a plugin has been added to the registry (possibly
225 * replacing a previously-added one by the same name)
227 gst_registry_signals[PLUGIN_ADDED] =
228 g_signal_new ("plugin-added", G_TYPE_FROM_CLASS (klass),
229 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
230 G_TYPE_NONE, 1, GST_TYPE_PLUGIN);
233 * GstRegistry::feature-added:
234 * @registry: the registry that emitted the signal
235 * @feature: the feature that has been added
237 * Signals that a feature has been added to the registry (possibly
238 * replacing a previously-added one by the same name)
240 gst_registry_signals[FEATURE_ADDED] =
241 g_signal_new ("feature-added", G_TYPE_FROM_CLASS (klass),
242 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
243 G_TYPE_NONE, 1, GST_TYPE_PLUGIN_FEATURE);
245 gobject_class->finalize = gst_registry_finalize;
249 gst_registry_init (GstRegistry * registry)
252 G_TYPE_INSTANCE_GET_PRIVATE (registry, GST_TYPE_REGISTRY,
254 registry->priv->feature_hash = g_hash_table_new (g_str_hash, g_str_equal);
255 registry->priv->basename_hash = g_hash_table_new (g_str_hash, g_str_equal);
259 gst_registry_finalize (GObject * object)
261 GstRegistry *registry = GST_REGISTRY (object);
265 plugins = registry->priv->plugins;
266 registry->priv->plugins = NULL;
268 GST_DEBUG_OBJECT (registry, "registry finalize");
271 GstPlugin *plugin = p->data;
274 GST_LOG_OBJECT (registry, "removing plugin %s",
275 gst_plugin_get_name (plugin));
276 gst_object_unref (plugin);
280 g_list_free (plugins);
282 features = registry->priv->features;
283 registry->priv->features = NULL;
287 GstPluginFeature *feature = f->data;
290 GST_LOG_OBJECT (registry, "removing feature %p (%s)", feature,
291 GST_OBJECT_NAME (feature));
292 gst_object_unparent (GST_OBJECT_CAST (feature));
296 g_list_free (features);
298 g_hash_table_destroy (registry->priv->feature_hash);
299 registry->priv->feature_hash = NULL;
300 g_hash_table_destroy (registry->priv->basename_hash);
301 registry->priv->basename_hash = NULL;
303 if (registry->priv->element_factory_list) {
304 GST_DEBUG_OBJECT (registry, "Cleaning up cached element factory list");
305 gst_plugin_feature_list_free (registry->priv->element_factory_list);
308 if (registry->priv->typefind_factory_list) {
309 GST_DEBUG_OBJECT (registry, "Cleaning up cached typefind factory list");
310 gst_plugin_feature_list_free (registry->priv->typefind_factory_list);
313 G_OBJECT_CLASS (parent_class)->finalize (object);
319 * Retrieves the singleton plugin registry. The caller does not own a
320 * reference on the registry, as it is alive as long as GStreamer is
323 * Returns: (transfer none): the #GstRegistry.
326 gst_registry_get (void)
328 GstRegistry *registry;
330 g_mutex_lock (&_gst_registry_mutex);
331 if (G_UNLIKELY (!_gst_registry_default)) {
332 _gst_registry_default = g_object_newv (GST_TYPE_REGISTRY, 0, NULL);
333 gst_object_ref_sink (GST_OBJECT_CAST (_gst_registry_default));
335 registry = _gst_registry_default;
336 g_mutex_unlock (&_gst_registry_mutex);
343 * gst_registry_add_path:
344 * @registry: the registry to add the path to
345 * @path: the path to add to the registry
347 * Add the given path to the registry. The syntax of the
348 * path is specific to the registry. If the path has already been
352 gst_registry_add_path (GstRegistry * registry, const gchar * path)
354 g_return_if_fail (GST_IS_REGISTRY (registry));
355 g_return_if_fail (path != NULL);
357 if (strlen (path) == 0)
360 GST_OBJECT_LOCK (registry);
361 if (g_list_find_custom (registry->priv->paths, path, (GCompareFunc) strcmp))
364 GST_INFO ("Adding plugin path: \"%s\"", path);
365 registry->priv->paths =
366 g_list_append (registry->priv->paths, g_strdup (path));
367 GST_OBJECT_UNLOCK (registry);
373 GST_INFO ("Ignoring empty plugin path");
378 g_warning ("path %s already added to registry", path);
379 GST_OBJECT_UNLOCK (registry);
385 * gst_registry_get_path_list:
386 * @registry: the registry to get the pathlist of
388 * Get the list of paths for the given registry.
390 * Returns: (transfer container) (element-type char*): A #GList of paths as
391 * strings. g_list_free after use.
396 gst_registry_get_path_list (GstRegistry * registry)
400 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
402 GST_OBJECT_LOCK (registry);
403 /* We don't need to copy the strings, because they won't be deleted
404 * as long as the GstRegistry is around */
405 list = g_list_copy (registry->priv->paths);
406 GST_OBJECT_UNLOCK (registry);
413 * gst_registry_add_plugin:
414 * @registry: the registry to add the plugin to
415 * @plugin: (transfer full): the plugin to add
417 * Add the plugin to the registry. The plugin-added signal will be emitted.
418 * This function will sink @plugin.
420 * Returns: TRUE on success.
425 gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin)
427 GstPlugin *existing_plugin;
429 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
430 g_return_val_if_fail (GST_IS_PLUGIN (plugin), FALSE);
432 GST_OBJECT_LOCK (registry);
433 if (G_LIKELY (plugin->basename)) {
434 /* we have a basename, see if we find the plugin */
436 gst_registry_lookup_bn_locked (registry, plugin->basename);
437 if (existing_plugin) {
438 GST_DEBUG_OBJECT (registry,
439 "Replacing existing plugin \"%s\" %p with new plugin %p for filename \"%s\"",
440 GST_STR_NULL (existing_plugin->filename), existing_plugin, plugin,
441 GST_STR_NULL (plugin->filename));
442 /* If the new plugin is blacklisted and the existing one isn't cached, do not
443 * accept if it's from a different location than the existing one */
444 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED) &&
445 strcmp (plugin->filename, existing_plugin->filename)) {
446 GST_WARNING_OBJECT (registry,
447 "Not replacing plugin because new one (%s) is blacklisted but for a different location than existing one (%s)",
448 plugin->filename, existing_plugin->filename);
449 gst_object_unref (plugin);
450 GST_OBJECT_UNLOCK (registry);
453 registry->priv->plugins =
454 g_list_remove (registry->priv->plugins, existing_plugin);
455 if (G_LIKELY (existing_plugin->basename))
456 g_hash_table_remove (registry->priv->basename_hash,
457 existing_plugin->basename);
458 gst_object_unref (existing_plugin);
462 GST_DEBUG_OBJECT (registry, "adding plugin %p for filename \"%s\"",
463 plugin, GST_STR_NULL (plugin->filename));
465 registry->priv->plugins = g_list_prepend (registry->priv->plugins, plugin);
466 if (G_LIKELY (plugin->basename))
467 g_hash_table_replace (registry->priv->basename_hash, plugin->basename,
470 gst_object_ref_sink (plugin);
471 GST_OBJECT_UNLOCK (registry);
473 GST_LOG_OBJECT (registry, "emitting plugin-added for filename \"%s\"",
474 GST_STR_NULL (plugin->filename));
475 g_signal_emit (registry, gst_registry_signals[PLUGIN_ADDED], 0, plugin);
481 gst_registry_remove_features_for_plugin_unlocked (GstRegistry * registry,
486 g_return_if_fail (GST_IS_REGISTRY (registry));
487 g_return_if_fail (GST_IS_PLUGIN (plugin));
489 /* Remove all features for this plugin */
490 f = registry->priv->features;
492 GList *next = g_list_next (f);
493 GstPluginFeature *feature = f->data;
495 if (G_UNLIKELY (feature && feature->plugin == plugin)) {
496 GST_DEBUG_OBJECT (registry, "removing feature %p (%s) for plugin %p (%s)",
497 feature, gst_plugin_feature_get_name (feature), plugin,
500 registry->priv->features =
501 g_list_delete_link (registry->priv->features, f);
502 g_hash_table_remove (registry->priv->feature_hash,
503 GST_OBJECT_NAME (feature));
504 gst_object_unparent (GST_OBJECT_CAST (feature));
508 registry->priv->cookie++;
512 * gst_registry_remove_plugin:
513 * @registry: the registry to remove the plugin from
514 * @plugin: (transfer none): the plugin to remove
516 * Remove the plugin from the registry.
521 gst_registry_remove_plugin (GstRegistry * registry, GstPlugin * plugin)
523 g_return_if_fail (GST_IS_REGISTRY (registry));
524 g_return_if_fail (GST_IS_PLUGIN (plugin));
526 GST_DEBUG_OBJECT (registry, "removing plugin %p (%s)",
527 plugin, gst_plugin_get_name (plugin));
529 GST_OBJECT_LOCK (registry);
530 registry->priv->plugins = g_list_remove (registry->priv->plugins, plugin);
531 if (G_LIKELY (plugin->basename))
532 g_hash_table_remove (registry->priv->basename_hash, plugin->basename);
533 gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
534 GST_OBJECT_UNLOCK (registry);
535 gst_object_unref (plugin);
539 * gst_registry_add_feature:
540 * @registry: the registry to add the plugin to
541 * @feature: (transfer full): the feature to add
543 * Add the feature to the registry. The feature-added signal will be emitted.
544 * This function sinks @feature.
546 * Returns: TRUE on success.
551 gst_registry_add_feature (GstRegistry * registry, GstPluginFeature * feature)
553 GstPluginFeature *existing_feature;
555 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
556 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
557 g_return_val_if_fail (GST_OBJECT_NAME (feature) != NULL, FALSE);
558 g_return_val_if_fail (feature->plugin_name != NULL, FALSE);
560 GST_OBJECT_LOCK (registry);
561 existing_feature = gst_registry_lookup_feature_locked (registry,
562 GST_OBJECT_NAME (feature));
563 if (G_UNLIKELY (existing_feature)) {
564 GST_DEBUG_OBJECT (registry, "replacing existing feature %p (%s)",
565 existing_feature, GST_OBJECT_NAME (feature));
566 /* Remove the existing feature from the list now, before we insert the new
567 * one, but don't unref yet because the hash is still storing a reference to
569 registry->priv->features =
570 g_list_remove (registry->priv->features, existing_feature);
573 GST_DEBUG_OBJECT (registry, "adding feature %p (%s)", feature,
574 GST_OBJECT_NAME (feature));
576 registry->priv->features = g_list_prepend (registry->priv->features, feature);
577 g_hash_table_replace (registry->priv->feature_hash, GST_OBJECT_NAME (feature),
580 if (G_UNLIKELY (existing_feature)) {
581 /* We unref now. No need to remove the feature name from the hash table, it
582 * got replaced by the new feature */
583 gst_object_unparent (GST_OBJECT_CAST (existing_feature));
586 gst_object_set_parent (GST_OBJECT_CAST (feature), GST_OBJECT_CAST (registry));
588 registry->priv->cookie++;
589 GST_OBJECT_UNLOCK (registry);
591 GST_LOG_OBJECT (registry, "emitting feature-added for %s",
592 GST_OBJECT_NAME (feature));
593 g_signal_emit (registry, gst_registry_signals[FEATURE_ADDED], 0, feature);
599 * gst_registry_remove_feature:
600 * @registry: the registry to remove the feature from
601 * @feature: (transfer none): the feature to remove
603 * Remove the feature from the registry.
608 gst_registry_remove_feature (GstRegistry * registry, GstPluginFeature * feature)
610 g_return_if_fail (GST_IS_REGISTRY (registry));
611 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
613 GST_DEBUG_OBJECT (registry, "removing feature %p (%s)",
614 feature, gst_plugin_feature_get_name (feature));
616 GST_OBJECT_LOCK (registry);
617 registry->priv->features = g_list_remove (registry->priv->features, feature);
618 g_hash_table_remove (registry->priv->feature_hash, GST_OBJECT_NAME (feature));
619 registry->priv->cookie++;
620 GST_OBJECT_UNLOCK (registry);
622 gst_object_unparent ((GstObject *) feature);
626 * gst_registry_plugin_filter:
627 * @registry: registry to query
628 * @filter: (scope call): the filter to use
629 * @first: only return first match
630 * @user_data: (closure): user data passed to the filter function
632 * Runs a filter against all plugins in the registry and returns a #GList with
633 * the results. If the first flag is set, only the first match is
634 * returned (as a list with a single object).
635 * Every plugin is reffed; use gst_plugin_list_free() after use, which
638 * Returns: (transfer full) (element-type Gst.Plugin): a #GList of #GstPlugin.
639 * Use gst_plugin_list_free() after usage.
644 gst_registry_plugin_filter (GstRegistry * registry,
645 GstPluginFilter filter, gboolean first, gpointer user_data)
649 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
651 GST_OBJECT_LOCK (registry);
655 for (walk = registry->priv->plugins; walk != NULL; walk = walk->next) {
656 GstPlugin *plugin = walk->data;
658 if (filter == NULL || filter (plugin, user_data)) {
659 list = g_list_prepend (list, gst_object_ref (plugin));
666 GST_OBJECT_UNLOCK (registry);
678 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
679 GstTypeNameData * data)
681 g_assert (GST_IS_PLUGIN_FEATURE (feature));
683 return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
684 (data->name == NULL || !strcmp (data->name, GST_OBJECT_NAME (feature))));
687 /* returns TRUE if the list was changed
689 * Must be called with the object lock taken */
691 gst_registry_get_feature_list_or_create (GstRegistry * registry,
692 GList ** previous, guint32 * cookie, GType type)
694 gboolean res = FALSE;
695 GstRegistryPrivate *priv = registry->priv;
697 if (G_UNLIKELY (!*previous || priv->cookie != *cookie)) {
698 GstTypeNameData data;
702 gst_plugin_feature_list_free (*previous);
709 for (walk = registry->priv->features; walk != NULL; walk = walk->next) {
710 GstPluginFeature *feature = walk->data;
712 if (gst_plugin_feature_type_name_filter (feature, &data)) {
713 *previous = g_list_prepend (*previous, gst_object_ref (feature));
717 *cookie = priv->cookie;
725 type_find_factory_rank_cmp (const GstPluginFeature * fac1,
726 const GstPluginFeature * fac2)
728 if (G_LIKELY (fac1->rank != fac2->rank))
729 return fac2->rank - fac1->rank;
731 /* to make the order in which things happen more deterministic,
732 * sort by name when the ranks are the same. */
733 return strcmp (GST_OBJECT_NAME (fac1), GST_OBJECT_NAME (fac2));
737 gst_registry_get_element_factory_list (GstRegistry * registry)
741 GST_OBJECT_LOCK (registry);
743 gst_registry_get_feature_list_or_create (registry,
744 ®istry->priv->element_factory_list, ®istry->priv->efl_cookie,
745 GST_TYPE_ELEMENT_FACTORY);
747 /* Return reffed copy */
748 list = gst_plugin_feature_list_copy (registry->priv->element_factory_list);
750 GST_OBJECT_UNLOCK (registry);
756 gst_registry_get_typefind_factory_list (GstRegistry * registry)
760 GST_OBJECT_LOCK (registry);
762 if (G_UNLIKELY (gst_registry_get_feature_list_or_create (registry,
763 ®istry->priv->typefind_factory_list,
764 ®istry->priv->tfl_cookie, GST_TYPE_TYPE_FIND_FACTORY)))
765 registry->priv->typefind_factory_list =
766 g_list_sort (registry->priv->typefind_factory_list,
767 (GCompareFunc) type_find_factory_rank_cmp);
769 /* Return reffed copy */
770 list = gst_plugin_feature_list_copy (registry->priv->typefind_factory_list);
772 GST_OBJECT_UNLOCK (registry);
778 * gst_registry_feature_filter:
779 * @registry: registry to query
780 * @filter: (scope call): the filter to use
781 * @first: only return first match
782 * @user_data: (closure): user data passed to the filter function
784 * Runs a filter against all features of the plugins in the registry
785 * and returns a GList with the results.
786 * If the first flag is set, only the first match is
787 * returned (as a list with a single object).
789 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
790 * #GstPluginFeature. Use gst_plugin_feature_list_free() after usage.
795 gst_registry_feature_filter (GstRegistry * registry,
796 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
800 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
802 GST_OBJECT_LOCK (registry);
806 for (walk = registry->priv->features; walk != NULL; walk = walk->next) {
807 GstPluginFeature *feature = walk->data;
809 if (filter == NULL || filter (feature, user_data)) {
810 list = g_list_prepend (list, gst_object_ref (feature));
817 GST_OBJECT_UNLOCK (registry);
823 gst_registry_plugin_name_filter (GstPlugin * plugin, const gchar * name)
825 return (plugin->desc.name && !strcmp (plugin->desc.name, name));
829 * gst_registry_find_plugin:
830 * @registry: the registry to search
831 * @name: the plugin name to find
833 * Find the plugin with the given name in the registry.
834 * The plugin will be reffed; caller is responsible for unreffing.
836 * Returns: (transfer full): the plugin with the given name or NULL if the
837 * plugin was not found. gst_object_unref() after usage.
842 gst_registry_find_plugin (GstRegistry * registry, const gchar * name)
845 GstPlugin *result = NULL;
847 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
848 g_return_val_if_fail (name != NULL, NULL);
850 walk = gst_registry_plugin_filter (registry,
851 (GstPluginFilter) gst_registry_plugin_name_filter, TRUE, (gpointer) name);
853 result = GST_PLUGIN_CAST (walk->data);
855 gst_object_ref (result);
856 gst_plugin_list_free (walk);
863 * gst_registry_find_feature:
864 * @registry: the registry to search
865 * @name: the pluginfeature name to find
866 * @type: the pluginfeature type to find
868 * Find the pluginfeature with the given name and type in the registry.
870 * Returns: (transfer full): the pluginfeature with the given name and type
871 * or NULL if the plugin was not found. gst_object_unref() after usage.
876 gst_registry_find_feature (GstRegistry * registry, const gchar * name,
879 GstPluginFeature *feature = NULL;
881 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
882 g_return_val_if_fail (name != NULL, NULL);
883 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_PLUGIN_FEATURE), NULL);
885 feature = gst_registry_lookup_feature (registry, name);
886 if (feature && !g_type_is_a (G_TYPE_FROM_INSTANCE (feature), type)) {
887 gst_object_unref (feature);
895 * gst_registry_get_feature_list:
896 * @registry: a #GstRegistry
899 * Retrieves a #GList of #GstPluginFeature of @type.
901 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
902 * #GstPluginFeature of @type. Use gst_plugin_feature_list_free() after use
907 gst_registry_get_feature_list (GstRegistry * registry, GType type)
909 GstTypeNameData data;
911 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
912 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_PLUGIN_FEATURE), NULL);
915 if (type == GST_TYPE_ELEMENT_FACTORY)
916 return gst_registry_get_element_factory_list (registry);
917 else if (type == GST_TYPE_TYPE_FIND_FACTORY)
918 return gst_registry_get_typefind_factory_list (registry);
923 return gst_registry_feature_filter (registry,
924 (GstPluginFeatureFilter) gst_plugin_feature_type_name_filter,
929 * gst_registry_get_plugin_list:
930 * @registry: the registry to search
932 * Get a copy of all plugins registered in the given registry. The refcount
933 * of each element in the list in incremented.
935 * Returns: (transfer full) (element-type Gst.Plugin): a #GList of #GstPlugin.
936 * Use gst_plugin_list_free() after usage.
941 gst_registry_get_plugin_list (GstRegistry * registry)
946 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
948 GST_OBJECT_LOCK (registry);
949 list = g_list_copy (registry->priv->plugins);
950 for (g = list; g; g = g->next) {
951 gst_object_ref (GST_PLUGIN_CAST (g->data));
953 GST_OBJECT_UNLOCK (registry);
958 static GstPluginFeature *
959 gst_registry_lookup_feature_locked (GstRegistry * registry, const char *name)
961 return g_hash_table_lookup (registry->priv->feature_hash, name);
965 * gst_registry_lookup_feature:
966 * @registry: a #GstRegistry
967 * @name: a #GstPluginFeature name
969 * Find a #GstPluginFeature with @name in @registry.
971 * Returns: (transfer full): a #GstPluginFeature with its refcount incremented,
972 * use gst_object_unref() after usage.
977 gst_registry_lookup_feature (GstRegistry * registry, const char *name)
979 GstPluginFeature *feature;
981 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
982 g_return_val_if_fail (name != NULL, NULL);
984 GST_OBJECT_LOCK (registry);
985 feature = gst_registry_lookup_feature_locked (registry, name);
987 gst_object_ref (feature);
988 GST_OBJECT_UNLOCK (registry);
994 gst_registry_lookup_bn_locked (GstRegistry * registry, const char *basename)
996 return g_hash_table_lookup (registry->priv->basename_hash, basename);
1000 gst_registry_lookup_bn (GstRegistry * registry, const char *basename)
1004 GST_OBJECT_LOCK (registry);
1005 plugin = gst_registry_lookup_bn_locked (registry, basename);
1007 gst_object_ref (plugin);
1008 GST_OBJECT_UNLOCK (registry);
1014 * gst_registry_lookup:
1015 * @registry: the registry to look up in
1016 * @filename: the name of the file to look up
1018 * Look up a plugin in the given registry with the given filename.
1019 * If found, plugin is reffed.
1021 * Returns: (transfer full): the #GstPlugin if found, or NULL if not.
1022 * gst_object_unref() after usage.
1025 gst_registry_lookup (GstRegistry * registry, const char *filename)
1030 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1031 g_return_val_if_fail (filename != NULL, NULL);
1033 basename = g_path_get_basename (filename);
1034 if (G_UNLIKELY (basename == NULL))
1037 plugin = gst_registry_lookup_bn (registry, basename);
1046 REGISTRY_SCAN_HELPER_NOT_STARTED = 0,
1047 REGISTRY_SCAN_HELPER_DISABLED,
1048 REGISTRY_SCAN_HELPER_RUNNING
1049 } GstRegistryScanHelperState;
1053 GstRegistry *registry;
1054 GstRegistryScanHelperState helper_state;
1055 GstPluginLoader *helper;
1057 } GstRegistryScanContext;
1060 init_scan_context (GstRegistryScanContext * context, GstRegistry * registry)
1064 context->registry = registry;
1066 /* see if forking is enabled and set up the scan helper state accordingly */
1067 do_fork = _gst_enable_registry_fork;
1069 const gchar *fork_env;
1071 /* forking enabled, see if it is disabled with an env var */
1072 if ((fork_env = g_getenv ("GST_REGISTRY_FORK"))) {
1073 /* fork enabled for any value different from "no" */
1074 do_fork = strcmp (fork_env, "no") != 0;
1079 context->helper_state = REGISTRY_SCAN_HELPER_NOT_STARTED;
1081 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1083 context->helper = NULL;
1084 context->changed = FALSE;
1088 clear_scan_context (GstRegistryScanContext * context)
1090 if (context->helper) {
1091 context->changed |= _priv_gst_plugin_loader_funcs.destroy (context->helper);
1092 context->helper = NULL;
1097 gst_registry_scan_plugin_file (GstRegistryScanContext * context,
1098 const gchar * filename, off_t file_size, time_t file_mtime)
1100 gboolean changed = FALSE;
1101 GstPlugin *newplugin = NULL;
1104 /* Disable external plugin loader on Windows until it is ported properly. */
1105 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1109 /* Have a plugin to load - see if the scan-helper needs starting */
1110 if (context->helper_state == REGISTRY_SCAN_HELPER_NOT_STARTED) {
1111 GST_DEBUG ("Starting plugin scanner for file %s", filename);
1112 context->helper = _priv_gst_plugin_loader_funcs.create (context->registry);
1113 if (context->helper != NULL)
1114 context->helper_state = REGISTRY_SCAN_HELPER_RUNNING;
1116 GST_WARNING ("Failed starting plugin scanner. Scanning in-process");
1117 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1121 if (context->helper_state == REGISTRY_SCAN_HELPER_RUNNING) {
1122 GST_DEBUG ("Using scan-helper to load plugin %s", filename);
1123 if (!_priv_gst_plugin_loader_funcs.load (context->helper,
1124 filename, file_size, file_mtime)) {
1125 g_warning ("External plugin loader failed. This most likely means that "
1126 "the plugin loader helper binary was not found or could not be run. "
1127 "You might need to set the GST_PLUGIN_SCANNER environment variable "
1128 "if your setup is unusual. This should normally not be required "
1130 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1134 /* Check if the helper is disabled (or just got disabled above) */
1135 if (context->helper_state == REGISTRY_SCAN_HELPER_DISABLED) {
1136 /* Load plugin the old fashioned way... */
1138 /* We don't use a GError here because a failure to load some shared
1139 * objects as plugins is normal (particularly in the uninstalled case)
1141 newplugin = gst_plugin_load_file (filename, NULL);
1145 GST_DEBUG_OBJECT (context->registry, "marking new plugin %p as registered",
1147 newplugin->registered = TRUE;
1148 gst_object_unref (newplugin);
1151 #ifndef GST_DISABLE_REGISTRY
1152 if (!__registry_reuse_plugin_scanner) {
1153 clear_scan_context (context);
1154 context->helper_state = REGISTRY_SCAN_HELPER_NOT_STARTED;
1162 is_blacklisted_hidden_directory (const gchar * dirent)
1164 if (G_LIKELY (dirent[0] != '.'))
1167 /* skip the .debug directory, these contain elf files that are not
1168 * useful or worse, can crash dlopen () */
1169 if (strcmp (dirent, ".debug") == 0)
1172 /* can also skip .git and .deps dirs, those won't contain useful files.
1173 * This speeds up scanning a bit in uninstalled setups. */
1174 if (strcmp (dirent, ".git") == 0 || strcmp (dirent, ".deps") == 0)
1181 gst_registry_scan_path_level (GstRegistryScanContext * context,
1182 const gchar * path, int level)
1185 const gchar *dirent;
1188 gboolean changed = FALSE;
1190 dir = g_dir_open (path, 0, NULL);
1194 while ((dirent = g_dir_read_name (dir))) {
1195 GStatBuf file_status;
1197 filename = g_build_filename (path, dirent, NULL);
1198 if (g_stat (filename, &file_status) < 0) {
1199 /* Plugin will be removed from cache after the scan completes if it
1200 * is still marked 'cached' */
1205 if (file_status.st_mode & S_IFDIR) {
1206 if (G_UNLIKELY (is_blacklisted_hidden_directory (dirent))) {
1207 GST_TRACE_OBJECT (context->registry, "ignoring %s directory", dirent);
1211 /* FIXME 0.11: Don't recurse into directories, this behaviour
1212 * is inconsistent with other PATH environment variables
1215 GST_LOG_OBJECT (context->registry, "recursing into directory %s",
1217 changed |= gst_registry_scan_path_level (context, filename, level - 1);
1219 GST_LOG_OBJECT (context->registry, "not recursing into directory %s, "
1220 "recursion level too deep", filename);
1225 if (!(file_status.st_mode & S_IFREG)) {
1226 GST_TRACE_OBJECT (context->registry, "%s is not a regular file, ignoring",
1231 if (!g_str_has_suffix (dirent, G_MODULE_SUFFIX)
1232 #ifdef GST_EXTRA_MODULE_SUFFIX
1233 && !g_str_has_suffix (dirent, GST_EXTRA_MODULE_SUFFIX)
1236 GST_TRACE_OBJECT (context->registry,
1237 "extension is not recognized as module file, ignoring file %s",
1243 GST_LOG_OBJECT (context->registry, "file %s looks like a possible module",
1246 /* try to avoid unnecessary plugin-move pain */
1247 if (g_str_has_prefix (dirent, "libgstvalve") ||
1248 g_str_has_prefix (dirent, "libgstselector")) {
1249 GST_WARNING_OBJECT (context->registry, "ignoring old plugin %s which "
1250 "has been merged into the corelements plugin", filename);
1251 /* Plugin will be removed from cache after the scan completes if it
1252 * is still marked 'cached' */
1257 /* plug-ins are considered unique by basename; if the given name
1258 * was already seen by the registry, we ignore it */
1259 plugin = gst_registry_lookup_bn (context->registry, dirent);
1261 gboolean env_vars_changed, deps_changed = FALSE;
1263 if (plugin->registered) {
1264 GST_DEBUG_OBJECT (context->registry,
1265 "plugin already registered from path \"%s\"",
1266 GST_STR_NULL (plugin->filename));
1268 gst_object_unref (plugin);
1272 env_vars_changed = _priv_plugin_deps_env_vars_changed (plugin);
1274 /* If a file with a certain basename is seen on a different path,
1275 * update the plugin to ensure the registry cache will reflect up
1276 * to date information */
1278 if (plugin->file_mtime == file_status.st_mtime &&
1279 plugin->file_size == file_status.st_size && !env_vars_changed &&
1280 !(deps_changed = _priv_plugin_deps_files_changed (plugin)) &&
1281 !strcmp (plugin->filename, filename)) {
1282 GST_LOG_OBJECT (context->registry, "file %s cached", filename);
1283 GST_OBJECT_FLAG_UNSET (plugin, GST_PLUGIN_FLAG_CACHED);
1284 GST_LOG_OBJECT (context->registry,
1285 "marking plugin %p as registered as %s", plugin, filename);
1286 plugin->registered = TRUE;
1288 GST_INFO_OBJECT (context->registry, "cached info for %s is stale",
1290 GST_DEBUG_OBJECT (context->registry, "mtime %" G_GINT64_FORMAT " != %"
1291 G_GINT64_FORMAT " or size %" G_GINT64_FORMAT " != %"
1292 G_GINT64_FORMAT " or external dependency env_vars changed: %d or"
1293 " external dependencies changed: %d or old path %s != new path %s",
1294 (gint64) plugin->file_mtime, (gint64) file_status.st_mtime,
1295 (gint64) plugin->file_size, (gint64) file_status.st_size,
1296 env_vars_changed, deps_changed, plugin->filename, filename);
1297 gst_registry_remove_plugin (context->registry, plugin);
1298 changed |= gst_registry_scan_plugin_file (context, filename,
1299 file_status.st_size, file_status.st_mtime);
1301 gst_object_unref (plugin);
1304 GST_DEBUG_OBJECT (context->registry, "file %s not yet in registry",
1306 changed |= gst_registry_scan_plugin_file (context, filename,
1307 file_status.st_size, file_status.st_mtime);
1319 gst_registry_scan_path_internal (GstRegistryScanContext * context,
1324 GST_DEBUG_OBJECT (context->registry, "scanning path %s", path);
1325 changed = gst_registry_scan_path_level (context, path, 10);
1327 GST_DEBUG_OBJECT (context->registry, "registry changed in path %s: %d", path,
1333 * gst_registry_scan_path:
1334 * @registry: the registry to add found plugins to
1335 * @path: the path to scan
1337 * Scan the given path for plugins to add to the registry. The syntax of the
1338 * path is specific to the registry.
1340 * Returns: %TRUE if registry changed
1343 gst_registry_scan_path (GstRegistry * registry, const gchar * path)
1345 GstRegistryScanContext context;
1348 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
1349 g_return_val_if_fail (path != NULL, FALSE);
1351 init_scan_context (&context, registry);
1353 result = gst_registry_scan_path_internal (&context, path);
1355 clear_scan_context (&context);
1356 result |= context.changed;
1362 _gst_plugin_feature_filter_plugin_name (GstPluginFeature * feature,
1365 return (strcmp (feature->plugin_name, (gchar *) user_data) == 0);
1369 * gst_registry_get_feature_list_by_plugin:
1370 * @registry: a #GstRegistry.
1371 * @name: a plugin name.
1373 * Retrieves a #GList of features of the plugin with name @name.
1375 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
1376 * #GstPluginFeature. Use gst_plugin_feature_list_free() after usage.
1379 gst_registry_get_feature_list_by_plugin (GstRegistry * registry,
1382 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1383 g_return_val_if_fail (name != NULL, NULL);
1385 return gst_registry_feature_filter (registry,
1386 _gst_plugin_feature_filter_plugin_name, FALSE, (gpointer) name);
1389 /* Unref and delete the default registry */
1391 _priv_gst_registry_cleanup (void)
1393 GstRegistry *registry;
1395 g_mutex_lock (&_gst_registry_mutex);
1396 if ((registry = _gst_registry_default) != NULL) {
1397 _gst_registry_default = NULL;
1399 g_mutex_unlock (&_gst_registry_mutex);
1401 /* unref outside of the lock because we can. */
1403 gst_object_unref (registry);
1407 * gst_registry_check_feature_version:
1408 * @registry: a #GstRegistry
1409 * @feature_name: the name of the feature (e.g. "oggdemux")
1410 * @min_major: the minimum major version number
1411 * @min_minor: the minimum minor version number
1412 * @min_micro: the minimum micro version number
1414 * Checks whether a plugin feature by the given name exists in
1415 * @registry and whether its version is at least the
1418 * Returns: #TRUE if the feature could be found and the version is
1419 * the same as the required version or newer, and #FALSE otherwise.
1422 gst_registry_check_feature_version (GstRegistry * registry,
1423 const gchar * feature_name, guint min_major, guint min_minor,
1426 GstPluginFeature *feature;
1427 gboolean ret = FALSE;
1429 g_return_val_if_fail (feature_name != NULL, FALSE);
1431 GST_DEBUG ("Looking up plugin feature '%s'", feature_name);
1433 feature = gst_registry_lookup_feature (registry, feature_name);
1435 ret = gst_plugin_feature_check_version (feature, min_major, min_minor,
1437 gst_object_unref (feature);
1439 GST_DEBUG ("Could not find plugin feature '%s'", feature_name);
1446 load_plugin_func (gpointer data, gpointer user_data)
1449 const gchar *filename;
1452 filename = (const gchar *) data;
1453 GST_DEBUG ("Pre-loading plugin %s", filename);
1455 plugin = gst_plugin_load_file (filename, &err);
1458 GST_INFO ("Loaded plugin: \"%s\"", filename);
1460 gst_registry_add_plugin (gst_registry_get (), plugin);
1463 /* Report error to user, and free error */
1464 GST_ERROR ("Failed to load plugin: %s", err->message);
1467 GST_WARNING ("Failed to load plugin: \"%s\"", filename);
1472 #ifndef GST_DISABLE_REGISTRY
1473 /* Unref all plugins marked 'cached', to clear old plugins that no
1474 * longer exist. Returns TRUE if any plugins were removed */
1476 gst_registry_remove_cache_plugins (GstRegistry * registry)
1481 gboolean changed = FALSE;
1483 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
1485 GST_OBJECT_LOCK (registry);
1487 GST_DEBUG_OBJECT (registry, "removing cached plugins");
1488 g = registry->priv->plugins;
1492 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_CACHED)) {
1493 GST_DEBUG_OBJECT (registry, "removing cached plugin \"%s\"",
1494 GST_STR_NULL (plugin->filename));
1495 registry->priv->plugins = g_list_delete_link (registry->priv->plugins, g);
1496 if (G_LIKELY (plugin->basename))
1497 g_hash_table_remove (registry->priv->basename_hash, plugin->basename);
1498 gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
1499 gst_object_unref (plugin);
1505 GST_OBJECT_UNLOCK (registry);
1512 REGISTRY_SCAN_AND_UPDATE_FAILURE = 0,
1513 REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED,
1514 REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED
1515 } GstRegistryScanAndUpdateResult;
1518 * scan_and_update_registry:
1519 * @default_registry: the #GstRegistry
1520 * @registry_file: registry filename
1521 * @write_changes: write registry if it has changed?
1523 * Scans for registry changes and eventually updates the registry cache.
1525 * Return: %REGISTRY_SCAN_AND_UPDATE_FAILURE if the registry could not scanned
1526 * or updated, %REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED if the
1527 * registry is clean and %REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED if
1528 * it has been updated and the cache needs to be re-read.
1530 static GstRegistryScanAndUpdateResult
1531 scan_and_update_registry (GstRegistry * default_registry,
1532 const gchar * registry_file, gboolean write_changes, GError ** error)
1534 const gchar *plugin_path;
1535 gboolean changed = FALSE;
1537 GstRegistryScanContext context;
1539 GST_INFO ("Validating plugins from registry cache: %s", registry_file);
1541 init_scan_context (&context, default_registry);
1543 /* It sounds tempting to just compare the mtime of directories with the mtime
1544 * of the registry cache, but it does not work. It would not catch updated
1545 * plugins, which might bring more or less features.
1548 /* scan paths specified via --gst-plugin-path */
1549 GST_DEBUG ("scanning paths added via --gst-plugin-path");
1550 for (l = _priv_gst_plugin_paths; l != NULL; l = l->next) {
1551 GST_INFO ("Scanning plugin path: \"%s\"", (gchar *) l->data);
1552 changed |= gst_registry_scan_path_internal (&context, (gchar *) l->data);
1554 /* keep plugin_paths around in case a re-scan is forced later on */
1556 /* GST_PLUGIN_PATH specifies a list of directories to scan for
1557 * additional plugins. These take precedence over the system plugins */
1558 plugin_path = g_getenv ("GST_PLUGIN_PATH_1_0");
1559 if (plugin_path == NULL)
1560 plugin_path = g_getenv ("GST_PLUGIN_PATH");
1565 GST_DEBUG ("GST_PLUGIN_PATH set to %s", plugin_path);
1566 list = g_strsplit (plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
1567 for (i = 0; list[i]; i++) {
1568 changed |= gst_registry_scan_path_internal (&context, list[i]);
1572 GST_DEBUG ("GST_PLUGIN_PATH not set");
1575 /* GST_PLUGIN_SYSTEM_PATH specifies a list of plugins that are always
1576 * loaded by default. If not set, this defaults to the system-installed
1577 * path, and the plugins installed in the user's home directory */
1578 plugin_path = g_getenv ("GST_PLUGIN_SYSTEM_PATH_1_0");
1579 if (plugin_path == NULL)
1580 plugin_path = g_getenv ("GST_PLUGIN_SYSTEM_PATH");
1581 if (plugin_path == NULL) {
1584 GST_DEBUG ("GST_PLUGIN_SYSTEM_PATH not set");
1586 /* plugins in the user's home directory take precedence over
1587 * system-installed ones */
1588 home_plugins = g_build_filename (g_get_user_data_dir (),
1589 "gstreamer-" GST_API_VERSION, "plugins", NULL);
1591 GST_DEBUG ("scanning home plugins %s", home_plugins);
1592 changed |= gst_registry_scan_path_internal (&context, home_plugins);
1593 g_free (home_plugins);
1595 /* add the main (installed) library path */
1596 GST_DEBUG ("scanning main plugins %s", PLUGINDIR);
1597 changed |= gst_registry_scan_path_internal (&context, PLUGINDIR);
1605 g_win32_get_package_installation_directory_of_module
1606 (_priv_gst_dll_handle);
1609 g_build_filename (base_dir, "lib", "gstreamer-" GST_API_VERSION,
1611 GST_DEBUG ("scanning DLL dir %s", dir);
1613 changed |= gst_registry_scan_path_internal (&context, dir);
1623 GST_DEBUG ("GST_PLUGIN_SYSTEM_PATH set to %s", plugin_path);
1624 list = g_strsplit (plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
1625 for (i = 0; list[i]; i++) {
1626 changed |= gst_registry_scan_path_internal (&context, list[i]);
1631 clear_scan_context (&context);
1632 changed |= context.changed;
1634 /* Remove cached plugins so stale info is cleared. */
1635 changed |= gst_registry_remove_cache_plugins (default_registry);
1638 GST_INFO ("Registry cache has not changed");
1639 return REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED;
1642 if (!write_changes) {
1643 GST_INFO ("Registry cache changed, but writing is disabled. Not writing.");
1644 return REGISTRY_SCAN_AND_UPDATE_FAILURE;
1647 GST_INFO ("Registry cache changed. Writing new registry cache");
1648 if (!priv_gst_registry_binary_write_cache (default_registry,
1649 default_registry->priv->plugins, registry_file)) {
1650 g_set_error (error, GST_CORE_ERROR, GST_CORE_ERROR_FAILED,
1651 _("Error writing registry cache to %s: %s"),
1652 registry_file, g_strerror (errno));
1653 return REGISTRY_SCAN_AND_UPDATE_FAILURE;
1656 GST_INFO ("Registry cache written successfully");
1657 return REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED;
1661 ensure_current_registry (GError ** error)
1663 gchar *registry_file;
1664 GstRegistry *default_registry;
1665 gboolean ret = TRUE;
1666 gboolean do_update = TRUE;
1667 gboolean have_cache = TRUE;
1669 default_registry = gst_registry_get ();
1671 registry_file = g_strdup (g_getenv ("GST_REGISTRY_1_0"));
1672 if (registry_file == NULL)
1673 registry_file = g_strdup (g_getenv ("GST_REGISTRY"));
1674 if (registry_file == NULL) {
1675 registry_file = g_build_filename (g_get_user_cache_dir (),
1676 "gstreamer-" GST_API_VERSION, "registry." TARGET_CPU ".bin", NULL);
1679 if (!_gst_disable_registry_cache) {
1680 GST_INFO ("reading registry cache: %s", registry_file);
1681 have_cache = priv_gst_registry_binary_read_cache (default_registry,
1683 /* Only ever read the registry cache once, then disable it for
1684 * subsequent updates during the program lifetime */
1685 _gst_disable_registry_cache = TRUE;
1689 do_update = !_priv_gst_disable_registry_update;
1691 const gchar *update_env;
1693 if ((update_env = g_getenv ("GST_REGISTRY_UPDATE"))) {
1694 /* do update for any value different from "no" */
1695 do_update = (strcmp (update_env, "no") != 0);
1701 const gchar *reuse_env;
1703 if ((reuse_env = g_getenv ("GST_REGISTRY_REUSE_PLUGIN_SCANNER"))) {
1704 /* do reuse for any value different from "no" */
1705 __registry_reuse_plugin_scanner = (strcmp (reuse_env, "no") != 0);
1707 /* now check registry */
1708 GST_DEBUG ("Updating registry cache");
1709 scan_and_update_registry (default_registry, registry_file, TRUE, error);
1711 GST_DEBUG ("Not updating registry cache (disabled)");
1714 g_free (registry_file);
1715 GST_INFO ("registry reading and updating done, result = %d", ret);
1719 #endif /* GST_DISABLE_REGISTRY */
1722 * gst_registry_fork_is_enabled:
1724 * By default GStreamer will perform scanning and rebuilding of the
1725 * registry file using a helper child process.
1727 * Applications might want to disable this behaviour with the
1728 * gst_registry_fork_set_enabled() function, in which case new plugins
1729 * are scanned (and loaded) into the application process.
1731 * Returns: %TRUE if GStreamer will use the child helper process when
1732 * rebuilding the registry.
1735 gst_registry_fork_is_enabled (void)
1737 return _gst_enable_registry_fork;
1741 * gst_registry_fork_set_enabled:
1742 * @enabled: whether rebuilding the registry can use a temporary child helper process.
1744 * Applications might want to disable/enable spawning of a child helper process
1745 * when rebuilding the registry. See gst_registry_fork_is_enabled() for more
1749 gst_registry_fork_set_enabled (gboolean enabled)
1751 _gst_enable_registry_fork = enabled;
1755 * gst_update_registry:
1757 * Forces GStreamer to re-scan its plugin paths and update the default
1760 * Applications will almost never need to call this function, it is only
1761 * useful if the application knows new plugins have been installed (or old
1762 * ones removed) since the start of the application (or, to be precise, the
1763 * first call to gst_init()) and the application wants to make use of any
1764 * newly-installed plugins without restarting the application.
1766 * Applications should assume that the registry update is neither atomic nor
1767 * thread-safe and should therefore not have any dynamic pipelines running
1768 * (including the playbin and decodebin elements) and should also not create
1769 * any elements or access the GStreamer registry while the update is in
1772 * Note that this function may block for a significant amount of time.
1774 * Returns: %TRUE if the registry has been updated successfully (does not
1775 * imply that there were changes), otherwise %FALSE.
1778 gst_update_registry (void)
1782 #ifndef GST_DISABLE_REGISTRY
1785 res = ensure_current_registry (&err);
1787 GST_WARNING ("registry update failed: %s", err->message);
1790 GST_LOG ("registry update succeeded");
1794 GST_WARNING ("registry update failed: %s", "registry disabled");
1796 #endif /* GST_DISABLE_REGISTRY */
1798 if (_priv_gst_preload_plugins) {
1799 GST_DEBUG ("Preloading indicated plugins...");
1800 g_slist_foreach (_priv_gst_preload_plugins, load_plugin_func, NULL);
1807 * gst_registry_get_feature_list_cookie:
1808 * @registry: the registry
1810 * Returns the registry's feature list cookie. This changes
1811 * every time a feature is added or removed from the registry.
1813 * Returns: the feature list cookie.
1816 gst_registry_get_feature_list_cookie (GstRegistry * registry)
1818 g_return_val_if_fail (GST_IS_REGISTRY (registry), 0);
1820 return registry->priv->cookie;