Duckstation/dep/cubeb/src/cubeb_osx_run_loop.cpp

35 lines
1.1 KiB
C++
Raw Normal View History

2020-01-10 04:59:53 +00:00
/*
* Copyright © 2016 Mozilla Foundation
*
* This program is made available under an ISC-style license. See the
* accompanying file LICENSE for details.
*/
#include "cubeb_osx_run_loop.h"
#include "cubeb_log.h"
#include <AudioUnit/AudioUnit.h>
#include <CoreAudio/AudioHardware.h>
#include <CoreAudio/HostTime.h>
#include <CoreFoundation/CoreFoundation.h>
2022-08-05 07:28:17 +00:00
#include <cubeb/cubeb.h>
2020-01-10 04:59:53 +00:00
2022-08-05 07:28:17 +00:00
void
cubeb_set_coreaudio_notification_runloop()
2020-01-10 04:59:53 +00:00
{
/* This is needed so that AudioUnit listeners get called on this thread, and
* not the main thread. If we don't do that, they are not called, or a crash
* occur, depending on the OSX version. */
AudioObjectPropertyAddress runloop_address = {
2022-08-05 07:28:17 +00:00
kAudioHardwarePropertyRunLoop, kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster};
2020-01-10 04:59:53 +00:00
CFRunLoopRef run_loop = nullptr;
OSStatus r;
2022-08-05 07:28:17 +00:00
r = AudioObjectSetPropertyData(kAudioObjectSystemObject, &runloop_address, 0,
NULL, sizeof(CFRunLoopRef), &run_loop);
2020-01-10 04:59:53 +00:00
if (r != noErr) {
LOG("Could not make global CoreAudio notifications use their own thread.");
}
}