Removing AEAudioUnitChannels and getting error -10861
I am getting the following error when I attempt to remove too many channels at once:
AEAudioController.m:1035: Update graph result -10861
My app creates and plays AEAudioUnitChannels on-demand, using local media files played thru the Audio Unit component kAudioUnitSubType_AudioFilePlayer.
I call AudioFileOpenURL() ahead of time in a prepareToPlay method, and when the play method is called, I set channelIsPlaying to YES, configure the kAudioUnitProperty_ScheduledFileRegion on the audio unit, and add the render callback using AudioUnitAddRenderNotify().
Upon stopping, I set channelIsPlaying to NO, call AudioUnitRemoveRenderNotify() followed by AudioUnitReset() before attempting to removeChannels: on the AEAudioController.
In the simulator, I can play and stop 5 audio files simultaneously without problem. But if I play 6 at once, I get the -10861 error after the last file stops. Once that error appears, the AEAudioController is horked and will not play any more audio until it is destroyed and a new one reinitialized.
This makes me think that the asynchronous calls inside so many removeChannels: calls are taking too long to complete, and maybe are causing the main Audio Unit render loop to screw up and fail somehow.
The only thing that "works" is not removing the channels after they finish playing. But then I'm faced with a 100 channel limit (as enforced by kMaximumChannelsPerGroup), and I can't afford to arbitrarily limit my users to only 100 items.
Should I be waiting until some proper moment to ask the Audio Controller to remove the channels, or should I queue the channels for removal at a more opportune time? I have tried not reusing the same channel objects, tried calling removeChannels: on the render loop thread (took too long), tried AEAudioControllerSendAsynchronousMessageToMainThread(). Nothing worked.
Anyone having this same issue? I assume it's an implementation issue on my end -- but I really could use some ideas about how to fix it.