Core Audio Output: Add a check that should prevent it from attempting to output data through the callback during or after destruction

CQTexperiment
Christopher Snowhill 2021-09-17 19:09:34 -07:00
parent 91473a11e9
commit da96d2c21e
2 changed files with 11 additions and 0 deletions

View File

@ -17,6 +17,8 @@
@interface OutputCoreAudio : NSObject {
OutputNode * outputController;
BOOL stopping;
AudioDeviceID outputDeviceID;
AudioUnit outputUnit;

View File

@ -34,6 +34,13 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
void *readPointer = ioData->mBuffers[0].mData;
int amountToRead, amountRead;
if (output->stopping == YES)
{
// *shrug* At least this will stop it from trying to emit data post-shutdown
ioData->mBuffers[0].mDataByteSize = 0;
return eofErr;
}
if ([output->outputController shouldContinue] == NO)
{
@ -384,6 +391,7 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
size);
//setup render callbacks
stopping = NO;
renderCallback.inputProc = Sound_Renderer;
renderCallback.inputProcRefCon = (__bridge void * _Nullable)(self);
@ -413,6 +421,7 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
{
if (outputUnit)
{
stopping = YES;
AudioOutputUnitStop(outputUnit);
AudioUnitUninitialize (outputUnit);
AudioComponentInstanceDispose(outputUnit);