From d427b4fd1cadcd4b7be9267ad1ea0af0bfa1cbb4 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 17 Jun 2013 23:03:19 +0200 Subject: ao_coreaudio: simplify render callback Read only the requested amount by the AUHAL (instead of all the buffered data). No idea what the deal is with pausing the audio units if there is no audio to play, maybe to avoid underruns of some sort. Anyway from my tests this condition never occurred so I'm removing it all. --- audio/out/ao_coreaudio.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) (limited to 'audio') diff --git a/audio/out/ao_coreaudio.c b/audio/out/ao_coreaudio.c index 38c7c7fc29..67cba53d66 100644 --- a/audio/out/ao_coreaudio.c +++ b/audio/out/ao_coreaudio.c @@ -100,30 +100,16 @@ static int get_ring_size(struct ao *ao) ao->format, 0.5, ao->channels.num, ao->samplerate); } -static OSStatus theRenderProc(void *inRefCon, - AudioUnitRenderActionFlags *inActionFlags, - const AudioTimeStamp *inTimeStamp, - UInt32 inBusNumber, UInt32 inNumFrames, - AudioBufferList *ioData) +static OSStatus render_cb_lpcm(void *ctx, AudioUnitRenderActionFlags *aflags, + const AudioTimeStamp *ts, UInt32 bus, + UInt32 frames, AudioBufferList *buffer_list) { - struct ao *ao = inRefCon; - struct priv *p = ao->priv; - - int buffered = mp_ring_buffered(p->buffer); - int requested = inNumFrames * p->packetSize; - - if (buffered > requested) - buffered = requested; - - if (buffered) { - mp_ring_read(p->buffer, - (unsigned char *)ioData->mBuffers[0].mData, - buffered); - } else { - audio_pause(ao); - } + struct ao *ao = ctx; + struct priv *p = ao->priv; + int requested = frames * p->packetSize; + AudioBuffer buf = buffer_list->mBuffers[0]; - ioData->mBuffers[0].mDataByteSize = buffered; + buf.mDataByteSize = mp_ring_read(p->buffer, buf.mData, requested); return noErr; } @@ -630,7 +616,7 @@ static int init(struct ao *ao, char *params) print_buffer(p->buffer); - renderCallback.inputProc = theRenderProc; + renderCallback.inputProc = render_cb_lpcm; renderCallback.inputProcRefCon = ao; err = AudioUnitSetProperty(p->theOutputUnit, kAudioUnitProperty_SetRenderCallback, -- cgit v1.2.3