From cf4371a0ad7c6dd92a7913504637d48a320baccc Mon Sep 17 00:00:00 2001 From: Marcelo Fernandez Date: Tue, 1 May 2018 10:44:08 -0300 Subject: [PATCH] Prevent PulseAudio driver to lock its mutex for too long --- drivers/pulseaudio/audio_driver_pulseaudio.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.cpp b/drivers/pulseaudio/audio_driver_pulseaudio.cpp index 733c7cc80c9..0f47949b4b4 100644 --- a/drivers/pulseaudio/audio_driver_pulseaudio.cpp +++ b/drivers/pulseaudio/audio_driver_pulseaudio.cpp @@ -340,13 +340,22 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { bytes = byte_size; } - int ret = pa_stream_write(ad->pa_str, ptr, bytes, NULL, 0LL, PA_SEEK_RELATIVE); + ret = pa_stream_write(ad->pa_str, ptr, bytes, NULL, 0LL, PA_SEEK_RELATIVE); if (ret >= 0) { byte_size -= bytes; ptr = (const char *)ptr + bytes; } } else { - pa_mainloop_iterate(ad->pa_ml, 1, NULL); + ret = pa_mainloop_iterate(ad->pa_ml, 0, NULL); + if (ret == 0) { + // If pa_mainloop_iterate returns 0 sleep for 1 msec to wait + // for the stream to be able to process more bytes + ad->unlock(); + + OS::get_singleton()->delay_usec(1000); + + ad->lock(); + } } } }