aboutsummaryrefslogtreecommitdiffstats
path: root/src/audioOutputs/audioOutput_ao.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/audioOutputs/audioOutput_ao.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/audioOutputs/audioOutput_ao.c b/src/audioOutputs/audioOutput_ao.c
index e7f3dcd6b..c28415410 100644
--- a/src/audioOutputs/audioOutput_ao.c
+++ b/src/audioOutputs/audioOutput_ao.c
@@ -199,19 +199,37 @@ static int audioOutputAo_openDevice(AudioOutput * audioOutput)
return 0;
}
-static int audioOutputAo_play(AudioOutput * audioOutput, char *playChunk,
- int size)
+/**
+ * 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;
+ void *out;
+ } u;
+
+ u.in = output_samples;
+ return ao_play(device, u.out, num_bytes);
+}
+
+static int audioOutputAo_play(AudioOutput * audioOutput,
+ const char *playChunk, size_t size)
{
- int send;
+ size_t send;
AoData *ad = (AoData *) audioOutput->data;
if (ad->device == NULL)
return -1;
while (size > 0) {
- send = ad->writeSize > size ? size : ad->writeSize;
+ send = (size_t)ad->writeSize > size
+ ? size : (size_t)ad->writeSize;
- if (ao_play(ad->device, playChunk, send) == 0) {
+ if (ao_play_deconst(ad->device, playChunk, send) == 0) {
audioOutputAo_error();
ERROR("closing audio device due to write error\n");
audioOutputAo_closeDevice(audioOutput);