Update ALSA device enumeration to return all devices
authorMithra Pattison <mithra.pattison@nokia.com>
Thu, 28 Jun 2012 05:40:16 +0000 (15:40 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 10 Jul 2012 07:18:21 +0000 (09:18 +0200)
Previously, if a device was marked as "Default Audio Device" then
only this device would be returned during device enumeration. Now
it returns all devices, with the default device placed first.

Task-number: QTBUG-22103
Change-Id: I1705415bf6b58ff046c4d2812107b46b76500001
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp

index 0c2fe49..4ef96c7 100644 (file)
@@ -406,7 +406,6 @@ void QAudioDeviceInfoInternal::updateLists()
 
 QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
 {
-    QList<QByteArray> allDevices;
     QList<QByteArray> devices;
     QByteArray filter;
 
@@ -436,8 +435,9 @@ QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
             if ((descr != NULL) && ((io == NULL) || (io == filter))) {
                 QString deviceName = QLatin1String(name);
                 QString deviceDescription = QLatin1String(descr);
-                allDevices.append(deviceName.toLocal8Bit().constData());
                 if (deviceDescription.contains(QLatin1String("Default Audio Device")))
+                    devices.prepend(deviceName.toLocal8Bit().constData());
+                else
                     devices.append(deviceName.toLocal8Bit().constData());
             }
 
@@ -450,10 +450,6 @@ QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
         ++n;
     }
     snd_device_name_free_hint(hints);
-
-    if(devices.size() > 0) {
-        devices.append("default");
-    }
 #else
     int idx = 0;
     char* name;
@@ -462,14 +458,11 @@ QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
         devices.append(name);
         idx++;
     }
-    if (idx > 0)
-        devices.append("default");
-#endif
-#if !defined(Q_WS_MAEMO_6)
-    if (devices.size() == 0 && allDevices.size() > 0)
-        return allDevices;
 #endif
 
+    if (devices.size() > 0)
+        devices.append("default");
+
     return devices;
 }