2016-11-14 211 views
4

我有一个音频节目,使得以AudioConverterFillComplexBuffer调用下面的代码:电话AudioConverterFillComplexBuffer结果CrashIfClientProvidedBogusAudioBufferList仅在MacOS塞拉利昂

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

当这个代码在10.6-10.11运行时,它工作正常。当代码在10.12运行时,它用下面的消息

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] 

调用栈中CrashIfClientProvidedBogusAudioBufferList结束崩溃。

大多数文章,文档和邮件列表会说我有一个糟糕的输出缓冲区,但对于我的生活,我不能告诉我会做什么错,但仍然有我的代码在所有版本的MacOS上工作,但最新。这里是我如何建立缓冲区:

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); 

这里是在崩溃点的全栈

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 

如果任何人有我如何调试这个问题的任何建议,我会非常感谢帮助。

+0

你能链接到一个小的项目,再现问题? –

+0

我正在努力创建一个。一旦完成,我会在这里上传。 –

+0

对不起,但我已经上传了一个示例项目http://www.desktopintercom.com/downloads/AudioUnitTest.zip。这个简单的程序将在10.11上运行,并在10.12上崩溃。 –

回答

2

MyAudioConverterCallbackioDataPacketCount应该返回帧为LPCM(我想包是未压缩的音频帧),所以将其设置为:

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

传递一个NULLAudioStreamPacketDescriptionAudioConverterFillComplexBuffer而不是数组的1(这在10.11导致我崩溃)。你的目标格式是LPCM,所以数据包描述是不必要的,因为你的“数据包”都是相同的大小。

同样,您的源格式也是LPCM,因此您可以删除返回MyAudioConverterCallback中数据包描述的代码 - 这也是错误的。

在我的机器上,我得到了非交错立体声streamFormat,这意味着MyAudioConverterCallback也必须填写ioData->mBuffers[1]

设置您的convertedDataAudioBufferList时,sizePerPacket正在使用源格式数据包大小而不是目标数据包大小。它应该是:

sizePerPacket = mOutputFormat.mBytesPerPacket; 

最后,即使它没有崩溃,此代码不能因为你录音(比方说)从麦克风512帧,然后要求音频转换器转换成16384是正确的 - 这会给你音频故障。

+0

我正在通过您的更改工作,但我仍然遇到了崩溃。我不知道你是否理解了你提出的有关提交iodate-> mBuffers [0]的评论,因为它看起来像我在MyAudioConverterCallback中的第27行和第28行填写: ioData-> mBuffers [0] .mNumberChannels = 1; ioData-> mBuffers [0] .mDataByteSize = recorderObj-> inputBuffer-> mBuffers [0]。mDataByteSize; 至于你最近的评论,我一直在玩弄这些数字,试图让这个工作。 –

+0

对不起,有一个错字 - 我的意思是我有两个缓冲区。你应该检查你是否也是。 –

+0

当我打印ioData-> mBuffers我得到以下输出 (AudioBuffer [1])$ ​​0 = { [0] =(mNumberChannels = 1,mDataByteSize = 0,MDATA = 0x0000000000000000)} 如果我在阅读本正确地说,我只处理一个缓冲区。 –