2 * Copyright (C) 2003-2009 The Music Player Daemon Project
3 * http://www.musicpd.org
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.
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.
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.
20 #ifndef MPD_OUTPUT_PLUGIN_H
21 #define MPD_OUTPUT_PLUGIN_H
33 * A plugin which controls an audio output device.
35 struct audio_output_plugin
{
42 * Test if this plugin can provide a default output, in case
43 * none has been configured. This method is optional.
45 bool (*test_default_device
)(void);
48 * Configure and initialize the device, but do not open it
51 * @param audio_format the configured audio format, or NULL if
53 * @param param the configuration section, or NULL if there is
55 * @param error location to store the error occuring, or NULL
57 * @return NULL on error, or an opaque pointer to the plugin's
60 void *(*init
)(const struct audio_format
*audio_format
,
61 const struct config_param
*param
,
65 * Free resources allocated by this device.
67 void (*finish
)(void *data
);
70 * Really open the device.
72 * @param audio_format the audio format in which data is going
73 * to be delivered; may be modified by the plugin
74 * @param error location to store the error occuring, or NULL
77 bool (*open
)(void *data
, struct audio_format
*audio_format
,
83 void (*close
)(void *data
);
86 * Display metadata for the next chunk. Optional method,
87 * because not all devices can display metadata.
89 void (*send_tag
)(void *data
, const struct tag
*tag
);
92 * Play a chunk of audio data.
94 * @param error location to store the error occuring, or NULL
96 * @return the number of bytes played, or 0 on error
98 size_t (*play
)(void *data
, const void *chunk
, size_t size
,
102 * Try to cancel data which may still be in the device's
105 void (*cancel
)(void *data
);
108 * Pause the device. If supported, it may perform a special
109 * action, which keeps the device open, but does not play
110 * anything. Output plugins like "shout" might want to play
111 * silence during pause, so their clients won't be
112 * disconnected. Plugins which do not support pausing will
113 * simply be closed, and have to be reopened when unpaused.
115 * @return false on error (output will be closed then), true
116 * for continue to pause
118 bool (*pause
)(void *data
);
121 * The mixer plugin associated with this output plugin. This
122 * may be NULL if no mixer plugin is implemented. When
123 * created, this mixer plugin gets the same #config_param as
124 * this audio output device.
126 const struct mixer_plugin
*mixer_plugin
;
130 ao_plugin_test_default_device(const struct audio_output_plugin
*plugin
)
132 return plugin
->test_default_device
!= NULL
133 ? plugin
->test_default_device()
138 ao_plugin_init(const struct audio_output_plugin
*plugin
,
139 const struct audio_format
*audio_format
,
140 const struct config_param
*param
,
143 return plugin
->init(audio_format
, param
, error
);
147 ao_plugin_finish(const struct audio_output_plugin
*plugin
, void *data
)
149 plugin
->finish(data
);
153 ao_plugin_open(const struct audio_output_plugin
*plugin
,
154 void *data
, struct audio_format
*audio_format
,
157 return plugin
->open(data
, audio_format
, error
);
161 ao_plugin_close(const struct audio_output_plugin
*plugin
, void *data
)
167 ao_plugin_send_tag(const struct audio_output_plugin
*plugin
,
168 void *data
, const struct tag
*tag
)
170 if (plugin
->send_tag
!= NULL
)
171 plugin
->send_tag(data
, tag
);
175 ao_plugin_play(const struct audio_output_plugin
*plugin
,
176 void *data
, const void *chunk
, size_t size
,
179 return plugin
->play(data
, chunk
, size
, error
);
183 ao_plugin_cancel(const struct audio_output_plugin
*plugin
, void *data
)
185 if (plugin
->cancel
!= NULL
)
186 plugin
->cancel(data
);
190 ao_plugin_pause(const struct audio_output_plugin
*plugin
, void *data
)
192 return plugin
->pause
!= NULL
193 ? plugin
->pause(data
)