diff options
author | Liang Qi <liang.qi@qt.io> | 2016-06-29 16:11:26 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-06-30 07:33:04 +0200 |
commit | 27681cba4695355f2a0a6b01b85c429186d11a34 (patch) | |
tree | f11df2ec52d983b552f2e1b673e0845bc7e3ef05 /src/plugins/alsa | |
parent | f7a93757c709e8b2902bc4707752edb8649d009c (diff) | |
parent | bc53bb7913bbf68519508a0ab76c513335b3e5bb (diff) |
Merge remote-tracking branch 'origin/5.6' into 5.7
Blacklisted a few functions in tst_QAudioInput.
Conflicts:
.qmake.conf
src/plugins/avfoundation/camera/avfcameracontrol.mm
src/plugins/avfoundation/camera/avfcameraservice.h
src/plugins/avfoundation/camera/avfcameraservice.mm
src/plugins/avfoundation/camera/avfcamerasession.h
src/plugins/avfoundation/camera/avfcamerasession.mm
src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.h
src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm
src/plugins/avfoundation/camera/avfimagecapturecontrol.mm
src/plugins/avfoundation/camera/avfimageencodercontrol.mm
src/plugins/avfoundation/camera/avfmediarecordercontrol.h
src/plugins/avfoundation/camera/avfmediarecordercontrol.mm
tests/auto/integration/qaudioinput/BLACKLIST
Task-number: QTBUG-54459
Task-number: QTBUG-49736
Change-Id: I3a1fe8cef50b44d5c2785aaf4cf69fe3f16728e6
Diffstat (limited to 'src/plugins/alsa')
-rw-r--r-- | src/plugins/alsa/qalsaaudiodeviceinfo.cpp | 96 | ||||
-rw-r--r-- | src/plugins/alsa/qalsaaudiodeviceinfo.h | 1 | ||||
-rw-r--r-- | src/plugins/alsa/qalsaaudioinput.cpp | 45 | ||||
-rw-r--r-- | src/plugins/alsa/qalsaaudiooutput.cpp | 42 |
4 files changed, 72 insertions, 112 deletions
diff --git a/src/plugins/alsa/qalsaaudiodeviceinfo.cpp b/src/plugins/alsa/qalsaaudiodeviceinfo.cpp index 0342ca546..869e1897e 100644 --- a/src/plugins/alsa/qalsaaudiodeviceinfo.cpp +++ b/src/plugins/alsa/qalsaaudiodeviceinfo.cpp @@ -143,35 +143,18 @@ QList<QAudioFormat::SampleType> QAlsaAudioDeviceInfo::supportedSampleTypes() 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 { @@ -200,30 +183,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; @@ -339,9 +304,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; @@ -365,12 +332,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); @@ -386,12 +350,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; } @@ -454,4 +420,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 diff --git a/src/plugins/alsa/qalsaaudiodeviceinfo.h b/src/plugins/alsa/qalsaaudiodeviceinfo.h index 0147a2cf9..97b59ebf3 100644 --- a/src/plugins/alsa/qalsaaudiodeviceinfo.h +++ b/src/plugins/alsa/qalsaaudiodeviceinfo.h @@ -91,6 +91,7 @@ public: static QByteArray defaultInputDevice(); static QByteArray defaultOutputDevice(); static QList<QByteArray> availableDevices(QAudio::Mode); + static QString deviceFromCardName(const QString &card); private: bool open(); diff --git a/src/plugins/alsa/qalsaaudioinput.cpp b/src/plugins/alsa/qalsaaudioinput.cpp index 6ad9a6c5b..8109e6932 100644 --- a/src/plugins/alsa/qalsaaudioinput.cpp +++ b/src/plugins/alsa/qalsaaudioinput.cpp @@ -127,6 +127,12 @@ int QAlsaAudioInput::xrun_recovery(int err) int count = 0; bool reset = false; + // ESTRPIPE is not available in all OSes where ALSA is available + int estrpipe = EIO; +#ifdef ESTRPIPE + estrpipe = ESTRPIPE; +#endif + if(err == -EPIPE) { errorState = QAudio::UnderrunError; err = snd_pcm_prepare(handle); @@ -137,8 +143,7 @@ int QAlsaAudioInput::xrun_recovery(int err) if (bytesAvailable <= 0) reset = true; } - - } else if((err == -ESTRPIPE)||(err == -EIO)) { + } else if ((err == -estrpipe)||(err == -EIO)) { errorState = QAudio::IOError; while((err = snd_pcm_resume(handle)) == -EAGAIN){ usleep(100); @@ -306,34 +311,16 @@ bool QAlsaAudioInput::open() } - QString dev = QString(QLatin1String(m_device.constData())); - QList<QByteArray> devices = QAlsaAudioDeviceInfo::availableDevices(QAudio::AudioInput); - if(dev.compare(QLatin1String("default")) == 0) { -#if SND_LIB_VERSION >= 0x1000e // 1.0.14 - if (devices.size() > 0) - dev = QLatin1String(devices.first()); - else - return false; -#else - dev = QLatin1String("hw:0,0"); -#endif - } else { -#if SND_LIB_VERSION >= 0x1000e // 1.0.14 - dev = QLatin1String(m_device); -#else - int idx = 0; - char *name; - - QString shortName = QLatin1String(m_device.mid(m_device.indexOf('=',0)+1).constData()); + if (!QAlsaAudioDeviceInfo::availableDevices(QAudio::AudioOutput).contains(m_device)) + return false; - while(snd_card_get_name(idx,&name) == 0) { - if(qstrncmp(shortName.toLocal8Bit().constData(),name,shortName.length()) == 0) - break; - idx++; - } - dev = QString(QLatin1String("hw:%1,0")).arg(idx); + QString dev; +#if SND_LIB_VERSION < 0x1000e // 1.0.14 + if (m_device != "default") + dev = QAlsaAudioDeviceInfo::deviceFromCardName(m_device); + else #endif - } + dev = m_device; // Step 1: try and open the device while((count < 5) && (err < 0)) { @@ -565,8 +552,10 @@ qint64 QAlsaAudioInput::read(char* data, qint64 len) if(readFrames == -EPIPE) { errorState = QAudio::UnderrunError; err = snd_pcm_prepare(handle); +#ifdef ESTRPIPE } else if(readFrames == -ESTRPIPE) { err = snd_pcm_prepare(handle); +#endif } if(err != 0) break; } diff --git a/src/plugins/alsa/qalsaaudiooutput.cpp b/src/plugins/alsa/qalsaaudiooutput.cpp index d59e2b740..5e444a0a9 100644 --- a/src/plugins/alsa/qalsaaudiooutput.cpp +++ b/src/plugins/alsa/qalsaaudiooutput.cpp @@ -120,6 +120,12 @@ int QAlsaAudioOutput::xrun_recovery(int err) int count = 0; bool reset = false; + // ESTRPIPE is not available in all OSes where ALSA is available + int estrpipe = EIO; +#ifdef ESTRPIPE + estrpipe = ESTRPIPE; +#endif + if(err == -EPIPE) { errorState = QAudio::UnderrunError; emit errorChanged(errorState); @@ -127,7 +133,7 @@ int QAlsaAudioOutput::xrun_recovery(int err) if(err < 0) reset = true; - } else if((err == -ESTRPIPE)||(err == -EIO)) { + } else if ((err == -estrpipe)||(err == -EIO)) { errorState = QAudio::IOError; emit errorChanged(errorState); while((err = snd_pcm_resume(handle)) == -EAGAIN){ @@ -309,34 +315,16 @@ bool QAlsaAudioOutput::open() return false; } - QString dev = QString(QLatin1String(m_device.constData())); - QList<QByteArray> devices = QAlsaAudioDeviceInfo::availableDevices(QAudio::AudioOutput); - if(dev.compare(QLatin1String("default")) == 0) { -#if SND_LIB_VERSION >= 0x1000e // 1.0.14 - if (devices.size() > 0) - dev = QLatin1String(devices.first()); - else - return false; -#else - dev = QLatin1String("hw:0,0"); -#endif - } else { -#if SND_LIB_VERSION >= 0x1000e // 1.0.14 - dev = QLatin1String(m_device); -#else - int idx = 0; - char *name; - - QString shortName = QLatin1String(m_device.mid(m_device.indexOf('=',0)+1).constData()); + if (!QAlsaAudioDeviceInfo::availableDevices(QAudio::AudioOutput).contains(m_device)) + return false; - while (snd_card_get_name(idx,&name) == 0) { - if(qstrncmp(shortName.toLocal8Bit().constData(),name,shortName.length()) == 0) - break; - idx++; - } - dev = QString(QLatin1String("hw:%1,0")).arg(idx); + QString dev; +#if SND_LIB_VERSION < 0x1000e // 1.0.14 + if (m_device != "default") + dev = QAlsaAudioDeviceInfo::deviceFromCardName(m_device); + else #endif - } + dev = m_device; // Step 1: try and open the device while((count < 5) && (err < 0)) { |