From e8aee4d992004e21e3862417e9ce0d1421073bb2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 10 Feb 2009 22:09:07 +0100 Subject: output_thread: moved code to ao_close() Merge some duplicate code into one function. --- src/output_thread.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/output_thread.c b/src/output_thread.c index 76f090c31..196aaf142 100644 --- a/src/output_thread.c +++ b/src/output_thread.c @@ -38,6 +38,16 @@ static void ao_command_finished(struct audio_output *ao) notify_signal(&audio_output_client_notify); } +static void +ao_close(struct audio_output *ao) +{ + assert(ao->open); + + ao->plugin->close(ao->data); + pcm_convert_deinit(&ao->convert_state); + ao->open = false; +} + static void ao_play(struct audio_output *ao) { const char *data = ao->args.play.data; @@ -62,9 +72,7 @@ static void ao_play(struct audio_output *ao) ret = ao->plugin->play(ao->data, data, size); if (!ret) { ao->plugin->cancel(ao->data); - ao->plugin->close(ao->data); - pcm_convert_deinit(&ao->convert_state); - ao->open = false; + ao_close(ao); } ao_command_finished(ao); @@ -83,17 +91,13 @@ static void ao_pause(struct audio_output *ao) ret = ao->plugin->pause(ao->data); if (!ret) { - ao->plugin->close(ao->data); - pcm_convert_deinit(&ao->convert_state); - ao->open = false; + ao_close(ao); break; } } while (ao->command == AO_COMMAND_NONE); } else { /* pause is not supported - simply close the device */ - ao->plugin->close(ao->data); - pcm_convert_deinit(&ao->convert_state); - ao->open = false; + ao_close(ao); ao_command_finished(ao); } } @@ -127,10 +131,8 @@ static gpointer audio_output_task(gpointer arg) case AO_COMMAND_CLOSE: assert(ao->open); ao->plugin->cancel(ao->data); - ao->plugin->close(ao->data); - pcm_convert_deinit(&ao->convert_state); - ao->open = false; + ao_close(ao); ao_command_finished(ao); break; -- cgit v1.2.3