gst-libs/gst/audio/gstbaseaudiosink.c: Buffers with no timestamps get aligned with...
authorWim Taymans <wim.taymans@gmail.com>
Mon, 24 Oct 2005 14:52:22 +0000 (14:52 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Mon, 24 Oct 2005 14:52:22 +0000 (14:52 +0000)
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_offset), (gst_base_audio_sink_render):
Buffers with no timestamps get aligned with previous buffers or
on underrun, played ASAP.

ChangeLog
gst-libs/gst/audio/gstbaseaudiosink.c

index b0533c6..419701d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-10-24  Wim Taymans  <wim@fluendo.com>
+
+       * gst-libs/gst/audio/gstbaseaudiosink.c:
+       (gst_base_audio_sink_get_offset), (gst_base_audio_sink_render):
+       Buffers with no timestamps get aligned with previous buffers or
+       on underrun, played ASAP.
+
 2005-10-24  Julien MOUTTE  <julien@moutte.net>
 
        * gst-libs/gst/video/video.h:
index 2aaa1a1..c9b99ad 100644 (file)
@@ -336,6 +336,38 @@ wrong_state:
   }
 }
 
+static guint64
+gst_base_audio_sink_get_offset (GstBaseAudioSink * sink)
+{
+  guint64 sample;
+  gint writeseg, segdone, sps;
+  gint diff;
+
+  /* assume we can append to the previous sample */
+  sample = sink->next_sample;
+
+  sps = sink->ringbuffer->samples_per_seg;
+
+  /* figure out the segment and the offset inside the segment where
+   * the sample should be written. */
+  writeseg = sample / sps;
+
+  /* get the currently processed segment */
+  segdone = g_atomic_int_get (&sink->ringbuffer->segdone)
+      - sink->ringbuffer->segbase;
+
+  /* see how far away it is from the write segment */
+  diff = writeseg - segdone;
+  if (diff < 0) {
+    /* sample would be dropped, position to next playable position */
+    sample = (segdone + 1) * sps;
+  }
+
+  g_print ("diff: %d\n", diff);
+
+  return sample;
+}
+
 static GstFlowReturn
 gst_base_audio_sink_render (GstBaseSink * bsink, GstBuffer * buf)
 {
@@ -375,7 +407,7 @@ gst_base_audio_sink_render (GstBaseSink * bsink, GstBuffer * buf)
       GST_TIME_ARGS (time), in_offset, GST_TIME_ARGS (bsink->segment_start));
 
   if (!GST_CLOCK_TIME_IS_VALID (time)) {
-    render_offset = sink->next_sample;
+    render_offset = gst_base_audio_sink_get_offset (sink);
     goto no_sync;
   }
 
@@ -423,7 +455,7 @@ gst_base_audio_sink_render (GstBaseSink * bsink, GstBuffer * buf)
 
 no_sync:
   /* clip length based on rate */
-  samples /= ABS (bsink->segment_rate);
+  samples = MIN (samples, samples / ABS (bsink->segment_rate));
 
   /* the next sample should be current sample and its length */
   sink->next_sample = render_offset + samples;