CoreAudio: error/crash if device for a running stream is removed/unplugged
Rob Watson writes:
> In CoreAudio, if a device which is being read from is suddenly removed/unplugged, then PortAudio repeatedly loops while printing an error:
>
> Error on line 2134: err='-10863', msg=Audio Unit: cannot do in current context
>
> and then usually crashes. I can see that this is the call to AudioUnitRender in pa_mac_core.c.
> I'm testing with a simple line in from a Maya 44 USB 4in/4out.
I haven't changed any [pa_mac_core.h stream modes], just the default
Ross says:
> I think there are a cluster of related issues in PA/CoreAudio that cause this kind of behavior when "things change" (sample rates, headphone disconnect, and now, apparently device disconnect).
( This is related to #102 )
> a quick hack fix is to check for this error code and return from the IOProc -- that should hopefully prevent the crash (and certainly the error message).
>
> A better fix is to have a notification listener that gets all the necessary changes and does something to reset the AudioUnits.
>
> getting a notification to your app that the device has been unplugged is the subject of some development. In the short term you may need to look for a way to get a notification outside the scope of PortAudio... but fixing the crash I think should be a priority (I can look into it if Bjorn doesn't have time).
> In CoreAudio, if a device which is being read from is suddenly removed/unplugged, then PortAudio repeatedly loops while printing an error:
>
> Error on line 2134: err='-10863', msg=Audio Unit: cannot do in current context
>
> and then usually crashes. I can see that this is the call to AudioUnitRender in pa_mac_core.c.
> I'm testing with a simple line in from a Maya 44 USB 4in/4out.
I haven't changed any [pa_mac_core.h stream modes], just the default
Ross says:
> I think there are a cluster of related issues in PA/CoreAudio that cause this kind of behavior when "things change" (sample rates, headphone disconnect, and now, apparently device disconnect).
( This is related to #102 )
> a quick hack fix is to check for this error code and return from the IOProc -- that should hopefully prevent the crash (and certainly the error message).
>
> A better fix is to have a notification listener that gets all the necessary changes and does something to reset the AudioUnits.
>
> getting a notification to your app that the device has been unplugged is the subject of some development. In the short term you may need to look for a way to get a notification outside the scope of PortAudio... but fixing the crash I think should be a priority (I can look into it if Bjorn doesn't have time).
Leave a comment
on 2016-05-01 18:20 *
By philburk
Status changed from New to Test
Total invested hours changed from 0.0 to 3.0
I was able to reproduce this using AudioInput from a USB device.
A possible fix is under review here:
https://www.assembla.com/spaces/portaudio/git/merge_requests/3218623
A possible fix is under review here:
https://www.assembla.com/spaces/portaudio/git/merge_requests/3218623