From 30d5186db44db788e609c0dea55b630c427c80e4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 25 Jan 2017 10:44:19 +0100 Subject: [PATCH] output/ao: use const_cast instead of the union hack --- src/output/plugins/AoOutputPlugin.cxx | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/output/plugins/AoOutputPlugin.cxx b/src/output/plugins/AoOutputPlugin.cxx index 0e815c1ed..df09af9f8 100644 --- a/src/output/plugins/AoOutputPlugin.cxx +++ b/src/output/plugins/AoOutputPlugin.cxx @@ -182,23 +182,6 @@ ao_output_open(AudioOutput *ao, AudioFormat &audio_format) throw MakeAoError(); } -/** - * For whatever reason, libao wants a non-const pointer. Let's hope - * it does not write to the buffer, and use the union deconst hack to - * work around this API misdesign. - */ -static int ao_play_deconst(ao_device *device, const void *output_samples, - uint_32 num_bytes) -{ - union { - const void *in; - char *out; - } u; - - u.in = output_samples; - return ao_play(device, u.out, num_bytes); -} - static size_t ao_output_play(AudioOutput *ao, const void *chunk, size_t size) { @@ -207,7 +190,12 @@ ao_output_play(AudioOutput *ao, const void *chunk, size_t size) if (size > ad->write_size) size = ad->write_size; - if (ao_play_deconst(ad->device, chunk, size) == 0) + /* For whatever reason, libao wants a non-const pointer. + Let's hope it does not write to the buffer, and use the + union deconst hack to * work around this API misdesign. */ + char *data = const_cast((const char *)chunk); + + if (ao_play(ad->device, data, size) == 0) throw MakeAoError(); return size;