diff options
author | Max Kellermann <max@duempel.org> | 2009-10-23 10:55:52 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-10-23 10:55:52 +0200 |
commit | e53ca368a5448291ca2783b8061727635084618f (patch) | |
tree | 596c18606cd386b580a23cc6d07cf121cca8db37 /src/output_thread.c | |
parent | c426a0bc5cc641ecd044c389f7180dad50a355bf (diff) | |
download | mpd-e53ca368a5448291ca2783b8061727635084618f.tar.gz mpd-e53ca368a5448291ca2783b8061727635084618f.tar.xz mpd-e53ca368a5448291ca2783b8061727635084618f.zip |
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.
Diffstat (limited to 'src/output_thread.c')
-rw-r--r-- | src/output_thread.c | 50 |
1 files changed, 50 insertions, 0 deletions
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); |