diff --git a/client/audiodevs/PipeWire/pipewire.c b/client/audiodevs/PipeWire/pipewire.c index 0170fb7f..1131169d 100644 --- a/client/audiodevs/PipeWire/pipewire.c +++ b/client/audiodevs/PipeWire/pipewire.c @@ -133,6 +133,18 @@ static void pipewire_free(void) pw_deinit(); } +static void pipewire_stop(void) +{ + if (!pw.stream) + return; + + pw_thread_loop_lock(pw.thread); + pw_stream_flush(pw.stream, true); + pw_stream_destroy(pw.stream); + pw.stream = NULL; + pw_thread_loop_unlock(pw.thread); +} + static void pipewire_start(int channels, int sampleRate) { const struct spa_pod * params[1]; @@ -144,6 +156,8 @@ static void pipewire_start(int channels, int sampleRate) .process = pipewire_on_process }; + pipewire_stop(); + pw.channels = channels; pw.stride = sizeof(uint16_t) * channels; pw.buffer = ringbuffer_new(sampleRate, channels * sizeof(uint16_t)); @@ -197,16 +211,9 @@ static void pipewire_play(uint8_t * data, int size) ringbuffer_push(pw.buffer, data + i); } -static void pipewire_stop(void) +static void pipewire_stop_nop(void) { - if (!pw.stream) - return; - - pw_thread_loop_lock(pw.thread); - pw_stream_flush(pw.stream, true); - pw_stream_destroy(pw.stream); - pw.stream = NULL; - pw_thread_loop_unlock(pw.thread); + // we ignore the stop message to avoid messing up any audio graph } struct LG_AudioDevOps LGAD_PipeWire = @@ -216,5 +223,5 @@ struct LG_AudioDevOps LGAD_PipeWire = .free = pipewire_free, .start = pipewire_start, .play = pipewire_play, - .stop = pipewire_stop + .stop = pipewire_stop_nop };