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., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, 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
150 /* hash to speedup _lookup_feature_locked() */
151 GHashTable *feature_hash;
152 /* hash to speedup _lookup */
153 GHashTable *basename_hash;
155 /* updated whenever the feature list changes */
157 /* speedup for searching features */
158 GList *element_factory_list;
160 GList *typefind_factory_list;
164 /* the one instance of the default registry and the mutex protecting the
166 static GMutex _gst_registry_mutex;
167 static GstRegistry *_gst_registry_default = NULL;
170 #define DEFAULT_FORK TRUE
172 /* control the behaviour of registry rebuild */
173 static gboolean _gst_enable_registry_fork = DEFAULT_FORK;
174 /* List of plugins that need preloading/reloading after scanning registry */
175 extern GSList *_priv_gst_preload_plugins;
177 #ifndef GST_DISABLE_REGISTRY
178 /*set to TRUE when registry needn't to be updated */
179 gboolean _priv_gst_disable_registry_update = FALSE;
180 extern GList *_priv_gst_plugin_paths;
182 /* Set to TRUE when the registry cache should be disabled */
183 gboolean _gst_disable_registry_cache = FALSE;
185 static gboolean __registry_reuse_plugin_scanner = TRUE;
188 /* Element signals and args */
196 static void gst_registry_finalize (GObject * object);
198 static guint gst_registry_signals[LAST_SIGNAL] = { 0 };
200 static GstPluginFeature *gst_registry_lookup_feature_locked (GstRegistry *
201 registry, const char *name);
202 static GstPlugin *gst_registry_lookup_bn_locked (GstRegistry * registry,
203 const char *basename);
205 #define gst_registry_parent_class parent_class
206 G_DEFINE_TYPE (GstRegistry, gst_registry, GST_TYPE_OBJECT);
209 gst_registry_class_init (GstRegistryClass * klass)
211 GObjectClass *gobject_class;
213 gobject_class = (GObjectClass *) klass;
215 g_type_class_add_private (klass, sizeof (GstRegistryPrivate));
218 * GstRegistry::plugin-added:
219 * @registry: the registry that emitted the signal
220 * @plugin: the plugin that has been added
222 * Signals that a plugin has been added to the registry (possibly
223 * replacing a previously-added one by the same name)
225 gst_registry_signals[PLUGIN_ADDED] =
226 g_signal_new ("plugin-added", G_TYPE_FROM_CLASS (klass),
227 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
228 G_TYPE_NONE, 1, GST_TYPE_PLUGIN);
231 * GstRegistry::feature-added:
232 * @registry: the registry that emitted the signal
233 * @feature: the feature that has been added
235 * Signals that a feature has been added to the registry (possibly
236 * replacing a previously-added one by the same name)
238 gst_registry_signals[FEATURE_ADDED] =
239 g_signal_new ("feature-added", G_TYPE_FROM_CLASS (klass),
240 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
241 G_TYPE_NONE, 1, GST_TYPE_PLUGIN_FEATURE);
243 gobject_class->finalize = gst_registry_finalize;
247 gst_registry_init (GstRegistry * registry)
250 G_TYPE_INSTANCE_GET_PRIVATE (registry, GST_TYPE_REGISTRY,
252 registry->priv->feature_hash = g_hash_table_new (g_str_hash, g_str_equal);
253 registry->priv->basename_hash = g_hash_table_new (g_str_hash, g_str_equal);
257 gst_registry_finalize (GObject * object)
259 GstRegistry *registry = GST_REGISTRY (object);
263 plugins = registry->priv->plugins;
264 registry->priv->plugins = NULL;
266 GST_DEBUG_OBJECT (registry, "registry finalize");
269 GstPlugin *plugin = p->data;
272 GST_LOG_OBJECT (registry, "removing plugin %s",
273 gst_plugin_get_name (plugin));
274 gst_object_unref (plugin);
278 g_list_free (plugins);
280 features = registry->priv->features;
281 registry->priv->features = NULL;
285 GstPluginFeature *feature = f->data;
288 GST_LOG_OBJECT (registry, "removing feature %p (%s)", feature,
289 GST_OBJECT_NAME (feature));
290 gst_object_unparent (GST_OBJECT_CAST (feature));
294 g_list_free (features);
296 g_hash_table_destroy (registry->priv->feature_hash);
297 registry->priv->feature_hash = NULL;
298 g_hash_table_destroy (registry->priv->basename_hash);
299 registry->priv->basename_hash = NULL;
301 if (registry->priv->element_factory_list) {
302 GST_DEBUG_OBJECT (registry, "Cleaning up cached element factory list");
303 gst_plugin_feature_list_free (registry->priv->element_factory_list);
306 if (registry->priv->typefind_factory_list) {
307 GST_DEBUG_OBJECT (registry, "Cleaning up cached typefind factory list");
308 gst_plugin_feature_list_free (registry->priv->typefind_factory_list);
311 G_OBJECT_CLASS (parent_class)->finalize (object);
317 * Retrieves the singleton plugin registry. The caller does not own a
318 * reference on the registry, as it is alive as long as GStreamer is
321 * Returns: (transfer none): the #GstRegistry.
324 gst_registry_get (void)
326 GstRegistry *registry;
328 g_mutex_lock (&_gst_registry_mutex);
329 if (G_UNLIKELY (!_gst_registry_default)) {
330 _gst_registry_default = g_object_newv (GST_TYPE_REGISTRY, 0, NULL);
331 gst_object_ref_sink (GST_OBJECT_CAST (_gst_registry_default));
333 registry = _gst_registry_default;
334 g_mutex_unlock (&_gst_registry_mutex);
340 * gst_registry_add_path:
341 * @registry: the registry to add the path to
342 * @path: the path to add to the registry
344 * Add the given path to the registry. The syntax of the
345 * path is specific to the registry. If the path has already been
349 gst_registry_add_path (GstRegistry * registry, const gchar * path)
351 g_return_if_fail (GST_IS_REGISTRY (registry));
352 g_return_if_fail (path != NULL);
354 if (strlen (path) == 0)
357 GST_OBJECT_LOCK (registry);
358 if (g_list_find_custom (registry->priv->paths, path, (GCompareFunc) strcmp))
361 GST_INFO ("Adding plugin path: \"%s\"", path);
362 registry->priv->paths =
363 g_list_append (registry->priv->paths, g_strdup (path));
364 GST_OBJECT_UNLOCK (registry);
370 GST_INFO ("Ignoring empty plugin path");
375 g_warning ("path %s already added to registry", path);
376 GST_OBJECT_UNLOCK (registry);
382 * gst_registry_get_path_list:
383 * @registry: the registry to get the pathlist of
385 * Get the list of paths for the given registry.
387 * Returns: (transfer container) (element-type char*): A #GList of paths as
388 * strings. g_list_free after use.
393 gst_registry_get_path_list (GstRegistry * registry)
397 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
399 GST_OBJECT_LOCK (registry);
400 /* We don't need to copy the strings, because they won't be deleted
401 * as long as the GstRegistry is around */
402 list = g_list_copy (registry->priv->paths);
403 GST_OBJECT_UNLOCK (registry);
410 * gst_registry_add_plugin:
411 * @registry: the registry to add the plugin to
412 * @plugin: (transfer full): the plugin to add
414 * Add the plugin to the registry. The plugin-added signal will be emitted.
415 * This function will sink @plugin.
417 * Returns: TRUE on success.
422 gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin)
424 GstPlugin *existing_plugin;
426 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
427 g_return_val_if_fail (GST_IS_PLUGIN (plugin), FALSE);
429 GST_OBJECT_LOCK (registry);
430 if (G_LIKELY (plugin->basename)) {
431 /* we have a basename, see if we find the plugin */
433 gst_registry_lookup_bn_locked (registry, plugin->basename);
434 if (existing_plugin) {
435 GST_DEBUG_OBJECT (registry,
436 "Replacing existing plugin \"%s\" %p with new plugin %p for filename \"%s\"",
437 GST_STR_NULL (existing_plugin->filename), existing_plugin, plugin,
438 GST_STR_NULL (plugin->filename));
439 /* If the new plugin is blacklisted and the existing one isn't cached, do not
440 * accept if it's from a different location than the existing one */
441 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED) &&
442 strcmp (plugin->filename, existing_plugin->filename)) {
443 GST_WARNING_OBJECT (registry,
444 "Not replacing plugin because new one (%s) is blacklisted but for a different location than existing one (%s)",
445 plugin->filename, existing_plugin->filename);
446 gst_object_unref (plugin);
447 GST_OBJECT_UNLOCK (registry);
450 registry->priv->plugins =
451 g_list_remove (registry->priv->plugins, existing_plugin);
452 if (G_LIKELY (existing_plugin->basename))
453 g_hash_table_remove (registry->priv->basename_hash,
454 existing_plugin->basename);
455 gst_object_unref (existing_plugin);
459 GST_DEBUG_OBJECT (registry, "adding plugin %p for filename \"%s\"",
460 plugin, GST_STR_NULL (plugin->filename));
462 registry->priv->plugins = g_list_prepend (registry->priv->plugins, plugin);
463 if (G_LIKELY (plugin->basename))
464 g_hash_table_replace (registry->priv->basename_hash, plugin->basename,
467 gst_object_ref_sink (plugin);
468 GST_OBJECT_UNLOCK (registry);
470 GST_LOG_OBJECT (registry, "emitting plugin-added for filename \"%s\"",
471 GST_STR_NULL (plugin->filename));
472 g_signal_emit (registry, gst_registry_signals[PLUGIN_ADDED], 0, plugin);
478 gst_registry_remove_features_for_plugin_unlocked (GstRegistry * registry,
483 g_return_if_fail (GST_IS_REGISTRY (registry));
484 g_return_if_fail (GST_IS_PLUGIN (plugin));
486 /* Remove all features for this plugin */
487 f = registry->priv->features;
489 GList *next = g_list_next (f);
490 GstPluginFeature *feature = f->data;
492 if (G_UNLIKELY (feature && feature->plugin == plugin)) {
493 GST_DEBUG_OBJECT (registry, "removing feature %p (%s) for plugin %p (%s)",
494 feature, gst_plugin_feature_get_name (feature), plugin,
497 registry->priv->features =
498 g_list_delete_link (registry->priv->features, f);
499 g_hash_table_remove (registry->priv->feature_hash,
500 GST_OBJECT_NAME (feature));
501 gst_object_unparent (GST_OBJECT_CAST (feature));
505 registry->priv->cookie++;
509 * gst_registry_remove_plugin:
510 * @registry: the registry to remove the plugin from
511 * @plugin: (transfer none): the plugin to remove
513 * Remove the plugin from the registry.
518 gst_registry_remove_plugin (GstRegistry * registry, GstPlugin * plugin)
520 g_return_if_fail (GST_IS_REGISTRY (registry));
521 g_return_if_fail (GST_IS_PLUGIN (plugin));
523 GST_DEBUG_OBJECT (registry, "removing plugin %p (%s)",
524 plugin, gst_plugin_get_name (plugin));
526 GST_OBJECT_LOCK (registry);
527 registry->priv->plugins = g_list_remove (registry->priv->plugins, plugin);
528 if (G_LIKELY (plugin->basename))
529 g_hash_table_remove (registry->priv->basename_hash, plugin->basename);
530 gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
531 GST_OBJECT_UNLOCK (registry);
532 gst_object_unref (plugin);
536 * gst_registry_add_feature:
537 * @registry: the registry to add the plugin to
538 * @feature: (transfer full): the feature to add
540 * Add the feature to the registry. The feature-added signal will be emitted.
541 * This function sinks @feature.
543 * Returns: TRUE on success.
548 gst_registry_add_feature (GstRegistry * registry, GstPluginFeature * feature)
550 GstPluginFeature *existing_feature;
552 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
553 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
554 g_return_val_if_fail (GST_OBJECT_NAME (feature) != NULL, FALSE);
555 g_return_val_if_fail (feature->plugin_name != NULL, FALSE);
557 GST_OBJECT_LOCK (registry);
558 existing_feature = gst_registry_lookup_feature_locked (registry,
559 GST_OBJECT_NAME (feature));
560 if (G_UNLIKELY (existing_feature)) {
561 GST_DEBUG_OBJECT (registry, "replacing existing feature %p (%s)",
562 existing_feature, GST_OBJECT_NAME (feature));
563 /* Remove the existing feature from the list now, before we insert the new
564 * one, but don't unref yet because the hash is still storing a reference to
566 registry->priv->features =
567 g_list_remove (registry->priv->features, existing_feature);
570 GST_DEBUG_OBJECT (registry, "adding feature %p (%s)", feature,
571 GST_OBJECT_NAME (feature));
573 registry->priv->features = g_list_prepend (registry->priv->features, feature);
574 g_hash_table_replace (registry->priv->feature_hash, GST_OBJECT_NAME (feature),
577 if (G_UNLIKELY (existing_feature)) {
578 /* We unref now. No need to remove the feature name from the hash table, it
579 * got replaced by the new feature */
580 gst_object_unparent (GST_OBJECT_CAST (existing_feature));
583 gst_object_set_parent (GST_OBJECT_CAST (feature), GST_OBJECT_CAST (registry));
585 registry->priv->cookie++;
586 GST_OBJECT_UNLOCK (registry);
588 GST_LOG_OBJECT (registry, "emitting feature-added for %s",
589 GST_OBJECT_NAME (feature));
590 g_signal_emit (registry, gst_registry_signals[FEATURE_ADDED], 0, feature);
596 * gst_registry_remove_feature:
597 * @registry: the registry to remove the feature from
598 * @feature: (transfer none): the feature to remove
600 * Remove the feature from the registry.
605 gst_registry_remove_feature (GstRegistry * registry, GstPluginFeature * feature)
607 g_return_if_fail (GST_IS_REGISTRY (registry));
608 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
610 GST_DEBUG_OBJECT (registry, "removing feature %p (%s)",
611 feature, gst_plugin_feature_get_name (feature));
613 GST_OBJECT_LOCK (registry);
614 registry->priv->features = g_list_remove (registry->priv->features, feature);
615 g_hash_table_remove (registry->priv->feature_hash, GST_OBJECT_NAME (feature));
616 registry->priv->cookie++;
617 GST_OBJECT_UNLOCK (registry);
619 gst_object_unparent ((GstObject *) feature);
623 * gst_registry_plugin_filter:
624 * @registry: registry to query
625 * @filter: (scope call): the filter to use
626 * @first: only return first match
627 * @user_data: (closure): user data passed to the filter function
629 * Runs a filter against all plugins in the registry and returns a #GList with
630 * the results. If the first flag is set, only the first match is
631 * returned (as a list with a single object).
632 * Every plugin is reffed; use gst_plugin_list_free() after use, which
635 * Returns: (transfer full) (element-type Gst.Plugin): a #GList of #GstPlugin.
636 * Use gst_plugin_list_free() after usage.
641 gst_registry_plugin_filter (GstRegistry * registry,
642 GstPluginFilter filter, gboolean first, gpointer user_data)
646 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
648 GST_OBJECT_LOCK (registry);
652 for (walk = registry->priv->plugins; walk != NULL; walk = walk->next) {
653 GstPlugin *plugin = walk->data;
655 if (filter == NULL || filter (plugin, user_data)) {
656 list = g_list_prepend (list, gst_object_ref (plugin));
663 GST_OBJECT_UNLOCK (registry);
675 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
676 GstTypeNameData * data)
678 g_assert (GST_IS_PLUGIN_FEATURE (feature));
680 return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
681 (data->name == NULL || !strcmp (data->name, GST_OBJECT_NAME (feature))));
684 /* returns TRUE if the list was changed
686 * Must be called with the object lock taken */
688 gst_registry_get_feature_list_or_create (GstRegistry * registry,
689 GList ** previous, guint32 * cookie, GType type)
691 gboolean res = FALSE;
692 GstRegistryPrivate *priv = registry->priv;
694 if (G_UNLIKELY (!*previous || priv->cookie != *cookie)) {
695 GstTypeNameData data;
699 gst_plugin_feature_list_free (*previous);
706 for (walk = registry->priv->features; walk != NULL; walk = walk->next) {
707 GstPluginFeature *feature = walk->data;
709 if (gst_plugin_feature_type_name_filter (feature, &data)) {
710 *previous = g_list_prepend (*previous, gst_object_ref (feature));
714 *cookie = priv->cookie;
722 type_find_factory_rank_cmp (const GstPluginFeature * fac1,
723 const GstPluginFeature * fac2)
725 if (G_LIKELY (fac1->rank != fac2->rank))
726 return fac2->rank - fac1->rank;
728 /* to make the order in which things happen more deterministic,
729 * sort by name when the ranks are the same. */
730 return strcmp (GST_OBJECT_NAME (fac1), GST_OBJECT_NAME (fac2));
734 gst_registry_get_element_factory_list (GstRegistry * registry)
738 GST_OBJECT_LOCK (registry);
740 gst_registry_get_feature_list_or_create (registry,
741 ®istry->priv->element_factory_list, ®istry->priv->efl_cookie,
742 GST_TYPE_ELEMENT_FACTORY);
744 /* Return reffed copy */
745 list = gst_plugin_feature_list_copy (registry->priv->element_factory_list);
747 GST_OBJECT_UNLOCK (registry);
753 gst_registry_get_typefind_factory_list (GstRegistry * registry)
757 GST_OBJECT_LOCK (registry);
759 if (G_UNLIKELY (gst_registry_get_feature_list_or_create (registry,
760 ®istry->priv->typefind_factory_list,
761 ®istry->priv->tfl_cookie, GST_TYPE_TYPE_FIND_FACTORY)))
762 registry->priv->typefind_factory_list =
763 g_list_sort (registry->priv->typefind_factory_list,
764 (GCompareFunc) type_find_factory_rank_cmp);
766 /* Return reffed copy */
767 list = gst_plugin_feature_list_copy (registry->priv->typefind_factory_list);
769 GST_OBJECT_UNLOCK (registry);
775 * gst_registry_feature_filter:
776 * @registry: registry to query
777 * @filter: (scope call): the filter to use
778 * @first: only return first match
779 * @user_data: (closure): user data passed to the filter function
781 * Runs a filter against all features of the plugins in the registry
782 * and returns a GList with the results.
783 * If the first flag is set, only the first match is
784 * returned (as a list with a single object).
786 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
787 * #GstPluginFeature. Use gst_plugin_feature_list_free() after usage.
792 gst_registry_feature_filter (GstRegistry * registry,
793 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
797 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
799 GST_OBJECT_LOCK (registry);
803 for (walk = registry->priv->features; walk != NULL; walk = walk->next) {
804 GstPluginFeature *feature = walk->data;
806 if (filter == NULL || filter (feature, user_data)) {
807 list = g_list_prepend (list, gst_object_ref (feature));
814 GST_OBJECT_UNLOCK (registry);
820 gst_registry_plugin_name_filter (GstPlugin * plugin, const gchar * name)
822 return (plugin->desc.name && !strcmp (plugin->desc.name, name));
826 * gst_registry_find_plugin:
827 * @registry: the registry to search
828 * @name: the plugin name to find
830 * Find the plugin with the given name in the registry.
831 * The plugin will be reffed; caller is responsible for unreffing.
833 * Returns: (transfer full): the plugin with the given name or NULL if the
834 * plugin was not found. gst_object_unref() after usage.
839 gst_registry_find_plugin (GstRegistry * registry, const gchar * name)
842 GstPlugin *result = NULL;
844 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
845 g_return_val_if_fail (name != NULL, NULL);
847 walk = gst_registry_plugin_filter (registry,
848 (GstPluginFilter) gst_registry_plugin_name_filter, TRUE, (gpointer) name);
850 result = GST_PLUGIN_CAST (walk->data);
852 gst_object_ref (result);
853 gst_plugin_list_free (walk);
860 * gst_registry_find_feature:
861 * @registry: the registry to search
862 * @name: the pluginfeature name to find
863 * @type: the pluginfeature type to find
865 * Find the pluginfeature with the given name and type in the registry.
867 * Returns: (transfer full): the pluginfeature with the given name and type
868 * or NULL if the plugin was not found. gst_object_unref() after usage.
873 gst_registry_find_feature (GstRegistry * registry, const gchar * name,
876 GstPluginFeature *feature = NULL;
878 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
879 g_return_val_if_fail (name != NULL, NULL);
880 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_PLUGIN_FEATURE), NULL);
882 feature = gst_registry_lookup_feature (registry, name);
883 if (feature && !g_type_is_a (G_TYPE_FROM_INSTANCE (feature), type)) {
884 gst_object_unref (feature);
892 * gst_registry_get_feature_list:
893 * @registry: a #GstRegistry
896 * Retrieves a #GList of #GstPluginFeature of @type.
898 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
899 * #GstPluginFeature of @type. Use gst_plugin_feature_list_free() after use
904 gst_registry_get_feature_list (GstRegistry * registry, GType type)
906 GstTypeNameData data;
908 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
909 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_PLUGIN_FEATURE), NULL);
912 if (type == GST_TYPE_ELEMENT_FACTORY)
913 return gst_registry_get_element_factory_list (registry);
914 else if (type == GST_TYPE_TYPE_FIND_FACTORY)
915 return gst_registry_get_typefind_factory_list (registry);
920 return gst_registry_feature_filter (registry,
921 (GstPluginFeatureFilter) gst_plugin_feature_type_name_filter,
926 * gst_registry_get_plugin_list:
927 * @registry: the registry to search
929 * Get a copy of all plugins registered in the given registry. The refcount
930 * of each element in the list in incremented.
932 * Returns: (transfer full) (element-type Gst.Plugin): a #GList of #GstPlugin.
933 * Use gst_plugin_list_free() after usage.
938 gst_registry_get_plugin_list (GstRegistry * registry)
943 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
945 GST_OBJECT_LOCK (registry);
946 list = g_list_copy (registry->priv->plugins);
947 for (g = list; g; g = g->next) {
948 gst_object_ref (GST_PLUGIN_CAST (g->data));
950 GST_OBJECT_UNLOCK (registry);
955 static GstPluginFeature *
956 gst_registry_lookup_feature_locked (GstRegistry * registry, const char *name)
958 return g_hash_table_lookup (registry->priv->feature_hash, name);
962 * gst_registry_lookup_feature:
963 * @registry: a #GstRegistry
964 * @name: a #GstPluginFeature name
966 * Find a #GstPluginFeature with @name in @registry.
968 * Returns: (transfer full): a #GstPluginFeature with its refcount incremented,
969 * use gst_object_unref() after usage.
974 gst_registry_lookup_feature (GstRegistry * registry, const char *name)
976 GstPluginFeature *feature;
978 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
979 g_return_val_if_fail (name != NULL, NULL);
981 GST_OBJECT_LOCK (registry);
982 feature = gst_registry_lookup_feature_locked (registry, name);
984 gst_object_ref (feature);
985 GST_OBJECT_UNLOCK (registry);
991 gst_registry_lookup_bn_locked (GstRegistry * registry, const char *basename)
993 return g_hash_table_lookup (registry->priv->basename_hash, basename);
997 gst_registry_lookup_bn (GstRegistry * registry, const char *basename)
1001 GST_OBJECT_LOCK (registry);
1002 plugin = gst_registry_lookup_bn_locked (registry, basename);
1004 gst_object_ref (plugin);
1005 GST_OBJECT_UNLOCK (registry);
1011 * gst_registry_lookup:
1012 * @registry: the registry to look up in
1013 * @filename: the name of the file to look up
1015 * Look up a plugin in the given registry with the given filename.
1016 * If found, plugin is reffed.
1018 * Returns: (transfer full): the #GstPlugin if found, or NULL if not.
1019 * gst_object_unref() after usage.
1022 gst_registry_lookup (GstRegistry * registry, const char *filename)
1027 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1028 g_return_val_if_fail (filename != NULL, NULL);
1030 basename = g_path_get_basename (filename);
1031 if (G_UNLIKELY (basename == NULL))
1034 plugin = gst_registry_lookup_bn (registry, basename);
1043 REGISTRY_SCAN_HELPER_NOT_STARTED = 0,
1044 REGISTRY_SCAN_HELPER_DISABLED,
1045 REGISTRY_SCAN_HELPER_RUNNING
1046 } GstRegistryScanHelperState;
1050 GstRegistry *registry;
1051 GstRegistryScanHelperState helper_state;
1052 GstPluginLoader *helper;
1054 } GstRegistryScanContext;
1057 init_scan_context (GstRegistryScanContext * context, GstRegistry * registry)
1061 context->registry = registry;
1063 /* see if forking is enabled and set up the scan helper state accordingly */
1064 do_fork = _gst_enable_registry_fork;
1066 const gchar *fork_env;
1068 /* forking enabled, see if it is disabled with an env var */
1069 if ((fork_env = g_getenv ("GST_REGISTRY_FORK"))) {
1070 /* fork enabled for any value different from "no" */
1071 do_fork = strcmp (fork_env, "no") != 0;
1076 context->helper_state = REGISTRY_SCAN_HELPER_NOT_STARTED;
1078 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1080 context->helper = NULL;
1081 context->changed = FALSE;
1085 clear_scan_context (GstRegistryScanContext * context)
1087 if (context->helper) {
1088 context->changed |= _priv_gst_plugin_loader_funcs.destroy (context->helper);
1089 context->helper = NULL;
1094 gst_registry_scan_plugin_file (GstRegistryScanContext * context,
1095 const gchar * filename, off_t file_size, time_t file_mtime)
1097 gboolean changed = FALSE;
1098 GstPlugin *newplugin = NULL;
1101 /* Disable external plugin loader on Windows until it is ported properly. */
1102 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1106 /* Have a plugin to load - see if the scan-helper needs starting */
1107 if (context->helper_state == REGISTRY_SCAN_HELPER_NOT_STARTED) {
1108 GST_DEBUG ("Starting plugin scanner for file %s", filename);
1109 context->helper = _priv_gst_plugin_loader_funcs.create (context->registry);
1110 if (context->helper != NULL)
1111 context->helper_state = REGISTRY_SCAN_HELPER_RUNNING;
1113 GST_WARNING ("Failed starting plugin scanner. Scanning in-process");
1114 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1118 if (context->helper_state == REGISTRY_SCAN_HELPER_RUNNING) {
1119 GST_DEBUG ("Using scan-helper to load plugin %s", filename);
1120 if (!_priv_gst_plugin_loader_funcs.load (context->helper,
1121 filename, file_size, file_mtime)) {
1122 g_warning ("External plugin loader failed. This most likely means that "
1123 "the plugin loader helper binary was not found or could not be run. "
1124 "You might need to set the GST_PLUGIN_SCANNER environment variable "
1125 "if your setup is unusual. This should normally not be required "
1127 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1131 /* Check if the helper is disabled (or just got disabled above) */
1132 if (context->helper_state == REGISTRY_SCAN_HELPER_DISABLED) {
1133 /* Load plugin the old fashioned way... */
1135 /* We don't use a GError here because a failure to load some shared
1136 * objects as plugins is normal (particularly in the uninstalled case)
1138 newplugin = gst_plugin_load_file (filename, NULL);
1142 GST_DEBUG_OBJECT (context->registry, "marking new plugin %p as registered",
1144 newplugin->registered = TRUE;
1145 gst_object_unref (newplugin);
1148 #ifndef GST_DISABLE_REGISTRY
1149 if (!__registry_reuse_plugin_scanner) {
1150 clear_scan_context (context);
1151 context->helper_state = REGISTRY_SCAN_HELPER_NOT_STARTED;
1159 is_blacklisted_hidden_directory (const gchar * dirent)
1161 if (G_LIKELY (dirent[0] != '.'))
1164 /* skip the .debug directory, these contain elf files that are not
1165 * useful or worse, can crash dlopen () */
1166 if (strcmp (dirent, ".debug") == 0)
1169 /* can also skip .git and .deps dirs, those won't contain useful files.
1170 * This speeds up scanning a bit in uninstalled setups. */
1171 if (strcmp (dirent, ".git") == 0 || strcmp (dirent, ".deps") == 0)
1178 gst_registry_scan_path_level (GstRegistryScanContext * context,
1179 const gchar * path, int level)
1182 const gchar *dirent;
1185 gboolean changed = FALSE;
1187 dir = g_dir_open (path, 0, NULL);
1191 while ((dirent = g_dir_read_name (dir))) {
1192 GStatBuf file_status;
1194 filename = g_build_filename (path, dirent, NULL);
1195 if (g_stat (filename, &file_status) < 0) {
1196 /* Plugin will be removed from cache after the scan completes if it
1197 * is still marked 'cached' */
1202 if (file_status.st_mode & S_IFDIR) {
1203 if (G_UNLIKELY (is_blacklisted_hidden_directory (dirent))) {
1204 GST_TRACE_OBJECT (context->registry, "ignoring %s directory", dirent);
1208 /* FIXME 0.11: Don't recurse into directories, this behaviour
1209 * is inconsistent with other PATH environment variables
1212 GST_LOG_OBJECT (context->registry, "recursing into directory %s",
1214 changed |= gst_registry_scan_path_level (context, filename, level - 1);
1216 GST_LOG_OBJECT (context->registry, "not recursing into directory %s, "
1217 "recursion level too deep", filename);
1222 if (!(file_status.st_mode & S_IFREG)) {
1223 GST_TRACE_OBJECT (context->registry, "%s is not a regular file, ignoring",
1228 if (!g_str_has_suffix (dirent, G_MODULE_SUFFIX)
1229 #ifdef GST_EXTRA_MODULE_SUFFIX
1230 && !g_str_has_suffix (dirent, GST_EXTRA_MODULE_SUFFIX)
1233 GST_TRACE_OBJECT (context->registry,
1234 "extension is not recognized as module file, ignoring file %s",
1240 GST_LOG_OBJECT (context->registry, "file %s looks like a possible module",
1243 /* try to avoid unnecessary plugin-move pain */
1244 if (g_str_has_prefix (dirent, "libgstvalve") ||
1245 g_str_has_prefix (dirent, "libgstselector")) {
1246 GST_WARNING_OBJECT (context->registry, "ignoring old plugin %s which "
1247 "has been merged into the corelements plugin", filename);
1248 /* Plugin will be removed from cache after the scan completes if it
1249 * is still marked 'cached' */
1254 /* plug-ins are considered unique by basename; if the given name
1255 * was already seen by the registry, we ignore it */
1256 plugin = gst_registry_lookup_bn (context->registry, dirent);
1258 gboolean env_vars_changed, deps_changed = FALSE;
1260 if (plugin->registered) {
1261 GST_DEBUG_OBJECT (context->registry,
1262 "plugin already registered from path \"%s\"",
1263 GST_STR_NULL (plugin->filename));
1265 gst_object_unref (plugin);
1269 env_vars_changed = _priv_plugin_deps_env_vars_changed (plugin);
1271 /* If a file with a certain basename is seen on a different path,
1272 * update the plugin to ensure the registry cache will reflect up
1273 * to date information */
1275 if (plugin->file_mtime == file_status.st_mtime &&
1276 plugin->file_size == file_status.st_size && !env_vars_changed &&
1277 !(deps_changed = _priv_plugin_deps_files_changed (plugin)) &&
1278 !strcmp (plugin->filename, filename)) {
1279 GST_LOG_OBJECT (context->registry, "file %s cached", filename);
1280 GST_OBJECT_FLAG_UNSET (plugin, GST_PLUGIN_FLAG_CACHED);
1281 GST_LOG_OBJECT (context->registry,
1282 "marking plugin %p as registered as %s", plugin, filename);
1283 plugin->registered = TRUE;
1285 GST_INFO_OBJECT (context->registry, "cached info for %s is stale",
1287 GST_DEBUG_OBJECT (context->registry, "mtime %" G_GINT64_FORMAT " != %"
1288 G_GINT64_FORMAT " or size %" G_GINT64_FORMAT " != %"
1289 G_GINT64_FORMAT " or external dependency env_vars changed: %d or"
1290 " external dependencies changed: %d or old path %s != new path %s",
1291 (gint64) plugin->file_mtime, (gint64) file_status.st_mtime,
1292 (gint64) plugin->file_size, (gint64) file_status.st_size,
1293 env_vars_changed, deps_changed, plugin->filename, filename);
1294 gst_registry_remove_plugin (context->registry, plugin);
1295 changed |= gst_registry_scan_plugin_file (context, filename,
1296 file_status.st_size, file_status.st_mtime);
1298 gst_object_unref (plugin);
1301 GST_DEBUG_OBJECT (context->registry, "file %s not yet in registry",
1303 changed |= gst_registry_scan_plugin_file (context, filename,
1304 file_status.st_size, file_status.st_mtime);
1316 gst_registry_scan_path_internal (GstRegistryScanContext * context,
1321 GST_DEBUG_OBJECT (context->registry, "scanning path %s", path);
1322 changed = gst_registry_scan_path_level (context, path, 10);
1324 GST_DEBUG_OBJECT (context->registry, "registry changed in path %s: %d", path,
1330 * gst_registry_scan_path:
1331 * @registry: the registry to add found plugins to
1332 * @path: the path to scan
1334 * Scan the given path for plugins to add to the registry. The syntax of the
1335 * path is specific to the registry.
1337 * Returns: %TRUE if registry changed
1340 gst_registry_scan_path (GstRegistry * registry, const gchar * path)
1342 GstRegistryScanContext context;
1345 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
1346 g_return_val_if_fail (path != NULL, FALSE);
1348 init_scan_context (&context, registry);
1350 result = gst_registry_scan_path_internal (&context, path);
1352 clear_scan_context (&context);
1353 result |= context.changed;
1359 _gst_plugin_feature_filter_plugin_name (GstPluginFeature * feature,
1362 return (strcmp (feature->plugin_name, (gchar *) user_data) == 0);
1366 * gst_registry_get_feature_list_by_plugin:
1367 * @registry: a #GstRegistry.
1368 * @name: a plugin name.
1370 * Retrieves a #GList of features of the plugin with name @name.
1372 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
1373 * #GstPluginFeature. Use gst_plugin_feature_list_free() after usage.
1376 gst_registry_get_feature_list_by_plugin (GstRegistry * registry,
1379 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1380 g_return_val_if_fail (name != NULL, NULL);
1382 return gst_registry_feature_filter (registry,
1383 _gst_plugin_feature_filter_plugin_name, FALSE, (gpointer) name);
1386 /* Unref and delete the default registry */
1388 _priv_gst_registry_cleanup (void)
1390 GstRegistry *registry;
1392 g_mutex_lock (&_gst_registry_mutex);
1393 if ((registry = _gst_registry_default) != NULL) {
1394 _gst_registry_default = NULL;
1396 g_mutex_unlock (&_gst_registry_mutex);
1398 /* unref outside of the lock because we can. */
1400 gst_object_unref (registry);
1404 * gst_registry_check_feature_version:
1405 * @registry: a #GstRegistry
1406 * @feature_name: the name of the feature (e.g. "oggdemux")
1407 * @min_major: the minimum major version number
1408 * @min_minor: the minimum minor version number
1409 * @min_micro: the minimum micro version number
1411 * Checks whether a plugin feature by the given name exists in
1412 * @registry and whether its version is at least the
1415 * Returns: #TRUE if the feature could be found and the version is
1416 * the same as the required version or newer, and #FALSE otherwise.
1419 gst_registry_check_feature_version (GstRegistry * registry,
1420 const gchar * feature_name, guint min_major, guint min_minor,
1423 GstPluginFeature *feature;
1424 gboolean ret = FALSE;
1426 g_return_val_if_fail (feature_name != NULL, FALSE);
1428 GST_DEBUG ("Looking up plugin feature '%s'", feature_name);
1430 feature = gst_registry_lookup_feature (registry, feature_name);
1432 ret = gst_plugin_feature_check_version (feature, min_major, min_minor,
1434 gst_object_unref (feature);
1436 GST_DEBUG ("Could not find plugin feature '%s'", feature_name);
1443 load_plugin_func (gpointer data, gpointer user_data)
1446 const gchar *filename;
1449 filename = (const gchar *) data;
1450 GST_DEBUG ("Pre-loading plugin %s", filename);
1452 plugin = gst_plugin_load_file (filename, &err);
1455 GST_INFO ("Loaded plugin: \"%s\"", filename);
1457 gst_registry_add_plugin (gst_registry_get (), plugin);
1460 /* Report error to user, and free error */
1461 GST_ERROR ("Failed to load plugin: %s", err->message);
1464 GST_WARNING ("Failed to load plugin: \"%s\"", filename);
1469 #ifndef GST_DISABLE_REGISTRY
1470 /* Unref all plugins marked 'cached', to clear old plugins that no
1471 * longer exist. Returns TRUE if any plugins were removed */
1473 gst_registry_remove_cache_plugins (GstRegistry * registry)
1478 gboolean changed = FALSE;
1480 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
1482 GST_OBJECT_LOCK (registry);
1484 GST_DEBUG_OBJECT (registry, "removing cached plugins");
1485 g = registry->priv->plugins;
1489 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_CACHED)) {
1490 GST_DEBUG_OBJECT (registry, "removing cached plugin \"%s\"",
1491 GST_STR_NULL (plugin->filename));
1492 registry->priv->plugins = g_list_delete_link (registry->priv->plugins, g);
1493 if (G_LIKELY (plugin->basename))
1494 g_hash_table_remove (registry->priv->basename_hash, plugin->basename);
1495 gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
1496 gst_object_unref (plugin);
1502 GST_OBJECT_UNLOCK (registry);
1509 REGISTRY_SCAN_AND_UPDATE_FAILURE = 0,
1510 REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED,
1511 REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED
1512 } GstRegistryScanAndUpdateResult;
1515 * scan_and_update_registry:
1516 * @default_registry: the #GstRegistry
1517 * @registry_file: registry filename
1518 * @write_changes: write registry if it has changed?
1520 * Scans for registry changes and eventually updates the registry cache.
1522 * Return: %REGISTRY_SCAN_AND_UPDATE_FAILURE if the registry could not scanned
1523 * or updated, %REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED if the
1524 * registry is clean and %REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED if
1525 * it has been updated and the cache needs to be re-read.
1527 static GstRegistryScanAndUpdateResult
1528 scan_and_update_registry (GstRegistry * default_registry,
1529 const gchar * registry_file, gboolean write_changes, GError ** error)
1531 const gchar *plugin_path;
1532 gboolean changed = FALSE;
1534 GstRegistryScanContext context;
1536 GST_INFO ("Validating plugins from registry cache: %s", registry_file);
1538 init_scan_context (&context, default_registry);
1540 /* It sounds tempting to just compare the mtime of directories with the mtime
1541 * of the registry cache, but it does not work. It would not catch updated
1542 * plugins, which might bring more or less features.
1545 /* scan paths specified via --gst-plugin-path */
1546 GST_DEBUG ("scanning paths added via --gst-plugin-path");
1547 for (l = _priv_gst_plugin_paths; l != NULL; l = l->next) {
1548 GST_INFO ("Scanning plugin path: \"%s\"", (gchar *) l->data);
1549 changed |= gst_registry_scan_path_internal (&context, (gchar *) l->data);
1551 /* keep plugin_paths around in case a re-scan is forced later on */
1553 /* GST_PLUGIN_PATH specifies a list of directories to scan for
1554 * additional plugins. These take precedence over the system plugins */
1555 plugin_path = g_getenv ("GST_PLUGIN_PATH_1_0");
1556 if (plugin_path == NULL)
1557 plugin_path = g_getenv ("GST_PLUGIN_PATH");
1562 GST_DEBUG ("GST_PLUGIN_PATH set to %s", plugin_path);
1563 list = g_strsplit (plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
1564 for (i = 0; list[i]; i++) {
1565 changed |= gst_registry_scan_path_internal (&context, list[i]);
1569 GST_DEBUG ("GST_PLUGIN_PATH not set");
1572 /* GST_PLUGIN_SYSTEM_PATH specifies a list of plugins that are always
1573 * loaded by default. If not set, this defaults to the system-installed
1574 * path, and the plugins installed in the user's home directory */
1575 plugin_path = g_getenv ("GST_PLUGIN_SYSTEM_PATH_1_0");
1576 if (plugin_path == NULL)
1577 plugin_path = g_getenv ("GST_PLUGIN_SYSTEM_PATH");
1578 if (plugin_path == NULL) {
1581 GST_DEBUG ("GST_PLUGIN_SYSTEM_PATH not set");
1583 /* plugins in the user's home directory take precedence over
1584 * system-installed ones */
1585 home_plugins = g_build_filename (g_get_user_data_dir (),
1586 "gstreamer-" GST_API_VERSION, "plugins", NULL);
1588 GST_DEBUG ("scanning home plugins %s", home_plugins);
1589 changed |= gst_registry_scan_path_internal (&context, home_plugins);
1590 g_free (home_plugins);
1592 /* add the main (installed) library path */
1593 GST_DEBUG ("scanning main plugins %s", PLUGINDIR);
1594 changed |= gst_registry_scan_path_internal (&context, PLUGINDIR);
1602 g_win32_get_package_installation_directory_of_module
1603 (_priv_gst_dll_handle);
1606 g_build_filename (base_dir, "lib", "gstreamer-" GST_API_VERSION,
1608 GST_DEBUG ("scanning DLL dir %s", dir);
1610 changed |= gst_registry_scan_path_internal (&context, dir);
1620 GST_DEBUG ("GST_PLUGIN_SYSTEM_PATH set to %s", plugin_path);
1621 list = g_strsplit (plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
1622 for (i = 0; list[i]; i++) {
1623 changed |= gst_registry_scan_path_internal (&context, list[i]);
1628 clear_scan_context (&context);
1629 changed |= context.changed;
1631 /* Remove cached plugins so stale info is cleared. */
1632 changed |= gst_registry_remove_cache_plugins (default_registry);
1635 GST_INFO ("Registry cache has not changed");
1636 return REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED;
1639 if (!write_changes) {
1640 GST_INFO ("Registry cache changed, but writing is disabled. Not writing.");
1641 return REGISTRY_SCAN_AND_UPDATE_FAILURE;
1644 GST_INFO ("Registry cache changed. Writing new registry cache");
1645 if (!priv_gst_registry_binary_write_cache (default_registry,
1646 default_registry->priv->plugins, registry_file)) {
1647 g_set_error (error, GST_CORE_ERROR, GST_CORE_ERROR_FAILED,
1648 _("Error writing registry cache to %s: %s"),
1649 registry_file, g_strerror (errno));
1650 return REGISTRY_SCAN_AND_UPDATE_FAILURE;
1653 GST_INFO ("Registry cache written successfully");
1654 return REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED;
1658 ensure_current_registry (GError ** error)
1660 gchar *registry_file;
1661 GstRegistry *default_registry;
1662 gboolean ret = TRUE;
1663 gboolean do_update = TRUE;
1664 gboolean have_cache = TRUE;
1666 default_registry = gst_registry_get ();
1668 registry_file = g_strdup (g_getenv ("GST_REGISTRY_1_0"));
1669 if (registry_file == NULL)
1670 registry_file = g_strdup (g_getenv ("GST_REGISTRY"));
1671 if (registry_file == NULL) {
1672 registry_file = g_build_filename (g_get_user_cache_dir (),
1673 "gstreamer-" GST_API_VERSION, "registry." TARGET_CPU ".bin", NULL);
1676 if (!_gst_disable_registry_cache) {
1677 GST_INFO ("reading registry cache: %s", registry_file);
1678 have_cache = priv_gst_registry_binary_read_cache (default_registry,
1680 /* Only ever read the registry cache once, then disable it for
1681 * subsequent updates during the program lifetime */
1682 _gst_disable_registry_cache = TRUE;
1686 do_update = !_priv_gst_disable_registry_update;
1688 const gchar *update_env;
1690 if ((update_env = g_getenv ("GST_REGISTRY_UPDATE"))) {
1691 /* do update for any value different from "no" */
1692 do_update = (strcmp (update_env, "no") != 0);
1698 const gchar *reuse_env;
1700 if ((reuse_env = g_getenv ("GST_REGISTRY_REUSE_PLUGIN_SCANNER"))) {
1701 /* do reuse for any value different from "no" */
1702 __registry_reuse_plugin_scanner = (strcmp (reuse_env, "no") != 0);
1704 /* now check registry */
1705 GST_DEBUG ("Updating registry cache");
1706 scan_and_update_registry (default_registry, registry_file, TRUE, error);
1708 GST_DEBUG ("Not updating registry cache (disabled)");
1711 g_free (registry_file);
1712 GST_INFO ("registry reading and updating done, result = %d", ret);
1716 #endif /* GST_DISABLE_REGISTRY */
1719 * gst_registry_fork_is_enabled:
1721 * By default GStreamer will perform scanning and rebuilding of the
1722 * registry file using a helper child process.
1724 * Applications might want to disable this behaviour with the
1725 * gst_registry_fork_set_enabled() function, in which case new plugins
1726 * are scanned (and loaded) into the application process.
1728 * Returns: %TRUE if GStreamer will use the child helper process when
1729 * rebuilding the registry.
1732 gst_registry_fork_is_enabled (void)
1734 return _gst_enable_registry_fork;
1738 * gst_registry_fork_set_enabled:
1739 * @enabled: whether rebuilding the registry can use a temporary child helper process.
1741 * Applications might want to disable/enable spawning of a child helper process
1742 * when rebuilding the registry. See gst_registry_fork_is_enabled() for more
1746 gst_registry_fork_set_enabled (gboolean enabled)
1748 _gst_enable_registry_fork = enabled;
1752 * gst_update_registry:
1754 * Forces GStreamer to re-scan its plugin paths and update the default
1757 * Applications will almost never need to call this function, it is only
1758 * useful if the application knows new plugins have been installed (or old
1759 * ones removed) since the start of the application (or, to be precise, the
1760 * first call to gst_init()) and the application wants to make use of any
1761 * newly-installed plugins without restarting the application.
1763 * Applications should assume that the registry update is neither atomic nor
1764 * thread-safe and should therefore not have any dynamic pipelines running
1765 * (including the playbin and decodebin elements) and should also not create
1766 * any elements or access the GStreamer registry while the update is in
1769 * Note that this function may block for a significant amount of time.
1771 * Returns: %TRUE if the registry has been updated successfully (does not
1772 * imply that there were changes), otherwise %FALSE.
1775 gst_update_registry (void)
1779 #ifndef GST_DISABLE_REGISTRY
1782 res = ensure_current_registry (&err);
1784 GST_WARNING ("registry update failed: %s", err->message);
1787 GST_LOG ("registry update succeeded");
1791 GST_WARNING ("registry update failed: %s", "registry disabled");
1793 #endif /* GST_DISABLE_REGISTRY */
1795 if (_priv_gst_preload_plugins) {
1796 GST_DEBUG ("Preloading indicated plugins...");
1797 g_slist_foreach (_priv_gst_preload_plugins, load_plugin_func, NULL);
1804 * gst_registry_get_feature_list_cookie:
1805 * @registry: the registry
1807 * Returns the registrys feature list cookie. This changes
1808 * every time a feature is added or removed from the registry.
1810 * Returns: the feature list cookie.
1813 gst_registry_get_feature_list_cookie (GstRegistry * registry)
1815 g_return_val_if_fail (GST_IS_REGISTRY (registry), 0);
1817 return registry->priv->cookie;