diff -Naurp -x .svn gst-plugins-base-orig/gst/playback/gstdecodebin2.c gst-plugins-base/gst/playback/gstdecodebin2.c
--- gst-plugins-base-orig/gst/playback/gstdecodebin2.c	2007-06-12 17:46:51.000000000 +0200
+++ gst-plugins-base/gst/playback/gstdecodebin2.c	2007-06-16 14:38:59.000000000 +0200
@@ -107,9 +107,9 @@ struct _GstDecodeBinClass
   void (*unknown_type) (GstElement * element, GstPad * pad, GstCaps * caps);
   /* signal fired to know if we continue trying to decode the given caps */
     gboolean (*autoplug_continue) (GstElement * element, GstCaps * caps);
-  /* signal fired to reorder the proposed list of factories */
-    gboolean (*autoplug_sort) (GstElement * element, GstCaps * caps,
-      GList ** list);
+  /* signal fired to select from the proposed list of factories */
+  GstElementFactory * (*autoplug_select) (GstElement * element, GstCaps * caps,
+      GValueArray * factories);
 };
 
 /* signals */
@@ -119,7 +119,7 @@ enum
   SIGNAL_REMOVED_DECODED_PAD,
   SIGNAL_UNKNOWN_TYPE,
   SIGNAL_AUTOPLUG_CONTINUE,
-  SIGNAL_AUTOPLUG_SORT,
+  SIGNAL_AUTOPLUG_SELECT,
   LAST_SIGNAL
 };
 
@@ -148,8 +148,8 @@ static void type_found (GstElement * typ
 
 static gboolean gst_decode_bin_autoplug_continue (GstElement * element,
     GstCaps * caps);
-static gboolean gst_decode_bin_autoplug_sort (GstElement * element,
-    GstCaps * caps, GList ** list);
+static GstElementFactory * gst_decode_bin_autoplug_select (GstElement * element,
+    GstCaps * caps, GValueArray * list);
 static void gst_decode_bin_set_property (GObject * object, guint prop_id,
     const GValue * value, GParamSpec * pspec);
 static void gst_decode_bin_get_property (GObject * object, guint prop_id,
@@ -308,6 +308,20 @@ _gst_boolean_accumulator (GSignalInvocat
   return myboolean;
 }
 
+static gboolean
+_gst_object_accumulator (GSignalInvocationHint * ihint,
+    GValue * return_accu, const GValue * handler_return, gpointer dummy)
+{
+  gpointer factory;
+
+  factory = g_value_get_object (handler_return);
+  if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
+    g_value_set_object (return_accu, factory);
+
+  /* stop emission if !NULL */
+  return (factory == NULL);
+}
+
 static void
 gst_decode_bin_class_init (GstDecodeBinClass * klass)
 {
@@ -390,26 +404,27 @@ gst_decode_bin_class_init (GstDecodeBinC
       G_TYPE_BOOLEAN, 1, GST_TYPE_CAPS);
 
   /**
-   * GstDecodeBin2::autoplug-sort:
+   * GstDecodeBin2::autoplug-select:
    * @caps: The #GstCaps.
-   * @factories: A #GList of possible #GstElementFactory to use.
+   * @factories: A #GValueArray of possible #GstElementFactory to use, sorted by
+   * rank (higher ranks come first).
    *
    * This signal is emitted once decodebin2 has found all the possible
    * #GstElementFactory that can be used to handle the given @caps.
    *
-   * UNSTABLE API. Will change soon.
+   * UNSTABLE API. Might change soon.
    *
-   * Returns: #TRUE if you wish decodebin2 to start trying to decode
-   * the given @caps with the list of factories. #FALSE if you do not want
-   * these #GstCaps, if so the pad will be exposed as unknown (see
-   * 'unknown-type' signal).
+   * Returns: A #GstElementFactory (most probably one from the provided list)
+   * that you wish decodebin2 to use for trying to decode the given @caps.
+   * #NULL to continue emission of the signal.  The default handler always
+   * returns the first possible factory.
    */
 
-  gst_decode_bin_signals[SIGNAL_AUTOPLUG_SORT] =
-      g_signal_new ("autoplug-sort", G_TYPE_FROM_CLASS (klass),
-      G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_sort),
-      _gst_boolean_accumulator, NULL, gst_play_marshal_BOOLEAN__OBJECT_POINTER,
-      G_TYPE_BOOLEAN, 2, GST_TYPE_CAPS, G_TYPE_POINTER);
+  gst_decode_bin_signals[SIGNAL_AUTOPLUG_SELECT] =
+      g_signal_new ("autoplug-select", G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_select),
+      _gst_object_accumulator, NULL, gst_play_marshal_OBJECT__OBJECT_POINTER,
+      GST_TYPE_ELEMENT_FACTORY, 2, GST_TYPE_CAPS, G_TYPE_VALUE_ARRAY);
 
   g_object_class_install_property (gobject_klass, PROP_CAPS,
       g_param_spec_boxed ("caps", "Caps", "The caps on which to stop decoding.",
@@ -417,7 +432,7 @@ gst_decode_bin_class_init (GstDecodeBinC
 
   klass->autoplug_continue =
       GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_continue);
-  klass->autoplug_sort = GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_sort);
+  klass->autoplug_select = GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_select);
 
   gst_element_class_add_pad_template (gstelement_klass,
       gst_static_pad_template_get (&decoder_bin_sink_template));
@@ -695,11 +710,15 @@ gst_decode_bin_autoplug_continue (GstEle
   return TRUE;
 }
 
-static gboolean
-gst_decode_bin_autoplug_sort (GstElement * element, GstCaps * caps,
-    GList ** list)
+static GstElementFactory *
+gst_decode_bin_autoplug_select (GstElement * element, GstCaps * caps,
+    GValueArray * factories)
 {
-  return TRUE;
+  g_return_val_if_fail (factories != NULL, NULL);
+  g_return_val_if_fail (factories->n_values > 0, NULL);
+
+  /* Return first factory. */  
+  return g_value_get_object (g_value_array_get_nth (factories, 0));
 }
 
 
@@ -710,11 +729,12 @@ gst_decode_bin_autoplug_sort (GstElement
 
 static gboolean are_raw_caps (GstDecodeBin * dbin, GstCaps * caps);
 static gboolean is_demuxer_element (GstElement * srcelement);
-static GList *find_compatibles (GstDecodeBin * decode_bin,
+static GValueArray *find_compatibles (GstDecodeBin * decode_bin,
     const GstCaps * caps);
 
 static gboolean connect_pad (GstDecodeBin * dbin, GstElement * src,
-    GstPad * pad, GList * factories, GstDecodeGroup * group);
+    GstPad * pad, GstCaps * caps, GValueArray * factories,
+    GstDecodeGroup * group);
 static gboolean connect_element (GstDecodeBin * dbin, GstElement * element,
     GstDecodeGroup * group);
 static void expose_pad (GstDecodeBin * dbin, GstElement * src, GstPad * pad,
@@ -739,8 +759,7 @@ analyze_new_pad (GstDecodeBin * dbin, Gs
     GstCaps * caps, GstDecodeGroup * group)
 {
   gboolean apcontinue = TRUE;
-  GList *factories = NULL;
-  gboolean apsort = TRUE;
+  GValueArray *factories = NULL;
 
   GST_DEBUG_OBJECT (dbin, "Pad %s:%s caps:%" GST_PTR_FORMAT,
       GST_DEBUG_PAD_NAME (pad), caps);
@@ -759,18 +778,9 @@ analyze_new_pad (GstDecodeBin * dbin, Gs
   if ((!apcontinue) || are_raw_caps (dbin, caps))
     goto expose_pad;
 
-  /* 1.b else if there's no compatible factory or 'autoplug-sort' returned FALSE, goto pad_not_used */
-  if ((factories = find_compatibles (dbin, caps))) {
-    /* emit autoplug-sort */
-    g_signal_emit (G_OBJECT (dbin),
-        gst_decode_bin_signals[SIGNAL_AUTOPLUG_SORT],
-        0, caps, &factories, &apsort);
-    if (!apsort) {
-      g_list_free (factories);
-      /* User doesn't want that pad */
-      goto pad_not_wanted;
-    }
-  } else {
+  /* 1.b else if there's no compatible factory goto unknown_type */
+  factories = find_compatibles (dbin, caps);
+  if (factories == NULL) {
     /* no compatible factories */
     goto unknown_type;
   }
@@ -778,8 +788,8 @@ analyze_new_pad (GstDecodeBin * dbin, Gs
   /* 1.c else goto pad_is_valid */
   GST_LOG_OBJECT (pad, "Let's continue discovery on this pad");
 
-  connect_pad (dbin, src, pad, factories, group);
-  g_list_free (factories);
+  connect_pad (dbin, src, pad, caps, factories, group);
+  g_value_array_free (factories);
 
   return;
 
@@ -790,12 +800,6 @@ expose_pad:
     return;
   }
 
-pad_not_wanted:
-  {
-    GST_LOG_OBJECT (pad, "User doesn't want this pad, stopping discovery");
-    return;
-  }
-
 unknown_type:
   {
     GST_LOG_OBJECT (pad, "Unknown type, firing signal");
@@ -831,13 +835,15 @@ any_caps:
 
 static gboolean
 connect_pad (GstDecodeBin * dbin, GstElement * src, GstPad * pad,
-    GList * factories, GstDecodeGroup * group)
+    GstCaps * caps, GValueArray * factories, GstDecodeGroup * group)
 {
   gboolean res = FALSE;
-  GList *tmp;
+  gint i;
   GstPad *mqpad = NULL;
 
   g_return_val_if_fail (factories != NULL, FALSE);
+  g_return_val_if_fail (factories->n_values > 0, FALSE);
+
   GST_DEBUG_OBJECT (dbin, "pad %s:%s , group:%p",
       GST_DEBUG_PAD_NAME (pad), group);
 
@@ -859,11 +865,29 @@ connect_pad (GstDecodeBin * dbin, GstEle
   }
 
   /* 2. Try to create an element and link to it */
-  for (tmp = factories; tmp; tmp = g_list_next (tmp)) {
-    GstElementFactory *factory = (GstElementFactory *) tmp->data;
+  while (factories->n_values > 0) {
+    GstElementFactory *factory;
     GstElement *element;
     GstPad *sinkpad;
 
+    /* emit autoplug-select */
+    g_signal_emit (G_OBJECT (dbin),
+        gst_decode_bin_signals[SIGNAL_AUTOPLUG_SELECT],
+        0, caps, factories, &factory);
+
+    /* factory is != NULL now since the default handler selects the first
+     * factory if all connected user handlers returned NULL. */
+
+    /* Remove selected factory from the list. */
+    for (i = 0; i < factories->n_values; i++) {
+      gpointer obj = g_value_get_object (g_value_array_get_nth (factories, i));
+
+      if (obj == (gpointer) factory) {
+        g_value_array_remove (factories, i);
+        break;
+      }
+    }
+    
     /* 2.1. Try to create an element */
     if ((element = gst_element_factory_create (factory, NULL)) == NULL) {
       GST_WARNING_OBJECT (dbin, "Could not create an element from %s",
@@ -1205,14 +1229,14 @@ no_group:
   }
 }
 
-/* this function runs through the element factories and returns a list
- * of all elements that are able to sink the given caps 
+/* this function runs through the element factories and returns a value array of
+ * all elements that are able to sink the given caps
  */
-static GList *
+static GValueArray *
 find_compatibles (GstDecodeBin * decode_bin, const GstCaps * caps)
 {
   GList *factories;
-  GList *to_try = NULL;
+  GValueArray *to_try = g_value_array_new (0);
 
   /* loop over all the factories */
   for (factories = decode_bin->factories; factories;
@@ -1240,7 +1264,11 @@ find_compatibles (GstDecodeBin * decode_
         /* check if the intersection is empty */
         if (!gst_caps_is_empty (intersect)) {
           /* non empty intersection, we can use this element */
-          to_try = g_list_prepend (to_try, factory);
+          GValue val = {0,};
+          g_value_init (&val, G_TYPE_OBJECT);
+          g_value_set_object (&val, factory);
+          g_value_array_append (to_try, &val);
+          g_value_unset (&val);
           gst_caps_unref (intersect);
           break;
         }
@@ -1248,7 +1276,6 @@ find_compatibles (GstDecodeBin * decode_
       }
     }
   }
-  to_try = g_list_reverse (to_try);
 
   return to_try;
 }
diff -Naurp -x .svn gst-plugins-base-orig/gst/playback/gstplay-marshal.list gst-plugins-base/gst/playback/gstplay-marshal.list
--- gst-plugins-base-orig/gst/playback/gstplay-marshal.list	2007-06-12 17:46:51.000000000 +0200
+++ gst-plugins-base/gst/playback/gstplay-marshal.list	2007-06-12 17:46:28.000000000 +0200
@@ -1,3 +1,3 @@
 BOOLEAN:OBJECT
 VOID:OBJECT,BOOLEAN
-BOOLEAN:OBJECT,POINTER
+OBJECT:OBJECT,POINTER
