I am developing a macOS application that captures audio through an AUHAL input AudioUnit.
The application registers an input callback using kAudioOutputUnitProperty_SetInputCallback. The callback receives an application-owned context through inputProcRefCon and obtains input audio using AudioUnitRender.
The intended shutdown sequence is:
- Close application-level callback admission.
- Call
AudioOutputUnitStop. - Remove the callback using
AudioUnitSetPropertywith a zero-initializedAURenderCallbackStruct. - Wait for callbacks already entered by the application to finish.
- Call
AudioUnitUninitializeandAudioComponentInstanceDispose. - Release the application-owned callback context.
We use an atomic active-callback counter, covering all context accesses made by callbacks that have entered the counted region.
However, this counter cannot account for a callback that Core Audio may have already dispatched but that has not yet executed its first instruction.
My question:
Is there a supported AUHAL teardown sequence that guarantees no previously scheduled, dispatched, or executing input callback can subsequently access inputProcRefCon?
Specifically, does successful return from AudioOutputUnitStop, callback removal, AudioUnitUninitialize, or AudioComponentInstanceDispose provide such a guarantee?
Is passing an AURenderCallbackStruct with both fields set to NULL a supported way to remove the input callback, and does removal have any documented completion semantics?
If none of these operations provides the required guarantee independently, what is the recommended lifetime-management pattern for safely releasing the application-owned callback context?
I have prepared a small standalone AUHAL test project that compiles the relevant Core Audio operations and passes deterministic offline lifecycle tests. Physical AUHAL activation and native callback teardown have not yet been executed, so I am not claiming a reproduced crash or verified native behavior.
I am primarily seeking clarification of the supported Core Audio API contract, rather than a diagnosis of an observed crash.
Thank you.