diff options
author | Lars Knoll <lars.knoll@qt.io> | 2021-05-25 16:55:23 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2021-05-26 10:18:49 +0000 |
commit | 23944677fdf465d4bf89bab65059ad1702bc5276 (patch) | |
tree | e201e2469f795cc02c6565739a8d20b750880d8f | |
parent | 2db739f2af5bd26e132232aa9ca88fd86008c1d7 (diff) |
Stabilize the qaudioinput autotest on Windows
Unfortunately, the only way to get reliable results for the
failing test is to increase the time spent sampling, so that
the inherent jitter contributes less to the measured timings.
Change-Id: Ie6bb97174d30b38a911519f73af0ae0881ed3536
Reviewed-by: André de la Rocha <andre.rocha@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r-- | src/multimedia/platform/windows/audio/qwindowsaudioinput.cpp | 12 | ||||
-rw-r--r-- | tests/auto/integration/qaudioinput/tst_qaudioinput.cpp | 8 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/multimedia/platform/windows/audio/qwindowsaudioinput.cpp b/src/multimedia/platform/windows/audio/qwindowsaudioinput.cpp index 74cbd782f..87f8571ce 100644 --- a/src/multimedia/platform/windows/audio/qwindowsaudioinput.cpp +++ b/src/multimedia/platform/windows/audio/qwindowsaudioinput.cpp @@ -436,7 +436,9 @@ void QWindowsAudioInput::closeMixer() qsizetype QWindowsAudioInput::bytesReady() const { - if(period_size == 0 || buffer_size == 0) + if (period_size == 0 || buffer_size == 0) + return 0; + if (deviceState == QAudio::StoppedState || deviceState == QAudio::SuspendedState) return 0; int buf = ((buffer_size/period_size)-waveFreeBlockCount)*period_size; @@ -566,7 +568,7 @@ qint64 QWindowsAudioInput::read(char* data, qint64 len) void QWindowsAudioInput::resume() { - if(deviceState == QAudio::SuspendedState) { + if (deviceState == QAudio::SuspendedState) { deviceState = QAudio::ActiveState; for(int i=0; i<buffer_size/period_size; i++) { result = waveInAddBuffer(hWaveIn, &waveBlocks[i], sizeof(WAVEHDR)); @@ -615,8 +617,8 @@ qint64 QWindowsAudioInput::processedUSecs() const void QWindowsAudioInput::suspend() { if(deviceState == QAudio::ActiveState) { - waveInReset(hWaveIn); deviceState = QAudio::SuspendedState; + waveInReset(hWaveIn); emit stateChanged(deviceState); } } @@ -627,7 +629,7 @@ void QWindowsAudioInput::feedback() QTime now(QTime::currentTime()); qDebug()<<now.second()<<"s "<<now.msec()<<"ms :feedback() INPUT "<<this; #endif - if(!(deviceState==QAudio::StoppedState||deviceState==QAudio::SuspendedState)) + if(deviceState != QAudio::StoppedState && deviceState != QAudio::SuspendedState) QMetaObject::invokeMethod(this, "deviceReady", Qt::QueuedConnection); } @@ -636,7 +638,7 @@ bool QWindowsAudioInput::deviceReady() bytesAvailable = bytesReady(); #ifdef DEBUG_AUDIO QTime now(QTime::currentTime()); - qDebug()<<now.second()<<"s "<<now.msec()<<"ms :deviceReady() INPUT"; + qDebug()<<now.second()<<"s "<<now.msec()<<"ms :deviceReady() INPUT" << bytesReady(); #endif if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState) return true; diff --git a/tests/auto/integration/qaudioinput/tst_qaudioinput.cpp b/tests/auto/integration/qaudioinput/tst_qaudioinput.cpp index 3b8dc6fd4..ca65c36c3 100644 --- a/tests/auto/integration/qaudioinput/tst_qaudioinput.cpp +++ b/tests/auto/integration/qaudioinput/tst_qaudioinput.cpp @@ -111,7 +111,7 @@ void tst_QAudioInput::generate_audiofile_testrows() QTest::addColumn<QAudioFormat>("audioFormat"); for (int i=0; i<audioFiles.count(); i++) { - QTest::newRow(QString("Audio File %1").arg(i).toUtf8().constData()) + QTest::newRow(QString("%1").arg(i).toUtf8().constData()) << audioFiles.at(i) << testFormats.at(i); // Only run first format in CI system to reduce test times @@ -607,7 +607,7 @@ void tst_QAudioInput::pushSuspendResume() qint64 totalBytesRead = 0; bool firstBuffer = true; - qint64 len = audioFormat.sampleRate() * audioFormat.bytesPerFrame() / 10; // 100 msecond + qint64 len = audioFormat.sampleRate() * audioFormat.bytesPerFrame() / 2; // .5 seconds while (totalBytesRead < len) { QTRY_VERIFY_WITH_TIMEOUT(audioInput.bytesAvailable() > 0, 1000); auto buffer = feed->readAll(); @@ -657,7 +657,7 @@ void tst_QAudioInput::pushSuspendResume() totalBytesRead = 0; firstBuffer = true; while (totalBytesRead < len && audioInput.state() != QAudio::StoppedState) { - QTRY_VERIFY_WITH_TIMEOUT(audioInput.bytesAvailable() > 0, 1000); + QTRY_VERIFY(audioInput.bytesAvailable() > 0); auto buffer = feed->readAll(); audioFile->write(buffer); totalBytesRead += buffer.size(); @@ -671,7 +671,7 @@ void tst_QAudioInput::pushSuspendResume() QString("didn't emit StoppedState signal after stop(), got %1 signals instead").arg(stateSignal.count()).toUtf8().constData()); QVERIFY2((audioInput.state() == QAudio::StoppedState), "didn't transitions to StoppedState after stop()"); - QVERIFY2(qTolerantCompare(processedUs, 240000LL), + QVERIFY2(qTolerantCompare(processedUs, 1000000LL), QString("processedUSecs() doesn't fall in acceptable range, should be 2040000 (%1)").arg(processedUs).toUtf8().constData()); QVERIFY2((audioInput.elapsedUSecs() == (qint64)0), "elapsedUSecs() not equal to zero in StoppedState"); |