From f1b8bcd6b26ff40fc49dab1b46f4a85e58eafeab Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Mon, 15 Feb 2021 16:02:01 +0100
Subject: [PATCH] output/pulse: don't drain if stream is suspended or corked

In this state, we can't make any progress.

Closes https://github.com/MusicPlayerDaemon/MPD/issues/1084
---
 NEWS                                     | 1 +
 src/output/plugins/PulseOutputPlugin.cxx | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 843f55db1..7b0615128 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ ver 0.22.5 (not yet released)
   - iso9660: another fix for unaligned reads
 * output
   - httpd: error handling on Windows improved
+  - pulse: fix deadlock with "always_on"
 * Windows:
   - enable https:// support (via Schannel)
 
diff --git a/src/output/plugins/PulseOutputPlugin.cxx b/src/output/plugins/PulseOutputPlugin.cxx
index a76562fef..47c5fe025 100644
--- a/src/output/plugins/PulseOutputPlugin.cxx
+++ b/src/output/plugins/PulseOutputPlugin.cxx
@@ -830,7 +830,9 @@ PulseOutput::Drain()
 {
 	Pulse::LockGuard lock(mainloop);
 
-	if (pa_stream_get_state(stream) != PA_STREAM_READY)
+	if (pa_stream_get_state(stream) != PA_STREAM_READY ||
+	    pa_stream_is_suspended(stream) ||
+	    pa_stream_is_corked(stream))
 		return;
 
 	pa_operation *o =