diff options
Diffstat (limited to 'src/player_control.h')
-rw-r--r-- | src/player_control.h | 160 |
1 files changed, 127 insertions, 33 deletions
diff --git a/src/player_control.h b/src/player_control.h index b1f7481cd..449e98aa5 100644 --- a/src/player_control.h +++ b/src/player_control.h @@ -35,11 +35,16 @@ enum player_command { PLAYER_COMMAND_NONE = 0, PLAYER_COMMAND_EXIT, PLAYER_COMMAND_STOP, - PLAYER_COMMAND_PLAY, PLAYER_COMMAND_PAUSE, PLAYER_COMMAND_SEEK, PLAYER_COMMAND_CLOSE_AUDIO, + /** + * At least one audio_output.enabled flag has been modified; + * commit those changes to the output threads. + */ + PLAYER_COMMAND_UPDATE_AUDIO, + /** player_control.next_song has been updated */ PLAYER_COMMAND_QUEUE, @@ -49,6 +54,12 @@ enum player_command { * stop */ PLAYER_COMMAND_CANCEL, + + /** + * Refresh status information in the #player_control struct, + * e.g. elapsed_time. + */ + PLAYER_COMMAND_REFRESH, }; enum player_error { @@ -60,6 +71,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; @@ -69,10 +88,19 @@ struct player_control { thread isn't running */ GThread *thread; - struct notify notify; - volatile enum player_command command; - volatile enum player_state state; - volatile enum player_error error; + /** + * This lock protects #command, #state, #error. + */ + GMutex *mutex; + + /** + * Trigger this object after you have modified #command. + */ + GCond *cond; + + enum player_command command; + enum player_state state; + enum player_error error; uint16_t bit_rate; struct audio_format audio_format; float total_time; @@ -81,7 +109,6 @@ struct player_control { struct song *errored_song; volatile double seek_where; float cross_fade_seconds; - uint16_t software_volume; double total_play_time; }; @@ -92,6 +119,67 @@ void pc_init(unsigned buffer_chunks, unsigned buffered_before_play); void pc_deinit(void); /** + * Locks the #player_control object. + */ +static inline void +player_lock(void) +{ + g_mutex_lock(pc.mutex); +} + +/** + * Unlocks the #player_control object. + */ +static inline void +player_unlock(void) +{ + g_mutex_unlock(pc.mutex); +} + +/** + * 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(void) +{ + g_cond_wait(pc.cond, 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(void); + +/** + * Signals the #player_control object. The object should be locked + * prior to calling this function. + */ +static inline void +player_signal(void) +{ + g_cond_signal(pc.cond); +} + +/** + * Signals the #player_control object. The object is temporarily + * locked by this function. + */ +static inline void +player_lock_signal(void) +{ + player_lock(); + player_signal(); + player_unlock(); +} + +/** * 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. @@ -100,37 +188,50 @@ void pc_song_deleted(const struct song *song); void -playerPlay(struct song *song); +pc_play(struct song *song); /** * see PLAYER_COMMAND_CANCEL */ void pc_cancel(void); -void playerSetPause(int pause_flag); - -void playerPause(void); +void +pc_set_pause(bool pause_flag); -void playerKill(void); +void +pc_pause(void); -int getPlayerTotalTime(void); +void +pc_kill(void); -int getPlayerElapsedTime(void); +void +pc_get_status(struct player_status *status); -unsigned long getPlayerBitRate(void); +enum player_state +pc_get_state(void); -enum player_state getPlayerState(void); +void +pc_clear_error(void); -void clearPlayerError(void); +/** + * 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(void); -char *getPlayerErrorStr(void); +enum player_error +pc_get_error(void); -enum player_error getPlayerError(void); +void +pc_stop(void); -void playerWait(void); +void +pc_update_audio(void); void -queueSong(struct song *song); +pc_enqueue_song(struct song *song); /** * Makes the player thread seek the specified song to a position. @@ -141,20 +242,13 @@ queueSong(struct song *song); bool pc_seek(struct song *song, float seek_time); -void setPlayerCrossFade(float crossFadeInSeconds); - -float getPlayerCrossFade(void); - -void setPlayerSoftwareVolume(int volume); - -double getPlayerTotalPlayTime(void); +void +pc_set_cross_fade(float cross_fade_seconds); -static inline const struct audio_format * -player_get_audio_format(void) -{ - return &pc.audio_format; -} +float +pc_get_cross_fade(void); -void playerInit(void); +double +pc_get_total_play_time(void); #endif |