summaryrefslogtreecommitdiffstats
path: root/src/plugins/alsa/qalsaaudiodeviceinfo.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2016-07-20 15:53:34 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2016-07-21 14:03:11 +0200
commit7a5e3145550015c9c6c3e8232c8257099aa2480c (patch)
tree0b5623c19c6d2ac39a9d95befcadc957029a2446 /src/plugins/alsa/qalsaaudiodeviceinfo.cpp
parent631b89ddde44dfc8b72b904d8c41368b2c02d037 (diff)
parent17d54a2eb57816dbc531feee80dbd25f835e733a (diff)
Merge remote-tracking branch 'origin/5.7' into dev
Conflicts: src/plugins/directshow/player/directshowiosource.cpp One side disintermediated filling a vector; the other reduced it to one entry. src/plugins/directshow/player/directshowiosource.h One side renamed a member, the other added another adjacent to it. src/plugins/pulseaudio/qpulseaudioengine.h One side added a header, the other replaced the next with a different header. Change-Id: I3a031975f5af43ca39cca571f215c612f640b7d6
Diffstat (limited to 'src/plugins/alsa/qalsaaudiodeviceinfo.cpp')
-rw-r--r--src/plugins/alsa/qalsaaudiodeviceinfo.cpp96
1 files changed, 39 insertions, 57 deletions
diff --git a/src/plugins/alsa/qalsaaudiodeviceinfo.cpp b/src/plugins/alsa/qalsaaudiodeviceinfo.cpp
index d0f772d5e..5e8edc3fc 100644
--- a/src/plugins/alsa/qalsaaudiodeviceinfo.cpp
+++ b/src/plugins/alsa/qalsaaudiodeviceinfo.cpp
@@ -152,35 +152,18 @@ QByteArray QAlsaAudioDeviceInfo::defaultDevice(QAudio::Mode mode)
bool QAlsaAudioDeviceInfo::open()
{
int err = 0;
- QString dev = device;
- QList<QByteArray> devices = availableDevices(mode);
+ QString dev;
- if(dev.compare(QLatin1String("default")) == 0) {
-#if SND_LIB_VERSION >= 0x1000e // 1.0.14
- if (devices.size() > 0)
- dev = QLatin1String(devices.first().constData());
- else
- return false;
-#else
- dev = QLatin1String("hw:0,0");
+ if (!availableDevices(mode).contains(device.toLocal8Bit()))
+ return false;
+
+#if SND_LIB_VERSION < 0x1000e // 1.0.14
+ if (device.compare(QLatin1String("default")) != 0)
+ dev = deviceFromCardName(device);
+ else
#endif
- } else {
-#if SND_LIB_VERSION >= 0x1000e // 1.0.14
dev = device;
-#else
- int idx = 0;
- char *name;
-
- QString shortName = device.mid(device.indexOf(QLatin1String("="),0)+1);
- while (snd_card_get_name(idx,&name) == 0) {
- if(dev.contains(QLatin1String(name)))
- break;
- idx++;
- }
- dev = QString(QLatin1String("hw:%1,0")).arg(idx);
-#endif
- }
if(mode == QAudio::AudioOutput) {
err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0);
} else {
@@ -209,30 +192,12 @@ bool QAlsaAudioDeviceInfo::testSettings(const QAudioFormat& format) const
snd_pcm_hw_params_t *params;
QString dev;
-#if SND_LIB_VERSION >= 0x1000e // 1.0.14
- dev = device;
- if (dev.compare(QLatin1String("default")) == 0) {
- QList<QByteArray> devices = availableDevices(QAudio::AudioOutput);
- if (!devices.isEmpty())
- dev = QLatin1String(devices.first().constData());
- }
-#else
- if (dev.compare(QLatin1String("default")) == 0) {
- dev = QLatin1String("hw:0,0");
- } else {
- int idx = 0;
- char *name;
-
- QString shortName = device.mid(device.indexOf(QLatin1String("="),0)+1);
-
- while(snd_card_get_name(idx,&name) == 0) {
- if(shortName.compare(QLatin1String(name)) == 0)
- break;
- idx++;
- }
- dev = QString(QLatin1String("hw:%1,0")).arg(idx);
- }
+#if SND_LIB_VERSION < 0x1000e // 1.0.14
+ if (device.compare(QLatin1String("default")) != 0)
+ dev = deviceFromCardName(device);
+ else
#endif
+ dev = device;
snd_pcm_stream_t stream = mode == QAudio::AudioOutput
? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE;
@@ -348,9 +313,11 @@ void QAlsaAudioDeviceInfo::updateLists()
QList<QByteArray> QAlsaAudioDeviceInfo::availableDevices(QAudio::Mode mode)
{
QList<QByteArray> devices;
- QByteArray filter;
+ bool hasDefault = false;
#if SND_LIB_VERSION >= 0x1000e // 1.0.14
+ QByteArray filter;
+
// Create a list of all current audio devices that support mode
void **hints, **n;
char *name, *descr, *io;
@@ -374,12 +341,9 @@ QList<QByteArray> QAlsaAudioDeviceInfo::availableDevices(QAudio::Mode mode)
io = snd_device_name_get_hint(*n, "IOID");
if ((descr != NULL) && ((io == NULL) || (io == filter))) {
- QString deviceName = QLatin1String(name);
- QString deviceDescription = QLatin1String(descr);
- if (deviceDescription.contains(QLatin1String("Default Audio Device")))
- devices.prepend(deviceName.toLocal8Bit().constData());
- else
- devices.append(deviceName.toLocal8Bit().constData());
+ devices.append(name);
+ if (strcmp(name, "default") == 0)
+ hasDefault = true;
}
free(descr);
@@ -395,12 +359,14 @@ QList<QByteArray> QAlsaAudioDeviceInfo::availableDevices(QAudio::Mode mode)
while(snd_card_get_name(idx,&name) == 0) {
devices.append(name);
+ if (strcmp(name, "default") == 0)
+ hasDefault = true;
idx++;
}
#endif
- if (devices.size() > 0)
- devices.append("default");
+ if (!hasDefault && devices.size() > 0)
+ devices.prepend("default");
return devices;
}
@@ -445,4 +411,20 @@ void QAlsaAudioDeviceInfo::checkSurround()
snd_device_name_free_hint(hints);
}
+QString QAlsaAudioDeviceInfo::deviceFromCardName(const QString &card)
+{
+ int idx = 0;
+ char *name;
+
+ QStringRef shortName = card.midRef(card.indexOf(QLatin1String("="), 0) + 1);
+
+ while (snd_card_get_name(idx, &name) == 0) {
+ if (shortName.compare(QLatin1String(name)) == 0)
+ break;
+ idx++;
+ }
+
+ return QString(QLatin1String("hw:%1,0")).arg(idx);
+}
+
QT_END_NAMESPACE