|
MPD
|
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_DECODER_CONTROL_H 00021 #define MPD_DECODER_CONTROL_H 00022 00023 #include "decoder_command.h" 00024 #include "audio_format.h" 00025 00026 #include <glib.h> 00027 00028 #include <assert.h> 00029 00030 enum decoder_state { 00031 DECODE_STATE_STOP = 0, 00032 DECODE_STATE_START, 00033 DECODE_STATE_DECODE, 00034 00041 DECODE_STATE_ERROR, 00042 }; 00043 00044 struct decoder_control { 00047 GThread *thread; 00048 00052 GMutex *mutex; 00053 00059 GCond *cond; 00060 00061 enum decoder_state state; 00062 enum decoder_command command; 00063 00064 bool quit; 00065 bool seek_error; 00066 bool seekable; 00067 double seek_where; 00068 00070 struct audio_format in_audio_format; 00071 00073 struct audio_format out_audio_format; 00074 00080 const struct song *song; 00081 00082 float total_time; 00083 00085 struct music_buffer *buffer; 00086 00091 struct music_pipe *pipe; 00092 00093 float replay_gain_db; 00094 float replay_gain_prev_db; 00095 char *mixramp_start; 00096 char *mixramp_end; 00097 char *mixramp_prev_end; 00098 }; 00099 00100 void 00101 dc_init(struct decoder_control *dc); 00102 00103 void 00104 dc_deinit(struct decoder_control *dc); 00105 00109 static inline void 00110 decoder_lock(struct decoder_control *dc) 00111 { 00112 g_mutex_lock(dc->mutex); 00113 } 00114 00118 static inline void 00119 decoder_unlock(struct decoder_control *dc) 00120 { 00121 g_mutex_unlock(dc->mutex); 00122 } 00123 00129 static inline void 00130 decoder_wait(struct decoder_control *dc) 00131 { 00132 g_cond_wait(dc->cond, dc->mutex); 00133 } 00134 00140 static inline void 00141 decoder_signal(struct decoder_control *dc) 00142 { 00143 g_cond_signal(dc->cond); 00144 } 00145 00146 static inline bool 00147 decoder_is_idle(const struct decoder_control *dc) 00148 { 00149 return dc->state == DECODE_STATE_STOP || 00150 dc->state == DECODE_STATE_ERROR; 00151 } 00152 00153 static inline bool 00154 decoder_is_starting(const struct decoder_control *dc) 00155 { 00156 return dc->state == DECODE_STATE_START; 00157 } 00158 00159 static inline bool 00160 decoder_has_failed(const struct decoder_control *dc) 00161 { 00162 assert(dc->command == DECODE_COMMAND_NONE); 00163 00164 return dc->state == DECODE_STATE_ERROR; 00165 } 00166 00167 static inline bool 00168 decoder_lock_is_idle(struct decoder_control *dc) 00169 { 00170 bool ret; 00171 00172 decoder_lock(dc); 00173 ret = decoder_is_idle(dc); 00174 decoder_unlock(dc); 00175 00176 return ret; 00177 } 00178 00179 static inline bool 00180 decoder_lock_is_starting(struct decoder_control *dc) 00181 { 00182 bool ret; 00183 00184 decoder_lock(dc); 00185 ret = decoder_is_starting(dc); 00186 decoder_unlock(dc); 00187 00188 return ret; 00189 } 00190 00191 static inline bool 00192 decoder_lock_has_failed(struct decoder_control *dc) 00193 { 00194 bool ret; 00195 00196 decoder_lock(dc); 00197 ret = decoder_has_failed(dc); 00198 decoder_unlock(dc); 00199 00200 return ret; 00201 } 00202 00203 static inline const struct song * 00204 decoder_current_song(const struct decoder_control *dc) 00205 { 00206 switch (dc->state) { 00207 case DECODE_STATE_STOP: 00208 case DECODE_STATE_ERROR: 00209 return NULL; 00210 00211 case DECODE_STATE_START: 00212 case DECODE_STATE_DECODE: 00213 return dc->song; 00214 } 00215 00216 assert(false); 00217 return NULL; 00218 } 00219 00220 void 00221 dc_command_wait(struct decoder_control *dc); 00222 00231 void 00232 dc_start(struct decoder_control *dc, struct song *song, 00233 struct music_buffer *buffer, struct music_pipe *pipe); 00234 00235 void 00236 dc_stop(struct decoder_control *dc); 00237 00238 bool 00239 dc_seek(struct decoder_control *dc, double where); 00240 00241 void 00242 dc_quit(struct decoder_control *dc); 00243 00244 void 00245 dc_mixramp_start(struct decoder_control *dc, char *mixramp_start); 00246 00247 void 00248 dc_mixramp_end(struct decoder_control *dc, char *mixramp_end); 00249 00250 void 00251 dc_mixramp_prev_end(struct decoder_control *dc, char *mixramp_prev_end); 00252 00253 #endif
1.7.3