From f0ac63d5af6dec68e507d62f021fd6031bf6a2e3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 27 Jun 2019 21:00:08 +0200 Subject: [PATCH] output/alsa: DrainInternal() ignores postponed partial frame --- src/lib/alsa/PeriodBuffer.hxx | 11 +++++++++++ src/output/plugins/AlsaOutputPlugin.cxx | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib/alsa/PeriodBuffer.hxx b/src/lib/alsa/PeriodBuffer.hxx index a1a683e68..473577a49 100644 --- a/src/lib/alsa/PeriodBuffer.hxx +++ b/src/lib/alsa/PeriodBuffer.hxx @@ -81,6 +81,17 @@ public: return head > 0; } + /** + * Has all data for the current period been drained? If not, + * then there is pending data. This ignores the partial frame + * which may have been postponed by FillWithSilence(). + */ + bool IsDrained() const noexcept { + /* compare head with capacity, not with tail; this + method makes only sense if the period is full */ + return head >= capacity; + } + /** * Returns the tail of the buffer, i.e. where new data can be * written. Call GetSpaceBytes() to find out how much may be diff --git a/src/output/plugins/AlsaOutputPlugin.cxx b/src/output/plugins/AlsaOutputPlugin.cxx index cae0d04ac..354788307 100644 --- a/src/output/plugins/AlsaOutputPlugin.cxx +++ b/src/output/plugins/AlsaOutputPlugin.cxx @@ -753,7 +753,7 @@ AlsaOutput::DrainInternal() period_buffer.FillWithSilence(silence, out_frame_size); /* drain period_buffer */ - if (!period_buffer.IsEmpty()) { + if (!period_buffer.IsDrained()) { auto frames_written = WriteFromPeriodBuffer(); if (frames_written < 0) { if (frames_written == -EAGAIN)