diff options
-rw-r--r-- | src/command.c | 21 | ||||
-rw-r--r-- | src/player_control.c | 20 | ||||
-rw-r--r-- | src/player_control.h | 21 | ||||
-rw-r--r-- | src/playlist_state.c | 18 |
4 files changed, 46 insertions, 34 deletions
diff --git a/src/command.c b/src/command.c index c48ea845d..9cd6d0e38 100644 --- a/src/command.c +++ b/src/command.c @@ -453,11 +453,14 @@ handle_status(struct 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; - switch (getPlayerState()) { + pc_get_status(&player_status); + + switch (player_status.state) { case PLAYER_STATE_STOP: state = "stop"; break; @@ -497,17 +500,19 @@ handle_status(struct client *client, song, playlist_get_song_id(&g_playlist, song)); } - if (getPlayerState() != PLAYER_STATE_STOP) { - const struct audio_format *af = player_get_audio_format(); + if (player_status.state != PLAYER_STATE_STOP) { client_printf(client, COMMAND_STATUS_TIME ": %i:%i\n" "elapsed: %1.3f\n" - COMMAND_STATUS_BITRATE ": %li\n" + COMMAND_STATUS_BITRATE ": %u\n" COMMAND_STATUS_AUDIO ": %u:%u:%u\n", - getPlayerElapsedTime(), getPlayerTotalTime(), - pc.elapsed_time, - getPlayerBitRate(), - af->sample_rate, af->bits, af->channels); + (int)(player_status.elapsed_time + 0.5), + (int)(player_status.total_time + 0.5), + player_status.elapsed_time, + player_status.bit_rate, + player_status.audio_format.sample_rate, + player_status.audio_format.bits, + player_status.audio_format.channels); } if ((updateJobId = isUpdatingDB())) { diff --git a/src/player_control.c b/src/player_control.c index bef19917f..e27052a4d 100644 --- a/src/player_control.c +++ b/src/player_control.c @@ -129,19 +129,17 @@ void playerSetPause(int pause_flag) } } -int getPlayerElapsedTime(void) -{ - return (int)(pc.elapsed_time + 0.5); -} - -unsigned long getPlayerBitRate(void) +void +pc_get_status(struct player_status *status) { - return pc.bit_rate; -} + status->state = pc.state; -int getPlayerTotalTime(void) -{ - return (int)(pc.total_time + 0.5); + 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; + } } enum player_state getPlayerState(void) diff --git a/src/player_control.h b/src/player_control.h index 9cf5b1377..e6b19ee68 100644 --- a/src/player_control.h +++ b/src/player_control.h @@ -60,6 +60,14 @@ enum player_error { PLAYER_ERROR_FILENOTFOUND, }; +struct player_status { + enum player_state state; + uint16_t bit_rate; + struct audio_format audio_format; + float total_time; + float elapsed_time; +}; + struct player_control { unsigned buffer_chunks; @@ -112,11 +120,8 @@ void playerPause(void); void playerKill(void); -int getPlayerTotalTime(void); - -int getPlayerElapsedTime(void); - -unsigned long getPlayerBitRate(void); +void +pc_get_status(struct player_status *status); enum player_state getPlayerState(void); @@ -151,12 +156,6 @@ float getPlayerCrossFade(void); double getPlayerTotalPlayTime(void); -static inline const struct audio_format * -player_get_audio_format(void) -{ - return &pc.audio_format; -} - void playerInit(void); #endif diff --git a/src/playlist_state.c b/src/playlist_state.c index 5d18cc339..16b75efae 100644 --- a/src/playlist_state.c +++ b/src/playlist_state.c @@ -51,10 +51,14 @@ void playlist_state_save(FILE *fp, const struct playlist *playlist) { + struct player_status player_status; + + pc_get_status(&player_status); + fprintf(fp, "%s", PLAYLIST_STATE_FILE_STATE); if (playlist->playing) { - switch (getPlayerState()) { + switch (player_status.state) { case PLAYER_STATE_PAUSE: fprintf(fp, "%s\n", PLAYLIST_STATE_FILE_STATE_PAUSE); break; @@ -65,7 +69,7 @@ playlist_state_save(FILE *fp, const struct playlist *playlist) queue_order_to_position(&playlist->queue, playlist->current)); fprintf(fp, "%s%i\n", PLAYLIST_STATE_FILE_TIME, - getPlayerElapsedTime()); + (int)player_status.elapsed_time); } else { fprintf(fp, "%s\n", PLAYLIST_STATE_FILE_STATE_STOP); @@ -204,14 +208,20 @@ playlist_state_restore(const char *line, FILE *fp, struct playlist *playlist) unsigned playlist_state_get_hash(const struct playlist *playlist) { + struct player_status player_status; + + pc_get_status(&player_status); + return playlist->queue.version ^ - (getPlayerElapsedTime() << 8) ^ + (player_status.state != PLAYER_STATE_STOP + ? ((int)player_status.elapsed_time << 8) + : 0) ^ (playlist->current >= 0 ? (queue_order_to_position(&playlist->queue, playlist->current) << 16) : 0) ^ ((int)getPlayerCrossFade() << 20) ^ - (getPlayerState() << 24) ^ + (player_status.state << 24) ^ (playlist->queue.random << 27) ^ (playlist->queue.repeat << 28) ^ (playlist->queue.single << 29) ^ |