1 /*
2  * Copyright © 2016 Mozilla Foundation
3  *
4  * This program is made available under an ISC-style license.  See the
5  * accompanying file LICENSE for details.
6  */
7 
8 #include <cubeb/cubeb.h>
9 #include "cubeb_osx_run_loop.h"
10 #include "cubeb_log.h"
11 #include <AudioUnit/AudioUnit.h>
12 #include <CoreAudio/AudioHardware.h>
13 #include <CoreAudio/HostTime.h>
14 #include <CoreFoundation/CoreFoundation.h>
15 
cubeb_set_coreaudio_notification_runloop()16 void cubeb_set_coreaudio_notification_runloop()
17 {
18   /* This is needed so that AudioUnit listeners get called on this thread, and
19    * not the main thread. If we don't do that, they are not called, or a crash
20    * occur, depending on the OSX version. */
21   AudioObjectPropertyAddress runloop_address = {
22     kAudioHardwarePropertyRunLoop,
23     kAudioObjectPropertyScopeGlobal,
24     kAudioObjectPropertyElementMaster
25   };
26 
27   CFRunLoopRef run_loop = nullptr;
28 
29   OSStatus r;
30   r = AudioObjectSetPropertyData(kAudioObjectSystemObject,
31                                  &runloop_address,
32                                  0, NULL, sizeof(CFRunLoopRef), &run_loop);
33   if (r != noErr) {
34     LOG("Could not make global CoreAudio notifications use their own thread.");
35   }
36 }
37