From 4247a757b3a9725f3327edf11c822e6b0a4f51dc Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 14 Nov 2018 09:43:14 +0100 Subject: [PATCH] output/alsa: call snd_pcm_prepare() if draining is requested early This fixes a corner case which has probably never occurred and probably never will: if Cancel() is called, and then Play() followed by Drain(), the plugin should really play that data. However currently, this never happens, because snd_pcm_prepare() is never called. --- src/output/plugins/AlsaOutputPlugin.cxx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/output/plugins/AlsaOutputPlugin.cxx b/src/output/plugins/AlsaOutputPlugin.cxx index 8d875ed26..00de0af18 100644 --- a/src/output/plugins/AlsaOutputPlugin.cxx +++ b/src/output/plugins/AlsaOutputPlugin.cxx @@ -891,6 +891,15 @@ AlsaOutput::DispatchSockets() noexcept try { non_block.DispatchSockets(*this, pcm); + if (must_prepare) { + must_prepare = false; + + int err = snd_pcm_prepare(pcm); + if (err < 0) + throw FormatRuntimeError("snd_pcm_prepare() failed: %s", + snd_strerror(-err)); + } + { const std::lock_guard lock(mutex); @@ -911,15 +920,6 @@ try { } } - if (must_prepare) { - must_prepare = false; - - int err = snd_pcm_prepare(pcm); - if (err < 0) - throw FormatRuntimeError("snd_pcm_prepare() failed: %s", - snd_strerror(-err)); - } - CopyRingToPeriodBuffer(); if (period_buffer.IsEmpty()) {