From e408ea51e238e8c2d11c84423e80ca506c6ee090 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 25 Dec 2021 15:03:50 +1100 Subject: [PATCH] [client] audio/pw: gracefully shutdown when asked to --- client/audiodevs/PipeWire/pipewire.c | 35 ++++++++++++---------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/client/audiodevs/PipeWire/pipewire.c b/client/audiodevs/PipeWire/pipewire.c index 03e41f84..6604ff1e 100644 --- a/client/audiodevs/PipeWire/pipewire.c +++ b/client/audiodevs/PipeWire/pipewire.c @@ -104,30 +104,11 @@ err_context: pw_context_destroy(context); err: + pw_loop_destroy(pw.loop); pw_deinit(); return false; } -static void pipewire_free(void) -{ - if (pw.thread) - { - pw_thread_loop_lock(pw.thread); - if (pw.stream) - { - pw_stream_destroy(pw.stream); - pw.stream = NULL; - } - - pw_thread_loop_signal(pw.thread, true); - pw_thread_loop_destroy(pw.thread); - pw.loop = NULL; - } - - ringbuffer_free(&pw.buffer); - pw_deinit(); -} - static void pipewire_stop_stream(void) { if (!pw.stream) @@ -140,6 +121,20 @@ static void pipewire_stop_stream(void) pw_thread_loop_unlock(pw.thread); } +static void pipewire_free(void) +{ + pipewire_stop_stream(); + pw_thread_loop_stop(pw.thread); + pw_thread_loop_destroy(pw.thread); + pw_loop_destroy(pw.loop); + + pw.loop = NULL; + pw.thread = NULL; + + ringbuffer_free(&pw.buffer); + pw_deinit(); +} + static void pipewire_start(int channels, int sampleRate) { const struct spa_pod * params[1];