From f2a4840dbde1098c1e8217681a2f8807e72e44d0 Mon Sep 17 00:00:00 2001 From: Tom Yan Date: Tue, 9 Apr 2019 00:54:38 +0800 Subject: [PATCH] libpulseaudio: fix aaudio error callback The error callback can be called before the transition of the sink state has completed. It therefore needs to wait until the sink has left init state before reconfiguring it with pa_sink_suspend calls. Also try to recover from all errors (and log what the error is when it is not AAUDIO_ERROR_DISCONNECTED). --- packages/libpulseaudio/module-aaudio-sink.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/libpulseaudio/module-aaudio-sink.c b/packages/libpulseaudio/module-aaudio-sink.c index ea43c225c..81340758f 100644 --- a/packages/libpulseaudio/module-aaudio-sink.c +++ b/packages/libpulseaudio/module-aaudio-sink.c @@ -125,10 +125,13 @@ static void error_callback(AAudioStream *stream, void *userdata, aaudio_result_t pa_assert(u); - if (error == AAUDIO_ERROR_DISCONNECTED) { - pa_sink_suspend(u->sink, true, PA_SUSPEND_UNAVAILABLE); - pa_sink_suspend(u->sink, false, PA_SUSPEND_UNAVAILABLE); - } + while (u->sink->state == PA_SINK_INIT); + + if (error != AAUDIO_ERROR_DISCONNECTED) + pa_log_debug("AAudio error: %d", error); + + pa_sink_suspend(u->sink, true, PA_SUSPEND_UNAVAILABLE); + pa_sink_suspend(u->sink, false, PA_SUSPEND_UNAVAILABLE); } #define CHK(stmt) { \