# HG changeset patch # User iive # Date 1328310708 0 # Node ID 96019b1174b89e0dea4dd169f77730bf86a46318 # Parent e659a561af750f5d39d6a7afb7cfcde66538c339 Workaround a bug in Pulse Audio (http://pulseaudio.org/ticket/866) that causes 2 second delay while trying to drain the current stream. It seems that if we wait for the data to be played before calling the pa_stream_drain function, it would not block for the whole duration of its internal buffer, thus avoid the 2 seconds delay. The code of this workaround is already used in ao_jack and ao_sdl. Special thanks to Rune Heggtveit who did all the heavy lifting in finding a working solution. diff -r e659a561af75 -r 96019b1174b8 libao2/ao_pulse.c --- a/libao2/ao_pulse.c Fri Feb 03 20:33:32 2012 +0000 +++ b/libao2/ao_pulse.c Fri Feb 03 23:11:48 2012 +0000 @@ -26,6 +26,7 @@ #include "config.h" #include "libaf/af_format.h" +#include "osdep/timer.h" #include "mp_msg.h" #include "audio_out.h" #include "audio_out_internal.h" @@ -249,6 +250,10 @@ /** Destroy libao driver */ static void uninit(int immed) { if (stream && !immed) { + /* Workaround the bug in pa_stream_drain that causes + a delay of 2 second if the buffer is not empty */ + usec_sleep(get_delay() * 1000 * 1000); + pa_threaded_mainloop_lock(mainloop); waitop(pa_stream_drain(stream, success_cb, NULL)); }