Port gtk-doc comments to their equivalent markdown syntax
[platform/upstream/gstreamer.git] / gst / gstregistry.c
index 090f814..cc094e3 100644 (file)
@@ -23,6 +23,7 @@
 
 /**
  * SECTION:gstregistry
+ * @title: GstRegistry
  * @short_description: Abstract base class for management of #GstPlugin objects
  * @see_also: #GstPlugin, #GstPluginFeature
  *
  *
  * On startup, plugins are searched for in the plugin search path. The following
  * locations are checked in this order:
- * <itemizedlist>
- *   <listitem>
- *     <para>location from --gst-plugin-path commandline option.</para>
- *   </listitem>
- *   <listitem>
- *     <para>the GST_PLUGIN_PATH environment variable.</para>
- *   </listitem>
- *   <listitem>
- *     <para>the GST_PLUGIN_SYSTEM_PATH environment variable.</para>
- *   </listitem>
- *   <listitem>
- *     <para>default locations (if GST_PLUGIN_SYSTEM_PATH is not set). Those
- *       default locations are:
- *       <filename>$XDG_DATA_HOME/gstreamer-$GST_API_VERSION/plugins/</filename>
- *       and <filename>$prefix/libs/gstreamer-$GST_API_VERSION/</filename>.
- *       <ulink url="http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">
- *       <filename>$XDG_DATA_HOME</filename></ulink> defaults to
- *       <filename>$HOME/.local/share</filename>.
- *     </para>
- *   </listitem>
- * </itemizedlist>
+ *
+ * * 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
- * <filename>$XDG_CACHE_HOME/gstreamer-$GST_API_VERSION/registry-$ARCH.bin</filename>
- * (where
- * <ulink url="http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">
- * <filename>$XDG_CACHE_HOME</filename></ulink> defaults to
- * <filename>$HOME/.cache</filename>) 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:
- * <itemizedlist>
- *   <listitem>
- *     <para>the cache may not contain information about a given file.</para>
- *   </listitem>
- *   <listitem>
- *     <para>the cache may have stale information.</para>
- *   </listitem>
- *   <listitem>
- *     <para>the cache may have current information.</para>
- *   </listitem>
- * </itemizedlist>
+ *
+ *   * 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.
  *
- * <emphasis role="bold">Implementation notes:</emphasis>
+ * ## 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
@@ -148,6 +129,7 @@ struct _GstRegistryPrivate
   GList *plugins;
   GList *features;
 
+  guint n_plugins;
 #if 0
   GList *paths;
 #endif
@@ -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;
@@ -271,6 +255,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;
@@ -465,6 +450,7 @@ gst_registry_add_plugin (GstRegistry * registry, GstPlugin * 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->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);
@@ -657,26 +646,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;
 }
@@ -830,26 +823,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;
 }
@@ -1533,6 +1530,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);
@@ -1823,14 +1821,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