MPD
decoder_control.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2010 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
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.
9  *
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.
14  *
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.
18  */
19 
20 #ifndef MPD_DECODER_CONTROL_H
21 #define MPD_DECODER_CONTROL_H
22 
23 #include "decoder_command.h"
24 #include "audio_format.h"
25 
26 #include <glib.h>
27 
28 #include <assert.h>
29 
34 
42 };
43 
47  GThread *thread;
48 
52  GMutex *mutex;
53 
59  GCond *cond;
60 
63 
64  bool quit;
65  bool seek_error;
66  bool seekable;
67  double seek_where;
68 
71 
74 
80  const struct song *song;
81 
88  unsigned start_ms;
89 
97  unsigned end_ms;
98 
99  float total_time;
100 
102  struct music_buffer *buffer;
103 
108  struct music_pipe *pipe;
109 
113  char *mixramp_end;
115 };
116 
117 void
118 dc_init(struct decoder_control *dc);
119 
120 void
121 dc_deinit(struct decoder_control *dc);
122 
126 static inline void
128 {
129  g_mutex_lock(dc->mutex);
130 }
131 
135 static inline void
137 {
138  g_mutex_unlock(dc->mutex);
139 }
140 
146 static inline void
148 {
149  g_cond_wait(dc->cond, dc->mutex);
150 }
151 
157 static inline void
159 {
160  g_cond_signal(dc->cond);
161 }
162 
163 static inline bool
165 {
166  return dc->state == DECODE_STATE_STOP ||
167  dc->state == DECODE_STATE_ERROR;
168 }
169 
170 static inline bool
172 {
173  return dc->state == DECODE_STATE_START;
174 }
175 
176 static inline bool
178 {
179  assert(dc->command == DECODE_COMMAND_NONE);
180 
181  return dc->state == DECODE_STATE_ERROR;
182 }
183 
184 static inline bool
186 {
187  bool ret;
188 
189  decoder_lock(dc);
190  ret = decoder_is_idle(dc);
191  decoder_unlock(dc);
192 
193  return ret;
194 }
195 
196 static inline bool
198 {
199  bool ret;
200 
201  decoder_lock(dc);
202  ret = decoder_is_starting(dc);
203  decoder_unlock(dc);
204 
205  return ret;
206 }
207 
208 static inline bool
210 {
211  bool ret;
212 
213  decoder_lock(dc);
214  ret = decoder_has_failed(dc);
215  decoder_unlock(dc);
216 
217  return ret;
218 }
219 
220 static inline const struct song *
222 {
223  switch (dc->state) {
224  case DECODE_STATE_STOP:
225  case DECODE_STATE_ERROR:
226  return NULL;
227 
228  case DECODE_STATE_START:
229  case DECODE_STATE_DECODE:
230  return dc->song;
231  }
232 
233  assert(false);
234  return NULL;
235 }
236 
237 void
238 dc_command_wait(struct decoder_control *dc);
239 
250 void
251 dc_start(struct decoder_control *dc, struct song *song,
252  unsigned start_ms, unsigned end_ms,
253  struct music_buffer *buffer, struct music_pipe *pipe);
254 
255 void
256 dc_stop(struct decoder_control *dc);
257 
258 bool
259 dc_seek(struct decoder_control *dc, double where);
260 
261 void
262 dc_quit(struct decoder_control *dc);
263 
264 void
265 dc_mixramp_start(struct decoder_control *dc, char *mixramp_start);
266 
267 void
268 dc_mixramp_end(struct decoder_control *dc, char *mixramp_end);
269 
270 void
271 dc_mixramp_prev_end(struct decoder_control *dc, char *mixramp_prev_end);
272 
273 #endif