diff --git a/src/detection/sound/sound_apple.c b/src/detection/sound/sound_apple.c index 8f23f2a3a..092d4479d 100644 --- a/src/detection/sound/sound_apple.c +++ b/src/detection/sound/sound_apple.c @@ -32,21 +32,40 @@ const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */) { AudioDeviceID deviceId = deviceIds[index]; - uint32_t muted; - dataSize = sizeof(muted); + FF_CFTYPE_AUTO_RELEASE CFStringRef name = NULL; + dataSize = sizeof(name); if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){ - kAudioDevicePropertyMute, + kAudioObjectPropertyName, kAudioObjectPropertyScopeOutput, kAudioObjectPropertyElementMain - }, 0, NULL, &dataSize, &muted) != kAudioHardwareNoError) + }, 0, NULL, &dataSize, &name) != kAudioHardwareNoError) continue; + uint32_t connected; + dataSize = sizeof(connected); + if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){ + kAudioDevicePropertyJackIsConnected, + kAudioObjectPropertyScopeOutput, + kAudioObjectPropertyElementMain + }, 0, NULL, &dataSize, &connected) == kAudioHardwareNoError) + if (!connected) continue; + FFSoundDevice* device = (FFSoundDevice*) ffListAdd(devices); device->main = deviceId == mainDeviceId; device->active = false; device->volume = FF_SOUND_VOLUME_UNKNOWN; ffStrbufInitF(&device->identifier, "%u", (unsigned) deviceId); ffStrbufInit(&device->name); + ffCfStrGetString(name, &device->name); + + uint32_t muted; + dataSize = sizeof(muted); + if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){ + kAudioDevicePropertyMute, + kAudioObjectPropertyScopeOutput, + kAudioObjectPropertyElementMain + }, 0, NULL, &dataSize, &muted) != kAudioHardwareNoError) + muted = false; // Device may not support volume control uint32_t active; dataSize = sizeof(active); @@ -96,18 +115,6 @@ const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */) } } } - - CFStringRef name; - dataSize = sizeof(name); - if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){ - kAudioObjectPropertyName, - kAudioObjectPropertyScopeOutput, - kAudioObjectPropertyElementMain - }, 0, NULL, &dataSize, &name) == kAudioHardwareNoError) - { - ffCfStrGetString(name, &device->name); - CFRelease(name); - } } return NULL; diff --git a/src/modules/sound/sound.c b/src/modules/sound/sound.c index 3796a7365..6157c32d3 100644 --- a/src/modules/sound/sound.c +++ b/src/modules/sound/sound.c @@ -173,7 +173,12 @@ void ffGenerateSoundJson(FF_MAYBE_UNUSED FFSoundOptions* options, yyjson_mut_doc yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr); yyjson_mut_obj_add_bool(doc, obj, "active", item->active); yyjson_mut_obj_add_bool(doc, obj, "main", item->main); - yyjson_mut_obj_add_uint(doc, obj, "volume", item->volume); + + if (item->volume != FF_SOUND_VOLUME_UNKNOWN) + yyjson_mut_obj_add_uint(doc, obj, "volume", item->volume); + else + yyjson_mut_obj_add_null(doc, obj, "volumne"); + yyjson_mut_obj_add_strbuf(doc, obj, "name", &item->name); yyjson_mut_obj_add_strbuf(doc, obj, "identifier", &item->identifier); }