Re: Device gone away notification?
Re: Device gone away notification?
- Subject: Re: Device gone away notification?
- From: Jeff Moore <email@hidden>
- Date: Tue, 8 Sep 2009 12:18:01 -0700
The device list, kAudioHardwarePropertyDevices, is a property of the
HAL's System Object. The HAL fires a notification off for this
property whenever there is a change (be it an addition, a subtraction
or some combination) to the device list.
To watch for the appearance of a particular device, you would add a
listener to the System Object for kAudioHardwarePropertyDevices. Then
the listener fires, you would get the current list of devices, iterate
through it and query each device until you find the one you are
looking for or run out of devices.
Note that you will need to use the HAL directly to do this since AUHAL
doesn't proxy System Object properties.
On Sep 8, 2009, at 12:06 PM, Ethan Funk wrote:
It sounds like kAudioDevicePropertyDeviceIsAlive is what I am after.
Then to go full circle with this, can I get notification from the
system, probably at the HAL level some place, when a device becomes
available from the system, or the device list changes? If so, I can
code things so that the output nicely goes away when the device is
removed using kAudioDevicePropertyDeviceIsAlive, and if a device
come online while my program is running, it can check to see if it
is a device it wants to use and set it back up again.
Thanks,
Ethan...
On Sep 8, 2009, at 11:50 AM, Jeff Moore wrote:
On Sep 8, 2009, at 10:27 AM, Ethan Funk wrote:
I am using kAudioUnitSubType_HALOutput. I was expecting my I/O
Proc would just stop getting called, which would be fine, but
instead, the device seems to get re-directed to the system default
device.
I'm pretty sure that this has been the default behavior of AUHAL. I
don't believe that there is a way to get AUHAL to just stop when
the device it is using goes away. It would probably be worth filing
a feature request about it.
I will have a look at some of the notifications mention and see
which fits best.
AUHAL will send a notification for
kAudioOutputUnitProperty_CurrentDevice on the global scope when it
changes the device it is using. You can use this as an opportunity
to stop IO or tell the instance of AUHAL to use a different device.
If you want to know when the AudioDevice you are using has been
removed from the system, you would listen for notifications on the
property, kAudioDevicePropertyDeviceIsAlive. The HAL fires this off
just prior to tearing things down.
If you want to know when the AudioDevice you are using stops IO,
you would listen to kAudioDevicePropertyDeviceIsRunning. The HAL
fires this off just prior to entering and just after leaving the IO
thread's work loop.
Remember that AUHAL proxies notifications from the HAL to make
listening to HAL property changes much simpler.
I assume the notifications will come in on a realtime thread, so I
will need to make sure the handler does not block, correct?
Only kAudioDevicePropertyDeviceIsRunning comes from the IO thread,
but it happens at a relatively safe time - either before the HAL
starts tracking time or after it is finished. The others will come
on less critical thread contexts - usually the HAL's notification
thread. Consequently, you can feel safe to block in the listener
for any of these properties.
On Sep 8, 2009, at 10:13 AM, Stephen Davis wrote:
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.
--
Jeff Moore
Core Audio
Apple
_______________________________________________
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
--
Jeff Moore
Core Audio
Apple
_______________________________________________
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