Commit bddd1792 authored by Kyle McKay's avatar Kyle McKay 💬
Browse files

ao_macosx.c: unbreak device selection on macOS

When commits 0dc94854 (Replace deprecated Carbon API calls with
modern AudioComponent APIs, 2016-01-11) and 18dc25cd

deprecated HAL APIs, 2016-01-11) attempted to update the API calls,
several of the replacements were completely incorrect.

Any attempt to select an output device was completely broken by
those changes.  Trying to select a device always fails and in
the process passes a bunch of mismatched, invalid argument combinations
to the API.  It's a surprise there aren't seg faults.

The only reason the default output device continued to work was
because it can be used without calling into the broken code.

Correct the brokenness so that devices can be selected correctly
on macOS again.

Signed-off-by: Kyle McKay's avatarKyle J. McKay <>
parent cafce902
Pipeline #2310 passed with stage
in 1 minute and 3 seconds
......@@ -259,7 +259,6 @@ static AudioDeviceID findAudioOutputDevice(const char *name)
OSStatus err;
AudioDeviceID aid;
AudioObjectPropertyAddress propertyAddress;
propertyAddress.mSelector = kAudioHardwarePropertyDefaultInputDevice;
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
propertyAddress.mElement = kAudioObjectPropertyElementMaster;
......@@ -273,6 +272,7 @@ static AudioDeviceID findAudioOutputDevice(const char *name)
if (!namestr)
return kAudioObjectUnknown;
propertyAddress.mSelector = kAudioHardwarePropertyDeviceForUID;
err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &size, &avt);
if (!err && aid != kAudioObjectUnknown)
......@@ -289,7 +289,8 @@ static AudioDeviceID findAudioOutputDevice(const char *name)
if (!lcname)
return kAudioObjectUnknown; /* no memory */
err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &size, devices);
propertyAddress.mSelector = kAudioHardwarePropertyDevices;
err = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &size);
if (err) {
return kAudioObjectUnknown;
......@@ -339,12 +340,13 @@ static AudioDeviceID findAudioOutputDevice(const char *name)
/* Check the source name too */
size = sizeof(srcnum);
AudioObjectPropertyAddress address = { kAudioDevicePropertyVolumeScalar, kAudioDevicePropertyScopeInput, 0 };
AudioObjectPropertyAddress address = { kAudioDevicePropertyDataSource, kAudioDevicePropertyScopeOutput, 0 };
err = AudioObjectGetPropertyData(devices[i], &address, 0, NULL, &size, &srcnum);
if (!err) {
CFStringRef srcstr;
AudioValueTranslation avt = {&srcnum, sizeof(srcnum), &srcstr, sizeof(srcstr)};
size = sizeof(avt);
address.mSelector = kAudioDevicePropertyDataSourceNameForIDCFString;
err = AudioObjectGetPropertyData(devices[i], &address, 0, NULL, &size, &avt);
if (!err && srcstr) {
srcname = cfstringdupe(srcstr);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment