MPD
output_plugin.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_OUTPUT_PLUGIN_H
21 #define MPD_OUTPUT_PLUGIN_H
22 
23 #include <glib.h>
24 
25 #include <stdbool.h>
26 #include <stddef.h>
27 
28 struct config_param;
29 struct audio_format;
30 struct tag;
31 
39  const char *name;
40 
45  bool (*test_default_device)(void);
46 
60  void *(*init)(const struct audio_format *audio_format,
61  const struct config_param *param,
62  GError **error);
63 
67  void (*finish)(void *data);
68 
79  bool (*enable)(void *data, GError **error_r);
80 
85  void (*disable)(void *data);
86 
95  bool (*open)(void *data, struct audio_format *audio_format,
96  GError **error);
97 
101  void (*close)(void *data);
102 
111  unsigned (*delay)(void *data);
112 
117  void (*send_tag)(void *data, const struct tag *tag);
118 
126  size_t (*play)(void *data, const void *chunk, size_t size,
127  GError **error);
128 
132  void (*drain)(void *data);
133 
138  void (*cancel)(void *data);
139 
151  bool (*pause)(void *data);
152 
159  const struct mixer_plugin *mixer_plugin;
160 };
161 
162 static inline bool
164 {
165  return plugin->test_default_device != NULL
166  ? plugin->test_default_device()
167  : false;
168 }
169 
170 static inline void *
171 ao_plugin_init(const struct audio_output_plugin *plugin,
172  const struct audio_format *audio_format,
173  const struct config_param *param,
174  GError **error)
175 {
176  return plugin->init(audio_format, param, error);
177 }
178 
179 static inline void
180 ao_plugin_finish(const struct audio_output_plugin *plugin, void *data)
181 {
182  plugin->finish(data);
183 }
184 
185 static inline bool
186 ao_plugin_enable(const struct audio_output_plugin *plugin, void *data,
187  GError **error_r)
188 {
189  return plugin->enable != NULL
190  ? plugin->enable(data, error_r)
191  : true;
192 }
193 
194 static inline void
195 ao_plugin_disable(const struct audio_output_plugin *plugin, void *data)
196 {
197  if (plugin->disable != NULL)
198  plugin->disable(data);
199 }
200 
201 static inline bool
202 ao_plugin_open(const struct audio_output_plugin *plugin,
203  void *data, struct audio_format *audio_format,
204  GError **error)
205 {
206  return plugin->open(data, audio_format, error);
207 }
208 
209 static inline void
210 ao_plugin_close(const struct audio_output_plugin *plugin, void *data)
211 {
212  plugin->close(data);
213 }
214 
215 static inline unsigned
216 ao_plugin_delay(const struct audio_output_plugin *plugin, void *data)
217 {
218  return plugin->delay != NULL
219  ? plugin->delay(data)
220  : 0;
221 }
222 
223 static inline void
225  void *data, const struct tag *tag)
226 {
227  if (plugin->send_tag != NULL)
228  plugin->send_tag(data, tag);
229 }
230 
231 static inline size_t
232 ao_plugin_play(const struct audio_output_plugin *plugin,
233  void *data, const void *chunk, size_t size,
234  GError **error)
235 {
236  return plugin->play(data, chunk, size, error);
237 }
238 
239 static inline void
240 ao_plugin_drain(const struct audio_output_plugin *plugin, void *data)
241 {
242  if (plugin->drain != NULL)
243  plugin->drain(data);
244 }
245 
246 static inline void
247 ao_plugin_cancel(const struct audio_output_plugin *plugin, void *data)
248 {
249  if (plugin->cancel != NULL)
250  plugin->cancel(data);
251 }
252 
253 static inline bool
254 ao_plugin_pause(const struct audio_output_plugin *plugin, void *data)
255 {
256  return plugin->pause != NULL
257  ? plugin->pause(data)
258  : false;
259 }
260 
261 #endif