From 1d00d55d53aed450fb5af1da00d81f07afed9f90 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 21 Sep 2018 19:05:25 +0200 Subject: [PATCH] player/Thread: stop buffering if buffer is full Shouldn't ever happen, but who knows... --- src/MusicBuffer.hxx | 7 ++++++- src/player/Thread.cxx | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/MusicBuffer.hxx b/src/MusicBuffer.hxx index 0ad6f49c0..10a6b906d 100644 --- a/src/MusicBuffer.hxx +++ b/src/MusicBuffer.hxx @@ -29,7 +29,7 @@ */ class MusicBuffer { /** a mutex which protects #buffer */ - Mutex mutex; + mutable Mutex mutex; SliceBuffer buffer; @@ -53,6 +53,11 @@ public: } #endif + bool IsFull() const noexcept { + const std::lock_guard protect(mutex); + return buffer.IsFull(); + } + /** * Returns the total number of reserved chunks in this buffer. This * is the same value which was passed to the constructor diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index 14f8aa08e..008b03c11 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -944,7 +944,7 @@ Player::Run() noexcept prevent stuttering on slow machines */ if (pipe->GetSize() < pc.buffered_before_play && - !dc.IsIdle()) { + !dc.IsIdle() && !buffer.IsFull()) { /* not enough decoded buffer space yet */ dc.WaitForDecoder();