Skip to content

Commit 7248868

Browse files
committed
Sound (macOS): improve device id detection
1 parent 2eda646 commit 7248868

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

src/detection/sound/sound_apple.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@ const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */)
3232
{
3333
AudioDeviceID deviceId = deviceIds[index];
3434

35-
FF_CFTYPE_AUTO_RELEASE CFStringRef name = NULL;
36-
dataSize = sizeof(name);
37-
if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
38-
kAudioObjectPropertyName,
39-
kAudioObjectPropertyScopeOutput,
40-
kAudioObjectPropertyElementMain
41-
}, 0, NULL, &dataSize, &name) != kAudioHardwareNoError)
42-
continue;
43-
4435
// Ignore input devices
4536
if(AudioObjectGetPropertyDataSize(deviceId, &(AudioObjectPropertyAddress){
4637
kAudioDevicePropertyStreams,
@@ -71,10 +62,31 @@ const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */)
7162
device->main = deviceId == mainDeviceId;
7263
device->active = false;
7364
device->volume = FF_SOUND_VOLUME_UNKNOWN;
74-
ffStrbufInitF(&device->identifier, "%u", (unsigned) deviceId);
65+
ffStrbufInit(&device->identifier);
7566
ffStrbufInit(&device->name);
7667
ffStrbufInitStatic(&device->platformApi, "Core Audio");
77-
ffCfStrGetString(name, &device->name);
68+
69+
FF_CFTYPE_AUTO_RELEASE CFStringRef uid = NULL;
70+
dataSize = sizeof(uid);
71+
if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress) {
72+
kAudioDevicePropertyDeviceUID,
73+
kAudioObjectPropertyScopeOutput,
74+
kAudioObjectPropertyElementMain
75+
}, 0, NULL, &dataSize, &uid) == kAudioHardwareNoError)
76+
ffCfStrGetString(uid, &device->identifier);
77+
else
78+
ffStrbufAppendF(&device->identifier, "ID-%u", (unsigned) deviceId);
79+
80+
FF_CFTYPE_AUTO_RELEASE CFStringRef name = NULL;
81+
dataSize = sizeof(name);
82+
if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
83+
kAudioObjectPropertyName,
84+
kAudioObjectPropertyScopeOutput,
85+
kAudioObjectPropertyElementMain
86+
}, 0, NULL, &dataSize, &name) == kAudioHardwareNoError)
87+
ffCfStrGetString(name, &device->name);
88+
else
89+
ffStrbufSet(&device->name, &device->identifier);
7890

7991
uint32_t muted;
8092
dataSize = sizeof(muted);

0 commit comments

Comments
 (0)