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. There may be multiple #GstRegistry objects,
36 * but the "default registry" is the only object that has any meaning to the
39 * The registry file is actually a cache of plugin information. This is
40 * unlike versions prior to 0.10, where the registry file was the primary source
41 * of plugin information, and was created by the gst-register command.
43 * The primary source, at all times, of plugin information is each plugin file
44 * itself. Thus, if an application wants information about a particular plugin,
45 * or wants to search for a feature that satisfies given criteria, the primary
46 * means of doing so is to load every plugin and look at the resulting
47 * information that is gathered in the default registry. Clearly, this is a time
48 * consuming process, so we cache information in the registry file. The format
49 * and location of the cache file is internal to gstreamer.
51 * On startup, plugins are searched for in the plugin search path. The following
52 * locations are checked in this order:
55 * <para>location from --gst-plugin-path commandline option.</para>
58 * <para>the GST_PLUGIN_PATH environment variable.</para>
61 * <para>the GST_PLUGIN_SYSTEM_PATH environment variable.</para>
64 * <para>default locations (if GST_PLUGIN_SYSTEM_PATH is not set). Those
65 * default locations are:
66 * <filename>~/.gstreamer-$GST_MAJORMINOR/plugins/</filename>
67 * and <filename>$prefix/libs/gstreamer-$GST_MAJORMINOR/</filename>.
71 * The registry cache file is loaded from
72 * <filename>~/.gstreamer-$GST_MAJORMINOR/registry-$ARCH.bin</filename> or the
73 * file listed in the GST_REGISTRY env var. One reason to change the registry
74 * location is for testing.
76 * For each plugin that is found in the plugin search path, there could be 3
77 * possibilities for cached information:
80 * <para>the cache may not contain information about a given file.</para>
83 * <para>the cache may have stale information.</para>
86 * <para>the cache may have current information.</para>
90 * In the first two cases, the plugin is loaded and the cache updated. In
91 * addition to these cases, the cache may have entries for plugins that are not
92 * relevant to the current process. These are marked as not available to the
93 * current process. If the cache is updated for whatever reason, it is marked
96 * A dirty cache is written out at the end of initialization. Each entry is
97 * checked to make sure the information is minimally valid. If not, the entry is
100 * <emphasis role="bold">Implementation notes:</emphasis>
102 * The "cache" and "default registry" are different concepts and can represent
103 * different sets of plugins. For various reasons, at init time, the cache is
104 * stored in the default registry, and plugins not relevant to the current
105 * process are marked with the %GST_PLUGIN_FLAG_CACHED bit. These plugins are
106 * removed at the end of initialization.
112 #include "gstconfig.h"
113 #include "gst_private.h"
115 #include <sys/types.h>
116 #include <sys/stat.h>
125 #include <glib/gstdio.h>
128 #include "gsterror.h"
129 #include "gstregistry.h"
130 #include "gstmarshal.h"
131 #include "gstfilter.h"
133 #include "gstpluginloader.h"
135 #include "gst-i18n-lib.h"
138 #include "glib-compat-private.h"
142 extern HMODULE _priv_gst_dll_handle;
145 #define GST_CAT_DEFAULT GST_CAT_REGISTRY
147 struct _GstRegistryPrivate
149 /* updated whenever the feature list changes */
151 /* speedup for searching features */
152 GList *element_factory_list;
154 GList *typefind_factory_list;
158 /* the one instance of the default registry and the mutex protecting the
160 static GStaticMutex _gst_registry_mutex = G_STATIC_MUTEX_INIT;
161 static GstRegistry *_gst_registry_default = NULL;
164 #define DEFAULT_FORK TRUE
166 /* control the behaviour of registry rebuild */
167 static gboolean _gst_enable_registry_fork = DEFAULT_FORK;
168 /* List of plugins that need preloading/reloading after scanning registry */
169 extern GSList *_priv_gst_preload_plugins;
171 #ifndef GST_DISABLE_REGISTRY
172 /*set to TRUE when registry needn't to be updated */
173 gboolean _priv_gst_disable_registry_update = FALSE;
174 extern GList *_priv_gst_plugin_paths;
176 /* Set to TRUE when the registry cache should be disabled */
177 gboolean _gst_disable_registry_cache = FALSE;
179 static gboolean __registry_reuse_plugin_scanner = TRUE;
182 /* Element signals and args */
190 static void gst_registry_finalize (GObject * object);
192 static guint gst_registry_signals[LAST_SIGNAL] = { 0 };
194 static GstPluginFeature *gst_registry_lookup_feature_locked (GstRegistry *
195 registry, const char *name);
196 static GstPlugin *gst_registry_lookup_bn_locked (GstRegistry * registry,
197 const char *basename);
199 #define gst_registry_parent_class parent_class
200 G_DEFINE_TYPE (GstRegistry, gst_registry, GST_TYPE_OBJECT);
203 gst_registry_class_init (GstRegistryClass * klass)
205 GObjectClass *gobject_class;
207 gobject_class = (GObjectClass *) klass;
209 g_type_class_add_private (klass, sizeof (GstRegistryPrivate));
212 * GstRegistry::plugin-added:
213 * @registry: the registry that emitted the signal
214 * @plugin: the plugin that has been added
216 * Signals that a plugin has been added to the registry (possibly
217 * replacing a previously-added one by the same name)
219 gst_registry_signals[PLUGIN_ADDED] =
220 g_signal_new ("plugin-added", G_TYPE_FROM_CLASS (klass),
221 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRegistryClass, plugin_added), NULL,
222 NULL, gst_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
225 * GstRegistry::feature-added:
226 * @registry: the registry that emitted the signal
227 * @feature: the feature that has been added
229 * Signals that a feature has been added to the registry (possibly
230 * replacing a previously-added one by the same name)
232 gst_registry_signals[FEATURE_ADDED] =
233 g_signal_new ("feature-added", G_TYPE_FROM_CLASS (klass),
234 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRegistryClass, feature_added),
235 NULL, NULL, gst_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
237 gobject_class->finalize = gst_registry_finalize;
241 gst_registry_init (GstRegistry * registry)
243 registry->feature_hash = g_hash_table_new (g_str_hash, g_str_equal);
244 registry->basename_hash = g_hash_table_new (g_str_hash, g_str_equal);
246 G_TYPE_INSTANCE_GET_PRIVATE (registry, GST_TYPE_REGISTRY,
251 gst_registry_finalize (GObject * object)
253 GstRegistry *registry = GST_REGISTRY (object);
257 plugins = registry->plugins;
258 registry->plugins = NULL;
260 GST_DEBUG_OBJECT (registry, "registry finalize");
263 GstPlugin *plugin = p->data;
266 GST_LOG_OBJECT (registry, "removing plugin %s",
267 gst_plugin_get_name (plugin));
268 gst_object_unref (plugin);
272 g_list_free (plugins);
274 features = registry->features;
275 registry->features = NULL;
279 GstPluginFeature *feature = f->data;
282 GST_LOG_OBJECT (registry, "removing feature %p (%s)", feature,
283 GST_OBJECT_NAME (feature));
284 gst_object_unparent (GST_OBJECT_CAST (feature));
288 g_list_free (features);
290 g_hash_table_destroy (registry->feature_hash);
291 registry->feature_hash = NULL;
292 g_hash_table_destroy (registry->basename_hash);
293 registry->basename_hash = NULL;
295 if (registry->priv->element_factory_list) {
296 GST_DEBUG_OBJECT (registry, "Cleaning up cached element factory list");
297 gst_plugin_feature_list_free (registry->priv->element_factory_list);
300 if (registry->priv->typefind_factory_list) {
301 GST_DEBUG_OBJECT (registry, "Cleaning up cached typefind factory list");
302 gst_plugin_feature_list_free (registry->priv->typefind_factory_list);
305 G_OBJECT_CLASS (parent_class)->finalize (object);
309 * gst_registry_get_default:
311 * Retrieves the default registry. The caller does not own a reference on the
312 * registry, as it is alive as long as GStreamer is initialized.
314 * Returns: (transfer none): The default #GstRegistry.
317 gst_registry_get_default (void)
319 GstRegistry *registry;
321 g_static_mutex_lock (&_gst_registry_mutex);
322 if (G_UNLIKELY (!_gst_registry_default)) {
323 _gst_registry_default = g_object_newv (GST_TYPE_REGISTRY, 0, NULL);
324 gst_object_ref_sink (GST_OBJECT_CAST (_gst_registry_default));
326 registry = _gst_registry_default;
327 g_static_mutex_unlock (&_gst_registry_mutex);
333 * gst_registry_add_path:
334 * @registry: the registry to add the path to
335 * @path: the path to add to the registry
337 * Add the given path to the registry. The syntax of the
338 * path is specific to the registry. If the path has already been
342 gst_registry_add_path (GstRegistry * registry, const gchar * path)
344 g_return_if_fail (GST_IS_REGISTRY (registry));
345 g_return_if_fail (path != NULL);
347 if (strlen (path) == 0)
350 GST_OBJECT_LOCK (registry);
351 if (g_list_find_custom (registry->paths, path, (GCompareFunc) strcmp))
354 GST_INFO ("Adding plugin path: \"%s\"", path);
355 registry->paths = g_list_append (registry->paths, g_strdup (path));
356 GST_OBJECT_UNLOCK (registry);
362 GST_INFO ("Ignoring empty plugin path");
367 g_warning ("path %s already added to registry", path);
368 GST_OBJECT_UNLOCK (registry);
374 * gst_registry_get_path_list:
375 * @registry: the registry to get the pathlist of
377 * Get the list of paths for the given registry.
379 * Returns: (transfer container) (element-type char*): A #GList of paths as
380 * strings. g_list_free after use.
385 gst_registry_get_path_list (GstRegistry * registry)
389 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
391 GST_OBJECT_LOCK (registry);
392 /* We don't need to copy the strings, because they won't be deleted
393 * as long as the GstRegistry is around */
394 list = g_list_copy (registry->paths);
395 GST_OBJECT_UNLOCK (registry);
402 * gst_registry_add_plugin:
403 * @registry: the registry to add the plugin to
404 * @plugin: (transfer full): the plugin to add
406 * Add the plugin to the registry. The plugin-added signal will be emitted.
407 * This function will sink @plugin.
409 * Returns: TRUE on success.
414 gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin)
416 GstPlugin *existing_plugin;
418 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
419 g_return_val_if_fail (GST_IS_PLUGIN (plugin), FALSE);
421 GST_OBJECT_LOCK (registry);
422 if (G_LIKELY (plugin->basename)) {
423 /* we have a basename, see if we find the plugin */
425 gst_registry_lookup_bn_locked (registry, plugin->basename);
426 if (existing_plugin) {
427 GST_DEBUG_OBJECT (registry,
428 "Replacing existing plugin \"%s\" %p with new plugin %p for filename \"%s\"",
429 GST_STR_NULL (existing_plugin->filename), existing_plugin, plugin,
430 GST_STR_NULL (plugin->filename));
431 /* If the new plugin is blacklisted and the existing one isn't cached, do not
432 * accept if it's from a different location than the existing one */
433 if ((plugin->flags & GST_PLUGIN_FLAG_BLACKLISTED) &&
434 strcmp (plugin->filename, existing_plugin->filename)) {
435 GST_WARNING_OBJECT (registry,
436 "Not replacing plugin because new one (%s) is blacklisted but for a different location than existing one (%s)",
437 plugin->filename, existing_plugin->filename);
438 gst_object_unref (plugin);
439 GST_OBJECT_UNLOCK (registry);
442 registry->plugins = g_list_remove (registry->plugins, existing_plugin);
443 if (G_LIKELY (existing_plugin->basename))
444 g_hash_table_remove (registry->basename_hash,
445 existing_plugin->basename);
446 gst_object_unref (existing_plugin);
450 GST_DEBUG_OBJECT (registry, "adding plugin %p for filename \"%s\"",
451 plugin, GST_STR_NULL (plugin->filename));
453 registry->plugins = g_list_prepend (registry->plugins, plugin);
454 if (G_LIKELY (plugin->basename))
455 g_hash_table_replace (registry->basename_hash, plugin->basename, plugin);
457 gst_object_ref_sink (plugin);
458 GST_OBJECT_UNLOCK (registry);
460 GST_LOG_OBJECT (registry, "emitting plugin-added for filename \"%s\"",
461 GST_STR_NULL (plugin->filename));
462 g_signal_emit (registry, gst_registry_signals[PLUGIN_ADDED], 0, plugin);
468 gst_registry_remove_features_for_plugin_unlocked (GstRegistry * registry,
473 g_return_if_fail (GST_IS_REGISTRY (registry));
474 g_return_if_fail (GST_IS_PLUGIN (plugin));
476 /* Remove all features for this plugin */
477 f = registry->features;
479 GList *next = g_list_next (f);
480 GstPluginFeature *feature = f->data;
482 if (G_UNLIKELY (feature && feature->plugin == plugin)) {
483 GST_DEBUG_OBJECT (registry, "removing feature %p (%s) for plugin %p (%s)",
484 feature, gst_plugin_feature_get_name (feature), plugin,
487 registry->features = g_list_delete_link (registry->features, f);
488 g_hash_table_remove (registry->feature_hash, GST_OBJECT_NAME (feature));
489 gst_object_unparent (GST_OBJECT_CAST (feature));
493 registry->priv->cookie++;
497 * gst_registry_remove_plugin:
498 * @registry: the registry to remove the plugin from
499 * @plugin: (transfer none): the plugin to remove
501 * Remove the plugin from the registry.
506 gst_registry_remove_plugin (GstRegistry * registry, GstPlugin * plugin)
508 g_return_if_fail (GST_IS_REGISTRY (registry));
509 g_return_if_fail (GST_IS_PLUGIN (plugin));
511 GST_DEBUG_OBJECT (registry, "removing plugin %p (%s)",
512 plugin, gst_plugin_get_name (plugin));
514 GST_OBJECT_LOCK (registry);
515 registry->plugins = g_list_remove (registry->plugins, plugin);
516 if (G_LIKELY (plugin->basename))
517 g_hash_table_remove (registry->basename_hash, plugin->basename);
518 gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
519 GST_OBJECT_UNLOCK (registry);
520 gst_object_unref (plugin);
524 * gst_registry_add_feature:
525 * @registry: the registry to add the plugin to
526 * @feature: (transfer full): the feature to add
528 * Add the feature to the registry. The feature-added signal will be emitted.
529 * This function sinks @feature.
531 * Returns: TRUE on success.
536 gst_registry_add_feature (GstRegistry * registry, GstPluginFeature * feature)
538 GstPluginFeature *existing_feature;
540 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
541 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
542 g_return_val_if_fail (GST_OBJECT_NAME (feature) != NULL, FALSE);
543 g_return_val_if_fail (feature->plugin_name != NULL, FALSE);
545 GST_OBJECT_LOCK (registry);
546 existing_feature = gst_registry_lookup_feature_locked (registry,
547 GST_OBJECT_NAME (feature));
548 if (G_UNLIKELY (existing_feature)) {
549 GST_DEBUG_OBJECT (registry, "replacing existing feature %p (%s)",
550 existing_feature, GST_OBJECT_NAME (feature));
551 /* Remove the existing feature from the list now, before we insert the new
552 * one, but don't unref yet because the hash is still storing a reference to
554 registry->features = g_list_remove (registry->features, existing_feature);
557 GST_DEBUG_OBJECT (registry, "adding feature %p (%s)", feature,
558 GST_OBJECT_NAME (feature));
560 registry->features = g_list_prepend (registry->features, feature);
561 g_hash_table_replace (registry->feature_hash, GST_OBJECT_NAME (feature),
564 if (G_UNLIKELY (existing_feature)) {
565 /* We unref now. No need to remove the feature name from the hash table, it
566 * got replaced by the new feature */
567 gst_object_unparent (GST_OBJECT_CAST (existing_feature));
570 gst_object_set_parent (GST_OBJECT_CAST (feature), GST_OBJECT_CAST (registry));
572 registry->priv->cookie++;
573 GST_OBJECT_UNLOCK (registry);
575 GST_LOG_OBJECT (registry, "emitting feature-added for %s",
576 GST_OBJECT_NAME (feature));
577 g_signal_emit (registry, gst_registry_signals[FEATURE_ADDED], 0, feature);
583 * gst_registry_remove_feature:
584 * @registry: the registry to remove the feature from
585 * @feature: (transfer none): the feature to remove
587 * Remove the feature from the registry.
592 gst_registry_remove_feature (GstRegistry * registry, GstPluginFeature * feature)
594 g_return_if_fail (GST_IS_REGISTRY (registry));
595 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
597 GST_DEBUG_OBJECT (registry, "removing feature %p (%s)",
598 feature, gst_plugin_feature_get_name (feature));
600 GST_OBJECT_LOCK (registry);
601 registry->features = g_list_remove (registry->features, feature);
602 g_hash_table_remove (registry->feature_hash, GST_OBJECT_NAME (feature));
603 registry->priv->cookie++;
604 GST_OBJECT_UNLOCK (registry);
606 gst_object_unparent ((GstObject *) feature);
610 * gst_registry_plugin_filter:
611 * @registry: registry to query
612 * @filter: (scope call): the filter to use
613 * @first: only return first match
614 * @user_data: (closure): user data passed to the filter function
616 * Runs a filter against all plugins in the registry and returns a #GList with
617 * the results. If the first flag is set, only the first match is
618 * returned (as a list with a single object).
619 * Every plugin is reffed; use gst_plugin_list_free() after use, which
622 * Returns: (transfer full) (element-type Gst.Plugin): a #GList of #GstPlugin.
623 * Use gst_plugin_list_free() after usage.
628 gst_registry_plugin_filter (GstRegistry * registry,
629 GstPluginFilter filter, gboolean first, gpointer user_data)
633 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
635 GST_OBJECT_LOCK (registry);
639 for (walk = registry->plugins; walk != NULL; walk = walk->next) {
640 GstPlugin *plugin = walk->data;
642 if (filter == NULL || filter (plugin, user_data)) {
643 list = g_list_prepend (list, gst_object_ref (plugin));
650 GST_OBJECT_UNLOCK (registry);
655 #ifdef GST_DISABLE_DEPRECATED
662 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
663 GstTypeNameData * data)
665 g_assert (GST_IS_PLUGIN_FEATURE (feature));
667 return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
668 (data->name == NULL || !strcmp (data->name, GST_OBJECT_NAME (feature))));
672 /* returns TRUE if the list was changed
674 * Must be called with the object lock taken */
676 gst_registry_get_feature_list_or_create (GstRegistry * registry,
677 GList ** previous, guint32 * cookie, GType type)
679 gboolean res = FALSE;
680 GstRegistryPrivate *priv = registry->priv;
682 if (G_UNLIKELY (!*previous || priv->cookie != *cookie)) {
683 GstTypeNameData data;
687 gst_plugin_feature_list_free (*previous);
694 for (walk = registry->features; walk != NULL; walk = walk->next) {
695 GstPluginFeature *feature = walk->data;
697 if (gst_plugin_feature_type_name_filter (feature, &data)) {
698 *previous = g_list_prepend (*previous, gst_object_ref (feature));
702 *cookie = priv->cookie;
710 type_find_factory_rank_cmp (const GstPluginFeature * fac1,
711 const GstPluginFeature * fac2)
713 if (G_LIKELY (fac1->rank != fac2->rank))
714 return fac2->rank - fac1->rank;
716 /* to make the order in which things happen more deterministic,
717 * sort by name when the ranks are the same. */
718 return strcmp (GST_OBJECT_NAME (fac1), GST_OBJECT_NAME (fac2));
722 gst_registry_get_element_factory_list (GstRegistry * registry)
726 GST_OBJECT_LOCK (registry);
728 gst_registry_get_feature_list_or_create (registry,
729 ®istry->priv->element_factory_list, ®istry->priv->efl_cookie,
730 GST_TYPE_ELEMENT_FACTORY);
732 /* Return reffed copy */
733 list = gst_plugin_feature_list_copy (registry->priv->element_factory_list);
735 GST_OBJECT_UNLOCK (registry);
741 gst_registry_get_typefind_factory_list (GstRegistry * registry)
745 GST_OBJECT_LOCK (registry);
747 if (G_UNLIKELY (gst_registry_get_feature_list_or_create (registry,
748 ®istry->priv->typefind_factory_list,
749 ®istry->priv->tfl_cookie, GST_TYPE_TYPE_FIND_FACTORY)))
750 registry->priv->typefind_factory_list =
751 g_list_sort (registry->priv->typefind_factory_list,
752 (GCompareFunc) type_find_factory_rank_cmp);
754 /* Return reffed copy */
755 list = gst_plugin_feature_list_copy (registry->priv->typefind_factory_list);
757 GST_OBJECT_UNLOCK (registry);
763 * gst_registry_feature_filter:
764 * @registry: registry to query
765 * @filter: (scope call): the filter to use
766 * @first: only return first match
767 * @user_data: (closure): user data passed to the filter function
769 * Runs a filter against all features of the plugins in the registry
770 * and returns a GList with the results.
771 * If the first flag is set, only the first match is
772 * returned (as a list with a single object).
774 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
775 * #GstPluginFeature. Use gst_plugin_feature_list_free() after usage.
780 gst_registry_feature_filter (GstRegistry * registry,
781 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
785 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
787 GST_OBJECT_LOCK (registry);
791 for (walk = registry->features; walk != NULL; walk = walk->next) {
792 GstPluginFeature *feature = walk->data;
794 if (filter == NULL || filter (feature, user_data)) {
795 list = g_list_prepend (list, gst_object_ref (feature));
802 GST_OBJECT_UNLOCK (registry);
808 * gst_registry_find_plugin:
809 * @registry: the registry to search
810 * @name: the plugin name to find
812 * Find the plugin with the given name in the registry.
813 * The plugin will be reffed; caller is responsible for unreffing.
815 * Returns: (transfer full): the plugin with the given name or NULL if the
816 * plugin was not found. gst_object_unref() after usage.
821 gst_registry_find_plugin (GstRegistry * registry, const gchar * name)
824 GstPlugin *result = NULL;
826 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
827 g_return_val_if_fail (name != NULL, NULL);
829 walk = gst_registry_plugin_filter (registry,
830 (GstPluginFilter) gst_plugin_name_filter, TRUE, (gpointer) name);
832 result = GST_PLUGIN_CAST (walk->data);
834 gst_object_ref (result);
835 gst_plugin_list_free (walk);
842 * gst_registry_find_feature:
843 * @registry: the registry to search
844 * @name: the pluginfeature name to find
845 * @type: the pluginfeature type to find
847 * Find the pluginfeature with the given name and type in the registry.
849 * Returns: (transfer full): the pluginfeature with the given name and type
850 * or NULL if the plugin was not found. gst_object_unref() after usage.
855 gst_registry_find_feature (GstRegistry * registry, const gchar * name,
858 GstPluginFeature *feature = NULL;
860 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
861 g_return_val_if_fail (name != NULL, NULL);
862 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_PLUGIN_FEATURE), NULL);
864 feature = gst_registry_lookup_feature (registry, name);
865 if (feature && !g_type_is_a (G_TYPE_FROM_INSTANCE (feature), type)) {
866 gst_object_unref (feature);
874 * gst_registry_get_feature_list:
875 * @registry: a #GstRegistry
878 * Retrieves a #GList of #GstPluginFeature of @type.
880 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
881 * #GstPluginFeature of @type. Use gst_plugin_feature_list_free() after use
886 gst_registry_get_feature_list (GstRegistry * registry, GType type)
888 GstTypeNameData data;
890 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
891 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_PLUGIN_FEATURE), NULL);
894 if (type == GST_TYPE_ELEMENT_FACTORY)
895 return gst_registry_get_element_factory_list (registry);
896 else if (type == GST_TYPE_TYPE_FIND_FACTORY)
897 return gst_registry_get_typefind_factory_list (registry);
902 return gst_registry_feature_filter (registry,
903 (GstPluginFeatureFilter) gst_plugin_feature_type_name_filter,
908 * gst_registry_get_plugin_list:
909 * @registry: the registry to search
911 * Get a copy of all plugins registered in the given registry. The refcount
912 * of each element in the list in incremented.
914 * Returns: (transfer full) (element-type Gst.Plugin): a #GList of #GstPlugin.
915 * Use gst_plugin_list_free() after usage.
920 gst_registry_get_plugin_list (GstRegistry * registry)
925 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
927 GST_OBJECT_LOCK (registry);
928 list = g_list_copy (registry->plugins);
929 for (g = list; g; g = g->next) {
930 gst_object_ref (GST_PLUGIN_CAST (g->data));
932 GST_OBJECT_UNLOCK (registry);
937 static GstPluginFeature *
938 gst_registry_lookup_feature_locked (GstRegistry * registry, const char *name)
940 return g_hash_table_lookup (registry->feature_hash, name);
944 * gst_registry_lookup_feature:
945 * @registry: a #GstRegistry
946 * @name: a #GstPluginFeature name
948 * Find a #GstPluginFeature with @name in @registry.
950 * Returns: (transfer full): a #GstPluginFeature with its refcount incremented,
951 * use gst_object_unref() after usage.
956 gst_registry_lookup_feature (GstRegistry * registry, const char *name)
958 GstPluginFeature *feature;
960 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
961 g_return_val_if_fail (name != NULL, NULL);
963 GST_OBJECT_LOCK (registry);
964 feature = gst_registry_lookup_feature_locked (registry, name);
966 gst_object_ref (feature);
967 GST_OBJECT_UNLOCK (registry);
973 gst_registry_lookup_bn_locked (GstRegistry * registry, const char *basename)
975 return g_hash_table_lookup (registry->basename_hash, basename);
979 gst_registry_lookup_bn (GstRegistry * registry, const char *basename)
983 GST_OBJECT_LOCK (registry);
984 plugin = gst_registry_lookup_bn_locked (registry, basename);
986 gst_object_ref (plugin);
987 GST_OBJECT_UNLOCK (registry);
993 * gst_registry_lookup:
994 * @registry: the registry to look up in
995 * @filename: the name of the file to look up
997 * Look up a plugin in the given registry with the given filename.
998 * If found, plugin is reffed.
1000 * Returns: (transfer full): the #GstPlugin if found, or NULL if not.
1001 * gst_object_unref() after usage.
1004 gst_registry_lookup (GstRegistry * registry, const char *filename)
1009 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1010 g_return_val_if_fail (filename != NULL, NULL);
1012 basename = g_path_get_basename (filename);
1013 if (G_UNLIKELY (basename == NULL))
1016 plugin = gst_registry_lookup_bn (registry, basename);
1025 REGISTRY_SCAN_HELPER_NOT_STARTED = 0,
1026 REGISTRY_SCAN_HELPER_DISABLED,
1027 REGISTRY_SCAN_HELPER_RUNNING
1028 } GstRegistryScanHelperState;
1032 GstRegistry *registry;
1033 GstRegistryScanHelperState helper_state;
1034 GstPluginLoader *helper;
1036 } GstRegistryScanContext;
1039 init_scan_context (GstRegistryScanContext * context, GstRegistry * registry)
1043 context->registry = registry;
1045 /* see if forking is enabled and set up the scan helper state accordingly */
1046 do_fork = _gst_enable_registry_fork;
1048 const gchar *fork_env;
1050 /* forking enabled, see if it is disabled with an env var */
1051 if ((fork_env = g_getenv ("GST_REGISTRY_FORK"))) {
1052 /* fork enabled for any value different from "no" */
1053 do_fork = strcmp (fork_env, "no") != 0;
1058 context->helper_state = REGISTRY_SCAN_HELPER_NOT_STARTED;
1060 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1062 context->helper = NULL;
1063 context->changed = FALSE;
1067 clear_scan_context (GstRegistryScanContext * context)
1069 if (context->helper) {
1070 context->changed |= _priv_gst_plugin_loader_funcs.destroy (context->helper);
1071 context->helper = NULL;
1076 gst_registry_scan_plugin_file (GstRegistryScanContext * context,
1077 const gchar * filename, off_t file_size, time_t file_mtime)
1079 gboolean changed = FALSE;
1080 GstPlugin *newplugin = NULL;
1083 /* Disable external plugin loader on Windows until it is ported properly. */
1084 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1088 /* Have a plugin to load - see if the scan-helper needs starting */
1089 if (context->helper_state == REGISTRY_SCAN_HELPER_NOT_STARTED) {
1090 GST_DEBUG ("Starting plugin scanner for file %s", filename);
1091 context->helper = _priv_gst_plugin_loader_funcs.create (context->registry);
1092 if (context->helper != NULL)
1093 context->helper_state = REGISTRY_SCAN_HELPER_RUNNING;
1095 GST_WARNING ("Failed starting plugin scanner. Scanning in-process");
1096 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1100 if (context->helper_state == REGISTRY_SCAN_HELPER_RUNNING) {
1101 GST_DEBUG ("Using scan-helper to load plugin %s", filename);
1102 if (!_priv_gst_plugin_loader_funcs.load (context->helper,
1103 filename, file_size, file_mtime)) {
1104 g_warning ("External plugin loader failed. This most likely means that "
1105 "the plugin loader helper binary was not found or could not be run. "
1106 "%s", (g_getenv ("GST_PLUGIN_PATH") != NULL) ?
1107 "If you are running an uninstalled GStreamer setup, you might need "
1108 "to update your gst-uninstalled script so that the "
1109 "GST_PLUGIN_SCANNER environment variable gets set." : "");
1110 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1114 /* Check if the helper is disabled (or just got disabled above) */
1115 if (context->helper_state == REGISTRY_SCAN_HELPER_DISABLED) {
1116 /* Load plugin the old fashioned way... */
1118 /* We don't use a GError here because a failure to load some shared
1119 * objects as plugins is normal (particularly in the uninstalled case)
1121 newplugin = gst_plugin_load_file (filename, NULL);
1125 GST_DEBUG_OBJECT (context->registry, "marking new plugin %p as registered",
1127 newplugin->registered = TRUE;
1128 gst_object_unref (newplugin);
1132 if (!__registry_reuse_plugin_scanner) {
1133 clear_scan_context (context);
1134 context->helper_state = REGISTRY_SCAN_HELPER_NOT_STARTED;
1141 is_blacklisted_hidden_directory (const gchar * dirent)
1143 if (G_LIKELY (dirent[0] != '.'))
1146 /* skip the .debug directory, these contain elf files that are not
1147 * useful or worse, can crash dlopen () */
1148 if (strcmp (dirent, ".debug") == 0)
1151 /* can also skip .git and .deps dirs, those won't contain useful files.
1152 * This speeds up scanning a bit in uninstalled setups. */
1153 if (strcmp (dirent, ".git") == 0 || strcmp (dirent, ".deps") == 0)
1160 gst_registry_scan_path_level (GstRegistryScanContext * context,
1161 const gchar * path, int level)
1164 const gchar *dirent;
1167 gboolean changed = FALSE;
1169 dir = g_dir_open (path, 0, NULL);
1173 while ((dirent = g_dir_read_name (dir))) {
1174 GStatBuf file_status;
1176 filename = g_build_filename (path, dirent, NULL);
1177 if (g_stat (filename, &file_status) < 0) {
1178 /* Plugin will be removed from cache after the scan completes if it
1179 * is still marked 'cached' */
1184 if (file_status.st_mode & S_IFDIR) {
1185 if (G_UNLIKELY (is_blacklisted_hidden_directory (dirent))) {
1186 GST_TRACE_OBJECT (context->registry, "ignoring %s directory", dirent);
1190 /* FIXME 0.11: Don't recurse into directories, this behaviour
1191 * is inconsistent with other PATH environment variables
1194 GST_LOG_OBJECT (context->registry, "recursing into directory %s",
1196 changed |= gst_registry_scan_path_level (context, filename, level - 1);
1198 GST_LOG_OBJECT (context->registry, "not recursing into directory %s, "
1199 "recursion level too deep", filename);
1204 if (!(file_status.st_mode & S_IFREG)) {
1205 GST_TRACE_OBJECT (context->registry, "%s is not a regular file, ignoring",
1210 if (!g_str_has_suffix (dirent, G_MODULE_SUFFIX)
1211 #ifdef GST_EXTRA_MODULE_SUFFIX
1212 && !g_str_has_suffix (dirent, GST_EXTRA_MODULE_SUFFIX)
1215 GST_TRACE_OBJECT (context->registry,
1216 "extension is not recognized as module file, ignoring file %s",
1222 GST_LOG_OBJECT (context->registry, "file %s looks like a possible module",
1225 /* try to avoid unnecessary plugin-move pain */
1226 if (g_str_has_prefix (dirent, "libgstvalve") ||
1227 g_str_has_prefix (dirent, "libgstselector")) {
1228 GST_WARNING_OBJECT (context->registry, "ignoring old plugin %s which "
1229 "has been merged into the corelements plugin", filename);
1230 /* Plugin will be removed from cache after the scan completes if it
1231 * is still marked 'cached' */
1236 /* plug-ins are considered unique by basename; if the given name
1237 * was already seen by the registry, we ignore it */
1238 plugin = gst_registry_lookup_bn (context->registry, dirent);
1240 gboolean env_vars_changed, deps_changed = FALSE;
1242 if (plugin->registered) {
1243 GST_DEBUG_OBJECT (context->registry,
1244 "plugin already registered from path \"%s\"",
1245 GST_STR_NULL (plugin->filename));
1247 gst_object_unref (plugin);
1251 env_vars_changed = _priv_plugin_deps_env_vars_changed (plugin);
1253 /* If a file with a certain basename is seen on a different path,
1254 * update the plugin to ensure the registry cache will reflect up
1255 * to date information */
1257 if (plugin->file_mtime == file_status.st_mtime &&
1258 plugin->file_size == file_status.st_size && !env_vars_changed &&
1259 !(deps_changed = _priv_plugin_deps_files_changed (plugin)) &&
1260 !strcmp (plugin->filename, filename)) {
1261 GST_LOG_OBJECT (context->registry, "file %s cached", filename);
1262 plugin->flags &= ~GST_PLUGIN_FLAG_CACHED;
1263 GST_LOG_OBJECT (context->registry,
1264 "marking plugin %p as registered as %s", plugin, filename);
1265 plugin->registered = TRUE;
1267 GST_INFO_OBJECT (context->registry, "cached info for %s is stale",
1269 GST_DEBUG_OBJECT (context->registry, "mtime %" G_GINT64_FORMAT " != %"
1270 G_GINT64_FORMAT " or size %" G_GINT64_FORMAT " != %"
1271 G_GINT64_FORMAT " or external dependency env_vars changed: %d or"
1272 " external dependencies changed: %d or old path %s != new path %s",
1273 (gint64) plugin->file_mtime, (gint64) file_status.st_mtime,
1274 (gint64) plugin->file_size, (gint64) file_status.st_size,
1275 env_vars_changed, deps_changed, plugin->filename, filename);
1276 gst_registry_remove_plugin (context->registry, plugin);
1277 changed |= gst_registry_scan_plugin_file (context, filename,
1278 file_status.st_size, file_status.st_mtime);
1280 gst_object_unref (plugin);
1283 GST_DEBUG_OBJECT (context->registry, "file %s not yet in registry",
1285 changed |= gst_registry_scan_plugin_file (context, filename,
1286 file_status.st_size, file_status.st_mtime);
1298 gst_registry_scan_path_internal (GstRegistryScanContext * context,
1303 GST_DEBUG_OBJECT (context->registry, "scanning path %s", path);
1304 changed = gst_registry_scan_path_level (context, path, 10);
1306 GST_DEBUG_OBJECT (context->registry, "registry changed in path %s: %d", path,
1312 * gst_registry_scan_path:
1313 * @registry: the registry to add found plugins to
1314 * @path: the path to scan
1316 * Scan the given path for plugins to add to the registry. The syntax of the
1317 * path is specific to the registry.
1319 * Returns: %TRUE if registry changed
1322 gst_registry_scan_path (GstRegistry * registry, const gchar * path)
1324 GstRegistryScanContext context;
1327 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
1328 g_return_val_if_fail (path != NULL, FALSE);
1330 init_scan_context (&context, registry);
1332 result = gst_registry_scan_path_internal (&context, path);
1334 clear_scan_context (&context);
1335 result |= context.changed;
1341 _gst_plugin_feature_filter_plugin_name (GstPluginFeature * feature,
1344 return (strcmp (feature->plugin_name, (gchar *) user_data) == 0);
1348 * gst_registry_get_feature_list_by_plugin:
1349 * @registry: a #GstRegistry.
1350 * @name: a plugin name.
1352 * Retrieves a #GList of features of the plugin with name @name.
1354 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
1355 * #GstPluginFeature. Use gst_plugin_feature_list_free() after usage.
1358 gst_registry_get_feature_list_by_plugin (GstRegistry * registry,
1361 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1362 g_return_val_if_fail (name != NULL, NULL);
1364 return gst_registry_feature_filter (registry,
1365 _gst_plugin_feature_filter_plugin_name, FALSE, (gpointer) name);
1368 /* Unref and delete the default registry */
1370 _priv_gst_registry_cleanup (void)
1372 GstRegistry *registry;
1374 g_static_mutex_lock (&_gst_registry_mutex);
1375 if ((registry = _gst_registry_default) != NULL) {
1376 _gst_registry_default = NULL;
1378 g_static_mutex_unlock (&_gst_registry_mutex);
1380 /* unref outside of the lock because we can. */
1382 gst_object_unref (registry);
1386 * gst_default_registry_check_feature_version:
1387 * @feature_name: the name of the feature (e.g. "oggdemux")
1388 * @min_major: the minimum major version number
1389 * @min_minor: the minimum minor version number
1390 * @min_micro: the minimum micro version number
1392 * Checks whether a plugin feature by the given name exists in the
1393 * default registry and whether its version is at least the
1396 * Returns: #TRUE if the feature could be found and the version is
1397 * the same as the required version or newer, and #FALSE otherwise.
1400 gst_default_registry_check_feature_version (const gchar * feature_name,
1401 guint min_major, guint min_minor, guint min_micro)
1403 GstPluginFeature *feature;
1404 GstRegistry *registry;
1405 gboolean ret = FALSE;
1407 g_return_val_if_fail (feature_name != NULL, FALSE);
1409 GST_DEBUG ("Looking up plugin feature '%s'", feature_name);
1411 registry = gst_registry_get_default ();
1412 feature = gst_registry_lookup_feature (registry, feature_name);
1414 ret = gst_plugin_feature_check_version (feature, min_major, min_minor,
1416 gst_object_unref (feature);
1418 GST_DEBUG ("Could not find plugin feature '%s'", feature_name);
1425 load_plugin_func (gpointer data, gpointer user_data)
1428 const gchar *filename;
1431 filename = (const gchar *) data;
1432 GST_DEBUG ("Pre-loading plugin %s", filename);
1434 plugin = gst_plugin_load_file (filename, &err);
1437 GST_INFO ("Loaded plugin: \"%s\"", filename);
1439 gst_default_registry_add_plugin (plugin);
1442 /* Report error to user, and free error */
1443 GST_ERROR ("Failed to load plugin: %s", err->message);
1446 GST_WARNING ("Failed to load plugin: \"%s\"", filename);
1451 #ifndef GST_DISABLE_REGISTRY
1452 /* Unref all plugins marked 'cached', to clear old plugins that no
1453 * longer exist. Returns TRUE if any plugins were removed */
1455 gst_registry_remove_cache_plugins (GstRegistry * registry)
1460 gboolean changed = FALSE;
1462 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
1464 GST_OBJECT_LOCK (registry);
1466 GST_DEBUG_OBJECT (registry, "removing cached plugins");
1467 g = registry->plugins;
1471 if (plugin->flags & GST_PLUGIN_FLAG_CACHED) {
1472 GST_DEBUG_OBJECT (registry, "removing cached plugin \"%s\"",
1473 GST_STR_NULL (plugin->filename));
1474 registry->plugins = g_list_delete_link (registry->plugins, g);
1475 if (G_LIKELY (plugin->basename))
1476 g_hash_table_remove (registry->basename_hash, plugin->basename);
1477 gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
1478 gst_object_unref (plugin);
1484 GST_OBJECT_UNLOCK (registry);
1491 REGISTRY_SCAN_AND_UPDATE_FAILURE = 0,
1492 REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED,
1493 REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED
1494 } GstRegistryScanAndUpdateResult;
1497 * scan_and_update_registry:
1498 * @default_registry: the #GstRegistry
1499 * @registry_file: registry filename
1500 * @write_changes: write registry if it has changed?
1502 * Scans for registry changes and eventually updates the registry cache.
1504 * Return: %REGISTRY_SCAN_AND_UPDATE_FAILURE if the registry could not scanned
1505 * or updated, %REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED if the
1506 * registry is clean and %REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED if
1507 * it has been updated and the cache needs to be re-read.
1509 static GstRegistryScanAndUpdateResult
1510 scan_and_update_registry (GstRegistry * default_registry,
1511 const gchar * registry_file, gboolean write_changes, GError ** error)
1513 const gchar *plugin_path;
1514 gboolean changed = FALSE;
1516 GstRegistryScanContext context;
1518 GST_INFO ("Validating plugins from registry cache: %s", registry_file);
1520 init_scan_context (&context, default_registry);
1522 /* It sounds tempting to just compare the mtime of directories with the mtime
1523 * of the registry cache, but it does not work. It would not catch updated
1524 * plugins, which might bring more or less features.
1527 /* scan paths specified via --gst-plugin-path */
1528 GST_DEBUG ("scanning paths added via --gst-plugin-path");
1529 for (l = _priv_gst_plugin_paths; l != NULL; l = l->next) {
1530 GST_INFO ("Scanning plugin path: \"%s\"", (gchar *) l->data);
1531 changed |= gst_registry_scan_path_internal (&context, (gchar *) l->data);
1533 /* keep plugin_paths around in case a re-scan is forced later on */
1535 /* GST_PLUGIN_PATH specifies a list of directories to scan for
1536 * additional plugins. These take precedence over the system plugins */
1537 plugin_path = g_getenv ("GST_PLUGIN_PATH");
1542 GST_DEBUG ("GST_PLUGIN_PATH set to %s", plugin_path);
1543 list = g_strsplit (plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
1544 for (i = 0; list[i]; i++) {
1545 changed |= gst_registry_scan_path_internal (&context, list[i]);
1549 GST_DEBUG ("GST_PLUGIN_PATH not set");
1552 /* GST_PLUGIN_SYSTEM_PATH specifies a list of plugins that are always
1553 * loaded by default. If not set, this defaults to the system-installed
1554 * path, and the plugins installed in the user's home directory */
1555 plugin_path = g_getenv ("GST_PLUGIN_SYSTEM_PATH");
1556 if (plugin_path == NULL) {
1559 GST_DEBUG ("GST_PLUGIN_SYSTEM_PATH not set");
1561 /* plugins in the user's home directory take precedence over
1562 * system-installed ones */
1563 home_plugins = g_build_filename (g_get_user_data_dir (),
1564 "gstreamer-" GST_MAJORMINOR, "plugins", NULL);
1566 GST_DEBUG ("scanning home plugins %s", home_plugins);
1567 changed |= gst_registry_scan_path_internal (&context, home_plugins);
1568 g_free (home_plugins);
1570 /* add the main (installed) library path */
1571 GST_DEBUG ("scanning main plugins %s", PLUGINDIR);
1572 changed |= gst_registry_scan_path_internal (&context, PLUGINDIR);
1580 g_win32_get_package_installation_directory_of_module
1581 (_priv_gst_dll_handle);
1583 dir = g_build_filename (base_dir, "lib", "gstreamer-0.10", NULL);
1584 GST_DEBUG ("scanning DLL dir %s", dir);
1586 changed |= gst_registry_scan_path_internal (&context, dir);
1596 GST_DEBUG ("GST_PLUGIN_SYSTEM_PATH set to %s", plugin_path);
1597 list = g_strsplit (plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
1598 for (i = 0; list[i]; i++) {
1599 changed |= gst_registry_scan_path_internal (&context, list[i]);
1604 clear_scan_context (&context);
1605 changed |= context.changed;
1607 /* Remove cached plugins so stale info is cleared. */
1608 changed |= gst_registry_remove_cache_plugins (default_registry);
1611 GST_INFO ("Registry cache has not changed");
1612 return REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED;
1615 if (!write_changes) {
1616 GST_INFO ("Registry cache changed, but writing is disabled. Not writing.");
1617 return REGISTRY_SCAN_AND_UPDATE_FAILURE;
1620 GST_INFO ("Registry cache changed. Writing new registry cache");
1621 if (!priv_gst_registry_binary_write_cache (default_registry, registry_file)) {
1622 g_set_error (error, GST_CORE_ERROR, GST_CORE_ERROR_FAILED,
1623 _("Error writing registry cache to %s: %s"),
1624 registry_file, g_strerror (errno));
1625 return REGISTRY_SCAN_AND_UPDATE_FAILURE;
1628 GST_INFO ("Registry cache written successfully");
1629 return REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED;
1633 ensure_current_registry (GError ** error)
1635 gchar *registry_file;
1636 GstRegistry *default_registry;
1637 gboolean ret = TRUE;
1638 gboolean do_update = TRUE;
1639 gboolean have_cache = TRUE;
1641 default_registry = gst_registry_get_default ();
1642 registry_file = g_strdup (g_getenv ("GST_REGISTRY"));
1643 if (registry_file == NULL) {
1644 registry_file = g_build_filename (g_get_user_cache_dir (),
1645 "gstreamer-" GST_MAJORMINOR, "registry." HOST_CPU ".bin", NULL);
1648 if (!_gst_disable_registry_cache) {
1649 GST_INFO ("reading registry cache: %s", registry_file);
1650 have_cache = priv_gst_registry_binary_read_cache (default_registry,
1652 /* Only ever read the registry cache once, then disable it for
1653 * subsequent updates during the program lifetime */
1654 _gst_disable_registry_cache = TRUE;
1658 do_update = !_priv_gst_disable_registry_update;
1660 const gchar *update_env;
1662 if ((update_env = g_getenv ("GST_REGISTRY_UPDATE"))) {
1663 /* do update for any value different from "no" */
1664 do_update = (strcmp (update_env, "no") != 0);
1670 const gchar *reuse_env;
1672 if ((reuse_env = g_getenv ("GST_REGISTRY_REUSE_PLUGIN_SCANNER"))) {
1673 /* do reuse for any value different from "no" */
1674 __registry_reuse_plugin_scanner = (strcmp (reuse_env, "no") != 0);
1676 /* now check registry */
1677 GST_DEBUG ("Updating registry cache");
1678 scan_and_update_registry (default_registry, registry_file, TRUE, error);
1680 GST_DEBUG ("Not updating registry cache (disabled)");
1683 g_free (registry_file);
1684 GST_INFO ("registry reading and updating done, result = %d", ret);
1688 #endif /* GST_DISABLE_REGISTRY */
1691 * gst_registry_fork_is_enabled:
1693 * By default GStreamer will perform scanning and rebuilding of the
1694 * registry file using a helper child process.
1696 * Applications might want to disable this behaviour with the
1697 * gst_registry_fork_set_enabled() function, in which case new plugins
1698 * are scanned (and loaded) into the application process.
1700 * Returns: %TRUE if GStreamer will use the child helper process when
1701 * rebuilding the registry.
1706 gst_registry_fork_is_enabled (void)
1708 return _gst_enable_registry_fork;
1712 * gst_registry_fork_set_enabled:
1713 * @enabled: whether rebuilding the registry can use a temporary child helper process.
1715 * Applications might want to disable/enable spawning of a child helper process
1716 * when rebuilding the registry. See gst_registry_fork_is_enabled() for more
1722 gst_registry_fork_set_enabled (gboolean enabled)
1724 _gst_enable_registry_fork = enabled;
1728 * gst_update_registry:
1730 * Forces GStreamer to re-scan its plugin paths and update the default
1733 * Applications will almost never need to call this function, it is only
1734 * useful if the application knows new plugins have been installed (or old
1735 * ones removed) since the start of the application (or, to be precise, the
1736 * first call to gst_init()) and the application wants to make use of any
1737 * newly-installed plugins without restarting the application.
1739 * Applications should assume that the registry update is neither atomic nor
1740 * thread-safe and should therefore not have any dynamic pipelines running
1741 * (including the playbin and decodebin elements) and should also not create
1742 * any elements or access the GStreamer registry while the update is in
1745 * Note that this function may block for a significant amount of time.
1747 * Returns: %TRUE if the registry has been updated successfully (does not
1748 * imply that there were changes), otherwise %FALSE.
1753 gst_update_registry (void)
1757 #ifndef GST_DISABLE_REGISTRY
1760 res = ensure_current_registry (&err);
1762 GST_WARNING ("registry update failed: %s", err->message);
1765 GST_LOG ("registry update succeeded");
1769 GST_WARNING ("registry update failed: %s", "registry disabled");
1771 #endif /* GST_DISABLE_REGISTRY */
1773 if (_priv_gst_preload_plugins) {
1774 GST_DEBUG ("Preloading indicated plugins...");
1775 g_slist_foreach (_priv_gst_preload_plugins, load_plugin_func, NULL);
1782 * gst_registry_get_feature_list_cookie:
1783 * @registry: the registry
1785 * Returns the registrys feature list cookie. This changes
1786 * every time a feature is added or removed from the registry.
1788 * Returns: the feature list cookie.
1793 gst_registry_get_feature_list_cookie (GstRegistry * registry)
1795 g_return_val_if_fail (GST_IS_REGISTRY (registry), 0);
1797 return registry->priv->cookie;