aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/output_control.c3
-rw-r--r--src/output_init.c7
-rw-r--r--src/output_plugin.h66
-rw-r--r--src/output_thread.c48
4 files changed, 91 insertions, 33 deletions
diff --git a/src/output_control.c b/src/output_control.c
index e8dcd5d9a..16908f1b4 100644
--- a/src/output_control.c
+++ b/src/output_control.c
@@ -140,8 +140,7 @@ void audio_output_finish(struct audio_output *ao)
g_thread_join(ao->thread);
}
- if (ao->plugin->finish)
- ao->plugin->finish(ao->data);
+ ao_plugin_finish(ao->plugin, ao->data);
notify_deinit(&ao->notify);
}
diff --git a/src/output_init.c b/src/output_init.c
index b7b088396..1e2592e8d 100644
--- a/src/output_init.c
+++ b/src/output_init.c
@@ -69,7 +69,7 @@ audio_output_init(struct audio_output *ao, const struct config_param *param)
if (plugin->test_default_device) {
g_warning("Attempting to detect a %s audio "
"device\n", plugin->name);
- if (plugin->test_default_device()) {
+ if (ao_plugin_test_default_device(plugin)) {
g_warning("Successfully detected a %s "
"audio device\n", plugin->name);
break;
@@ -109,8 +109,9 @@ audio_output_init(struct audio_output *ao, const struct config_param *param)
notify_init(&ao->notify);
ao->command = AO_COMMAND_NONE;
- ao->data = plugin->init(ao, format ? &ao->config_audio_format : NULL,
- param);
+ ao->data = ao_plugin_init(plugin, ao,
+ format ? &ao->config_audio_format : NULL,
+ param);
if (ao->data == NULL)
return 0;
diff --git a/src/output_plugin.h b/src/output_plugin.h
index 925982a9c..0166322fc 100644
--- a/src/output_plugin.h
+++ b/src/output_plugin.h
@@ -112,4 +112,70 @@ struct audio_output_plugin {
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
diff --git a/src/output_thread.c b/src/output_thread.c
index 196aaf142..098e1b427 100644
--- a/src/output_thread.c
+++ b/src/output_thread.c
@@ -43,7 +43,7 @@ ao_close(struct audio_output *ao)
{
assert(ao->open);
- ao->plugin->close(ao->data);
+ ao_plugin_close(ao->plugin, ao->data);
pcm_convert_deinit(&ao->convert_state);
ao->open = false;
}
@@ -69,9 +69,9 @@ static void ao_play(struct audio_output *ao)
return;
}
- ret = ao->plugin->play(ao->data, data, size);
+ ret = ao_plugin_play(ao->plugin, ao->data, data, size);
if (!ret) {
- ao->plugin->cancel(ao->data);
+ ao_plugin_cancel(ao->plugin, ao->data);
ao_close(ao);
}
@@ -80,26 +80,18 @@ static void ao_play(struct audio_output *ao)
static void ao_pause(struct audio_output *ao)
{
- ao->plugin->cancel(ao->data);
-
- if (ao->plugin->pause != NULL) {
- /* pause is supported */
- ao_command_finished(ao);
-
- do {
- bool ret;
-
- ret = ao->plugin->pause(ao->data);
- if (!ret) {
- ao_close(ao);
- break;
- }
- } while (ao->command == AO_COMMAND_NONE);
- } else {
- /* pause is not supported - simply close the device */
- ao_close(ao);
- ao_command_finished(ao);
- }
+ bool ret;
+
+ ao_plugin_cancel(ao->plugin, ao->data);
+ ao_command_finished(ao);
+
+ do {
+ ret = ao_plugin_pause(ao->plugin, ao->data);
+ if (!ret) {
+ ao_close(ao);
+ break;
+ }
+ } while (ao->command == AO_COMMAND_NONE);
}
static gpointer audio_output_task(gpointer arg)
@@ -115,8 +107,8 @@ static gpointer audio_output_task(gpointer arg)
case AO_COMMAND_OPEN:
assert(!ao->open);
- ret = ao->plugin->open(ao->data,
- &ao->out_audio_format);
+ ret = ao_plugin_open(ao->plugin, ao->data,
+ &ao->out_audio_format);
assert(!ao->open);
if (ret) {
@@ -130,8 +122,8 @@ static gpointer audio_output_task(gpointer arg)
case AO_COMMAND_CLOSE:
assert(ao->open);
- ao->plugin->cancel(ao->data);
+ ao_plugin_cancel(ao->plugin, ao->data);
ao_close(ao);
ao_command_finished(ao);
break;
@@ -145,12 +137,12 @@ static gpointer audio_output_task(gpointer arg)
break;
case AO_COMMAND_CANCEL:
- ao->plugin->cancel(ao->data);
+ ao_plugin_cancel(ao->plugin, ao->data);
ao_command_finished(ao);
break;
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);
break;