mac-capture: Simplify coreaudio_get_device_id

The current method would enum though all devices looking for a matching
uid instead of directly asking for kAudioHardwarePropertyDeviceForUID.
Asking directly instead would also enable finding hidden devices that
can only be found directly via uid and not via enumerating (were we ever
to need to find such a device).
This commit is contained in:
gxalpha 2023-03-30 17:52:47 +02:00 committed by Jim
parent 584de6b264
commit eaf6444236

View file

@ -137,30 +137,19 @@ void coreaudio_enum_devices(struct device_list *list, bool input)
enum_devices(coreaudio_enum_add_device, &data);
}
struct device_id_data {
CFStringRef uid;
AudioDeviceID *id;
bool found;
};
static bool get_device_id(void *param, CFStringRef cf_name, CFStringRef cf_uid,
AudioDeviceID id)
{
struct device_id_data *data = param;
if (CFStringCompare(cf_uid, data->uid, 0) == 0) {
*data->id = id;
data->found = true;
return false;
}
UNUSED_PARAMETER(cf_name);
return true;
}
bool coreaudio_get_device_id(CFStringRef uid, AudioDeviceID *id)
{
struct device_id_data data = {uid, id, false};
enum_devices(get_device_id, &data);
return data.found;
AudioObjectPropertyAddress propertyAddress = {
kAudioHardwarePropertyDeviceForUID,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster};
AudioValueTranslation translation = {&uid, sizeof(CFStringRef), id,
sizeof(AudioDeviceID)};
UInt32 size = sizeof(translation);
OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
&propertyAddress, 0, NULL,
&size, &translation);
return result == noErr;
}