summaryrefslogtreecommitdiffstats
path: root/src/multimedia/audio
diff options
context:
space:
mode:
authorKurt Korbatits <kurt.korbatits@nokia.com>2009-11-16 02:04:34 (GMT)
committerKurt Korbatits <kurt.korbatits@nokia.com>2009-11-16 02:04:34 (GMT)
commit35c534491ef048abc072d5ebaaecb756fe8f5773 (patch)
treec5a9c3fe35352101158ebcd48eb186beb58fab95 /src/multimedia/audio
parent300ab260c96d1e0a28f44d7e6c1d80b6124efd6c (diff)
downloadQt-35c534491ef048abc072d5ebaaecb756fe8f5773.zip
Qt-35c534491ef048abc072d5ebaaecb756fe8f5773.tar.gz
Qt-35c534491ef048abc072d5ebaaecb756fe8f5773.tar.bz2
No audio devices found for Ubuntu with QAudio classes
Changed alsa implementation to present audio devices from alsa. Task-number:QTBUG-5723 Reviewed-by:Justin McPherson
Diffstat (limited to 'src/multimedia/audio')
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp48
-rw-r--r--src/multimedia/audio/qaudioinput.cpp1
-rw-r--r--src/multimedia/audio/qaudioinput_alsa_p.cpp25
-rw-r--r--src/multimedia/audio/qaudiooutput_alsa_p.cpp21
4 files changed, 66 insertions, 29 deletions
diff --git a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp
index 5de6c70..9645fa8 100644
--- a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp
+++ b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp
@@ -152,13 +152,23 @@ bool QAudioDeviceInfoInternal::open()
{
int err = 0;
QString dev = device;
- if(!dev.contains(QLatin1String("default"))) {
+ QList<QByteArray> devices = availableDevices(mode);
+
+ if(dev.compare(QLatin1String("default")) == 0) {
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+ dev = QLatin1String(devices.first().constData());
+#else
+ dev = QLatin1String("hw:0,0");
+#endif
+ } else {
#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
- dev = QString(QLatin1String("default:CARD=%1")).arg(dev);
+ 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;
@@ -195,16 +205,25 @@ bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const
snd_pcm_hw_params_t *params;
QString dev = device;
- // open()
- if(!dev.contains(QLatin1String("default"))) {
+ QList<QByteArray> devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioOutput);
+
+ if(dev.compare(QLatin1String("default")) == 0) {
#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
- dev = QString(QLatin1String("default:CARD=%1")).arg(dev);
+ dev = QLatin1String(devices.first().constData());
+#else
+ dev = QLatin1String("hw:0,0");
+#endif
+ } else {
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 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)))
+ if(shortName.compare(QLatin1String(name)) == 0)
break;
idx++;
}
@@ -386,6 +405,7 @@ QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
{
QList<QByteArray> devices;
QByteArray filter;
+
#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
// Create a list of all current audio devices that support mode
void **hints, **n;
@@ -408,12 +428,10 @@ QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
descr = snd_device_name_get_hint(*n, "DESC");
io = snd_device_name_get_hint(*n, "IOID");
if((name != NULL) && (descr != NULL) && ((io == NULL) || (io == filter))) {
- QString str = QLatin1String(name);
-
- if(str.contains(QLatin1String("default"))) {
- int pos = str.indexOf(QLatin1String("="),0);
- devices.append(str.mid(pos+1).toLocal8Bit().constData());
- }
+ QString deviceName = QLatin1String(name);
+ QString deviceDescription = QLatin1String(descr);
+ if(deviceDescription.contains(QLatin1String("Default Audio Device")))
+ devices.append(deviceName.toLocal8Bit().constData());
}
if(name != NULL)
free(name);
@@ -448,7 +466,7 @@ QByteArray QAudioDeviceInfoInternal::defaultInputDevice()
if(devices.size() == 0)
return QByteArray();
- return QByteArray("default");
+ return devices.first();
}
QByteArray QAudioDeviceInfoInternal::defaultOutputDevice()
@@ -457,7 +475,7 @@ QByteArray QAudioDeviceInfoInternal::defaultOutputDevice()
if(devices.size() == 0)
return QByteArray();
- return QByteArray("default");
+ return devices.first();
}
QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudioinput.cpp b/src/multimedia/audio/qaudioinput.cpp
index e794eaf..8b368d5 100644
--- a/src/multimedia/audio/qaudioinput.cpp
+++ b/src/multimedia/audio/qaudioinput.cpp
@@ -47,7 +47,6 @@
#include "qaudiodevicefactory_p.h"
-
QT_BEGIN_NAMESPACE
/*!
diff --git a/src/multimedia/audio/qaudioinput_alsa_p.cpp b/src/multimedia/audio/qaudioinput_alsa_p.cpp
index 8a8f0db..3dbe66c 100644
--- a/src/multimedia/audio/qaudioinput_alsa_p.cpp
+++ b/src/multimedia/audio/qaudioinput_alsa_p.cpp
@@ -52,6 +52,7 @@
#include <QtCore/qcoreapplication.h>
#include "qaudioinput_alsa_p.h"
+#include "qaudiodeviceinfo_alsa_p.h"
QT_BEGIN_NAMESPACE
@@ -80,8 +81,7 @@ QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFor
pullMode = true;
resuming = false;
- QStringList list1 = QString(QLatin1String(device)).split(QLatin1String(":"));
- m_device = QByteArray(list1.at(0).toLocal8Bit().constData());
+ m_device = device;
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),SLOT(userFeed()));
@@ -259,22 +259,31 @@ bool QAudioInputPrivate::open()
unsigned int freakuency=settings.frequency();
QString dev = QString(QLatin1String(m_device.constData()));
- if(!dev.contains(QLatin1String("default"))) {
-#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
- dev = QString(QLatin1String("default:CARD=%1")).arg(QLatin1String(m_device.constData()));
+ QList<QByteArray> devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioInput);
+ if(dev.compare(QLatin1String("default")) == 0) {
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+ dev = QLatin1String(devices.first());
+#else
+ dev = QLatin1String("hw:0,0");
+#endif
+ } else {
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+ dev = QLatin1String(m_device);
#else
int idx = 0;
char *name;
+ QString shortName = QLatin1String(m_device.mid(m_device.indexOf('=',0)+1).constData());
+
while(snd_card_get_name(idx,&name) == 0) {
- if(m_device.contains(name))
+ if(qstrncmp(shortName.toLocal8Bit().constData(),name,shortName.length()) == 0)
break;
idx++;
}
dev = QString(QLatin1String("hw:%1,0")).arg(idx);
#endif
}
-
+
// Step 1: try and open the device
while((count < 5) && (err < 0)) {
err=snd_pcm_open(&handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0);
@@ -614,7 +623,7 @@ qint64 QAudioInputPrivate::elapsedUSecs() const
if (deviceState == QAudio::StoppedState)
return 0;
-#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
snd_pcm_status_t* status;
snd_pcm_status_alloca(&status);
diff --git a/src/multimedia/audio/qaudiooutput_alsa_p.cpp b/src/multimedia/audio/qaudiooutput_alsa_p.cpp
index e9784d2..020a104 100644
--- a/src/multimedia/audio/qaudiooutput_alsa_p.cpp
+++ b/src/multimedia/audio/qaudiooutput_alsa_p.cpp
@@ -52,6 +52,7 @@
#include <QtCore/qcoreapplication.h>
#include "qaudiooutput_alsa_p.h"
+#include "qaudiodeviceinfo_alsa_p.h"
QT_BEGIN_NAMESPACE
@@ -281,21 +282,31 @@ bool QAudioOutputPrivate::open()
unsigned int freakuency=settings.frequency();
QString dev = QLatin1String(m_device.constData());
- if(!dev.contains(QLatin1String("default"))) {
-#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
- dev = QString(QLatin1String("default:CARD=%1")).arg(QLatin1String(m_device.constData()));
+ QList<QByteArray> devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioOutput);
+ if(dev.compare(QLatin1String("default")) == 0) {
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+ dev = QLatin1String(devices.first().constData());
+#else
+ dev = QLatin1String("hw:0,0");
+#endif
+ } else {
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+ dev = QLatin1String(m_device);
#else
int idx = 0;
char *name;
+ QString shortName = QLatin1String(m_device.mid(m_device.indexOf('=',0)+1).constData());
+
while(snd_card_get_name(idx,&name) == 0) {
- if(m_device.contains(name))
+ if(qstrncmp(shortName.toLocal8Bit().constData(),name,shortName.length()) == 0)
break;
idx++;
}
dev = QString(QLatin1String("hw:%1,0")).arg(idx);
#endif
}
+
// Step 1: try and open the device
while((count < 5) && (err < 0)) {
err=snd_pcm_open(&handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0);
@@ -666,7 +677,7 @@ qint64 QAudioOutputPrivate::elapsedUSecs() const
if (deviceState == QAudio::StoppedState)
return 0;
-#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
snd_pcm_status_t* status;
snd_pcm_status_alloca(&status);