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

 (Replace
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 <mackyle@gmail.com>
parent cafce902
Pipeline #2310 passed with stage
in 1 minute and 3 seconds
...@@ -259,7 +259,6 @@ static AudioDeviceID findAudioOutputDevice(const char *name) ...@@ -259,7 +259,6 @@ static AudioDeviceID findAudioOutputDevice(const char *name)
OSStatus err; OSStatus err;
AudioDeviceID aid; AudioDeviceID aid;
AudioObjectPropertyAddress propertyAddress; AudioObjectPropertyAddress propertyAddress;
propertyAddress.mSelector = kAudioHardwarePropertyDefaultInputDevice;
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal; propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
propertyAddress.mElement = kAudioObjectPropertyElementMaster; propertyAddress.mElement = kAudioObjectPropertyElementMaster;
...@@ -273,6 +272,7 @@ static AudioDeviceID findAudioOutputDevice(const char *name) ...@@ -273,6 +272,7 @@ static AudioDeviceID findAudioOutputDevice(const char *name)
kCFAllocatorNull); kCFAllocatorNull);
if (!namestr) if (!namestr)
return kAudioObjectUnknown; return kAudioObjectUnknown;
propertyAddress.mSelector = kAudioHardwarePropertyDeviceForUID;
err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &size, &avt); err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &size, &avt);
CFRelease(namestr); CFRelease(namestr);
if (!err && aid != kAudioObjectUnknown) if (!err && aid != kAudioObjectUnknown)
...@@ -289,7 +289,8 @@ static AudioDeviceID findAudioOutputDevice(const char *name) ...@@ -289,7 +289,8 @@ static AudioDeviceID findAudioOutputDevice(const char *name)
if (!lcname) if (!lcname)
return kAudioObjectUnknown; /* no memory */ return kAudioObjectUnknown; /* no memory */
lowercasestr(lcname); lowercasestr(lcname);
err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &size, devices); propertyAddress.mSelector = kAudioHardwarePropertyDevices;
err = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &size);
if (err) { if (err) {
free(lcname); free(lcname);
return kAudioObjectUnknown; return kAudioObjectUnknown;
...@@ -339,12 +340,13 @@ static AudioDeviceID findAudioOutputDevice(const char *name) ...@@ -339,12 +340,13 @@ static AudioDeviceID findAudioOutputDevice(const char *name)
} }
/* Check the source name too */ /* Check the source name too */
size = sizeof(srcnum); size = sizeof(srcnum);
AudioObjectPropertyAddress address = { kAudioDevicePropertyVolumeScalar, kAudioDevicePropertyScopeInput, 0 }; AudioObjectPropertyAddress address = { kAudioDevicePropertyDataSource, kAudioDevicePropertyScopeOutput, 0 };
err = AudioObjectGetPropertyData(devices[i], &address, 0, NULL, &size, &srcnum); err = AudioObjectGetPropertyData(devices[i], &address, 0, NULL, &size, &srcnum);
if (!err) { if (!err) {
CFStringRef srcstr; CFStringRef srcstr;
AudioValueTranslation avt = {&srcnum, sizeof(srcnum), &srcstr, sizeof(srcstr)}; AudioValueTranslation avt = {&srcnum, sizeof(srcnum), &srcstr, sizeof(srcstr)};
size = sizeof(avt); size = sizeof(avt);
address.mSelector = kAudioDevicePropertyDataSourceNameForIDCFString;
err = AudioObjectGetPropertyData(devices[i], &address, 0, NULL, &size, &avt); err = AudioObjectGetPropertyData(devices[i], &address, 0, NULL, &size, &avt);
if (!err && srcstr) { if (!err && srcstr) {
srcname = cfstringdupe(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