Crashes with 1.4.8 Measurement Mode changes?

Since updating to 1.4.8, I've seen the following crash happen quite a few times although I haven't yet figured out how to re-create it on demand, I'm just working on the traces. So over on the main thread, we're waiting for a synchronous block---that's running in response to an audioRouteChangeNotification---to report as finished:

Thread : com.apple.main-thread
0  libsystem_kernel.dylib         0x0000000196d9f570 __semwait_signal + 8
1  libsystem_c.dylib              0x0000000196cc18a8 nanosleep + 216
2  Foundation                     0x0000000185a6d2a0 +[NSThread sleepForTimeInterval:] + 148
3  TestApp                        0x00000001001997d4 -[AEAudioController performSynchronousMessageExchangeWithBlock:] (AEAudioController.m:1758)
4  TestApp                        0x00000001001a1040 -[AEAudioController updateInputDeviceStatus] (AEAudioController.m:3073)
5  TestApp                        0x000000010019cf5c __50-[AEAudioController audioRouteChangeNotification:]_block_invoke (AEAudioController.m:2446)

12 GraphicsServices               0x000000018e36f6fc GSEventRunModal + 168
13 UIKit                          0x000000018964ed94 UIApplicationMain + 1488
14 TestApp                        0x0000000100071cf4 main (main.m:16)
15 libdyld.dylib                  0x0000000196c86a08 start + 4

The block being performed happens to look like this:

        _numberOfInputChannels    = numberOfInputChannels;
        _rawInputAudioDescription = rawAudioDescription;
        _inputAudioBufferList     = inputAudioBufferList;
        _inputAudioScratchBufferList = inputAudioScratchBufferList;
        _inputAudioFloatConverter = inputAudioFloatConverter;
        _audioInputAvailable      = inputAvailable;
        _hardwareInputAvailable   = hardwareInputAvailable;
        _inputCallbacks           = inputCallbacks;
        _inputCallbackCount       = inputCallbackCount;
        _usingAudiobusInput       = usingAudiobus;
        _inputLevelMonitorData    = inputLevelMonitorData;

Over on the AURemoteIO thread, the following crash happens:

Thread : Crashed: AURemoteIO::IOThread
0  libsystem_kernel.dylib         0x0000000196d9f270 __pthread_kill + 8
1  libsystem_pthread.dylib        0x0000000196e3d160 pthread_kill + 112
2  libsystem_c.dylib              0x0000000196d16aa0 abort + 112
3  libsystem_c.dylib              0x0000000196ceb9c4 basename + 90
4  TestApp                        0x00000001001af138 AEFloatConverterFromFloat (AEFloatConverter.m:173)
5  TestApp                        0x00000001001a7848 serviceAudioInput (AEAudioController.m:659)
6  TestApp                        0x000000010019e0b8 topRenderNotifyCallback (AEAudioController.m:574)
7  AudioToolbox                   0x0000000184145788 AUBase::DoRender(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int, AudioBufferList&) + 560
8  AudioToolbox                   0x000000018416f368 AUMethodRender(void*, unsigned int*, AudioTimeStamp const*, unsigned int, unsigned int, AudioBufferList*) + 44
9  TestApp                        0x00000001001a72d0 channelAudioProducer (AEAudioController.m:382)
10 TestApp                        0x00000001001a43bc renderCallback (AEAudioController.m:431)
11 AudioToolbox                   0x000000018414a29c AUInputElement::PullInput(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int) + 176
12 AudioToolbox                   0x000000018413f010 AUInputFormatConverter2::InputProc(OpaqueAudioConverter*, unsigned int*, AudioBufferList*, AudioStreamPacketDescription**, void*) + 216
13 AudioToolbox                   0x000000018409c3b0 AudioConverterChain::CallInputProc(unsigned int) + 340
14 AudioToolbox                   0x000000018409c090 AudioConverterChain::FillBufferFromInputProc(unsigned int*, CABufferList*) + 148
15 AudioToolbox                   0x000000018407d748 BufferedAudioConverter::GetInputBytes(unsigned int, unsigned int&, CABufferList const*&) + 180
16 AudioToolbox                   0x0000000184073230 CBRConverter::RenderOutput(CABufferList*, unsigned int, unsigned int&, AudioStreamPacketDescription*) + 112
17 AudioToolbox                   0x000000018407d5c4 BufferedAudioConverter::FillBuffer(unsigned int&, AudioBufferList&, AudioStreamPacketDescription*) + 404
18 AudioToolbox                   0x000000018409be5c AudioConverterChain::RenderOutput(CABufferList*, unsigned int, unsigned int&, AudioStreamPacketDescription*) + 116
19 AudioToolbox                   0x000000018407d5c4 BufferedAudioConverter::FillBuffer(unsigned int&, AudioBufferList&, AudioStreamPacketDescription*) + 404
20 AudioToolbox                   0x000000018405d064 AudioConverterFillComplexBuffer + 352
21 AudioToolbox                   0x000000018413eebc AUInputFormatConverter2::PullAndConvertInput(AudioTimeStamp const&, unsigned int&, AudioBufferList&, AudioStreamPacketDescription*, bool&) + 120
22 AudioToolbox                   0x000000018413e940 AUConverterBase::RenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int) + 264
23 AudioToolbox                   0x0000000184146ed8 AUBase::DoRenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, AUOutputElement*, unsigned int, AudioBufferList&) + 216
24 AudioToolbox                   0x00000001841457b0 AUBase::DoRender(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int, AudioBufferList&) + 600
25 AudioToolbox                   0x0000000184133038 AURemoteIO::PerformIO(unsigned int, unsigned int, unsigned int, AudioTimeStamp const&, AudioTimeStamp const&, AudioBufferList const*, AudioBufferList*, int&) + 444
26 AudioToolbox                   0x0000000184133f10 AURIOCallbackReceiver_PerformIO + 360
27 AudioToolbox                   0x000000018412c280 _XPerformIO + 108
28 AudioToolbox                   0x00000001840698a8 mshMIGPerform + 252
29 AudioToolbox                   0x00000001841022a4 MSHMIGDispatchMessage + 36
30 AudioToolbox                   0x00000001841333c8 AURemoteIO::IOThread::Run() + 140

35 libsystem_pthread.dylib        0x0000000196e38ee8 thread_start + 4

AEAudioController.m:659 happens to be in the middle of this code

        if ( THIS->_recordingThroughDeviceMicrophone && THIS->_useMeasurementMode && THIS->_boostBuiltInMicGainInMeasurementMode && THIS->_inputAudioFloatConverter ) {
            // Boost input volume
====>       AEFloatConverterToFloatBufferList(THIS->_inputAudioFloatConverter, THIS->_inputAudioBufferList, THIS->_inputAudioScratchBufferList, inNumberFrames);
            for ( int i=0; i_inputAudioScratchBufferList->mNumberBuffers; i++ ) {
                vDSP_vsmul(THIS->_inputAudioScratchBufferList->mBuffers[i].mData, 1, &kBoostForBuiltInMicInMeasurementMode, THIS->_inputAudioScratchBufferList->mBuffers[i].mData, 1, inNumberFrames);
            }
            AEFloatConverterFromFloatBufferList(THIS->_inputAudioFloatConverter, THIS->_inputAudioScratchBufferList, THIS->_inputAudioBufferList, inNumberFrames);
        }

Confusingly, AEFloatConverter.m:173 is a function definition

BOOL AEFloatConverterFromFloat(__unsafe_unretained AEFloatConverter* THIS, float * const * sourceBuffers, AudioBufferList *targetBuffer, UInt32 frames) {

However, right above that is the definition for AEFloatConverterToFloatBufferList i.e. the function called from 659 of AEAudioController, so it seems like we're in the right place.

Could it be that somehow bunch of assignments on the main thread is causing problems AEFloatConverterToFloatBufferList? Or is that a red herring?

I'd welcome any suggestions for debugging or fixing :)

In the meantime I shall keep prodding and trying to re-create the issue.

Thanks!

Comments

  • edited August 2015

    @EdSharp, My crash experience with upgrading to 1.4.8, was that I had to update the effects blocks and change inputEnabled to YES. Please check out this thread, if you haven't seen it, already:

    http://forum.theamazingaudioengine.com/discussion/comment/1832/#Comment_1832

  • @markjeschke Thanks for the suggestion. I checked that thread out and I have done the initialiser conversions and on the whole the app works well. I'd say what I'm experiencing is perhaps a race condition between the main thread and the core audio thread. Frustratingly I've not yet re-created it on demand, but I have quite a few examples of it having happened.

    I've tried to force audio change notification by plugging and unplugging headphones and making phone calls to the device. I'd originally thought maybe it was related to Audiobus route changes, too, although having then read that the whole of the block around AEAudioController.m:659 is conditional on !useAudiobusReceiverPort, it made me think it was less likely to do with Audiobus route changes. That said, it could still be related to the transition from being Audiobus connected to disconnecting or vice versa. However, I tried moving between those states and also couldn't reproduce the bug.

  • edited September 2015

    Sorry about the delay, guys. I think this commit should address the problem. It was related to a race condition that can occur when the number of input channels changes.

Sign In or Register to comment.