Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
GUI Apps should set kAudioHardwarePropertyRunLoop in the HAL
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

GUI Apps should set kAudioHardwarePropertyRunLoop in the HAL



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.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.