diff options
Diffstat (limited to 'gst/gstregistry.c')
-rw-r--r-- | gst/gstregistry.c | 253 |
1 files changed, 160 insertions, 93 deletions
diff --git a/gst/gstregistry.c b/gst/gstregistry.c index 345068e..6f41dcf 100644 --- a/gst/gstregistry.c +++ b/gst/gstregistry.c @@ -32,13 +32,7 @@ * * The #GstRegistry object is a list of plugins and some functions for dealing * with them. Each #GstPlugin is matched 1-1 with a file on disk, and may or may - * not be loaded at a given time. There may be multiple #GstRegistry objects, - * but the "default registry" is the only object that has any meaning to the - * core. - * - * The registry file is actually a cache of plugin information. This is - * unlike versions prior to 0.10, where the registry file was the primary source - * of plugin information, and was created by the gst-register command. + * not be loaded at a given time. * * The primary source, at all times, of plugin information is each plugin file * itself. Thus, if an application wants information about a particular plugin, @@ -63,13 +57,13 @@ * <listitem> * <para>default locations (if GST_PLUGIN_SYSTEM_PATH is not set). Those * default locations are: - * <filename>~/.gstreamer-$GST_MAJORMINOR/plugins/</filename> - * and <filename>$prefix/libs/gstreamer-$GST_MAJORMINOR/</filename>. + * <filename>~/.gstreamer-$GST_API_VERSION/plugins/</filename> + * and <filename>$prefix/libs/gstreamer-$GST_API_VERSION/</filename>. * </para> * </listitem> * </itemizedlist> * The registry cache file is loaded from - * <filename>~/.gstreamer-$GST_MAJORMINOR/registry-$ARCH.bin</filename> or the + * <filename>~/.gstreamer-$GST_API_VERSION/registry-$ARCH.bin</filename> or the * file listed in the GST_REGISTRY env var. One reason to change the registry * location is for testing. * @@ -99,11 +93,13 @@ * * <emphasis role="bold">Implementation notes:</emphasis> * - * The "cache" and "default registry" are different concepts and can represent + * The "cache" and "registry" are different concepts and can represent * different sets of plugins. For various reasons, at init time, the cache is * stored in the default registry, and plugins not relevant to the current * process are marked with the %GST_PLUGIN_FLAG_CACHED bit. These plugins are * removed at the end of initialization. + * + * Last reviewed on 2012-03-29 (0.11.3) */ #ifdef HAVE_CONFIG_H @@ -127,8 +123,6 @@ #include "gstinfo.h" #include "gsterror.h" #include "gstregistry.h" -#include "gstmarshal.h" -#include "gstfilter.h" #include "gstpluginloader.h" @@ -146,6 +140,18 @@ extern HMODULE _priv_gst_dll_handle; struct _GstRegistryPrivate { + GList *plugins; + GList *features; + + GList *paths; + + int cache_file; + + /* hash to speedup _lookup_feature_locked() */ + GHashTable *feature_hash; + /* hash to speedup _lookup */ + GHashTable *basename_hash; + /* updated whenever the feature list changes */ guint32 cookie; /* speedup for searching features */ @@ -157,7 +163,7 @@ struct _GstRegistryPrivate /* the one instance of the default registry and the mutex protecting the * variable. */ -static GStaticMutex _gst_registry_mutex = G_STATIC_MUTEX_INIT; +static GMutex _gst_registry_mutex; static GstRegistry *_gst_registry_default = NULL; /* defaults */ @@ -175,6 +181,8 @@ extern GList *_priv_gst_plugin_paths; /* Set to TRUE when the registry cache should be disabled */ gboolean _gst_disable_registry_cache = FALSE; + +static gboolean __registry_reuse_plugin_scanner = TRUE; #endif /* Element signals and args */ @@ -194,8 +202,8 @@ static GstPluginFeature *gst_registry_lookup_feature_locked (GstRegistry * static GstPlugin *gst_registry_lookup_bn_locked (GstRegistry * registry, const char *basename); +#define gst_registry_parent_class parent_class G_DEFINE_TYPE (GstRegistry, gst_registry, GST_TYPE_OBJECT); -static GstObjectClass *parent_class = NULL; static void gst_registry_class_init (GstRegistryClass * klass) @@ -204,7 +212,6 @@ gst_registry_class_init (GstRegistryClass * klass) gobject_class = (GObjectClass *) klass; - parent_class = g_type_class_peek_parent (klass); g_type_class_add_private (klass, sizeof (GstRegistryPrivate)); /** @@ -217,8 +224,8 @@ gst_registry_class_init (GstRegistryClass * klass) */ gst_registry_signals[PLUGIN_ADDED] = g_signal_new ("plugin-added", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRegistryClass, plugin_added), NULL, - NULL, gst_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); + G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic, + G_TYPE_NONE, 1, GST_TYPE_PLUGIN); /** * GstRegistry::feature-added: @@ -230,8 +237,8 @@ gst_registry_class_init (GstRegistryClass * klass) */ gst_registry_signals[FEATURE_ADDED] = g_signal_new ("feature-added", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRegistryClass, feature_added), - NULL, NULL, gst_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); + G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic, + G_TYPE_NONE, 1, GST_TYPE_PLUGIN_FEATURE); gobject_class->finalize = gst_registry_finalize; } @@ -239,11 +246,11 @@ gst_registry_class_init (GstRegistryClass * klass) static void gst_registry_init (GstRegistry * registry) { - registry->feature_hash = g_hash_table_new (g_str_hash, g_str_equal); - registry->basename_hash = g_hash_table_new (g_str_hash, g_str_equal); registry->priv = G_TYPE_INSTANCE_GET_PRIVATE (registry, GST_TYPE_REGISTRY, GstRegistryPrivate); + registry->priv->feature_hash = g_hash_table_new (g_str_hash, g_str_equal); + registry->priv->basename_hash = g_hash_table_new (g_str_hash, g_str_equal); } static void @@ -253,8 +260,8 @@ gst_registry_finalize (GObject * object) GList *plugins, *p; GList *features, *f; - plugins = registry->plugins; - registry->plugins = NULL; + plugins = registry->priv->plugins; + registry->priv->plugins = NULL; GST_DEBUG_OBJECT (registry, "registry finalize"); p = plugins; @@ -270,26 +277,26 @@ gst_registry_finalize (GObject * object) } g_list_free (plugins); - features = registry->features; - registry->features = NULL; + features = registry->priv->features; + registry->priv->features = NULL; f = features; while (f) { GstPluginFeature *feature = f->data; if (feature) { - GST_LOG_OBJECT (registry, "removing feature %p (%s)", - feature, gst_plugin_feature_get_name (feature)); + GST_LOG_OBJECT (registry, "removing feature %p (%s)", feature, + GST_OBJECT_NAME (feature)); gst_object_unparent (GST_OBJECT_CAST (feature)); } f = g_list_next (f); } g_list_free (features); - g_hash_table_destroy (registry->feature_hash); - registry->feature_hash = NULL; - g_hash_table_destroy (registry->basename_hash); - registry->basename_hash = NULL; + g_hash_table_destroy (registry->priv->feature_hash); + registry->priv->feature_hash = NULL; + g_hash_table_destroy (registry->priv->basename_hash); + registry->priv->basename_hash = NULL; if (registry->priv->element_factory_list) { GST_DEBUG_OBJECT (registry, "Cleaning up cached element factory list"); @@ -305,25 +312,26 @@ gst_registry_finalize (GObject * object) } /** - * gst_registry_get_default: + * gst_registry_get: * - * Retrieves the default registry. The caller does not own a reference on the - * registry, as it is alive as long as GStreamer is initialized. + * Retrieves the singleton plugin registry. The caller does not own a + * reference on the registry, as it is alive as long as GStreamer is + * initialized. * - * Returns: (transfer none): The default #GstRegistry. + * Returns: (transfer none): the #GstRegistry. */ GstRegistry * -gst_registry_get_default (void) +gst_registry_get (void) { GstRegistry *registry; - g_static_mutex_lock (&_gst_registry_mutex); + g_mutex_lock (&_gst_registry_mutex); if (G_UNLIKELY (!_gst_registry_default)) { _gst_registry_default = g_object_newv (GST_TYPE_REGISTRY, 0, NULL); gst_object_ref_sink (GST_OBJECT_CAST (_gst_registry_default)); } registry = _gst_registry_default; - g_static_mutex_unlock (&_gst_registry_mutex); + g_mutex_unlock (&_gst_registry_mutex); return registry; } @@ -347,11 +355,12 @@ gst_registry_add_path (GstRegistry * registry, const gchar * path) goto empty_path; GST_OBJECT_LOCK (registry); - if (g_list_find_custom (registry->paths, path, (GCompareFunc) strcmp)) + if (g_list_find_custom (registry->priv->paths, path, (GCompareFunc) strcmp)) goto was_added; GST_INFO ("Adding plugin path: \"%s\"", path); - registry->paths = g_list_append (registry->paths, g_strdup (path)); + registry->priv->paths = + g_list_append (registry->priv->paths, g_strdup (path)); GST_OBJECT_UNLOCK (registry); return; @@ -390,7 +399,7 @@ gst_registry_get_path_list (GstRegistry * registry) GST_OBJECT_LOCK (registry); /* We don't need to copy the strings, because they won't be deleted * as long as the GstRegistry is around */ - list = g_list_copy (registry->paths); + list = g_list_copy (registry->priv->paths); GST_OBJECT_UNLOCK (registry); return list; @@ -438,9 +447,10 @@ gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin) GST_OBJECT_UNLOCK (registry); return FALSE; } - registry->plugins = g_list_remove (registry->plugins, existing_plugin); + registry->priv->plugins = + g_list_remove (registry->priv->plugins, existing_plugin); if (G_LIKELY (existing_plugin->basename)) - g_hash_table_remove (registry->basename_hash, + g_hash_table_remove (registry->priv->basename_hash, existing_plugin->basename); gst_object_unref (existing_plugin); } @@ -449,9 +459,10 @@ gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin) GST_DEBUG_OBJECT (registry, "adding plugin %p for filename \"%s\"", plugin, GST_STR_NULL (plugin->filename)); - registry->plugins = g_list_prepend (registry->plugins, plugin); + registry->priv->plugins = g_list_prepend (registry->priv->plugins, plugin); if (G_LIKELY (plugin->basename)) - g_hash_table_replace (registry->basename_hash, plugin->basename, plugin); + g_hash_table_replace (registry->priv->basename_hash, plugin->basename, + plugin); gst_object_ref_sink (plugin); GST_OBJECT_UNLOCK (registry); @@ -473,7 +484,7 @@ gst_registry_remove_features_for_plugin_unlocked (GstRegistry * registry, g_return_if_fail (GST_IS_PLUGIN (plugin)); /* Remove all features for this plugin */ - f = registry->features; + f = registry->priv->features; while (f != NULL) { GList *next = g_list_next (f); GstPluginFeature *feature = f->data; @@ -483,8 +494,10 @@ gst_registry_remove_features_for_plugin_unlocked (GstRegistry * registry, feature, gst_plugin_feature_get_name (feature), plugin, plugin->desc.name); - registry->features = g_list_delete_link (registry->features, f); - g_hash_table_remove (registry->feature_hash, GST_OBJECT_NAME (feature)); + registry->priv->features = + g_list_delete_link (registry->priv->features, f); + g_hash_table_remove (registry->priv->feature_hash, + GST_OBJECT_NAME (feature)); gst_object_unparent (GST_OBJECT_CAST (feature)); } f = next; @@ -511,9 +524,9 @@ gst_registry_remove_plugin (GstRegistry * registry, GstPlugin * plugin) plugin, gst_plugin_get_name (plugin)); GST_OBJECT_LOCK (registry); - registry->plugins = g_list_remove (registry->plugins, plugin); + registry->priv->plugins = g_list_remove (registry->priv->plugins, plugin); if (G_LIKELY (plugin->basename)) - g_hash_table_remove (registry->basename_hash, plugin->basename); + g_hash_table_remove (registry->priv->basename_hash, plugin->basename); gst_registry_remove_features_for_plugin_unlocked (registry, plugin); GST_OBJECT_UNLOCK (registry); gst_object_unref (plugin); @@ -550,14 +563,15 @@ gst_registry_add_feature (GstRegistry * registry, GstPluginFeature * feature) /* Remove the existing feature from the list now, before we insert the new * one, but don't unref yet because the hash is still storing a reference to * it. */ - registry->features = g_list_remove (registry->features, existing_feature); + registry->priv->features = + g_list_remove (registry->priv->features, existing_feature); } GST_DEBUG_OBJECT (registry, "adding feature %p (%s)", feature, GST_OBJECT_NAME (feature)); - registry->features = g_list_prepend (registry->features, feature); - g_hash_table_replace (registry->feature_hash, GST_OBJECT_NAME (feature), + registry->priv->features = g_list_prepend (registry->priv->features, feature); + g_hash_table_replace (registry->priv->feature_hash, GST_OBJECT_NAME (feature), feature); if (G_UNLIKELY (existing_feature)) { @@ -597,8 +611,8 @@ gst_registry_remove_feature (GstRegistry * registry, GstPluginFeature * feature) feature, gst_plugin_feature_get_name (feature)); GST_OBJECT_LOCK (registry); - registry->features = g_list_remove (registry->features, feature); - g_hash_table_remove (registry->feature_hash, GST_OBJECT_NAME (feature)); + registry->priv->features = g_list_remove (registry->priv->features, feature); + g_hash_table_remove (registry->priv->feature_hash, GST_OBJECT_NAME (feature)); registry->priv->cookie++; GST_OBJECT_UNLOCK (registry); @@ -627,22 +641,46 @@ GList * gst_registry_plugin_filter (GstRegistry * registry, GstPluginFilter filter, gboolean first, gpointer user_data) { - GList *list; - GList *g; + GList *list = NULL; g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL); GST_OBJECT_LOCK (registry); - list = gst_filter_run (registry->plugins, (GstFilterFunc) filter, first, - user_data); - for (g = list; g; g = g->next) { - gst_object_ref (GST_PLUGIN_CAST (g->data)); + { + const GList *walk; + + for (walk = registry->priv->plugins; walk != NULL; walk = walk->next) { + GstPlugin *plugin = walk->data; + + if (filter == NULL || filter (plugin, user_data)) { + list = g_list_prepend (list, gst_object_ref (plugin)); + + if (first) + break; + } + } } GST_OBJECT_UNLOCK (registry); return list; } +typedef struct +{ + const gchar *name; + GType type; +} GstTypeNameData; + +static gboolean +gst_plugin_feature_type_name_filter (GstPluginFeature * feature, + GstTypeNameData * data) +{ + g_assert (GST_IS_PLUGIN_FEATURE (feature)); + + return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) && + (data->name == NULL || !strcmp (data->name, GST_OBJECT_NAME (feature)))); +} + /* returns TRUE if the list was changed * * Must be called with the object lock taken */ @@ -655,16 +693,24 @@ gst_registry_get_feature_list_or_create (GstRegistry * registry, if (G_UNLIKELY (!*previous || priv->cookie != *cookie)) { GstTypeNameData data; + const GList *walk; - if (*previous) + if (*previous) { gst_plugin_feature_list_free (*previous); + *previous = NULL; + } data.type = type; data.name = NULL; - *previous = - gst_filter_run (registry->features, - (GstFilterFunc) gst_plugin_feature_type_name_filter, FALSE, &data); - g_list_foreach (*previous, (GFunc) gst_object_ref, NULL); + + for (walk = registry->priv->features; walk != NULL; walk = walk->next) { + GstPluginFeature *feature = walk->data; + + if (gst_plugin_feature_type_name_filter (feature, &data)) { + *previous = g_list_prepend (*previous, gst_object_ref (feature)); + } + } + *cookie = priv->cookie; res = TRUE; } @@ -746,16 +792,24 @@ GList * gst_registry_feature_filter (GstRegistry * registry, GstPluginFeatureFilter filter, gboolean first, gpointer user_data) { - GList *list; - GList *g; + GList *list = NULL; g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL); GST_OBJECT_LOCK (registry); - list = gst_filter_run (registry->features, (GstFilterFunc) filter, first, - user_data); - for (g = list; g; g = g->next) { - gst_object_ref (GST_PLUGIN_FEATURE_CAST (g->data)); + { + const GList *walk; + + for (walk = registry->priv->features; walk != NULL; walk = walk->next) { + GstPluginFeature *feature = walk->data; + + if (filter == NULL || filter (feature, user_data)) { + list = g_list_prepend (list, gst_object_ref (feature)); + + if (first) + break; + } + } } GST_OBJECT_UNLOCK (registry); @@ -883,7 +937,7 @@ gst_registry_get_plugin_list (GstRegistry * registry) g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL); GST_OBJECT_LOCK (registry); - list = g_list_copy (registry->plugins); + list = g_list_copy (registry->priv->plugins); for (g = list; g; g = g->next) { gst_object_ref (GST_PLUGIN_CAST (g->data)); } @@ -895,7 +949,7 @@ gst_registry_get_plugin_list (GstRegistry * registry) static GstPluginFeature * gst_registry_lookup_feature_locked (GstRegistry * registry, const char *name) { - return g_hash_table_lookup (registry->feature_hash, name); + return g_hash_table_lookup (registry->priv->feature_hash, name); } /** @@ -930,7 +984,7 @@ gst_registry_lookup_feature (GstRegistry * registry, const char *name) static GstPlugin * gst_registry_lookup_bn_locked (GstRegistry * registry, const char *basename) { - return g_hash_table_lookup (registry->basename_hash, basename); + return g_hash_table_lookup (registry->priv->basename_hash, basename); } static GstPlugin * @@ -1086,6 +1140,12 @@ gst_registry_scan_plugin_file (GstRegistryScanContext * context, gst_object_unref (newplugin); changed = TRUE; } +#ifndef GST_DISABLE_REGISTRY + if (!__registry_reuse_plugin_scanner) { + clear_scan_context (context); + context->helper_state = REGISTRY_SCAN_HELPER_NOT_STARTED; + } +#endif return changed; } @@ -1324,11 +1384,11 @@ _priv_gst_registry_cleanup (void) { GstRegistry *registry; - g_static_mutex_lock (&_gst_registry_mutex); + g_mutex_lock (&_gst_registry_mutex); if ((registry = _gst_registry_default) != NULL) { _gst_registry_default = NULL; } - g_static_mutex_unlock (&_gst_registry_mutex); + g_mutex_unlock (&_gst_registry_mutex); /* unref outside of the lock because we can. */ if (registry) @@ -1336,32 +1396,32 @@ _priv_gst_registry_cleanup (void) } /** - * gst_default_registry_check_feature_version: + * gst_registry_check_feature_version: + * @registry: a #GstRegistry * @feature_name: the name of the feature (e.g. "oggdemux") * @min_major: the minimum major version number * @min_minor: the minimum minor version number * @min_micro: the minimum micro version number * - * Checks whether a plugin feature by the given name exists in the - * default registry and whether its version is at least the + * Checks whether a plugin feature by the given name exists in + * @registry and whether its version is at least the * version required. * * Returns: #TRUE if the feature could be found and the version is * the same as the required version or newer, and #FALSE otherwise. */ gboolean -gst_default_registry_check_feature_version (const gchar * feature_name, - guint min_major, guint min_minor, guint min_micro) +gst_registry_check_feature_version (GstRegistry * registry, + const gchar * feature_name, guint min_major, guint min_minor, + guint min_micro) { GstPluginFeature *feature; - GstRegistry *registry; gboolean ret = FALSE; g_return_val_if_fail (feature_name != NULL, FALSE); GST_DEBUG ("Looking up plugin feature '%s'", feature_name); - registry = gst_registry_get_default (); feature = gst_registry_lookup_feature (registry, feature_name); if (feature) { ret = gst_plugin_feature_check_version (feature, min_major, min_minor, @@ -1389,7 +1449,7 @@ load_plugin_func (gpointer data, gpointer user_data) if (plugin) { GST_INFO ("Loaded plugin: \"%s\"", filename); - gst_default_registry_add_plugin (plugin); + gst_registry_add_plugin (gst_registry_get (), plugin); } else { if (err) { /* Report error to user, and free error */ @@ -1417,16 +1477,16 @@ gst_registry_remove_cache_plugins (GstRegistry * registry) GST_OBJECT_LOCK (registry); GST_DEBUG_OBJECT (registry, "removing cached plugins"); - g = registry->plugins; + g = registry->priv->plugins; while (g) { g_next = g->next; plugin = g->data; if (plugin->flags & GST_PLUGIN_FLAG_CACHED) { GST_DEBUG_OBJECT (registry, "removing cached plugin \"%s\"", GST_STR_NULL (plugin->filename)); - registry->plugins = g_list_delete_link (registry->plugins, g); + registry->priv->plugins = g_list_delete_link (registry->priv->plugins, g); if (G_LIKELY (plugin->basename)) - g_hash_table_remove (registry->basename_hash, plugin->basename); + g_hash_table_remove (registry->priv->basename_hash, plugin->basename); gst_registry_remove_features_for_plugin_unlocked (registry, plugin); gst_object_unref (plugin); changed = TRUE; @@ -1514,7 +1574,7 @@ scan_and_update_registry (GstRegistry * default_registry, /* plugins in the user's home directory take precedence over * system-installed ones */ home_plugins = g_build_filename (g_get_user_data_dir (), - "gstreamer-" GST_MAJORMINOR, "plugins", NULL); + "gstreamer-" GST_API_VERSION, "plugins", NULL); GST_DEBUG ("scanning home plugins %s", home_plugins); changed |= gst_registry_scan_path_internal (&context, home_plugins); @@ -1571,7 +1631,8 @@ scan_and_update_registry (GstRegistry * default_registry, } GST_INFO ("Registry cache changed. Writing new registry cache"); - if (!priv_gst_registry_binary_write_cache (default_registry, registry_file)) { + if (!priv_gst_registry_binary_write_cache (default_registry, + default_registry->priv->plugins, registry_file)) { g_set_error (error, GST_CORE_ERROR, GST_CORE_ERROR_FAILED, _("Error writing registry cache to %s: %s"), registry_file, g_strerror (errno)); @@ -1591,11 +1652,11 @@ ensure_current_registry (GError ** error) gboolean do_update = TRUE; gboolean have_cache = TRUE; - default_registry = gst_registry_get_default (); + default_registry = gst_registry_get (); registry_file = g_strdup (g_getenv ("GST_REGISTRY")); if (registry_file == NULL) { registry_file = g_build_filename (g_get_user_cache_dir (), - "gstreamer-" GST_MAJORMINOR, "registry." HOST_CPU ".bin", NULL); + "gstreamer-" GST_API_VERSION, "registry." HOST_CPU ".bin", NULL); } if (!_gst_disable_registry_cache) { @@ -1620,6 +1681,12 @@ ensure_current_registry (GError ** error) } if (do_update) { + const gchar *reuse_env; + + if ((reuse_env = g_getenv ("GST_REGISTRY_REUSE_PLUGIN_SCANNER"))) { + /* do reuse for any value different from "no" */ + __registry_reuse_plugin_scanner = (strcmp (reuse_env, "no") != 0); + } /* now check registry */ GST_DEBUG ("Updating registry cache"); scan_and_update_registry (default_registry, registry_file, TRUE, error); |