Commit e1b03b4a authored by Max Kellermann's avatar Max Kellermann

PlayerControl: move functions into the class

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