output_thread: moved code to ao_close()

Merge some duplicate code into one function.
This commit is contained in:
Max Kellermann 2009-02-10 22:09:07 +01:00
parent a96993f655
commit e8aee4d992

View File

@ -38,6 +38,16 @@ static void ao_command_finished(struct audio_output *ao)
notify_signal(&audio_output_client_notify); 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) static void ao_play(struct audio_output *ao)
{ {
const char *data = ao->args.play.data; 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); ret = ao->plugin->play(ao->data, data, size);
if (!ret) { if (!ret) {
ao->plugin->cancel(ao->data); ao->plugin->cancel(ao->data);
ao->plugin->close(ao->data); ao_close(ao);
pcm_convert_deinit(&ao->convert_state);
ao->open = false;
} }
ao_command_finished(ao); ao_command_finished(ao);
@ -83,17 +91,13 @@ static void ao_pause(struct audio_output *ao)
ret = ao->plugin->pause(ao->data); ret = ao->plugin->pause(ao->data);
if (!ret) { if (!ret) {
ao->plugin->close(ao->data); ao_close(ao);
pcm_convert_deinit(&ao->convert_state);
ao->open = false;
break; break;
} }
} while (ao->command == AO_COMMAND_NONE); } while (ao->command == AO_COMMAND_NONE);
} else { } else {
/* pause is not supported - simply close the device */ /* pause is not supported - simply close the device */
ao->plugin->close(ao->data); ao_close(ao);
pcm_convert_deinit(&ao->convert_state);
ao->open = false;
ao_command_finished(ao); ao_command_finished(ao);
} }
} }
@ -127,10 +131,8 @@ static gpointer audio_output_task(gpointer arg)
case AO_COMMAND_CLOSE: case AO_COMMAND_CLOSE:
assert(ao->open); assert(ao->open);
ao->plugin->cancel(ao->data); ao->plugin->cancel(ao->data);
ao->plugin->close(ao->data);
pcm_convert_deinit(&ao->convert_state); ao_close(ao);
ao->open = false;
ao_command_finished(ao); ao_command_finished(ao);
break; break;