iPhone CoreAudio hang when stopping
I have an iPhone app that is recording audio and then broadcasting it across the network. In response to a "stop" from the far end it queues a notification to stop the recording. Alas when it gets to the AudioQueueStop call the application just hangs (ie Stop never exits). Thanks to the notification all AudioQueue manipulation is happening on the same thread.
Has anyone got any idea whats going on here?
Edit: I have set up a listener in the UI thread that handles the recorder.
Then from my network thread I use a "postNotificationName" beliving that it was post a message to the UI thread and everything would run from that thread. This does not appear to be the case. When I break point the function that is ca开发者_如何学JAVAlled by the postNotificationName it appears that the call is being made on the networking thread and NOT on the UI Thread.
I assume this is my error. Anyone know how to make it work by notifying the UIThread to handle it?
Edit2: OK I've re-written it to use performSelectorOnMainThread. And it still crashes.
On the plus side I just learnt how to get a lot more info out of XCode so I can see the call stack goes:
semaphore_timedwait_signal_trap
semaphore_timedwait_signal _pthread_cond_wait pthread_cond_timedwait_relative_np CAGuard::WaitFor ClientAudioQueue::ServicePendingCallbacks AudioQueueStop [etc]Anyone got any ideas why it hangs?
How do you call AudioQueueStop ? The function supports two modes: synchronous and asynchronous.
The preferred way is to use the asynchronous stopping as the function will return immediately, while the remaining buffers will be played/recorded.
If you want to go synchronous and you get a hang, then maybe there is a dead-lock or a race condition somewhere. Have you tried to pause the application under the debugger and check the threads' stack-frames to see where the problem is ?
精彩评论