Receiving kAUGraphErr_CannotDoInCurrentContext when calling AUGraphStart for playback

試著忘記壹切 提交于 2019-12-20 15:37:23

问题


I'm working with AUGraph and Audio Units API to playback and record audio in my iOS app. Now I have a rare issue when an AUGraph is unable to start with the following error:

result = kAUGraphErr_CannotDoInCurrentContext (-10863)

The error occurred unpredictably when we try to call AUGraphStart which is set up for audio playback:

(BOOL)startRendering
{
    if (playing) {
        return YES;
    }

    playing = YES;

    if (NO == [self setupAudioForGraph:&au_play_graph playout:YES]) {
        print_error("Failed to create play AUGraph",0);
        playing = NO;
        return NO;
    }

    //result = kAUGraphErr_CannotDoInCurrentContext (-10863)
    OSStatus result = AUGraphStart(au_play_graph);
    if (noErr != result) {
        print_error("AUGraphStart", result);
        playing = NO;
    }

    return playing;
}

Here what we get from the documentation:

To avoid spinning or waiting in the render thread (a bad idea!), many of the calls to AUGraph can return: kAUGraphErr_CannotDoInCurrentContext. This result is only generated when you call an AUGraph API from its render callback. It means that the lock that it required was held at that time, by another thread. If you see this result code, you can generally attempt the action again - typically the NEXT render cycle (so in the meantime the lock can be cleared), or you can delegate that call to another thread in your app. You should not spin or put-to-sleep the render thread.

This result code is only a transitory state, which will pass as soon as your other thread's call to AUGraph (that has the lock) completes.

In my case, I just start the AUGraph, it's new and just created. How can I debug the case and what could be the potential issue here?


回答1:


You can make something out of CSS or SQLite. This is why

OSStatus result = AUGraphStart(au_play_graph);
if (noErr != result) {
    print_error("AUGraphStart", result);
    playing = NO;
}

return playing;

}

Try to just manipulate this code, there is a problem with Booleans in your code...



来源:https://stackoverflow.com/questions/30224371/receiving-kaugrapherr-cannotdoincurrentcontext-when-calling-augraphstart-for-pla

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!