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_sink (GST_OBJECT_CAST (_gst_registry_default));
246 registry = _gst_registry_default;
247 g_static_mutex_unlock (&_gst_registry_mutex);
253 * gst_registry_add_path:
254 * @registry: the registry to add the path to
255 * @path: the path to add to the registry
257 * Add the given path to the registry. The syntax of the
258 * path is specific to the registry. If the path has already been
262 gst_registry_add_path (GstRegistry * registry, const gchar * path)
264 g_return_if_fail (GST_IS_REGISTRY (registry));
265 g_return_if_fail (path != NULL);
267 if (strlen (path) == 0)
270 GST_OBJECT_LOCK (registry);
271 if (g_list_find_custom (registry->paths, path, (GCompareFunc) strcmp))
274 GST_INFO ("Adding plugin path: \"%s\"", path);
275 registry->paths = g_list_append (registry->paths, g_strdup (path));
276 GST_OBJECT_UNLOCK (registry);
282 GST_INFO ("Ignoring empty plugin path");
287 g_warning ("path %s already added to registry", path);
288 GST_OBJECT_UNLOCK (registry);
294 * gst_registry_get_path_list:
295 * @registry: the registry to get the pathlist of
297 * Get the list of paths for the given registry.
299 * Returns: A Glist of paths as strings. g_list_free after use.
304 gst_registry_get_path_list (GstRegistry * registry)
308 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
310 GST_OBJECT_LOCK (registry);
311 /* We don't need to copy the strings, because they won't be deleted
312 * as long as the GstRegistry is around */
313 list = g_list_copy (registry->paths);
314 GST_OBJECT_UNLOCK (registry);
321 * gst_registry_add_plugin:
322 * @registry: the registry to add the plugin to
323 * @plugin: the plugin to add
325 * Add the plugin to the registry. The plugin-added signal will be emitted.
326 * This function will sink @plugin.
328 * Returns: TRUE on success.
333 gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin)
335 GstPlugin *existing_plugin;
337 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
338 g_return_val_if_fail (GST_IS_PLUGIN (plugin), FALSE);
340 GST_OBJECT_LOCK (registry);
341 existing_plugin = gst_registry_lookup_locked (registry, plugin->filename);
342 if (G_UNLIKELY (existing_plugin)) {
343 GST_DEBUG_OBJECT (registry,
344 "Replacing existing plugin %p with new plugin %p for filename \"%s\"",
345 existing_plugin, plugin, GST_STR_NULL (plugin->filename));
346 registry->plugins = g_list_remove (registry->plugins, existing_plugin);
347 gst_object_unref (existing_plugin);
350 GST_DEBUG_OBJECT (registry, "adding plugin %p for filename \"%s\"",
351 plugin, GST_STR_NULL (plugin->filename));
353 registry->plugins = g_list_prepend (registry->plugins, plugin);
355 gst_object_ref_sink (plugin);
356 GST_OBJECT_UNLOCK (registry);
358 GST_LOG_OBJECT (registry, "emitting plugin-added for filename \"%s\"",
359 GST_STR_NULL (plugin->filename));
360 g_signal_emit (registry, gst_registry_signals[PLUGIN_ADDED], 0, plugin);
366 gst_registry_remove_features_for_plugin_unlocked (GstRegistry * registry,
372 g_return_if_fail (GST_IS_REGISTRY (registry));
373 g_return_if_fail (GST_IS_PLUGIN (plugin));
375 name = gst_plugin_get_name (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, name)) {
384 GST_DEBUG_OBJECT (registry, "removing feature %p (%s) for plugin %s",
385 feature, gst_plugin_feature_get_name (feature), name);
387 registry->features = g_list_delete_link (registry->features, f);
388 g_hash_table_remove (registry->feature_hash, feature->name);
389 gst_object_unref (feature);
396 * gst_registry_remove_plugin:
397 * @registry: the registry to remove the plugin from
398 * @plugin: the plugin to remove
400 * Remove the plugin from the registry.
405 gst_registry_remove_plugin (GstRegistry * registry, GstPlugin * plugin)
407 g_return_if_fail (GST_IS_REGISTRY (registry));
408 g_return_if_fail (GST_IS_PLUGIN (plugin));
410 GST_DEBUG_OBJECT (registry, "removing plugin %p (%s)",
411 plugin, gst_plugin_get_name (plugin));
413 GST_OBJECT_LOCK (registry);
414 registry->plugins = g_list_remove (registry->plugins, plugin);
415 gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
416 GST_OBJECT_UNLOCK (registry);
417 gst_object_unref (plugin);
421 * gst_registry_add_feature:
422 * @registry: the registry to add the plugin to
423 * @feature: the feature to add
425 * Add the feature to the registry. The feature-added signal will be emitted.
426 * This function sinks @feature.
428 * Returns: TRUE on success.
433 gst_registry_add_feature (GstRegistry * registry, GstPluginFeature * feature)
435 GstPluginFeature *existing_feature;
437 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
438 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
439 g_return_val_if_fail (feature->name != NULL, FALSE);
440 g_return_val_if_fail (feature->plugin_name != NULL, FALSE);
442 GST_OBJECT_LOCK (registry);
443 existing_feature = gst_registry_lookup_feature_locked (registry,
445 if (G_UNLIKELY (existing_feature)) {
446 GST_DEBUG_OBJECT (registry, "replacing existing feature %p (%s)",
447 existing_feature, feature->name);
448 /* Remove the existing feature from the list now, before we insert the new
449 * one, but don't unref yet because the hash is still storing a reference to * it. */
450 registry->features = g_list_remove (registry->features, existing_feature);
453 GST_DEBUG_OBJECT (registry, "adding feature %p (%s)", feature, feature->name);
455 registry->features = g_list_prepend (registry->features, feature);
456 g_hash_table_replace (registry->feature_hash, feature->name, feature);
458 if (G_UNLIKELY (existing_feature)) {
459 /* We unref now. No need to remove the feature name from the hash table, it * got replaced by the new feature */
460 gst_object_unref (existing_feature);
463 gst_object_ref_sink (feature);
464 GST_OBJECT_UNLOCK (registry);
466 GST_LOG_OBJECT (registry, "emitting feature-added for %s", feature->name);
467 g_signal_emit (registry, gst_registry_signals[FEATURE_ADDED], 0, feature);
473 * gst_registry_remove_feature:
474 * @registry: the registry to remove the feature from
475 * @feature: the feature to remove
477 * Remove the feature from the registry.
482 gst_registry_remove_feature (GstRegistry * registry, GstPluginFeature * feature)
484 g_return_if_fail (GST_IS_REGISTRY (registry));
485 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
487 GST_DEBUG_OBJECT (registry, "removing feature %p (%s)",
488 feature, gst_plugin_feature_get_name (feature));
490 GST_OBJECT_LOCK (registry);
491 registry->features = g_list_remove (registry->features, feature);
492 g_hash_table_remove (registry->feature_hash, feature->name);
493 GST_OBJECT_UNLOCK (registry);
494 gst_object_unref (feature);
498 * gst_registry_plugin_filter:
499 * @registry: registry to query
500 * @filter: the filter to use
501 * @first: only return first match
502 * @user_data: user data passed to the filter function
504 * Runs a filter against all plugins in the registry and returns a #GList with
505 * the results. If the first flag is set, only the first match is
506 * returned (as a list with a single object).
507 * Every plugin is reffed; use gst_plugin_list_free() after use, which
510 * Returns: a #GList of #GstPlugin. Use gst_plugin_list_free() after usage.
515 gst_registry_plugin_filter (GstRegistry * registry,
516 GstPluginFilter filter, gboolean first, gpointer user_data)
521 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
523 GST_OBJECT_LOCK (registry);
524 list = gst_filter_run (registry->plugins, (GstFilterFunc) filter, first,
526 for (g = list; g; g = g->next) {
527 gst_object_ref (GST_PLUGIN_CAST (g->data));
529 GST_OBJECT_UNLOCK (registry);
535 * gst_registry_feature_filter:
536 * @registry: registry to query
537 * @filter: the filter to use
538 * @first: only return first match
539 * @user_data: user data passed to the filter function
541 * Runs a filter against all features of the plugins in the registry
542 * and returns a GList with the results.
543 * If the first flag is set, only the first match is
544 * returned (as a list with a single object).
546 * Returns: a #GList of #GstPluginFeature. Use gst_plugin_feature_list_free()
552 gst_registry_feature_filter (GstRegistry * registry,
553 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
558 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
560 GST_OBJECT_LOCK (registry);
561 list = gst_filter_run (registry->features, (GstFilterFunc) filter, first,
563 for (g = list; g; g = g->next) {
564 gst_object_ref (GST_PLUGIN_FEATURE_CAST (g->data));
566 GST_OBJECT_UNLOCK (registry);
572 * gst_registry_find_plugin:
573 * @registry: the registry to search
574 * @name: the plugin name to find
576 * Find the plugin with the given name in the registry.
577 * The plugin will be reffed; caller is responsible for unreffing.
579 * Returns: The plugin with the given name or NULL if the plugin was not found.
580 * gst_object_unref() after usage.
585 gst_registry_find_plugin (GstRegistry * registry, const gchar * name)
588 GstPlugin *result = NULL;
590 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
591 g_return_val_if_fail (name != NULL, NULL);
593 walk = gst_registry_plugin_filter (registry,
594 (GstPluginFilter) gst_plugin_name_filter, TRUE, (gpointer) name);
596 result = GST_PLUGIN_CAST (walk->data);
598 gst_object_ref (result);
599 gst_plugin_list_free (walk);
606 * gst_registry_find_feature:
607 * @registry: the registry to search
608 * @name: the pluginfeature name to find
609 * @type: the pluginfeature type to find
611 * Find the pluginfeature with the given name and type in the registry.
613 * Returns: The pluginfeature with the given name and type or NULL
614 * if the plugin was not found. gst_object_unref() after usage.
619 gst_registry_find_feature (GstRegistry * registry, const gchar * name,
622 GstPluginFeature *feature = NULL;
624 GstTypeNameData data;
626 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
627 g_return_val_if_fail (name != NULL, NULL);
628 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_PLUGIN_FEATURE), NULL);
633 walk = gst_registry_feature_filter (registry,
634 (GstPluginFeatureFilter) gst_plugin_feature_type_name_filter,
638 feature = GST_PLUGIN_FEATURE_CAST (walk->data);
640 gst_object_ref (feature);
641 gst_plugin_feature_list_free (walk);
648 * gst_registry_get_feature_list:
649 * @registry: a #GstRegistry
652 * Retrieves a #GList of #GstPluginFeature of @type.
654 * Returns: a #GList of #GstPluginFeature of @type. Use
655 * gst_plugin_feature_list_free() after usage.
660 gst_registry_get_feature_list (GstRegistry * registry, GType type)
662 GstTypeNameData data;
664 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
665 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_PLUGIN_FEATURE), NULL);
670 return gst_registry_feature_filter (registry,
671 (GstPluginFeatureFilter) gst_plugin_feature_type_name_filter,
676 * gst_registry_get_plugin_list:
677 * @registry: the registry to search
679 * Get a copy of all plugins registered in the given registry. The refcount
680 * of each element in the list in incremented.
682 * Returns: a #GList of #GstPlugin. Use gst_plugin_list_free() after usage.
687 gst_registry_get_plugin_list (GstRegistry * registry)
692 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
694 GST_OBJECT_LOCK (registry);
695 list = g_list_copy (registry->plugins);
696 for (g = list; g; g = g->next) {
697 gst_object_ref (GST_PLUGIN_CAST (g->data));
699 GST_OBJECT_UNLOCK (registry);
704 static GstPluginFeature *
705 gst_registry_lookup_feature_locked (GstRegistry * registry, const char *name)
707 if (G_UNLIKELY (name == NULL))
710 return g_hash_table_lookup (registry->feature_hash, name);
714 * gst_registry_lookup_feature:
715 * @registry: a #GstRegistry
716 * @name: a #GstPluginFeature name
718 * Find a #GstPluginFeature with @name in @registry.
720 * Returns: a #GstPluginFeature with its refcount incremented, use
721 * gst_object_unref() after usage.
726 gst_registry_lookup_feature (GstRegistry * registry, const char *name)
728 GstPluginFeature *feature;
730 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
731 g_return_val_if_fail (name != NULL, NULL);
733 GST_OBJECT_LOCK (registry);
734 feature = gst_registry_lookup_feature_locked (registry, name);
736 gst_object_ref (feature);
737 GST_OBJECT_UNLOCK (registry);
743 gst_registry_lookup_locked (GstRegistry * registry, const char *filename)
749 if (G_UNLIKELY (filename == NULL))
752 basename = g_path_get_basename (filename);
753 /* FIXME: use GTree speed up lookups */
754 for (g = registry->plugins; g; g = g_list_next (g)) {
755 plugin = GST_PLUGIN_CAST (g->data);
756 if (plugin->basename && strcmp (basename, plugin->basename) == 0) {
767 * gst_registry_lookup:
768 * @registry: the registry to look up in
769 * @filename: the name of the file to look up
771 * Look up a plugin in the given registry with the given filename.
772 * If found, plugin is reffed.
774 * Returns: the #GstPlugin if found, or NULL if not. gst_object_unref()
778 gst_registry_lookup (GstRegistry * registry, const char *filename)
782 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
783 g_return_val_if_fail (filename != NULL, NULL);
785 GST_OBJECT_LOCK (registry);
786 plugin = gst_registry_lookup_locked (registry, filename);
788 gst_object_ref (plugin);
789 GST_OBJECT_UNLOCK (registry);
795 gst_registry_scan_path_level (GstRegistry * registry, const gchar * path,
802 GstPlugin *newplugin;
803 gboolean changed = FALSE;
805 dir = g_dir_open (path, 0, NULL);
809 while ((dirent = g_dir_read_name (dir))) {
810 struct stat file_status;
812 filename = g_strjoin ("/", path, dirent, NULL);
813 if (g_stat (filename, &file_status) < 0) {
814 /* Plugin will be removed from cache after the scan completes if it
815 * is still marked 'cached' */
820 if (file_status.st_mode & S_IFDIR) {
821 /* skip the .debug directory, these contain elf files that are not
822 * useful or worse, can crash dlopen () */
823 if (g_str_equal (dirent, ".debug") || g_str_equal (dirent, ".git")) {
824 GST_LOG_OBJECT (registry, "ignoring .debug or .git directory");
828 /* FIXME 0.11: Don't recurse into directories, this behaviour
829 * is inconsistent with other PATH environment variables
832 GST_LOG_OBJECT (registry, "recursing into directory %s", filename);
833 changed |= gst_registry_scan_path_level (registry, filename, level - 1);
835 GST_LOG_OBJECT (registry, "not recursing into directory %s, "
836 "recursion level too deep", filename);
841 if (!(file_status.st_mode & S_IFREG)) {
842 GST_LOG_OBJECT (registry, "%s is not a regular file, ignoring", filename);
846 if (!g_str_has_suffix (dirent, G_MODULE_SUFFIX)
847 #ifdef GST_EXTRA_MODULE_SUFFIX
848 && !g_str_has_suffix (dirent, GST_EXTRA_MODULE_SUFFIX)
851 GST_LOG_OBJECT (registry, "extension is not recognized as module file, "
852 "ignoring file %s", filename);
857 GST_LOG_OBJECT (registry, "file %s looks like a possible module", filename);
859 /* plug-ins are considered unique by basename; if the given name
860 * was already seen by the registry, we ignore it */
861 plugin = gst_registry_lookup (registry, filename);
863 gboolean env_vars_changed, deps_changed = FALSE;
865 if (plugin->registered) {
866 GST_DEBUG_OBJECT (registry,
867 "plugin already registered from path \"%s\"",
868 GST_STR_NULL (plugin->filename));
870 gst_object_unref (plugin);
874 env_vars_changed = _priv_plugin_deps_env_vars_changed (plugin);
876 if (plugin->file_mtime == file_status.st_mtime &&
877 plugin->file_size == file_status.st_size && !env_vars_changed &&
878 !(deps_changed = _priv_plugin_deps_files_changed (plugin))) {
879 GST_LOG_OBJECT (registry, "file %s cached", filename);
880 plugin->flags &= ~GST_PLUGIN_FLAG_CACHED;
881 GST_LOG_OBJECT (registry, "marking plugin %p as registered as %s",
883 plugin->registered = TRUE;
884 /* Update the file path on which we've seen this cached plugin
885 * to ensure the registry cache will reflect up to date information */
886 if (strcmp (plugin->filename, filename) != 0) {
887 g_free (plugin->filename);
888 plugin->filename = g_strdup (filename);
892 GST_INFO_OBJECT (registry, "cached info for %s is stale", filename);
893 GST_DEBUG_OBJECT (registry, "mtime %ld != %ld or size %"
894 G_GINT64_FORMAT " != %" G_GINT64_FORMAT " or external dependency "
895 "env_vars changed: %d or external dependencies changed: %d",
896 plugin->file_mtime, file_status.st_mtime,
897 (gint64) plugin->file_size, (gint64) file_status.st_size,
898 env_vars_changed, deps_changed);
899 gst_registry_remove_plugin (gst_registry_get_default (), plugin);
900 /* We don't use a GError here because a failure to load some shared
901 * objects as plugins is normal (particularly in the uninstalled case)
903 newplugin = gst_plugin_load_file (filename, NULL);
905 GST_DEBUG_OBJECT (registry, "marking new plugin %p as registered",
907 newplugin->registered = TRUE;
908 gst_object_unref (newplugin);
912 gst_object_unref (plugin);
915 GST_DEBUG_OBJECT (registry, "file %s not yet in registry", filename);
916 newplugin = gst_plugin_load_file (filename, NULL);
918 newplugin->registered = TRUE;
919 gst_object_unref (newplugin);
933 * gst_registry_scan_path:
934 * @registry: the registry to add the path to
935 * @path: the path to add to the registry
937 * Add the given path to the registry. The syntax of the
938 * path is specific to the registry. If the path has already been
941 * Returns: %TRUE if registry changed
944 gst_registry_scan_path (GstRegistry * registry, const gchar * path)
948 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
949 g_return_val_if_fail (path != NULL, FALSE);
951 GST_DEBUG_OBJECT (registry, "scanning path %s", path);
952 changed = gst_registry_scan_path_level (registry, path, 10);
954 GST_DEBUG_OBJECT (registry, "registry changed in path %s: %d", path, changed);
959 /* Unref all plugins marked 'cached', to clear old plugins that no
960 * longer exist. Returns TRUE if any plugins were removed */
962 _priv_gst_registry_remove_cache_plugins (GstRegistry * registry)
967 gboolean changed = FALSE;
969 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
971 GST_OBJECT_LOCK (registry);
973 GST_DEBUG_OBJECT (registry, "removing cached plugins");
974 g = registry->plugins;
978 if (plugin->flags & GST_PLUGIN_FLAG_CACHED) {
979 GST_DEBUG_OBJECT (registry, "removing cached plugin \"%s\"",
980 GST_STR_NULL (plugin->filename));
981 registry->plugins = g_list_delete_link (registry->plugins, g);
982 gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
983 gst_object_unref (plugin);
989 GST_OBJECT_UNLOCK (registry);
996 _gst_plugin_feature_filter_plugin_name (GstPluginFeature * feature,
999 return (strcmp (feature->plugin_name, (gchar *) user_data) == 0);
1003 * gst_registry_get_feature_list_by_plugin:
1004 * @registry: a #GstRegistry.
1005 * @name: a plugin name.
1007 * Retrieves a #GList of features of the plugin with name @name.
1009 * Returns: a #GList of #GstPluginFeature. Use gst_plugin_feature_list_free()
1013 gst_registry_get_feature_list_by_plugin (GstRegistry * registry,
1016 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
1017 g_return_val_if_fail (name != NULL, NULL);
1019 return gst_registry_feature_filter (registry,
1020 _gst_plugin_feature_filter_plugin_name, FALSE, (gpointer) name);
1023 /* Unref and delete the default registry */
1025 _priv_gst_registry_cleanup ()
1027 GstRegistry *registry;
1029 g_static_mutex_lock (&_gst_registry_mutex);
1030 if ((registry = _gst_registry_default) != NULL) {
1031 _gst_registry_default = NULL;
1033 g_static_mutex_unlock (&_gst_registry_mutex);
1035 /* unref outside of the lock because we can. */
1037 gst_object_unref (registry);
1041 * gst_default_registry_check_feature_version:
1042 * @feature_name: the name of the feature (e.g. "oggdemux")
1043 * @min_major: the minimum major version number
1044 * @min_minor: the minimum minor version number
1045 * @min_micro: the minimum micro version number
1047 * Checks whether a plugin feature by the given name exists in the
1048 * default registry and whether its version is at least the
1051 * Returns: #TRUE if the feature could be found and the version is
1052 * the same as the required version or newer, and #FALSE otherwise.
1055 gst_default_registry_check_feature_version (const gchar * feature_name,
1056 guint min_major, guint min_minor, guint min_micro)
1058 GstPluginFeature *feature;
1059 GstRegistry *registry;
1060 gboolean ret = FALSE;
1062 g_return_val_if_fail (feature_name != NULL, FALSE);
1064 GST_DEBUG ("Looking up plugin feature '%s'", feature_name);
1066 registry = gst_registry_get_default ();
1067 feature = gst_registry_lookup_feature (registry, feature_name);
1069 ret = gst_plugin_feature_check_version (feature, min_major, min_minor,
1071 gst_object_unref (feature);
1073 GST_DEBUG ("Could not find plugin feature '%s'", feature_name);