MPD

src/player_control.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-2010 The Music Player Daemon Project
00003  * http://www.musicpd.org
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, write to the Free Software Foundation, Inc.,
00017  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018  */
00019 
00020 #ifndef MPD_PLAYER_H
00021 #define MPD_PLAYER_H
00022 
00023 #include "notify.h"
00024 #include "audio_format.h"
00025 
00026 #include <stdint.h>
00027 
00028 struct decoder_control;
00029 
00030 enum player_state {
00031         PLAYER_STATE_STOP = 0,
00032         PLAYER_STATE_PAUSE,
00033         PLAYER_STATE_PLAY
00034 };
00035 
00036 enum player_command {
00037         PLAYER_COMMAND_NONE = 0,
00038         PLAYER_COMMAND_EXIT,
00039         PLAYER_COMMAND_STOP,
00040         PLAYER_COMMAND_PAUSE,
00041         PLAYER_COMMAND_SEEK,
00042         PLAYER_COMMAND_CLOSE_AUDIO,
00043 
00048         PLAYER_COMMAND_UPDATE_AUDIO,
00049 
00051         PLAYER_COMMAND_QUEUE,
00052 
00058         PLAYER_COMMAND_CANCEL,
00059 
00064         PLAYER_COMMAND_REFRESH,
00065 };
00066 
00067 enum player_error {
00068         PLAYER_ERROR_NOERROR = 0,
00069         PLAYER_ERROR_FILE,
00070         PLAYER_ERROR_AUDIO,
00071         PLAYER_ERROR_SYSTEM,
00072         PLAYER_ERROR_UNKTYPE,
00073         PLAYER_ERROR_FILENOTFOUND,
00074 };
00075 
00076 struct player_status {
00077         enum player_state state;
00078         uint16_t bit_rate;
00079         struct audio_format audio_format;
00080         float total_time;
00081         float elapsed_time;
00082 };
00083 
00084 struct player_control {
00085         unsigned buffer_chunks;
00086 
00087         unsigned int buffered_before_play;
00088 
00091         GThread *thread;
00092 
00096         GMutex *mutex;
00097 
00101         GCond *cond;
00102 
00103         enum player_command command;
00104         enum player_state state;
00105         enum player_error error;
00106         uint16_t bit_rate;
00107         struct audio_format audio_format;
00108         float total_time;
00109         float elapsed_time;
00110         struct song *next_song;
00111         const struct song *errored_song;
00112         double seek_where;
00113         float cross_fade_seconds;
00114         float mixramp_db;
00115         float mixramp_delay_seconds;
00116         double total_play_time;
00117 };
00118 
00119 extern struct player_control pc;
00120 
00121 void pc_init(unsigned buffer_chunks, unsigned buffered_before_play);
00122 
00123 void pc_deinit(void);
00124 
00128 static inline void
00129 player_lock(void)
00130 {
00131         g_mutex_lock(pc.mutex);
00132 }
00133 
00137 static inline void
00138 player_unlock(void)
00139 {
00140         g_mutex_unlock(pc.mutex);
00141 }
00142 
00148 static inline void
00149 player_wait(void)
00150 {
00151         g_cond_wait(pc.cond, pc.mutex);
00152 }
00153 
00161 void
00162 player_wait_decoder(struct decoder_control *dc);
00163 
00168 static inline void
00169 player_signal(void)
00170 {
00171         g_cond_signal(pc.cond);
00172 }
00173 
00178 static inline void
00179 player_lock_signal(void)
00180 {
00181         player_lock();
00182         player_signal();
00183         player_unlock();
00184 }
00185 
00191 void
00192 pc_song_deleted(const struct song *song);
00193 
00194 void
00195 pc_play(struct song *song);
00196 
00200 void pc_cancel(void);
00201 
00202 void
00203 pc_set_pause(bool pause_flag);
00204 
00205 void
00206 pc_pause(void);
00207 
00208 void
00209 pc_kill(void);
00210 
00211 void
00212 pc_get_status(struct player_status *status);
00213 
00214 enum player_state
00215 pc_get_state(void);
00216 
00217 void
00218 pc_clear_error(void);
00219 
00225 char *
00226 pc_get_error_message(void);
00227 
00228 enum player_error
00229 pc_get_error(void);
00230 
00231 void
00232 pc_stop(void);
00233 
00234 void
00235 pc_update_audio(void);
00236 
00237 void
00238 pc_enqueue_song(struct song *song);
00239 
00246 bool
00247 pc_seek(struct song *song, float seek_time);
00248 
00249 void
00250 pc_set_cross_fade(float cross_fade_seconds);
00251 
00252 float
00253 pc_get_cross_fade(void);
00254 
00255 void
00256 pc_set_mixramp_db(float mixramp_db);
00257 
00258 float
00259 pc_get_mixramp_db(void);
00260 
00261 void
00262 pc_set_mixramp_delay(float mixramp_delay_seconds);
00263 
00264 float
00265 pc_get_mixramp_delay(void);
00266 
00267 double
00268 pc_get_total_play_time(void);
00269 
00270 #endif