Re: Device gone away notification?
Re: Device gone away notification?
- Subject: Re: Device gone away notification?
- From: Stephen Davis <email@hidden>
- Date: Tue, 8 Sep 2009 10:13:06 -0700
On Sep 6, 2009, at 8:12 PM, Brian Willoughby wrote:
On Sep 6, 2009, at 12:55, Ethan Funk wrote:
I noticed the following behavior in the HAL output unit:
The units device is set to a USB audio device, everything is set up
and running with audio playing through the unit, then I pull the
USB plug. Suddenly, the audio starts playing through the system
sound device.
Are you using the HAL directly, via AudioDeviceAddIOProc(), or one
of the AudioUnit Output Units such as
kAudioUnitSubType_DefaultOutput, or kAudioUnitSubType_HALOutput?
Just wanted to make sure we're on the same page.
OK, that's a nifty trick, but what I really need is some sort of
notification so I can stop and tear down the audio unit. Is there
such a mechanism? What would be really nice is if the rendering
would stop until the device comes back, but that is a lot to ask.
You possibly want AudioDeviceAddPropertyListener() with
kAudioDevicePropertyDeviceIsAlive,
kAudioDevicePropertyDeviceHasChanged,
kAudioDevicePropertyDeviceIsRunning, or
kAudioDevicePropertyDeviceIsRunningSomewhere.
If you're using the AudioUnit Output Units instead of accessing the
HAL directly, then you would ask the AU for the Device via
kAudioOutputUnitProperty_CurrentDevice. If you're setting the unit
to a specific USB device elsewhere in your code, then you probably
already have the AudioDeviceID somewhere in a local variable. You
could also skip the device property listener from the paragraph
above and simply call AudioUnitAddPropertyListener() with
kAudioOutputUnitProperty_CurrentDevice,
kAudioOutputUnitProperty_IsRunning, or perhaps
kAudioOutputUnitProperty_EnableIO or kAudioOutputUnitProperty_HasIO.
If you are using kAudioUnitSubType_DefaultOutput, CoreAudio will track
the default device for you which sounds like the behavior you're
seeing. If you want to be tied to a particular device, you use
kAudioUnitSubType_HALOutput and tell it which device to use.
Off-hand, I'm not sure what happens when the device goes away but, in
the absence of any special handling by you, I suspect your I/O proc
will just stop getting called which is also what happens when somebody
else takes hog mode on the device you're using. I do not know if it
will come back but it should be pretty easy for you to find out. As
Brian said, you'll need to listen to notifications on that device to
find out when it goes away.
hth,
stephen
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden