X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gst%2Fgstregistry.c;h=a8b2f51ca7c8f92f702a2a3c3c9c577578ede4a3;hb=0c6f5b3e4c3dc55e684bca1e3fc9a2a9b74407b9;hp=3e843c85983e47ac5ea0838f6768af09350a3018;hpb=81ce8b76d0b31c130ea4a49ea10eb7718490ba6e;p=platform%2Fupstream%2Fgstreamer.git diff --git a/gst/gstregistry.c b/gst/gstregistry.c index 3e843c8..a8b2f51 100644 --- a/gst/gstregistry.c +++ b/gst/gstregistry.c @@ -17,12 +17,13 @@ * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ /** * SECTION:gstregistry + * @title: GstRegistry * @short_description: Abstract base class for management of #GstPlugin objects * @see_also: #GstPlugin, #GstPluginFeature * @@ -32,13 +33,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, @@ -50,42 +45,28 @@ * * On startup, plugins are searched for in the plugin search path. The following * locations are checked in this order: - * - * - * location from --gst-plugin-path commandline option. - * - * - * the GST_PLUGIN_PATH environment variable. - * - * - * the GST_PLUGIN_SYSTEM_PATH environment variable. - * - * - * default locations (if GST_PLUGIN_SYSTEM_PATH is not set). Those - * default locations are: - * ~/.gstreamer-$GST_MAJORMINOR/plugins/ - * and $prefix/libs/gstreamer-$GST_MAJORMINOR/. - * - * - * + * + * * location from --gst-plugin-path commandline option. + * * the GST_PLUGIN_PATH environment variable. + * * the GST_PLUGIN_SYSTEM_PATH environment variable. + * * default locations (if GST_PLUGIN_SYSTEM_PATH is not set). + * Those default locations are: + * `$XDG_DATA_HOME/gstreamer-$GST_API_VERSION/plugins/` + * and `$prefix/libs/gstreamer-$GST_API_VERSION/`. + * [$XDG_DATA_HOME](http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) defaults to + * `$HOME/.local/share`. + * * The registry cache file is loaded from - * ~/.gstreamer-$GST_MAJORMINOR/registry-$ARCH.bin or the - * file listed in the GST_REGISTRY env var. One reason to change the registry - * location is for testing. + * `$XDG_CACHE_HOME/gstreamer-$GST_API_VERSION/registry-$ARCH.bin` + * (where $XDG_CACHE_HOME defaults to `$HOME/.cache`) or the file listed in the `GST_REGISTRY` + * env var. One reason to change the registry location is for testing. * * For each plugin that is found in the plugin search path, there could be 3 * possibilities for cached information: - * - * - * the cache may not contain information about a given file. - * - * - * the cache may have stale information. - * - * - * the cache may have current information. - * - * + * + * * the cache may not contain information about a given file. + * * the cache may have stale information. + * * the cache may have current information. * * In the first two cases, the plugin is loaded and the cache updated. In * addition to these cases, the cache may have entries for plugins that are not @@ -97,9 +78,9 @@ * checked to make sure the information is minimally valid. If not, the entry is * simply dropped. * - * Implementation notes: + * ## Implementation notes: * - * 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 @@ -127,7 +108,7 @@ #include "gstinfo.h" #include "gsterror.h" #include "gstregistry.h" -#include "gstmarshal.h" +#include "gstdeviceproviderfactory.h" #include "gstpluginloader.h" @@ -145,6 +126,21 @@ extern HMODULE _priv_gst_dll_handle; struct _GstRegistryPrivate { + GList *plugins; + GList *features; + + guint n_plugins; +#if 0 + GList *paths; +#endif + + 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 */ @@ -152,11 +148,13 @@ struct _GstRegistryPrivate guint32 efl_cookie; GList *typefind_factory_list; guint32 tfl_cookie; + GList *device_provider_factory_list; + guint32 dmfl_cookie; }; /* 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 */ @@ -168,6 +166,8 @@ static gboolean _gst_enable_registry_fork = DEFAULT_FORK; extern GSList *_priv_gst_preload_plugins; #ifndef GST_DISABLE_REGISTRY +/* Set to TRUE to disable registry, behaves similar to GST_DISABLE_REGISTRY */ +gboolean _priv_gst_disable_registry = FALSE; /*set to TRUE when registry needn't to be updated */ gboolean _priv_gst_disable_registry_update = FALSE; extern GList *_priv_gst_plugin_paths; @@ -196,7 +196,7 @@ 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); +G_DEFINE_TYPE_WITH_PRIVATE (GstRegistry, gst_registry, GST_TYPE_OBJECT); static void gst_registry_class_init (GstRegistryClass * klass) @@ -205,8 +205,6 @@ gst_registry_class_init (GstRegistryClass * klass) gobject_class = (GObjectClass *) klass; - g_type_class_add_private (klass, sizeof (GstRegistryPrivate)); - /** * GstRegistry::plugin-added: * @registry: the registry that emitted the signal @@ -217,8 +215,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 +228,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 +237,9 @@ 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 = gst_registry_get_instance_private (registry); + 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 +249,9 @@ 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; + registry->priv->n_plugins = 0; GST_DEBUG_OBJECT (registry, "registry finalize"); p = plugins; @@ -270,8 +267,8 @@ 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) { @@ -286,10 +283,10 @@ gst_registry_finalize (GObject * object) } 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"); @@ -301,33 +298,41 @@ gst_registry_finalize (GObject * object) gst_plugin_feature_list_free (registry->priv->typefind_factory_list); } + if (registry->priv->device_provider_factory_list) { + GST_DEBUG_OBJECT (registry, + "Cleaning up cached device provider factory list"); + gst_plugin_feature_list_free (registry->priv->device_provider_factory_list); + } + G_OBJECT_CLASS (parent_class)->finalize (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_registry_default = g_object_new (GST_TYPE_REGISTRY, 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; } +#if 0 /** * gst_registry_add_path: * @registry: the registry to add the path to @@ -347,11 +352,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,22 +396,24 @@ 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; } - +#endif /** * gst_registry_add_plugin: * @registry: the registry to add the plugin to - * @plugin: (transfer full): the plugin to add + * @plugin: (transfer floating): the plugin to add * * Add the plugin to the registry. The plugin-added signal will be emitted. - * This function will sink @plugin. * - * Returns: TRUE on success. + * @plugin's reference count will be incremented, and any floating + * reference will be removed (see gst_object_ref_sink()) + * + * Returns: %TRUE on success. * * MT safe. */ @@ -429,18 +437,22 @@ gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin) GST_STR_NULL (plugin->filename)); /* If the new plugin is blacklisted and the existing one isn't cached, do not * accept if it's from a different location than the existing one */ - if ((plugin->flags & GST_PLUGIN_FLAG_BLACKLISTED) && + if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED) && strcmp (plugin->filename, existing_plugin->filename)) { GST_WARNING_OBJECT (registry, "Not replacing plugin because new one (%s) is blacklisted but for a different location than existing one (%s)", plugin->filename, existing_plugin->filename); + /* Keep reference counting consistent */ + gst_object_ref_sink (plugin); gst_object_unref (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); + --registry->priv->n_plugins; 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 +461,12 @@ 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); + ++registry->priv->n_plugins; + 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 +488,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 +498,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 +528,10 @@ 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); + --registry->priv->n_plugins; 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); @@ -522,12 +540,14 @@ gst_registry_remove_plugin (GstRegistry * registry, GstPlugin * plugin) /** * gst_registry_add_feature: * @registry: the registry to add the plugin to - * @feature: (transfer full): the feature to add + * @feature: (transfer floating): the feature to add * * Add the feature to the registry. The feature-added signal will be emitted. - * This function sinks @feature. * - * Returns: TRUE on success. + * @feature's reference count will be incremented, and any floating + * reference will be removed (see gst_object_ref_sink()) + * + * Returns: %TRUE on success. * * MT safe. */ @@ -550,14 +570,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 +618,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,26 +648,30 @@ GList * gst_registry_plugin_filter (GstRegistry * registry, GstPluginFilter filter, gboolean first, gpointer user_data) { - GList *list = NULL; + GstPlugin **plugins; + GList *walk, *list = NULL; + guint n_plugins, i; g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL); GST_OBJECT_LOCK (registry); - { - const GList *walk; - - for (walk = registry->plugins; walk != NULL; walk = walk->next) { - GstPlugin *plugin = walk->data; + n_plugins = registry->priv->n_plugins; + plugins = g_newa (GstPlugin *, n_plugins + 1); + for (walk = registry->priv->plugins, i = 0; walk != NULL; walk = walk->next) + plugins[i++] = gst_object_ref (walk->data); + GST_OBJECT_UNLOCK (registry); - if (filter == NULL || filter (plugin, user_data)) { - list = g_list_prepend (list, gst_object_ref (plugin)); + for (i = 0; i < n_plugins; ++i) { + if (filter == NULL || filter (plugins[i], user_data)) { + list = g_list_prepend (list, gst_object_ref (plugins[i])); - if (first) - break; - } + if (first) + break; } } - GST_OBJECT_UNLOCK (registry); + + for (i = 0; i < n_plugins; ++i) + gst_object_unref (plugins[i]); return list; } @@ -689,7 +714,7 @@ gst_registry_get_feature_list_or_create (GstRegistry * registry, data.type = type; data.name = NULL; - for (walk = registry->features; walk != NULL; walk = walk->next) { + for (walk = registry->priv->features; walk != NULL; walk = walk->next) { GstPluginFeature *feature = walk->data; if (gst_plugin_feature_type_name_filter (feature, &data)) { @@ -757,6 +782,28 @@ gst_registry_get_typefind_factory_list (GstRegistry * registry) return list; } + +static GList * +gst_registry_get_device_provider_factory_list (GstRegistry * registry) +{ + GList *list; + + GST_OBJECT_LOCK (registry); + + gst_registry_get_feature_list_or_create (registry, + ®istry->priv->device_provider_factory_list, + ®istry->priv->dmfl_cookie, GST_TYPE_DEVICE_PROVIDER_FACTORY); + + /* Return reffed copy */ + list = + gst_plugin_feature_list_copy (registry-> + priv->device_provider_factory_list); + + GST_OBJECT_UNLOCK (registry); + + return list; +} + /** * gst_registry_feature_filter: * @registry: registry to query @@ -778,30 +825,40 @@ GList * gst_registry_feature_filter (GstRegistry * registry, GstPluginFeatureFilter filter, gboolean first, gpointer user_data) { - GList *list = NULL; + GstPluginFeature **features; + GList *walk, *list = NULL; + guint n_features, i; g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL); GST_OBJECT_LOCK (registry); - { - const GList *walk; - - for (walk = registry->features; walk != NULL; walk = walk->next) { - GstPluginFeature *feature = walk->data; + n_features = g_hash_table_size (registry->priv->feature_hash); + features = g_newa (GstPluginFeature *, n_features + 1); + for (walk = registry->priv->features, i = 0; walk != NULL; walk = walk->next) + features[i++] = gst_object_ref (walk->data); + GST_OBJECT_UNLOCK (registry); - if (filter == NULL || filter (feature, user_data)) { - list = g_list_prepend (list, gst_object_ref (feature)); + for (i = 0; i < n_features; ++i) { + if (filter == NULL || filter (features[i], user_data)) { + list = g_list_prepend (list, gst_object_ref (features[i])); - if (first) - break; - } + if (first) + break; } } - GST_OBJECT_UNLOCK (registry); + + for (i = 0; i < n_features; ++i) + gst_object_unref (features[i]); return list; } +static gboolean +gst_registry_plugin_name_filter (GstPlugin * plugin, const gchar * name) +{ + return (plugin->desc.name && !strcmp (plugin->desc.name, name)); +} + /** * gst_registry_find_plugin: * @registry: the registry to search @@ -810,8 +867,9 @@ gst_registry_feature_filter (GstRegistry * registry, * Find the plugin with the given name in the registry. * The plugin will be reffed; caller is responsible for unreffing. * - * Returns: (transfer full): the plugin with the given name or NULL if the - * plugin was not found. gst_object_unref() after usage. + * Returns: (transfer full) (nullable): the plugin with the given name + * or %NULL if the plugin was not found. gst_object_unref() after + * usage. * * MT safe. */ @@ -825,7 +883,7 @@ gst_registry_find_plugin (GstRegistry * registry, const gchar * name) g_return_val_if_fail (name != NULL, NULL); walk = gst_registry_plugin_filter (registry, - (GstPluginFilter) gst_plugin_name_filter, TRUE, (gpointer) name); + (GstPluginFilter) gst_registry_plugin_name_filter, TRUE, (gpointer) name); if (walk) { result = GST_PLUGIN_CAST (walk->data); @@ -844,8 +902,9 @@ gst_registry_find_plugin (GstRegistry * registry, const gchar * name) * * Find the pluginfeature with the given name and type in the registry. * - * Returns: (transfer full): the pluginfeature with the given name and type - * or NULL if the plugin was not found. gst_object_unref() after usage. + * Returns: (transfer full) (nullable): the pluginfeature with the + * given name and type or %NULL if the plugin was not + * found. gst_object_unref() after usage. * * MT safe. */ @@ -893,6 +952,8 @@ gst_registry_get_feature_list (GstRegistry * registry, GType type) return gst_registry_get_element_factory_list (registry); else if (type == GST_TYPE_TYPE_FIND_FACTORY) return gst_registry_get_typefind_factory_list (registry); + else if (type == GST_TYPE_DEVICE_PROVIDER_FACTORY) + return gst_registry_get_device_provider_factory_list (registry); data.type = type; data.name = NULL; @@ -923,7 +984,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)); } @@ -935,7 +996,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); } /** @@ -970,7 +1031,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 * @@ -995,8 +1056,8 @@ gst_registry_lookup_bn (GstRegistry * registry, const char *basename) * Look up a plugin in the given registry with the given filename. * If found, plugin is reffed. * - * Returns: (transfer full): the #GstPlugin if found, or NULL if not. - * gst_object_unref() after usage. + * Returns: (transfer full) (nullable): the #GstPlugin if found, or + * %NULL if not. gst_object_unref() after usage. */ GstPlugin * gst_registry_lookup (GstRegistry * registry, const char *filename) @@ -1101,10 +1162,9 @@ gst_registry_scan_plugin_file (GstRegistryScanContext * context, filename, file_size, file_mtime)) { g_warning ("External plugin loader failed. This most likely means that " "the plugin loader helper binary was not found or could not be run. " - "%s", (g_getenv ("GST_PLUGIN_PATH") != NULL) ? - "If you are running an uninstalled GStreamer setup, you might need " - "to update your gst-uninstalled script so that the " - "GST_PLUGIN_SCANNER environment variable gets set." : ""); + "You might need to set the GST_PLUGIN_SCANNER environment variable " + "if your setup is unusual. This should normally not be required " + "though."); context->helper_state = REGISTRY_SCAN_HELPER_DISABLED; } } @@ -1116,7 +1176,8 @@ gst_registry_scan_plugin_file (GstRegistryScanContext * context, /* We don't use a GError here because a failure to load some shared * objects as plugins is normal (particularly in the uninstalled case) */ - newplugin = gst_plugin_load_file (filename, NULL); + newplugin = _priv_gst_plugin_load_file_for_registry (filename, + context->registry, NULL); } if (newplugin) { @@ -1126,11 +1187,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; } @@ -1185,7 +1247,7 @@ gst_registry_scan_path_level (GstRegistryScanContext * context, g_free (filename); continue; } - /* FIXME 0.11: Don't recurse into directories, this behaviour + /* FIXME 2.0: Don't recurse into directories, this behaviour * is inconsistent with other PATH environment variables */ if (level > 0) { @@ -1205,7 +1267,7 @@ gst_registry_scan_path_level (GstRegistryScanContext * context, g_free (filename); continue; } - if (!g_str_has_suffix (dirent, G_MODULE_SUFFIX) + if (!g_str_has_suffix (dirent, "." G_MODULE_SUFFIX) #ifdef GST_EXTRA_MODULE_SUFFIX && !g_str_has_suffix (dirent, GST_EXTRA_MODULE_SUFFIX) #endif @@ -1257,7 +1319,7 @@ gst_registry_scan_path_level (GstRegistryScanContext * context, !(deps_changed = _priv_plugin_deps_files_changed (plugin)) && !strcmp (plugin->filename, filename)) { GST_LOG_OBJECT (context->registry, "file %s cached", filename); - plugin->flags &= ~GST_PLUGIN_FLAG_CACHED; + GST_OBJECT_FLAG_UNSET (plugin, GST_PLUGIN_FLAG_CACHED); GST_LOG_OBJECT (context->registry, "marking plugin %p as registered as %s", plugin, filename); plugin->registered = TRUE; @@ -1309,7 +1371,7 @@ gst_registry_scan_path_internal (GstRegistryScanContext * context, /** * gst_registry_scan_path: * @registry: the registry to add found plugins to - * @path: the path to scan + * @path: (type filename): the path to scan * * Scan the given path for plugins to add to the registry. The syntax of the * path is specific to the registry. @@ -1369,11 +1431,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) @@ -1381,32 +1443,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. + * 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, @@ -1434,7 +1496,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 */ @@ -1448,7 +1510,7 @@ load_plugin_func (gpointer data, gpointer user_data) #ifndef GST_DISABLE_REGISTRY /* Unref all plugins marked 'cached', to clear old plugins that no - * longer exist. Returns TRUE if any plugins were removed */ + * longer exist. Returns %TRUE if any plugins were removed */ static gboolean gst_registry_remove_cache_plugins (GstRegistry * registry) { @@ -1462,16 +1524,17 @@ 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) { + if (GST_OBJECT_FLAG_IS_SET (plugin, 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); + --registry->priv->n_plugins; 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; @@ -1532,7 +1595,9 @@ scan_and_update_registry (GstRegistry * default_registry, /* GST_PLUGIN_PATH specifies a list of directories to scan for * additional plugins. These take precedence over the system plugins */ - plugin_path = g_getenv ("GST_PLUGIN_PATH"); + plugin_path = g_getenv ("GST_PLUGIN_PATH_1_0"); + if (plugin_path == NULL) + plugin_path = g_getenv ("GST_PLUGIN_PATH"); if (plugin_path) { char **list; int i; @@ -1550,7 +1615,9 @@ scan_and_update_registry (GstRegistry * default_registry, /* GST_PLUGIN_SYSTEM_PATH specifies a list of plugins that are always * loaded by default. If not set, this defaults to the system-installed * path, and the plugins installed in the user's home directory */ - plugin_path = g_getenv ("GST_PLUGIN_SYSTEM_PATH"); + plugin_path = g_getenv ("GST_PLUGIN_SYSTEM_PATH_1_0"); + if (plugin_path == NULL) + plugin_path = g_getenv ("GST_PLUGIN_SYSTEM_PATH"); if (plugin_path == NULL) { char *home_plugins; @@ -1559,15 +1626,13 @@ 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); g_free (home_plugins); /* add the main (installed) library path */ - GST_DEBUG ("scanning main plugins %s", PLUGINDIR); - changed |= gst_registry_scan_path_internal (&context, PLUGINDIR); #ifdef G_OS_WIN32 { @@ -1578,7 +1643,8 @@ scan_and_update_registry (GstRegistry * default_registry, g_win32_get_package_installation_directory_of_module (_priv_gst_dll_handle); - dir = g_build_filename (base_dir, "lib", "gstreamer-0.10", NULL); + dir = g_build_filename (base_dir, GST_PLUGIN_SUBDIR, + "gstreamer-" GST_API_VERSION, NULL); GST_DEBUG ("scanning DLL dir %s", dir); changed |= gst_registry_scan_path_internal (&context, dir); @@ -1586,6 +1652,9 @@ scan_and_update_registry (GstRegistry * default_registry, g_free (dir); g_free (base_dir); } +#else + GST_DEBUG ("scanning main plugins %s", PLUGINDIR); + changed |= gst_registry_scan_path_internal (&context, PLUGINDIR); #endif } else { gchar **list; @@ -1616,7 +1685,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)); @@ -1636,11 +1706,14 @@ ensure_current_registry (GError ** error) gboolean do_update = TRUE; gboolean have_cache = TRUE; - default_registry = gst_registry_get_default (); - registry_file = g_strdup (g_getenv ("GST_REGISTRY")); + default_registry = gst_registry_get (); + + registry_file = g_strdup (g_getenv ("GST_REGISTRY_1_0")); + if (registry_file == NULL) + 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." TARGET_CPU ".bin", NULL); } if (!_gst_disable_registry_cache) { @@ -1697,8 +1770,6 @@ ensure_current_registry (GError ** error) * * Returns: %TRUE if GStreamer will use the child helper process when * rebuilding the registry. - * - * Since: 0.10.10 */ gboolean gst_registry_fork_is_enabled (void) @@ -1713,8 +1784,6 @@ gst_registry_fork_is_enabled (void) * Applications might want to disable/enable spawning of a child helper process * when rebuilding the registry. See gst_registry_fork_is_enabled() for more * information. - * - * Since: 0.10.10 */ void gst_registry_fork_set_enabled (gboolean enabled) @@ -1744,8 +1813,6 @@ gst_registry_fork_set_enabled (gboolean enabled) * * Returns: %TRUE if the registry has been updated successfully (does not * imply that there were changes), otherwise %FALSE. - * - * Since: 0.10.12 */ gboolean gst_update_registry (void) @@ -1753,14 +1820,19 @@ gst_update_registry (void) gboolean res; #ifndef GST_DISABLE_REGISTRY - GError *err = NULL; + if (!_priv_gst_disable_registry) { + GError *err = NULL; - res = ensure_current_registry (&err); - if (err) { - GST_WARNING ("registry update failed: %s", err->message); - g_error_free (err); + res = ensure_current_registry (&err); + if (err) { + GST_WARNING ("registry update failed: %s", err->message); + g_error_free (err); + } else { + GST_LOG ("registry update succeeded"); + } } else { - GST_LOG ("registry update succeeded"); + GST_INFO ("registry update disabled by environment"); + res = TRUE; } #else @@ -1780,12 +1852,10 @@ gst_update_registry (void) * gst_registry_get_feature_list_cookie: * @registry: the registry * - * Returns the registrys feature list cookie. This changes + * Returns the registry's feature list cookie. This changes * every time a feature is added or removed from the registry. * * Returns: the feature list cookie. - * - * Since: 0.10.26 */ guint32 gst_registry_get_feature_list_cookie (GstRegistry * registry)