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_control.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src/output_control.c') 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); -- cgit v1.2.3