tee: add special case for only one pad conected
authorStefan Kost <ensonic@users.sf.net>
Thu, 3 Dec 2009 14:44:28 +0000 (16:44 +0200)
committerStefan Kost <ensonic@users.sf.net>
Thu, 3 Dec 2009 14:44:28 +0000 (16:44 +0200)
It is not easy to setup a tee on the fly, thus apps need to add them always if
they might need them. This changes the code so, that if only one src-pad is
active, we push buffers directly. In the normal code path all buffers are pushed
with an extra ref, that forces followup inplace elements to copy the data.

plugins/elements/gsttee.c

index a7df2ba..1e4b5ac 100644 (file)
@@ -643,9 +643,25 @@ gst_tee_handle_data (GstTee * tee, gpointer data, gboolean is_list)
     gst_tee_do_message (tee, tee->sinkpad, data, is_list);
 
   GST_OBJECT_LOCK (tee);
+  pads = GST_ELEMENT_CAST (tee)->srcpads;
+
+  /* special case for just one pad that avoids reffing the buffer */
+  if (!pads->next) {
+    GstPad *pad = GST_PAD_CAST (pads->data);
+
+    GST_OBJECT_UNLOCK (tee);
+    if (pad == tee->pull_pad) {
+      ret = GST_FLOW_OK;
+    } else if (!is_list) {
+      ret = gst_pad_push (pad, GST_BUFFER_CAST (data));
+    } else {
+      ret = gst_pad_push_list (pad, GST_BUFFER_LIST_CAST (data));
+    }
+    return ret;
+  }
 
   /* mark all pads as 'not pushed on yet' */
-  g_list_foreach (GST_ELEMENT_CAST (tee)->srcpads, (GFunc) clear_pads, tee);
+  g_list_foreach (pads, (GFunc) clear_pads, tee);
 
 restart:
   cret = GST_FLOW_NOT_LINKED;