Calling in AudioConverterFillComplexBuffer results in CrashIfClientProvidedBogusAudioBufferList only on MacOS Sierra

I have a sound program that calls an AudioConverterFillComplexBuffer call with the following code:

OSStatus error = AudioConverterFillComplexBuffer(recorderObj->audioConverter,
                                                     MyAudioConverterCallback,
                                                     (__bridge void *)playerLocal,
                                                     &ioOutputDataPackets,
                                                     convertedData,
                                                     &streamDesc);

When this code runs 10.6-10.11, it works fine. When the code runs 10.12, it crashes with the following message

Crashed Thread:        16  com.apple.audio.IOThread.client

Exception Type:        EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes:       0x0000000000000001, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Illegal instruction: 4
Termination Reason:    Namespace SIGNAL, Code 0x4
Terminating Process:   exc handler [0]

The call column ends at CrashIfClientProvidedBogusAudioBufferList.

Most articles, documentation, and mailing lists say that I have a bad output buffer, but for the rest of my life I can't say what I would do wrong, but still the code works in all versions of MacOS, but the latter. This is how I configure the buffer:

AudioBufferList *convertedData = (AudioBufferList*)malloc(sizeof(AudioBufferList) * 2);

convertedData->mNumberBuffers = 1;
convertedData->mBuffers[0].mNumberChannels =  2;
convertedData->mBuffers[0].mDataByteSize = 64 * 1024;
convertedData->mBuffers[0].mData = (UInt8 *)malloc(sizeof(UInt8) * 64 * 1024);

Here is the full stack at the time of the crash

Thread 16 Crashed:: com.apple.audio.IOThread.client
0   com.apple.audio.toolbox.AudioToolbox    0x00007fff89b9a330 CADebuggerStop() + 4
1   com.apple.audio.toolbox.AudioToolbox    0x00007fff89a21e71 CrashIfClientProvidedBogusAudioBufferList + 97
2   com.apple.audio.toolbox.AudioToolbox    0x00007fff89a2f710 AudioConverterChain::CallInputProc(unsigned int) + 646
3   com.apple.audio.toolbox.AudioToolbox    0x00007fff89a2f386 AudioConverterChain::FillBufferFromInputProc(unsigned int*, CABufferList*) + 130
4   com.apple.audio.toolbox.AudioToolbox    0x00007fff89a2f2ee BufferedAudioConverter::GetInputBytes(unsigned int, unsigned int&, CABufferList const*&) + 178
5   com.apple.audio.toolbox.AudioToolbox    0x00007fff89a2f1b2 CBRConverter::RenderOutput(CABufferList*, unsigned int, unsigned int&, AudioStreamPacketDescription*) + 106
6   com.apple.audio.toolbox.AudioToolbox    0x00007fff89a2225d BufferedAudioConverter::FillBuffer(unsigned int&, AudioBufferList&, AudioStreamPacketDescription*) + 281
7   com.apple.audio.toolbox.AudioToolbox    0x00007fff89a2f2c3 BufferedAudioConverter::GetInputBytes(unsigned int, unsigned int&, CABufferList const*&) + 135
8   com.apple.audio.toolbox.AudioToolbox    0x00007fff89a9369b Resampler2Wrapper::RenderOutput(CABufferList*, unsigned int, unsigned int&) + 183
9   com.apple.audio.toolbox.AudioToolbox    0x00007fff89a2225d BufferedAudioConverter::FillBuffer(unsigned int&, AudioBufferList&, AudioStreamPacketDescription*) + 281
10  com.apple.audio.toolbox.AudioToolbox    0x00007fff89a2f2c3 BufferedAudioConverter::GetInputBytes(unsigned int, unsigned int&, CABufferList const*&) + 135
11  com.apple.audio.toolbox.AudioToolbox    0x00007fff89a2f1b2 CBRConverter::RenderOutput(CABufferList*, unsigned int, unsigned int&, AudioStreamPacketDescription*) + 106
12  com.apple.audio.toolbox.AudioToolbox    0x00007fff89a2225d BufferedAudioConverter::FillBuffer(unsigned int&, AudioBufferList&, AudioStreamPacketDescription*) + 281
13  com.apple.audio.toolbox.AudioToolbox    0x00007fff89a2253f AudioConverterChain::RenderOutput(CABufferList*, unsigned int, unsigned int&, AudioStreamPacketDescription*) + 99
14  com.apple.audio.toolbox.AudioToolbox    0x00007fff89a2225d BufferedAudioConverter::FillBuffer(unsigned int&, AudioBufferList&, AudioStreamPacketDescription*) + 281
15  com.apple.audio.toolbox.AudioToolbox    0x00007fff89a21d2f AudioConverterFillComplexBuffer + 282
16  com.pc-intercom.Intercom        0x0000000107a52803 0x107a4a000 + 34819
17  com.apple.audio.units.Components    0x000000010a38c97c AUHAL::AUIOProc(unsigned int, AudioTimeStamp const*, AudioBufferList const*, AudioTimeStamp const*, AudioBufferList*, AudioTimeStamp const*, void*) + 2324
18  com.apple.audio.CoreAudio       0x00007fff8a71f951 HALC_ProxyIOContext::IOWorkLoop() + 4369
19  com.apple.audio.CoreAudio       0x00007fff8a71e667 HALC_ProxyIOContext::IOThreadEntry(void*) + 131
20  com.apple.audio.CoreAudio       0x00007fff8a71e38b HALB_IOThread::Entry(void*) + 75
21  libsystem_pthread.dylib         0x0000000108134aab _pthread_body + 180
22  libsystem_pthread.dylib         0x00000001081349f7 _pthread_start + 286
23  libsystem_pthread.dylib         0x0000000108134221 thread_start + 13

- , , .

+4
1

MyAudioConverterCallback , ioDataPacketCount LPCM ( , ), :

*ioDataPacketCount = recorderObj->inputBuffer->mBuffers[0].mDataByteSize/recorderObj->streamFormat.mBytesPerFrame; 

NULL AudioStreamPacketDescription AudioConverterFillComplexBuffer 1 ( 10.11). - LPCM, , "" .

, LPCM, , MyAudioConverterCallback, .

streamFormat, , MyAudioConverterCallback ioData->mBuffers[1] .

convertedData AudioBufferList, sizePerPacket . :

sizePerPacket = mOutputFormat.mBytesPerPacket;

, , , , () 512 , 16384 - .

+2

Source: https://habr.com/ru/post/1660644/


All Articles