aboutsummaryrefslogtreecommitdiffstats
path: root/src/output_thread.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-10-29 15:59:40 +0100
committerMax Kellermann <max@duempel.org>2009-10-29 15:59:40 +0100
commit1403172ef397c3dfc58a64c999a362cca977241b (patch)
tree5fcd866c62528295dfa697cc06dfba862ed3ff61 /src/output_thread.c
parentf74ee1a352a0fb39fd0a0b42ab740f2f6e6957a3 (diff)
downloadmpd-1403172ef397c3dfc58a64c999a362cca977241b.tar.gz
mpd-1403172ef397c3dfc58a64c999a362cca977241b.tar.xz
mpd-1403172ef397c3dfc58a64c999a362cca977241b.zip
output_plugin: added method "drain"
drain() is the opposite of cancel(): it waits until all data in the buffer has finished playing. Instead of implicitly draining in the close() method like the ALSA plugin has been doing it forever, let the output thread decide whether to drain or to cancel.
Diffstat (limited to 'src/output_thread.c')
-rw-r--r--src/output_thread.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/output_thread.c b/src/output_thread.c
index f1af81a37..9d25d4758 100644
--- a/src/output_thread.c
+++ b/src/output_thread.c
@@ -62,13 +62,13 @@ ao_enable(struct audio_output *ao)
}
static void
-ao_close(struct audio_output *ao);
+ao_close(struct audio_output *ao, bool drain);
static void
ao_disable(struct audio_output *ao)
{
if (ao->open)
- ao_close(ao);
+ ao_close(ao, false);
if (ao->really_enabled) {
ao->really_enabled = false;
@@ -151,7 +151,7 @@ ao_open(struct audio_output *ao)
}
static void
-ao_close(struct audio_output *ao)
+ao_close(struct audio_output *ao, bool drain)
{
assert(ao->open);
@@ -162,6 +162,11 @@ ao_close(struct audio_output *ao)
ao->open = false;
g_mutex_unlock(ao->mutex);
+ if (drain)
+ ao_plugin_drain(ao->plugin, ao->data);
+ else
+ ao_plugin_cancel(ao->plugin, ao->data);
+
ao_plugin_close(ao->plugin, ao->data);
filter_close(ao->filter);
@@ -208,7 +213,7 @@ ao_reopen(struct audio_output *ao)
if (!audio_format_fully_defined(&ao->config_audio_format)) {
if (ao->open) {
const struct music_pipe *mp = ao->pipe;
- ao_close(ao);
+ ao_close(ao, true);
ao->pipe = mp;
}
@@ -253,8 +258,7 @@ ao_play_chunk(struct audio_output *ao, const struct music_chunk *chunk)
ao->name, ao->plugin->name, error->message);
g_error_free(error);
- ao_plugin_cancel(ao->plugin, ao->data);
- ao_close(ao);
+ ao_close(ao, false);
/* don't automatically reopen this device for 10
seconds */
@@ -273,8 +277,7 @@ ao_play_chunk(struct audio_output *ao, const struct music_chunk *chunk)
ao->name, ao->plugin->name, error->message);
g_error_free(error);
- ao_plugin_cancel(ao->plugin, ao->data);
- ao_close(ao);
+ ao_close(ao, false);
/* don't automatically reopen this device for
10 seconds */
@@ -344,7 +347,7 @@ static void ao_pause(struct audio_output *ao)
do {
ret = ao_plugin_pause(ao->plugin, ao->data);
if (!ret) {
- ao_close(ao);
+ ao_close(ao, false);
break;
}
} while (ao->command == AO_COMMAND_NONE);
@@ -385,8 +388,7 @@ static gpointer audio_output_task(gpointer arg)
assert(ao->open);
assert(ao->pipe != NULL);
- ao_plugin_cancel(ao->plugin, ao->data);
- ao_close(ao);
+ ao_close(ao, false);
ao_command_finished(ao);
break;