[vlc-commits] PulseAudio: do not ignore latency updates before stream trigger

Rémi Denis-Courmont git at videolan.org
Thu Aug 9 20:16:51 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Aug  9 20:57:10 2012 +0300| [1b06737a297cc5b9c48dd12e2e456b45bc6891d2] | committer: Rémi Denis-Courmont

PulseAudio: do not ignore latency updates before stream trigger

Such a latency update is an opportunity to reschedule the stream
trigger time, or to trigger immediately if late. That can reduce the
initial audio delay in some cases.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1b06737a297cc5b9c48dd12e2e456b45bc6891d2
---

 modules/audio_output/pulse.c |   36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c
index 4c9351f..14b4b24 100644
--- a/modules/audio_output/pulse.c
+++ b/modules/audio_output/pulse.c
@@ -195,10 +195,7 @@ static void stream_start(pa_stream *s, audio_output_t *aout)
     aout_sys_t *sys = aout->sys;
     pa_operation *op;
 
-    if (sys->trigger != NULL) {
-        vlc_pa_rttime_free(sys->mainloop, sys->trigger);
-        sys->trigger = NULL;
-    }
+    assert (sys->trigger == NULL);
 
     op = pa_stream_cork(s, 0, NULL, NULL);
     if (op != NULL)
@@ -229,8 +226,11 @@ static void stream_trigger_cb(pa_mainloop_api *api, pa_time_event *e,
     audio_output_t *aout = userdata;
     aout_sys_t *sys = aout->sys;
 
-    msg_Dbg(aout, "starting deferred");
     assert (sys->trigger == e);
+
+    msg_Dbg(aout, "starting deferred");
+    vlc_pa_rttime_free(sys->mainloop, sys->trigger);
+    sys->trigger = NULL;
     stream_start(sys->stream, aout);
     (void) api; (void) e; (void) tv;
 }
@@ -248,18 +248,21 @@ static void stream_resync(audio_output_t *aout, pa_stream *s)
 
     assert (sys->pts != VLC_TS_INVALID);
 
+    if (sys->trigger != NULL) {
+        vlc_pa_rttime_free(sys->mainloop, sys->trigger);
+        sys->trigger = NULL;
+    }
+
     delta = vlc_pa_get_latency(aout, sys->context, s);
     if (unlikely(delta == VLC_TS_INVALID))
         delta = 0; /* screwed */
 
     delta = (sys->pts - mdate()) - delta;
     if (delta > 0) {
-        if (sys->trigger == NULL) {
-            msg_Dbg(aout, "deferring start (%"PRId64" us)", delta);
-            delta += pa_rtclock_now();
-            sys->trigger = pa_context_rttime_new(sys->context, delta,
-                                                 stream_trigger_cb, aout);
-        }
+        msg_Dbg(aout, "deferring start (%"PRId64" us)", delta);
+        delta += pa_rtclock_now();
+        sys->trigger = pa_context_rttime_new(sys->context, delta,
+                                             stream_trigger_cb, aout);
     } else {
         msg_Warn(aout, "starting late (%"PRId64" us)", delta);
         stream_start(s, aout);
@@ -272,13 +275,16 @@ static void stream_latency_cb(pa_stream *s, void *userdata)
     aout_sys_t *sys = aout->sys;
     mtime_t delta, change;
 
-    if (pa_stream_is_corked(s))
-        return;
-    if (sys->pts == VLC_TS_INVALID)
-    {
+    if (sys->paused != VLC_TS_INVALID)
+        return; /* nothing to do while paused */
+    if (sys->pts == VLC_TS_INVALID) {
         msg_Dbg(aout, "missing latency from input");
         return;
     }
+    if (pa_stream_is_corked(s) > 0) {
+        stream_resync(aout, s);
+        return;
+    }
 
     /* Compute lip desynchronization */
     delta = vlc_pa_get_latency(aout, sys->context, s);



More information about the vlc-commits mailing list