AudioUnitRender got error kAudioUnitErr_CannotDoInCurrentContext (-10863)

青春壹個敷衍的年華 提交于 2019-12-11 07:34:06

问题


I want to play the recorded audio directly to speaker when headset is plugged in an iOS device.

What I did is calling AudioUnitRender in AURenderCallback func so that the audio data is writed to AudioBuffer structure.

It works well if the "IO buffer duration" is not set or set to 0.020seconds. If the "IO buffer duration" is set to a small value (0.005 etc.) by calling setPreferredIOBufferDuration, AudioUnitRender() will return an error:

kAudioUnitErr_CannotDoInCurrentContext (-10863).

Any one can help to figure out why and how to resolve it please? Thanks


回答1:


The buffer is full so wait until a subsequent render pass or use a larger buffer.

This same error code is used by AudioToolbox, AudioUnit and AUGraph but only documented for AUGraph.

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 mean time 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.

https://developer.apple.com/reference/audiotoolbox/kaugrapherr_cannotdoincurrentcontext



来源:https://stackoverflow.com/questions/41824058/audiounitrender-got-error-kaudiouniterr-cannotdoincurrentcontext-10863

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