Skip to content

Commit 9972c61

Browse files
committed
Sound (macOS): support non-controllable devices
1 parent 8795d99 commit 9972c61

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

src/detection/sound/sound_apple.c

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

35-
uint32_t muted;
36-
dataSize = sizeof(muted);
35+
FF_CFTYPE_AUTO_RELEASE CFStringRef name = NULL;
36+
dataSize = sizeof(name);
3737
if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
38-
kAudioDevicePropertyMute,
38+
kAudioObjectPropertyName,
3939
kAudioObjectPropertyScopeOutput,
4040
kAudioObjectPropertyElementMain
41-
}, 0, NULL, &dataSize, &muted) != kAudioHardwareNoError)
41+
}, 0, NULL, &dataSize, &name) != kAudioHardwareNoError)
4242
continue;
4343

44+
uint32_t connected;
45+
dataSize = sizeof(connected);
46+
if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
47+
kAudioDevicePropertyJackIsConnected,
48+
kAudioObjectPropertyScopeOutput,
49+
kAudioObjectPropertyElementMain
50+
}, 0, NULL, &dataSize, &connected) == kAudioHardwareNoError)
51+
if (!connected) continue;
52+
4453
FFSoundDevice* device = (FFSoundDevice*) ffListAdd(devices);
4554
device->main = deviceId == mainDeviceId;
4655
device->active = false;
4756
device->volume = FF_SOUND_VOLUME_UNKNOWN;
4857
ffStrbufInitF(&device->identifier, "%u", (unsigned) deviceId);
4958
ffStrbufInit(&device->name);
59+
ffCfStrGetString(name, &device->name);
60+
61+
uint32_t muted;
62+
dataSize = sizeof(muted);
63+
if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
64+
kAudioDevicePropertyMute,
65+
kAudioObjectPropertyScopeOutput,
66+
kAudioObjectPropertyElementMain
67+
}, 0, NULL, &dataSize, &muted) != kAudioHardwareNoError)
68+
muted = false; // Device may not support volume control
5069

5170
uint32_t active;
5271
dataSize = sizeof(active);
@@ -96,18 +115,6 @@ const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */)
96115
}
97116
}
98117
}
99-
100-
CFStringRef name;
101-
dataSize = sizeof(name);
102-
if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
103-
kAudioObjectPropertyName,
104-
kAudioObjectPropertyScopeOutput,
105-
kAudioObjectPropertyElementMain
106-
}, 0, NULL, &dataSize, &name) == kAudioHardwareNoError)
107-
{
108-
ffCfStrGetString(name, &device->name);
109-
CFRelease(name);
110-
}
111118
}
112119

113120
return NULL;

src/modules/sound/sound.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ void ffGenerateSoundJson(FF_MAYBE_UNUSED FFSoundOptions* options, yyjson_mut_doc
173173
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
174174
yyjson_mut_obj_add_bool(doc, obj, "active", item->active);
175175
yyjson_mut_obj_add_bool(doc, obj, "main", item->main);
176-
yyjson_mut_obj_add_uint(doc, obj, "volume", item->volume);
176+
177+
if (item->volume != FF_SOUND_VOLUME_UNKNOWN)
178+
yyjson_mut_obj_add_uint(doc, obj, "volume", item->volume);
179+
else
180+
yyjson_mut_obj_add_null(doc, obj, "volumne");
181+
177182
yyjson_mut_obj_add_strbuf(doc, obj, "name", &item->name);
178183
yyjson_mut_obj_add_strbuf(doc, obj, "identifier", &item->identifier);
179184
}

0 commit comments

Comments
 (0)