From bad3283182927332bf3f39084ad1a047def95b7f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 24 Sep 2021 11:33:09 +0200 Subject: [PATCH] output/pipewire: add flag "active", replaces some uses of "paused" This way, we know whether we're explicitly "paused" or "not yet activated because the ring buffer hasn't been filled yet". --- src/output/plugins/PipeWireOutputPlugin.cxx | 28 +++++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/output/plugins/PipeWireOutputPlugin.cxx b/src/output/plugins/PipeWireOutputPlugin.cxx index 5e4938589..9cea7fdb8 100644 --- a/src/output/plugins/PipeWireOutputPlugin.cxx +++ b/src/output/plugins/PipeWireOutputPlugin.cxx @@ -93,6 +93,12 @@ class PipeWireOutput final : AudioOutput { bool interrupted; bool paused; + /** + * Is the PipeWire stream active, i.e. has + * pw_stream_set_active() been called successfully? + */ + bool active; + /** * Has Drain() been called? This causes Process() to invoke * pw_stream_flush() to drain PipeWire as soon as the @@ -353,11 +359,11 @@ PipeWireOutput::Open(AudioFormat &audio_format) disconnected = false; restore_volume = true; - /* we're paused (inactive) now because of the flag - PW_STREAM_FLAG_INACTIVE; this way, we can fill the - ring_buffer before activating the stream, to avoid - underruns */ - paused = true; + paused = false; + + /* stay inactive (PW_STREAM_FLAG_INACTIVE) until the ring + buffer has been filled */ + active = false; drain_requested = false; drained = true; @@ -492,6 +498,8 @@ PipeWireOutput::Play(const void *chunk, size_t size) { const PipeWire::ThreadLoopLock lock(thread_loop); + paused = false; + while (true) { CheckThrowError(); @@ -502,11 +510,11 @@ PipeWireOutput::Play(const void *chunk, size_t size) return bytes_written; } - if (paused) { + if (!active) { /* now that the ring_buffer is full, there is enough data for Process(), so let's resume the stream now */ - paused = false; + active = true; pw_stream_set_active(stream, true); } @@ -547,7 +555,11 @@ PipeWireOutput::Pause() noexcept interrupted = false; paused = true; - pw_stream_set_active(stream, false); + + if (active) { + active = false; + pw_stream_set_active(stream, false); + } return true; }