MPD

src/output_plugin.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_OUTPUT_PLUGIN_H
00021 #define MPD_OUTPUT_PLUGIN_H
00022 
00023 #include <glib.h>
00024 
00025 #include <stdbool.h>
00026 #include <stddef.h>
00027 
00028 struct config_param;
00029 struct audio_format;
00030 struct tag;
00031 
00035 struct audio_output_plugin {
00039         const char *name;
00040 
00045         bool (*test_default_device)(void);
00046 
00060         void *(*init)(const struct audio_format *audio_format,
00061                       const struct config_param *param,
00062                       GError **error);
00063 
00067         void (*finish)(void *data);
00068 
00079         bool (*enable)(void *data, GError **error_r);
00080 
00085         void (*disable)(void *data);
00086 
00095         bool (*open)(void *data, struct audio_format *audio_format,
00096                      GError **error);
00097 
00101         void (*close)(void *data);
00102 
00111         unsigned (*delay)(void *data);
00112 
00117         void (*send_tag)(void *data, const struct tag *tag);
00118 
00126         size_t (*play)(void *data, const void *chunk, size_t size,
00127                        GError **error);
00128 
00132         void (*drain)(void *data);
00133 
00138         void (*cancel)(void *data);
00139 
00151         bool (*pause)(void *data);
00152 
00159         const struct mixer_plugin *mixer_plugin;
00160 };
00161 
00162 static inline bool
00163 ao_plugin_test_default_device(const struct audio_output_plugin *plugin)
00164 {
00165         return plugin->test_default_device != NULL
00166                 ? plugin->test_default_device()
00167                 : false;
00168 }
00169 
00170 static inline void *
00171 ao_plugin_init(const struct audio_output_plugin *plugin,
00172                const struct audio_format *audio_format,
00173                const struct config_param *param,
00174                GError **error)
00175 {
00176         return plugin->init(audio_format, param, error);
00177 }
00178 
00179 static inline void
00180 ao_plugin_finish(const struct audio_output_plugin *plugin, void *data)
00181 {
00182         plugin->finish(data);
00183 }
00184 
00185 static inline bool
00186 ao_plugin_enable(const struct audio_output_plugin *plugin, void *data,
00187                  GError **error_r)
00188 {
00189         return plugin->enable != NULL
00190                 ? plugin->enable(data, error_r)
00191                 : true;
00192 }
00193 
00194 static inline void
00195 ao_plugin_disable(const struct audio_output_plugin *plugin, void *data)
00196 {
00197         if (plugin->disable != NULL)
00198                 plugin->disable(data);
00199 }
00200 
00201 static inline bool
00202 ao_plugin_open(const struct audio_output_plugin *plugin,
00203                void *data, struct audio_format *audio_format,
00204                GError **error)
00205 {
00206         return plugin->open(data, audio_format, error);
00207 }
00208 
00209 static inline void
00210 ao_plugin_close(const struct audio_output_plugin *plugin, void *data)
00211 {
00212         plugin->close(data);
00213 }
00214 
00215 static inline unsigned
00216 ao_plugin_delay(const struct audio_output_plugin *plugin, void *data)
00217 {
00218         return plugin->delay != NULL
00219                 ? plugin->delay(data)
00220                 : 0;
00221 }
00222 
00223 static inline void
00224 ao_plugin_send_tag(const struct audio_output_plugin *plugin,
00225                    void *data, const struct tag *tag)
00226 {
00227         if (plugin->send_tag != NULL)
00228                 plugin->send_tag(data, tag);
00229 }
00230 
00231 static inline size_t
00232 ao_plugin_play(const struct audio_output_plugin *plugin,
00233                void *data, const void *chunk, size_t size,
00234                GError **error)
00235 {
00236         return plugin->play(data, chunk, size, error);
00237 }
00238 
00239 static inline void
00240 ao_plugin_drain(const struct audio_output_plugin *plugin, void *data)
00241 {
00242         if (plugin->drain != NULL)
00243                 plugin->drain(data);
00244 }
00245 
00246 static inline void
00247 ao_plugin_cancel(const struct audio_output_plugin *plugin, void *data)
00248 {
00249         if (plugin->cancel != NULL)
00250                 plugin->cancel(data);
00251 }
00252 
00253 static inline bool
00254 ao_plugin_pause(const struct audio_output_plugin *plugin, void *data)
00255 {
00256         return plugin->pause != NULL
00257                 ? plugin->pause(data)
00258                 : false;
00259 }
00260 
00261 #endif