[vlc-devel] [RFC PATCH] PulseAudio: fix audio drop after an underflow

Thomas Guillem thomas at gllm.fr
Fri Apr 17 15:29:48 CEST 2015

This fixes audio drop when the track has a positive delay.

I'm trying to fix an issue with Pulse Audio when changing the audio track
synchronization. Indeed, you can loose audio when you seek after selecting a
positive delay. I think it happens because we wait too long between the last
pa_stream_cork/pa_stream_flush and the first pa_stream_write.

I'm not sure if this is the best way to fix this issue.

An other way to fix this issue is to pause pulse after a flush and start it
again before the next write.

How to reproduce:
$ ./vlc --audio-desync=2500 <video>
Audio will start playing after a delay of 2500ms, but if you seek, you'll loose

 modules/audio_output/pulse.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c
index 5947ceb..1284097 100644
--- a/modules/audio_output/pulse.c
+++ b/modules/audio_output/pulse.c
@@ -351,9 +351,13 @@ static void stream_suspended_cb(pa_stream *s, void *userdata)
 static void stream_underflow_cb(pa_stream *s, void *userdata)
     audio_output_t *aout = userdata;
+    aout_sys_t *sys = aout->sys;
     msg_Dbg(aout, "underflow");
-    (void) s;
+    sys->first_pts = VLC_TS_INVALID;
+    pa_stream_set_latency_update_callback(s, NULL, NULL);
+    stream_stop(s, aout);
 static int stream_wait(pa_stream *stream, pa_threaded_mainloop *mainloop)

More information about the vlc-devel mailing list