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)