gst/gstutils.c: Check if the caps of the pads are compatible before returning a pad...
authorSebastian Dröge <slomo@circular-chaos.org>
Tue, 9 Dec 2008 15:45:36 +0000 (15:45 +0000)
committerSebastian Dröge <slomo@circular-chaos.org>
Tue, 9 Dec 2008 15:45:36 +0000 (15:45 +0000)
Original commit message from CVS:
* gst/gstutils.c: (gst_element_get_compatible_pad):
Check if the caps of the pads are compatible before returning
a pad and claiming it is compatible. This, among other things,
fixes a bug with gst-launch where an incompatible pad is chosen
and linking fails. Fixes bug #544003.

ChangeLog
gst/gstutils.c

index 5db745b..892cb50 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2008-12-09  Sebastian Dröge  <sebastian.droege@collabora.co.uk>
 
+       * gst/gstutils.c: (gst_element_get_compatible_pad):
+       Check if the caps of the pads are compatible before returning
+       a pad and claiming it is compatible. This, among other things,
+       fixes a bug with gst-launch where an incompatible pad is chosen
+       and linking fails. Fixes bug #544003.
+
+2008-12-09  Sebastian Dröge  <sebastian.droege@collabora.co.uk>
+
        * libs/gst/check/gstcheck.c: (gst_check_init):
        Revert accidentially commited patch for bug #404631 which
        tries to print a backtrace if a testcase is terminated by
index 75dee71..16e5b0a 100644 (file)
@@ -941,8 +941,6 @@ gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
   GstPad *foundpad = NULL;
   gboolean done;
 
-  /* FIXME check for caps compatibility */
-
   g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
   g_return_val_if_fail (GST_IS_PAD (pad), NULL);
 
@@ -972,21 +970,38 @@ gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
         peer = gst_pad_get_peer (current);
 
         if (peer == NULL && gst_pad_can_link (pad, current)) {
+          GstCaps *temp, *temp2, *intersection;
+
+          /* Now check if the two pads' caps are compatible */
+          temp = gst_pad_get_caps (pad);
+          if (caps) {
+            intersection = gst_caps_intersect (temp, caps);
+            gst_caps_unref (temp);
+          } else {
+            intersection = temp;
+          }
 
-          GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
-              "found existing unlinked pad %s:%s",
-              GST_DEBUG_PAD_NAME (current));
+          temp = gst_pad_get_caps (current);
+          temp2 = gst_caps_intersect (temp, intersection);
+          gst_caps_unref (temp);
+          gst_caps_unref (intersection);
 
-          gst_iterator_free (pads);
+          intersection = temp2;
 
-          return current;
-        } else {
-          GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unreffing pads");
+          if (!gst_caps_is_empty (intersection)) {
+            GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
+                "found existing unlinked compatible pad %s:%s",
+                GST_DEBUG_PAD_NAME (current));
+            gst_iterator_free (pads);
 
-          gst_object_unref (current);
-          if (peer)
-            gst_object_unref (peer);
+            return current;
+          }
         }
+        GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unreffing pads");
+
+        gst_object_unref (current);
+        if (peer)
+          gst_object_unref (peer);
         break;
       }
       case GST_ITERATOR_DONE:
@@ -1145,8 +1160,8 @@ gst_element_factory_can_src_caps (GstElementFactory * factory,
     GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
 
     if (template->direction == GST_PAD_SRC) {
-      if (gst_caps_is_always_compatible (gst_static_caps_get (&template->
-                  static_caps), caps))
+      if (gst_caps_is_always_compatible (gst_static_caps_get
+              (&template->static_caps), caps))
         return TRUE;
     }
     templates = g_list_next (templates);