X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gst%2Fgstregistry.c;h=a8b2f51ca7c8f92f702a2a3c3c9c577578ede4a3;hb=94ba1cea88788fd3ad72fadcc2ceb7884ed6df50;hp=cb5af83f245aa0be3806a68d890bbaf4a6888b36;hpb=6eb6d9ec3802249673fd79830dc319575d765361;p=platform%2Fupstream%2Fgstreamer.git
diff --git a/gst/gstregistry.c b/gst/gstregistry.c
index cb5af83..a8b2f51 100644
--- a/gst/gstregistry.c
+++ b/gst/gstregistry.c
@@ -23,6 +23,7 @@
/**
* SECTION:gstregistry
+ * @title: GstRegistry
* @short_description: Abstract base class for management of #GstPlugin objects
* @see_also: #GstPlugin, #GstPluginFeature
*
@@ -44,48 +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:
- * $XDG_DATA_HOME/gstreamer-$GST_API_VERSION/plugins/
- * and $prefix/libs/gstreamer-$GST_API_VERSION/.
- *
- * $XDG_DATA_HOME defaults to
- * $HOME/.local/share.
- *
- *
- *
+ *
+ * * 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
- * $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
+ * `$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,7 +78,7 @@
* checked to make sure the information is minimally valid. If not, the entry is
* simply dropped.
*
- * Implementation notes:
+ * ## Implementation notes:
*
* The "cache" and "registry" are different concepts and can represent
* different sets of plugins. For various reasons, at init time, the cache is
@@ -127,7 +108,7 @@
#include "gstinfo.h"
#include "gsterror.h"
#include "gstregistry.h"
-#include "gstdevicemonitorfactory.h"
+#include "gstdeviceproviderfactory.h"
#include "gstpluginloader.h"
@@ -148,6 +129,7 @@ struct _GstRegistryPrivate
GList *plugins;
GList *features;
+ guint n_plugins;
#if 0
GList *paths;
#endif
@@ -166,7 +148,7 @@ struct _GstRegistryPrivate
guint32 efl_cookie;
GList *typefind_factory_list;
guint32 tfl_cookie;
- GList *device_monitor_factory_list;
+ GList *device_provider_factory_list;
guint32 dmfl_cookie;
};
@@ -184,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;
@@ -212,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)
@@ -221,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
@@ -255,9 +237,7 @@ gst_registry_class_init (GstRegistryClass * klass)
static void
gst_registry_init (GstRegistry * registry)
{
- 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);
}
@@ -271,6 +251,7 @@ gst_registry_finalize (GObject * object)
plugins = registry->priv->plugins;
registry->priv->plugins = NULL;
+ registry->priv->n_plugins = 0;
GST_DEBUG_OBJECT (registry, "registry finalize");
p = plugins;
@@ -317,10 +298,10 @@ gst_registry_finalize (GObject * object)
gst_plugin_feature_list_free (registry->priv->typefind_factory_list);
}
- if (registry->priv->device_monitor_factory_list) {
+ if (registry->priv->device_provider_factory_list) {
GST_DEBUG_OBJECT (registry,
- "Cleaning up cached device monitor factory list");
- gst_plugin_feature_list_free (registry->priv->device_monitor_factory_list);
+ "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);
@@ -342,7 +323,7 @@ gst_registry_get (void)
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;
@@ -425,12 +406,14 @@ gst_registry_get_path_list (GstRegistry * registry)
/**
* 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.
*/
@@ -459,12 +442,15 @@ gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin)
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->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->priv->basename_hash,
existing_plugin->basename);
@@ -476,6 +462,8 @@ gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin)
plugin, GST_STR_NULL (plugin->filename));
registry->priv->plugins = g_list_prepend (registry->priv->plugins, plugin);
+ ++registry->priv->n_plugins;
+
if (G_LIKELY (plugin->basename))
g_hash_table_replace (registry->priv->basename_hash, plugin->basename,
plugin);
@@ -541,6 +529,7 @@ gst_registry_remove_plugin (GstRegistry * registry, GstPlugin * plugin)
GST_OBJECT_LOCK (registry);
registry->priv->plugins = g_list_remove (registry->priv->plugins, plugin);
+ --registry->priv->n_plugins;
if (G_LIKELY (plugin->basename))
g_hash_table_remove (registry->priv->basename_hash, plugin->basename);
gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
@@ -551,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.
*/
@@ -657,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->priv->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;
}
@@ -789,20 +784,20 @@ gst_registry_get_typefind_factory_list (GstRegistry * registry)
static GList *
-gst_registry_get_device_monitor_factory_list (GstRegistry * registry)
+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_monitor_factory_list,
- ®istry->priv->dmfl_cookie, GST_TYPE_DEVICE_MONITOR_FACTORY);
+ ®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_monitor_factory_list);
+ gst_plugin_feature_list_copy (registry->
+ priv->device_provider_factory_list);
GST_OBJECT_UNLOCK (registry);
@@ -830,26 +825,30 @@ 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->priv->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;
}
@@ -868,8 +867,9 @@ gst_registry_plugin_name_filter (GstPlugin * plugin, const gchar * name)
* 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.
*/
@@ -902,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.
*/
@@ -951,8 +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_MONITOR_FACTORY)
- return gst_registry_get_device_monitor_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;
@@ -1055,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)
@@ -1175,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) {
@@ -1245,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) {
@@ -1265,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
@@ -1369,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.
@@ -1452,8 +1454,8 @@ _priv_gst_registry_cleanup (void)
* @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_registry_check_feature_version (GstRegistry * registry,
@@ -1508,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)
{
@@ -1530,6 +1532,7 @@ gst_registry_remove_cache_plugins (GstRegistry * registry)
GST_DEBUG_OBJECT (registry, "removing cached plugin \"%s\"",
GST_STR_NULL (plugin->filename));
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->priv->basename_hash, plugin->basename);
gst_registry_remove_features_for_plugin_unlocked (registry, plugin);
@@ -1640,14 +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,
-#ifdef _DEBUG
- "debug"
-#endif
- "lib",
- "gstreamer-" GST_API_VERSION,
- 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);
@@ -1823,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