audiobasesink: clip start samples to match clipped start time
authorVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Mon, 24 Feb 2014 16:17:05 +0000 (11:17 -0500)
committerVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Fri, 4 Apr 2014 16:04:06 +0000 (17:04 +0100)
Clock slaving can clip start time to zero, giving us a shorted
duration than we originally got. To keep in sync, we must then
discard the samples falling before that zero timestamp.

This possibly fixes random distortion caused by constant PA
underflows which are never resynced.

gst-libs/gst/audio/gstaudiobasesink.c

index 6efb84c..42e9801 100644 (file)
@@ -1853,6 +1853,23 @@ gst_audio_base_sink_render (GstBaseSink * bsink, GstBuffer * buf)
   render_start = gst_util_uint64_scale_int (render_start, rate, GST_SECOND);
   render_stop = gst_util_uint64_scale_int (render_stop, rate, GST_SECOND);
 
+  /* If the slaving got us an interval spanning 0, render_start will
+     have been set to 0. So if render_start is 0, we check whether
+     render_stop is set to contain all samples. If not, we need to
+     drop samples to match. */
+  if (render_start == 0) {
+    guint nsamples = render_stop - render_start;
+    if (nsamples < samples) {
+      guint diff;
+
+      diff = samples - nsamples;
+      GST_DEBUG_OBJECT (bsink, "Clipped start: %u/%u samples", nsamples,
+          samples);
+      samples -= diff;
+      offset += diff * bpf;
+    }
+  }
+
   /* positive playback rate, first sample is render_start, negative rate, first
    * sample is render_stop. When no rate conversion is active, render exactly
    * the amount of input samples to avoid aligning to rounding errors. */