Commit ada67a6a authored by Max Kellermann's avatar Max Kellermann

PlayerThread: move code to player_control::CommandFinished()

parent b6a5d1ad
...@@ -229,6 +229,20 @@ struct player_control { ...@@ -229,6 +229,20 @@ struct player_control {
} }
/** /**
* A command has been finished. This method clears the
* command and signals the client.
*
* To be called from the player thread. Caller must lock the
* object.
*/
void CommandFinished() {
assert(command != PLAYER_COMMAND_NONE);
command = PLAYER_COMMAND_NONE;
ClientSignal();
}
/**
* @param song the song to be queued; the given instance will * @param song the song to be queued; the given instance will
* be owned and freed by the player * be owned and freed by the player
*/ */
......
...@@ -271,19 +271,10 @@ struct player { ...@@ -271,19 +271,10 @@ struct player {
}; };
static void static void
player_command_finished_locked(player_control &pc)
{
assert(pc.command != PLAYER_COMMAND_NONE);
pc.command = PLAYER_COMMAND_NONE;
pc.ClientSignal();
}
static void
player_command_finished(player_control &pc) player_command_finished(player_control &pc)
{ {
pc.Lock(); pc.Lock();
player_command_finished_locked(pc); pc.CommandFinished();
pc.Unlock(); pc.Unlock();
} }
...@@ -608,7 +599,7 @@ player::ProcessCommand() ...@@ -608,7 +599,7 @@ player::ProcessCommand()
pc.Unlock(); pc.Unlock();
audio_output_all_enable_disable(); audio_output_all_enable_disable();
pc.Lock(); pc.Lock();
player_command_finished_locked(pc); pc.CommandFinished();
break; break;
case PLAYER_COMMAND_QUEUE: case PLAYER_COMMAND_QUEUE:
...@@ -617,7 +608,7 @@ player::ProcessCommand() ...@@ -617,7 +608,7 @@ player::ProcessCommand()
assert(!IsDecoderAtNextSong()); assert(!IsDecoderAtNextSong());
queued = true; queued = true;
player_command_finished_locked(pc); pc.CommandFinished();
break; break;
case PLAYER_COMMAND_PAUSE: case PLAYER_COMMAND_PAUSE:
...@@ -641,7 +632,7 @@ player::ProcessCommand() ...@@ -641,7 +632,7 @@ player::ProcessCommand()
pc.Lock(); pc.Lock();
} }
player_command_finished_locked(pc); pc.CommandFinished();
break; break;
case PLAYER_COMMAND_SEEK: case PLAYER_COMMAND_SEEK:
...@@ -670,7 +661,7 @@ player::ProcessCommand() ...@@ -670,7 +661,7 @@ player::ProcessCommand()
pc.next_song->Free(); pc.next_song->Free();
pc.next_song = nullptr; pc.next_song = nullptr;
queued = false; queued = false;
player_command_finished_locked(pc); pc.CommandFinished();
break; break;
case PLAYER_COMMAND_REFRESH: case PLAYER_COMMAND_REFRESH:
...@@ -684,7 +675,7 @@ player::ProcessCommand() ...@@ -684,7 +675,7 @@ player::ProcessCommand()
if (pc.elapsed_time < 0.0) if (pc.elapsed_time < 0.0)
pc.elapsed_time = elapsed_time; pc.elapsed_time = elapsed_time;
player_command_finished_locked(pc); pc.CommandFinished();
break; break;
} }
} }
...@@ -930,7 +921,7 @@ player::Run() ...@@ -930,7 +921,7 @@ player::Run()
if (pc.command == PLAYER_COMMAND_SEEK) if (pc.command == PLAYER_COMMAND_SEEK)
elapsed_time = pc.seek_where; elapsed_time = pc.seek_where;
player_command_finished_locked(pc); pc.CommandFinished();
while (true) { while (true) {
ProcessCommand(); ProcessCommand();
...@@ -1138,7 +1129,7 @@ player_task(gpointer arg) ...@@ -1138,7 +1129,7 @@ player_task(gpointer arg)
pc.next_song = nullptr; pc.next_song = nullptr;
} }
player_command_finished_locked(pc); pc.CommandFinished();
break; break;
case PLAYER_COMMAND_CLOSE_AUDIO: case PLAYER_COMMAND_CLOSE_AUDIO:
...@@ -1147,7 +1138,7 @@ player_task(gpointer arg) ...@@ -1147,7 +1138,7 @@ player_task(gpointer arg)
audio_output_all_release(); audio_output_all_release();
pc.Lock(); pc.Lock();
player_command_finished_locked(pc); pc.CommandFinished();
assert(buffer.IsEmptyUnsafe()); assert(buffer.IsEmptyUnsafe());
...@@ -1157,7 +1148,7 @@ player_task(gpointer arg) ...@@ -1157,7 +1148,7 @@ player_task(gpointer arg)
pc.Unlock(); pc.Unlock();
audio_output_all_enable_disable(); audio_output_all_enable_disable();
pc.Lock(); pc.Lock();
player_command_finished_locked(pc); pc.CommandFinished();
break; break;
case PLAYER_COMMAND_EXIT: case PLAYER_COMMAND_EXIT:
...@@ -1176,12 +1167,12 @@ player_task(gpointer arg) ...@@ -1176,12 +1167,12 @@ player_task(gpointer arg)
pc.next_song = nullptr; pc.next_song = nullptr;
} }
player_command_finished_locked(pc); pc.CommandFinished();
break; break;
case PLAYER_COMMAND_REFRESH: case PLAYER_COMMAND_REFRESH:
/* no-op when not playing */ /* no-op when not playing */
player_command_finished_locked(pc); pc.CommandFinished();
break; break;
case PLAYER_COMMAND_NONE: case PLAYER_COMMAND_NONE:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment