diff options
author | Max Kellermann <max@duempel.org> | 2008-04-12 04:15:52 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-04-12 04:15:52 +0000 |
commit | 01bf82289659b334a837062aef0c4814e26ed4fb (patch) | |
tree | 7f1bbd246e1925af986079fbe380822ccb452da1 /src/audioOutputs/audioOutput_ao.c | |
parent | a2380928dbc4d46c7bc3104df2dee47219db4b93 (diff) | |
download | mpd-01bf82289659b334a837062aef0c4814e26ed4fb.tar.gz mpd-01bf82289659b334a837062aef0c4814e26ed4fb.tar.xz mpd-01bf82289659b334a837062aef0c4814e26ed4fb.zip |
use size_t and constant pointer in ao plugins
The audio output plugins should get a constant pointer, because they
must not modify the buffer. Since the size is a non-negative buffer
size in bytes, we should change its type to size_t.
git-svn-id: https://svn.musicpd.org/mpd/trunk@7293 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/audioOutputs/audioOutput_ao.c')
-rw-r--r-- | src/audioOutputs/audioOutput_ao.c | 28 |
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); |