2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2005 David A. Schleef <ds@schleef.org>
6 * gstregistry.c: handle registry
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
27 * @short_description: Abstract base class for management of #GstPlugin objects
28 * @see_also: #GstPlugin, #GstPluginFeature
30 * One registry holds the metadata of a set of plugins.
32 * <emphasis role="bold">Design:</emphasis>
34 * The #GstRegistry object is a list of plugins and some functions for dealing
35 * with them. Each #GstPlugin is matched 1-1 with a file on disk, and may or may
36 * not be loaded at a given time.
38 * The primary source, at all times, of plugin information is each plugin file
39 * itself. Thus, if an application wants information about a particular plugin,
40 * or wants to search for a feature that satisfies given criteria, the primary
41 * means of doing so is to load every plugin and look at the resulting
42 * information that is gathered in the default registry. Clearly, this is a time
43 * consuming process, so we cache information in the registry file. The format
44 * and location of the cache file is internal to gstreamer.
46 * On startup, plugins are searched for in the plugin search path. The following
47 * locations are checked in this order:
49 * * location from --gst-plugin-path commandline option.
50 * * the GST_PLUGIN_PATH environment variable.
51 * * the GST_PLUGIN_SYSTEM_PATH environment variable.
52 * * default locations (if GST_PLUGIN_SYSTEM_PATH is not set).
53 * Those default locations are:
54 * `$XDG_DATA_HOME/gstreamer-$GST_API_VERSION/plugins/`
55 * and `$prefix/libs/gstreamer-$GST_API_VERSION/`.
56 * [$XDG_DATA_HOME](http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) defaults to
57 * `$HOME/.local/share`.
59 * The registry cache file is loaded from
60 * `$XDG_CACHE_HOME/gstreamer-$GST_API_VERSION/registry-$ARCH.bin`
61 * (where $XDG_CACHE_HOME defaults to `$HOME/.cache`) or the file listed in the `GST_REGISTRY`
62 * env var. One reason to change the registry location is for testing.
64 * For each plugin that is found in the plugin search path, there could be 3
65 * possibilities for cached information:
67 * * the cache may not contain information about a given file.
68 * * the cache may have stale information.
69 * * the cache may have current information.
71 * In the first two cases, the plugin is loaded and the cache updated. In
72 * addition to these cases, the cache may have entries for plugins that are not
73 * relevant to the current process. These are marked as not available to the
74 * current process. If the cache is updated for whatever reason, it is marked
77 * A dirty cache is written out at the end of initialization. Each entry is
78 * checked to make sure the information is minimally valid. If not, the entry is
81 * ## Implementation notes:
83 * The "cache" and "registry" are different concepts and can represent
84 * different sets of plugins. For various reasons, at init time, the cache is
85 * stored in the default registry, and plugins not relevant to the current
86 * process are marked with the %GST_PLUGIN_FLAG_CACHED bit. These plugins are
87 * removed at the end of initialization.
93 #include "gstconfig.h"
94 #include "gst_private.h"
96 #include <sys/types.h>
106 #include <glib/gstdio.h>
109 #include "gsterror.h"
110 #include "gstregistry.h"
111 #include "gstdeviceproviderfactory.h"
113 #include "gstpluginloader.h"
115 #include <glib/gi18n-lib.h>
118 #include "glib-compat-private.h"
122 extern HMODULE _priv_gst_dll_handle;
128 /* Use a toolchain-dependent suffix on Windows */
131 # define GST_REGISTRY_FILE_SUFFIX TARGET_CPU "-msvc"
133 # define GST_REGISTRY_FILE_SUFFIX TARGET_CPU "-mingw"
136 # define GST_REGISTRY_FILE_SUFFIX TARGET_CPU
138 #define GST_REGISTRY_FILE_NAME "registry." GST_REGISTRY_FILE_SUFFIX ".bin"
141 #define GST_CAT_DEFAULT GST_CAT_REGISTRY
143 struct _GstRegistryPrivate
155 /* hash to speedup _lookup_feature_locked() */
156 GHashTable *feature_hash;
157 /* hash to speedup _lookup */
158 GHashTable *basename_hash;
160 /* updated whenever the feature list changes */
162 /* speedup for searching features */
163 GList *element_factory_list;
165 GList *typefind_factory_list;
167 GList *device_provider_factory_list;
171 /* the one instance of the default registry and the mutex protecting the
173 static GMutex _gst_registry_mutex;
174 static GstRegistry *_gst_registry_default = NULL;
177 #define DEFAULT_FORK TRUE
179 /* control the behaviour of registry rebuild */
180 static gboolean _gst_enable_registry_fork = DEFAULT_FORK;
181 /* List of plugins that need preloading/reloading after scanning registry */
182 extern GSList *_priv_gst_preload_plugins;
184 #ifndef GST_DISABLE_REGISTRY
185 /* Set to TRUE to disable registry, behaves similar to GST_DISABLE_REGISTRY */
186 gboolean _priv_gst_disable_registry = FALSE;
187 /*set to TRUE when registry needn't to be updated */
188 gboolean _priv_gst_disable_registry_update = FALSE;
189 extern GList *_priv_gst_plugin_paths;
191 /* Set to TRUE when the registry cache should be disabled */
192 gboolean _gst_disable_registry_cache = FALSE;
194 static gboolean __registry_reuse_plugin_scanner = TRUE;
197 /* Element signals and args */
205 static void gst_registry_finalize (GObject * object);
207 static guint gst_registry_signals[LAST_SIGNAL] = { 0 };
209 static GstPluginFeature *gst_registry_lookup_feature_locked (GstRegistry *
210 registry, const char *name);
211 static GstPlugin *gst_registry_lookup_bn_locked (GstRegistry * registry,
212 const char *basename);
214 #define gst_registry_parent_class parent_class
215 G_DEFINE_TYPE_WITH_PRIVATE (GstRegistry, gst_registry, GST_TYPE_OBJECT);
218 gst_registry_class_init (GstRegistryClass * klass)
220 GObjectClass *gobject_class;
222 gobject_class = (GObjectClass *) klass;
225 * GstRegistry::plugin-added:
226 * @registry: the registry that emitted the signal
227 * @plugin: the plugin that has been added
229 * Signals that a plugin has been added to the registry (possibly
230 * replacing a previously-added one by the same name)
232 gst_registry_signals[PLUGIN_ADDED] =
233 g_signal_new ("plugin-added", G_TYPE_FROM_CLASS (klass),
234 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_PLUGIN);
237 * GstRegistry::feature-added:
238 * @registry: the registry that emitted the signal
239 * @feature: the feature that has been added
241 * Signals that a feature has been added to the registry (possibly
242 * replacing a previously-added one by the same name)
244 gst_registry_signals[FEATURE_ADDED] =
245 g_signal_new ("feature-added", G_TYPE_FROM_CLASS (klass),
246 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL,
247 G_TYPE_NONE, 1, GST_TYPE_PLUGIN_FEATURE);
249 gobject_class->finalize = gst_registry_finalize;
253 gst_registry_init (GstRegistry * registry)
255 registry->priv = gst_registry_get_instance_private (registry);
256 registry->priv->feature_hash = g_hash_table_new (g_str_hash, g_str_equal);
257 registry->priv->basename_hash = g_hash_table_new (g_str_hash, g_str_equal);
261 gst_registry_finalize (GObject * object)
263 GstRegistry *registry = GST_REGISTRY (object);
267 plugins = registry->priv->plugins;
268 registry->priv->plugins = NULL;
269 registry->priv->n_plugins = 0;
271 GST_DEBUG_OBJECT (registry, "registry finalize");
274 GstPlugin *plugin = p->data;
277 GST_LOG_OBJECT (registry, "removing plugin %s",
278 gst_plugin_get_name (plugin));
279 gst_object_unref (plugin);
283 g_list_free (plugins);
285 features = registry->priv->features;
286 registry->priv->features = NULL;
290 GstPluginFeature *feature = f->data;
293 GST_LOG_OBJECT (registry, "removing feature %p (%s)", feature,
294 GST_OBJECT_NAME (feature));
295 gst_object_unparent (GST_OBJECT_CAST (feature));
299 g_list_free (features);
301 g_hash_table_destroy (registry->priv->feature_hash);
302 registry->priv->feature_hash = NULL;
303 g_hash_table_destroy (registry->priv->basename_hash);
304 registry->priv->basename_hash = NULL;
306 if (registry->priv->element_factory_list) {
307 GST_DEBUG_OBJECT (registry, "Cleaning up cached element factory list");
308 gst_plugin_feature_list_free (registry->priv->element_factory_list);
311 if (registry->priv->typefind_factory_list) {
312 GST_DEBUG_OBJECT (registry, "Cleaning up cached typefind factory list");
313 gst_plugin_feature_list_free (registry->priv->typefind_factory_list);
316 if (registry->priv->device_provider_factory_list) {
317 GST_DEBUG_OBJECT (registry,
318 "Cleaning up cached device provider factory list");
319 gst_plugin_feature_list_free (registry->priv->device_provider_factory_list);
322 G_OBJECT_CLASS (parent_class)->finalize (object);
328 * Retrieves the singleton plugin registry. The caller does not own a
329 * reference on the registry, as it is alive as long as GStreamer is
332 * Returns: (transfer none): the #GstRegistry.
335 gst_registry_get (void)
337 GstRegistry *registry;
339 g_mutex_lock (&_gst_registry_mutex);
340 if (G_UNLIKELY (!_gst_registry_default)) {
341 _gst_registry_default = g_object_new (GST_TYPE_REGISTRY, NULL);
342 gst_object_ref_sink (GST_OBJECT_CAST (_gst_registry_default));
344 registry = _gst_registry_default;
345 g_mutex_unlock (&_gst_registry_mutex);
352 * gst_registry_add_path:
353 * @registry: the registry to add the path to
354 * @path: the path to add to the registry
356 * Add the given path to the registry. The syntax of the
357 * path is specific to the registry. If the path has already been
361 gst_registry_add_path (GstRegistry * registry, const gchar * path)
363 g_return_if_fail (GST_IS_REGISTRY (registry));
364 g_return_if_fail (path != NULL);
366 if (strlen (path) == 0)
369 GST_OBJECT_LOCK (registry);
370 if (g_list_find_custom (registry->priv->paths, path, (GCompareFunc) strcmp))
373 GST_INFO ("Adding plugin path: \"%s\"", path);
374 registry->priv->paths =
375 g_list_append (registry->priv->paths, g_strdup (path));
376 GST_OBJECT_UNLOCK (registry);
382 GST_INFO ("Ignoring empty plugin path");
387 g_warning ("path %s already added to registry", path);
388 GST_OBJECT_UNLOCK (registry);
394 * gst_registry_get_path_list:
395 * @registry: the registry to get the pathlist of
397 * Get the list of paths for the given registry.
399 * Returns: (transfer container) (element-type filename): A #GList of
400 * paths as strings. g_list_free after use.
405 gst_registry_get_path_list (GstRegistry * registry)
409 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
411 GST_OBJECT_LOCK (registry);
412 /* We don't need to copy the strings, because they won't be deleted
413 * as long as the GstRegistry is around */
414 list = g_list_copy (registry->priv->paths);
415 GST_OBJECT_UNLOCK (registry);
422 * gst_registry_add_plugin:
423 * @registry: the registry to add the plugin to
424 * @plugin: (transfer floating): the plugin to add
426 * Add the plugin to the registry. The plugin-added signal will be emitted.
428 * @plugin's reference count will be incremented, and any floating
429 * reference will be removed (see gst_object_ref_sink())
431 * Returns: %TRUE on success.
436 gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin)
438 GstPlugin *existing_plugin;
440 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
441 g_return_val_if_fail (GST_IS_PLUGIN (plugin), FALSE);
443 GST_OBJECT_LOCK (registry);
444 if (G_LIKELY (plugin->basename)) {
445 /* we have a basename, see if we find the plugin */
447 gst_registry_lookup_bn_locked (registry, plugin->basename);
448 if (existing_plugin) {
449 GST_DEBUG_OBJECT (registry,
450 "Replacing existing plugin \"%s\" %p with new plugin %p for filename \"%s\"",
451 GST_STR_NULL (existing_plugin->filename), existing_plugin, plugin,
452 GST_STR_NULL (plugin->filename));
453 /* If the new plugin is blacklisted and the existing one isn't cached, do not
454 * accept if it's from a different location than the existing one */
455 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED) &&
456 strcmp (plugin->filename, existing_plugin->filename)) {
457 GST_WARNING_OBJECT (registry,
458 "Not replacing plugin because new one (%s) is blacklisted but for a different location than existing one (%s)",
459 plugin->filename, existing_plugin->filename);
460 /* Keep reference counting consistent */
461 gst_object_ref_sink (plugin);
462 gst_object_unref (plugin);
463 GST_OBJECT_UNLOCK (registry);
466 registry->priv->plugins =
467 g_list_remove (registry->priv->plugins, existing_plugin);
468 --registry->priv->n_plugins;
469 if (G_LIKELY (existing_plugin->basename))
470 g_hash_table_remove (registry->priv->basename_hash,
471 existing_plugin->basename);
472 gst_object_unref (existing_plugin);
476 GST_DEBUG_OBJECT (registry, "adding plugin %p for filename \"%s\"",
477 plugin, GST_STR_NULL (plugin->filename));
479 registry->priv->plugins = g_list_prepend (registry->priv->plugins, plugin);
480 ++registry->priv->n_plugins;
482 if (G_LIKELY (plugin->basename))
483 g_hash_table_replace (registry->priv->basename_hash, plugin->basename,
486 gst_object_ref_sink (plugin);
487 GST_OBJECT_UNLOCK (registry);
489 GST_LOG_OBJECT (registry, "emitting plugin-added for filename \"%s\"",
490 GST_STR_NULL (plugin->filename));
491 g_signal_emit (registry, gst_registry_signals[PLUGIN_ADDED], 0, plugin);
497 gst_registry_remove_features_for_plugin_unlocked (GstRegistry * registry,
502 g_return_if_fail (GST_IS_REGISTRY (registry));
503 g_return_if_fail (GST_IS_PLUGIN (plugin));
505 /* Remove all features for this plugin */
506 f = registry->priv->features;
508 GList *next = g_list_next (f);
509 GstPluginFeature *feature = f->data;
511 if (G_UNLIKELY (feature && feature->plugin == plugin)) {
512 GST_DEBUG_OBJECT (registry, "removing feature %p (%s) for plugin %p (%s)",
513 feature, gst_plugin_feature_get_name (feature), plugin,
516 registry->priv->features =
517 g_list_delete_link (registry->priv->features, f);
518 g_hash_table_remove (registry->priv->feature_hash,
519 GST_OBJECT_NAME (feature));
520 gst_object_unparent (GST_OBJECT_CAST (feature));
524 registry->priv->cookie++;
528 * gst_registry_remove_plugin:
529 * @registry: the registry to remove the plugin from
530 * @plugin: (transfer none): the plugin to remove
532 * Remove the plugin from the registry.
537 gst_registry_remove_plugin (GstRegistry * registry, GstPlugin * plugin)
539 g_return_if_fail (GST_IS_REGISTRY (registry));
540 g_return_if_fail (GST_IS_PLUGIN (plugin));
542 GST_DEBUG_OBJECT (registry, "removing plugin %p (%s)",
543 plugin, gst_plugin_get_name (plugin));
545 GST_OBJECT_LOCK (registry);
546 registry->priv->plugins = g_list_remove (registry->priv->plugins, plugin);
547 --registry->priv->n_plugins;
548 if (G_LIKELY (plugin->basename))
549 g_hash_table_remove (registry->priv->basename_hash, plugin->basename);
550 gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
551 GST_OBJECT_UNLOCK (registry);
552 gst_object_unref (plugin);
556 * gst_registry_add_feature:
557 * @registry: the registry to add the plugin to
558 * @feature: (transfer floating): the feature to add
560 * Add the feature to the registry. The feature-added signal will be emitted.
562 * @feature's reference count will be incremented, and any floating
563 * reference will be removed (see gst_object_ref_sink())
565 * Returns: %TRUE on success.
570 gst_registry_add_feature (GstRegistry * registry, GstPluginFeature * feature)
572 GstPluginFeature *existing_feature;
574 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
575 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
576 g_return_val_if_fail (GST_OBJECT_NAME (feature) != NULL, FALSE);
577 g_return_val_if_fail (feature->plugin_name != NULL, FALSE);
579 GST_OBJECT_LOCK (registry);
580 existing_feature = gst_registry_lookup_feature_locked (registry,
581 GST_OBJECT_NAME (feature));
582 if (G_UNLIKELY (existing_feature)) {
583 GST_DEBUG_OBJECT (registry, "replacing existing feature %p (%s)",
584 existing_feature, GST_OBJECT_NAME (feature));
585 /* Remove the existing feature from the list now, before we insert the new
586 * one, but don't unref yet because the hash is still storing a reference to
588 registry->priv->features =
589 g_list_remove (registry->priv->features, existing_feature);
592 GST_DEBUG_OBJECT (registry, "adding feature %p (%s)", feature,
593 GST_OBJECT_NAME (feature));
595 registry->priv->features = g_list_prepend (registry->priv->features, feature);
596 g_hash_table_replace (registry->priv->feature_hash, GST_OBJECT_NAME (feature),
599 if (G_UNLIKELY (existing_feature)) {
600 /* We unref now. No need to remove the feature name from the hash table, it
601 * got replaced by the new feature */
602 gst_object_unparent (GST_OBJECT_CAST (existing_feature));
605 gst_object_set_parent (GST_OBJECT_CAST (feature), GST_OBJECT_CAST (registry));
607 registry->priv->cookie++;
608 GST_OBJECT_UNLOCK (registry);
610 GST_LOG_OBJECT (registry, "emitting feature-added for %s",
611 GST_OBJECT_NAME (feature));
612 g_signal_emit (registry, gst_registry_signals[FEATURE_ADDED], 0, feature);
618 * gst_registry_remove_feature:
619 * @registry: the registry to remove the feature from
620 * @feature: (transfer none): the feature to remove
622 * Remove the feature from the registry.
627 gst_registry_remove_feature (GstRegistry * registry, GstPluginFeature * feature)
629 g_return_if_fail (GST_IS_REGISTRY (registry));
630 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
632 GST_DEBUG_OBJECT (registry, "removing feature %p (%s)",
633 feature, gst_plugin_feature_get_name (feature));
635 GST_OBJECT_LOCK (registry);
636 registry->priv->features = g_list_remove (registry->priv->features, feature);
637 g_hash_table_remove (registry->priv->feature_hash, GST_OBJECT_NAME (feature));
638 registry->priv->cookie++;
639 GST_OBJECT_UNLOCK (registry);
641 gst_object_unparent ((GstObject *) feature);
645 * gst_registry_plugin_filter:
646 * @registry: registry to query
647 * @filter: (scope call): the filter to use
648 * @first: only return first match
649 * @user_data: (closure): user data passed to the filter function
651 * Runs a filter against all plugins in the registry and returns a #GList with
652 * the results. If the first flag is set, only the first match is
653 * returned (as a list with a single object).
654 * Every plugin is reffed; use gst_plugin_list_free() after use, which
657 * Returns: (transfer full) (element-type Gst.Plugin): a #GList of #GstPlugin.
658 * Use gst_plugin_list_free() after usage.
663 gst_registry_plugin_filter (GstRegistry * registry,
664 GstPluginFilter filter, gboolean first, gpointer user_data)
667 GList *walk, *list = NULL;
670 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
672 GST_OBJECT_LOCK (registry);
673 n_plugins = registry->priv->n_plugins;
674 plugins = g_newa (GstPlugin *, n_plugins + 1);
675 for (walk = registry->priv->plugins, i = 0; walk != NULL; walk = walk->next)
676 plugins[i++] = gst_object_ref (walk->data);
677 GST_OBJECT_UNLOCK (registry);
679 for (i = 0; i < n_plugins; ++i) {
680 if (filter == NULL || filter (plugins[i], user_data)) {
681 list = g_list_prepend (list, gst_object_ref (plugins[i]));
688 for (i = 0; i < n_plugins; ++i)
689 gst_object_unref (plugins[i]);
701 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
702 GstTypeNameData * data)
704 g_assert (GST_IS_PLUGIN_FEATURE (feature));
706 return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
707 (data->name == NULL || !strcmp (data->name, GST_OBJECT_NAME (feature))));
710 /* returns TRUE if the list was changed
712 * Must be called with the object lock taken */
714 gst_registry_get_feature_list_or_create (GstRegistry * registry,
715 GList ** previous, guint32 * cookie, GType type)
717 gboolean res = FALSE;
718 GstRegistryPrivate *priv = registry->priv;
720 if (G_UNLIKELY (!*previous || priv->cookie != *cookie)) {
721 GstTypeNameData data;
725 gst_plugin_feature_list_free (*previous);
732 for (walk = registry->priv->features; walk != NULL; walk = walk->next) {
733 GstPluginFeature *feature = walk->data;
735 if (gst_plugin_feature_type_name_filter (feature, &data)) {
736 *previous = g_list_prepend (*previous, gst_object_ref (feature));
740 *cookie = priv->cookie;
748 type_find_factory_rank_cmp (const GstPluginFeature * fac1,
749 const GstPluginFeature * fac2)
751 if (G_LIKELY (fac1->rank != fac2->rank))
752 return fac2->rank - fac1->rank;
754 /* to make the order in which things happen more deterministic,
755 * sort by name when the ranks are the same. */
756 return strcmp (GST_OBJECT_NAME (fac1), GST_OBJECT_NAME (fac2));
760 gst_registry_get_element_factory_list (GstRegistry * registry)
764 GST_OBJECT_LOCK (registry);
766 gst_registry_get_feature_list_or_create (registry,
767 ®istry->priv->element_factory_list, ®istry->priv->efl_cookie,
768 GST_TYPE_ELEMENT_FACTORY);
770 /* Return reffed copy */
771 list = gst_plugin_feature_list_copy (registry->priv->element_factory_list);
773 GST_OBJECT_UNLOCK (registry);
779 gst_registry_get_typefind_factory_list (GstRegistry * registry)
783 GST_OBJECT_LOCK (registry);
785 if (G_UNLIKELY (gst_registry_get_feature_list_or_create (registry,
786 ®istry->priv->typefind_factory_list,
787 ®istry->priv->tfl_cookie, GST_TYPE_TYPE_FIND_FACTORY)))
788 registry->priv->typefind_factory_list =
789 g_list_sort (registry->priv->typefind_factory_list,
790 (GCompareFunc) type_find_factory_rank_cmp);
792 /* Return reffed copy */
793 list = gst_plugin_feature_list_copy (registry->priv->typefind_factory_list);
795 GST_OBJECT_UNLOCK (registry);
802 gst_registry_get_device_provider_factory_list (GstRegistry * registry)
806 GST_OBJECT_LOCK (registry);
808 gst_registry_get_feature_list_or_create (registry,
809 ®istry->priv->device_provider_factory_list,
810 ®istry->priv->dmfl_cookie, GST_TYPE_DEVICE_PROVIDER_FACTORY);
812 /* Return reffed copy */
814 gst_plugin_feature_list_copy (registry->
815 priv->device_provider_factory_list);
817 GST_OBJECT_UNLOCK (registry);
823 * gst_registry_feature_filter:
824 * @registry: registry to query
825 * @filter: (scope call): the filter to use
826 * @first: only return first match
827 * @user_data: (closure): user data passed to the filter function
829 * Runs a filter against all features of the plugins in the registry
830 * and returns a GList with the results.
831 * If the first flag is set, only the first match is
832 * returned (as a list with a single object).
834 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
835 * #GstPluginFeature. Use gst_plugin_feature_list_free() after usage.
840 gst_registry_feature_filter (GstRegistry * registry,
841 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
843 GstPluginFeature **features;
844 GList *walk, *list = NULL;
847 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
849 GST_OBJECT_LOCK (registry);
850 n_features = g_hash_table_size (registry->priv->feature_hash);
851 features = g_newa (GstPluginFeature *, n_features + 1);
852 for (walk = registry->priv->features, i = 0; walk != NULL; walk = walk->next)
853 features[i++] = gst_object_ref (walk->data);
854 GST_OBJECT_UNLOCK (registry);
856 for (i = 0; i < n_features; ++i) {
857 if (filter == NULL || filter (features[i], user_data)) {
858 list = g_list_prepend (list, gst_object_ref (features[i]));
865 for (i = 0; i < n_features; ++i)
866 gst_object_unref (features[i]);
872 gst_registry_plugin_name_filter (GstPlugin * plugin, const gchar * name)
874 return (plugin->desc.name && !strcmp (plugin->desc.name, name));
878 * gst_registry_find_plugin:
879 * @registry: the registry to search
880 * @name: the plugin name to find
882 * Find the plugin with the given name in the registry.
883 * The plugin will be reffed; caller is responsible for unreffing.
885 * Returns: (transfer full) (nullable): the plugin with the given name
886 * or %NULL if the plugin was not found. gst_object_unref() after
892 gst_registry_find_plugin (GstRegistry * registry, const gchar * name)
895 GstPlugin *result = NULL;
897 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
898 g_return_val_if_fail (name != NULL, NULL);
900 walk = gst_registry_plugin_filter (registry,
901 (GstPluginFilter) gst_registry_plugin_name_filter, TRUE, (gpointer) name);
903 result = GST_PLUGIN_CAST (walk->data);
905 gst_object_ref (result);
906 gst_plugin_list_free (walk);
913 * gst_registry_find_feature:
914 * @registry: the registry to search
915 * @name: the pluginfeature name to find
916 * @type: the pluginfeature type to find
918 * Find the pluginfeature with the given name and type in the registry.
920 * Returns: (transfer full) (nullable): the pluginfeature with the
921 * given name and type or %NULL if the plugin was not
922 * found. gst_object_unref() after usage.
927 gst_registry_find_feature (GstRegistry * registry, const gchar * name,
930 GstPluginFeature *feature = NULL;
932 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
933 g_return_val_if_fail (name != NULL, NULL);
934 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_PLUGIN_FEATURE), NULL);
936 feature = gst_registry_lookup_feature (registry, name);
937 if (feature && !g_type_is_a (G_TYPE_FROM_INSTANCE (feature), type)) {
938 gst_object_unref (feature);
946 * gst_registry_get_feature_list:
947 * @registry: a #GstRegistry
950 * Retrieves a #GList of #GstPluginFeature of @type.
952 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
953 * #GstPluginFeature of @type. Use gst_plugin_feature_list_free() after use
958 gst_registry_get_feature_list (GstRegistry * registry, GType type)
960 GstTypeNameData data;
962 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
963 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_PLUGIN_FEATURE), NULL);
966 if (type == GST_TYPE_ELEMENT_FACTORY)
967 return gst_registry_get_element_factory_list (registry);
968 else if (type == GST_TYPE_TYPE_FIND_FACTORY)
969 return gst_registry_get_typefind_factory_list (registry);
970 else if (type == GST_TYPE_DEVICE_PROVIDER_FACTORY)
971 return gst_registry_get_device_provider_factory_list (registry);
976 return gst_registry_feature_filter (registry,
977 (GstPluginFeatureFilter) gst_plugin_feature_type_name_filter,
982 * gst_registry_get_plugin_list:
983 * @registry: the registry to search
985 * Get a copy of all plugins registered in the given registry. The refcount
986 * of each element in the list in incremented.
988 * Returns: (transfer full) (element-type Gst.Plugin): a #GList of #GstPlugin.
989 * Use gst_plugin_list_free() after usage.
994 gst_registry_get_plugin_list (GstRegistry * registry)
999 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1001 GST_OBJECT_LOCK (registry);
1002 list = g_list_copy (registry->priv->plugins);
1003 for (g = list; g; g = g->next) {
1004 gst_object_ref (GST_PLUGIN_CAST (g->data));
1006 GST_OBJECT_UNLOCK (registry);
1011 static GstPluginFeature *
1012 gst_registry_lookup_feature_locked (GstRegistry * registry, const char *name)
1014 return g_hash_table_lookup (registry->priv->feature_hash, name);
1018 * gst_registry_lookup_feature:
1019 * @registry: a #GstRegistry
1020 * @name: a #GstPluginFeature name
1022 * Find a #GstPluginFeature with @name in @registry.
1024 * Returns: (transfer full) (nullable): a #GstPluginFeature with its refcount incremented,
1025 * use gst_object_unref() after usage.
1030 gst_registry_lookup_feature (GstRegistry * registry, const char *name)
1032 GstPluginFeature *feature;
1034 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1035 g_return_val_if_fail (name != NULL, NULL);
1037 GST_OBJECT_LOCK (registry);
1038 feature = gst_registry_lookup_feature_locked (registry, name);
1040 gst_object_ref (feature);
1041 GST_OBJECT_UNLOCK (registry);
1047 gst_registry_lookup_bn_locked (GstRegistry * registry, const char *basename)
1049 return g_hash_table_lookup (registry->priv->basename_hash, basename);
1053 gst_registry_lookup_bn (GstRegistry * registry, const char *basename)
1057 GST_OBJECT_LOCK (registry);
1058 plugin = gst_registry_lookup_bn_locked (registry, basename);
1060 gst_object_ref (plugin);
1061 GST_OBJECT_UNLOCK (registry);
1067 * gst_registry_lookup:
1068 * @registry: the registry to look up in
1069 * @filename: the name of the file to look up
1071 * Look up a plugin in the given registry with the given filename.
1072 * If found, plugin is reffed.
1074 * Returns: (transfer full) (nullable): the #GstPlugin if found, or
1075 * %NULL if not. gst_object_unref() after usage.
1078 gst_registry_lookup (GstRegistry * registry, const char *filename)
1083 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1084 g_return_val_if_fail (filename != NULL, NULL);
1086 basename = g_path_get_basename (filename);
1087 if (G_UNLIKELY (basename == NULL))
1090 plugin = gst_registry_lookup_bn (registry, basename);
1099 REGISTRY_SCAN_HELPER_NOT_STARTED = 0,
1100 REGISTRY_SCAN_HELPER_DISABLED,
1101 REGISTRY_SCAN_HELPER_RUNNING
1102 } GstRegistryScanHelperState;
1106 GstRegistry *registry;
1107 GstRegistryScanHelperState helper_state;
1108 GstPluginLoader *helper;
1110 } GstRegistryScanContext;
1113 init_scan_context (GstRegistryScanContext * context, GstRegistry * registry)
1117 context->registry = registry;
1119 /* see if forking is enabled and set up the scan helper state accordingly */
1120 do_fork = _gst_enable_registry_fork;
1122 const gchar *fork_env;
1124 /* forking enabled, see if it is disabled with an env var */
1125 if ((fork_env = g_getenv ("GST_REGISTRY_FORK"))) {
1126 /* fork enabled for any value different from "no" */
1127 do_fork = strcmp (fork_env, "no") != 0;
1132 context->helper_state = REGISTRY_SCAN_HELPER_NOT_STARTED;
1134 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1136 context->helper = NULL;
1137 context->changed = FALSE;
1141 clear_scan_context (GstRegistryScanContext * context)
1143 if (context->helper) {
1144 context->changed |= _priv_gst_plugin_loader_funcs.destroy (context->helper);
1145 context->helper = NULL;
1150 gst_registry_scan_plugin_file (GstRegistryScanContext * context,
1151 const gchar * filename, off_t file_size, time_t file_mtime)
1153 gboolean changed = FALSE;
1154 GstPlugin *newplugin = NULL;
1157 /* Disable external plugin loader on Windows until it is ported properly. */
1158 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1162 /* Have a plugin to load - see if the scan-helper needs starting */
1163 if (context->helper_state == REGISTRY_SCAN_HELPER_NOT_STARTED) {
1164 GST_DEBUG ("Starting plugin scanner for file %s", filename);
1165 context->helper = _priv_gst_plugin_loader_funcs.create (context->registry);
1166 if (context->helper != NULL)
1167 context->helper_state = REGISTRY_SCAN_HELPER_RUNNING;
1169 GST_WARNING ("Failed starting plugin scanner. Scanning in-process");
1170 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1174 if (context->helper_state == REGISTRY_SCAN_HELPER_RUNNING) {
1175 GST_DEBUG ("Using scan-helper to load plugin %s", filename);
1176 if (!_priv_gst_plugin_loader_funcs.load (context->helper,
1177 filename, file_size, file_mtime)) {
1178 g_warning ("External plugin loader failed. This most likely means that "
1179 "the plugin loader helper binary was not found or could not be run. "
1180 "You might need to set the GST_PLUGIN_SCANNER environment variable "
1181 "if your setup is unusual. This should normally not be required "
1183 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1187 /* Check if the helper is disabled (or just got disabled above) */
1188 if (context->helper_state == REGISTRY_SCAN_HELPER_DISABLED) {
1189 /* Load plugin the old fashioned way... */
1191 /* We don't use a GError here because a failure to load some shared
1192 * objects as plugins is normal (particularly in the development environment case)
1194 newplugin = _priv_gst_plugin_load_file_for_registry (filename,
1195 context->registry, NULL);
1199 GST_DEBUG_OBJECT (context->registry, "marking new plugin %p as registered",
1201 newplugin->registered = TRUE;
1202 gst_object_unref (newplugin);
1205 #ifndef GST_DISABLE_REGISTRY
1206 if (!__registry_reuse_plugin_scanner) {
1207 clear_scan_context (context);
1208 context->helper_state = REGISTRY_SCAN_HELPER_NOT_STARTED;
1216 skip_directory (const gchar * parent_path, const gchar * dirent)
1218 const gchar *target;
1220 /* hotdoc private folder can contain many files and it slows down
1221 * the discovery for nothing */
1222 if (g_str_has_prefix (dirent, "hotdoc-private-"))
1225 /* Rust build dirs which may contain artefacts we should skip, can be
1226 * /target/{debug,release} or /target/{arch}/{debug,release} */
1227 target = strstr (parent_path, "/target/");
1229 /* On Windows both forward and backward slashes may be used */
1232 target = strstr (parent_path, "\\target\\");
1235 if (target != NULL) {
1236 if (g_str_has_suffix (target + 7, "/debug")
1238 || g_str_has_suffix (target + 7, "\\debug")
1239 || g_str_has_suffix (target + 7, "\\release")
1241 || g_str_has_suffix (target + 7, "/release")) {
1242 if (dirent[0] == '.'
1243 || strcmp (dirent, "build") == 0
1244 || strcmp (dirent, "deps") == 0
1245 || strcmp (dirent, "incremental") == 0) {
1251 if (G_LIKELY (dirent[0] != '.'))
1254 /* skip the .debug directory, these contain elf files that are not
1255 * useful or worse, can crash dlopen () */
1256 if (strcmp (dirent, ".debug") == 0)
1259 /* can also skip .git and .deps dirs, those won't contain useful files.
1260 * This speeds up scanning a bit in development environment setups. */
1261 if (strcmp (dirent, ".git") == 0 || strcmp (dirent, ".deps") == 0)
1268 gst_registry_scan_path_level (GstRegistryScanContext * context,
1269 const gchar * path, int level)
1272 const gchar *dirent;
1275 gboolean changed = FALSE;
1277 dir = g_dir_open (path, 0, NULL);
1281 while ((dirent = g_dir_read_name (dir))) {
1282 GStatBuf file_status;
1284 filename = g_build_filename (path, dirent, NULL);
1285 if (g_stat (filename, &file_status) < 0) {
1286 /* Plugin will be removed from cache after the scan completes if it
1287 * is still marked 'cached' */
1292 if (file_status.st_mode & S_IFDIR) {
1293 if (G_UNLIKELY (skip_directory (path, dirent))) {
1294 GST_TRACE_OBJECT (context->registry, "ignoring %s directory", dirent);
1298 /* FIXME 2.0: Don't recurse into directories, this behaviour
1299 * is inconsistent with other PATH environment variables
1302 GST_LOG_OBJECT (context->registry, "recursing into directory %s",
1304 changed |= gst_registry_scan_path_level (context, filename, level - 1);
1306 GST_LOG_OBJECT (context->registry, "not recursing into directory %s, "
1307 "recursion level too deep", filename);
1312 if (!(file_status.st_mode & S_IFREG)) {
1313 GST_TRACE_OBJECT (context->registry, "%s is not a regular file, ignoring",
1318 if (!g_str_has_suffix (dirent, "." G_MODULE_SUFFIX)
1319 #ifdef GST_EXTRA_MODULE_SUFFIX
1320 && !g_str_has_suffix (dirent, GST_EXTRA_MODULE_SUFFIX)
1323 GST_TRACE_OBJECT (context->registry,
1324 "extension is not recognized as module file, ignoring file %s",
1330 GST_LOG_OBJECT (context->registry, "file %s looks like a possible module",
1333 /* try to avoid unnecessary plugin-move pain */
1334 if (g_str_has_prefix (dirent, "libgstvalve") ||
1335 g_str_has_prefix (dirent, "libgstselector")) {
1336 GST_WARNING_OBJECT (context->registry, "ignoring old plugin %s which "
1337 "has been merged into the corelements plugin", filename);
1338 /* Plugin will be removed from cache after the scan completes if it
1339 * is still marked 'cached' */
1344 /* plug-ins are considered unique by basename; if the given name
1345 * was already seen by the registry, we ignore it */
1346 plugin = gst_registry_lookup_bn (context->registry, dirent);
1348 gboolean env_vars_changed, deps_changed = FALSE;
1350 if (plugin->registered) {
1351 GST_DEBUG_OBJECT (context->registry,
1352 "plugin already registered from path \"%s\"",
1353 GST_STR_NULL (plugin->filename));
1355 gst_object_unref (plugin);
1359 env_vars_changed = _priv_plugin_deps_env_vars_changed (plugin);
1361 /* If a file with a certain basename is seen on a different path,
1362 * update the plugin to ensure the registry cache will reflect up
1363 * to date information */
1365 if (plugin->file_mtime == file_status.st_mtime &&
1366 plugin->file_size == file_status.st_size && !env_vars_changed &&
1367 !(deps_changed = _priv_plugin_deps_files_changed (plugin)) &&
1368 !strcmp (plugin->filename, filename)) {
1369 GST_LOG_OBJECT (context->registry, "file %s cached", filename);
1370 GST_OBJECT_FLAG_UNSET (plugin, GST_PLUGIN_FLAG_CACHED);
1371 GST_LOG_OBJECT (context->registry,
1372 "marking plugin %p as registered as %s", plugin, filename);
1373 plugin->registered = TRUE;
1375 GST_INFO_OBJECT (context->registry, "cached info for %s is stale",
1377 GST_DEBUG_OBJECT (context->registry, "mtime %" G_GINT64_FORMAT " != %"
1378 G_GINT64_FORMAT " or size %" G_GINT64_FORMAT " != %"
1379 G_GINT64_FORMAT " or external dependency env_vars changed: %d or"
1380 " external dependencies changed: %d or old path %s != new path %s",
1381 (gint64) plugin->file_mtime, (gint64) file_status.st_mtime,
1382 (gint64) plugin->file_size, (gint64) file_status.st_size,
1383 env_vars_changed, deps_changed, plugin->filename, filename);
1384 gst_registry_remove_plugin (context->registry, plugin);
1385 changed |= gst_registry_scan_plugin_file (context, filename,
1386 file_status.st_size, file_status.st_mtime);
1388 gst_object_unref (plugin);
1391 GST_DEBUG_OBJECT (context->registry, "file %s not yet in registry",
1393 changed |= gst_registry_scan_plugin_file (context, filename,
1394 file_status.st_size, file_status.st_mtime);
1406 gst_registry_scan_path_internal (GstRegistryScanContext * context,
1411 GST_DEBUG_OBJECT (context->registry, "scanning path %s", path);
1412 changed = gst_registry_scan_path_level (context, path, 10);
1414 GST_DEBUG_OBJECT (context->registry, "registry changed in path %s: %d", path,
1420 * gst_registry_scan_path:
1421 * @registry: the registry to add found plugins to
1422 * @path: (type filename): the path to scan
1424 * Scan the given path for plugins to add to the registry. The syntax of the
1425 * path is specific to the registry.
1427 * Returns: %TRUE if registry changed
1430 gst_registry_scan_path (GstRegistry * registry, const gchar * path)
1432 GstRegistryScanContext context;
1435 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
1436 g_return_val_if_fail (path != NULL, FALSE);
1438 init_scan_context (&context, registry);
1440 result = gst_registry_scan_path_internal (&context, path);
1442 clear_scan_context (&context);
1443 result |= context.changed;
1449 _gst_plugin_feature_filter_plugin_name (GstPluginFeature * feature,
1452 return (strcmp (feature->plugin_name, (gchar *) user_data) == 0);
1456 * gst_registry_get_feature_list_by_plugin:
1457 * @registry: a #GstRegistry.
1458 * @name: a plugin name.
1460 * Retrieves a #GList of features of the plugin with name @name.
1462 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
1463 * #GstPluginFeature. Use gst_plugin_feature_list_free() after usage.
1466 gst_registry_get_feature_list_by_plugin (GstRegistry * registry,
1469 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1470 g_return_val_if_fail (name != NULL, NULL);
1472 return gst_registry_feature_filter (registry,
1473 _gst_plugin_feature_filter_plugin_name, FALSE, (gpointer) name);
1476 /* Private function for getting plugin features directly */
1478 _priv_plugin_get_features (GstRegistry * registry, GstPlugin * plugin)
1483 GST_OBJECT_LOCK (registry);
1484 for (walk = registry->priv->features; walk; walk = walk->next) {
1485 GstPluginFeature *feat = (GstPluginFeature *) walk->data;
1486 if (feat->plugin == plugin)
1487 res = g_list_prepend (res, gst_object_ref (feat));
1489 GST_OBJECT_UNLOCK (registry);
1494 /* Unref and delete the default registry */
1496 _priv_gst_registry_cleanup (void)
1498 GstRegistry *registry;
1500 g_mutex_lock (&_gst_registry_mutex);
1501 if ((registry = _gst_registry_default) != NULL) {
1502 _gst_registry_default = NULL;
1504 g_mutex_unlock (&_gst_registry_mutex);
1506 /* unref outside of the lock because we can. */
1508 gst_object_unref (registry);
1512 * gst_registry_check_feature_version:
1513 * @registry: a #GstRegistry
1514 * @feature_name: the name of the feature (e.g. "oggdemux")
1515 * @min_major: the minimum major version number
1516 * @min_minor: the minimum minor version number
1517 * @min_micro: the minimum micro version number
1519 * Checks whether a plugin feature by the given name exists in
1520 * @registry and whether its version is at least the
1523 * Returns: %TRUE if the feature could be found and the version is
1524 * the same as the required version or newer, and %FALSE otherwise.
1527 gst_registry_check_feature_version (GstRegistry * registry,
1528 const gchar * feature_name, guint min_major, guint min_minor,
1531 GstPluginFeature *feature;
1532 gboolean ret = FALSE;
1534 g_return_val_if_fail (feature_name != NULL, FALSE);
1536 GST_DEBUG ("Looking up plugin feature '%s'", feature_name);
1538 feature = gst_registry_lookup_feature (registry, feature_name);
1540 ret = gst_plugin_feature_check_version (feature, min_major, min_minor,
1542 gst_object_unref (feature);
1544 GST_DEBUG ("Could not find plugin feature '%s'", feature_name);
1551 load_plugin_func (gpointer data, gpointer user_data)
1554 const gchar *filename;
1557 filename = (const gchar *) data;
1558 GST_DEBUG ("Pre-loading plugin %s", filename);
1560 plugin = gst_plugin_load_file (filename, &err);
1563 GST_INFO ("Loaded plugin: \"%s\"", filename);
1565 gst_registry_add_plugin (gst_registry_get (), plugin);
1568 /* Report error to user, and free error */
1569 GST_ERROR ("Failed to load plugin: %s", err->message);
1572 GST_WARNING ("Failed to load plugin: \"%s\"", filename);
1578 priv_gst_get_relocated_libgstreamer (void)
1586 GST_DEBUG ("attempting to retrieve libgstreamer-1.0 location using "
1587 "Win32-specific method");
1590 g_win32_get_package_installation_directory_of_module
1591 (_priv_gst_dll_handle);
1595 dir = g_build_filename (base_dir, GST_PLUGIN_SUBDIR, NULL);
1596 GST_DEBUG ("using DLL dir %s", dir);
1600 #elif defined(HAVE_DLADDR)
1604 GST_DEBUG ("attempting to retrieve libgstreamer-1.0 location using "
1607 if (dladdr (&gst_init, &info)) {
1608 GST_LOG ("dli_fname: %s", info.dli_fname);
1610 if (!info.dli_fname) {
1614 dir = g_path_get_dirname (info.dli_fname);
1616 GST_LOG ("dladdr() failed");
1621 #warning "Unsupported platform for retrieving the current location of a shared library."
1622 #warning "Relocatable builds will not work."
1623 GST_WARNING ("Don't know how to retrieve the location of the shared "
1624 "library libgstreamer-" GST_API_VERSION);
1630 #ifndef GST_DISABLE_REGISTRY
1631 /* Unref all plugins marked 'cached', to clear old plugins that no
1632 * longer exist. Returns %TRUE if any plugins were removed */
1634 gst_registry_remove_cache_plugins (GstRegistry * registry)
1639 gboolean changed = FALSE;
1641 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
1643 GST_OBJECT_LOCK (registry);
1645 GST_DEBUG_OBJECT (registry, "removing cached plugins");
1646 g = registry->priv->plugins;
1650 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_CACHED)) {
1651 GST_DEBUG_OBJECT (registry, "removing cached plugin \"%s\"",
1652 GST_STR_NULL (plugin->filename));
1653 registry->priv->plugins = g_list_delete_link (registry->priv->plugins, g);
1654 --registry->priv->n_plugins;
1655 if (G_LIKELY (plugin->basename))
1656 g_hash_table_remove (registry->priv->basename_hash, plugin->basename);
1657 gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
1658 gst_object_unref (plugin);
1664 GST_OBJECT_UNLOCK (registry);
1671 REGISTRY_SCAN_AND_UPDATE_FAILURE = 0,
1672 REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED,
1673 REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED
1674 } GstRegistryScanAndUpdateResult;
1677 * scan_and_update_registry:
1678 * @default_registry: the #GstRegistry
1679 * @registry_file: registry filename
1680 * @write_changes: write registry if it has changed?
1682 * Scans for registry changes and eventually updates the registry cache.
1684 * Return: %REGISTRY_SCAN_AND_UPDATE_FAILURE if the registry could not scanned
1685 * or updated, %REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED if the
1686 * registry is clean and %REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED if
1687 * it has been updated and the cache needs to be re-read.
1689 static GstRegistryScanAndUpdateResult
1690 scan_and_update_registry (GstRegistry * default_registry,
1691 const gchar * registry_file, gboolean write_changes, GError ** error)
1693 const gchar *plugin_path;
1694 gboolean changed = FALSE;
1696 GstRegistryScanContext context;
1698 GST_INFO ("Validating plugins from registry cache: %s", registry_file);
1700 init_scan_context (&context, default_registry);
1702 /* It sounds tempting to just compare the mtime of directories with the mtime
1703 * of the registry cache, but it does not work. It would not catch updated
1704 * plugins, which might bring more or less features.
1707 /* scan paths specified via --gst-plugin-path */
1708 GST_DEBUG ("scanning paths added via --gst-plugin-path");
1709 for (l = _priv_gst_plugin_paths; l != NULL; l = l->next) {
1710 GST_INFO ("Scanning plugin path: \"%s\"", (gchar *) l->data);
1711 changed |= gst_registry_scan_path_internal (&context, (gchar *) l->data);
1713 /* keep plugin_paths around in case a re-scan is forced later on */
1715 /* GST_PLUGIN_PATH specifies a list of directories to scan for
1716 * additional plugins. These take precedence over the system plugins */
1717 plugin_path = g_getenv ("GST_PLUGIN_PATH_1_0");
1718 if (plugin_path == NULL)
1719 plugin_path = g_getenv ("GST_PLUGIN_PATH");
1724 GST_DEBUG ("GST_PLUGIN_PATH set to %s", plugin_path);
1725 list = g_strsplit (plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
1726 for (i = 0; list[i]; i++) {
1727 changed |= gst_registry_scan_path_internal (&context, list[i]);
1731 GST_DEBUG ("GST_PLUGIN_PATH not set");
1734 /* GST_PLUGIN_SYSTEM_PATH specifies a list of plugins that are always
1735 * loaded by default. If not set, this defaults to the system-installed
1736 * path, and the plugins installed in the user's home directory */
1737 plugin_path = g_getenv ("GST_PLUGIN_SYSTEM_PATH_1_0");
1738 if (plugin_path == NULL)
1739 plugin_path = g_getenv ("GST_PLUGIN_SYSTEM_PATH");
1740 if (plugin_path == NULL) {
1741 char *home_plugins, *relocated_libgstreamer, *system_plugindir;
1743 GST_DEBUG ("GST_PLUGIN_SYSTEM_PATH not set");
1745 /* plugins in the user's home directory take precedence over
1746 * system-installed ones */
1747 home_plugins = g_build_filename (g_get_user_data_dir (),
1748 "gstreamer-" GST_API_VERSION, "plugins", NULL);
1750 GST_DEBUG ("scanning home plugins %s", home_plugins);
1751 changed |= gst_registry_scan_path_internal (&context, home_plugins);
1752 g_free (home_plugins);
1754 /* add the main (installed) library path */
1756 relocated_libgstreamer = priv_gst_get_relocated_libgstreamer ();
1757 if (relocated_libgstreamer) {
1758 GST_DEBUG ("found libgstreamer-" GST_API_VERSION " library "
1759 "at %s", relocated_libgstreamer);
1760 system_plugindir = g_build_filename (relocated_libgstreamer,
1761 "gstreamer-" GST_API_VERSION, NULL);
1763 system_plugindir = g_strdup (PLUGINDIR);
1766 GST_DEBUG ("using plugin dir %s", system_plugindir);
1767 changed |= gst_registry_scan_path_internal (&context, system_plugindir);
1769 g_clear_pointer (&system_plugindir, g_free);
1770 g_clear_pointer (&relocated_libgstreamer, g_free);
1775 GST_DEBUG ("GST_PLUGIN_SYSTEM_PATH set to %s", plugin_path);
1776 list = g_strsplit (plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
1777 for (i = 0; list[i]; i++) {
1778 changed |= gst_registry_scan_path_internal (&context, list[i]);
1783 clear_scan_context (&context);
1784 changed |= context.changed;
1786 /* Remove cached plugins so stale info is cleared. */
1787 changed |= gst_registry_remove_cache_plugins (default_registry);
1790 GST_INFO ("Registry cache has not changed");
1791 return REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED;
1794 if (!write_changes) {
1795 GST_INFO ("Registry cache changed, but writing is disabled. Not writing.");
1796 return REGISTRY_SCAN_AND_UPDATE_FAILURE;
1799 GST_INFO ("Registry cache changed. Writing new registry cache");
1800 if (!priv_gst_registry_binary_write_cache (default_registry,
1801 default_registry->priv->plugins, registry_file)) {
1802 g_set_error (error, GST_CORE_ERROR, GST_CORE_ERROR_FAILED,
1803 _("Error writing registry cache to %s: %s"),
1804 registry_file, g_strerror (errno));
1805 return REGISTRY_SCAN_AND_UPDATE_FAILURE;
1808 GST_INFO ("Registry cache written successfully");
1809 return REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED;
1813 ensure_current_registry (GError ** error)
1815 gchar *registry_file;
1816 GstRegistry *default_registry;
1817 gboolean ret = TRUE;
1818 gboolean do_update = TRUE;
1819 gboolean have_cache = TRUE;
1821 default_registry = gst_registry_get ();
1823 registry_file = g_strdup (g_getenv ("GST_REGISTRY_1_0"));
1824 if (registry_file == NULL)
1825 registry_file = g_strdup (g_getenv ("GST_REGISTRY"));
1826 if (registry_file == NULL) {
1827 registry_file = g_build_filename (g_get_user_cache_dir (),
1828 "gstreamer-" GST_API_VERSION, GST_REGISTRY_FILE_NAME, NULL);
1831 if (!_gst_disable_registry_cache) {
1832 GST_INFO ("reading registry cache: %s", registry_file);
1833 have_cache = priv_gst_registry_binary_read_cache (default_registry,
1835 /* Only ever read the registry cache once, then disable it for
1836 * subsequent updates during the program lifetime */
1837 _gst_disable_registry_cache = TRUE;
1841 do_update = !_priv_gst_disable_registry_update;
1843 const gchar *update_env;
1845 if ((update_env = g_getenv ("GST_REGISTRY_UPDATE"))) {
1846 /* do update for any value different from "no" */
1847 do_update = (strcmp (update_env, "no") != 0);
1853 const gchar *reuse_env;
1855 if ((reuse_env = g_getenv ("GST_REGISTRY_REUSE_PLUGIN_SCANNER"))) {
1856 /* do reuse for any value different from "no" */
1857 __registry_reuse_plugin_scanner = (strcmp (reuse_env, "no") != 0);
1859 /* now check registry */
1860 GST_DEBUG ("Updating registry cache");
1861 scan_and_update_registry (default_registry, registry_file, TRUE, error);
1863 GST_DEBUG ("Not updating registry cache (disabled)");
1866 g_free (registry_file);
1867 GST_INFO ("registry reading and updating done, result = %d", ret);
1871 #endif /* GST_DISABLE_REGISTRY */
1874 * gst_registry_fork_is_enabled:
1876 * By default GStreamer will perform scanning and rebuilding of the
1877 * registry file using a helper child process.
1879 * Applications might want to disable this behaviour with the
1880 * gst_registry_fork_set_enabled() function, in which case new plugins
1881 * are scanned (and loaded) into the application process.
1883 * Returns: %TRUE if GStreamer will use the child helper process when
1884 * rebuilding the registry.
1887 gst_registry_fork_is_enabled (void)
1889 return _gst_enable_registry_fork;
1893 * gst_registry_fork_set_enabled:
1894 * @enabled: whether rebuilding the registry can use a temporary child helper process.
1896 * Applications might want to disable/enable spawning of a child helper process
1897 * when rebuilding the registry. See gst_registry_fork_is_enabled() for more
1901 gst_registry_fork_set_enabled (gboolean enabled)
1903 _gst_enable_registry_fork = enabled;
1907 * gst_update_registry:
1909 * Forces GStreamer to re-scan its plugin paths and update the default
1912 * Applications will almost never need to call this function, it is only
1913 * useful if the application knows new plugins have been installed (or old
1914 * ones removed) since the start of the application (or, to be precise, the
1915 * first call to gst_init()) and the application wants to make use of any
1916 * newly-installed plugins without restarting the application.
1918 * Applications should assume that the registry update is neither atomic nor
1919 * thread-safe and should therefore not have any dynamic pipelines running
1920 * (including the playbin and decodebin elements) and should also not create
1921 * any elements or access the GStreamer registry while the update is in
1924 * Note that this function may block for a significant amount of time.
1926 * Returns: %TRUE if the registry has been updated successfully (does not
1927 * imply that there were changes), otherwise %FALSE.
1930 gst_update_registry (void)
1934 #ifndef GST_DISABLE_REGISTRY
1935 if (!_priv_gst_disable_registry) {
1938 res = ensure_current_registry (&err);
1940 GST_WARNING ("registry update failed: %s", err->message);
1943 GST_LOG ("registry update succeeded");
1946 GST_INFO ("registry update disabled by environment");
1951 GST_WARNING ("registry update failed: %s", "registry disabled");
1953 #endif /* GST_DISABLE_REGISTRY */
1955 #ifndef GST_DISABLE_OPTION_PARSING
1956 if (_priv_gst_preload_plugins) {
1957 GST_DEBUG ("Preloading indicated plugins...");
1958 g_slist_foreach (_priv_gst_preload_plugins, load_plugin_func, NULL);
1966 * gst_registry_get_feature_list_cookie:
1967 * @registry: the registry
1969 * Returns the registry's feature list cookie. This changes
1970 * every time a feature is added or removed from the registry.
1972 * Returns: the feature list cookie.
1975 gst_registry_get_feature_list_cookie (GstRegistry * registry)
1977 g_return_val_if_fail (GST_IS_REGISTRY (registry), 0);
1979 return registry->priv->cookie;