output/pipewire: implement Pause()

This commit is contained in:
Max Kellermann 2021-08-04 17:25:22 +02:00
parent 52577ac87a
commit 4d1ce7023b
1 changed files with 18 additions and 1 deletions

View File

@ -58,6 +58,7 @@ class PipeWireOutput final : AudioOutput {
bool disconnected;
bool interrupted;
bool paused;
bool drained;
explicit PipeWireOutput(const ConfigBlock &block);
@ -139,7 +140,7 @@ private:
void Drain() override;
void Cancel() noexcept override;
// TODO: bool Pause() noexcept override;
bool Pause() noexcept override;
};
static constexpr auto stream_events = PipeWireOutput::MakeStreamEvents();
@ -287,6 +288,7 @@ void
PipeWireOutput::Open(AudioFormat &audio_format)
{
disconnected = false;
paused = false;
drained = true;
auto props = pw_properties_new(PW_KEY_MEDIA_TYPE, "Audio",
@ -379,6 +381,9 @@ PipeWireOutput::Play(const void *chunk, size_t size)
{
const PipeWire::ThreadLoopLock lock(thread_loop);
if (paused)
pw_stream_set_active(stream, true);
while (true) {
CheckThrowError();
@ -416,6 +421,18 @@ PipeWireOutput::Cancel() noexcept
ring_buffer->reset();
}
bool
PipeWireOutput::Pause() noexcept
{
const PipeWire::ThreadLoopLock lock(thread_loop);
interrupted = false;
paused = true;
pw_stream_set_active(stream, false);
return true;
}
const struct AudioOutputPlugin pipewire_output_plugin = {
"pipewire",
nullptr,