typefind: Keep typefind factories sorted in the registry. Fixes #599147
authorEdward Hervey <bilboed@bilboed.com>
Wed, 21 Oct 2009 07:48:41 +0000 (09:48 +0200)
committerEdward Hervey <bilboed@bilboed.com>
Sat, 24 Oct 2009 08:44:09 +0000 (10:44 +0200)
This avoids having to do the sorting everytime we use typefind

The behaviour of gst_type_find_factory_get_list has subtlely changed
in the sense that the order was previously undefined, whereas now
it returns them sorted by rank and then by name.

gst/gstregistry.c
gst/gsttypefindfactory.c
libs/gst/base/gsttypefindhelper.c

index 8571d50..ee9ef5b 100644 (file)
@@ -635,6 +635,18 @@ gst_registry_get_feature_list_or_create (GstRegistry * registry,
   return res;
 }
 
+static gint
+type_find_factory_rank_cmp (const GstPluginFeature * fac1,
+    const GstPluginFeature * fac2)
+{
+  if (G_LIKELY (fac1->rank != fac2->rank))
+    return fac2->rank - fac1->rank;
+
+  /* to make the order in which things happen more deterministic,
+   * sort by name when the ranks are the same. */
+  return strcmp (fac1->name, fac2->name);
+}
+
 static GList *
 gst_registry_get_element_factory_list (GstRegistry * registry)
 {
@@ -661,9 +673,12 @@ gst_registry_get_typefind_factory_list (GstRegistry * registry)
 
   GST_OBJECT_LOCK (registry);
 
-  gst_registry_get_feature_list_or_create (registry,
-      &registry->private->typefind_factory_list,
-      &registry->private->tfl_cookie, GST_TYPE_TYPE_FIND_FACTORY);
+  if (G_UNLIKELY (gst_registry_get_feature_list_or_create (registry,
+              &registry->private->typefind_factory_list,
+              &registry->private->tfl_cookie, GST_TYPE_TYPE_FIND_FACTORY)))
+    registry->private->typefind_factory_list =
+        g_list_sort (registry->private->typefind_factory_list,
+        (GCompareFunc) type_find_factory_rank_cmp);
 
   /* Return reffed copy */
   list =
index 1ea013a..fca00b2 100644 (file)
@@ -146,6 +146,9 @@ gst_type_find_factory_dispose (GObject * object)
  * Gets the list of all registered typefind factories. You must free the
  * list using gst_plugin_feature_list_free.
  *
+ * The returned factories are sorted by highest rank first, and then by
+ * factory name. (behaviour change since 0.10.26)
+ *
  * Returns: the list of all registered #GstTypeFindFactory.
  */
 GList *
index bf5d273..9f4be9a 100644 (file)
 
 #include "gsttypefindhelper.h"
 
-static gint
-type_find_factory_rank_cmp (const GstPluginFeature * fac1,
-    const GstPluginFeature * fac2)
-{
-  if (G_LIKELY (fac1->rank != fac2->rank))
-    return fac2->rank - fac1->rank;
-
-  /* to make the order in which things happen more deterministic,
-   * sort by name when the ranks are the same. */
-  return strcmp (fac1->name, fac2->name);
-}
-
 /* ********************** typefinding in pull mode ************************ */
 
 static void
@@ -279,10 +267,7 @@ gst_type_find_helper_get_range (GstObject * obj,
     find.get_length = helper_find_get_length;
   }
 
-  /* FIXME: we need to keep this list within the registry */
   type_list = gst_type_find_factory_get_list ();
-  type_list =
-      g_list_sort (type_list, (GCompareFunc) type_find_factory_rank_cmp);
 
   for (l = type_list; l; l = l->next) {
     helper.factory = GST_TYPE_FIND_FACTORY (l->data);
@@ -456,8 +441,6 @@ gst_type_find_helper_for_buffer (GstObject * obj, GstBuffer * buf,
 
   /* FIXME: we need to keep this list within the registry */
   type_list = gst_type_find_factory_get_list ();
-  type_list =
-      g_list_sort (type_list, (GCompareFunc) type_find_factory_rank_cmp);
 
   for (l = type_list; l; l = l->next) {
     helper.factory = GST_TYPE_FIND_FACTORY (l->data);
@@ -506,8 +489,6 @@ gst_type_find_helper_for_extension (GstObject * obj, const gchar * extension)
   GST_LOG_OBJECT (obj, "finding caps for extension %s", extension);
 
   type_list = gst_type_find_factory_get_list ();
-  type_list =
-      g_list_sort (type_list, (GCompareFunc) type_find_factory_rank_cmp);
 
   for (l = type_list; l; l = g_list_next (l)) {
     GstTypeFindFactory *factory;