summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--examples/multimedia/audiodecoder/audiodecoder.cpp36
-rw-r--r--examples/multimedia/audiodecoder/audiodecoder.h2
-rw-r--r--src/multimedia/audio/qaudiodecoder.cpp56
-rw-r--r--src/multimedia/audio/qaudiodecoder.h21
-rw-r--r--src/multimedia/platform/darwin/audio/avfaudiodecoder.mm51
-rw-r--r--src/multimedia/platform/darwin/audio/avfaudiodecoder_p.h10
-rw-r--r--src/multimedia/platform/gstreamer/audio/qgstreameraudiodecoder.cpp53
-rw-r--r--src/multimedia/platform/gstreamer/audio/qgstreameraudiodecoder_p.h11
-rw-r--r--src/multimedia/platform/gstreamer/common/qgstutils.cpp10
-rw-r--r--src/multimedia/platform/gstreamer/common/qgstutils_p.h1
-rw-r--r--src/multimedia/platform/qplatformaudiodecoder.cpp36
-rw-r--r--src/multimedia/platform/qplatformaudiodecoder_p.h16
-rw-r--r--src/multimedia/platform/windows/decoder/mfaudiodecodercontrol.cpp235
-rw-r--r--src/multimedia/platform/windows/decoder/mfaudiodecodercontrol_p.h10
-rw-r--r--src/multimedia/platform/windows/decoder/mfdecodersourcereader.cpp9
-rw-r--r--src/multimedia/platform/windows/decoder/mfdecodersourcereader_p.h2
-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
19 files changed, 174 insertions, 709 deletions
diff --git a/examples/multimedia/audiodecoder/audiodecoder.cpp b/examples/multimedia/audiodecoder/audiodecoder.cpp
index 891499ea2..f3492a52a 100644
--- a/examples/multimedia/audiodecoder/audiodecoder.cpp
+++ b/examples/multimedia/audiodecoder/audiodecoder.cpp
@@ -59,24 +59,12 @@ AudioDecoder::AudioDecoder(bool isPlayback, bool isDelete, const QString &target
m_isPlayback = isPlayback;
m_isDelete = isDelete;
- // Make sure the data we receive is in correct PCM format.
- // Our wav file writer only supports SignedInt sample type.
- QAudioFormat format;
- format.setChannelCount(2);
- format.setSampleFormat(QAudioFormat::Int16);
- format.setSampleRate(48000);
- m_decoder.setAudioFormat(format);
-
- QIODevice* target = new QFile(targetFileName, this);
- if (target->open(QIODevice::WriteOnly))
- m_waveDecoder = new QWaveDecoder(target, format);
-
connect(&m_decoder, &QAudioDecoder::bufferReady,
this, &AudioDecoder::bufferReady);
connect(&m_decoder, QOverload<QAudioDecoder::Error>::of(&QAudioDecoder::error),
this, QOverload<QAudioDecoder::Error>::of(&AudioDecoder::error));
- connect(&m_decoder, &QAudioDecoder::stateChanged,
- this, &AudioDecoder::stateChanged);
+ connect(&m_decoder, &QAudioDecoder::isDecodingChanged,
+ this, &AudioDecoder::isDecodingChanged);
connect(&m_decoder, &QAudioDecoder::finished,
this, &AudioDecoder::finished);
connect(&m_decoder, &QAudioDecoder::positionChanged,
@@ -129,6 +117,16 @@ void AudioDecoder::bufferReady()
if (!buffer.isValid())
return;
+ if (!m_waveDecoder) {
+ QIODevice* target = new QFile(m_targetFilename, this);
+ if (!target->open(QIODevice::WriteOnly)) {
+ qWarning() << "target file is not writable";
+ m_decoder.stop();
+ return;
+ }
+ m_waveDecoder = new QWaveDecoder(target, buffer.format());
+ }
+
if (!m_waveDecoder || (!m_waveDecoder->isOpen()
&& !m_waveDecoder->open(QIODevice::WriteOnly))) {
m_decoder.stop();
@@ -160,16 +158,12 @@ void AudioDecoder::error(QAudioDecoder::Error error)
emit done();
}
-void AudioDecoder::stateChanged(QAudioDecoder::State newState)
+void AudioDecoder::isDecodingChanged(bool isDecoding)
{
- switch (newState) {
- case QAudioDecoder::DecodingState:
+ if (isDecoding)
m_cout << "Decoding...\n";
- break;
- case QAudioDecoder::StoppedState:
+ else
m_cout << "Decoding stopped\n";
- break;
- }
}
void AudioDecoder::finished()
diff --git a/examples/multimedia/audiodecoder/audiodecoder.h b/examples/multimedia/audiodecoder/audiodecoder.h
index cd27a9bf3..d75eecb8d 100644
--- a/examples/multimedia/audiodecoder/audiodecoder.h
+++ b/examples/multimedia/audiodecoder/audiodecoder.h
@@ -78,7 +78,7 @@ signals:
public slots:
void bufferReady();
void error(QAudioDecoder::Error error);
- void stateChanged(QAudioDecoder::State newState);
+ void isDecodingChanged(bool isDecoding);
void finished();
void playbackStatusChanged();
diff --git a/src/multimedia/audio/qaudiodecoder.cpp b/src/multimedia/audio/qaudiodecoder.cpp
index 9c2c3bc36..8b8db59ba 100644
--- a/src/multimedia/audio/qaudiodecoder.cpp
+++ b/src/multimedia/audio/qaudiodecoder.cpp
@@ -89,17 +89,17 @@ QAudioDecoder::~QAudioDecoder() = default;
/*!
Returns true is audio decoding is supported on this platform.
*/
-bool QAudioDecoder::isAvailable() const
+bool QAudioDecoder::isSupported() const
{
return decoder != nullptr;
}
/*!
- Returns the current state of the audio decoder.
+ Returns true if the decoder is currently running and decoding audio data.
*/
-QAudioDecoder::State QAudioDecoder::state() const
+bool QAudioDecoder::isDecoding() const
{
- return decoder ? decoder->state() : QAudioDecoder::StoppedState;
+ return decoder && decoder->isDecoding();
}
/*!
@@ -151,8 +151,10 @@ void QAudioDecoder::start()
*/
void QAudioDecoder::stop()
{
- if (decoder != nullptr)
- decoder->stop();
+ if (!decoder)
+ return;
+
+ decoder->stop();
}
/*!
@@ -207,47 +209,9 @@ QIODevice *QAudioDecoder::sourceDevice() const
*/
void QAudioDecoder::setSourceDevice(QIODevice *device)
{
- if (decoder != nullptr)
- decoder->setSourceDevice(device);
-}
-
-/*!
- Returns the current audio format of the decoded stream.
-
- Any buffers returned should have this format.
-
- \sa setAudioFormat(), formatChanged()
-*/
-QAudioFormat QAudioDecoder::audioFormat() const
-{
- if (decoder)
- return decoder->audioFormat();
- return QAudioFormat();
-}
-
-/*!
- Set the desired audio format for decoded samples to \a format.
-
- This property can only be set while the decoder is stopped.
- Setting this property at other times will be ignored.
-
- If the decoder does not support this format, \l error() will
- be set to \c FormatError.
-
- If you do not specify a format, the format of the decoded
- audio itself will be used. Otherwise, some format conversion
- will be applied.
-
- If you wish to reset the decoded format to that of the original
- audio file, you can specify an invalid \a format.
-*/
-void QAudioDecoder::setAudioFormat(const QAudioFormat &format)
-{
- if (state() != QAudioDecoder::StoppedState)
+ if (!decoder)
return;
-
- if (decoder != nullptr)
- decoder->setAudioFormat(format);
+ decoder->setSourceDevice(device);
}
/*!
diff --git a/src/multimedia/audio/qaudiodecoder.h b/src/multimedia/audio/qaudiodecoder.h
index 9dd257cc9..465bb3974 100644
--- a/src/multimedia/audio/qaudiodecoder.h
+++ b/src/multimedia/audio/qaudiodecoder.h
@@ -52,18 +52,11 @@ class Q_MULTIMEDIA_EXPORT QAudioDecoder : public QObject
{
Q_OBJECT
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
- Q_PROPERTY(State state READ state NOTIFY stateChanged)
+ Q_PROPERTY(bool isDecoding READ isDecoding NOTIFY isDecodingChanged)
Q_PROPERTY(QString error READ errorString)
Q_PROPERTY(bool bufferAvailable READ bufferAvailable NOTIFY bufferAvailableChanged)
public:
- enum State
- {
- StoppedState,
- DecodingState
- };
- Q_ENUM(State)
-
enum Error
{
NoError,
@@ -77,8 +70,8 @@ public:
explicit QAudioDecoder(QObject *parent = nullptr);
~QAudioDecoder();
- bool isAvailable() const;
- State state() const;
+ bool isSupported() const;
+ bool isDecoding() const;
QUrl source() const;
void setSource(const QUrl &fileName);
@@ -86,9 +79,6 @@ public:
QIODevice* sourceDevice() const;
void setSourceDevice(QIODevice *device);
- QAudioFormat audioFormat() const;
- void setAudioFormat(const QAudioFormat &format);
-
Error error() const;
QString errorString() const;
@@ -106,9 +96,7 @@ Q_SIGNALS:
void bufferAvailableChanged(bool);
void bufferReady();
void finished();
-
- void stateChanged(QAudioDecoder::State newState);
- void formatChanged(const QAudioFormat &format);
+ void isDecodingChanged(bool);
void error(QAudioDecoder::Error error);
@@ -124,7 +112,6 @@ private:
QT_END_NAMESPACE
-Q_MEDIA_ENUM_DEBUG(QAudioDecoder, State)
Q_MEDIA_ENUM_DEBUG(QAudioDecoder, Error)
#endif // QAUDIODECODER_H
diff --git a/src/multimedia/platform/darwin/audio/avfaudiodecoder.mm b/src/multimedia/platform/darwin/audio/avfaudiodecoder.mm
index 2ff872212..ecea99f74 100644
--- a/src/multimedia/platform/darwin/audio/avfaudiodecoder.mm
+++ b/src/multimedia/platform/darwin/audio/avfaudiodecoder.mm
@@ -90,7 +90,7 @@ QT_USE_NAMESPACE
return;
const AudioStreamBasicDescription* const asbd = CMAudioFormatDescriptionGetStreamBasicDescription(formatDescription);
QAudioFormat qtFormat = CoreAudioUtils::toQAudioFormat(*asbd);
- if (!qtFormat.isValid() || qtFormat != m_decoder->audioFormat())
+ if (!qtFormat.isValid())
return;
// Get the required size to allocate to audioBufferList
@@ -314,7 +314,7 @@ void AVFAudioDecoder::setSourceDevice(QIODevice *device)
void AVFAudioDecoder::start()
{
Q_ASSERT(!m_buffersAvailable);
- if (m_state != QAudioDecoder::StoppedState)
+ if (isDecoding())
return;
if (m_position != -1) {
@@ -348,16 +348,13 @@ void AVFAudioDecoder::start()
];
if (m_device && m_loadingSource) {
- m_state = QAudioDecoder::DecodingState;
- emit stateChanged(m_state);
+ setIsDecoding(true);
return;
}
}
void AVFAudioDecoder::stop()
{
- QAudioDecoder::State oldState = m_state;
- m_state = QAudioDecoder::StoppedState;
if (m_asset)
[m_asset cancelLoading];
if (m_reader)
@@ -375,21 +372,7 @@ void AVFAudioDecoder::stop()
m_duration = -1;
emit durationChanged(m_duration);
}
- if (m_state != oldState)
- emit stateChanged(m_state);
-}
-
-QAudioFormat AVFAudioDecoder::audioFormat() const
-{
- return m_format;
-}
-
-void AVFAudioDecoder::setAudioFormat(const QAudioFormat &format)
-{
- if (m_format != format) {
- m_format = format;
- emit formatChanged(m_format);
- }
+ setIsDecoding(false);
}
QAudioBuffer AVFAudioDecoder::read()
@@ -444,18 +427,10 @@ void AVFAudioDecoder::initAssetReader()
// Set format
QAudioFormat format;
- if (m_format.isValid()) {
- format = m_format;
- } else {
- format = qt_format_for_audio_track(track);
- if (!format.isValid())
- {
- processInvalidMedia(QAudioDecoder::FormatError, tr("Unsupported source format"));
- return;
- }
- // ### Change QAudioDecoder's format to resolved one?
- m_format = format;
- emit formatChanged(m_format);
+ format = qt_format_for_audio_track(track);
+ if (!format.isValid()) {
+ processInvalidMedia(QAudioDecoder::FormatError, tr("Unsupported source format"));
+ return;
}
// Set duration
@@ -498,10 +473,7 @@ void AVFAudioDecoder::startReading()
return;
}
- QAudioDecoder::State oldState = m_state;
- m_state = QAudioDecoder::DecodingState;
- if (oldState != m_state)
- emit stateChanged(m_state);
+ setIsDecoding(true);
// Since copyNextSampleBuffer is synchronous, submit it to an async dispatch queue
// to run in a separate thread. Call the handleNextSampleBuffer "callback" on another
@@ -515,11 +487,8 @@ void AVFAudioDecoder::startReading()
CFRelease(sampleBuffer);
});
}
- if (m_reader.status == AVAssetReaderStatusCompleted) {
- m_state = QAudioDecoder::StoppedState;
+ if (m_reader.status == AVAssetReaderStatusCompleted)
emit finished();
- emit stateChanged(m_state);
- }
});
}
diff --git a/src/multimedia/platform/darwin/audio/avfaudiodecoder_p.h b/src/multimedia/platform/darwin/audio/avfaudiodecoder_p.h
index 9f302cc39..5348b06fd 100644
--- a/src/multimedia/platform/darwin/audio/avfaudiodecoder_p.h
+++ b/src/multimedia/platform/darwin/audio/avfaudiodecoder_p.h
@@ -75,9 +75,6 @@ public:
AVFAudioDecoder(QAudioDecoder *parent);
virtual ~AVFAudioDecoder();
- // QAudioDecoder interface
- QAudioDecoder::State state() const override { return m_state; }
-
QUrl source() const override;
void setSource(const QUrl &fileName) override;
@@ -87,9 +84,6 @@ public:
void start() override;
void stop() override;
- QAudioFormat audioFormat() const override;
- void setAudioFormat(const QAudioFormat &format) override;
-
QAudioBuffer read() override;
bool bufferAvailable() const override;
@@ -108,12 +102,8 @@ private:
void processInvalidMedia(QAudioDecoder::Error errorCode, const QString& errorString);
void initAssetReader();
- QAudioDecoder::State m_state = QAudioDecoder::StoppedState;
- QAudioDecoder::State m_pendingState = QAudioDecoder::StoppedState;
-
QUrl m_source;
QIODevice *m_device = nullptr;
- QAudioFormat m_format;
int m_buffersAvailable = 0;
QList<QAudioBuffer> m_cachedBuffers;
diff --git a/src/multimedia/platform/gstreamer/audio/qgstreameraudiodecoder.cpp b/src/multimedia/platform/gstreamer/audio/qgstreameraudiodecoder.cpp
index 817e168bf..db23ac80f 100644
--- a/src/multimedia/platform/gstreamer/audio/qgstreameraudiodecoder.cpp
+++ b/src/multimedia/platform/gstreamer/audio/qgstreameraudiodecoder.cpp
@@ -163,21 +163,17 @@ bool QGstreamerAudioDecoder::processBusMessage(const QGstreamerMessage &message)
.arg(states[pending]) << "internal" << m_state;
#endif
- QAudioDecoder::State prevState = m_state;
-
+ bool isDecoding = false;
switch (newState) {
case GST_STATE_VOID_PENDING:
case GST_STATE_NULL:
- m_state = QAudioDecoder::StoppedState;
- break;
case GST_STATE_READY:
- m_state = QAudioDecoder::StoppedState;
break;
case GST_STATE_PLAYING:
- m_state = QAudioDecoder::DecodingState;
+ isDecoding = true;
break;
case GST_STATE_PAUSED:
- m_state = QAudioDecoder::DecodingState;
+ isDecoding = true;
//gstreamer doesn't give a reliable indication the duration
//information is ready, GST_MESSAGE_DURATION is not sent by most elements
@@ -187,15 +183,12 @@ bool QGstreamerAudioDecoder::processBusMessage(const QGstreamerMessage &message)
break;
}
- if (prevState != m_state)
- emit stateChanged(m_state);
+ setIsDecoding(isDecoding);
}
break;
case GST_MESSAGE_EOS:
- m_pendingState = m_state = QAudioDecoder::StoppedState;
- emit finished();
- emit stateChanged(m_state);
+ finished();
break;
case GST_MESSAGE_ERROR: {
@@ -338,24 +331,15 @@ void QGstreamerAudioDecoder::start()
// Set audio format
if (m_appSink) {
- if (mFormat.isValid()) {
- setAudioFlags(false);
- QGstMutableCaps caps = QGstUtils::capsForAudioFormat(mFormat);
- gst_app_sink_set_caps(m_appSink, caps.get());
- } else {
- // We want whatever the native audio format is
- setAudioFlags(true);
- gst_app_sink_set_caps(m_appSink, nullptr);
- }
+ // We want whatever the native audio format is
+ setAudioFlags(true);
+ gst_app_sink_set_caps(m_appSink, nullptr);
}
- m_pendingState = QAudioDecoder::DecodingState;
if (m_playbin.setState(GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
qWarning() << "GStreamer; Unable to start decoding process";
m_playbin.dumpGraph("failed");
- m_pendingState = m_state = QAudioDecoder::StoppedState;
-
- emit stateChanged(m_state);
+ return;
}
}
@@ -367,9 +351,6 @@ void QGstreamerAudioDecoder::stop()
m_playbin.setState(GST_STATE_NULL);
removeAppSink();
- QAudioDecoder::State oldState = m_state;
- m_pendingState = m_state = QAudioDecoder::StoppedState;
-
// GStreamer thread is stopped. Can safely access m_buffersAvailable
if (m_buffersAvailable != 0) {
m_buffersAvailable = 0;
@@ -386,21 +367,7 @@ void QGstreamerAudioDecoder::stop()
emit durationChanged(m_duration);
}
- if (oldState != m_state)
- emit stateChanged(m_state);
-}
-
-QAudioFormat QGstreamerAudioDecoder::audioFormat() const
-{
- return mFormat;
-}
-
-void QGstreamerAudioDecoder::setAudioFormat(const QAudioFormat &format)
-{
- if (mFormat != format) {
- mFormat = format;
- emit formatChanged(mFormat);
- }
+ setIsDecoding(false);
}
QAudioBuffer QGstreamerAudioDecoder::read()
diff --git a/src/multimedia/platform/gstreamer/audio/qgstreameraudiodecoder_p.h b/src/multimedia/platform/gstreamer/audio/qgstreameraudiodecoder_p.h
index be2343916..de9d59baf 100644
--- a/src/multimedia/platform/gstreamer/audio/qgstreameraudiodecoder_p.h
+++ b/src/multimedia/platform/gstreamer/audio/qgstreameraudiodecoder_p.h
@@ -81,9 +81,6 @@ public:
QGstreamerAudioDecoder(QAudioDecoder *parent);
virtual ~QGstreamerAudioDecoder();
- // QAudioDecoder interface
- QAudioDecoder::State state() const override { return m_state; }
-
QUrl source() const override;
void setSource(const QUrl &fileName) override;
@@ -93,9 +90,6 @@ public:
void start() override;
void stop() override;
- QAudioFormat audioFormat() const override;
- void setAudioFormat(const QAudioFormat &format) override;
-
QAudioBuffer read() override;
bool bufferAvailable() const override;
@@ -105,8 +99,6 @@ public:
// GStreamerBusMessageFilter interface
bool processBusMessage(const QGstreamerMessage &message) override;
- QAudioDecoder::State pendingState() const { return m_pendingState; }
-
#if QT_CONFIG(gstreamer_app)
QGstAppSrc *appsrc() const { return m_appSrc; }
static void configureAppSrcElement(GObject*, GObject*, GParamSpec*, QGstreamerAudioDecoder *_this);
@@ -125,8 +117,6 @@ private:
void processInvalidMedia(QAudioDecoder::Error errorCode, const QString& errorString);
static qint64 getPositionFromBuffer(GstBuffer* buffer);
- QAudioDecoder::State m_state = QAudioDecoder::StoppedState;
- QAudioDecoder::State m_pendingState = QAudioDecoder::StoppedState;
QGstPipeline m_playbin;
QGstBin m_outputBin;
QGstElement m_audioConvert;
@@ -135,7 +125,6 @@ private:
QUrl mSource;
QIODevice *mDevice = nullptr;
- QAudioFormat mFormat;
mutable QMutex m_buffersMutex;
int m_buffersAvailable = 0;
diff --git a/src/multimedia/platform/gstreamer/common/qgstutils.cpp b/src/multimedia/platform/gstreamer/common/qgstutils.cpp
index 7dd733f00..5d88f7e13 100644
--- a/src/multimedia/platform/gstreamer/common/qgstutils.cpp
+++ b/src/multimedia/platform/gstreamer/common/qgstutils.cpp
@@ -100,12 +100,16 @@ static QAudioFormat::SampleFormat gstSampleFormatToSampleFormat(const char *fmt)
*/
QAudioFormat QGstUtils::audioFormatForSample(GstSample *sample)
{
- GstCaps* caps = gst_sample_get_caps(sample);
- if (!caps)
+ QGstCaps caps = gst_sample_get_caps(sample);
+ if (caps.isNull())
return QAudioFormat();
+ return audioFormatForCaps(caps);
+}
+QAudioFormat QGstUtils::audioFormatForCaps(QGstCaps caps)
+{
QAudioFormat format;
- QGstStructure s = QGstCaps(caps).at(0);
+ QGstStructure s = caps.at(0);
if (s.name() != "audio/x-raw")
return format;
diff --git a/src/multimedia/platform/gstreamer/common/qgstutils_p.h b/src/multimedia/platform/gstreamer/common/qgstutils_p.h
index 651152950..0e6e76954 100644
--- a/src/multimedia/platform/gstreamer/common/qgstutils_p.h
+++ b/src/multimedia/platform/gstreamer/common/qgstutils_p.h
@@ -72,6 +72,7 @@ class QVideoFrameFormat;
namespace QGstUtils {
Q_MULTIMEDIA_EXPORT QAudioFormat audioFormatForSample(GstSample *sample);
+ QAudioFormat audioFormatForCaps(QGstCaps caps);
Q_MULTIMEDIA_EXPORT QGstMutableCaps capsForAudioFormat(const QAudioFormat &format);
Q_MULTIMEDIA_EXPORT QVideoFrameFormat formatForCaps(
diff --git a/src/multimedia/platform/qplatformaudiodecoder.cpp b/src/multimedia/platform/qplatformaudiodecoder.cpp
index b7da0a304..817e0656f 100644
--- a/src/multimedia/platform/qplatformaudiodecoder.cpp
+++ b/src/multimedia/platform/qplatformaudiodecoder.cpp
@@ -67,28 +67,6 @@ QPlatformAudioDecoder::QPlatformAudioDecoder(QAudioDecoder *parent)
}
/*!
- \fn QPlatformAudioDecoder::state() const
-
- Returns the state of a player control.
-*/
-
-void QPlatformAudioDecoder::stateChanged(QAudioDecoder::State newState)
-{
- if (m_state == newState)
- return;
- m_state = newState;
- emit q->stateChanged(newState);
-}
-
-/*!
- \fn QPlatformAudioDecoder::stateChanged(QAudioDecoder::State newState)
-
- Signals that the state of a player control has changed to \a newState.
-
- \sa state()
-*/
-
-/*!
\fn QPlatformAudioDecoder::source() const
Returns the current media source filename, or a null QString if none (or a device)
@@ -150,6 +128,7 @@ void QPlatformAudioDecoder::error(int error, const QString &errorString)
return;
m_error = QAudioDecoder::Error(error);
m_errorString = errorString;
+ setIsDecoding(false);
emit q->error(m_error);
}
@@ -193,18 +172,6 @@ void QPlatformAudioDecoder::sourceChanged()
}
/*!
- \fn QPlatformAudioDecoder::formatChanged(const QAudioFormat &format)
-
- Signals that the current audio format of the decoder has changed to \a format.
-
- \sa audioFormat(), setAudioFormat()
-*/
-void QPlatformAudioDecoder::formatChanged(const QAudioFormat &format)
-{
- emit q->formatChanged(format);
-}
-
-/*!
\fn void QPlatformAudioDecoder::finished()
Signals that the decoding has finished successfully.
@@ -214,6 +181,7 @@ void QPlatformAudioDecoder::formatChanged(const QAudioFormat &format)
*/
void QPlatformAudioDecoder::finished()
{
+ setIsDecoding(false);
emit q->finished();
}
diff --git a/src/multimedia/platform/qplatformaudiodecoder_p.h b/src/multimedia/platform/qplatformaudiodecoder_p.h
index 91877e647..e097b79fa 100644
--- a/src/multimedia/platform/qplatformaudiodecoder_p.h
+++ b/src/multimedia/platform/qplatformaudiodecoder_p.h
@@ -66,8 +66,6 @@ class Q_MULTIMEDIA_EXPORT QPlatformAudioDecoder : public QObject
Q_OBJECT
public:
- virtual QAudioDecoder::State state() const { return m_state; }
-
virtual QUrl source() const = 0;
virtual void setSource(const QUrl &fileName) = 0;
@@ -77,17 +75,12 @@ public:
virtual void start() = 0;
virtual void stop() = 0;
- virtual QAudioFormat audioFormat() const = 0;
- virtual void setAudioFormat(const QAudioFormat &format) = 0;
-
virtual QAudioBuffer read() = 0;
virtual bool bufferAvailable() const = 0;
virtual qint64 position() const = 0;
virtual qint64 duration() const = 0;
- void stateChanged(QAudioDecoder::State newState);
- void formatChanged(const QAudioFormat &format);
void sourceChanged();
void error(int error, const QString &errorString);
@@ -95,7 +88,14 @@ public:
void bufferReady();
void bufferAvailableChanged(bool available);
+ void setIsDecoding(bool running = true) {
+ if (m_isDecoding == running)
+ return;
+ m_isDecoding = running;
+ emit q->isDecodingChanged(m_isDecoding);
+ }
void finished();
+ bool isDecoding() const { return m_isDecoding; }
void positionChanged(qint64 position);
void durationChanged(qint64 duration);
@@ -108,9 +108,9 @@ protected:
private:
QAudioDecoder *q = nullptr;
- QAudioDecoder::State m_state = QAudioDecoder::StoppedState;
QAudioDecoder::Error m_error = QAudioDecoder::NoError;
QString m_errorString;
+ bool m_isDecoding = false;
};
QT_END_NAMESPACE
diff --git a/src/multimedia/platform/windows/decoder/mfaudiodecodercontrol.cpp b/src/multimedia/platform/windows/decoder/mfaudiodecodercontrol.cpp
index 953281f31..7a460533d 100644
--- a/src/multimedia/platform/windows/decoder/mfaudiodecodercontrol.cpp
+++ b/src/multimedia/platform/windows/decoder/mfaudiodecodercontrol.cpp
@@ -44,8 +44,6 @@ MFAudioDecoderControl::MFAudioDecoderControl(QAudioDecoder *parent)
: QPlatformAudioDecoder(parent)
, m_decoderSourceReader(new MFDecoderSourceReader)
, m_sourceResolver(new SourceResolver)
- , m_resampler(0)
- , m_state(QAudioDecoder::StoppedState)
, m_device(0)
, m_mfInputStreamID(0)
, m_mfOutputStreamID(0)
@@ -56,21 +54,10 @@ MFAudioDecoderControl::MFAudioDecoderControl(QAudioDecoder *parent)
, m_mfOutputType(0)
, m_convertSample(0)
, m_sourceReady(false)
- , m_resamplerDirty(false)
{
- CoCreateInstance(CLSID_CResamplerMediaObject, NULL, CLSCTX_INPROC_SERVER, IID_IMFTransform, (LPVOID*)(&m_resampler));
- if (!m_resampler) {
- qCritical("MFAudioDecoderControl: Failed to create resampler(CLSID_CResamplerMediaObject)!");
- return;
- }
- m_resampler->AddInputStreams(1, &m_mfInputStreamID);
-
connect(m_sourceResolver, SIGNAL(mediaSourceReady()), this, SLOT(handleMediaSourceReady()));
connect(m_sourceResolver, SIGNAL(error(long)), this, SLOT(handleMediaSourceError(long)));
connect(m_decoderSourceReader, SIGNAL(finished()), this, SLOT(handleSourceFinished()));
-
- QAudioFormat defaultFormat;
- setAudioFormat(defaultFormat);
}
MFAudioDecoderControl::~MFAudioDecoderControl()
@@ -80,13 +67,6 @@ MFAudioDecoderControl::~MFAudioDecoderControl()
m_decoderSourceReader->shutdown();
m_decoderSourceReader->Release();
m_sourceResolver->Release();
- if (m_resampler)
- m_resampler->Release();
-}
-
-QAudioDecoder::State MFAudioDecoderControl::state() const
-{
- return m_state;
}
QUrl MFAudioDecoderControl::source() const
@@ -107,9 +87,9 @@ void MFAudioDecoderControl::onSourceCleared()
durationDirty = true;
}
if (positionDirty)
- emit positionChanged(m_position);
+ positionChanged(m_position);
if (durationDirty)
- emit durationChanged(m_duration);
+ durationChanged(m_duration);
}
void MFAudioDecoderControl::setSource(const QUrl &fileName)
@@ -118,7 +98,7 @@ void MFAudioDecoderControl::setSource(const QUrl &fileName)
return;
m_sourceReady = false;
m_sourceResolver->cancel();
- m_decoderSourceReader->setSource(0, m_audioFormat);
+ m_decoderSourceReader->setSource(nullptr);
m_device = 0;
m_source = fileName;
if (!m_source.isEmpty()) {
@@ -128,7 +108,7 @@ void MFAudioDecoderControl::setSource(const QUrl &fileName)
} else {
onSourceCleared();
}
- emit sourceChanged();
+ sourceChanged();
}
QIODevice* MFAudioDecoderControl::sourceDevice() const
@@ -142,7 +122,7 @@ void MFAudioDecoderControl::setSourceDevice(QIODevice *device)
return;
m_sourceReady = false;
m_sourceResolver->cancel();
- m_decoderSourceReader->setSource(0, m_audioFormat);
+ m_decoderSourceReader->setSource(nullptr);
m_source.clear();
m_device = device;
if (m_device) {
@@ -152,48 +132,17 @@ void MFAudioDecoderControl::setSourceDevice(QIODevice *device)
} else {
onSourceCleared();
}
- emit sourceChanged();
-}
-
-void MFAudioDecoderControl::updateResamplerOutputType()
-{
- m_resamplerDirty = false;
- if (m_audioFormat == m_sourceOutputFormat)
- return;
- HRESULT hr = m_resampler->SetOutputType(m_mfOutputStreamID, m_mfOutputType, 0);
- if (SUCCEEDED(hr)) {
- MFT_OUTPUT_STREAM_INFO streamInfo;
- m_resampler->GetOutputStreamInfo(m_mfOutputStreamID, &streamInfo);
- if ((streamInfo.dwFlags & (MFT_OUTPUT_STREAM_PROVIDES_SAMPLES | MFT_OUTPUT_STREAM_CAN_PROVIDE_SAMPLES)) == 0) {
- //if resampler does not allocate output sample memory, we do it here
- if (m_convertSample) {
- m_convertSample->Release();
- m_convertSample = 0;
- }
- if (SUCCEEDED(MFCreateSample(&m_convertSample))) {
- IMFMediaBuffer *mbuf = 0;;
- if (SUCCEEDED(MFCreateMemoryBuffer(streamInfo.cbSize, &mbuf))) {
- m_convertSample->AddBuffer(mbuf);
- mbuf->Release();
- }
- }
- }
- } else {
- qWarning() << "MFAudioDecoderControl: failed to SetOutputType of resampler" << hr;
- }
+ sourceChanged();
}
void MFAudioDecoderControl::handleMediaSourceReady()
{
m_loadingSource = false;
m_sourceReady = true;
- IMFMediaType *mediaType = m_decoderSourceReader->setSource(m_sourceResolver->mediaSource(), m_audioFormat);
+ IMFMediaType *mediaType = m_decoderSourceReader->setSource(m_sourceResolver->mediaSource());
m_sourceOutputFormat = QAudioFormat();
if (mediaType) {
- m_sourceOutputFormat = m_audioFormat;
- QAudioFormat af = m_audioFormat;
-
UINT32 val = 0;
if (SUCCEEDED(mediaType->GetUINT32(MF_MT_AUDIO_NUM_CHANNELS, &val))) {
m_sourceOutputFormat.setChannelCount(int(val));
@@ -210,30 +159,15 @@ void MFAudioDecoderControl::handleMediaSourceReady()
m_sourceOutputFormat.setSampleFormat(QAudioFormat::Float);
} else if (bitsPerSample == 8) {
m_sourceOutputFormat.setSampleFormat(QAudioFormat::UInt8);
- } else {
+ } else if (bitsPerSample == 16) {
m_sourceOutputFormat.setSampleFormat(QAudioFormat::Int16);
+ } else if (bitsPerSample == 32){
+ m_sourceOutputFormat.setSampleFormat(QAudioFormat::Int32);
}
}
-
- if (m_audioFormat.channelCount() <= 0) {
- af.setChannelCount(m_sourceOutputFormat.channelCount());
- }
- if (m_audioFormat.sampleRate() <= 0) {
- af.setSampleRate(m_sourceOutputFormat.sampleRate());
- }
- setAudioFormat(af);
}
if (m_sourceResolver->mediaSource()) {
- if (mediaType && m_resampler) {
- HRESULT hr = S_OK;
- hr = m_resampler->SetInputType(m_mfInputStreamID, mediaType, 0);
- if (SUCCEEDED(hr)) {
- updateResamplerOutputType();
- } else {
- qWarning() << "MFAudioDecoderControl: failed to SetInputType of resampler" << hr;
- }
- }
IMFPresentationDescriptor *pd;
if (SUCCEEDED(m_sourceResolver->mediaSource()->CreatePresentationDescriptor(&pd))) {
UINT64 duration = 0;
@@ -242,15 +176,14 @@ void MFAudioDecoderControl::handleMediaSourceReady()
duration /= 10000;
if (m_duration != qint64(duration)) {
m_duration = qint64(duration);
- emit durationChanged(m_duration);
+ durationChanged(m_duration);
}
}
- if (m_state == QAudioDecoder::DecodingState) {
+ if (isDecoding()) {
activatePipeline();
}
- } else if (m_state != QAudioDecoder::StoppedState) {
- m_state = QAudioDecoder::StoppedState;
- emit stateChanged(m_state);
+ } else if (isDecoding()) {
+ setIsDecoding(false);
}
}
@@ -258,58 +191,49 @@ void MFAudioDecoderControl::handleMediaSourceError(long hr)
{
Q_UNUSED(hr);
m_loadingSource = false;
- m_decoderSourceReader->setSource(0, m_audioFormat);
- if (m_state != QAudioDecoder::StoppedState) {
- m_state = QAudioDecoder::StoppedState;
- emit stateChanged(m_state);
- }
+ m_decoderSourceReader->setSource(nullptr);
+ setIsDecoding(false);
}
void MFAudioDecoderControl::activatePipeline()
{
Q_ASSERT(!m_bufferReady);
- m_state = QAudioDecoder::DecodingState;
+ setIsDecoding(true);
connect(m_decoderSourceReader, SIGNAL(sampleAdded()), this, SLOT(handleSampleAdded()));
- if (m_resamplerDirty) {
- updateResamplerOutputType();
- }
m_decoderSourceReader->reset();
m_decoderSourceReader->readNextSample();
if (m_position != 0) {
m_position = 0;
- emit positionChanged(0);
+ positionChanged(0);
}
}
void MFAudioDecoderControl::start()
{
- if (m_state != QAudioDecoder::StoppedState)
+ if (isDecoding())
return;
if (m_loadingSource) {
//deferred starting
- m_state = QAudioDecoder::DecodingState;
- emit stateChanged(m_state);
+ setIsDecoding(true);
return;
}
if (!m_decoderSourceReader->mediaSource())
return;
activatePipeline();
- emit stateChanged(m_state);
}
void MFAudioDecoderControl::stop()
{
- if (m_state == QAudioDecoder::StoppedState)
+ if (!isDecoding())
return;
- m_state = QAudioDecoder::StoppedState;
disconnect(m_decoderSourceReader, SIGNAL(sampleAdded()), this, SLOT(handleSampleAdded()));
if (m_bufferReady) {
m_bufferReady = false;
emit bufferAvailableChanged(m_bufferReady);
}
- emit stateChanged(m_state);
+ setIsDecoding(false);
}
void MFAudioDecoderControl::handleSampleAdded()
@@ -317,64 +241,29 @@ void MFAudioDecoderControl::handleSampleAdded()
QList<IMFSample*> samples = m_decoderSourceReader->takeSamples();
Q_ASSERT(samples.count() > 0);
Q_ASSERT(!m_bufferReady);
- Q_ASSERT(m_resampler);
LONGLONG sampleStartTime = 0;
IMFSample *firstSample = samples.first();
firstSample->GetSampleTime(&sampleStartTime);
QByteArray abuf;
- if (m_sourceOutputFormat == m_audioFormat) {
- //no need for resampling
- for (IMFSample *s : qAsConst(samples)) {
- IMFMediaBuffer *buffer;
- s->ConvertToContiguousBuffer(&buffer);
- DWORD bufLen = 0;
- BYTE *buf = 0;
- if (SUCCEEDED(buffer->Lock(&buf, NULL, &bufLen))) {
- abuf.push_back(QByteArray(reinterpret_cast<char*>(buf), bufLen));
- buffer->Unlock();
- }
- buffer->Release();
- LONGLONG sampleTime = 0, sampleDuration = 0;
- s->GetSampleTime(&sampleTime);
- s->GetSampleDuration(&sampleDuration);
- m_position = qint64(sampleTime + sampleDuration) / 10000;
- s->Release();
- }
- } else {
- for (IMFSample *s : qAsConst(samples)) {
- HRESULT hr = m_resampler->ProcessInput(m_mfInputStreamID, s, 0);
- if (SUCCEEDED(hr)) {
- MFT_OUTPUT_DATA_BUFFER outputDataBuffer;
- outputDataBuffer.dwStreamID = m_mfOutputStreamID;
- while (true) {
- outputDataBuffer.pEvents = 0;
- outputDataBuffer.dwStatus = 0;
- outputDataBuffer.pSample = m_convertSample;
- DWORD status = 0;
- if (SUCCEEDED(m_resampler->ProcessOutput(0, 1, &outputDataBuffer, &status))) {
- IMFMediaBuffer *buffer;
- outputDataBuffer.pSample->ConvertToContiguousBuffer(&buffer);
- DWORD bufLen = 0;
- BYTE *buf = 0;
- if (SUCCEEDED(buffer->Lock(&buf, NULL, &bufLen))) {
- abuf.push_back(QByteArray(reinterpret_cast<char*>(buf), bufLen));
- buffer->Unlock();
- }
- buffer->Release();
- } else {
- break;
- }
- }
- }
- LONGLONG sampleTime = 0, sampleDuration = 0;
- s->GetSampleTime(&sampleTime);
- s->GetSampleDuration(&sampleDuration);
- m_position = qint64(sampleTime + sampleDuration) / 10000;
- s->Release();
+ for (IMFSample *s : qAsConst(samples)) {
+ IMFMediaBuffer *buffer;
+ s->ConvertToContiguousBuffer(&buffer);
+ DWORD bufLen = 0;
+ BYTE *buf = 0;
+ if (SUCCEEDED(buffer->Lock(&buf, NULL, &bufLen))) {
+ abuf.push_back(QByteArray(reinterpret_cast<char*>(buf), bufLen));
+ buffer->Unlock();
}
+ buffer->Release();
+ LONGLONG sampleTime = 0, sampleDuration = 0;
+ s->GetSampleTime(&sampleTime);
+ s->GetSampleDuration(&sampleDuration);
+ m_position = qint64(sampleTime + sampleDuration) / 10000;
+ s->Release();
}
+
// WMF uses 100-nanosecond units, QAudioDecoder uses milliseconds, QAudioBuffer uses microseconds...
- m_cachedAudioBuffer = QAudioBuffer(abuf, m_audioFormat, qint64(sampleStartTime / 10));
+ m_cachedAudioBuffer = QAudioBuffer(abuf, m_sourceOutputFormat, qint64(sampleStartTime / 10));
m_bufferReady = true;
emit positionChanged(m_position);
emit bufferAvailableChanged(m_bufferReady);
@@ -387,54 +276,6 @@ void MFAudioDecoderControl::handleSourceFinished()
emit finished();
}
-QAudioFormat MFAudioDecoderControl::audioFormat() const
-{
- return m_audioFormat;
-}
-
-void MFAudioDecoderControl::setAudioFormat(const QAudioFormat &format)
-{
- if (m_audioFormat == format || !m_resampler)
- return;
- m_audioFormat = format;
-
- if (m_audioFormat.isValid()) {
- IMFMediaType *mediaType = 0;
- MFCreateMediaType(&mediaType);
- mediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
- if (format.sampleFormat() == QAudioFormat::Float) {
- mediaType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_Float);
- } else {
- mediaType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);
- }
-
- mediaType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, UINT32(m_audioFormat.channelCount()));
- mediaType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, UINT32(m_audioFormat.sampleRate()));
- UINT32 alignmentBlock = UINT32(m_audioFormat.bytesPerFrame());
- mediaType->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, alignmentBlock);
- UINT32 avgBytesPerSec = UINT32(m_audioFormat.sampleRate() * m_audioFormat.bytesPerFrame());
- mediaType->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, avgBytesPerSec);
- mediaType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, UINT32(m_audioFormat.bytesPerSample()*8));
- mediaType->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
-
- if (m_mfOutputType)
- m_mfOutputType->Release();
- m_mfOutputType = mediaType;
- } else {
- if (m_mfOutputType)
- m_mfOutputType->Release();
- m_mfOutputType = NULL;
- }
-
- if (m_sourceReady && m_state == QAudioDecoder::StoppedState) {
- updateResamplerOutputType();
- } else {
- m_resamplerDirty = true;
- }
-
- emit formatChanged(m_audioFormat);
-}
-
QAudioBuffer MFAudioDecoderControl::read()
{
if (!m_bufferReady)
diff --git a/src/multimedia/platform/windows/decoder/mfaudiodecodercontrol_p.h b/src/multimedia/platform/windows/decoder/mfaudiodecodercontrol_p.h
index 56edb95c0..8cd769e67 100644
--- a/src/multimedia/platform/windows/decoder/mfaudiodecodercontrol_p.h
+++ b/src/multimedia/platform/windows/decoder/mfaudiodecodercontrol_p.h
@@ -64,8 +64,6 @@ public:
MFAudioDecoderControl(QAudioDecoder *parent);
~MFAudioDecoderControl();
- QAudioDecoder::State state() const;
-
QUrl source() const;
void setSource(const QUrl &fileName);
@@ -75,9 +73,6 @@ public:
void start();
void stop();
- QAudioFormat audioFormat() const;
- void setAudioFormat(const QAudioFormat &format);
-
QAudioBuffer read();
bool bufferAvailable() const;
@@ -91,17 +86,13 @@ private Q_SLOTS:
void handleSourceFinished();
private:
- void updateResamplerOutputType();
void activatePipeline();
void onSourceCleared();
MFDecoderSourceReader *m_decoderSourceReader;
SourceResolver *m_sourceResolver;
- IMFTransform *m_resampler;
- QAudioDecoder::State m_state;
QUrl m_source;
QIODevice *m_device;
- QAudioFormat m_audioFormat;
DWORD m_mfInputStreamID;
DWORD m_mfOutputStreamID;
bool m_bufferReady;
@@ -113,7 +104,6 @@ private:
IMFSample *m_convertSample;
QAudioFormat m_sourceOutputFormat;
bool m_sourceReady;
- bool m_resamplerDirty;
};
#endif//MFAUDIODECODERCONTROL_H
diff --git a/src/multimedia/platform/windows/decoder/mfdecodersourcereader.cpp b/src/multimedia/platform/windows/decoder/mfdecodersourcereader.cpp
index 381c60dc5..d10839a63 100644
--- a/src/multimedia/platform/windows/decoder/mfdecodersourcereader.cpp
+++ b/src/multimedia/platform/windows/decoder/mfdecodersourcereader.cpp
@@ -64,7 +64,7 @@ IMFMediaSource* MFDecoderSourceReader::mediaSource()
return m_source;
}
-IMFMediaType* MFDecoderSourceReader::setSource(IMFMediaSource *source, const QAudioFormat &audioFormat)
+IMFMediaType* MFDecoderSourceReader::setSource(IMFMediaSource *source)
{
IMFMediaType *mediaType = NULL;
if (m_source == source)
@@ -90,12 +90,7 @@ IMFMediaType* MFDecoderSourceReader::setSource(IMFMediaSource *source, const QAu
IMFMediaType *pPartialType = NULL;
MFCreateMediaType(&pPartialType);
pPartialType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
-
- if (audioFormat.sampleFormat() == QAudioFormat::Float) {
- pPartialType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_Float);
- } else {
- pPartialType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);
- }
+ pPartialType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);
m_sourceReader->SetCurrentMediaType(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), NULL, pPartialType);
pPartialType->Release();
diff --git a/src/multimedia/platform/windows/decoder/mfdecodersourcereader_p.h b/src/multimedia/platform/windows/decoder/mfdecodersourcereader_p.h
index 7d63f5368..6730dbf7f 100644
--- a/src/multimedia/platform/windows/decoder/mfdecodersourcereader_p.h
+++ b/src/multimedia/platform/windows/decoder/mfdecodersourcereader_p.h
@@ -69,7 +69,7 @@ public:
void shutdown();
IMFMediaSource* mediaSource();
- IMFMediaType* setSource(IMFMediaSource *source, const QAudioFormat &audioFormat);
+ IMFMediaType* setSource(IMFMediaSource *source);
void reset();
void readNextSample();
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();
}