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 "gst-i18n-lib.h"
118 #include "glib-compat-private.h"
122 extern HMODULE _priv_gst_dll_handle;
125 /* Use a toolchain-dependent suffix on Windows */
128 # define GST_REGISTRY_FILE_SUFFIX TARGET_CPU "-msvc"
130 # define GST_REGISTRY_FILE_SUFFIX TARGET_CPU "-mingw"
133 # define GST_REGISTRY_FILE_SUFFIX TARGET_CPU
135 #define GST_REGISTRY_FILE_NAME "registry." GST_REGISTRY_FILE_SUFFIX ".bin"
138 #define GST_CAT_DEFAULT GST_CAT_REGISTRY
140 struct _GstRegistryPrivate
152 /* hash to speedup _lookup_feature_locked() */
153 GHashTable *feature_hash;
154 /* hash to speedup _lookup */
155 GHashTable *basename_hash;
157 /* updated whenever the feature list changes */
159 /* speedup for searching features */
160 GList *element_factory_list;
162 GList *typefind_factory_list;
164 GList *device_provider_factory_list;
168 /* the one instance of the default registry and the mutex protecting the
170 static GMutex _gst_registry_mutex;
171 static GstRegistry *_gst_registry_default = NULL;
174 #define DEFAULT_FORK TRUE
176 /* control the behaviour of registry rebuild */
177 static gboolean _gst_enable_registry_fork = DEFAULT_FORK;
178 /* List of plugins that need preloading/reloading after scanning registry */
179 extern GSList *_priv_gst_preload_plugins;
181 #ifndef GST_DISABLE_REGISTRY
182 /* Set to TRUE to disable registry, behaves similar to GST_DISABLE_REGISTRY */
183 gboolean _priv_gst_disable_registry = FALSE;
184 /*set to TRUE when registry needn't to be updated */
185 gboolean _priv_gst_disable_registry_update = FALSE;
186 extern GList *_priv_gst_plugin_paths;
188 /* Set to TRUE when the registry cache should be disabled */
189 gboolean _gst_disable_registry_cache = FALSE;
191 static gboolean __registry_reuse_plugin_scanner = TRUE;
194 /* Element signals and args */
202 static void gst_registry_finalize (GObject * object);
204 static guint gst_registry_signals[LAST_SIGNAL] = { 0 };
206 static GstPluginFeature *gst_registry_lookup_feature_locked (GstRegistry *
207 registry, const char *name);
208 static GstPlugin *gst_registry_lookup_bn_locked (GstRegistry * registry,
209 const char *basename);
211 #define gst_registry_parent_class parent_class
212 G_DEFINE_TYPE_WITH_PRIVATE (GstRegistry, gst_registry, GST_TYPE_OBJECT);
215 gst_registry_class_init (GstRegistryClass * klass)
217 GObjectClass *gobject_class;
219 gobject_class = (GObjectClass *) klass;
222 * GstRegistry::plugin-added:
223 * @registry: the registry that emitted the signal
224 * @plugin: the plugin that has been added
226 * Signals that a plugin has been added to the registry (possibly
227 * replacing a previously-added one by the same name)
229 gst_registry_signals[PLUGIN_ADDED] =
230 g_signal_new ("plugin-added", G_TYPE_FROM_CLASS (klass),
231 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_PLUGIN);
234 * GstRegistry::feature-added:
235 * @registry: the registry that emitted the signal
236 * @feature: the feature that has been added
238 * Signals that a feature has been added to the registry (possibly
239 * replacing a previously-added one by the same name)
241 gst_registry_signals[FEATURE_ADDED] =
242 g_signal_new ("feature-added", G_TYPE_FROM_CLASS (klass),
243 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL,
244 G_TYPE_NONE, 1, GST_TYPE_PLUGIN_FEATURE);
246 gobject_class->finalize = gst_registry_finalize;
250 gst_registry_init (GstRegistry * registry)
252 registry->priv = gst_registry_get_instance_private (registry);
253 registry->priv->feature_hash = g_hash_table_new (g_str_hash, g_str_equal);
254 registry->priv->basename_hash = g_hash_table_new (g_str_hash, g_str_equal);
258 gst_registry_finalize (GObject * object)
260 GstRegistry *registry = GST_REGISTRY (object);
264 plugins = registry->priv->plugins;
265 registry->priv->plugins = NULL;
266 registry->priv->n_plugins = 0;
268 GST_DEBUG_OBJECT (registry, "registry finalize");
271 GstPlugin *plugin = p->data;
274 GST_LOG_OBJECT (registry, "removing plugin %s",
275 gst_plugin_get_name (plugin));
276 gst_object_unref (plugin);
280 g_list_free (plugins);
282 features = registry->priv->features;
283 registry->priv->features = NULL;
287 GstPluginFeature *feature = f->data;
290 GST_LOG_OBJECT (registry, "removing feature %p (%s)", feature,
291 GST_OBJECT_NAME (feature));
292 gst_object_unparent (GST_OBJECT_CAST (feature));
296 g_list_free (features);
298 g_hash_table_destroy (registry->priv->feature_hash);
299 registry->priv->feature_hash = NULL;
300 g_hash_table_destroy (registry->priv->basename_hash);
301 registry->priv->basename_hash = NULL;
303 if (registry->priv->element_factory_list) {
304 GST_DEBUG_OBJECT (registry, "Cleaning up cached element factory list");
305 gst_plugin_feature_list_free (registry->priv->element_factory_list);
308 if (registry->priv->typefind_factory_list) {
309 GST_DEBUG_OBJECT (registry, "Cleaning up cached typefind factory list");
310 gst_plugin_feature_list_free (registry->priv->typefind_factory_list);
313 if (registry->priv->device_provider_factory_list) {
314 GST_DEBUG_OBJECT (registry,
315 "Cleaning up cached device provider factory list");
316 gst_plugin_feature_list_free (registry->priv->device_provider_factory_list);
319 G_OBJECT_CLASS (parent_class)->finalize (object);
325 * Retrieves the singleton plugin registry. The caller does not own a
326 * reference on the registry, as it is alive as long as GStreamer is
329 * Returns: (transfer none): the #GstRegistry.
332 gst_registry_get (void)
334 GstRegistry *registry;
336 g_mutex_lock (&_gst_registry_mutex);
337 if (G_UNLIKELY (!_gst_registry_default)) {
338 _gst_registry_default = g_object_new (GST_TYPE_REGISTRY, NULL);
339 gst_object_ref_sink (GST_OBJECT_CAST (_gst_registry_default));
341 registry = _gst_registry_default;
342 g_mutex_unlock (&_gst_registry_mutex);
349 * gst_registry_add_path:
350 * @registry: the registry to add the path to
351 * @path: the path to add to the registry
353 * Add the given path to the registry. The syntax of the
354 * path is specific to the registry. If the path has already been
358 gst_registry_add_path (GstRegistry * registry, const gchar * path)
360 g_return_if_fail (GST_IS_REGISTRY (registry));
361 g_return_if_fail (path != NULL);
363 if (strlen (path) == 0)
366 GST_OBJECT_LOCK (registry);
367 if (g_list_find_custom (registry->priv->paths, path, (GCompareFunc) strcmp))
370 GST_INFO ("Adding plugin path: \"%s\"", path);
371 registry->priv->paths =
372 g_list_append (registry->priv->paths, g_strdup (path));
373 GST_OBJECT_UNLOCK (registry);
379 GST_INFO ("Ignoring empty plugin path");
384 g_warning ("path %s already added to registry", path);
385 GST_OBJECT_UNLOCK (registry);
391 * gst_registry_get_path_list:
392 * @registry: the registry to get the pathlist of
394 * Get the list of paths for the given registry.
396 * Returns: (transfer container) (element-type filename): A #GList of
397 * paths as strings. g_list_free after use.
402 gst_registry_get_path_list (GstRegistry * registry)
406 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
408 GST_OBJECT_LOCK (registry);
409 /* We don't need to copy the strings, because they won't be deleted
410 * as long as the GstRegistry is around */
411 list = g_list_copy (registry->priv->paths);
412 GST_OBJECT_UNLOCK (registry);
419 * gst_registry_add_plugin:
420 * @registry: the registry to add the plugin to
421 * @plugin: (transfer floating): the plugin to add
423 * Add the plugin to the registry. The plugin-added signal will be emitted.
425 * @plugin's reference count will be incremented, and any floating
426 * reference will be removed (see gst_object_ref_sink())
428 * Returns: %TRUE on success.
433 gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin)
435 GstPlugin *existing_plugin;
437 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
438 g_return_val_if_fail (GST_IS_PLUGIN (plugin), FALSE);
440 GST_OBJECT_LOCK (registry);
441 if (G_LIKELY (plugin->basename)) {
442 /* we have a basename, see if we find the plugin */
444 gst_registry_lookup_bn_locked (registry, plugin->basename);
445 if (existing_plugin) {
446 GST_DEBUG_OBJECT (registry,
447 "Replacing existing plugin \"%s\" %p with new plugin %p for filename \"%s\"",
448 GST_STR_NULL (existing_plugin->filename), existing_plugin, plugin,
449 GST_STR_NULL (plugin->filename));
450 /* If the new plugin is blacklisted and the existing one isn't cached, do not
451 * accept if it's from a different location than the existing one */
452 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED) &&
453 strcmp (plugin->filename, existing_plugin->filename)) {
454 GST_WARNING_OBJECT (registry,
455 "Not replacing plugin because new one (%s) is blacklisted but for a different location than existing one (%s)",
456 plugin->filename, existing_plugin->filename);
457 /* Keep reference counting consistent */
458 gst_object_ref_sink (plugin);
459 gst_object_unref (plugin);
460 GST_OBJECT_UNLOCK (registry);
463 registry->priv->plugins =
464 g_list_remove (registry->priv->plugins, existing_plugin);
465 --registry->priv->n_plugins;
466 if (G_LIKELY (existing_plugin->basename))
467 g_hash_table_remove (registry->priv->basename_hash,
468 existing_plugin->basename);
469 gst_object_unref (existing_plugin);
473 GST_DEBUG_OBJECT (registry, "adding plugin %p for filename \"%s\"",
474 plugin, GST_STR_NULL (plugin->filename));
476 registry->priv->plugins = g_list_prepend (registry->priv->plugins, plugin);
477 ++registry->priv->n_plugins;
479 if (G_LIKELY (plugin->basename))
480 g_hash_table_replace (registry->priv->basename_hash, plugin->basename,
483 gst_object_ref_sink (plugin);
484 GST_OBJECT_UNLOCK (registry);
486 GST_LOG_OBJECT (registry, "emitting plugin-added for filename \"%s\"",
487 GST_STR_NULL (plugin->filename));
488 g_signal_emit (registry, gst_registry_signals[PLUGIN_ADDED], 0, plugin);
494 gst_registry_remove_features_for_plugin_unlocked (GstRegistry * registry,
499 g_return_if_fail (GST_IS_REGISTRY (registry));
500 g_return_if_fail (GST_IS_PLUGIN (plugin));
502 /* Remove all features for this plugin */
503 f = registry->priv->features;
505 GList *next = g_list_next (f);
506 GstPluginFeature *feature = f->data;
508 if (G_UNLIKELY (feature && feature->plugin == plugin)) {
509 GST_DEBUG_OBJECT (registry, "removing feature %p (%s) for plugin %p (%s)",
510 feature, gst_plugin_feature_get_name (feature), plugin,
513 registry->priv->features =
514 g_list_delete_link (registry->priv->features, f);
515 g_hash_table_remove (registry->priv->feature_hash,
516 GST_OBJECT_NAME (feature));
517 gst_object_unparent (GST_OBJECT_CAST (feature));
521 registry->priv->cookie++;
525 * gst_registry_remove_plugin:
526 * @registry: the registry to remove the plugin from
527 * @plugin: (transfer none): the plugin to remove
529 * Remove the plugin from the registry.
534 gst_registry_remove_plugin (GstRegistry * registry, GstPlugin * plugin)
536 g_return_if_fail (GST_IS_REGISTRY (registry));
537 g_return_if_fail (GST_IS_PLUGIN (plugin));
539 GST_DEBUG_OBJECT (registry, "removing plugin %p (%s)",
540 plugin, gst_plugin_get_name (plugin));
542 GST_OBJECT_LOCK (registry);
543 registry->priv->plugins = g_list_remove (registry->priv->plugins, plugin);
544 --registry->priv->n_plugins;
545 if (G_LIKELY (plugin->basename))
546 g_hash_table_remove (registry->priv->basename_hash, plugin->basename);
547 gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
548 GST_OBJECT_UNLOCK (registry);
549 gst_object_unref (plugin);
553 * gst_registry_add_feature:
554 * @registry: the registry to add the plugin to
555 * @feature: (transfer floating): the feature to add
557 * Add the feature to the registry. The feature-added signal will be emitted.
559 * @feature's reference count will be incremented, and any floating
560 * reference will be removed (see gst_object_ref_sink())
562 * Returns: %TRUE on success.
567 gst_registry_add_feature (GstRegistry * registry, GstPluginFeature * feature)
569 GstPluginFeature *existing_feature;
571 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
572 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
573 g_return_val_if_fail (GST_OBJECT_NAME (feature) != NULL, FALSE);
574 g_return_val_if_fail (feature->plugin_name != NULL, FALSE);
576 GST_OBJECT_LOCK (registry);
577 existing_feature = gst_registry_lookup_feature_locked (registry,
578 GST_OBJECT_NAME (feature));
579 if (G_UNLIKELY (existing_feature)) {
580 GST_DEBUG_OBJECT (registry, "replacing existing feature %p (%s)",
581 existing_feature, GST_OBJECT_NAME (feature));
582 /* Remove the existing feature from the list now, before we insert the new
583 * one, but don't unref yet because the hash is still storing a reference to
585 registry->priv->features =
586 g_list_remove (registry->priv->features, existing_feature);
589 GST_DEBUG_OBJECT (registry, "adding feature %p (%s)", feature,
590 GST_OBJECT_NAME (feature));
592 registry->priv->features = g_list_prepend (registry->priv->features, feature);
593 g_hash_table_replace (registry->priv->feature_hash, GST_OBJECT_NAME (feature),
596 if (G_UNLIKELY (existing_feature)) {
597 /* We unref now. No need to remove the feature name from the hash table, it
598 * got replaced by the new feature */
599 gst_object_unparent (GST_OBJECT_CAST (existing_feature));
602 gst_object_set_parent (GST_OBJECT_CAST (feature), GST_OBJECT_CAST (registry));
604 registry->priv->cookie++;
605 GST_OBJECT_UNLOCK (registry);
607 GST_LOG_OBJECT (registry, "emitting feature-added for %s",
608 GST_OBJECT_NAME (feature));
609 g_signal_emit (registry, gst_registry_signals[FEATURE_ADDED], 0, feature);
615 * gst_registry_remove_feature:
616 * @registry: the registry to remove the feature from
617 * @feature: (transfer none): the feature to remove
619 * Remove the feature from the registry.
624 gst_registry_remove_feature (GstRegistry * registry, GstPluginFeature * feature)
626 g_return_if_fail (GST_IS_REGISTRY (registry));
627 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
629 GST_DEBUG_OBJECT (registry, "removing feature %p (%s)",
630 feature, gst_plugin_feature_get_name (feature));
632 GST_OBJECT_LOCK (registry);
633 registry->priv->features = g_list_remove (registry->priv->features, feature);
634 g_hash_table_remove (registry->priv->feature_hash, GST_OBJECT_NAME (feature));
635 registry->priv->cookie++;
636 GST_OBJECT_UNLOCK (registry);
638 gst_object_unparent ((GstObject *) feature);
642 * gst_registry_plugin_filter:
643 * @registry: registry to query
644 * @filter: (scope call): the filter to use
645 * @first: only return first match
646 * @user_data: (closure): user data passed to the filter function
648 * Runs a filter against all plugins in the registry and returns a #GList with
649 * the results. If the first flag is set, only the first match is
650 * returned (as a list with a single object).
651 * Every plugin is reffed; use gst_plugin_list_free() after use, which
654 * Returns: (transfer full) (element-type Gst.Plugin): a #GList of #GstPlugin.
655 * Use gst_plugin_list_free() after usage.
660 gst_registry_plugin_filter (GstRegistry * registry,
661 GstPluginFilter filter, gboolean first, gpointer user_data)
664 GList *walk, *list = NULL;
667 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
669 GST_OBJECT_LOCK (registry);
670 n_plugins = registry->priv->n_plugins;
671 plugins = g_newa (GstPlugin *, n_plugins + 1);
672 for (walk = registry->priv->plugins, i = 0; walk != NULL; walk = walk->next)
673 plugins[i++] = gst_object_ref (walk->data);
674 GST_OBJECT_UNLOCK (registry);
676 for (i = 0; i < n_plugins; ++i) {
677 if (filter == NULL || filter (plugins[i], user_data)) {
678 list = g_list_prepend (list, gst_object_ref (plugins[i]));
685 for (i = 0; i < n_plugins; ++i)
686 gst_object_unref (plugins[i]);
698 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
699 GstTypeNameData * data)
701 g_assert (GST_IS_PLUGIN_FEATURE (feature));
703 return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
704 (data->name == NULL || !strcmp (data->name, GST_OBJECT_NAME (feature))));
707 /* returns TRUE if the list was changed
709 * Must be called with the object lock taken */
711 gst_registry_get_feature_list_or_create (GstRegistry * registry,
712 GList ** previous, guint32 * cookie, GType type)
714 gboolean res = FALSE;
715 GstRegistryPrivate *priv = registry->priv;
717 if (G_UNLIKELY (!*previous || priv->cookie != *cookie)) {
718 GstTypeNameData data;
722 gst_plugin_feature_list_free (*previous);
729 for (walk = registry->priv->features; walk != NULL; walk = walk->next) {
730 GstPluginFeature *feature = walk->data;
732 if (gst_plugin_feature_type_name_filter (feature, &data)) {
733 *previous = g_list_prepend (*previous, gst_object_ref (feature));
737 *cookie = priv->cookie;
745 type_find_factory_rank_cmp (const GstPluginFeature * fac1,
746 const GstPluginFeature * fac2)
748 if (G_LIKELY (fac1->rank != fac2->rank))
749 return fac2->rank - fac1->rank;
751 /* to make the order in which things happen more deterministic,
752 * sort by name when the ranks are the same. */
753 return strcmp (GST_OBJECT_NAME (fac1), GST_OBJECT_NAME (fac2));
757 gst_registry_get_element_factory_list (GstRegistry * registry)
761 GST_OBJECT_LOCK (registry);
763 gst_registry_get_feature_list_or_create (registry,
764 ®istry->priv->element_factory_list, ®istry->priv->efl_cookie,
765 GST_TYPE_ELEMENT_FACTORY);
767 /* Return reffed copy */
768 list = gst_plugin_feature_list_copy (registry->priv->element_factory_list);
770 GST_OBJECT_UNLOCK (registry);
776 gst_registry_get_typefind_factory_list (GstRegistry * registry)
780 GST_OBJECT_LOCK (registry);
782 if (G_UNLIKELY (gst_registry_get_feature_list_or_create (registry,
783 ®istry->priv->typefind_factory_list,
784 ®istry->priv->tfl_cookie, GST_TYPE_TYPE_FIND_FACTORY)))
785 registry->priv->typefind_factory_list =
786 g_list_sort (registry->priv->typefind_factory_list,
787 (GCompareFunc) type_find_factory_rank_cmp);
789 /* Return reffed copy */
790 list = gst_plugin_feature_list_copy (registry->priv->typefind_factory_list);
792 GST_OBJECT_UNLOCK (registry);
799 gst_registry_get_device_provider_factory_list (GstRegistry * registry)
803 GST_OBJECT_LOCK (registry);
805 gst_registry_get_feature_list_or_create (registry,
806 ®istry->priv->device_provider_factory_list,
807 ®istry->priv->dmfl_cookie, GST_TYPE_DEVICE_PROVIDER_FACTORY);
809 /* Return reffed copy */
811 gst_plugin_feature_list_copy (registry->
812 priv->device_provider_factory_list);
814 GST_OBJECT_UNLOCK (registry);
820 * gst_registry_feature_filter:
821 * @registry: registry to query
822 * @filter: (scope call): the filter to use
823 * @first: only return first match
824 * @user_data: (closure): user data passed to the filter function
826 * Runs a filter against all features of the plugins in the registry
827 * and returns a GList with the results.
828 * If the first flag is set, only the first match is
829 * returned (as a list with a single object).
831 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
832 * #GstPluginFeature. Use gst_plugin_feature_list_free() after usage.
837 gst_registry_feature_filter (GstRegistry * registry,
838 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
840 GstPluginFeature **features;
841 GList *walk, *list = NULL;
844 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
846 GST_OBJECT_LOCK (registry);
847 n_features = g_hash_table_size (registry->priv->feature_hash);
848 features = g_newa (GstPluginFeature *, n_features + 1);
849 for (walk = registry->priv->features, i = 0; walk != NULL; walk = walk->next)
850 features[i++] = gst_object_ref (walk->data);
851 GST_OBJECT_UNLOCK (registry);
853 for (i = 0; i < n_features; ++i) {
854 if (filter == NULL || filter (features[i], user_data)) {
855 list = g_list_prepend (list, gst_object_ref (features[i]));
862 for (i = 0; i < n_features; ++i)
863 gst_object_unref (features[i]);
869 gst_registry_plugin_name_filter (GstPlugin * plugin, const gchar * name)
871 return (plugin->desc.name && !strcmp (plugin->desc.name, name));
875 * gst_registry_find_plugin:
876 * @registry: the registry to search
877 * @name: the plugin name to find
879 * Find the plugin with the given name in the registry.
880 * The plugin will be reffed; caller is responsible for unreffing.
882 * Returns: (transfer full) (nullable): the plugin with the given name
883 * or %NULL if the plugin was not found. gst_object_unref() after
889 gst_registry_find_plugin (GstRegistry * registry, const gchar * name)
892 GstPlugin *result = NULL;
894 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
895 g_return_val_if_fail (name != NULL, NULL);
897 walk = gst_registry_plugin_filter (registry,
898 (GstPluginFilter) gst_registry_plugin_name_filter, TRUE, (gpointer) name);
900 result = GST_PLUGIN_CAST (walk->data);
902 gst_object_ref (result);
903 gst_plugin_list_free (walk);
910 * gst_registry_find_feature:
911 * @registry: the registry to search
912 * @name: the pluginfeature name to find
913 * @type: the pluginfeature type to find
915 * Find the pluginfeature with the given name and type in the registry.
917 * Returns: (transfer full) (nullable): the pluginfeature with the
918 * given name and type or %NULL if the plugin was not
919 * found. gst_object_unref() after usage.
924 gst_registry_find_feature (GstRegistry * registry, const gchar * name,
927 GstPluginFeature *feature = NULL;
929 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
930 g_return_val_if_fail (name != NULL, NULL);
931 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_PLUGIN_FEATURE), NULL);
933 feature = gst_registry_lookup_feature (registry, name);
934 if (feature && !g_type_is_a (G_TYPE_FROM_INSTANCE (feature), type)) {
935 gst_object_unref (feature);
943 * gst_registry_get_feature_list:
944 * @registry: a #GstRegistry
947 * Retrieves a #GList of #GstPluginFeature of @type.
949 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
950 * #GstPluginFeature of @type. Use gst_plugin_feature_list_free() after use
955 gst_registry_get_feature_list (GstRegistry * registry, GType type)
957 GstTypeNameData data;
959 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
960 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_PLUGIN_FEATURE), NULL);
963 if (type == GST_TYPE_ELEMENT_FACTORY)
964 return gst_registry_get_element_factory_list (registry);
965 else if (type == GST_TYPE_TYPE_FIND_FACTORY)
966 return gst_registry_get_typefind_factory_list (registry);
967 else if (type == GST_TYPE_DEVICE_PROVIDER_FACTORY)
968 return gst_registry_get_device_provider_factory_list (registry);
973 return gst_registry_feature_filter (registry,
974 (GstPluginFeatureFilter) gst_plugin_feature_type_name_filter,
979 * gst_registry_get_plugin_list:
980 * @registry: the registry to search
982 * Get a copy of all plugins registered in the given registry. The refcount
983 * of each element in the list in incremented.
985 * Returns: (transfer full) (element-type Gst.Plugin): a #GList of #GstPlugin.
986 * Use gst_plugin_list_free() after usage.
991 gst_registry_get_plugin_list (GstRegistry * registry)
996 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
998 GST_OBJECT_LOCK (registry);
999 list = g_list_copy (registry->priv->plugins);
1000 for (g = list; g; g = g->next) {
1001 gst_object_ref (GST_PLUGIN_CAST (g->data));
1003 GST_OBJECT_UNLOCK (registry);
1008 static GstPluginFeature *
1009 gst_registry_lookup_feature_locked (GstRegistry * registry, const char *name)
1011 return g_hash_table_lookup (registry->priv->feature_hash, name);
1015 * gst_registry_lookup_feature:
1016 * @registry: a #GstRegistry
1017 * @name: a #GstPluginFeature name
1019 * Find a #GstPluginFeature with @name in @registry.
1021 * Returns: (transfer full) (nullable): a #GstPluginFeature with its refcount incremented,
1022 * use gst_object_unref() after usage.
1027 gst_registry_lookup_feature (GstRegistry * registry, const char *name)
1029 GstPluginFeature *feature;
1031 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1032 g_return_val_if_fail (name != NULL, NULL);
1034 GST_OBJECT_LOCK (registry);
1035 feature = gst_registry_lookup_feature_locked (registry, name);
1037 gst_object_ref (feature);
1038 GST_OBJECT_UNLOCK (registry);
1044 gst_registry_lookup_bn_locked (GstRegistry * registry, const char *basename)
1046 return g_hash_table_lookup (registry->priv->basename_hash, basename);
1050 gst_registry_lookup_bn (GstRegistry * registry, const char *basename)
1054 GST_OBJECT_LOCK (registry);
1055 plugin = gst_registry_lookup_bn_locked (registry, basename);
1057 gst_object_ref (plugin);
1058 GST_OBJECT_UNLOCK (registry);
1064 * gst_registry_lookup:
1065 * @registry: the registry to look up in
1066 * @filename: the name of the file to look up
1068 * Look up a plugin in the given registry with the given filename.
1069 * If found, plugin is reffed.
1071 * Returns: (transfer full) (nullable): the #GstPlugin if found, or
1072 * %NULL if not. gst_object_unref() after usage.
1075 gst_registry_lookup (GstRegistry * registry, const char *filename)
1080 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1081 g_return_val_if_fail (filename != NULL, NULL);
1083 basename = g_path_get_basename (filename);
1084 if (G_UNLIKELY (basename == NULL))
1087 plugin = gst_registry_lookup_bn (registry, basename);
1096 REGISTRY_SCAN_HELPER_NOT_STARTED = 0,
1097 REGISTRY_SCAN_HELPER_DISABLED,
1098 REGISTRY_SCAN_HELPER_RUNNING
1099 } GstRegistryScanHelperState;
1103 GstRegistry *registry;
1104 GstRegistryScanHelperState helper_state;
1105 GstPluginLoader *helper;
1107 } GstRegistryScanContext;
1110 init_scan_context (GstRegistryScanContext * context, GstRegistry * registry)
1114 context->registry = registry;
1116 /* see if forking is enabled and set up the scan helper state accordingly */
1117 do_fork = _gst_enable_registry_fork;
1119 const gchar *fork_env;
1121 /* forking enabled, see if it is disabled with an env var */
1122 if ((fork_env = g_getenv ("GST_REGISTRY_FORK"))) {
1123 /* fork enabled for any value different from "no" */
1124 do_fork = strcmp (fork_env, "no") != 0;
1129 context->helper_state = REGISTRY_SCAN_HELPER_NOT_STARTED;
1131 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1133 context->helper = NULL;
1134 context->changed = FALSE;
1138 clear_scan_context (GstRegistryScanContext * context)
1140 if (context->helper) {
1141 context->changed |= _priv_gst_plugin_loader_funcs.destroy (context->helper);
1142 context->helper = NULL;
1147 gst_registry_scan_plugin_file (GstRegistryScanContext * context,
1148 const gchar * filename, off_t file_size, time_t file_mtime)
1150 gboolean changed = FALSE;
1151 GstPlugin *newplugin = NULL;
1154 /* Disable external plugin loader on Windows until it is ported properly. */
1155 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1159 /* Have a plugin to load - see if the scan-helper needs starting */
1160 if (context->helper_state == REGISTRY_SCAN_HELPER_NOT_STARTED) {
1161 GST_DEBUG ("Starting plugin scanner for file %s", filename);
1162 context->helper = _priv_gst_plugin_loader_funcs.create (context->registry);
1163 if (context->helper != NULL)
1164 context->helper_state = REGISTRY_SCAN_HELPER_RUNNING;
1166 GST_WARNING ("Failed starting plugin scanner. Scanning in-process");
1167 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1171 if (context->helper_state == REGISTRY_SCAN_HELPER_RUNNING) {
1172 GST_DEBUG ("Using scan-helper to load plugin %s", filename);
1173 if (!_priv_gst_plugin_loader_funcs.load (context->helper,
1174 filename, file_size, file_mtime)) {
1175 g_warning ("External plugin loader failed. This most likely means that "
1176 "the plugin loader helper binary was not found or could not be run. "
1177 "You might need to set the GST_PLUGIN_SCANNER environment variable "
1178 "if your setup is unusual. This should normally not be required "
1180 context->helper_state = REGISTRY_SCAN_HELPER_DISABLED;
1184 /* Check if the helper is disabled (or just got disabled above) */
1185 if (context->helper_state == REGISTRY_SCAN_HELPER_DISABLED) {
1186 /* Load plugin the old fashioned way... */
1188 /* We don't use a GError here because a failure to load some shared
1189 * objects as plugins is normal (particularly in the uninstalled case)
1191 newplugin = _priv_gst_plugin_load_file_for_registry (filename,
1192 context->registry, NULL);
1196 GST_DEBUG_OBJECT (context->registry, "marking new plugin %p as registered",
1198 newplugin->registered = TRUE;
1199 gst_object_unref (newplugin);
1202 #ifndef GST_DISABLE_REGISTRY
1203 if (!__registry_reuse_plugin_scanner) {
1204 clear_scan_context (context);
1205 context->helper_state = REGISTRY_SCAN_HELPER_NOT_STARTED;
1213 is_blacklisted_directory (const gchar * dirent)
1215 /* hotdoc private folder can contain many files and it slows down
1216 * the discovery for nothing */
1217 if (g_str_has_prefix (dirent, "hotdoc-private-"))
1220 if (G_LIKELY (dirent[0] != '.'))
1223 /* skip the .debug directory, these contain elf files that are not
1224 * useful or worse, can crash dlopen () */
1225 if (strcmp (dirent, ".debug") == 0)
1228 /* can also skip .git and .deps dirs, those won't contain useful files.
1229 * This speeds up scanning a bit in uninstalled setups. */
1230 if (strcmp (dirent, ".git") == 0 || strcmp (dirent, ".deps") == 0)
1237 gst_registry_scan_path_level (GstRegistryScanContext * context,
1238 const gchar * path, int level)
1241 const gchar *dirent;
1244 gboolean changed = FALSE;
1246 dir = g_dir_open (path, 0, NULL);
1250 while ((dirent = g_dir_read_name (dir))) {
1251 GStatBuf file_status;
1253 filename = g_build_filename (path, dirent, NULL);
1254 if (g_stat (filename, &file_status) < 0) {
1255 /* Plugin will be removed from cache after the scan completes if it
1256 * is still marked 'cached' */
1261 if (file_status.st_mode & S_IFDIR) {
1262 if (G_UNLIKELY (is_blacklisted_directory (dirent))) {
1263 GST_TRACE_OBJECT (context->registry, "ignoring %s directory", dirent);
1267 /* FIXME 2.0: Don't recurse into directories, this behaviour
1268 * is inconsistent with other PATH environment variables
1271 GST_LOG_OBJECT (context->registry, "recursing into directory %s",
1273 changed |= gst_registry_scan_path_level (context, filename, level - 1);
1275 GST_LOG_OBJECT (context->registry, "not recursing into directory %s, "
1276 "recursion level too deep", filename);
1281 if (!(file_status.st_mode & S_IFREG)) {
1282 GST_TRACE_OBJECT (context->registry, "%s is not a regular file, ignoring",
1287 if (!g_str_has_suffix (dirent, "." G_MODULE_SUFFIX)
1288 #ifdef GST_EXTRA_MODULE_SUFFIX
1289 && !g_str_has_suffix (dirent, GST_EXTRA_MODULE_SUFFIX)
1292 GST_TRACE_OBJECT (context->registry,
1293 "extension is not recognized as module file, ignoring file %s",
1299 GST_LOG_OBJECT (context->registry, "file %s looks like a possible module",
1302 /* try to avoid unnecessary plugin-move pain */
1303 if (g_str_has_prefix (dirent, "libgstvalve") ||
1304 g_str_has_prefix (dirent, "libgstselector")) {
1305 GST_WARNING_OBJECT (context->registry, "ignoring old plugin %s which "
1306 "has been merged into the corelements plugin", filename);
1307 /* Plugin will be removed from cache after the scan completes if it
1308 * is still marked 'cached' */
1313 /* plug-ins are considered unique by basename; if the given name
1314 * was already seen by the registry, we ignore it */
1315 plugin = gst_registry_lookup_bn (context->registry, dirent);
1317 gboolean env_vars_changed, deps_changed = FALSE;
1319 if (plugin->registered) {
1320 GST_DEBUG_OBJECT (context->registry,
1321 "plugin already registered from path \"%s\"",
1322 GST_STR_NULL (plugin->filename));
1324 gst_object_unref (plugin);
1328 env_vars_changed = _priv_plugin_deps_env_vars_changed (plugin);
1330 /* If a file with a certain basename is seen on a different path,
1331 * update the plugin to ensure the registry cache will reflect up
1332 * to date information */
1334 if (plugin->file_mtime == file_status.st_mtime &&
1335 plugin->file_size == file_status.st_size && !env_vars_changed &&
1336 !(deps_changed = _priv_plugin_deps_files_changed (plugin)) &&
1337 !strcmp (plugin->filename, filename)) {
1338 GST_LOG_OBJECT (context->registry, "file %s cached", filename);
1339 GST_OBJECT_FLAG_UNSET (plugin, GST_PLUGIN_FLAG_CACHED);
1340 GST_LOG_OBJECT (context->registry,
1341 "marking plugin %p as registered as %s", plugin, filename);
1342 plugin->registered = TRUE;
1344 GST_INFO_OBJECT (context->registry, "cached info for %s is stale",
1346 GST_DEBUG_OBJECT (context->registry, "mtime %" G_GINT64_FORMAT " != %"
1347 G_GINT64_FORMAT " or size %" G_GINT64_FORMAT " != %"
1348 G_GINT64_FORMAT " or external dependency env_vars changed: %d or"
1349 " external dependencies changed: %d or old path %s != new path %s",
1350 (gint64) plugin->file_mtime, (gint64) file_status.st_mtime,
1351 (gint64) plugin->file_size, (gint64) file_status.st_size,
1352 env_vars_changed, deps_changed, plugin->filename, filename);
1353 gst_registry_remove_plugin (context->registry, plugin);
1354 changed |= gst_registry_scan_plugin_file (context, filename,
1355 file_status.st_size, file_status.st_mtime);
1357 gst_object_unref (plugin);
1360 GST_DEBUG_OBJECT (context->registry, "file %s not yet in registry",
1362 changed |= gst_registry_scan_plugin_file (context, filename,
1363 file_status.st_size, file_status.st_mtime);
1375 gst_registry_scan_path_internal (GstRegistryScanContext * context,
1380 GST_DEBUG_OBJECT (context->registry, "scanning path %s", path);
1381 changed = gst_registry_scan_path_level (context, path, 10);
1383 GST_DEBUG_OBJECT (context->registry, "registry changed in path %s: %d", path,
1389 * gst_registry_scan_path:
1390 * @registry: the registry to add found plugins to
1391 * @path: (type filename): the path to scan
1393 * Scan the given path for plugins to add to the registry. The syntax of the
1394 * path is specific to the registry.
1396 * Returns: %TRUE if registry changed
1399 gst_registry_scan_path (GstRegistry * registry, const gchar * path)
1401 GstRegistryScanContext context;
1404 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
1405 g_return_val_if_fail (path != NULL, FALSE);
1407 init_scan_context (&context, registry);
1409 result = gst_registry_scan_path_internal (&context, path);
1411 clear_scan_context (&context);
1412 result |= context.changed;
1418 _gst_plugin_feature_filter_plugin_name (GstPluginFeature * feature,
1421 return (strcmp (feature->plugin_name, (gchar *) user_data) == 0);
1425 * gst_registry_get_feature_list_by_plugin:
1426 * @registry: a #GstRegistry.
1427 * @name: a plugin name.
1429 * Retrieves a #GList of features of the plugin with name @name.
1431 * Returns: (transfer full) (element-type Gst.PluginFeature): a #GList of
1432 * #GstPluginFeature. Use gst_plugin_feature_list_free() after usage.
1435 gst_registry_get_feature_list_by_plugin (GstRegistry * registry,
1438 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1439 g_return_val_if_fail (name != NULL, NULL);
1441 return gst_registry_feature_filter (registry,
1442 _gst_plugin_feature_filter_plugin_name, FALSE, (gpointer) name);
1445 /* Private function for getting plugin features directly */
1447 _priv_plugin_get_features (GstRegistry * registry, GstPlugin * plugin)
1452 GST_OBJECT_LOCK (registry);
1453 for (walk = registry->priv->features; walk; walk = walk->next) {
1454 GstPluginFeature *feat = (GstPluginFeature *) walk->data;
1455 if (feat->plugin == plugin)
1456 res = g_list_prepend (res, gst_object_ref (feat));
1458 GST_OBJECT_UNLOCK (registry);
1463 /* Unref and delete the default registry */
1465 _priv_gst_registry_cleanup (void)
1467 GstRegistry *registry;
1469 g_mutex_lock (&_gst_registry_mutex);
1470 if ((registry = _gst_registry_default) != NULL) {
1471 _gst_registry_default = NULL;
1473 g_mutex_unlock (&_gst_registry_mutex);
1475 /* unref outside of the lock because we can. */
1477 gst_object_unref (registry);
1481 * gst_registry_check_feature_version:
1482 * @registry: a #GstRegistry
1483 * @feature_name: the name of the feature (e.g. "oggdemux")
1484 * @min_major: the minimum major version number
1485 * @min_minor: the minimum minor version number
1486 * @min_micro: the minimum micro version number
1488 * Checks whether a plugin feature by the given name exists in
1489 * @registry and whether its version is at least the
1492 * Returns: %TRUE if the feature could be found and the version is
1493 * the same as the required version or newer, and %FALSE otherwise.
1496 gst_registry_check_feature_version (GstRegistry * registry,
1497 const gchar * feature_name, guint min_major, guint min_minor,
1500 GstPluginFeature *feature;
1501 gboolean ret = FALSE;
1503 g_return_val_if_fail (feature_name != NULL, FALSE);
1505 GST_DEBUG ("Looking up plugin feature '%s'", feature_name);
1507 feature = gst_registry_lookup_feature (registry, feature_name);
1509 ret = gst_plugin_feature_check_version (feature, min_major, min_minor,
1511 gst_object_unref (feature);
1513 GST_DEBUG ("Could not find plugin feature '%s'", feature_name);
1520 load_plugin_func (gpointer data, gpointer user_data)
1523 const gchar *filename;
1526 filename = (const gchar *) data;
1527 GST_DEBUG ("Pre-loading plugin %s", filename);
1529 plugin = gst_plugin_load_file (filename, &err);
1532 GST_INFO ("Loaded plugin: \"%s\"", filename);
1534 gst_registry_add_plugin (gst_registry_get (), plugin);
1537 /* Report error to user, and free error */
1538 GST_ERROR ("Failed to load plugin: %s", err->message);
1541 GST_WARNING ("Failed to load plugin: \"%s\"", filename);
1546 #ifndef GST_DISABLE_REGISTRY
1547 /* Unref all plugins marked 'cached', to clear old plugins that no
1548 * longer exist. Returns %TRUE if any plugins were removed */
1550 gst_registry_remove_cache_plugins (GstRegistry * registry)
1555 gboolean changed = FALSE;
1557 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
1559 GST_OBJECT_LOCK (registry);
1561 GST_DEBUG_OBJECT (registry, "removing cached plugins");
1562 g = registry->priv->plugins;
1566 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_CACHED)) {
1567 GST_DEBUG_OBJECT (registry, "removing cached plugin \"%s\"",
1568 GST_STR_NULL (plugin->filename));
1569 registry->priv->plugins = g_list_delete_link (registry->priv->plugins, g);
1570 --registry->priv->n_plugins;
1571 if (G_LIKELY (plugin->basename))
1572 g_hash_table_remove (registry->priv->basename_hash, plugin->basename);
1573 gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
1574 gst_object_unref (plugin);
1580 GST_OBJECT_UNLOCK (registry);
1587 REGISTRY_SCAN_AND_UPDATE_FAILURE = 0,
1588 REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED,
1589 REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED
1590 } GstRegistryScanAndUpdateResult;
1593 * scan_and_update_registry:
1594 * @default_registry: the #GstRegistry
1595 * @registry_file: registry filename
1596 * @write_changes: write registry if it has changed?
1598 * Scans for registry changes and eventually updates the registry cache.
1600 * Return: %REGISTRY_SCAN_AND_UPDATE_FAILURE if the registry could not scanned
1601 * or updated, %REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED if the
1602 * registry is clean and %REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED if
1603 * it has been updated and the cache needs to be re-read.
1605 static GstRegistryScanAndUpdateResult
1606 scan_and_update_registry (GstRegistry * default_registry,
1607 const gchar * registry_file, gboolean write_changes, GError ** error)
1609 const gchar *plugin_path;
1610 gboolean changed = FALSE;
1612 GstRegistryScanContext context;
1614 GST_INFO ("Validating plugins from registry cache: %s", registry_file);
1616 init_scan_context (&context, default_registry);
1618 /* It sounds tempting to just compare the mtime of directories with the mtime
1619 * of the registry cache, but it does not work. It would not catch updated
1620 * plugins, which might bring more or less features.
1623 /* scan paths specified via --gst-plugin-path */
1624 GST_DEBUG ("scanning paths added via --gst-plugin-path");
1625 for (l = _priv_gst_plugin_paths; l != NULL; l = l->next) {
1626 GST_INFO ("Scanning plugin path: \"%s\"", (gchar *) l->data);
1627 changed |= gst_registry_scan_path_internal (&context, (gchar *) l->data);
1629 /* keep plugin_paths around in case a re-scan is forced later on */
1631 /* GST_PLUGIN_PATH specifies a list of directories to scan for
1632 * additional plugins. These take precedence over the system plugins */
1633 plugin_path = g_getenv ("GST_PLUGIN_PATH_1_0");
1634 if (plugin_path == NULL)
1635 plugin_path = g_getenv ("GST_PLUGIN_PATH");
1640 GST_DEBUG ("GST_PLUGIN_PATH set to %s", plugin_path);
1641 list = g_strsplit (plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
1642 for (i = 0; list[i]; i++) {
1643 changed |= gst_registry_scan_path_internal (&context, list[i]);
1647 GST_DEBUG ("GST_PLUGIN_PATH not set");
1650 /* GST_PLUGIN_SYSTEM_PATH specifies a list of plugins that are always
1651 * loaded by default. If not set, this defaults to the system-installed
1652 * path, and the plugins installed in the user's home directory */
1653 plugin_path = g_getenv ("GST_PLUGIN_SYSTEM_PATH_1_0");
1654 if (plugin_path == NULL)
1655 plugin_path = g_getenv ("GST_PLUGIN_SYSTEM_PATH");
1656 if (plugin_path == NULL) {
1659 GST_DEBUG ("GST_PLUGIN_SYSTEM_PATH not set");
1661 /* plugins in the user's home directory take precedence over
1662 * system-installed ones */
1663 home_plugins = g_build_filename (g_get_user_data_dir (),
1664 "gstreamer-" GST_API_VERSION, "plugins", NULL);
1666 GST_DEBUG ("scanning home plugins %s", home_plugins);
1667 changed |= gst_registry_scan_path_internal (&context, home_plugins);
1668 g_free (home_plugins);
1670 /* add the main (installed) library path */
1678 g_win32_get_package_installation_directory_of_module
1679 (_priv_gst_dll_handle);
1681 dir = g_build_filename (base_dir, GST_PLUGIN_SUBDIR,
1682 "gstreamer-" GST_API_VERSION, NULL);
1683 GST_DEBUG ("scanning DLL dir %s", dir);
1685 changed |= gst_registry_scan_path_internal (&context, dir);
1691 GST_DEBUG ("scanning main plugins %s", PLUGINDIR);
1692 changed |= gst_registry_scan_path_internal (&context, PLUGINDIR);
1698 GST_DEBUG ("GST_PLUGIN_SYSTEM_PATH set to %s", plugin_path);
1699 list = g_strsplit (plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
1700 for (i = 0; list[i]; i++) {
1701 changed |= gst_registry_scan_path_internal (&context, list[i]);
1706 clear_scan_context (&context);
1707 changed |= context.changed;
1709 /* Remove cached plugins so stale info is cleared. */
1710 changed |= gst_registry_remove_cache_plugins (default_registry);
1713 GST_INFO ("Registry cache has not changed");
1714 return REGISTRY_SCAN_AND_UPDATE_SUCCESS_NOT_CHANGED;
1717 if (!write_changes) {
1718 GST_INFO ("Registry cache changed, but writing is disabled. Not writing.");
1719 return REGISTRY_SCAN_AND_UPDATE_FAILURE;
1722 GST_INFO ("Registry cache changed. Writing new registry cache");
1723 if (!priv_gst_registry_binary_write_cache (default_registry,
1724 default_registry->priv->plugins, registry_file)) {
1725 g_set_error (error, GST_CORE_ERROR, GST_CORE_ERROR_FAILED,
1726 _("Error writing registry cache to %s: %s"),
1727 registry_file, g_strerror (errno));
1728 return REGISTRY_SCAN_AND_UPDATE_FAILURE;
1731 GST_INFO ("Registry cache written successfully");
1732 return REGISTRY_SCAN_AND_UPDATE_SUCCESS_UPDATED;
1736 ensure_current_registry (GError ** error)
1738 gchar *registry_file;
1739 GstRegistry *default_registry;
1740 gboolean ret = TRUE;
1741 gboolean do_update = TRUE;
1742 gboolean have_cache = TRUE;
1744 default_registry = gst_registry_get ();
1746 registry_file = g_strdup (g_getenv ("GST_REGISTRY_1_0"));
1747 if (registry_file == NULL)
1748 registry_file = g_strdup (g_getenv ("GST_REGISTRY"));
1749 if (registry_file == NULL) {
1750 registry_file = g_build_filename (g_get_user_cache_dir (),
1751 "gstreamer-" GST_API_VERSION, GST_REGISTRY_FILE_NAME, NULL);
1754 if (!_gst_disable_registry_cache) {
1755 GST_INFO ("reading registry cache: %s", registry_file);
1756 have_cache = priv_gst_registry_binary_read_cache (default_registry,
1758 /* Only ever read the registry cache once, then disable it for
1759 * subsequent updates during the program lifetime */
1760 _gst_disable_registry_cache = TRUE;
1764 do_update = !_priv_gst_disable_registry_update;
1766 const gchar *update_env;
1768 if ((update_env = g_getenv ("GST_REGISTRY_UPDATE"))) {
1769 /* do update for any value different from "no" */
1770 do_update = (strcmp (update_env, "no") != 0);
1776 const gchar *reuse_env;
1778 if ((reuse_env = g_getenv ("GST_REGISTRY_REUSE_PLUGIN_SCANNER"))) {
1779 /* do reuse for any value different from "no" */
1780 __registry_reuse_plugin_scanner = (strcmp (reuse_env, "no") != 0);
1782 /* now check registry */
1783 GST_DEBUG ("Updating registry cache");
1784 scan_and_update_registry (default_registry, registry_file, TRUE, error);
1786 GST_DEBUG ("Not updating registry cache (disabled)");
1789 g_free (registry_file);
1790 GST_INFO ("registry reading and updating done, result = %d", ret);
1794 #endif /* GST_DISABLE_REGISTRY */
1797 * gst_registry_fork_is_enabled:
1799 * By default GStreamer will perform scanning and rebuilding of the
1800 * registry file using a helper child process.
1802 * Applications might want to disable this behaviour with the
1803 * gst_registry_fork_set_enabled() function, in which case new plugins
1804 * are scanned (and loaded) into the application process.
1806 * Returns: %TRUE if GStreamer will use the child helper process when
1807 * rebuilding the registry.
1810 gst_registry_fork_is_enabled (void)
1812 return _gst_enable_registry_fork;
1816 * gst_registry_fork_set_enabled:
1817 * @enabled: whether rebuilding the registry can use a temporary child helper process.
1819 * Applications might want to disable/enable spawning of a child helper process
1820 * when rebuilding the registry. See gst_registry_fork_is_enabled() for more
1824 gst_registry_fork_set_enabled (gboolean enabled)
1826 _gst_enable_registry_fork = enabled;
1830 * gst_update_registry:
1832 * Forces GStreamer to re-scan its plugin paths and update the default
1835 * Applications will almost never need to call this function, it is only
1836 * useful if the application knows new plugins have been installed (or old
1837 * ones removed) since the start of the application (or, to be precise, the
1838 * first call to gst_init()) and the application wants to make use of any
1839 * newly-installed plugins without restarting the application.
1841 * Applications should assume that the registry update is neither atomic nor
1842 * thread-safe and should therefore not have any dynamic pipelines running
1843 * (including the playbin and decodebin elements) and should also not create
1844 * any elements or access the GStreamer registry while the update is in
1847 * Note that this function may block for a significant amount of time.
1849 * Returns: %TRUE if the registry has been updated successfully (does not
1850 * imply that there were changes), otherwise %FALSE.
1853 gst_update_registry (void)
1857 #ifndef GST_DISABLE_REGISTRY
1858 if (!_priv_gst_disable_registry) {
1861 res = ensure_current_registry (&err);
1863 GST_WARNING ("registry update failed: %s", err->message);
1866 GST_LOG ("registry update succeeded");
1869 GST_INFO ("registry update disabled by environment");
1874 GST_WARNING ("registry update failed: %s", "registry disabled");
1876 #endif /* GST_DISABLE_REGISTRY */
1878 #ifndef GST_DISABLE_OPTION_PARSING
1879 if (_priv_gst_preload_plugins) {
1880 GST_DEBUG ("Preloading indicated plugins...");
1881 g_slist_foreach (_priv_gst_preload_plugins, load_plugin_func, NULL);
1889 * gst_registry_get_feature_list_cookie:
1890 * @registry: the registry
1892 * Returns the registry's feature list cookie. This changes
1893 * every time a feature is added or removed from the registry.
1895 * Returns: the feature list cookie.
1898 gst_registry_get_feature_list_cookie (GstRegistry * registry)
1900 g_return_val_if_fail (GST_IS_REGISTRY (registry), 0);
1902 return registry->priv->cookie;