player/Thread: ProcessCommand() returns bool

Allows signalling a failed seek, and replaces several redundant
command checks after the ProcessCommand() call.
This commit is contained in:
Max Kellermann 2017-12-28 08:30:01 +01:00
parent 8838bdc1e3
commit e1349ccadc

View File

@ -339,8 +339,10 @@ private:
/** /**
* Player lock must be held before calling. * Player lock must be held before calling.
*
* @return false to stop playback
*/ */
void ProcessCommand() noexcept; bool ProcessCommand() noexcept;
/** /**
* This is called at the border between two songs: the audio output * This is called at the border between two songs: the audio output
@ -673,15 +675,17 @@ Player::SeekDecoder() noexcept
return true; return true;
} }
inline void inline bool
Player::ProcessCommand() noexcept Player::ProcessCommand() noexcept
{ {
switch (pc.command) { switch (pc.command) {
case PlayerCommand::NONE: case PlayerCommand::NONE:
break;
case PlayerCommand::STOP: case PlayerCommand::STOP:
case PlayerCommand::EXIT: case PlayerCommand::EXIT:
case PlayerCommand::CLOSE_AUDIO: case PlayerCommand::CLOSE_AUDIO:
break; return false;
case PlayerCommand::UPDATE_AUDIO: case PlayerCommand::UPDATE_AUDIO:
{ {
@ -724,17 +728,14 @@ Player::ProcessCommand() noexcept
break; break;
case PlayerCommand::SEEK: case PlayerCommand::SEEK:
SeekDecoder(); return SeekDecoder();
break;
case PlayerCommand::CANCEL: case PlayerCommand::CANCEL:
if (pc.next_song == nullptr) { if (pc.next_song == nullptr)
/* the cancel request arrived too late, we're /* the cancel request arrived too late, we're
already playing the queued song... stop already playing the queued song... stop
everything now */ everything now */
pc.command = PlayerCommand::STOP; return false;
return;
}
if (IsDecoderAtNextSong()) if (IsDecoderAtNextSong())
/* the decoder is already decoding the song - /* the decoder is already decoding the song -
@ -759,6 +760,8 @@ Player::ProcessCommand() noexcept
pc.CommandFinished(); pc.CommandFinished();
break; break;
} }
return true;
} }
static void static void
@ -986,10 +989,7 @@ Player::Run() noexcept
pc.CommandFinished(); pc.CommandFinished();
while (true) { while (true) {
ProcessCommand(); if (!ProcessCommand()) {
if (pc.command == PlayerCommand::STOP ||
pc.command == PlayerCommand::EXIT ||
pc.command == PlayerCommand::CLOSE_AUDIO) {
const ScopeUnlock unlock(pc.mutex); const ScopeUnlock unlock(pc.mutex);
pc.outputs.Cancel(); pc.outputs.Cancel();
break; break;