diff options
Diffstat (limited to '')
-rw-r--r-- | src/PlayerControl.hxx (renamed from src/player_control.h) | 124 |
1 files changed, 88 insertions, 36 deletions
diff --git a/src/player_control.h b/src/PlayerControl.hxx index a77d31ec5..322b95c84 100644 --- a/src/player_control.h +++ b/src/PlayerControl.hxx @@ -21,6 +21,8 @@ #define MPD_PLAYER_H #include "audio_format.h" +#include "thread/Mutex.hxx" +#include "thread/Cond.hxx" #include <glib.h> @@ -66,12 +68,17 @@ enum player_command { }; enum player_error { - PLAYER_ERROR_NOERROR = 0, - PLAYER_ERROR_FILE, - PLAYER_ERROR_AUDIO, - PLAYER_ERROR_SYSTEM, - PLAYER_ERROR_UNKTYPE, - PLAYER_ERROR_FILENOTFOUND, + PLAYER_ERROR_NONE = 0, + + /** + * The decoder has failed to decode the song. + */ + PLAYER_ERROR_DECODER, + + /** + * The audio output has failed. + */ + PLAYER_ERROR_OUTPUT, }; struct player_status { @@ -94,22 +101,39 @@ struct player_control { /** * This lock protects #command, #state, #error. */ - GMutex *mutex; + Mutex mutex; /** * Trigger this object after you have modified #command. */ - GCond *cond; + Cond cond; enum player_command command; enum player_state state; - enum player_error error; + + enum player_error error_type; + + /** + * The error that occurred in the player thread. This + * attribute is only valid if #error is not + * #PLAYER_ERROR_NONE. The object must be freed when this + * object transitions back to #PLAYER_ERROR_NONE. + */ + GError *error; + uint16_t bit_rate; struct audio_format audio_format; float total_time; float elapsed_time; + + /** + * The next queued song. + * + * This is a duplicate, and must be freed when this attribute + * is cleared. + */ struct song *next_song; - const struct song *errored_song; + double seek_where; float cross_fade_seconds; float mixramp_db; @@ -124,13 +148,11 @@ struct player_control { * time. */ bool border_pause; -}; - -struct player_control * -pc_new(unsigned buffer_chunks, unsigned buffered_before_play); -void -pc_free(struct player_control *pc); + player_control(unsigned buffer_chunks, + unsigned buffered_before_play); + ~player_control(); +}; /** * Locks the #player_control object. @@ -138,7 +160,7 @@ pc_free(struct player_control *pc); static inline void player_lock(struct player_control *pc) { - g_mutex_lock(pc->mutex); + pc->mutex.lock(); } /** @@ -147,7 +169,7 @@ player_lock(struct player_control *pc) static inline void player_unlock(struct player_control *pc) { - g_mutex_unlock(pc->mutex); + pc->mutex.unlock(); } /** @@ -158,7 +180,7 @@ player_unlock(struct player_control *pc) static inline void player_wait(struct player_control *pc) { - g_cond_wait(pc->cond, pc->mutex); + pc->cond.wait(pc->mutex); } /** @@ -178,7 +200,7 @@ player_wait_decoder(struct player_control *pc, struct decoder_control *dc); static inline void player_signal(struct player_control *pc) { - g_cond_signal(pc->cond); + pc->cond.signal(); } /** @@ -194,14 +216,10 @@ player_lock_signal(struct player_control *pc) } /** - * Call this function when the specified song pointer is about to be - * invalidated. This makes sure that player_control.errored_song does - * not point to an invalid pointer. + * @param song the song to be queued; the given instance will be owned + * and freed by the player */ void -pc_song_deleted(struct player_control *pc, const struct song *song); - -void pc_play(struct player_control *pc, struct song *song); /** @@ -228,8 +246,24 @@ pc_kill(struct player_control *pc); void pc_get_status(struct player_control *pc, struct player_status *status); -enum player_state -pc_get_state(struct player_control *pc); +static inline enum player_state +pc_get_state(struct player_control *pc) +{ + return pc->state; +} + +/** + * 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); void pc_clear_error(struct player_control *pc); @@ -242,8 +276,11 @@ pc_clear_error(struct player_control *pc); char * pc_get_error_message(struct player_control *pc); -enum player_error -pc_get_error(struct player_control *pc); +static inline enum player_error +pc_get_error_type(struct player_control *pc) +{ + return pc->error_type; +} void pc_stop(struct player_control *pc); @@ -251,12 +288,18 @@ pc_stop(struct player_control *pc); void pc_update_audio(struct player_control *pc); +/** + * @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); /** * 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) */ @@ -272,16 +315,25 @@ pc_get_cross_fade(const struct player_control *pc); void pc_set_mixramp_db(struct player_control *pc, float mixramp_db); -float -pc_get_mixramp_db(const struct player_control *pc); +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); -float -pc_get_mixramp_delay(const struct player_control *pc); +static inline float +pc_get_mixramp_delay(const struct player_control *pc) +{ + return pc->mixramp_delay_seconds; +} -double -pc_get_total_play_time(const struct player_control *pc); +static inline double +pc_get_total_play_time(const struct player_control *pc) +{ + return pc->total_play_time; +} #endif |