From 7171e237007db547088c38295a7351573c0d79bf Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 30 Dec 2017 11:31:26 +0100 Subject: [PATCH] player/Thread: make seeking into a new song non-blocking --- src/player/Thread.cxx | 45 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index 77eee0aa7..801114d06 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -210,37 +210,6 @@ private: */ bool CheckDecoderStartup() noexcept; - /** - * Call CheckDecoderStartup() repeatedly until the decoder has - * finished startup. Returns false on decoder error (and - * finishes the #PlayerCommand). - * - * This method does not check for commands. It is only - * allowed to be used while a command is being handled. - * - * Caller must lock the mutex. - * - * @return false if the decoder has failed - */ - bool WaitDecoderStartup() noexcept { - while (decoder_starting) { - if (!CheckDecoderStartup()) { - /* if decoder startup fails, make sure - the previous song is not being - played anymore */ - { - const ScopeUnlock unlock(pc.mutex); - pc.outputs.Cancel(); - } - - pc.CommandFinished(); - return false; - } - } - - return true; - } - /** * Stop the decoder and clears (and frees) its music pipe. * @@ -553,6 +522,12 @@ Player::CheckDecoderStartup() noexcept if (!success) return false; + /* re-fill the buffer after seeking */ + buffering = true; + } else if (pc.seeking) { + pc.seeking = false; + pc.ClientSignal(); + /* re-fill the buffer after seeking */ buffering = true; } @@ -669,8 +644,12 @@ Player::SeekDecoder() noexcept StartDecoder(*pipe); ActivateDecoder(); - if (!WaitDecoderStartup()) - return false; + pc.seeking = true; + pc.CommandFinished(); + + assert(xfade_state == CrossFadeState::UNKNOWN); + + return true; } else { if (!IsDecoderAtCurrentSong()) { /* the decoder is already decoding the "next" song,