summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-06-14 15:42:59 +0200
committerLars Knoll <lars.knoll@qt.io>2021-06-17 23:13:28 +0200
commitaf1182b5e29afa0cd69f929d54da224019707214 (patch)
tree45c04b63af92bc43d7125494284a2347c9ae7dab /tests
parent0bd8c0a36e8ccff03af7f6990298238455443ec4 (diff)
Fix the QAudioDecoder API
Adjust API after code review. Remove the audioFormat property. QAudioDecoder will now always decode to the native format used in the encoded file. QAudioBuffer will have the correct format set, and it's up to the app to handle this correctly. Remove state() and replace by isDecoding(). Change-Id: I6f2ac375d98b2d7c36aebaa729599f78699b1c7b Reviewed-by: André de la Rocha <andre.rocha@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Doris Verria <doris.verria@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp221
-rw-r--r--tests/auto/unit/mockbackend/qmockaudiodecoder.h32
-rw-r--r--tests/auto/unit/multimedia/qaudiodecoder/tst_qaudiodecoder.cpp71
3 files changed, 65 insertions, 259 deletions
diff --git a/tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp b/tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp
index 8a948e905..5e32efa16 100644
--- a/tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp
+++ b/tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp
@@ -72,7 +72,7 @@ void tst_QAudioDecoderBackend::init()
void tst_QAudioDecoderBackend::initTestCase()
{
QAudioDecoder d;
- if (!d.isAvailable())
+ if (!d.isSupported())
QSKIP("Audio decoder service is not available");
}
@@ -102,30 +102,29 @@ void tst_QAudioDecoderBackend::fileTest()
int byteCount = 0;
int sampleCount = 0;
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
QCOMPARE(d.source(), QString(""));
- QVERIFY(d.audioFormat() == QAudioFormat());
// Test local file
QFileInfo fileInfo(QFINDTESTDATA(TEST_FILE_NAME));
QUrl url = QUrl::fromLocalFile(fileInfo.absoluteFilePath());
d.setSource(url);
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(!d.bufferAvailable());
QCOMPARE(d.source(), url);
QSignalSpy readySpy(&d, SIGNAL(bufferReady()));
QSignalSpy bufferChangedSpy(&d, SIGNAL(bufferAvailableChanged(bool)));
QSignalSpy errorSpy(&d, SIGNAL(error(QAudioDecoder::Error)));
- QSignalSpy stateSpy(&d, SIGNAL(stateChanged(QAudioDecoder::State)));
+ QSignalSpy isDecodingSpy(&d, SIGNAL(isDecodingChanged(bool)));
QSignalSpy durationSpy(&d, SIGNAL(durationChanged(qint64)));
QSignalSpy finishedSpy(&d, SIGNAL(finished()));
QSignalSpy positionSpy(&d, SIGNAL(positionChanged(qint64)));
d.start();
- QTRY_VERIFY(d.state() == QAudioDecoder::DecodingState);
- QTRY_VERIFY(!stateSpy.isEmpty());
+ QTRY_VERIFY(d.isDecoding());
+ QTRY_VERIFY(!isDecodingSpy.isEmpty());
QTRY_VERIFY(!readySpy.isEmpty());
QTRY_VERIFY(!bufferChangedSpy.isEmpty());
QVERIFY(d.bufferAvailable());
@@ -141,11 +140,6 @@ void tst_QAudioDecoderBackend::fileTest()
QCOMPARE(buffer.format().sampleFormat(), QAudioFormat::Int16);
QCOMPARE(buffer.byteCount(), buffer.sampleCount() * 2); // 16bit mono
- // This does not make a lot of sense
- // The decoder's audioFormat() should report the actual buffer format?
- // // The decoder should still have no format set
- // QVERIFY(d.audioFormat() == QAudioFormat());
-
QVERIFY(errorSpy.isEmpty());
duration += buffer.duration();
@@ -179,94 +173,10 @@ void tst_QAudioDecoderBackend::fileTest()
QVERIFY(qAbs((d.position() + (buffer.duration() / 1000)) - 1000) < 20);
QTRY_COMPARE(finishedSpy.count(), 1);
QVERIFY(!d.bufferAvailable());
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
-
- d.stop();
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
- QTRY_COMPARE(durationSpy.count(), 2);
- QCOMPARE(d.duration(), qint64(-1));
- QVERIFY(!d.bufferAvailable());
- readySpy.clear();
- bufferChangedSpy.clear();
- stateSpy.clear();
- durationSpy.clear();
- finishedSpy.clear();
- positionSpy.clear();
-
- // change output audio format
- QAudioFormat format;
- format.setChannelCount(2);
- format.setSampleRate(11050);
- format.setSampleFormat(QAudioFormat::UInt8);
-
- d.setAudioFormat(format);
-
- // We expect 1 second still, at 11050 * 2 samples == 22k samples.
- // (at 1 byte/sample -> 22kb)
-
- // Make sure it stuck
- QVERIFY(d.audioFormat() == format);
-
- duration = 0;
- sampleCount = 0;
- byteCount = 0;
-
- d.start();
- QTRY_VERIFY(d.state() == QAudioDecoder::DecodingState);
- QTRY_VERIFY(!stateSpy.isEmpty());
- QTRY_VERIFY(!readySpy.isEmpty());
- QTRY_VERIFY(!bufferChangedSpy.isEmpty());
- QVERIFY(d.bufferAvailable());
- QTRY_VERIFY(!durationSpy.isEmpty());
- QVERIFY(qAbs(d.duration() - 1000) < 20);
-
- buffer = d.read();
- QVERIFY(buffer.isValid());
- // See if we got the right format
- QVERIFY(buffer.format() == format);
-
- // The decoder should still have the same format
- QVERIFY(d.audioFormat() == format);
-
- QVERIFY(errorSpy.isEmpty());
-
- duration += buffer.duration();
- sampleCount += buffer.sampleCount();
- byteCount += buffer.byteCount();
-
- // Now drain the decoder
- if (duration < 998000) {
- QTRY_COMPARE(d.bufferAvailable(), true);
- }
-
- while (d.bufferAvailable()) {
- buffer = d.read();
- QVERIFY(buffer.isValid());
- QTRY_VERIFY(!positionSpy.isEmpty());
- QVERIFY(positionSpy.takeLast().at(0).toLongLong() == qint64(duration / 1000));
- QVERIFY(d.position() - (duration / 1000) < 20);
-
- duration += buffer.duration();
- sampleCount += buffer.sampleCount();
- byteCount += buffer.byteCount();
-
- if (duration < 998000) {
- QTRY_COMPARE(d.bufferAvailable(), true);
- }
- }
-
- // Resampling might end up with fewer or more samples
- // so be a bit sloppy
- QVERIFY(qAbs(sampleCount - 22047) < 100);
- QVERIFY(qAbs(byteCount - 22047) < 100);
- QVERIFY(qAbs(qint64(duration) - 1000000) < 20000);
- QVERIFY(qAbs((d.position() + (buffer.duration() / 1000)) - 1000) < 20);
- QTRY_COMPARE(finishedSpy.count(), 1);
- QVERIFY(!d.bufferAvailable());
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
d.stop();
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QTRY_COMPARE(durationSpy.count(), 2);
QCOMPARE(d.duration(), qint64(-1));
QVERIFY(!d.bufferAvailable());
@@ -282,31 +192,29 @@ void tst_QAudioDecoderBackend::unsupportedFileTest()
QSKIP("There is no audio decoding support on this platform.");
QAudioBuffer buffer;
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
QCOMPARE(d.source(), QString(""));
- QVERIFY(d.audioFormat() == QAudioFormat());
// Test local file
QFileInfo fileInfo(QFINDTESTDATA(TEST_UNSUPPORTED_FILE_NAME));
QUrl url = QUrl::fromLocalFile(fileInfo.absoluteFilePath());
d.setSource(url);
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(!d.bufferAvailable());
QCOMPARE(d.source(), url);
QSignalSpy readySpy(&d, SIGNAL(bufferReady()));
QSignalSpy bufferChangedSpy(&d, SIGNAL(bufferAvailableChanged(bool)));
QSignalSpy errorSpy(&d, SIGNAL(error(QAudioDecoder::Error)));
- QSignalSpy stateSpy(&d, SIGNAL(stateChanged(QAudioDecoder::State)));
+ QSignalSpy isDecodingSpy(&d, SIGNAL(isDecodingChanged(bool)));
QSignalSpy durationSpy(&d, SIGNAL(durationChanged(qint64)));
QSignalSpy finishedSpy(&d, SIGNAL(finished()));
QSignalSpy positionSpy(&d, SIGNAL(positionChanged(qint64)));
d.start();
- QTRY_VERIFY(d.state() == QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QVERIFY(!d.bufferAvailable());
- QCOMPARE(d.audioFormat(), QAudioFormat());
QCOMPARE(d.duration(), qint64(-1));
QCOMPARE(d.position(), qint64(-1));
@@ -321,7 +229,7 @@ void tst_QAudioDecoderBackend::unsupportedFileTest()
// Check all other spies.
QVERIFY(readySpy.isEmpty());
QVERIFY(bufferChangedSpy.isEmpty());
- QVERIFY(stateSpy.isEmpty());
+ QVERIFY(isDecodingSpy.isEmpty());
QVERIFY(finishedSpy.isEmpty());
QVERIFY(positionSpy.isEmpty());
QVERIFY(durationSpy.isEmpty());
@@ -330,7 +238,7 @@ void tst_QAudioDecoderBackend::unsupportedFileTest()
// Try read even if the file is not supported to test robustness.
buffer = d.read();
- QTRY_VERIFY(d.state() == QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QVERIFY(!buffer.isValid());
QVERIFY(!d.bufferAvailable());
QCOMPARE(d.position(), qint64(-1));
@@ -338,14 +246,14 @@ void tst_QAudioDecoderBackend::unsupportedFileTest()
QVERIFY(errorSpy.isEmpty());
QVERIFY(readySpy.isEmpty());
QVERIFY(bufferChangedSpy.isEmpty());
- QVERIFY(stateSpy.isEmpty());
+ QVERIFY(isDecodingSpy.isEmpty());
QVERIFY(finishedSpy.isEmpty());
QVERIFY(positionSpy.isEmpty());
QVERIFY(durationSpy.isEmpty());
d.stop();
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QCOMPARE(d.duration(), qint64(-1));
QVERIFY(!d.bufferAvailable());
}
@@ -361,31 +269,29 @@ void tst_QAudioDecoderBackend::corruptedFileTest()
QSKIP("There is no audio decoding support on this platform.");
QAudioBuffer buffer;
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
QCOMPARE(d.source(), QUrl());
- QVERIFY(d.audioFormat() == QAudioFormat());
// Test local file
QFileInfo fileInfo(QFINDTESTDATA(TEST_CORRUPTED_FILE_NAME));
QUrl url = QUrl::fromLocalFile(fileInfo.absoluteFilePath());
d.setSource(url);
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(!d.bufferAvailable());
QCOMPARE(d.source(), url);
QSignalSpy readySpy(&d, SIGNAL(bufferReady()));
QSignalSpy bufferChangedSpy(&d, SIGNAL(bufferAvailableChanged(bool)));
QSignalSpy errorSpy(&d, SIGNAL(error(QAudioDecoder::Error)));
- QSignalSpy stateSpy(&d, SIGNAL(stateChanged(QAudioDecoder::State)));
+ QSignalSpy isDecodingSpy(&d, SIGNAL(isDecodingChanged(bool)));
QSignalSpy durationSpy(&d, SIGNAL(durationChanged(qint64)));
QSignalSpy finishedSpy(&d, SIGNAL(finished()));
QSignalSpy positionSpy(&d, SIGNAL(positionChanged(qint64)));
d.start();
- QTRY_VERIFY(d.state() == QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QVERIFY(!d.bufferAvailable());
- QCOMPARE(d.audioFormat(), QAudioFormat());
QCOMPARE(d.duration(), qint64(-1));
QCOMPARE(d.position(), qint64(-1));
@@ -400,7 +306,7 @@ void tst_QAudioDecoderBackend::corruptedFileTest()
// Check all other spies.
QVERIFY(readySpy.isEmpty());
QVERIFY(bufferChangedSpy.isEmpty());
- QVERIFY(stateSpy.isEmpty());
+ QVERIFY(isDecodingSpy.isEmpty());
QVERIFY(finishedSpy.isEmpty());
QVERIFY(positionSpy.isEmpty());
QVERIFY(durationSpy.isEmpty());
@@ -409,7 +315,7 @@ void tst_QAudioDecoderBackend::corruptedFileTest()
// Try read even if the file is corrupted to test the robustness.
buffer = d.read();
- QTRY_VERIFY(d.state() == QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QVERIFY(!buffer.isValid());
QVERIFY(!d.bufferAvailable());
QCOMPARE(d.position(), qint64(-1));
@@ -417,14 +323,14 @@ void tst_QAudioDecoderBackend::corruptedFileTest()
QVERIFY(errorSpy.isEmpty());
QVERIFY(readySpy.isEmpty());
QVERIFY(bufferChangedSpy.isEmpty());
- QVERIFY(stateSpy.isEmpty());
+ QVERIFY(isDecodingSpy.isEmpty());
QVERIFY(finishedSpy.isEmpty());
QVERIFY(positionSpy.isEmpty());
QVERIFY(durationSpy.isEmpty());
d.stop();
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QCOMPARE(d.duration(), qint64(-1));
QVERIFY(!d.bufferAvailable());
}
@@ -436,31 +342,29 @@ void tst_QAudioDecoderBackend::invalidSource()
QSKIP("There is no audio decoding support on this platform.");
QAudioBuffer buffer;
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
QCOMPARE(d.source(), QUrl());
- QVERIFY(d.audioFormat() == QAudioFormat());
// Test invalid file source
QFileInfo fileInfo(TEST_INVALID_SOURCE);
QUrl url = QUrl::fromLocalFile(fileInfo.absoluteFilePath());
d.setSource(url);
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(!d.bufferAvailable());
QCOMPARE(d.source(), url);
QSignalSpy readySpy(&d, SIGNAL(bufferReady()));
QSignalSpy bufferChangedSpy(&d, SIGNAL(bufferAvailableChanged(bool)));
QSignalSpy errorSpy(&d, SIGNAL(error(QAudioDecoder::Error)));
- QSignalSpy stateSpy(&d, SIGNAL(stateChanged(QAudioDecoder::State)));
+ QSignalSpy isDecodingSpy(&d, SIGNAL(isDecodingChanged(bool)));
QSignalSpy durationSpy(&d, SIGNAL(durationChanged(qint64)));
QSignalSpy finishedSpy(&d, SIGNAL(finished()));
QSignalSpy positionSpy(&d, SIGNAL(positionChanged(qint64)));
d.start();
- QTRY_VERIFY(d.state() == QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QVERIFY(!d.bufferAvailable());
- QCOMPARE(d.audioFormat(), QAudioFormat());
QCOMPARE(d.duration(), qint64(-1));
QCOMPARE(d.position(), qint64(-1));
@@ -475,7 +379,7 @@ void tst_QAudioDecoderBackend::invalidSource()
// Check all other spies.
QVERIFY(readySpy.isEmpty());
QVERIFY(bufferChangedSpy.isEmpty());
- QVERIFY(stateSpy.isEmpty());
+ QVERIFY(isDecodingSpy.isEmpty());
QVERIFY(finishedSpy.isEmpty());
QVERIFY(positionSpy.isEmpty());
QVERIFY(durationSpy.isEmpty());
@@ -483,7 +387,7 @@ void tst_QAudioDecoderBackend::invalidSource()
errorSpy.clear();
d.stop();
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QCOMPARE(d.duration(), qint64(-1));
QVERIFY(!d.bufferAvailable());
@@ -493,9 +397,8 @@ void tst_QAudioDecoderBackend::invalidSource()
d.setSourceDevice(&file);
d.start();
- QTRY_VERIFY(d.state() == QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QVERIFY(!d.bufferAvailable());
- QCOMPARE(d.audioFormat(), QAudioFormat());
QCOMPARE(d.duration(), qint64(-1));
QCOMPARE(d.position(), qint64(-1));
@@ -508,7 +411,7 @@ void tst_QAudioDecoderBackend::invalidSource()
// Check all other spies.
QVERIFY(readySpy.isEmpty());
QVERIFY(bufferChangedSpy.isEmpty());
- QVERIFY(stateSpy.isEmpty());
+ QVERIFY(isDecodingSpy.isEmpty());
QVERIFY(finishedSpy.isEmpty());
QVERIFY(positionSpy.isEmpty());
QVERIFY(durationSpy.isEmpty());
@@ -516,7 +419,7 @@ void tst_QAudioDecoderBackend::invalidSource()
errorSpy.clear();
d.stop();
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QCOMPARE(d.duration(), qint64(-1));
QVERIFY(!d.bufferAvailable());
}
@@ -536,15 +439,14 @@ void tst_QAudioDecoderBackend::deviceTest()
QSignalSpy readySpy(&d, SIGNAL(bufferReady()));
QSignalSpy bufferChangedSpy(&d, SIGNAL(bufferAvailableChanged(bool)));
QSignalSpy errorSpy(&d, SIGNAL(error(QAudioDecoder::Error)));
- QSignalSpy stateSpy(&d, SIGNAL(stateChanged(QAudioDecoder::State)));
+ QSignalSpy isDecodingSpy(&d, SIGNAL(isDecodingChanged(bool)));
QSignalSpy durationSpy(&d, SIGNAL(durationChanged(qint64)));
QSignalSpy finishedSpy(&d, SIGNAL(finished()));
QSignalSpy positionSpy(&d, SIGNAL(positionChanged(qint64)));
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
QCOMPARE(d.source(), QString(""));
- QVERIFY(d.audioFormat() == QAudioFormat());
QFileInfo fileInfo(QFINDTESTDATA(TEST_FILE_NAME));
QFile file(fileInfo.absoluteFilePath());
@@ -554,13 +456,10 @@ void tst_QAudioDecoderBackend::deviceTest()
QVERIFY(d.sourceDevice() == &file);
QVERIFY(d.source().isEmpty());
- // We haven't set the format yet
- QVERIFY(d.audioFormat() == QAudioFormat());
-
d.start();
- QTRY_VERIFY(d.state() == QAudioDecoder::DecodingState);
- QTRY_VERIFY(!stateSpy.isEmpty());
+ QTRY_VERIFY(d.isDecoding());
+ QTRY_VERIFY(!isDecodingSpy.isEmpty());
QTRY_VERIFY(!readySpy.isEmpty());
QTRY_VERIFY(!bufferChangedSpy.isEmpty());
QVERIFY(d.bufferAvailable());
@@ -605,52 +504,10 @@ void tst_QAudioDecoderBackend::deviceTest()
QVERIFY(qAbs((d.position() + (buffer.duration() / 1000)) - 1000) < 20);
QTRY_COMPARE(finishedSpy.count(), 1);
QVERIFY(!d.bufferAvailable());
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
-
- d.stop();
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
- QVERIFY(!d.bufferAvailable());
- QTRY_COMPARE(durationSpy.count(), 2);
- QCOMPARE(d.duration(), qint64(-1));
- readySpy.clear();
- bufferChangedSpy.clear();
- stateSpy.clear();
- durationSpy.clear();
- finishedSpy.clear();
- positionSpy.clear();
-
- // Now try changing formats
- QAudioFormat format;
- format.setChannelCount(2);
- format.setSampleRate(8000);
- format.setSampleFormat(QAudioFormat::UInt8);
-
- d.setAudioFormat(format);
-
- // Make sure it stuck
- QVERIFY(d.audioFormat() == format);
-
- d.start();
- QTRY_VERIFY(d.state() == QAudioDecoder::DecodingState);
- QTRY_VERIFY(!stateSpy.isEmpty());
- QTRY_VERIFY(!readySpy.isEmpty());
- QTRY_VERIFY(!bufferChangedSpy.isEmpty());
- QVERIFY(d.bufferAvailable());
- QTRY_VERIFY(!durationSpy.isEmpty());
- QVERIFY(qAbs(d.duration() - 1000) < 20);
-
- buffer = d.read();
- QVERIFY(buffer.isValid());
- // See if we got the right format
- QVERIFY(buffer.format() == format);
-
- // The decoder should still have the same format
- QVERIFY(d.audioFormat() == format);
-
- QVERIFY(errorSpy.isEmpty());
+ QTRY_VERIFY(!d.isDecoding());
d.stop();
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QVERIFY(!d.bufferAvailable());
QTRY_COMPARE(durationSpy.count(), 2);
QCOMPARE(d.duration(), qint64(-1));
diff --git a/tests/auto/unit/mockbackend/qmockaudiodecoder.h b/tests/auto/unit/mockbackend/qmockaudiodecoder.h
index 24cd98756..a106a83d2 100644
--- a/tests/auto/unit/mockbackend/qmockaudiodecoder.h
+++ b/tests/auto/unit/mockbackend/qmockaudiodecoder.h
@@ -49,7 +49,6 @@ class QMockAudioDecoder : public QPlatformAudioDecoder
public:
QMockAudioDecoder(QAudioDecoder *parent = 0)
: QPlatformAudioDecoder(parent)
- , mState(QAudioDecoder::StoppedState)
, mDevice(0)
, mPosition(-1)
, mSerial(0)
@@ -59,29 +58,11 @@ public:
mFormat.setSampleRate(1000);
}
- QAudioDecoder::State state() const
- {
- return mState;
- }
-
QUrl source() const
{
return mSource;
}
- QAudioFormat audioFormat() const
- {
- return mFormat;
- }
-
- void setAudioFormat(const QAudioFormat &format)
- {
- if (mFormat != format) {
- mFormat = format;
- emit formatChanged(mFormat);
- }
- }
-
void setSource(const QUrl &fileName)
{
mSource = fileName;
@@ -106,10 +87,9 @@ public:
// 5 buffers
void start()
{
- if (mState == QAudioDecoder::StoppedState) {
+ if (!isDecoding()) {
if (!mSource.isEmpty()) {
- mState = QAudioDecoder::DecodingState;
- emit stateChanged(mState);
+ setIsDecoding(true);
emit durationChanged(duration());
QTimer::singleShot(50, this, SLOT(pretendDecode()));
@@ -121,12 +101,11 @@ public:
void stop()
{
- if (mState != QAudioDecoder::StoppedState) {
- mState = QAudioDecoder::StoppedState;
+ if (isDecoding()) {
mSerial = 0;
mPosition = 0;
mBuffers.clear();
- emit stateChanged(mState);
+ setIsDecoding(false);
emit bufferAvailableChanged(false);
}
}
@@ -143,9 +122,7 @@ public:
emit bufferAvailableChanged(false);
if (mBuffers.isEmpty() && mSerial >= MOCK_DECODER_MAX_BUFFERS) {
- mState = QAudioDecoder::StoppedState;
emit finished();
- emit stateChanged(mState);
} else
QTimer::singleShot(50, this, SLOT(pretendDecode()));
}
@@ -189,7 +166,6 @@ private slots:
}
public:
- QAudioDecoder::State mState;
QUrl mSource;
QIODevice *mDevice;
QAudioFormat mFormat;
diff --git a/tests/auto/unit/multimedia/qaudiodecoder/tst_qaudiodecoder.cpp b/tests/auto/unit/multimedia/qaudiodecoder/tst_qaudiodecoder.cpp
index cd404d448..1c200cb21 100644
--- a/tests/auto/unit/multimedia/qaudiodecoder/tst_qaudiodecoder.cpp
+++ b/tests/auto/unit/multimedia/qaudiodecoder/tst_qaudiodecoder.cpp
@@ -61,12 +61,12 @@ tst_QAudioDecoder::tst_QAudioDecoder()
void tst_QAudioDecoder::ctors()
{
QAudioDecoder d;
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
QCOMPARE(d.source(), QString(""));
d.setSource(QUrl());
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
QCOMPARE(d.source(), QUrl());
}
@@ -74,7 +74,7 @@ void tst_QAudioDecoder::ctors()
void tst_QAudioDecoder::read()
{
QAudioDecoder d;
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
QSignalSpy readySpy(&d, SIGNAL(bufferReady()));
@@ -84,7 +84,7 @@ void tst_QAudioDecoder::read()
// Starting with empty source == error
d.start();
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
QCOMPARE(readySpy.count(), 0);
@@ -100,7 +100,7 @@ void tst_QAudioDecoder::read()
bufferChangedSpy.clear();
d.start();
- QCOMPARE(d.state(), QAudioDecoder::DecodingState);
+ QVERIFY(d.isDecoding());
QCOMPARE(d.bufferAvailable(), false); // not yet
// Try to read
@@ -135,7 +135,7 @@ void tst_QAudioDecoder::read()
void tst_QAudioDecoder::stop()
{
QAudioDecoder d;
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
QSignalSpy readySpy(&d, SIGNAL(bufferReady()));
@@ -145,7 +145,7 @@ void tst_QAudioDecoder::stop()
// Starting with empty source == error
d.start();
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
QCOMPARE(readySpy.count(), 0);
@@ -161,7 +161,7 @@ void tst_QAudioDecoder::stop()
bufferChangedSpy.clear();
d.start();
- QCOMPARE(d.state(), QAudioDecoder::DecodingState);
+ QVERIFY(d.isDecoding());
QCOMPARE(d.bufferAvailable(), false); // not yet
// Try to read
@@ -180,14 +180,14 @@ void tst_QAudioDecoder::stop()
// Now stop
d.stop();
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
}
void tst_QAudioDecoder::format()
{
QAudioDecoder d;
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
QSignalSpy readySpy(&d, SIGNAL(bufferReady()));
@@ -203,7 +203,7 @@ void tst_QAudioDecoder::format()
bufferChangedSpy.clear();
d.start();
- QCOMPARE(d.state(), QAudioDecoder::DecodingState);
+ QVERIFY(d.isDecoding());
QCOMPARE(d.bufferAvailable(), false); // not yet
// Try to read
@@ -218,28 +218,7 @@ void tst_QAudioDecoder::format()
QTRY_VERIFY(d.bufferAvailable());
b = d.read();
- QVERIFY(d.audioFormat() == b.format());
-
- // Setting format while decoding is forbidden
- QAudioFormat f(d.audioFormat());
- f.setChannelCount(2);
-
- d.setAudioFormat(f);
- QVERIFY(d.audioFormat() != f);
- QVERIFY(d.audioFormat() == b.format());
-
- // Now stop, and set something specific
- d.stop();
- d.setAudioFormat(f);
- QVERIFY(d.audioFormat() == f);
-
- // Decode again
- d.start();
- QTRY_VERIFY(d.bufferAvailable());
-
- b = d.read();
- QVERIFY(d.audioFormat() == f);
- QVERIFY(b.format() == f);
+ QVERIFY(b.format().isValid());
}
void tst_QAudioDecoder::source()
@@ -275,18 +254,18 @@ void tst_QAudioDecoder::readAll()
{
QAudioDecoder d;
d.setSource(QUrl::fromLocalFile("Foo"));
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QSignalSpy durationSpy(&d, SIGNAL(durationChanged(qint64)));
QSignalSpy positionSpy(&d, SIGNAL(positionChanged(qint64)));
- QSignalSpy stateSpy(&d, SIGNAL(stateChanged(QAudioDecoder::State)));
+ QSignalSpy isDecodingSpy(&d, SIGNAL(isDecodingChanged(bool)));
QSignalSpy finishedSpy(&d, SIGNAL(finished()));
QSignalSpy bufferAvailableSpy(&d, SIGNAL(bufferAvailableChanged(bool)));
d.start();
int i = 0;
forever {
- QVERIFY(d.state() == QAudioDecoder::DecodingState);
- QCOMPARE(stateSpy.count(), 1);
+ QVERIFY(d.isDecoding());
+ QCOMPARE(isDecodingSpy.count(), 1);
QCOMPARE(durationSpy.count(), 1);
QVERIFY(finishedSpy.isEmpty());
QTRY_VERIFY(bufferAvailableSpy.count() >= 1);
@@ -301,10 +280,10 @@ void tst_QAudioDecoder::readAll()
i++;
if (i == MOCK_DECODER_MAX_BUFFERS) {
QCOMPARE(finishedSpy.count(), 1);
- QCOMPARE(stateSpy.count(), 2);
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
- QList<QVariant> arguments = stateSpy.takeLast();
- QVERIFY(arguments.at(0).toInt() == (int)QAudioDecoder::StoppedState);
+ QCOMPARE(isDecodingSpy.count(), 2);
+ QVERIFY(!d.isDecoding());
+ QList<QVariant> arguments = isDecodingSpy.takeLast();
+ QVERIFY(arguments.at(0).toBool() == false);
QVERIFY(!d.bufferAvailable());
QVERIFY(!bufferAvailableSpy.isEmpty());
arguments = bufferAvailableSpy.takeLast();
@@ -324,7 +303,7 @@ void tst_QAudioDecoder::nullControl()
QVERIFY(d.error() == QAudioDecoder::NotSupportedError);
QVERIFY(!d.errorString().isEmpty());
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.source().isEmpty());
d.setSource(QUrl::fromLocalFile("test"));
@@ -335,12 +314,6 @@ void tst_QAudioDecoder::nullControl()
d.setSourceDevice(&f);
QVERIFY(d.sourceDevice() == nullptr);
- QAudioFormat format;
- format.setChannelCount(2);
- QVERIFY(!d.audioFormat().isValid());
- d.setAudioFormat(format);
- QVERIFY(!d.audioFormat().isValid());
-
QVERIFY(!d.read().isValid());
QVERIFY(!d.bufferAvailable());
@@ -350,7 +323,7 @@ void tst_QAudioDecoder::nullControl()
d.start();
QVERIFY(d.error() == QAudioDecoder::NotSupportedError);
QVERIFY(!d.errorString().isEmpty());
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
d.stop();
}