所以我正在使用cocos2dx新的AudioEngine,并且遇到了以下崩溃:https://github.com/cocos2d/cocos2d-x/issues/18948。
0 0x0000000184a5cea8 in CrashIfClientProvidedBogusAudioBufferList ()
1 0x000000018493f270 in AudioConverterConvertComplexBuffer ()
2 0x0000000184939460 in AUSpatialMixer::Render(unsigned int&, AudioTimeStamp const&, unsigned int) ()
3 0x0000000184a62a20 in AUBase::DoRenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, AUOutputElement*, unsigned int, AudioBufferList&) ()
4 0x0000000184a621ac in AUBase::DoRender(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int, AudioBufferList&) ()
5 0x0000000184a6b550 in AUMethodRender(void*, unsigned int*, AudioTimeStamp const*, unsigned int, unsigned int, AudioBufferList*) ()
6 0x0000000184a5d284 in AUInputElement::PullInput(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int) ()
7 0x00000001847e8e00 in AUInputFormatConverter2::InputProc(OpaqueAudioConverter*, unsigned int*, AudioBufferList*, AudioStreamPacketDescription**, void*) ()
8 0x000000018474fdd4 in AudioConverterChain::CallInputProc(unsigned int) ()
9 0x000000018474fa64 in AudioConverterChain::FillBufferFromInputProc(unsigned int*, CABufferList*) ()
10 0x000000018472be38 in BufferedAudioConverter::GetInputBytes(unsigned int, unsigned int&, CABufferList const*&) ()
11 0x00000001849906f8 in Resampler2Wrapper::RenderOutput(CABufferList*, unsigned int, unsigned int&) ()
12 0x0000000184752a7c in SampleRateConverter::RenderOutput(CABufferList*, unsigned int, unsigned int&, AudioStreamPacketDescription*) ()
13 0x000000018472bcc8 in BufferedAudioConverter::FillBuffer(unsigned int&, AudioBufferList&, AudioStreamPacketDescription*) ()
14 0x000000018474f65c in AudioConverterChain::RenderOutput(CABufferList*, unsigned int, unsigned int&, AudioStreamPacketDescription*) ()
15 0x000000018472bcc8 in BufferedAudioConverter::FillBuffer(unsigned int&, AudioBufferList&, AudioStreamPacketDescription*) ()
16 0x000000018493ec98 in AudioConverterFillComplexBuffer ()
17 0x00000001847e864c in AUConverterBase::RenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int) ()
18 0x00000001846cd07c in AURemoteIO::RenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int) ()
19 0x0000000184a62a20 in AUBase::DoRenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, AUOutputElement*, unsigned int, AudioBufferList&) ()
20 0x0000000184a621ac in AUBase::DoRender(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int, AudioBufferList&) ()
21 0x00000001846ccd28 in AURemoteIO::PerformIO(unsigned int, unsigned int, unsigned int, AudioTimeStamp const&, AudioTimeStamp const&, AudioBufferList const*, AudioBufferList*, int&) ()
22 0x00000001846ce1a0 in AURIOCallbackReceiver_PerformIO ()
23 0x0000000184860018 in _XPerformIO ()
24 0x0000000184a4a5ec in mshMIGPerform ()
25 0x0000000184a4a804 in MSHMIGDispatchMessage ()
26 0x00000001846cd4c0 in AURemoteIO::IOThread::Run() ()
27 0x00000001846d1a40 in AURemoteIO::IOThread::Entry(void*) ()
28 0x0000000184a52630 in CAPThread::Entry(CAPThread*) ()
29 0x00000001808c432c in _pthread_body ()
30 0x00000001808c41f8 in _pthread_start ()
31 0x00000001808c2c38 in thread_start ()
基本上,发生的是AudioEngine使用AlBufferDataStatic,将要读取的数据存储在char * pcmData缓冲区内(您可以在此处查看代码:https://github.com/cocos2d/cocos2d-x/tree/v3/cocos/audio/apple(主要是AudioCache.mm和AudioDecoder。毫米)),然后在AudioCache析构函数(从主线程调用)中释放pcmData缓冲区时,存在竞争条件,因为AURemoteIO正在轮询客户端数据(对我来说它在mp3中)将其转换为pcm进入自己的线程。
所以问题是:我们可以在释放的确切时刻停止现在使用此释放的pcmData缓冲区的AURemoteIO线程执行任何操作吗?