From 75f3e34951f165a523825472dc22bfc557277a00 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 24 Apr 2023 11:05:21 -0700 Subject: Try to detect headphones with CoreAudio --- alc/backends/coreaudio.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'alc') diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index 8b0e75fd..86f58637 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -388,6 +388,24 @@ void CoreAudioPlayback::open(const char *name) if(!devname.empty()) mDevice->DeviceName = std::move(devname); else mDevice->DeviceName = "Unknown Device Name"; } + + if(audioDevice != kAudioDeviceUnknown) + { + UInt32 type{}; + err = GetDevProperty(audioDevice, kAudioDevicePropertyTransportType, false, + kAudioObjectPropertyElementMaster, sizeof(type), &type); + if(err != noErr) + ERR("Failed to get audio device type: %u\n", err); + else + { + static constexpr UInt32 HeadphoneType{('h'<<24u) | ('d'<<16u) | ('p'<<8u) | 'n'}; + TRACE("Got device type '%c%c%c%c'\n", static_cast((type>>24)&0xff), + static_cast((type>>16)&0xff), static_cast((type>>8)&0xff), + static_cast(type&0xff)); + mDevice->Flags.set(DirectEar, (type == HeadphoneType)); + } + } + #else mDevice->DeviceName = name; #endif -- cgit v1.2.3