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".
This commit is contained in:
Max Kellermann 2021-09-24 11:33:09 +02:00
parent 6ed4aff4d3
commit bad3283182

View File

@ -93,6 +93,12 @@ class PipeWireOutput final : AudioOutput {
bool interrupted; bool interrupted;
bool paused; 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 * Has Drain() been called? This causes Process() to invoke
* pw_stream_flush() to drain PipeWire as soon as the * pw_stream_flush() to drain PipeWire as soon as the
@ -353,11 +359,11 @@ PipeWireOutput::Open(AudioFormat &audio_format)
disconnected = false; disconnected = false;
restore_volume = true; restore_volume = true;
/* we're paused (inactive) now because of the flag paused = false;
PW_STREAM_FLAG_INACTIVE; this way, we can fill the
ring_buffer before activating the stream, to avoid /* stay inactive (PW_STREAM_FLAG_INACTIVE) until the ring
underruns */ buffer has been filled */
paused = true; active = false;
drain_requested = false; drain_requested = false;
drained = true; drained = true;
@ -492,6 +498,8 @@ PipeWireOutput::Play(const void *chunk, size_t size)
{ {
const PipeWire::ThreadLoopLock lock(thread_loop); const PipeWire::ThreadLoopLock lock(thread_loop);
paused = false;
while (true) { while (true) {
CheckThrowError(); CheckThrowError();
@ -502,11 +510,11 @@ PipeWireOutput::Play(const void *chunk, size_t size)
return bytes_written; return bytes_written;
} }
if (paused) { if (!active) {
/* now that the ring_buffer is full, there is /* now that the ring_buffer is full, there is
enough data for Process(), so let's resume enough data for Process(), so let's resume
the stream now */ the stream now */
paused = false; active = true;
pw_stream_set_active(stream, true); pw_stream_set_active(stream, true);
} }
@ -547,7 +555,11 @@ PipeWireOutput::Pause() noexcept
interrupted = false; interrupted = false;
paused = true; paused = true;
pw_stream_set_active(stream, false);
if (active) {
active = false;
pw_stream_set_active(stream, false);
}
return true; return true;
} }