Receiving kAUGraphErr_CannotDoInCurrentContext when calling AUGraphStart for playback
IosAudiounitAudiotoolboxIos Problem Overview
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?
Ios Solutions
Solution 1 - Ios
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...