From ebdc847ef19e65d97b0804faf099aa2bcf1751af Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 25 Dec 2021 13:44:40 +1100 Subject: [PATCH] [client] audio/pw: don't re-create an idle stream with matching format --- client/audiodevs/PipeWire/pipewire.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client/audiodevs/PipeWire/pipewire.c b/client/audiodevs/PipeWire/pipewire.c index 1b659065..03e41f84 100644 --- a/client/audiodevs/PipeWire/pipewire.c +++ b/client/audiodevs/PipeWire/pipewire.c @@ -32,6 +32,7 @@ struct PipeWire struct pw_thread_loop * thread; struct pw_stream * stream; int channels; + int sampleRate; int stride; RingBuffer buffer; @@ -150,11 +151,15 @@ static void pipewire_start(int channels, int sampleRate) .process = pipewire_on_process }; + if (pw.stream && pw.channels == channels && pw.sampleRate == sampleRate) + return; + pipewire_stop_stream(); - pw.channels = channels; - pw.stride = sizeof(uint16_t) * channels; - pw.buffer = ringbuffer_new(sampleRate / 10, channels * sizeof(uint16_t)); + pw.channels = channels; + pw.sampleRate = sampleRate; + pw.stride = sizeof(uint16_t) * channels; + pw.buffer = ringbuffer_new(sampleRate / 10, channels * sizeof(uint16_t)); pw_thread_loop_lock(pw.thread); pw.stream = pw_stream_new_simple(