MPD 0.17~git
src/decoder_control.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-2011 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 
00065         GCond *client_cond;
00066 
00067         enum decoder_state state;
00068         enum decoder_command command;
00069 
00070         bool quit;
00071         bool seek_error;
00072         bool seekable;
00073         double seek_where;
00074 
00076         struct audio_format in_audio_format;
00077 
00079         struct audio_format out_audio_format;
00080 
00086         const struct song *song;
00087 
00094         unsigned start_ms;
00095 
00103         unsigned end_ms;
00104 
00105         float total_time;
00106 
00108         struct music_buffer *buffer;
00109 
00114         struct music_pipe *pipe;
00115 
00116         float replay_gain_db;
00117         float replay_gain_prev_db;
00118         char *mixramp_start;
00119         char *mixramp_end;
00120         char *mixramp_prev_end;
00121 };
00122 
00123 G_GNUC_MALLOC
00124 struct decoder_control *
00125 dc_new(GCond *client_cond);
00126 
00127 void
00128 dc_free(struct decoder_control *dc);
00129 
00133 static inline void
00134 decoder_lock(struct decoder_control *dc)
00135 {
00136         g_mutex_lock(dc->mutex);
00137 }
00138 
00142 static inline void
00143 decoder_unlock(struct decoder_control *dc)
00144 {
00145         g_mutex_unlock(dc->mutex);
00146 }
00147 
00153 static inline void
00154 decoder_wait(struct decoder_control *dc)
00155 {
00156         g_cond_wait(dc->cond, dc->mutex);
00157 }
00158 
00164 static inline void
00165 decoder_signal(struct decoder_control *dc)
00166 {
00167         g_cond_signal(dc->cond);
00168 }
00169 
00170 static inline bool
00171 decoder_is_idle(const struct decoder_control *dc)
00172 {
00173         return dc->state == DECODE_STATE_STOP ||
00174                 dc->state == DECODE_STATE_ERROR;
00175 }
00176 
00177 static inline bool
00178 decoder_is_starting(const struct decoder_control *dc)
00179 {
00180         return dc->state == DECODE_STATE_START;
00181 }
00182 
00183 static inline bool
00184 decoder_has_failed(const struct decoder_control *dc)
00185 {
00186         assert(dc->command == DECODE_COMMAND_NONE);
00187 
00188         return dc->state == DECODE_STATE_ERROR;
00189 }
00190 
00191 static inline bool
00192 decoder_lock_is_idle(struct decoder_control *dc)
00193 {
00194         bool ret;
00195 
00196         decoder_lock(dc);
00197         ret = decoder_is_idle(dc);
00198         decoder_unlock(dc);
00199 
00200         return ret;
00201 }
00202 
00203 static inline bool
00204 decoder_lock_is_starting(struct decoder_control *dc)
00205 {
00206         bool ret;
00207 
00208         decoder_lock(dc);
00209         ret = decoder_is_starting(dc);
00210         decoder_unlock(dc);
00211 
00212         return ret;
00213 }
00214 
00215 static inline bool
00216 decoder_lock_has_failed(struct decoder_control *dc)
00217 {
00218         bool ret;
00219 
00220         decoder_lock(dc);
00221         ret = decoder_has_failed(dc);
00222         decoder_unlock(dc);
00223 
00224         return ret;
00225 }
00226 
00227 static inline const struct song *
00228 decoder_current_song(const struct decoder_control *dc)
00229 {
00230         switch (dc->state) {
00231         case DECODE_STATE_STOP:
00232         case DECODE_STATE_ERROR:
00233                 return NULL;
00234 
00235         case DECODE_STATE_START:
00236         case DECODE_STATE_DECODE:
00237                 return dc->song;
00238         }
00239 
00240         assert(false);
00241         return NULL;
00242 }
00243 
00254 void
00255 dc_start(struct decoder_control *dc, struct song *song,
00256          unsigned start_ms, unsigned end_ms,
00257          struct music_buffer *buffer, struct music_pipe *pipe);
00258 
00259 void
00260 dc_stop(struct decoder_control *dc);
00261 
00262 bool
00263 dc_seek(struct decoder_control *dc, double where);
00264 
00265 void
00266 dc_quit(struct decoder_control *dc);
00267 
00268 void
00269 dc_mixramp_start(struct decoder_control *dc, char *mixramp_start);
00270 
00271 void
00272 dc_mixramp_end(struct decoder_control *dc, char *mixramp_end);
00273 
00274 void
00275 dc_mixramp_prev_end(struct decoder_control *dc, char *mixramp_prev_end);
00276 
00277 #endif