Index: gsttee.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/elements/gsttee.c,v
retrieving revision 1.29.4.1
diff -u -r1.29.4.1 gsttee.c
--- gsttee.c	2 Feb 2003 00:05:38 -0000	1.29.4.1
+++ gsttee.c	16 Sep 2003 17:12:36 -0000
@@ -20,8 +20,13 @@
  * Boston, MA 02111-1307, USA.
  */
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include "gsttee.h"
 
+#define GST_CAT_DEFAULT gst_tee_debug
 
 GstElementDetails gst_tee_details = {
   "Tee pipe fitting",
@@ -52,7 +57,7 @@
   "src%d",
   GST_PAD_SRC,
   GST_PAD_REQUEST,
-  NULL			/* no caps */
+  NULL
 );
 
 static void 	gst_tee_class_init	(GstTeeClass *klass);
@@ -125,13 +130,21 @@
   GstTee *tee;
   const GList *pads;
   GstPadLinkReturn set_retval;
+  GstCaps *caps1;
   
+  GST_DEBUG (0, "gst_tee_sinklink caps=%s", gst_caps_get_mime(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,16 +152,66 @@
     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_try_set_caps (outpad, caps)) <= 0) {
       return set_retval;
+    } else {
+      GST_PAD_ELEMENT_PRIVATE (outpad) = (gpointer) 0x1;
     }
   }
   return GST_PAD_LINK_OK;
 }
 
+static GstPadLinkReturn 
+gst_tee_srclink (GstPad *pad, GstCaps *caps) 
+{
+  GstTee *tee;
+
+  GST_DEBUG (0, "gst_tee_srclink caps=%s", gst_caps_get_mime(caps));
+
+  tee = GST_TEE (gst_pad_get_parent (pad));
+
+  return gst_pad_proxy_link (tee->sinkpad, caps);
+}
+
+static GstCaps* 
+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);
+
+    peer = gst_pad_get_peer(srcpad);
+    if(!peer){
+      continue;
+    }
+
+    peercaps = gst_pad_get_caps (peer);
+    newcaps = gst_caps_intersect (caps, peercaps);
+    gst_caps_unref (caps);
+    gst_caps_sink (peercaps);
+    caps = newcaps;
+  }
+
+  return caps;
+}
+
 static void 
 gst_tee_init (GstTee *tee) 
 {
@@ -156,6 +219,7 @@
   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_getcaps));
 
   tee->silent = FALSE;
   tee->last_message = NULL;
@@ -213,11 +277,18 @@
   
   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;
 
   if (GST_PAD_CAPS (tee->sinkpad)) {
     gst_pad_try_set_caps (srcpad, GST_PAD_CAPS (tee->sinkpad));
+
+    if (gst_element_get_state (GST_ELEMENT (tee)) == GST_STATE_PAUSED ||
+	gst_element_get_state (GST_ELEMENT (tee)) == GST_STATE_PLAYING) {
+      GST_PAD_ELEMENT_PRIVATE (srcpad) =  (gpointer) 0x1;
+    }
   }
 
   return srcpad;
@@ -307,9 +378,21 @@
       g_object_notify (G_OBJECT (tee), "last_message");
     }
 
-    if (GST_PAD_IS_USABLE (outpad))
+    if (GST_PAD_IS_USABLE (outpad)) {
+      if (GST_PAD_ELEMENT_PRIVATE (outpad) == (gpointer) 0x1) {
+	if (GST_BUFFER_TIMESTAMP (buf) != 0) {
+	  GstEvent *event;
+	  event = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME,
+					       GST_BUFFER_TIMESTAMP (buf),
+					       0);
+	  g_print ("pushing a discont event %llu", GST_BUFFER_TIMESTAMP (buf));
+	  gst_pad_push (outpad, GST_BUFFER (event));
+	}
+	GST_PAD_ELEMENT_PRIVATE (outpad) = NULL;
+      }
+
       gst_pad_push (outpad, buf);
-    else
+    } else
       gst_buffer_unref (buf);
   }
 }
@@ -321,4 +404,3 @@
 
   return TRUE;
 }
-
