CoreAudio: Use the real default audio device for QSoundEffect
authorAndy Nichols <andy.nichols@digia.com>
Sun, 2 Mar 2014 19:39:44 +0000 (20:39 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 3 Mar 2014 15:45:38 +0000 (16:45 +0100)
There is an assumption in QtMultimedia that the first audio device
returned by QAudioDeviceInfo::availableDevices is the default device, so
we must make an effor to make sure this is true.  This commit should fix
the issue on OS X.

Task-number: QTBUG-36638
Change-Id: Id388d7218b465cb29d826f46ee825e982c5f7ffc
Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
src/plugins/coreaudio/coreaudiodeviceinfo.mm

index 5d07ca4..bb1f046 100644 (file)
@@ -327,7 +327,7 @@ QByteArray CoreAudioDeviceInfo::defaultOutputDevice()
 #if defined(Q_OS_OSX)
     AudioDeviceID audioDevice;
     UInt32        size = sizeof(audioDevice);
-    AudioObjectPropertyAddress defaultOutputDevicePropertyAddress = { kAudioHardwarePropertyDefaultInputDevice,
+    AudioObjectPropertyAddress defaultOutputDevicePropertyAddress = { kAudioHardwarePropertyDefaultOutputDevice,
                                                                      kAudioObjectPropertyScopeGlobal,
                                                                      kAudioObjectPropertyElementMaster };
 
@@ -363,10 +363,15 @@ QList<QByteArray> CoreAudioDeviceInfo::availableDevices(QAudio::Mode mode)
             AudioDeviceID*  audioDevices = new AudioDeviceID[dc];
 
             if (AudioObjectGetPropertyData(kAudioObjectSystemObject, &audioDevicesPropertyAddress, 0, NULL, &propSize, audioDevices) == noErr) {
+                QByteArray defaultDevice = (mode == QAudio::AudioOutput) ? defaultOutputDevice() : defaultInputDevice();
                 for (int i = 0; i < dc; ++i) {
                     QByteArray info = get_device_info(audioDevices[i], mode);
-                    if (!info.isNull())
-                        devices << info;
+                    if (!info.isNull()) {
+                        if (info == defaultDevice)
+                            devices.prepend(info);
+                        else
+                            devices << info;
+                    }
                 }
             }