aboutsummaryrefslogtreecommitdiffstats
path: root/src/player_control.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/player_control.h')
-rw-r--r--src/player_control.h178
1 files changed, 144 insertions, 34 deletions
diff --git a/src/player_control.h b/src/player_control.h
index b1f7481cd..76c47609a 100644
--- a/src/player_control.h
+++ b/src/player_control.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * Copyright (C) 2003-2010 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -25,6 +25,8 @@
#include <stdint.h>
+struct decoder_control;
+
enum player_state {
PLAYER_STATE_STOP = 0,
PLAYER_STATE_PAUSE,
@@ -35,11 +37,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 +56,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 +73,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,19 +90,29 @@ 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;
float elapsed_time;
- struct song *volatile next_song;
- struct song *errored_song;
- volatile double seek_where;
+ struct song *next_song;
+ const struct song *errored_song;
+ double seek_where;
float cross_fade_seconds;
- uint16_t software_volume;
+ float mixramp_db;
+ float mixramp_delay_seconds;
double total_play_time;
};
@@ -92,6 +123,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(struct decoder_control *dc);
+
+/**
+ * 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 +192,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 +246,25 @@ queueSong(struct song *song);
bool
pc_seek(struct song *song, float seek_time);
-void setPlayerCrossFade(float crossFadeInSeconds);
+void
+pc_set_cross_fade(float cross_fade_seconds);
+
+float
+pc_get_cross_fade(void);
-float getPlayerCrossFade(void);
+void
+pc_set_mixramp_db(float mixramp_db);
-void setPlayerSoftwareVolume(int volume);
+float
+pc_get_mixramp_db(void);
-double getPlayerTotalPlayTime(void);
+void
+pc_set_mixramp_delay(float mixramp_delay_seconds);
-static inline const struct audio_format *
-player_get_audio_format(void)
-{
- return &pc.audio_format;
-}
+float
+pc_get_mixramp_delay(void);
-void playerInit(void);
+double
+pc_get_total_play_time(void);
#endif