diff options
author | Pekka Gehör <pekka.gehor@qt.io> | 2022-04-27 15:45:54 +0300 |
---|---|---|
committer | Pekka Gehör <pekka.gehor@qt.io> | 2022-05-30 13:21:44 +0300 |
commit | 3bfffbea7a1c84624035f765d45678604bc37889 (patch) | |
tree | b480b8bdb21fd7b9f67a7ace2afd66fdd8cba5a6 | |
parent | 1b75b54984c6e9d0fab18eb99b47af7bf8833993 (diff) |
Android: Correct the wrong signal call sequence
The call sequence of the signals and
buffer handling are now implemented against
the tst_QAudioDecoderBackend test.
Task-number: QTBUG-100079
Change-Id: I55b02ffe34ab13ee35b71741fb139914d9f16b62
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit f324a096cb57b89b084d0c73ee92568d697260f3)
-rw-r--r-- | src/multimedia/platform/android/audio/qandroidaudiodecoder.cpp | 41 | ||||
-rw-r--r-- | src/multimedia/platform/android/audio/qandroidaudiodecoder_p.h | 7 |
2 files changed, 29 insertions, 19 deletions
diff --git a/src/multimedia/platform/android/audio/qandroidaudiodecoder.cpp b/src/multimedia/platform/android/audio/qandroidaudiodecoder.cpp index f56cced6a..d84085800 100644 --- a/src/multimedia/platform/android/audio/qandroidaudiodecoder.cpp +++ b/src/multimedia/platform/android/audio/qandroidaudiodecoder.cpp @@ -204,6 +204,7 @@ void Decoder::doDecode() AMediaExtractor_selectTrack(m_extractor, 0); + emit decodingChanged(true); m_inputEOS = false; while (!m_inputEOS) { // handle input buffer @@ -273,13 +274,16 @@ QAndroidAudioDecoder::QAndroidAudioDecoder(QAudioDecoder *parent) connect(m_decoder, &Decoder::durationChanged, this, &QAndroidAudioDecoder::durationChanged); connect(m_decoder, &Decoder::error, this, &QAndroidAudioDecoder::error); connect(m_decoder, &Decoder::finished, this, &QAndroidAudioDecoder::finished); + connect(m_decoder, &Decoder::decodingChanged, this, &QPlatformAudioDecoder::setIsDecoding); + connect(this, &QAndroidAudioDecoder::setSourceUrl, m_decoder, & Decoder::setSource); } QAndroidAudioDecoder::~QAndroidAudioDecoder() { m_decoder->thread()->quit(); m_decoder->thread()->wait(); - m_decoder->deleteLater(); + delete m_threadDecoder; + delete m_decoder; } void QAndroidAudioDecoder::setSource(const QUrl &fileName) @@ -295,7 +299,7 @@ void QAndroidAudioDecoder::setSource(const QUrl &fileName) if (m_source != fileName) { m_source = fileName; - m_decoder->setSource(m_source); + emit setSourceUrl(m_source); sourceChanged(); } } @@ -321,7 +325,6 @@ void QAndroidAudioDecoder::start() if (isDecoding()) return; - setIsDecoding(true); m_position = -1; if (!m_threadDecoder) { @@ -335,24 +338,26 @@ void QAndroidAudioDecoder::start() void QAndroidAudioDecoder::stop() { - if (!isDecoding()) + if (!isDecoding() && m_position < 0 && m_duration < 0) return; m_decoder->stop(); - - if (m_threadDecoder && m_threadDecoder->isRunning()) - m_threadDecoder->exit(); - - m_position = -1; m_audioBuffer.clear(); + m_position = -1; + m_duration = -1; setIsDecoding(false); + + emit bufferAvailableChanged(false); + emit QPlatformAudioDecoder::positionChanged(m_position); } QAudioBuffer QAndroidAudioDecoder::read() { - if (m_buffersAvailable && !m_audioBuffer.isEmpty()) { - --m_buffersAvailable; - return m_audioBuffer.takeFirst(); + if (!m_audioBuffer.isEmpty()) { + QPair<QAudioBuffer, int> buffer = m_audioBuffer.takeFirst(); + m_position = buffer.second; + emit QPlatformAudioDecoder::positionChanged(buffer.second); + return buffer.first; } // no buffers available @@ -361,7 +366,7 @@ QAudioBuffer QAndroidAudioDecoder::read() bool QAndroidAudioDecoder::bufferAvailable() const { - return m_buffersAvailable; + return m_audioBuffer.size() > 0; } qint64 QAndroidAudioDecoder::position() const @@ -376,11 +381,9 @@ qint64 QAndroidAudioDecoder::duration() const void QAndroidAudioDecoder::positionChanged(QAudioBuffer audioBuffer, qint64 position) { - m_audioBuffer.append(audioBuffer); + m_audioBuffer.append(QPair<QAudioBuffer, int>(audioBuffer, position)); m_position = position; - m_buffersAvailable++; emit bufferReady(); - emit QPlatformAudioDecoder::positionChanged(position); } void QAndroidAudioDecoder::durationChanged(qint64 duration) @@ -397,7 +400,11 @@ void QAndroidAudioDecoder::error(const QAudioDecoder::Error err, const QString & void QAndroidAudioDecoder::finished() { - stop(); + emit bufferAvailableChanged(m_audioBuffer.size() > 0); + + if (m_duration != -1) + emit durationChanged(m_duration); + // remove temp file when decoding is finished QFile(QString(QDir::tempPath()).append(QString::fromUtf8(tempFile))).remove(); emit QPlatformAudioDecoder::finished(); diff --git a/src/multimedia/platform/android/audio/qandroidaudiodecoder_p.h b/src/multimedia/platform/android/audio/qandroidaudiodecoder_p.h index 29e43ebae..a1795e39b 100644 --- a/src/multimedia/platform/android/audio/qandroidaudiodecoder_p.h +++ b/src/multimedia/platform/android/audio/qandroidaudiodecoder_p.h @@ -80,6 +80,7 @@ signals: void durationChanged(const qint64 duration); void error(const QAudioDecoder::Error error, const QString &errorString); void finished(); + void decodingChanged(bool decoding); private: void createDecoder(); @@ -118,6 +119,9 @@ public: qint64 position() const override; qint64 duration() const override; +signals: + void setSourceUrl(const QUrl &source); + private slots: void positionChanged(QAudioBuffer audioBuffer, qint64 position); void durationChanged(qint64 duration); @@ -133,13 +137,12 @@ private: QIODevice *m_device = nullptr; Decoder *m_decoder; - QList<QAudioBuffer> m_audioBuffer; + QList<QPair<QAudioBuffer, int>> m_audioBuffer; QUrl m_source; qint64 m_position = -1; qint64 m_duration = -1; long long m_presentationTimeUs = 0; - int m_buffersAvailable = 0; QByteArray m_deviceBuffer; |