I am using a render callback to send PCM data to the audio hardware, it is
installed
like this:
callback.inputProc = MixerInputCallback;
callback.inputProcRefCon = ci;
AudioUnitSetProperty(mixerAudioUnit,
kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &callback,
sizeof(AURenderCallbackStruct));
My MixerInputCallback() then looks like this:
static OSStatus MixerInputCallback(void *inRefCon,
AudioUnitRenderActionFlags *inActionFlags, const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber, UInt32 inNumFrames, AudioBufferList *ioData)
{
struct channelinfo *ci = (struct channelinfo *) inRefCon;
AudioConverterFillComplexBuffer(ci->converter,
ACComplexInputProc, inRefCon, &inNumFrames, ioData, NULL);
return noErr;
}
Now how can I safely dispose of the audio converter object accessed in
MixerInputCallback()?
i.e. I need to make sure that the converter isn't accessed while I'm trying to
kill it.
AFAIU I'm not allowed to use any form of mutex protection inside
MixerInputCallback()
because it's running on the audio I/O proc and mustn't block.
So how can I make sure that it is safe to kill the audio converter? I've tried
to kill the render
callback first, like so:
callback.inputProc = NULL;
callback.inputProcRefCon = NULL;
AudioUnitSetProperty(mixerAudioUnit,
kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &callback,
sizeof(AURenderCallbackStruct));
And then kill the audio convert using
AudioConverterDispose(ci->converter);
But it doesn't work. Running a stress test with such code often leads to memory
access faults
when disposing of the converter.
So how can I make sure that the audio converter is no longer in use when
calling AudioConverterDispose()?
I'd somehow need to find a way to wait for the completion of
MixerInputCallback() while at the same
time forbidding Core Audio to run MixerInputCallback() again. I don't think
this is as easy as setting
a flag because multithreading is involved and MixerInputCallback() runs on the
audio I/O proc.
So how can I do this? How can I safely stop my MixerInputCallback() so that I
can safely dispose of
the audio converter accessed by MixerInputCallback()?
--
Best regards,
Andreas Falkenhahn mailto:[email protected]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/coreaudio-api/archive%40mail-archive.com
This email sent to [email protected]