aboutsummaryrefslogtreecommitdiff
path: root/src/output_thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/output_thread.c')
-rw-r--r--src/output_thread.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/output_thread.c b/src/output_thread.c
index 9eb2478b..4bae2f16 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);