configure.ac: Move the encoders before the audio outputs.
[mpd-mk.git] / src / player_control.h
blob76c47609a02c833d600692a568e943fc0bc3d771
1 /*
2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef MPD_PLAYER_H
21 #define MPD_PLAYER_H
23 #include "notify.h"
24 #include "audio_format.h"
26 #include <stdint.h>
28 struct decoder_control;
30 enum player_state {
31 PLAYER_STATE_STOP = 0,
32 PLAYER_STATE_PAUSE,
33 PLAYER_STATE_PLAY
36 enum player_command {
37 PLAYER_COMMAND_NONE = 0,
38 PLAYER_COMMAND_EXIT,
39 PLAYER_COMMAND_STOP,
40 PLAYER_COMMAND_PAUSE,
41 PLAYER_COMMAND_SEEK,
42 PLAYER_COMMAND_CLOSE_AUDIO,
44 /**
45 * At least one audio_output.enabled flag has been modified;
46 * commit those changes to the output threads.
48 PLAYER_COMMAND_UPDATE_AUDIO,
50 /** player_control.next_song has been updated */
51 PLAYER_COMMAND_QUEUE,
53 /**
54 * cancel pre-decoding player_control.next_song; if the player
55 * has already started playing this song, it will completely
56 * stop
58 PLAYER_COMMAND_CANCEL,
60 /**
61 * Refresh status information in the #player_control struct,
62 * e.g. elapsed_time.
64 PLAYER_COMMAND_REFRESH,
67 enum player_error {
68 PLAYER_ERROR_NOERROR = 0,
69 PLAYER_ERROR_FILE,
70 PLAYER_ERROR_AUDIO,
71 PLAYER_ERROR_SYSTEM,
72 PLAYER_ERROR_UNKTYPE,
73 PLAYER_ERROR_FILENOTFOUND,
76 struct player_status {
77 enum player_state state;
78 uint16_t bit_rate;
79 struct audio_format audio_format;
80 float total_time;
81 float elapsed_time;
84 struct player_control {
85 unsigned buffer_chunks;
87 unsigned int buffered_before_play;
89 /** the handle of the player thread, or NULL if the player
90 thread isn't running */
91 GThread *thread;
93 /**
94 * This lock protects #command, #state, #error.
96 GMutex *mutex;
98 /**
99 * Trigger this object after you have modified #command.
101 GCond *cond;
103 enum player_command command;
104 enum player_state state;
105 enum player_error error;
106 uint16_t bit_rate;
107 struct audio_format audio_format;
108 float total_time;
109 float elapsed_time;
110 struct song *next_song;
111 const struct song *errored_song;
112 double seek_where;
113 float cross_fade_seconds;
114 float mixramp_db;
115 float mixramp_delay_seconds;
116 double total_play_time;
119 extern struct player_control pc;
121 void pc_init(unsigned buffer_chunks, unsigned buffered_before_play);
123 void pc_deinit(void);
126 * Locks the #player_control object.
128 static inline void
129 player_lock(void)
131 g_mutex_lock(pc.mutex);
135 * Unlocks the #player_control object.
137 static inline void
138 player_unlock(void)
140 g_mutex_unlock(pc.mutex);
144 * Waits for a signal on the #player_control object. This function is
145 * only valid in the player thread. The object must be locked prior
146 * to calling this function.
148 static inline void
149 player_wait(void)
151 g_cond_wait(pc.cond, pc.mutex);
155 * Waits for a signal on the #player_control object. This function is
156 * only valid in the player thread. The #decoder_control object must
157 * be locked prior to calling this function.
159 * Note the small difference to the player_wait() function!
161 void
162 player_wait_decoder(struct decoder_control *dc);
165 * Signals the #player_control object. The object should be locked
166 * prior to calling this function.
168 static inline void
169 player_signal(void)
171 g_cond_signal(pc.cond);
175 * Signals the #player_control object. The object is temporarily
176 * locked by this function.
178 static inline void
179 player_lock_signal(void)
181 player_lock();
182 player_signal();
183 player_unlock();
187 * Call this function when the specified song pointer is about to be
188 * invalidated. This makes sure that player_control.errored_song does
189 * not point to an invalid pointer.
191 void
192 pc_song_deleted(const struct song *song);
194 void
195 pc_play(struct song *song);
198 * see PLAYER_COMMAND_CANCEL
200 void pc_cancel(void);
202 void
203 pc_set_pause(bool pause_flag);
205 void
206 pc_pause(void);
208 void
209 pc_kill(void);
211 void
212 pc_get_status(struct player_status *status);
214 enum player_state
215 pc_get_state(void);
217 void
218 pc_clear_error(void);
221 * Returns the human-readable message describing the last error during
222 * playback, NULL if no error occurred. The caller has to free the
223 * returned string.
225 char *
226 pc_get_error_message(void);
228 enum player_error
229 pc_get_error(void);
231 void
232 pc_stop(void);
234 void
235 pc_update_audio(void);
237 void
238 pc_enqueue_song(struct song *song);
241 * Makes the player thread seek the specified song to a position.
243 * @return true on success, false on failure (e.g. if MPD isn't
244 * playing currently)
246 bool
247 pc_seek(struct song *song, float seek_time);
249 void
250 pc_set_cross_fade(float cross_fade_seconds);
252 float
253 pc_get_cross_fade(void);
255 void
256 pc_set_mixramp_db(float mixramp_db);
258 float
259 pc_get_mixramp_db(void);
261 void
262 pc_set_mixramp_delay(float mixramp_delay_seconds);
264 float
265 pc_get_mixramp_delay(void);
267 double
268 pc_get_total_play_time(void);
270 #endif