Sound (macOS): support non-controllable devices

This commit is contained in:
Carter Li
2023-10-04 14:59:13 +08:00
parent 8795d99f79
commit 9972c61bbe
2 changed files with 29 additions and 17 deletions
+23 -16
View File
@@ -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;