views:

73

answers:

1

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 called 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?

+1  A: 

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 ?

Laurent Etiemble
I AM doing it synchronously because i want it to end immediately. Please check my edit :)
Goz
Have you tried the "detachNewThreadSelector:toTarget:withObject:" method of NSThread instead of "performSelectorOnMainThread" ? The fact that the stop will called in a new thread will maybe solve the hang.
Laurent Etiemble
Actually on closer inspection you are COMPLETELY right there. My inter thread communication is holding a lock which stops the audio from getting sent across the network and since thats in the buffer filled callback I'm guessing it can't exit. I'll check this quickly now :)
Goz
Yup that was it! Damn I wish I'd checked that earlier. THANKS! :D
Goz