player/Thread: make seeking into a new song non-blocking

This commit is contained in:
Max Kellermann 2017-12-30 11:31:26 +01:00
parent dee378b775
commit 7171e23700
1 changed files with 12 additions and 33 deletions

View File

@ -210,37 +210,6 @@ private:
*/ */
bool CheckDecoderStartup() noexcept; 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. * Stop the decoder and clears (and frees) its music pipe.
* *
@ -553,6 +522,12 @@ Player::CheckDecoderStartup() noexcept
if (!success) if (!success)
return false; 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 */ /* re-fill the buffer after seeking */
buffering = true; buffering = true;
} }
@ -669,8 +644,12 @@ Player::SeekDecoder() noexcept
StartDecoder(*pipe); StartDecoder(*pipe);
ActivateDecoder(); ActivateDecoder();
if (!WaitDecoderStartup()) pc.seeking = true;
return false; pc.CommandFinished();
assert(xfade_state == CrossFadeState::UNKNOWN);
return true;
} else { } else {
if (!IsDecoderAtCurrentSong()) { if (!IsDecoderAtCurrentSong()) {
/* the decoder is already decoding the "next" song, /* the decoder is already decoding the "next" song,