2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2005 David A. Schleef <ds@schleef.org>
6 * gstregistry.c: handle registry
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
26 * @short_description: Abstract base class for management of #GstPlugin objects
27 * @see_also: #GstPlugin, #GstPluginFeature
29 * One registry holds the metadata of a set of plugins.
31 * <emphasis role="bold">Design:</emphasis>
33 * The #GstRegistry object is a list of plugins and some functions for dealing
34 * with them. #GstPlugins are matched 1-1 with a file on disk, and may or may
35 * not be loaded at a given time. There may be multiple #GstRegistry objects,
36 * but the "default registry" is the only object that has any meaning to the
39 * The registry.xml file is actually a cache of plugin information. This is
40 * unlike versions prior to 0.10, where the registry file was the primary source
41 * of plugin information, and was created by the gst-register command.
43 * The primary source, at all times, of plugin information is each plugin file
44 * itself. Thus, if an application wants information about a particular plugin,
45 * or wants to search for a feature that satisfies given criteria, the primary
46 * means of doing so is to load every plugin and look at the resulting
47 * information that is gathered in the default registry. Clearly, this is a time
48 * consuming process, so we cache information in the registry.xml file.
50 * On startup, plugins are searched for in the plugin search path. This path can
51 * be set directly using the %GST_PLUGIN_PATH environment variable. The registry
52 * file is loaded from ~/.gstreamer-$GST_MAJORMINOR/registry-$ARCH.xml or the
53 * file listed in the %GST_REGISTRY env var. The only reason to change the
54 * registry location is for testing.
56 * For each plugin that is found in the plugin search path, there could be 3
57 * possibilities for cached information:
60 * <para>the cache may not contain information about a given file.</para>
63 * <para>the cache may have stale information.</para>
66 * <para>the cache may have current information.</para>
70 * In the first two cases, the plugin is loaded and the cache updated. In
71 * addition to these cases, the cache may have entries for plugins that are not
72 * relevant to the current process. These are marked as not available to the
73 * current process. If the cache is updated for whatever reason, it is marked
76 * A dirty cache is written out at the end of initialization. Each entry is
77 * checked to make sure the information is minimally valid. If not, the entry is
80 * <emphasis role="bold">Implementation notes:</emphasis>
82 * The "cache" and "default registry" are different concepts and can represent
83 * different sets of plugins. For various reasons, at init time, the cache is
84 * stored in the default registry, and plugins not relevant to the current
85 * process are marked with the %GST_PLUGIN_FLAG_CACHED bit. These plugins are
86 * removed at the end of intitialization.
92 #include "gst_private.h"
94 #include <sys/types.h>
104 #include <glib/gstdio.h>
107 #include "gstregistry.h"
108 #include "gstmarshal.h"
109 #include "gstfilter.h"
111 #define GST_CAT_DEFAULT GST_CAT_REGISTRY
113 /* the one instance of the default registry and the mutex protecting the
115 static GStaticMutex _gst_registry_mutex = G_STATIC_MUTEX_INIT;
116 static GstRegistry *_gst_registry_default = NULL;
118 /* Element signals and args */
126 static void gst_registry_finalize (GObject * object);
128 static guint gst_registry_signals[LAST_SIGNAL] = { 0 };
130 static GstPluginFeature *gst_registry_lookup_feature_locked (GstRegistry *
131 registry, const char *name);
132 static GstPlugin *gst_registry_lookup_locked (GstRegistry * registry,
133 const char *filename);
135 G_DEFINE_TYPE (GstRegistry, gst_registry, GST_TYPE_OBJECT);
136 static GstObjectClass *parent_class = NULL;
139 gst_registry_class_init (GstRegistryClass * klass)
141 GObjectClass *gobject_class;
143 gobject_class = (GObjectClass *) klass;
145 parent_class = g_type_class_peek_parent (klass);
148 * GstRegistry::plugin-added:
149 * @registry: the registry that emitted the signal
150 * @plugin: the plugin that has been added
152 * Signals that a plugin has been added to the registry (possibly
153 * replacing a previously-added one by the same name)
155 gst_registry_signals[PLUGIN_ADDED] =
156 g_signal_new ("plugin-added", G_TYPE_FROM_CLASS (klass),
157 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRegistryClass, plugin_added), NULL,
158 NULL, gst_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
161 * GstRegistry::feature-added:
162 * @registry: the registry that emitted the signal
163 * @feature: the feature that has been added
165 * Signals that a feature has been added to the registry (possibly
166 * replacing a previously-added one by the same name)
168 gst_registry_signals[FEATURE_ADDED] =
169 g_signal_new ("feature-added", G_TYPE_FROM_CLASS (klass),
170 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRegistryClass, feature_added),
171 NULL, NULL, gst_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
173 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_registry_finalize);
177 gst_registry_init (GstRegistry * registry)
179 registry->feature_hash = g_hash_table_new (g_str_hash, g_str_equal);
183 gst_registry_finalize (GObject * object)
185 GstRegistry *registry = GST_REGISTRY (object);
189 plugins = registry->plugins;
190 registry->plugins = NULL;
192 GST_DEBUG_OBJECT (registry, "registry finalize");
195 GstPlugin *plugin = p->data;
198 GST_LOG_OBJECT (registry, "removing plugin %s",
199 gst_plugin_get_name (plugin));
200 gst_object_unref (plugin);
204 g_list_free (plugins);
206 features = registry->features;
207 registry->features = NULL;
211 GstPluginFeature *feature = f->data;
214 GST_LOG_OBJECT (registry, "removing feature %p (%s)",
215 feature, gst_plugin_feature_get_name (feature));
216 gst_object_unref (feature);
220 g_list_free (features);
222 g_hash_table_destroy (registry->feature_hash);
223 registry->feature_hash = NULL;
225 G_OBJECT_CLASS (parent_class)->finalize (object);
229 * gst_registry_get_default:
231 * Retrieves the default registry. The caller does not own a reference on the
232 * registry, as it is alive as long as GStreamer is initialized.
234 * Returns: The default #GstRegistry.
237 gst_registry_get_default (void)
239 GstRegistry *registry;
241 g_static_mutex_lock (&_gst_registry_mutex);
242 if (G_UNLIKELY (!_gst_registry_default)) {
243 _gst_registry_default = g_object_new (GST_TYPE_REGISTRY, NULL);
244 gst_object_ref (GST_OBJECT_CAST (_gst_registry_default));
245 gst_object_sink (GST_OBJECT_CAST (_gst_registry_default));
247 registry = _gst_registry_default;
248 g_static_mutex_unlock (&_gst_registry_mutex);
254 * gst_registry_add_path:
255 * @registry: the registry to add the path to
256 * @path: the path to add to the registry
258 * Add the given path to the registry. The syntax of the
259 * path is specific to the registry. If the path has already been
263 gst_registry_add_path (GstRegistry * registry, const gchar * path)
265 g_return_if_fail (GST_IS_REGISTRY (registry));
266 g_return_if_fail (path != NULL);
268 if (strlen (path) == 0)
271 GST_OBJECT_LOCK (registry);
272 if (g_list_find_custom (registry->paths, path, (GCompareFunc) strcmp))
275 GST_INFO ("Adding plugin path: \"%s\"", path);
276 registry->paths = g_list_append (registry->paths, g_strdup (path));
277 GST_OBJECT_UNLOCK (registry);
283 GST_INFO ("Ignoring empty plugin path");
288 g_warning ("path %s already added to registry", path);
289 GST_OBJECT_UNLOCK (registry);
295 * gst_registry_get_path_list:
296 * @registry: the registry to get the pathlist of
298 * Get the list of paths for the given registry.
300 * Returns: A Glist of paths as strings. g_list_free after use.
305 gst_registry_get_path_list (GstRegistry * registry)
309 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
311 GST_OBJECT_LOCK (registry);
312 /* We don't need to copy the strings, because they won't be deleted
313 * as long as the GstRegistry is around */
314 list = g_list_copy (registry->paths);
315 GST_OBJECT_UNLOCK (registry);
322 * gst_registry_add_plugin:
323 * @registry: the registry to add the plugin to
324 * @plugin: the plugin to add
326 * Add the plugin to the registry. The plugin-added signal will be emitted.
327 * This function will sink @plugin.
329 * Returns: TRUE on success.
334 gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin)
336 GstPlugin *existing_plugin;
338 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
339 g_return_val_if_fail (GST_IS_PLUGIN (plugin), FALSE);
341 GST_OBJECT_LOCK (registry);
342 existing_plugin = gst_registry_lookup_locked (registry, plugin->filename);
343 if (G_UNLIKELY (existing_plugin)) {
344 GST_DEBUG_OBJECT (registry,
345 "Replacing existing plugin %p with new plugin %p for filename \"%s\"",
346 existing_plugin, plugin, GST_STR_NULL (plugin->filename));
347 registry->plugins = g_list_remove (registry->plugins, existing_plugin);
348 gst_object_unref (existing_plugin);
351 GST_DEBUG_OBJECT (registry, "adding plugin %p for filename \"%s\"",
352 plugin, GST_STR_NULL (plugin->filename));
354 registry->plugins = g_list_prepend (registry->plugins, plugin);
356 gst_object_ref (plugin);
357 gst_object_sink (plugin);
358 GST_OBJECT_UNLOCK (registry);
360 GST_LOG_OBJECT (registry, "emitting plugin-added for filename \"%s\"",
361 GST_STR_NULL (plugin->filename));
362 g_signal_emit (G_OBJECT (registry), gst_registry_signals[PLUGIN_ADDED], 0,
369 gst_registry_remove_features_for_plugin_unlocked (GstRegistry * registry,
374 g_return_if_fail (GST_IS_REGISTRY (registry));
375 g_return_if_fail (GST_IS_PLUGIN (plugin));
377 /* Remove all features for this plugin */
378 f = registry->features;
380 GList *next = g_list_next (f);
381 GstPluginFeature *feature = f->data;
383 if (feature && !strcmp (feature->plugin_name, gst_plugin_get_name (plugin))) {
384 GST_DEBUG_OBJECT (registry, "removing feature %p (%s) for plugin %s",
385 feature, gst_plugin_feature_get_name (feature),
386 gst_plugin_get_name (plugin));
388 registry->features = g_list_delete_link (registry->features, f);
389 g_hash_table_remove (registry->feature_hash, feature->name);
390 gst_object_unref (feature);
397 * gst_registry_remove_plugin:
398 * @registry: the registry to remove the plugin from
399 * @plugin: the plugin to remove
401 * Remove the plugin from the registry.
406 gst_registry_remove_plugin (GstRegistry * registry, GstPlugin * plugin)
408 g_return_if_fail (GST_IS_REGISTRY (registry));
409 g_return_if_fail (GST_IS_PLUGIN (plugin));
411 GST_DEBUG_OBJECT (registry, "removing plugin %p (%s)",
412 plugin, gst_plugin_get_name (plugin));
414 GST_OBJECT_LOCK (registry);
415 registry->plugins = g_list_remove (registry->plugins, plugin);
416 gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
417 GST_OBJECT_UNLOCK (registry);
418 gst_object_unref (plugin);
422 * gst_registry_add_feature:
423 * @registry: the registry to add the plugin to
424 * @feature: the feature to add
426 * Add the feature to the registry. The feature-added signal will be emitted.
427 * This function sinks @feature.
429 * Returns: TRUE on success.
434 gst_registry_add_feature (GstRegistry * registry, GstPluginFeature * feature)
436 GstPluginFeature *existing_feature;
438 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
439 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
440 g_return_val_if_fail (feature->name != NULL, FALSE);
441 g_return_val_if_fail (feature->plugin_name != NULL, FALSE);
443 GST_OBJECT_LOCK (registry);
444 existing_feature = gst_registry_lookup_feature_locked (registry,
446 if (G_UNLIKELY (existing_feature)) {
447 GST_DEBUG_OBJECT (registry, "replacing existing feature %p (%s)",
448 existing_feature, feature->name);
449 /* Remove the existing feature from the list now, before we insert the new
450 * one, but don't unref yet because the hash is still storing a reference to * it. */
451 registry->features = g_list_remove (registry->features, existing_feature);
454 GST_DEBUG_OBJECT (registry, "adding feature %p (%s)", feature, feature->name);
456 registry->features = g_list_prepend (registry->features, feature);
457 g_hash_table_replace (registry->feature_hash, feature->name, feature);
459 if (G_UNLIKELY (existing_feature)) {
460 /* We unref now. No need to remove the feature name from the hash table, it * got replaced by the new feature */
461 gst_object_unref (existing_feature);
464 gst_object_ref (feature);
465 gst_object_sink (feature);
466 GST_OBJECT_UNLOCK (registry);
468 GST_LOG_OBJECT (registry, "emitting feature-added for %s", feature->name);
469 g_signal_emit (G_OBJECT (registry), gst_registry_signals[FEATURE_ADDED], 0,
476 * gst_registry_remove_feature:
477 * @registry: the registry to remove the feature from
478 * @feature: the feature to remove
480 * Remove the feature from the registry.
485 gst_registry_remove_feature (GstRegistry * registry, GstPluginFeature * feature)
487 g_return_if_fail (GST_IS_REGISTRY (registry));
488 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
490 GST_DEBUG_OBJECT (registry, "removing feature %p (%s)",
491 feature, gst_plugin_feature_get_name (feature));
493 GST_OBJECT_LOCK (registry);
494 registry->features = g_list_remove (registry->features, feature);
495 g_hash_table_remove (registry->feature_hash, feature->name);
496 GST_OBJECT_UNLOCK (registry);
497 gst_object_unref (feature);
501 * gst_registry_plugin_filter:
502 * @registry: registry to query
503 * @filter: the filter to use
504 * @first: only return first match
505 * @user_data: user data passed to the filter function
507 * Runs a filter against all plugins in the registry and returns a #GList with
508 * the results. If the first flag is set, only the first match is
509 * returned (as a list with a single object).
510 * Every plugin is reffed; use gst_plugin_list_free() after use, which
513 * Returns: a #GList of #GstPlugin. Use gst_plugin_list_free() after usage.
518 gst_registry_plugin_filter (GstRegistry * registry,
519 GstPluginFilter filter, gboolean first, gpointer user_data)
524 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
526 GST_OBJECT_LOCK (registry);
527 list = gst_filter_run (registry->plugins, (GstFilterFunc) filter, first,
529 for (g = list; g; g = g->next) {
530 gst_object_ref (GST_PLUGIN_CAST (g->data));
532 GST_OBJECT_UNLOCK (registry);
538 * gst_registry_feature_filter:
539 * @registry: registry to query
540 * @filter: the filter to use
541 * @first: only return first match
542 * @user_data: user data passed to the filter function
544 * Runs a filter against all features of the plugins in the registry
545 * and returns a GList with the results.
546 * If the first flag is set, only the first match is
547 * returned (as a list with a single object).
549 * Returns: a #GList of #GstPluginFeature. Use gst_plugin_feature_list_free()
555 gst_registry_feature_filter (GstRegistry * registry,
556 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
561 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
563 GST_OBJECT_LOCK (registry);
564 list = gst_filter_run (registry->features, (GstFilterFunc) filter, first,
566 for (g = list; g; g = g->next) {
567 gst_object_ref (GST_PLUGIN_FEATURE_CAST (g->data));
569 GST_OBJECT_UNLOCK (registry);
575 * gst_registry_find_plugin:
576 * @registry: the registry to search
577 * @name: the plugin name to find
579 * Find the plugin with the given name in the registry.
580 * The plugin will be reffed; caller is responsible for unreffing.
582 * Returns: The plugin with the given name or NULL if the plugin was not found.
583 * gst_object_unref() after usage.
588 gst_registry_find_plugin (GstRegistry * registry, const gchar * name)
591 GstPlugin *result = NULL;
593 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
594 g_return_val_if_fail (name != NULL, NULL);
596 walk = gst_registry_plugin_filter (registry,
597 (GstPluginFilter) gst_plugin_name_filter, TRUE, (gpointer) name);
599 result = GST_PLUGIN_CAST (walk->data);
601 gst_object_ref (result);
602 gst_plugin_list_free (walk);
609 * gst_registry_find_feature:
610 * @registry: the registry to search
611 * @name: the pluginfeature name to find
612 * @type: the pluginfeature type to find
614 * Find the pluginfeature with the given name and type in the registry.
616 * Returns: The pluginfeature with the given name and type or NULL
617 * if the plugin was not found. gst_object_unref() after usage.
622 gst_registry_find_feature (GstRegistry * registry, const gchar * name,
625 GstPluginFeature *feature = NULL;
627 GstTypeNameData data;
629 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
630 g_return_val_if_fail (name != NULL, NULL);
631 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_PLUGIN_FEATURE), NULL);
636 walk = gst_registry_feature_filter (registry,
637 (GstPluginFeatureFilter) gst_plugin_feature_type_name_filter,
641 feature = GST_PLUGIN_FEATURE_CAST (walk->data);
643 gst_object_ref (feature);
644 gst_plugin_feature_list_free (walk);
651 * gst_registry_get_feature_list:
652 * @registry: a #GstRegistry
655 * Retrieves a #GList of #GstPluginFeature of @type.
657 * Returns: a #GList of #GstPluginFeature of @type. Use
658 * gst_plugin_feature_list_free() after usage.
663 gst_registry_get_feature_list (GstRegistry * registry, GType type)
665 GstTypeNameData data;
667 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
668 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_PLUGIN_FEATURE), NULL);
673 return gst_registry_feature_filter (registry,
674 (GstPluginFeatureFilter) gst_plugin_feature_type_name_filter,
679 * gst_registry_get_plugin_list:
680 * @registry: the registry to search
682 * Get a copy of all plugins registered in the given registry. The refcount
683 * of each element in the list in incremented.
685 * Returns: a #GList of #GstPlugin. Use gst_plugin_list_free() after usage.
690 gst_registry_get_plugin_list (GstRegistry * registry)
695 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
697 GST_OBJECT_LOCK (registry);
698 list = g_list_copy (registry->plugins);
699 for (g = list; g; g = g->next) {
700 gst_object_ref (GST_PLUGIN_CAST (g->data));
702 GST_OBJECT_UNLOCK (registry);
707 static GstPluginFeature *
708 gst_registry_lookup_feature_locked (GstRegistry * registry, const char *name)
710 if (G_UNLIKELY (name == NULL))
713 return g_hash_table_lookup (registry->feature_hash, name);
717 * gst_registry_lookup_feature:
718 * @registry: a #GstRegistry
719 * @name: a #GstPluginFeature name
721 * Find a #GstPluginFeature with @name in @registry.
723 * Returns: a #GstPluginFeature with its refcount incremented, use
724 * gst_object_unref() after usage.
729 gst_registry_lookup_feature (GstRegistry * registry, const char *name)
731 GstPluginFeature *feature;
733 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
734 g_return_val_if_fail (name != NULL, NULL);
736 GST_OBJECT_LOCK (registry);
737 feature = gst_registry_lookup_feature_locked (registry, name);
739 gst_object_ref (feature);
740 GST_OBJECT_UNLOCK (registry);
746 gst_registry_lookup_locked (GstRegistry * registry, const char *filename)
752 if (G_UNLIKELY (filename == NULL))
755 basename = g_path_get_basename (filename);
756 /* FIXME: use GTree speed up lookups */
757 for (g = registry->plugins; g; g = g_list_next (g)) {
758 plugin = GST_PLUGIN_CAST (g->data);
759 if (plugin->basename && strcmp (basename, plugin->basename) == 0) {
770 * gst_registry_lookup:
771 * @registry: the registry to look up in
772 * @filename: the name of the file to look up
774 * Look up a plugin in the given registry with the given filename.
775 * If found, plugin is reffed.
777 * Returns: the #GstPlugin if found, or NULL if not. gst_object_unref()
781 gst_registry_lookup (GstRegistry * registry, const char *filename)
785 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
786 g_return_val_if_fail (filename != NULL, NULL);
788 GST_OBJECT_LOCK (registry);
789 plugin = gst_registry_lookup_locked (registry, filename);
791 gst_object_ref (plugin);
792 GST_OBJECT_UNLOCK (registry);
798 gst_registry_scan_path_level (GstRegistry * registry, const gchar * path,
805 GstPlugin *newplugin;
806 gboolean changed = FALSE;
808 dir = g_dir_open (path, 0, NULL);
812 while ((dirent = g_dir_read_name (dir))) {
813 struct stat file_status;
815 filename = g_strjoin ("/", path, dirent, NULL);
816 if (g_stat (filename, &file_status) < 0) {
817 /* Plugin will be removed from cache after the scan completes if it
818 * is still marked 'cached' */
823 if (file_status.st_mode & S_IFDIR) {
824 /* skip the .debug directory, these contain elf files that are not
825 * useful or worse, can crash dlopen () */
826 if (g_str_equal (dirent, ".debug") || g_str_equal (dirent, ".git")) {
827 GST_LOG_OBJECT (registry, "ignoring .debug or .git directory");
831 /* FIXME 0.11: Don't recurse into directories, this behaviour
832 * is inconsistent with other PATH environment variables
835 GST_LOG_OBJECT (registry, "recursing into directory %s", filename);
836 changed |= gst_registry_scan_path_level (registry, filename, level - 1);
838 GST_LOG_OBJECT (registry, "not recursing into directory %s, "
839 "recursion level too deep", filename);
844 if (!(file_status.st_mode & S_IFREG)) {
845 GST_LOG_OBJECT (registry, "%s is not a regular file, ignoring", filename);
849 if (!g_str_has_suffix (dirent, G_MODULE_SUFFIX)
850 #ifdef GST_EXTRA_MODULE_SUFFIX
851 && !g_str_has_suffix (dirent, GST_EXTRA_MODULE_SUFFIX)
854 GST_LOG_OBJECT (registry, "extension is not recognized as module file, "
855 "ignoring file %s", filename);
860 GST_LOG_OBJECT (registry, "file %s looks like a possible module", filename);
862 /* plug-ins are considered unique by basename; if the given name
863 * was already seen by the registry, we ignore it */
864 plugin = gst_registry_lookup (registry, filename);
866 gboolean env_vars_changed, deps_changed = FALSE;
868 if (plugin->registered) {
869 GST_DEBUG_OBJECT (registry,
870 "plugin already registered from path \"%s\"",
871 GST_STR_NULL (plugin->filename));
873 gst_object_unref (plugin);
877 env_vars_changed = _priv_plugin_deps_env_vars_changed (plugin);
879 if (plugin->file_mtime == file_status.st_mtime &&
880 plugin->file_size == file_status.st_size && !env_vars_changed &&
881 !(deps_changed = _priv_plugin_deps_files_changed (plugin))) {
882 GST_LOG_OBJECT (registry, "file %s cached", filename);
883 plugin->flags &= ~GST_PLUGIN_FLAG_CACHED;
884 GST_LOG_OBJECT (registry, "marking plugin %p as registered as %s",
886 plugin->registered = TRUE;
887 /* Update the file path on which we've seen this cached plugin
888 * to ensure the registry cache will reflect up to date information */
889 if (strcmp (plugin->filename, filename) != 0) {
890 g_free (plugin->filename);
891 plugin->filename = g_strdup (filename);
895 GST_INFO_OBJECT (registry, "cached info for %s is stale", filename);
896 GST_DEBUG_OBJECT (registry, "mtime %ld != %ld or size %"
897 G_GINT64_FORMAT " != %" G_GINT64_FORMAT " or external dependency "
898 "env_vars changed: %d or external dependencies changed: %d",
899 plugin->file_mtime, file_status.st_mtime,
900 (gint64) plugin->file_size, (gint64) file_status.st_size,
901 env_vars_changed, deps_changed);
902 gst_registry_remove_plugin (gst_registry_get_default (), plugin);
903 /* We don't use a GError here because a failure to load some shared
904 * objects as plugins is normal (particularly in the uninstalled case)
906 newplugin = gst_plugin_load_file (filename, NULL);
908 GST_DEBUG_OBJECT (registry, "marking new plugin %p as registered",
910 newplugin->registered = TRUE;
911 gst_object_unref (newplugin);
915 gst_object_unref (plugin);
918 GST_DEBUG_OBJECT (registry, "file %s not yet in registry", filename);
919 newplugin = gst_plugin_load_file (filename, NULL);
921 newplugin->registered = TRUE;
922 gst_object_unref (newplugin);
936 * gst_registry_scan_path:
937 * @registry: the registry to add the path to
938 * @path: the path to add to the registry
940 * Add the given path to the registry. The syntax of the
941 * path is specific to the registry. If the path has already been
944 * Returns: %TRUE if registry changed
947 gst_registry_scan_path (GstRegistry * registry, const gchar * path)
951 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
952 g_return_val_if_fail (path != NULL, FALSE);
954 GST_DEBUG_OBJECT (registry, "scanning path %s", path);
955 changed = gst_registry_scan_path_level (registry, path, 10);
957 GST_DEBUG_OBJECT (registry, "registry changed in path %s: %d", path, changed);
962 /* Unref all plugins marked 'cached', to clear old plugins that no
963 * longer exist. Returns TRUE if any plugins were removed */
965 _priv_gst_registry_remove_cache_plugins (GstRegistry * registry)
970 gboolean changed = FALSE;
972 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
974 GST_OBJECT_LOCK (registry);
976 GST_DEBUG_OBJECT (registry, "removing cached plugins");
977 g = registry->plugins;
981 if (plugin->flags & GST_PLUGIN_FLAG_CACHED) {
982 GST_DEBUG_OBJECT (registry, "removing cached plugin \"%s\"",
983 GST_STR_NULL (plugin->filename));
984 registry->plugins = g_list_delete_link (registry->plugins, g);
985 gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
986 gst_object_unref (plugin);
992 GST_OBJECT_UNLOCK (registry);
999 _gst_plugin_feature_filter_plugin_name (GstPluginFeature * feature,
1002 return (strcmp (feature->plugin_name, (gchar *) user_data) == 0);
1006 * gst_registry_get_feature_list_by_plugin:
1007 * @registry: a #GstRegistry.
1008 * @name: a plugin name.
1010 * Retrieves a #GList of features of the plugin with name @name.
1012 * Returns: a #GList of #GstPluginFeature. Use gst_plugin_feature_list_free()
1016 gst_registry_get_feature_list_by_plugin (GstRegistry * registry,
1019 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1020 g_return_val_if_fail (name != NULL, NULL);
1022 return gst_registry_feature_filter (registry,
1023 _gst_plugin_feature_filter_plugin_name, FALSE, (gpointer) name);
1026 /* Unref and delete the default registry */
1028 _priv_gst_registry_cleanup ()
1030 GstRegistry *registry;
1032 g_static_mutex_lock (&_gst_registry_mutex);
1033 if ((registry = _gst_registry_default) != NULL) {
1034 _gst_registry_default = NULL;
1036 g_static_mutex_unlock (&_gst_registry_mutex);
1038 /* unref outside of the lock because we can. */
1040 gst_object_unref (registry);
1044 * gst_default_registry_check_feature_version:
1045 * @feature_name: the name of the feature (e.g. "oggdemux")
1046 * @min_major: the minimum major version number
1047 * @min_minor: the minimum minor version number
1048 * @min_micro: the minimum micro version number
1050 * Checks whether a plugin feature by the given name exists in the
1051 * default registry and whether its version is at least the
1054 * Returns: #TRUE if the feature could be found and the version is
1055 * the same as the required version or newer, and #FALSE otherwise.
1058 gst_default_registry_check_feature_version (const gchar * feature_name,
1059 guint min_major, guint min_minor, guint min_micro)
1061 GstPluginFeature *feature;
1062 GstRegistry *registry;
1063 gboolean ret = FALSE;
1065 g_return_val_if_fail (feature_name != NULL, FALSE);
1067 GST_DEBUG ("Looking up plugin feature '%s'", feature_name);
1069 registry = gst_registry_get_default ();
1070 feature = gst_registry_lookup_feature (registry, feature_name);
1072 ret = gst_plugin_feature_check_version (feature, min_major, min_minor,
1074 gst_object_unref (feature);
1076 GST_DEBUG ("Could not find plugin feature '%s'", feature_name);