Re: GUI Apps should set kAudioHardwarePropertyRunLoop in the HAL
Re: GUI Apps should set kAudioHardwarePropertyRunLoop in the HAL
- Subject: Re: GUI Apps should set kAudioHardwarePropertyRunLoop in the HAL
- From: Jeff Moore <email@hidden>
- Date: Sun, 8 Dec 2002 18:54:21 -0800
Any old thread will do. I use the main event thread in my apps. The
important thing is that the thread's run loop gets regular time to run.
On Saturday, December 7, 2002, at 05:26 PM, Herbie Robinson wrote:
What kind of thread should this be? [post the answer, didn't see much
point in porting the question]
The HAL needs a thread on which it can hang it's notification
handlers for the various messages it gets from the driver and from
other instances of itself in other processes.
kAudioHardwarePropertyRunLoop is used to point the HAL at the
CFRunLoop to use for this purpose. By default, the HAL creates it's
own thread for it's notifications. This is so that all processes,
even those without a GUI, can receive notifications.
Most GUI applciations have several threads on which they receive
notifications already, so the having the HAL's thread around is
wasteful. Here's what you should do: On the thread you want the HAL
to use for notifications (for most apps, this will be the main
thread), add the following two lines of code.
// tell the HAL to use the current thread as it's run loop
CFRunLoopRef theRunLoop = CFRunLoopGetCurrent();
AudioHardwareSetProperty(kAudioHardwarePropertyRunLoop,
sizeof(CFRunLoopRef), &theRunLoop);
The only notable exception is for Java apps as the Java VM does this
for you already. Otherwise, all apps should be setting this property.
For instance, in my own Cocoa apps, I put this code directly in the
main() just before I call NSApplicationMain().
--
Jeff Moore
Core Audio
Apple
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.