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_control.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_control.c')
-rw-r--r-- | src/output_control.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/output_control.c b/src/output_control.c index b833fb08d..6512cbe74 100644 --- a/src/output_control.c +++ b/src/output_control.c @@ -59,6 +59,41 @@ static void ao_command_async(struct audio_output *ao, notify_signal(&ao->notify); } +void +audio_output_enable(struct audio_output *ao) +{ + if (ao->thread == NULL) { + if (ao->plugin->enable == NULL) { + /* don't bother to start the thread now if the + device doesn't even have a enable() method; + just assign the variable and we're done */ + ao->really_enabled = true; + return; + } + + audio_output_thread_start(ao); + } + + ao_command(ao, AO_COMMAND_ENABLE); +} + +void +audio_output_disable(struct audio_output *ao) +{ + if (ao->thread == NULL) { + if (ao->plugin->disable == NULL) + ao->really_enabled = false; + else + /* if there's no thread yet, the device cannot + be enabled */ + assert(!ao->really_enabled); + + return; + } + + ao_command(ao, AO_COMMAND_DISABLE); +} + static bool audio_output_open(struct audio_output *ao, const struct audio_format *audio_format, @@ -122,7 +157,7 @@ audio_output_update(struct audio_output *ao, { assert(mp != NULL); - if (ao->enabled) { + if (ao->enabled && ao->really_enabled) { if (ao->fail_timer == NULL || g_timer_elapsed(ao->fail_timer, NULL) > REOPEN_AFTER) return audio_output_open(ao, audio_format, mp); |