typefind: Keep typefind factories sorted in the registry. Fixes #599147

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.
This commit is contained in:
Edward Hervey 2009-10-21 09:48:41 +02:00
parent c79ed99bab
commit 5067664c09
3 changed files with 21 additions and 22 deletions

View 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 =

View 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 *

View file

@ -40,18 +40,6 @@
#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;