Fix a few logic bugs in gst_element_get_compatible_pad_filtered() caused by new pad...
authorDavid Schleef <ds@schleef.org>
Wed, 24 Dec 2003 03:28:27 +0000 (03:28 +0000)
committerDavid Schleef <ds@schleef.org>
Wed, 24 Dec 2003 03:28:27 +0000 (03:28 +0000)
Original commit message from CVS:
Fix a few logic bugs in gst_element_get_compatible_pad_filtered() caused
by new pad negotiation.  Add some debugging, and fix logic bug in gstpad.c.

gst/gstelement.c
gst/gstpad.c

index dd47bba..3657dfa 100644 (file)
@@ -1442,6 +1442,9 @@ gst_element_get_compatible_pad_filtered (GstElement *element, GstPad *pad,
   g_return_val_if_fail (pad != NULL, NULL);
   g_return_val_if_fail (GST_IS_PAD (pad), NULL);
 
+  GST_DEBUG ("finding pad in %s compatible with %s:%s",
+        GST_ELEMENT_NAME (element), GST_DEBUG_PAD_NAME (pad));    
+
   /* let's use the real pad */
   pad = (GstPad *) GST_PAD_REALIZE (pad);
   g_return_val_if_fail (pad != NULL, NULL);
@@ -1460,30 +1463,37 @@ gst_element_get_compatible_pad_filtered (GstElement *element, GstPad *pad,
 
   /* try to create a new one */
   /* requesting is a little crazy, we need a template. Let's create one */
+  templcaps = gst_pad_get_caps (pad);
   if (filtercaps != NULL) {
-    templcaps = gst_caps_intersect (filtercaps, (GstCaps *) GST_RPAD_CAPS (pad));
-    /* FIXME */
-    if (templcaps == NULL)
-      return NULL;
-  } else {
-    templcaps = gst_caps_copy (gst_pad_get_caps (pad));
+    GstCaps *temp;
+    temp = gst_caps_intersect (filtercaps, templcaps);
+    gst_caps_free (templcaps);
+    templcaps = temp;
   }
 
-  templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad), GST_RPAD_DIRECTION (pad),
-                               GST_PAD_ALWAYS, templcaps);
+  templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad),
+      GST_RPAD_DIRECTION (pad), GST_PAD_ALWAYS, templcaps);
   foundpad = gst_element_request_compatible_pad (element, templ);
-  gst_object_unref (GST_OBJECT (templ)); /* this will take care of the caps too */
+  gst_object_unref (GST_OBJECT (templ));
+
+  if (foundpad) return foundpad;
 
-  /* FIXME: this is broken, but it's in here so autoplugging elements that don't
-     have caps on their source padtemplates (spider) can link... */
-  if (!foundpad && !filtercaps) {
-    templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad), GST_RPAD_DIRECTION (pad),
-                                 GST_PAD_ALWAYS, gst_caps_new_any());
+  /* FIXME: this is broken, but it's in here so autoplugging elements
+   * that don't have caps on their source padtemplates (spider) can
+   * link... */
+  //g_warning("got here");
+  //if (filtercaps == NULL) {
+    templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad),
+        GST_RPAD_DIRECTION (pad), GST_PAD_ALWAYS, gst_caps_new_any());
     foundpad = gst_element_request_compatible_pad (element, templ);
     gst_object_unref (GST_OBJECT (templ));
-  }
+
+    if (foundpad) return foundpad;
+  //}
   
-  return foundpad;
+  g_critical("could not find a compatible pad");
+
+  return NULL;
 }
 
 /**
index 6205c6f..8eeaa42 100644 (file)
@@ -1052,11 +1052,14 @@ gst_pad_link_fixate (GstPadLink *link)
   g_return_if_fail (caps != NULL);
   g_return_if_fail (!gst_caps_is_empty(caps));
 
+  GST_DEBUG_CAPS ("trying to fixate caps", caps);
+
   while (!gst_caps_is_fixed (caps)) {
     if (link->app_fixate) {
       newcaps = (link->app_fixate) (GST_PAD (link->srcpad), caps, NULL);
       if (newcaps) {
         caps = newcaps;
+        GST_DEBUG_CAPS ("app fixated to", caps);
         continue;
       }
     }
@@ -1065,6 +1068,7 @@ gst_pad_link_fixate (GstPadLink *link)
           caps, NULL);
       if (newcaps) {
         caps = newcaps;
+        GST_DEBUG_CAPS ("src pad fixated to", caps);
         continue;
       }
     }
@@ -1073,10 +1077,12 @@ gst_pad_link_fixate (GstPadLink *link)
           caps, NULL);
       if (newcaps) {
         caps = newcaps;
+        GST_DEBUG_CAPS ("sink pad fixated to", caps);
         continue;
       }
     }
     caps = _gst_pad_default_fixate_func (GST_PAD(link->srcpad), caps, NULL);
+    GST_DEBUG_CAPS ("core fixated to", caps);
   }
 
   GST_DEBUG_CAPS ("fixate decided on", caps);
@@ -1296,7 +1302,7 @@ gst_pad_can_link_filtered (GstPad *srcpad, GstPad *sinkpad,
   GstRealPad *realsrc, *realsink;
   GstPadLink *link;
 
-  /* FIXME This function is gosss.  It's almost a direct copy of
+  /* FIXME This function is gross.  It's almost a direct copy of
    * gst_pad_link_filtered().  Any decent programmer would attempt
    * to merge the two functions, which I will do some day. --ds
    */
@@ -1376,10 +1382,6 @@ gst_pad_can_link_filtered (GstPad *srcpad, GstPad *sinkpad,
   link->sinkcaps = gst_pad_get_caps (link->sinkpad);
   if (filtercaps) link->filtercaps = gst_caps_copy (filtercaps);
 
-  if (!gst_pad_link_ready_for_negotiation (link)) {
-    return FALSE;
-  }
-
   gst_pad_link_intersect (link);
   if (gst_caps_is_empty (link->caps))
     return FALSE;