@@ -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 ;
0 commit comments