Fix caps negotiation problems.
authorDavid Schleef <ds@schleef.org>
Mon, 19 May 2003 02:36:01 +0000 (02:36 +0000)
committerDavid Schleef <ds@schleef.org>
Mon, 19 May 2003 02:36:01 +0000 (02:36 +0000)
Original commit message from CVS:
Fix caps negotiation problems.

gst/elements/gsttee.c
plugins/elements/gsttee.c

index a4be79f..1b2eba0 100644 (file)
@@ -125,13 +125,21 @@ gst_tee_sinklink (GstPad *pad, GstCaps *caps)
   GstTee *tee;
   const GList *pads;
   GstPadLinkReturn set_retval;
+  GstCaps *caps1;
   
+  GST_DEBUG (0, "gst_tee_sinklink caps=%s", gst_caps_to_string(caps));
+
   tee = GST_TEE (gst_pad_get_parent (pad));
 
   if (!GST_CAPS_IS_FIXED (caps)) {
     return GST_PAD_LINK_DELAYED;
   }
 
+  if (GST_CAPS_IS_CHAINED (caps)) {
+    caps1 = gst_caps_copy_1(caps);
+    caps = caps1;
+  }
+
   /* go through all the src pads */
   pads = gst_element_get_pad_list (GST_ELEMENT (tee));
 
@@ -139,10 +147,10 @@ gst_tee_sinklink (GstPad *pad, GstCaps *caps)
     GstPad *outpad = GST_PAD (pads->data);
     pads = g_list_next (pads);
                     
-    if (GST_PAD_DIRECTION (outpad) != GST_PAD_SRC || !GST_PAD_IS_USABLE (outpad))
+    if (GST_PAD_DIRECTION (outpad) != GST_PAD_SRC || !GST_PAD_IS_LINKED (outpad))
       continue;
 
-    if ((set_retval = gst_pad_proxy_link (outpad, caps)) <= 0) {
+    if ((set_retval = gst_pad_try_set_caps (outpad, caps)) <= 0) {
       return set_retval;
     }
   }
@@ -154,35 +162,44 @@ gst_tee_srclink (GstPad *pad, GstCaps *caps)
 {
   GstTee *tee;
 
+  GST_DEBUG (0, "gst_tee_srclink caps=%s", gst_caps_to_string(caps));
+
   tee = GST_TEE (gst_pad_get_parent (pad));
 
   return gst_pad_proxy_link (tee->sinkpad, caps);
 }
 
 static GstCaps* 
-gst_tee_sinkgetcaps (GstPad *pad, GstCaps *filter) 
+gst_tee_getcaps (GstPad *pad, GstCaps *filter) 
 {
   GstCaps *caps = NULL;
   GstTee *tee;
   const GList *pads;
 
+  GST_DEBUG (0, "gst_tee_getcaps");
+
   tee = GST_TEE (gst_pad_get_parent (pad));
 
   pads = gst_element_get_pad_list (GST_ELEMENT (tee));
 
   while (pads) {
     GstPad *srcpad = GST_PAD_CAST (pads->data);
+    GstPad *peer;
     GstCaps *peercaps;
+    GstCaps *newcaps;
 
     pads = g_list_next (pads);
 
-    if (!GST_PAD_IS_SRC (srcpad))
+    peer = gst_pad_get_peer(srcpad);
+    if(!peer){
       continue;
+    }
 
-    peercaps = gst_pad_get_caps (srcpad);
-    caps = gst_caps_intersect (caps, peercaps);
+    peercaps = gst_pad_get_caps (peer);
+    newcaps = gst_caps_intersect (caps, peercaps);
     gst_caps_unref (caps);
     gst_caps_unref (peercaps);
+    caps = newcaps;
   }
 
   return caps;
@@ -195,7 +212,7 @@ gst_tee_init (GstTee *tee)
   gst_element_add_pad (GST_ELEMENT (tee), tee->sinkpad);
   gst_pad_set_chain_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_chain));
   gst_pad_set_link_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_sinklink));
-  gst_pad_set_getcaps_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_sinkgetcaps));
+  gst_pad_set_getcaps_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_getcaps));
 
   tee->silent = FALSE;
   tee->last_message = NULL;
@@ -254,6 +271,7 @@ gst_tee_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar
   srcpad = gst_pad_new_from_template (templ, name);
   g_free (name);
   gst_pad_set_link_function (srcpad, GST_DEBUG_FUNCPTR (gst_tee_srclink));
+  gst_pad_set_getcaps_function (srcpad, GST_DEBUG_FUNCPTR (gst_tee_getcaps));
   gst_element_add_pad (GST_ELEMENT (tee), srcpad);
   GST_PAD_ELEMENT_PRIVATE (srcpad) = NULL;
 
index a4be79f..1b2eba0 100644 (file)
@@ -125,13 +125,21 @@ gst_tee_sinklink (GstPad *pad, GstCaps *caps)
   GstTee *tee;
   const GList *pads;
   GstPadLinkReturn set_retval;
+  GstCaps *caps1;
   
+  GST_DEBUG (0, "gst_tee_sinklink caps=%s", gst_caps_to_string(caps));
+
   tee = GST_TEE (gst_pad_get_parent (pad));
 
   if (!GST_CAPS_IS_FIXED (caps)) {
     return GST_PAD_LINK_DELAYED;
   }
 
+  if (GST_CAPS_IS_CHAINED (caps)) {
+    caps1 = gst_caps_copy_1(caps);
+    caps = caps1;
+  }
+
   /* go through all the src pads */
   pads = gst_element_get_pad_list (GST_ELEMENT (tee));
 
@@ -139,10 +147,10 @@ gst_tee_sinklink (GstPad *pad, GstCaps *caps)
     GstPad *outpad = GST_PAD (pads->data);
     pads = g_list_next (pads);
                     
-    if (GST_PAD_DIRECTION (outpad) != GST_PAD_SRC || !GST_PAD_IS_USABLE (outpad))
+    if (GST_PAD_DIRECTION (outpad) != GST_PAD_SRC || !GST_PAD_IS_LINKED (outpad))
       continue;
 
-    if ((set_retval = gst_pad_proxy_link (outpad, caps)) <= 0) {
+    if ((set_retval = gst_pad_try_set_caps (outpad, caps)) <= 0) {
       return set_retval;
     }
   }
@@ -154,35 +162,44 @@ gst_tee_srclink (GstPad *pad, GstCaps *caps)
 {
   GstTee *tee;
 
+  GST_DEBUG (0, "gst_tee_srclink caps=%s", gst_caps_to_string(caps));
+
   tee = GST_TEE (gst_pad_get_parent (pad));
 
   return gst_pad_proxy_link (tee->sinkpad, caps);
 }
 
 static GstCaps* 
-gst_tee_sinkgetcaps (GstPad *pad, GstCaps *filter) 
+gst_tee_getcaps (GstPad *pad, GstCaps *filter) 
 {
   GstCaps *caps = NULL;
   GstTee *tee;
   const GList *pads;
 
+  GST_DEBUG (0, "gst_tee_getcaps");
+
   tee = GST_TEE (gst_pad_get_parent (pad));
 
   pads = gst_element_get_pad_list (GST_ELEMENT (tee));
 
   while (pads) {
     GstPad *srcpad = GST_PAD_CAST (pads->data);
+    GstPad *peer;
     GstCaps *peercaps;
+    GstCaps *newcaps;
 
     pads = g_list_next (pads);
 
-    if (!GST_PAD_IS_SRC (srcpad))
+    peer = gst_pad_get_peer(srcpad);
+    if(!peer){
       continue;
+    }
 
-    peercaps = gst_pad_get_caps (srcpad);
-    caps = gst_caps_intersect (caps, peercaps);
+    peercaps = gst_pad_get_caps (peer);
+    newcaps = gst_caps_intersect (caps, peercaps);
     gst_caps_unref (caps);
     gst_caps_unref (peercaps);
+    caps = newcaps;
   }
 
   return caps;
@@ -195,7 +212,7 @@ gst_tee_init (GstTee *tee)
   gst_element_add_pad (GST_ELEMENT (tee), tee->sinkpad);
   gst_pad_set_chain_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_chain));
   gst_pad_set_link_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_sinklink));
-  gst_pad_set_getcaps_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_sinkgetcaps));
+  gst_pad_set_getcaps_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_getcaps));
 
   tee->silent = FALSE;
   tee->last_message = NULL;
@@ -254,6 +271,7 @@ gst_tee_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar
   srcpad = gst_pad_new_from_template (templ, name);
   g_free (name);
   gst_pad_set_link_function (srcpad, GST_DEBUG_FUNCPTR (gst_tee_srclink));
+  gst_pad_set_getcaps_function (srcpad, GST_DEBUG_FUNCPTR (gst_tee_getcaps));
   gst_element_add_pad (GST_ELEMENT (tee), srcpad);
   GST_PAD_ELEMENT_PRIVATE (srcpad) = NULL;