From 9a21bdfd6ae8314d9d8c8c879df2e7988b77c5f1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 31 Oct 2021 16:19:52 +0100 Subject: [PATCH] output/snapcast: implement Pause() This uncomments the code which had been present already in the first Snapcast commit (copied from the "httpd" output plugin), but I commented it because I did not know whether I needed to send silence samples to all Snapcast clients. As a side effect, this fixes playback when no Snapcast client is connected; this was broken because Pause() always returned a positive value when there were no clients. Closes https://github.com/MusicPlayerDaemon/MPD/issues/1310 --- src/output/plugins/snapcast/Internal.hxx | 6 ++++++ src/output/plugins/snapcast/SnapcastOutputPlugin.cxx | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/output/plugins/snapcast/Internal.hxx b/src/output/plugins/snapcast/Internal.hxx index 33fc85b26..e21d3cd94 100644 --- a/src/output/plugins/snapcast/Internal.hxx +++ b/src/output/plugins/snapcast/Internal.hxx @@ -51,6 +51,12 @@ class SnapcastOutput final : AudioOutput, ServerSocket { */ bool open; + /** + * Is the output current paused? This is set by Pause() and + * is cleared by the next Play() call. It is used in Delay(). + */ + bool pause; + InjectEvent inject_event; #ifdef HAVE_ZEROCONF diff --git a/src/output/plugins/snapcast/SnapcastOutputPlugin.cxx b/src/output/plugins/snapcast/SnapcastOutputPlugin.cxx index 522943939..73778e6b8 100644 --- a/src/output/plugins/snapcast/SnapcastOutputPlugin.cxx +++ b/src/output/plugins/snapcast/SnapcastOutputPlugin.cxx @@ -161,6 +161,7 @@ SnapcastOutput::Open(AudioFormat &audio_format) timer = new Timer(audio_format); open = true; + pause = false; } void @@ -213,7 +214,7 @@ SnapcastOutput::RemoveClient(SnapcastClient &client) noexcept std::chrono::steady_clock::duration SnapcastOutput::Delay() const noexcept { - if (!LockHasClients() /*&& pause*/) { + if (!LockHasClients() && pause) { /* if there's no client and this output is paused, then Pause() will not do anything, it will not fill the buffer and it will not update the timer; @@ -307,7 +308,7 @@ SnapcastOutput::SendTag(const Tag &tag) size_t SnapcastOutput::Play(const void *chunk, size_t size) { - //pause = false; + pause = false; const auto now = std::chrono::steady_clock::now(); @@ -355,8 +356,7 @@ SnapcastOutput::Play(const void *chunk, size_t size) bool SnapcastOutput::Pause() { - // TODO: implement - //pause = true; + pause = true; return true; }