pulsesink: Update segdone periodically
authorArun Raghavan <arun.raghavan@collabora.co.uk>
Tue, 20 Nov 2012 06:44:07 +0000 (12:14 +0530)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Sat, 23 Feb 2013 03:56:19 +0000 (09:26 +0530)
This makes sure that we update segdone based on the read index received
during latency updates. As the comment notes, we make some compromises
to deal with the fact that segdone is a segment multiple, while the read
index offers finer granularity. The updates are also not very often
(100ms since that is how often automatic timing updates are provided).

All this is required for the baseaudiosink sample alignment code to work
at all.

https://bugzilla.gnome.org/show_bug.cgi?id=694257

ext/pulse/pulsesink.c

index 0827a06..1029e97 100644 (file)
@@ -657,6 +657,7 @@ gst_pulsering_stream_latency_cb (pa_stream * s, void *userdata)
 {
   GstPulseSink *psink;
   GstPulseRingBuffer *pbuf;
+  GstAudioRingBuffer *ringbuf;
   const pa_timing_info *info;
   pa_usec_t sink_usec;
 
@@ -664,11 +665,26 @@ gst_pulsering_stream_latency_cb (pa_stream * s, void *userdata)
 
   pbuf = GST_PULSERING_BUFFER_CAST (userdata);
   psink = GST_PULSESINK_CAST (GST_OBJECT_PARENT (pbuf));
+  ringbuf = GST_AUDIO_RING_BUFFER (pbuf);
 
   if (!info) {
     GST_LOG_OBJECT (psink, "latency update (information unknown)");
     return;
   }
+
+  if (!info->read_index_corrupt) {
+    /* Update segdone based on the read index. segdone is of segment
+     * granularity, while the read index is at byte granularity. We take the
+     * ceiling while converting the latter to the former since it is more
+     * conservative to report that we've read more than we have than to report
+     * less. One concern here is that latency updates happen every 100ms, which
+     * means segdone is not updated very often, but increasing the update
+     * frequency would mean more communication overhead. */
+    g_atomic_int_set (&ringbuf->segdone,
+        (int) gst_util_uint64_scale_ceil (info->read_index, 1,
+            ringbuf->spec.segsize));
+  }
+
   sink_usec = info->configured_sink_usec;
 
   GST_LOG_OBJECT (psink,