From e53ca368a5448291ca2783b8061727635084618f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 23 Oct 2009 10:55:52 +0200 Subject: output_plugin: added methods enable() and disable() With these methods, an output plugin can allocate some global resources only if it is actually enabled. The method enable() is called after daemonization, which allows for more sophisticated resource allocation during that method. --- src/output_thread.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/output_thread.c') diff --git a/src/output_thread.c b/src/output_thread.c index 9eb2478b0..4bae2f162 100644 --- a/src/output_thread.c +++ b/src/output_thread.c @@ -42,6 +42,40 @@ static void ao_command_finished(struct audio_output *ao) notify_signal(&audio_output_client_notify); } +static bool +ao_enable(struct audio_output *ao) +{ + GError *error = NULL; + + if (ao->really_enabled) + return true; + + if (!ao_plugin_enable(ao->plugin, ao->data, &error)) { + g_warning("Failed to enable \"%s\" [%s]: %s\n", + ao->name, ao->plugin->name, error->message); + g_error_free(error); + return false; + } + + ao->really_enabled = true; + return true; +} + +static void +ao_close(struct audio_output *ao); + +static void +ao_disable(struct audio_output *ao) +{ + if (ao->open) + ao_close(ao); + + if (ao->really_enabled) { + ao->really_enabled = false; + ao_plugin_disable(ao->plugin, ao->data); + } +} + static void ao_open(struct audio_output *ao) { @@ -54,6 +88,12 @@ ao_open(struct audio_output *ao) assert(ao->pipe != NULL); assert(ao->chunk == NULL); + /* enable the device (just in case the last enable has failed) */ + + if (!ao_enable(ao)) + /* still no luck */ + return; + /* open the filter */ filter_audio_format = filter_open(ao->filter, &ao->in_audio_format, @@ -321,6 +361,16 @@ static gpointer audio_output_task(gpointer arg) case AO_COMMAND_NONE: break; + case AO_COMMAND_ENABLE: + ao_enable(ao); + ao_command_finished(ao); + break; + + case AO_COMMAND_DISABLE: + ao_disable(ao); + ao_command_finished(ao); + break; + case AO_COMMAND_OPEN: ao_open(ao); ao_command_finished(ao); -- cgit v1.2.3