gst/adder/gstadder.c: Fix timestamps and fix deadlock when stopping the collectpads.
authorWim Taymans <wim.taymans@gmail.com>
Thu, 27 Oct 2005 09:54:06 +0000 (09:54 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Thu, 27 Oct 2005 09:54:06 +0000 (09:54 +0000)
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_query), (gst_adder_collected),
(gst_adder_change_state):
Fix timestamps and fix deadlock when stopping the collectpads.

ChangeLog
gst/adder/gstadder.c

index 0f6fb1e..9b44137 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-10-27  Wim Taymans  <wim@fluendo.com>
+
+       * gst/adder/gstadder.c: (gst_adder_query), (gst_adder_collected),
+       (gst_adder_change_state):
+       Fix timestamps and fix deadlock when stopping the collectpads.
+
 2005-10-27  Zeeshan Ali  <zeenix@gmail.com>
 
        * gst-libs/gst/rtp/gstrtpbuffer.h:
index 5f3eb92..2a3d66c 100644 (file)
@@ -402,17 +402,21 @@ gst_adder_collected (GstCollectPads * pads, gpointer user_data)
 
   /* set timestamps on the output buffer */
   {
+    guint64 samples;
     guint64 duration;
 
     /* width is in bits and we need bytes */
-    duration = size * (adder->width / 8) / adder->channels;
+    samples = size / ((adder->width / 8) * adder->channels);
+    duration = samples * GST_SECOND / adder->rate;
 
     GST_BUFFER_TIMESTAMP (outbuf) = adder->timestamp;
     GST_BUFFER_OFFSET (outbuf) = adder->offset;
-    GST_BUFFER_DURATION (outbuf) = duration;
 
-    adder->offset += duration;
+    adder->offset += samples;
     adder->timestamp = adder->offset * GST_SECOND / adder->rate;
+
+    GST_BUFFER_DURATION (outbuf) = adder->timestamp -
+        GST_BUFFER_TIMESTAMP (outbuf);
   }
 
   /* send it out */
@@ -446,6 +450,11 @@ gst_adder_change_state (GstElement * element, GstStateChange transition)
       break;
     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
       break;
+    case GST_STATE_CHANGE_PAUSED_TO_READY:
+      /* need to unblock the collectpads before calling the
+       * parent change_state so that streaming can finish */
+      gst_collectpads_stop (adder->collect);
+      break;
     default:
       break;
   }
@@ -453,9 +462,6 @@ gst_adder_change_state (GstElement * element, GstStateChange transition)
   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
 
   switch (transition) {
-    case GST_STATE_CHANGE_PAUSED_TO_READY:
-      gst_collectpads_stop (adder->collect);
-      break;
     default:
       break;
   }