output_plugin: added inline wrapper functions

Similar to the decoder plugin API: added wrapper functions to increase
code readability.
This commit is contained in:
Max Kellermann 2009-02-16 01:38:10 +01:00
parent 67da4cfe3c
commit 79b50b7d9c
4 changed files with 89 additions and 31 deletions

View File

@ -140,8 +140,7 @@ void audio_output_finish(struct audio_output *ao)
g_thread_join(ao->thread); g_thread_join(ao->thread);
} }
if (ao->plugin->finish) ao_plugin_finish(ao->plugin, ao->data);
ao->plugin->finish(ao->data);
notify_deinit(&ao->notify); notify_deinit(&ao->notify);
} }

View File

@ -69,7 +69,7 @@ audio_output_init(struct audio_output *ao, const struct config_param *param)
if (plugin->test_default_device) { if (plugin->test_default_device) {
g_warning("Attempting to detect a %s audio " g_warning("Attempting to detect a %s audio "
"device\n", plugin->name); "device\n", plugin->name);
if (plugin->test_default_device()) { if (ao_plugin_test_default_device(plugin)) {
g_warning("Successfully detected a %s " g_warning("Successfully detected a %s "
"audio device\n", plugin->name); "audio device\n", plugin->name);
break; break;
@ -109,8 +109,9 @@ audio_output_init(struct audio_output *ao, const struct config_param *param)
notify_init(&ao->notify); notify_init(&ao->notify);
ao->command = AO_COMMAND_NONE; ao->command = AO_COMMAND_NONE;
ao->data = plugin->init(ao, format ? &ao->config_audio_format : NULL, ao->data = ao_plugin_init(plugin, ao,
param); format ? &ao->config_audio_format : NULL,
param);
if (ao->data == NULL) if (ao->data == NULL)
return 0; return 0;

View File

@ -112,4 +112,70 @@ struct audio_output_plugin {
bool (*control)(void *data, int cmd, void *arg); bool (*control)(void *data, int cmd, void *arg);
}; };
static inline bool
ao_plugin_test_default_device(const struct audio_output_plugin *plugin)
{
return plugin->test_default_device != NULL
? plugin->test_default_device()
: false;
}
static inline void *
ao_plugin_init(const struct audio_output_plugin *plugin,
struct audio_output *ao,
const struct audio_format *audio_format,
const struct config_param *param)
{
return plugin->init(ao, audio_format, param);
}
static inline void
ao_plugin_finish(const struct audio_output_plugin *plugin, void *data)
{
plugin->finish(data);
}
static inline bool
ao_plugin_open(const struct audio_output_plugin *plugin,
void *data, struct audio_format *audio_format)
{
return plugin->open(data, audio_format);
}
static inline void
ao_plugin_close(const struct audio_output_plugin *plugin, void *data)
{
plugin->close(data);
}
static inline void
ao_plugin_send_tag(const struct audio_output_plugin *plugin,
void *data, const struct tag *tag)
{
if (plugin->send_tag != NULL)
plugin->send_tag(data, tag);
}
static inline bool
ao_plugin_play(const struct audio_output_plugin *plugin,
void *data, const void *chunk, size_t size)
{
return plugin->play(data, chunk, size);
}
static inline void
ao_plugin_cancel(const struct audio_output_plugin *plugin, void *data)
{
if (plugin->cancel != NULL)
plugin->cancel(data);
}
static inline bool
ao_plugin_pause(const struct audio_output_plugin *plugin, void *data)
{
return plugin->pause != NULL
? plugin->pause(data)
: false;
}
#endif #endif

View File

@ -43,7 +43,7 @@ ao_close(struct audio_output *ao)
{ {
assert(ao->open); assert(ao->open);
ao->plugin->close(ao->data); ao_plugin_close(ao->plugin, ao->data);
pcm_convert_deinit(&ao->convert_state); pcm_convert_deinit(&ao->convert_state);
ao->open = false; ao->open = false;
} }
@ -69,9 +69,9 @@ static void ao_play(struct audio_output *ao)
return; return;
} }
ret = ao->plugin->play(ao->data, data, size); ret = ao_plugin_play(ao->plugin, ao->data, data, size);
if (!ret) { if (!ret) {
ao->plugin->cancel(ao->data); ao_plugin_cancel(ao->plugin, ao->data);
ao_close(ao); ao_close(ao);
} }
@ -80,26 +80,18 @@ static void ao_play(struct audio_output *ao)
static void ao_pause(struct audio_output *ao) static void ao_pause(struct audio_output *ao)
{ {
ao->plugin->cancel(ao->data); bool ret;
if (ao->plugin->pause != NULL) { ao_plugin_cancel(ao->plugin, ao->data);
/* pause is supported */ ao_command_finished(ao);
ao_command_finished(ao);
do { do {
bool ret; ret = ao_plugin_pause(ao->plugin, ao->data);
if (!ret) {
ret = ao->plugin->pause(ao->data); ao_close(ao);
if (!ret) { break;
ao_close(ao); }
break; } while (ao->command == AO_COMMAND_NONE);
}
} while (ao->command == AO_COMMAND_NONE);
} else {
/* pause is not supported - simply close the device */
ao_close(ao);
ao_command_finished(ao);
}
} }
static gpointer audio_output_task(gpointer arg) static gpointer audio_output_task(gpointer arg)
@ -115,8 +107,8 @@ static gpointer audio_output_task(gpointer arg)
case AO_COMMAND_OPEN: case AO_COMMAND_OPEN:
assert(!ao->open); assert(!ao->open);
ret = ao->plugin->open(ao->data, ret = ao_plugin_open(ao->plugin, ao->data,
&ao->out_audio_format); &ao->out_audio_format);
assert(!ao->open); assert(!ao->open);
if (ret) { if (ret) {
@ -130,8 +122,8 @@ static gpointer audio_output_task(gpointer arg)
case AO_COMMAND_CLOSE: case AO_COMMAND_CLOSE:
assert(ao->open); assert(ao->open);
ao->plugin->cancel(ao->data);
ao_plugin_cancel(ao->plugin, ao->data);
ao_close(ao); ao_close(ao);
ao_command_finished(ao); ao_command_finished(ao);
break; break;
@ -145,12 +137,12 @@ static gpointer audio_output_task(gpointer arg)
break; break;
case AO_COMMAND_CANCEL: case AO_COMMAND_CANCEL:
ao->plugin->cancel(ao->data); ao_plugin_cancel(ao->plugin, ao->data);
ao_command_finished(ao); ao_command_finished(ao);
break; break;
case AO_COMMAND_SEND_TAG: case AO_COMMAND_SEND_TAG:
ao->plugin->send_tag(ao->data, ao->args.tag); ao_plugin_send_tag(ao->plugin, ao->data, ao->args.tag);
ao_command_finished(ao); ao_command_finished(ao);
break; break;