`// PCM -> AAC AudioBufferList* convertPCMToAAC (XDXRecorder *recoder) {
UInt32 maxPacketSize = 0;
UInt32 size = sizeof(maxPacketSize);
OSStatus status;
status = AudioConverterGetProperty(_encodeConvertRef,
kAudioConverterPropertyMaximumOutputPacketSize,
&size,
&maxPacketSize);
// log4cplus_info("AudioConverter","kAudioConverterPropertyMaximumOutputPacketSize status:%d \n",(int)status);
AudioBufferList *bufferList = (AudioBufferList *)malloc(sizeof(AudioBufferList));
bufferList->mNumberBuffers = 1;
bufferList->mBuffers[0].mNumberChannels = _targetDes.mChannelsPerFrame;
bufferList->mBuffers[0].mData = malloc(maxPacketSize);
bufferList->mBuffers[0].mDataByteSize = kTVURecoderPCMMaxBuffSize;
AudioStreamPacketDescription outputPacketDescriptions;
UInt32 inNumPackets = 1;
pthread_mutex_lock(&pcmBufferMutex);
status = AudioConverterFillComplexBuffer(_encodeConvertRef,
encodeConverterComplexInputDataProc,
pcm_buffer,
&inNumPackets,
bufferList,
&outputPacketDescriptions);
pthread_mutex_unlock(&pcmBufferMutex);
if(status != noErr){
// log4cplus_debug("Audio Recoder","set AudioConverterFillComplexBuffer status:%d inNumPackets:%d \n",(int)status, inNumPackets);
free(bufferList->mBuffers[0].mData);
free(bufferList);
return NULL;
}
if (recoder.needsVoiceDemo) {
OSStatus status = AudioFileWritePackets(recoder.mRecordFile,
FALSE,
bufferList->mBuffers[0].mDataByteSize,
&outputPacketDescriptions,
recoder.mRecordPacket,
&inNumPackets,
bufferList->mBuffers[0].mData);
// log4cplus_info("write file","write file status = %d",(int)status);
if (status == noErr) {
recoder.mRecordPacket += inNumPackets;
}
}
return bufferList;
} `
The above code for converting PCM to AAC works normally in iOS versions below 18, but in iOS 18, crashes occur during the conversion process. The console does not provide much useful information, and the application crashes at malloc(maxPacketSize) or AudioConverterFillComplexBuffer(), displaying the message AURemoteIO::IOThread (14): EXC_BAD_ACCESS (code=1, address=0x0). Please help identify the cause of the crash.