From a9d72938182aae285fd32aa00236038959902fa1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 13 Dec 2016 22:39:20 +0100 Subject: [PATCH] output/Thread: wake up the player thread periodically while playing Without this, the pipe would run empty very often, which may result in an xrun if the roundtrip to the PlayerThread and back takes too long. By waking up the PlayerThread before the pipe runs empty, we make MPD much more latency tolerant, which is a major optimization. --- NEWS | 1 + src/output/OutputThread.cxx | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/NEWS b/NEWS index 3c6d12e33..d0eb9126b 100644 --- a/NEWS +++ b/NEWS @@ -52,6 +52,7 @@ ver 0.20 (not yet released) - soxr: allow multi-threaded resampling * player - reset song priority on playback + - reduce xruns * write database and state file atomically * always write UTF-8 to the log file. * remove dependency on GLib diff --git a/src/output/OutputThread.cxx b/src/output/OutputThread.cxx index 2ac59f534..799626f33 100644 --- a/src/output/OutputThread.cxx +++ b/src/output/OutputThread.cxx @@ -493,10 +493,21 @@ AudioOutput::Play() in_playback_loop = false; }; + unsigned n = 0; + do { if (command != Command::NONE) return true; + if (++n >= 64) { + /* wake up the player every now and then to + give it a chance to refill the pipe before + it runs empty */ + const ScopeUnlock unlock(mutex); + player_control->LockSignal(); + n = 0; + } + if (!PlayChunk(chunk)) break;