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

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


vlc/vlc-2.0 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Aug  9 20:57:10 2012 +0300| [472b7408ef57daf5715545c8c90437b6b4e5ee5f] | 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.
(cherry picked from commit 1b06737a297cc5b9c48dd12e2e456b45bc6891d2)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=472b7408ef57daf5715545c8c90437b6b4e5ee5f
---

 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 13d8384..561e6f4 100644
--- a/modules/audio_output/pulse.c
+++ b/modules/audio_output/pulse.c
@@ -203,10 +203,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)
@@ -237,8 +234,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;
 }
@@ -256,18 +256,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);
@@ -280,13 +283,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