From 84b5478b02a4c22e3cfce66be4d103ab5106ba5e Mon Sep 17 00:00:00 2001 From: Chris Spencer Date: Sun, 20 Feb 2022 16:51:33 +0000 Subject: [PATCH] [client] audio/pa: fix assertion failure when keep alive playback stops When the 'keep alive' playback times out, playback is stopped from the audio callback, resulting in an assertion failure inside PulseAudio as we try to lock the main loop thread while already inside it. --- client/audiodevs/PulseAudio/pulseaudio.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/client/audiodevs/PulseAudio/pulseaudio.c b/client/audiodevs/PulseAudio/pulseaudio.c index a9d9719f..83ea9ac9 100644 --- a/client/audiodevs/PulseAudio/pulseaudio.c +++ b/client/audiodevs/PulseAudio/pulseaudio.c @@ -313,10 +313,15 @@ static void pulseaudio_stop(void) if (!pa.sink) return; - pa_threaded_mainloop_lock(pa.loop); + bool needLock = !pa_threaded_mainloop_in_thread(pa.loop); + if (needLock) + pa_threaded_mainloop_lock(pa.loop); + pa_stream_cork(pa.sink, 1, NULL, NULL); pa.sinkCorked = true; - pa_threaded_mainloop_unlock(pa.loop); + + if (needLock) + pa_threaded_mainloop_unlock(pa.loop); } static void pulseaudio_volume(int channels, const uint16_t volume[])