From b5fde6dfa55676560ee8805e8e00bc188a5ad928 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 Aug 2012 17:49:23 +0200 Subject: decoder_control: add function _is_current_song() Replaces _current_song(). --- src/decoder_control.c | 21 +++++++++++++++++++++ src/decoder_control.h | 34 ++++++++++++++++++++-------------- src/player_thread.c | 2 +- 3 files changed, 42 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/decoder_control.c b/src/decoder_control.c index caa3705f5..2a2d8ac66 100644 --- a/src/decoder_control.c +++ b/src/decoder_control.c @@ -97,6 +97,27 @@ dc_command_async(struct decoder_control *dc, enum decoder_command cmd) decoder_unlock(dc); } +bool +decoder_is_current_song(const struct decoder_control *dc, + const struct song *song) +{ + assert(dc != NULL); + assert(song != NULL); + + switch (dc->state) { + case DECODE_STATE_STOP: + case DECODE_STATE_ERROR: + return false; + + case DECODE_STATE_START: + case DECODE_STATE_DECODE: + return dc->song == song; + } + + assert(false); + return false; +} + void dc_start(struct decoder_control *dc, struct song *song, unsigned start_ms, unsigned end_ms, diff --git a/src/decoder_control.h b/src/decoder_control.h index 743c8fb58..7305e5813 100644 --- a/src/decoder_control.h +++ b/src/decoder_control.h @@ -276,21 +276,27 @@ decoder_lock_has_failed(struct decoder_control *dc) return ret; } -static inline const struct song * -decoder_current_song(const struct decoder_control *dc) -{ - switch (dc->state) { - case DECODE_STATE_STOP: - case DECODE_STATE_ERROR: - return NULL; - - case DECODE_STATE_START: - case DECODE_STATE_DECODE: - return dc->song; - } +/** + * Check if the specified song is currently being decoded. If the + * decoder is not running currently (or being started), then this + * function returns false in any case. + * + * Caller must lock the object. + */ +gcc_pure +bool +decoder_is_current_song(const struct decoder_control *dc, + const struct song *song); - assert(false); - return NULL; +gcc_pure +static inline bool +decoder_lock_is_current_song(struct decoder_control *dc, + const struct song *song) +{ + decoder_lock(dc); + const bool result = decoder_is_current_song(dc, song); + decoder_unlock(dc); + return result; } /** diff --git a/src/player_thread.c b/src/player_thread.c index 486a8c96e..15fc9d235 100644 --- a/src/player_thread.c +++ b/src/player_thread.c @@ -458,7 +458,7 @@ static bool player_seek_decoder(struct player *player) assert(pc->next_song != NULL); - if (decoder_current_song(dc) != song) { + if (!decoder_lock_is_current_song(dc, song)) { /* the decoder is already decoding the "next" song - stop it and start the previous song again */ -- cgit v1.2.3