diff options
author | Max Kellermann <max@duempel.org> | 2013-01-20 17:48:23 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-01-20 17:48:23 +0100 |
commit | e1b03b4a716dbb35a737d34fba531e623f7980f3 (patch) | |
tree | ac2143b4b3122d594000a70b51ca29fb2c937307 | |
parent | e6ed592b8aeb5025be0893ee99ff44e46a9ffd1c (diff) | |
download | mpd-e1b03b4a716dbb35a737d34fba531e623f7980f3.tar.gz mpd-e1b03b4a716dbb35a737d34fba531e623f7980f3.tar.xz mpd-e1b03b4a716dbb35a737d34fba531e623f7980f3.zip |
PlayerControl: move functions into the class
-rw-r--r-- | src/DecoderControl.hxx | 9 | ||||
-rw-r--r-- | src/Main.cxx | 4 | ||||
-rw-r--r-- | src/OutputAll.cxx | 8 | ||||
-rw-r--r-- | src/OutputCommand.cxx | 4 | ||||
-rw-r--r-- | src/OutputThread.cxx | 2 | ||||
-rw-r--r-- | src/PlayerCommands.cxx | 24 | ||||
-rw-r--r-- | src/PlayerControl.cxx | 200 | ||||
-rw-r--r-- | src/PlayerControl.hxx | 288 | ||||
-rw-r--r-- | src/PlayerThread.cxx | 122 | ||||
-rw-r--r-- | src/Playlist.cxx | 26 | ||||
-rw-r--r-- | src/PlaylistControl.cxx | 13 | ||||
-rw-r--r-- | src/PlaylistEdit.cxx | 4 | ||||
-rw-r--r-- | src/PlaylistState.cxx | 29 | ||||
-rw-r--r-- | src/Stats.cxx | 2 |
14 files changed, 335 insertions, 400 deletions
diff --git a/src/DecoderControl.hxx b/src/DecoderControl.hxx index 42c28d785..02b98672c 100644 --- a/src/DecoderControl.hxx +++ b/src/DecoderControl.hxx @@ -129,6 +129,15 @@ struct decoder_control { char *mixramp_start; char *mixramp_end; char *mixramp_prev_end; + + /** + * Waits for a signal from the decoder thread. This object + * must be locked prior to calling this function. This method + * is only valid in the player thread. + */ + void WaitForDecoder() { + g_cond_wait(client_cond, mutex); + } }; G_GNUC_MALLOC diff --git a/src/Main.cxx b/src/Main.cxx index ef78c92b2..6d4fc82d2 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -509,7 +509,7 @@ int mpd_main(int argc, char *argv[]) /* enable all audio outputs (if not already done by playlist_state_restore() */ - pc_update_audio(&global_partition->pc); + global_partition->pc.UpdateAudio(); #ifdef WIN32 win32_app_started(); @@ -535,7 +535,7 @@ int mpd_main(int argc, char *argv[]) delete state_file; } - pc_kill(&global_partition->pc); + global_partition->pc.Kill(); finishZeroconf(); listen_global_finish(); delete client_list; diff --git a/src/OutputAll.cxx b/src/OutputAll.cxx index a18a63385..4cdcc84e7 100644 --- a/src/OutputAll.cxx +++ b/src/OutputAll.cxx @@ -481,15 +481,15 @@ audio_output_all_check(void) bool audio_output_all_wait(struct player_control *pc, unsigned threshold) { - player_lock(pc); + pc->Lock(); if (audio_output_all_check() < threshold) { - player_unlock(pc); + pc->Unlock(); return true; } - player_wait(pc); - player_unlock(pc); + pc->Wait(); + pc->Unlock(); return audio_output_all_check() < threshold; } diff --git a/src/OutputCommand.cxx b/src/OutputCommand.cxx index f4edaa4a1..be52b49a8 100644 --- a/src/OutputCommand.cxx +++ b/src/OutputCommand.cxx @@ -53,7 +53,7 @@ audio_output_enable_index(unsigned idx) ao->enabled = true; idle_add(IDLE_OUTPUT); - pc_update_audio(ao->player_control); + ao->player_control->UpdateAudio(); ++audio_output_state_version; @@ -82,7 +82,7 @@ audio_output_disable_index(unsigned idx) idle_add(IDLE_MIXER); } - pc_update_audio(ao->player_control); + ao->player_control->UpdateAudio(); ++audio_output_state_version; diff --git a/src/OutputThread.cxx b/src/OutputThread.cxx index 59394e072..20212cef9 100644 --- a/src/OutputThread.cxx +++ b/src/OutputThread.cxx @@ -548,7 +548,7 @@ ao_play(struct audio_output *ao) ao->chunk_finished = true; g_mutex_unlock(ao->mutex); - player_lock_signal(ao->player_control); + ao->player_control->LockSignal(); g_mutex_lock(ao->mutex); return true; diff --git a/src/PlayerCommands.cxx b/src/PlayerCommands.cxx index 99ede9bd8..32cd16d9d 100644 --- a/src/PlayerCommands.cxx +++ b/src/PlayerCommands.cxx @@ -106,9 +106,9 @@ handle_pause(Client *client, if (!check_bool(client, &pause_flag, argv[1])) return COMMAND_RETURN_ERROR; - pc_set_pause(client->player_control, pause_flag); + client->player_control->SetPause(pause_flag); } else - pc_pause(client->player_control); + client->player_control->Pause(); return COMMAND_RETURN_OK; } @@ -118,12 +118,10 @@ handle_status(Client *client, G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) { const char *state = NULL; - struct player_status player_status; int updateJobId; - char *error; int song; - pc_get_status(client->player_control, &player_status); + const auto player_status = client->player_control->GetStatus(); switch (player_status.state) { case PLAYER_STATE_STOP: @@ -157,9 +155,9 @@ handle_status(Client *client, playlist.GetConsume(), (unsigned long)playlist.GetVersion(), playlist.GetLength(), - (int)(pc_get_cross_fade(client->player_control) + 0.5), - pc_get_mixramp_db(client->player_control), - pc_get_mixramp_delay(client->player_control), + (int)(client->player_control->GetCrossFade() + 0.5), + client->player_control->GetMixRampDb(), + client->player_control->GetMixRampDelay(), state); song = playlist.GetCurrentPosition(); @@ -192,7 +190,7 @@ handle_status(Client *client, updateJobId); } - error = pc_get_error_message(client->player_control); + char *error = client->player_control->GetErrorMessage(); if (error != NULL) { client_printf(client, COMMAND_STATUS_ERROR ": %s\n", @@ -285,7 +283,7 @@ enum command_return handle_clearerror(G_GNUC_UNUSED Client *client, G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) { - pc_clear_error(client->player_control); + client->player_control->ClearError(); return COMMAND_RETURN_OK; } @@ -340,7 +338,7 @@ handle_crossfade(Client *client, G_GNUC_UNUSED int argc, char *argv[]) if (!check_unsigned(client, &xfade_time, argv[1])) return COMMAND_RETURN_ERROR; - pc_set_cross_fade(client->player_control, xfade_time); + client->player_control->SetCrossFade(xfade_time); return COMMAND_RETURN_OK; } @@ -352,7 +350,7 @@ handle_mixrampdb(Client *client, G_GNUC_UNUSED int argc, char *argv[]) if (!check_float(client, &db, argv[1])) return COMMAND_RETURN_ERROR; - pc_set_mixramp_db(client->player_control, db); + client->player_control->SetMixRampDb(db); return COMMAND_RETURN_OK; } @@ -364,7 +362,7 @@ handle_mixrampdelay(Client *client, G_GNUC_UNUSED int argc, char *argv[]) if (!check_float(client, &delay_secs, argv[1])) return COMMAND_RETURN_ERROR; - pc_set_mixramp_delay(client->player_control, delay_secs); + client->player_control->SetMixRampDelay(delay_secs); return COMMAND_RETURN_OK; } diff --git a/src/PlayerControl.cxx b/src/PlayerControl.cxx index 62a8a4f80..3805f776f 100644 --- a/src/PlayerControl.cxx +++ b/src/PlayerControl.cxx @@ -56,18 +56,6 @@ player_control::~player_control() song_free(next_song); } -void -player_wait_decoder(gcc_unused struct player_control *pc, - struct decoder_control *dc) -{ - assert(pc != NULL); - assert(dc != NULL); - - /* during this function, the decoder lock is held, because - we're waiting for the decoder thread */ - g_cond_wait(dc->client_cond, dc->mutex); -} - static void player_command_wait_locked(struct player_control *pc) { @@ -81,84 +69,84 @@ player_command_locked(struct player_control *pc, enum player_command cmd) assert(pc->command == PLAYER_COMMAND_NONE); pc->command = cmd; - player_signal(pc); + pc->Signal(); player_command_wait_locked(pc); } static void player_command(struct player_control *pc, enum player_command cmd) { - player_lock(pc); + pc->Lock(); player_command_locked(pc, cmd); - player_unlock(pc); + pc->Unlock(); } void -pc_play(struct player_control *pc, struct song *song) +player_control::Play(struct song *song) { assert(song != NULL); - player_lock(pc); + Lock(); - if (pc->state != PLAYER_STATE_STOP) - player_command_locked(pc, PLAYER_COMMAND_STOP); + if (state != PLAYER_STATE_STOP) + player_command_locked(this, PLAYER_COMMAND_STOP); - assert(pc->next_song == NULL); + assert(next_song == nullptr); - pc_enqueue_song_locked(pc, song); + pc_enqueue_song_locked(this, song); - assert(pc->next_song == NULL); + assert(next_song == nullptr); - player_unlock(pc); + Unlock(); idle_add(IDLE_PLAYER); } void -pc_cancel(struct player_control *pc) +player_control::Cancel() { - player_command(pc, PLAYER_COMMAND_CANCEL); - assert(pc->next_song == NULL); + player_command(this, PLAYER_COMMAND_CANCEL); + assert(next_song == NULL); } void -pc_stop(struct player_control *pc) +player_control::Stop() { - player_command(pc, PLAYER_COMMAND_CLOSE_AUDIO); - assert(pc->next_song == NULL); + player_command(this, PLAYER_COMMAND_CLOSE_AUDIO); + assert(next_song == nullptr); idle_add(IDLE_PLAYER); } void -pc_update_audio(struct player_control *pc) +player_control::UpdateAudio() { - player_command(pc, PLAYER_COMMAND_UPDATE_AUDIO); + player_command(this, PLAYER_COMMAND_UPDATE_AUDIO); } void -pc_kill(struct player_control *pc) +player_control::Kill() { - assert(pc->thread != NULL); + assert(thread != NULL); - player_command(pc, PLAYER_COMMAND_EXIT); - g_thread_join(pc->thread); - pc->thread = NULL; + player_command(this, PLAYER_COMMAND_EXIT); + g_thread_join(thread); + thread = NULL; idle_add(IDLE_PLAYER); } void -pc_pause(struct player_control *pc) +player_control::Pause() { - player_lock(pc); + Lock(); - if (pc->state != PLAYER_STATE_STOP) { - player_command_locked(pc, PLAYER_COMMAND_PAUSE); + if (state != PLAYER_STATE_STOP) { + player_command_locked(this, PLAYER_COMMAND_PAUSE); idle_add(IDLE_PLAYER); } - player_unlock(pc); + Unlock(); } static void @@ -171,90 +159,92 @@ pc_pause_locked(struct player_control *pc) } void -pc_set_pause(struct player_control *pc, bool pause_flag) +player_control::SetPause(bool pause_flag) { - player_lock(pc); + Lock(); - switch (pc->state) { + switch (state) { case PLAYER_STATE_STOP: break; case PLAYER_STATE_PLAY: if (pause_flag) - pc_pause_locked(pc); + pc_pause_locked(this); break; case PLAYER_STATE_PAUSE: if (!pause_flag) - pc_pause_locked(pc); + pc_pause_locked(this); break; } - player_unlock(pc); + Unlock(); } void -pc_set_border_pause(struct player_control *pc, bool border_pause) +player_control::SetBorderPause(bool _border_pause) { - player_lock(pc); - pc->border_pause = border_pause; - player_unlock(pc); + Lock(); + border_pause = _border_pause; + Unlock(); } -void -pc_get_status(struct player_control *pc, struct player_status *status) +player_status +player_control::GetStatus() { - player_lock(pc); - player_command_locked(pc, PLAYER_COMMAND_REFRESH); + player_status status; - status->state = pc->state; + Lock(); + player_command_locked(this, PLAYER_COMMAND_REFRESH); - if (pc->state != PLAYER_STATE_STOP) { - status->bit_rate = pc->bit_rate; - status->audio_format = pc->audio_format; - status->total_time = pc->total_time; - status->elapsed_time = pc->elapsed_time; + status.state = state; + + if (state != PLAYER_STATE_STOP) { + status.bit_rate = bit_rate; + status.audio_format = audio_format; + status.total_time = total_time; + status.elapsed_time = elapsed_time; } - player_unlock(pc); + Unlock(); + + return status; } void -pc_set_error(struct player_control *pc, enum player_error type, - GError *error) +player_control::SetError(player_error type, GError *_error) { - assert(pc != NULL); assert(type != PLAYER_ERROR_NONE); - assert(error != NULL); + assert(_error != NULL); - if (pc->error_type != PLAYER_ERROR_NONE) - g_error_free(pc->error); + if (error_type != PLAYER_ERROR_NONE) + g_error_free(error); - pc->error_type = type; - pc->error = error; + error_type = type; + error = _error; } void -pc_clear_error(struct player_control *pc) +player_control::ClearError() { - player_lock(pc); + Lock(); - if (pc->error_type != PLAYER_ERROR_NONE) { - pc->error_type = PLAYER_ERROR_NONE; - g_error_free(pc->error); + if (error_type != PLAYER_ERROR_NONE) { + error_type = PLAYER_ERROR_NONE; + g_error_free(error); } - player_unlock(pc); + Unlock(); } char * -pc_get_error_message(struct player_control *pc) +player_control::GetErrorMessage() const { - player_lock(pc); - char *message = pc->error_type != PLAYER_ERROR_NONE - ? g_strdup(pc->error->message) + Lock(); + char *message = error_type != PLAYER_ERROR_NONE + ? g_strdup(error->message) : NULL; - player_unlock(pc); + Unlock(); return message; } @@ -269,65 +259,59 @@ pc_enqueue_song_locked(struct player_control *pc, struct song *song) } void -pc_enqueue_song(struct player_control *pc, struct song *song) +player_control::EnqueueSong(struct song *song) { assert(song != NULL); - player_lock(pc); - pc_enqueue_song_locked(pc, song); - player_unlock(pc); + Lock(); + pc_enqueue_song_locked(this, song); + Unlock(); } bool -pc_seek(struct player_control *pc, struct song *song, float seek_time) +player_control::Seek(struct song *song, float seek_time) { assert(song != NULL); - player_lock(pc); + Lock(); - if (pc->next_song != NULL) - song_free(pc->next_song); + if (next_song != nullptr) + song_free(next_song); - pc->next_song = song; - pc->seek_where = seek_time; - player_command_locked(pc, PLAYER_COMMAND_SEEK); - player_unlock(pc); + next_song = song; + seek_where = seek_time; + player_command_locked(this, PLAYER_COMMAND_SEEK); + Unlock(); - assert(pc->next_song == NULL); + assert(next_song == nullptr); idle_add(IDLE_PLAYER); return true; } -float -pc_get_cross_fade(const struct player_control *pc) -{ - return pc->cross_fade_seconds; -} - void -pc_set_cross_fade(struct player_control *pc, float cross_fade_seconds) +player_control::SetCrossFade(float _cross_fade_seconds) { - if (cross_fade_seconds < 0) - cross_fade_seconds = 0; - pc->cross_fade_seconds = cross_fade_seconds; + if (_cross_fade_seconds < 0) + _cross_fade_seconds = 0; + cross_fade_seconds = _cross_fade_seconds; idle_add(IDLE_OPTIONS); } void -pc_set_mixramp_db(struct player_control *pc, float mixramp_db) +player_control::SetMixRampDb(float _mixramp_db) { - pc->mixramp_db = mixramp_db; + mixramp_db = _mixramp_db; idle_add(IDLE_OPTIONS); } void -pc_set_mixramp_delay(struct player_control *pc, float mixramp_delay_seconds) +player_control::SetMixRampDelay(float _mixramp_delay_seconds) { - pc->mixramp_delay_seconds = mixramp_delay_seconds; + mixramp_delay_seconds = _mixramp_delay_seconds; idle_add(IDLE_OPTIONS); } diff --git a/src/PlayerControl.hxx b/src/PlayerControl.hxx index 322b95c84..2b25177fb 100644 --- a/src/PlayerControl.hxx +++ b/src/PlayerControl.hxx @@ -101,7 +101,7 @@ struct player_control { /** * This lock protects #command, #state, #error. */ - Mutex mutex; + mutable Mutex mutex; /** * Trigger this object after you have modified #command. @@ -152,188 +152,142 @@ struct player_control { player_control(unsigned buffer_chunks, unsigned buffered_before_play); ~player_control(); -}; -/** - * Locks the #player_control object. - */ -static inline void -player_lock(struct player_control *pc) -{ - pc->mutex.lock(); -} - -/** - * Unlocks the #player_control object. - */ -static inline void -player_unlock(struct player_control *pc) -{ - pc->mutex.unlock(); -} - -/** - * Waits for a signal on the #player_control object. This function is - * only valid in the player thread. The object must be locked prior - * to calling this function. - */ -static inline void -player_wait(struct player_control *pc) -{ - pc->cond.wait(pc->mutex); -} - -/** - * Waits for a signal on the #player_control object. This function is - * only valid in the player thread. The #decoder_control object must - * be locked prior to calling this function. - * - * Note the small difference to the player_wait() function! - */ -void -player_wait_decoder(struct player_control *pc, struct decoder_control *dc); + /** + * Locks the object. + */ + void Lock() const { + mutex.lock(); + } -/** - * Signals the #player_control object. The object should be locked - * prior to calling this function. - */ -static inline void -player_signal(struct player_control *pc) -{ - pc->cond.signal(); -} - -/** - * Signals the #player_control object. The object is temporarily - * locked by this function. - */ -static inline void -player_lock_signal(struct player_control *pc) -{ - player_lock(pc); - player_signal(pc); - player_unlock(pc); -} - -/** - * @param song the song to be queued; the given instance will be owned - * and freed by the player - */ -void -pc_play(struct player_control *pc, struct song *song); + /** + * Unlocks the object. + */ + void Unlock() const { + mutex.unlock(); + } -/** - * see PLAYER_COMMAND_CANCEL - */ -void -pc_cancel(struct player_control *pc); + /** + * Signals the object. The object should be locked prior to + * calling this function. + */ + void Signal() { + cond.signal(); + } -void -pc_set_pause(struct player_control *pc, bool pause_flag); + /** + * Signals the object. The object is temporarily locked by + * this function. + */ + void LockSignal() { + Lock(); + Signal(); + Unlock(); + } -void -pc_pause(struct player_control *pc); + /** + * Waits for a signal on the object. This function is only + * valid in the player thread. The object must be locked + * prior to calling this function. + */ + void Wait() { + cond.wait(mutex); + } -/** - * Set the player's #border_pause flag. - */ -void -pc_set_border_pause(struct player_control *pc, bool border_pause); + /** + * @param song the song to be queued; the given instance will + * be owned and freed by the player + */ + void Play(struct song *song); -void -pc_kill(struct player_control *pc); + /** + * see PLAYER_COMMAND_CANCEL + */ + void Cancel(); -void -pc_get_status(struct player_control *pc, struct player_status *status); + void SetPause(bool pause_flag); -static inline enum player_state -pc_get_state(struct player_control *pc) -{ - return pc->state; -} + void Pause(); -/** - * Set the error. Discards any previous error condition. - * - * Caller must lock the object. - * - * @param type the error type; must not be #PLAYER_ERROR_NONE - * @param error detailed error information; must not be NULL; the - * #player_control takes over ownership of this #GError instance - */ -void -pc_set_error(struct player_control *pc, enum player_error type, - GError *error); + /** + * Set the player's #border_pause flag. + */ + void SetBorderPause(bool border_pause); -void -pc_clear_error(struct player_control *pc); + void Kill(); -/** - * Returns the human-readable message describing the last error during - * playback, NULL if no error occurred. The caller has to free the - * returned string. - */ -char * -pc_get_error_message(struct player_control *pc); + gcc_pure + player_status GetStatus(); -static inline enum player_error -pc_get_error_type(struct player_control *pc) -{ - return pc->error_type; -} + player_state GetState() const { + return state; + } -void -pc_stop(struct player_control *pc); + /** + * Set the error. Discards any previous error condition. + * + * Caller must lock the object. + * + * @param type the error type; must not be #PLAYER_ERROR_NONE + * @param error detailed error information; must not be NULL; the + * #player_control takes over ownership of this #GError instance + */ + void SetError(player_error type, GError *error); -void -pc_update_audio(struct player_control *pc); + void ClearError(); -/** - * @param song the song to be queued; the given instance will be owned - * and freed by the player - */ -void -pc_enqueue_song(struct player_control *pc, struct song *song); + /** + * Returns the human-readable message describing the last + * error during playback, NULL if no error occurred. The + * caller has to free the returned string. + */ + char *GetErrorMessage() const; -/** - * Makes the player thread seek the specified song to a position. - * - * @param song the song to be queued; the given instance will be owned - * and freed by the player - * @return true on success, false on failure (e.g. if MPD isn't - * playing currently) - */ -bool -pc_seek(struct player_control *pc, struct song *song, float seek_time); - -void -pc_set_cross_fade(struct player_control *pc, float cross_fade_seconds); - -float -pc_get_cross_fade(const struct player_control *pc); - -void -pc_set_mixramp_db(struct player_control *pc, float mixramp_db); - -static inline float -pc_get_mixramp_db(const struct player_control *pc) -{ - return pc->mixramp_db; -} - -void -pc_set_mixramp_delay(struct player_control *pc, float mixramp_delay_seconds); - -static inline float -pc_get_mixramp_delay(const struct player_control *pc) -{ - return pc->mixramp_delay_seconds; -} - -static inline double -pc_get_total_play_time(const struct player_control *pc) -{ - return pc->total_play_time; -} + player_error GetErrorType() const { + return error_type; + } + + void Stop(); + + void UpdateAudio(); + + /** + * @param song the song to be queued; the given instance will be owned + * and freed by the player + */ + void EnqueueSong(struct song *song); + + /** + * Makes the player thread seek the specified song to a position. + * + * @param song the song to be queued; the given instance will be owned + * and freed by the player + * @return true on success, false on failure (e.g. if MPD isn't + * playing currently) + */ + bool Seek(struct song *song, float seek_time); + + void SetCrossFade(float cross_fade_seconds); + + float GetCrossFade() const { + return cross_fade_seconds; + } + + void SetMixRampDb(float mixramp_db); + + float GetMixRampDb() const { + return mixramp_db; + } + + void SetMixRampDelay(float mixramp_delay_seconds); + + float GetMixRampDelay() const { + return mixramp_delay_seconds; + } + + double GetTotalPlayTime() const { + return total_play_time; + } +}; #endif diff --git a/src/PlayerThread.cxx b/src/PlayerThread.cxx index fb7432368..d061064ba 100644 --- a/src/PlayerThread.cxx +++ b/src/PlayerThread.cxx @@ -153,9 +153,9 @@ player_command_finished_locked(struct player_control *pc) static void player_command_finished(struct player_control *pc) { - player_lock(pc); + pc->Lock(); player_command_finished_locked(pc); - player_unlock(pc); + pc->Unlock(); } /** @@ -251,13 +251,13 @@ player_wait_for_decoder(struct player *player) GError *error = dc_lock_get_error(dc); if (error != NULL) { - player_lock(pc); - pc_set_error(pc, PLAYER_ERROR_DECODER, error); + pc->Lock(); + pc->SetError(PLAYER_ERROR_DECODER, error); song_free(pc->next_song); pc->next_song = NULL; - player_unlock(pc); + pc->Unlock(); return false; } @@ -272,7 +272,7 @@ player_wait_for_decoder(struct player *player) player_check_decoder_startup() */ player->decoder_starting = true; - player_lock(pc); + pc->Lock(); /* update player_control's song information */ pc->total_time = song_get_duration(pc->next_song); @@ -282,7 +282,7 @@ player_wait_for_decoder(struct player *player) /* clear the queued song */ pc->next_song = NULL; - player_unlock(pc); + pc->Unlock(); /* call syncPlaylistWithQueue() in the main thread */ GlobalEvents::Emit(GlobalEvents::PLAYLIST); @@ -331,9 +331,9 @@ player_open_output(struct player *player) player->output_open = true; player->paused = false; - player_lock(pc); + pc->Lock(); pc->state = PLAYER_STATE_PLAY; - player_unlock(pc); + pc->Unlock(); return true; } else { @@ -345,10 +345,10 @@ player_open_output(struct player *player) audio output becomes available */ player->paused = true; - player_lock(pc); - pc_set_error(pc, PLAYER_ERROR_OUTPUT, error); + pc->Lock(); + pc->SetError(PLAYER_ERROR_OUTPUT, error); pc->state = PLAYER_STATE_PAUSE; - player_unlock(pc); + pc->Unlock(); return false; } @@ -376,9 +376,9 @@ player_check_decoder_startup(struct player *player) /* the decoder failed */ decoder_unlock(dc); - player_lock(pc); - pc_set_error(pc, PLAYER_ERROR_DECODER, error); - player_unlock(pc); + pc->Lock(); + pc->SetError(PLAYER_ERROR_DECODER, error); + pc->Unlock(); return false; } else if (!decoder_is_starting(dc)) { @@ -392,10 +392,10 @@ player_check_decoder_startup(struct player *player) all chunks yet - wait for that */ return true; - player_lock(pc); + pc->Lock(); pc->total_time = real_song_duration(dc->song, dc->total_time); pc->audio_format = dc->in_audio_format; - player_unlock(pc); + pc->Unlock(); player->play_audio_format = dc->out_audio_format; player->decoder_starting = false; @@ -413,7 +413,7 @@ player_check_decoder_startup(struct player *player) } else { /* the decoder is not yet ready; wait some more */ - player_wait_decoder(pc, dc); + dc->WaitForDecoder(); decoder_unlock(dc); return true; @@ -565,9 +565,9 @@ static void player_process_command(struct player *player) break; case PLAYER_COMMAND_UPDATE_AUDIO: - player_unlock(pc); + pc->Unlock(); audio_output_all_enable_disable(); - player_lock(pc); + pc->Lock(); player_command_finished_locked(pc); break; @@ -581,33 +581,33 @@ static void player_process_command(struct player *player) break; case PLAYER_COMMAND_PAUSE: - player_unlock(pc); + pc->Unlock(); player->paused = !player->paused; if (player->paused) { audio_output_all_pause(); - player_lock(pc); + pc->Lock(); pc->state = PLAYER_STATE_PAUSE; } else if (!audio_format_defined(&player->play_audio_format)) { /* the decoder hasn't provided an audio format yet - don't open the audio device yet */ - player_lock(pc); + pc->Lock(); pc->state = PLAYER_STATE_PLAY; } else { player_open_output(player); - player_lock(pc); + pc->Lock(); } player_command_finished_locked(pc); break; case PLAYER_COMMAND_SEEK: - player_unlock(pc); + pc->Unlock(); player_seek_decoder(player); - player_lock(pc); + pc->Lock(); break; case PLAYER_COMMAND_CANCEL: @@ -622,9 +622,9 @@ static void player_process_command(struct player *player) if (player_dc_at_next_song(player)) { /* the decoder is already decoding the song - stop it and reset the position */ - player_unlock(pc); + pc->Unlock(); player_dc_stop(player); - player_lock(pc); + pc->Lock(); } song_free(pc->next_song); @@ -635,9 +635,9 @@ static void player_process_command(struct player *player) case PLAYER_COMMAND_REFRESH: if (player->output_open && !player->paused) { - player_unlock(pc); + pc->Unlock(); audio_output_all_check(); - player_lock(pc); + pc->Lock(); } pc->elapsed_time = audio_output_all_get_elapsed_time(); @@ -695,9 +695,9 @@ play_chunk(struct player_control *pc, return true; } - player_lock(pc); + pc->Lock(); pc->bit_rate = chunk->bit_rate; - player_unlock(pc); + pc->Unlock(); /* send the chunk to the audio outputs */ @@ -793,7 +793,7 @@ play_next_chunk(struct player *player) } else { /* wait for the decoder */ decoder_signal(dc); - player_wait_decoder(pc, dc); + dc->WaitForDecoder(); decoder_unlock(dc); return true; @@ -823,16 +823,16 @@ play_next_chunk(struct player *player) music_buffer_return(player_buffer, chunk); - player_lock(pc); + pc->Lock(); - pc_set_error(pc, PLAYER_ERROR_OUTPUT, error); + pc->SetError(PLAYER_ERROR_OUTPUT, error); /* pause: the user may resume playback as soon as an audio output becomes available */ pc->state = PLAYER_STATE_PAUSE; player->paused = true; - player_unlock(pc); + pc->Unlock(); return false; } @@ -877,14 +877,14 @@ player_song_border(struct player *player) return false; struct player_control *const pc = player->pc; - player_lock(pc); + pc->Lock(); if (pc->border_pause) { player->paused = true; pc->state = PLAYER_STATE_PAUSE; } - player_unlock(pc); + pc->Unlock(); return true; } @@ -898,7 +898,7 @@ static void do_play(struct player_control *pc, struct decoder_control *dc) { player player(pc, dc); - player_unlock(pc); + pc->Unlock(); player.pipe = music_pipe_new(); @@ -910,11 +910,11 @@ static void do_play(struct player_control *pc, struct decoder_control *dc) player_command_finished(pc); music_pipe_free(player.pipe); GlobalEvents::Emit(GlobalEvents::PLAYLIST); - player_lock(pc); + pc->Lock(); return; } - player_lock(pc); + pc->Lock(); pc->state = PLAYER_STATE_PLAY; if (pc->command == PLAYER_COMMAND_SEEK) @@ -927,12 +927,12 @@ static void do_play(struct player_control *pc, struct decoder_control *dc) if (pc->command == PLAYER_COMMAND_STOP || pc->command == PLAYER_COMMAND_EXIT || pc->command == PLAYER_COMMAND_CLOSE_AUDIO) { - player_unlock(pc); + pc->Unlock(); audio_output_all_cancel(); break; } - player_unlock(pc); + pc->Unlock(); if (player.buffering) { /* buffering at the start of the song - wait @@ -951,9 +951,9 @@ static void do_play(struct player_control *pc, struct decoder_control *dc) decoder_lock(dc); /* XXX race condition: check decoder again */ - player_wait_decoder(pc, dc); + dc->WaitForDecoder(); decoder_unlock(dc); - player_lock(pc); + pc->Lock(); continue; } else { /* buffering is complete */ @@ -967,7 +967,7 @@ static void do_play(struct player_control *pc, struct decoder_control *dc) if (!player_check_decoder_startup(&player)) break; - player_lock(pc); + pc->Lock(); continue; } @@ -1020,10 +1020,10 @@ static void do_play(struct player_control *pc, struct decoder_control *dc) } if (player.paused) { - player_lock(pc); + pc->Lock(); if (pc->command == PLAYER_COMMAND_NONE) - player_wait(pc); + pc->Wait(); continue; } else if (!music_pipe_empty(player.pipe)) { /* at least one music chunk is ready - send it @@ -1060,7 +1060,7 @@ static void do_play(struct player_control *pc, struct decoder_control *dc) break; } - player_lock(pc); + pc->Lock(); } player_dc_stop(&player); @@ -1074,7 +1074,7 @@ static void do_play(struct player_control *pc, struct decoder_control *dc) if (player.song != NULL) song_free(player.song); - player_lock(pc); + pc->Lock(); if (player.queued) { assert(pc->next_song != NULL); @@ -1084,11 +1084,11 @@ static void do_play(struct player_control *pc, struct decoder_control *dc) pc->state = PLAYER_STATE_STOP; - player_unlock(pc); + pc->Unlock(); GlobalEvents::Emit(GlobalEvents::PLAYLIST); - player_lock(pc); + pc->Lock(); } static gpointer @@ -1101,7 +1101,7 @@ player_task(gpointer arg) player_buffer = music_buffer_new(pc->buffer_chunks); - player_lock(pc); + pc->Lock(); while (1) { switch (pc->command) { @@ -1113,9 +1113,9 @@ player_task(gpointer arg) break; case PLAYER_COMMAND_STOP: - player_unlock(pc); + pc->Unlock(); audio_output_all_cancel(); - player_lock(pc); + pc->Lock(); /* fall through */ @@ -1129,11 +1129,11 @@ player_task(gpointer arg) break; case PLAYER_COMMAND_CLOSE_AUDIO: - player_unlock(pc); + pc->Unlock(); audio_output_all_release(); - player_lock(pc); + pc->Lock(); player_command_finished_locked(pc); #ifndef NDEBUG @@ -1147,14 +1147,14 @@ player_task(gpointer arg) break; case PLAYER_COMMAND_UPDATE_AUDIO: - player_unlock(pc); + pc->Unlock(); audio_output_all_enable_disable(); - player_lock(pc); + pc->Lock(); player_command_finished_locked(pc); break; case PLAYER_COMMAND_EXIT: - player_unlock(pc); + pc->Unlock(); dc_quit(dc); dc_free(dc); @@ -1179,7 +1179,7 @@ player_task(gpointer arg) break; case PLAYER_COMMAND_NONE: - player_wait(pc); + pc->Wait(); break; } } diff --git a/src/Playlist.cxx b/src/Playlist.cxx index 1977188da..89bdac637 100644 --- a/src/Playlist.cxx +++ b/src/Playlist.cxx @@ -69,7 +69,7 @@ playlist_queue_song_order(struct playlist *playlist, struct player_control *pc, g_debug("queue song %i:\"%s\"", playlist->queued, uri); g_free(uri); - pc_enqueue_song(pc, song); + pc->EnqueueSong(song); } /** @@ -136,7 +136,7 @@ playlist::UpdateQueuedSong(player_control &pc, const song *prev) if (prev != NULL && next_song != prev) { /* clear the currently queued song */ - pc_cancel(&pc); + pc.Cancel(); queued = -1; } @@ -160,7 +160,7 @@ playlist::PlayOrder(player_control &pc, int order) g_debug("play %i:\"%s\"", order, uri); g_free(uri); - pc_play(&pc, song); + pc.Play(song); current = order; } @@ -175,10 +175,10 @@ playlist::SyncWithPlayer(player_control &pc) playing anymore; ignore the event */ return; - player_lock(&pc); - const enum player_state pc_state = pc_get_state(&pc); + pc.Lock(); + const player_state pc_state = pc.GetState(); const song *pc_next_song = pc.next_song; - player_unlock(&pc); + pc.Unlock(); if (pc_state == PLAYER_STATE_STOP) /* the player thread has stopped: check if playback @@ -192,9 +192,9 @@ playlist::SyncWithPlayer(player_control &pc) if (pc_next_song == nullptr && queued != -1) playlist_song_started(this, &pc); - player_lock(&pc); + pc.Lock(); pc_next_song = pc.next_song; - player_unlock(&pc); + pc.Unlock(); /* make sure the queued song is always set (if possible) */ @@ -210,12 +210,10 @@ playlist::SyncWithPlayer(player_control &pc) static void playlist_resume_playback(struct playlist *playlist, struct player_control *pc) { - enum player_error error; - assert(playlist->playing); - assert(pc_get_state(pc) == PLAYER_STATE_STOP); + assert(pc->GetState() == PLAYER_STATE_STOP); - error = pc_get_error_type(pc); + const auto error = pc->GetErrorType(); if (error == PLAYER_ERROR_NONE) playlist->error_count = 0; else @@ -240,7 +238,7 @@ playlist::SetRepeat(player_control &pc, bool status) queue.repeat = status; - pc_set_border_pause(&pc, queue.single && !queue.repeat); + pc.SetBorderPause(queue.single && !queue.repeat); /* if the last song is currently being played, the "next song" might change when repeat mode is toggled */ @@ -267,7 +265,7 @@ playlist::SetSingle(player_control &pc, bool status) queue.single = status; - pc_set_border_pause(&pc, queue.single && !queue.repeat); + pc.SetBorderPause(queue.single && !queue.repeat); /* if the last song is currently being played, the "next song" might change when single mode is toggled */ diff --git a/src/PlaylistControl.cxx b/src/PlaylistControl.cxx index 323192242..3db61cc7c 100644 --- a/src/PlaylistControl.cxx +++ b/src/PlaylistControl.cxx @@ -41,7 +41,7 @@ playlist::Stop(player_control &pc) assert(current >= 0); g_debug("stop"); - pc_stop(&pc); + pc.Stop(); queued = -1; playing = false; @@ -62,7 +62,7 @@ playlist::Stop(player_control &pc) enum playlist_result playlist::PlayPosition(player_control &pc, int song) { - pc_clear_error(&pc); + pc.ClearError(); unsigned i = song; if (song == -1) { @@ -74,7 +74,7 @@ playlist::PlayPosition(player_control &pc, int song) if (playing) { /* already playing: unpause playback, just in case it was paused, and return */ - pc_set_pause(&pc, false); + pc.SetPause(false); return PLAYLIST_RESULT_SUCCESS; } @@ -204,7 +204,7 @@ playlist::SeekSongPosition(player_control &pc, unsigned song, float seek_time) ? queue.PositionToOrder(song) : song; - pc_clear_error(&pc); + pc.ClearError(); stop_on_error = true; error_count = 0; @@ -219,7 +219,7 @@ playlist::SeekSongPosition(player_control &pc, unsigned song, float seek_time) } struct song *the_song = song_dup_detached(queue.GetOrder(i)); - if (!pc_seek(&pc, the_song, seek_time)) { + if (!pc.Seek(the_song, seek_time)) { UpdateQueuedSong(pc, queued_song); return PLAYLIST_RESULT_NOT_PLAYING; @@ -248,8 +248,7 @@ playlist::SeekCurrent(player_control &pc, float seek_time, bool relative) return PLAYLIST_RESULT_NOT_PLAYING; if (relative) { - struct player_status status; - pc_get_status(&pc, &status); + const auto status = pc.GetStatus(); if (status.state != PLAYER_STATE_PLAY && status.state != PLAYER_STATE_PAUSE) diff --git a/src/PlaylistEdit.cxx b/src/PlaylistEdit.cxx index 138289dd5..df38c3da1 100644 --- a/src/PlaylistEdit.cxx +++ b/src/PlaylistEdit.cxx @@ -229,11 +229,11 @@ playlist::DeleteInternal(player_control &pc, unsigned songOrder = queue.PositionToOrder(song); if (playing && current == (int)songOrder) { - bool paused = pc_get_state(&pc) == PLAYER_STATE_PAUSE; + const bool paused = pc.GetState() == PLAYER_STATE_PAUSE; /* the current song is going to be deleted: stop the player */ - pc_stop(&pc); + pc.Stop(); playing = false; /* see which song is going to be played instead */ diff --git a/src/PlaylistState.cxx b/src/PlaylistState.cxx index 14c6d231e..212b52868 100644 --- a/src/PlaylistState.cxx +++ b/src/PlaylistState.cxx @@ -56,9 +56,7 @@ void playlist_state_save(FILE *fp, const struct playlist *playlist, struct player_control *pc) { - struct player_status player_status; - - pc_get_status(pc, &player_status); + const auto player_status = pc->GetStatus(); fputs(PLAYLIST_STATE_FILE_STATE, fp); @@ -88,11 +86,11 @@ playlist_state_save(FILE *fp, const struct playlist *playlist, fprintf(fp, PLAYLIST_STATE_FILE_CONSUME "%i\n", playlist->queue.consume); fprintf(fp, PLAYLIST_STATE_FILE_CROSSFADE "%i\n", - (int)(pc_get_cross_fade(pc))); + (int)pc->GetCrossFade()); fprintf(fp, PLAYLIST_STATE_FILE_MIXRAMPDB "%f\n", - pc_get_mixramp_db(pc)); + pc->GetMixRampDb()); fprintf(fp, PLAYLIST_STATE_FILE_MIXRAMPDELAY "%f\n", - pc_get_mixramp_delay(pc)); + pc->GetMixRampDelay()); fputs(PLAYLIST_STATE_FILE_PLAYLIST_BEGIN "\n", fp); queue_save(fp, &playlist->queue); fputs(PLAYLIST_STATE_FILE_PLAYLIST_END "\n", fp); @@ -156,14 +154,11 @@ playlist_state_restore(const char *line, TextFile &file, playlist->SetConsume(strcmp(&(line[strlen(PLAYLIST_STATE_FILE_CONSUME)]), "1") == 0); } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_CROSSFADE)) { - pc_set_cross_fade(pc, - atoi(line + strlen(PLAYLIST_STATE_FILE_CROSSFADE))); + pc->SetCrossFade(atoi(line + strlen(PLAYLIST_STATE_FILE_CROSSFADE))); } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_MIXRAMPDB)) { - pc_set_mixramp_db(pc, - atof(line + strlen(PLAYLIST_STATE_FILE_MIXRAMPDB))); + pc->SetMixRampDb(atof(line + strlen(PLAYLIST_STATE_FILE_MIXRAMPDB))); } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_MIXRAMPDELAY)) { - pc_set_mixramp_delay(pc, - atof(line + strlen(PLAYLIST_STATE_FILE_MIXRAMPDELAY))); + pc->SetMixRampDelay(atof(line + strlen(PLAYLIST_STATE_FILE_MIXRAMPDELAY))); } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_RANDOM)) { random_mode = strcmp(line + strlen(PLAYLIST_STATE_FILE_RANDOM), @@ -195,7 +190,7 @@ playlist_state_restore(const char *line, TextFile &file, called here, after the audio output states were restored, before playback begins */ if (state != PLAYER_STATE_STOP) - pc_update_audio(pc); + pc->UpdateAudio(); if (state == PLAYER_STATE_STOP /* && config_option */) playlist->current = current; @@ -205,7 +200,7 @@ playlist_state_restore(const char *line, TextFile &file, playlist->SeekSongPosition(*pc, current, seek_time); if (state == PLAYER_STATE_PAUSE) - pc_pause(pc); + pc->Pause(); } return true; @@ -215,9 +210,7 @@ unsigned playlist_state_get_hash(const struct playlist *playlist, struct player_control *pc) { - struct player_status player_status; - - pc_get_status(pc, &player_status); + const auto player_status = pc->GetStatus(); return playlist->queue.version ^ (player_status.state != PLAYER_STATE_STOP @@ -226,7 +219,7 @@ playlist_state_get_hash(const struct playlist *playlist, (playlist->current >= 0 ? (playlist->queue.OrderToPosition(playlist->current) << 16) : 0) ^ - ((int)pc_get_cross_fade(pc) << 20) ^ + ((int)pc->GetCrossFade() << 20) ^ (player_status.state << 24) ^ (playlist->queue.random << 27) ^ (playlist->queue.repeat << 28) ^ diff --git a/src/Stats.cxx b/src/Stats.cxx index f848a9b03..354d26c59 100644 --- a/src/Stats.cxx +++ b/src/Stats.cxx @@ -79,7 +79,7 @@ stats_print(Client *client) stats.album_count, stats.song_count, (long)g_timer_elapsed(stats.timer, NULL), - (long)(pc_get_total_play_time(client->player_control) + 0.5), + (long)(client->player_control->GetTotalPlayTime() + 0.5), stats.song_duration); if (db_is_simple()) |