summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Mira <samuel.mira@qt.io>2021-10-20 15:21:09 +0300
committerSamuel Mira <samuel.mira@qt.io>2021-10-21 14:16:21 +0000
commit634f211ae69c6fa327d410527b00d3f7d00126e7 (patch)
treedc70d4b2a377b2b76f884571d07a2737847a7459
parent3ed3e14a8965f4e231d80480a587c62d556199b7 (diff)
Fix crashes on qandroidaudiodecoder
Running the auto tests in android can fail and it could lead to crashes and a pending QThread. This patch is for fixing those issues. Fixes: QTBUG-97647 Pick-to: 6.2 Change-Id: I578f199127519e4620abcb0dac36a1603d8d77bd Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/multimedia/platform/android/audio/qandroidaudiodecoder.cpp18
-rw-r--r--src/multimedia/platform/android/audio/qandroidaudiodecoder_p.h2
2 files changed, 17 insertions, 3 deletions
diff --git a/src/multimedia/platform/android/audio/qandroidaudiodecoder.cpp b/src/multimedia/platform/android/audio/qandroidaudiodecoder.cpp
index 718492118..d6d284504 100644
--- a/src/multimedia/platform/android/audio/qandroidaudiodecoder.cpp
+++ b/src/multimedia/platform/android/audio/qandroidaudiodecoder.cpp
@@ -81,6 +81,9 @@ Decoder::~Decoder()
void Decoder::stop()
{
+ if (!m_codec)
+ return;
+
const media_status_t err = AMediaCodec_stop(m_codec);
if (err != AMEDIA_OK)
qCWarning(adLogger) << "stop() error: " << err;
@@ -165,6 +168,11 @@ void Decoder::doDecode()
createDecoder();
+ if (!m_codec) {
+ emit error(QAudioDecoder::ResourceError, tr("Audio Decoder could not be created."));
+ return;
+ }
+
media_status_t status = AMediaCodec_configure(m_codec, m_format, nullptr /* surface */,
nullptr /* crypto */, 0);
@@ -298,9 +306,9 @@ void QAndroidAudioDecoder::start()
setIsDecoding(true);
m_position = -1;
- QThread *threadDecoder = new QThread(this);
- m_decoder->moveToThread(threadDecoder);
- threadDecoder->start();
+ m_threadDecoder = new QThread(this);
+ m_decoder->moveToThread(m_threadDecoder);
+ m_threadDecoder->start();
decode();
}
@@ -311,6 +319,9 @@ void QAndroidAudioDecoder::stop()
m_decoder->stop();
+ if (m_threadDecoder && m_threadDecoder->isRunning())
+ m_threadDecoder->exit();
+
QMutexLocker locker(&m_buffersMutex);
m_position = -1;
m_audioBuffer.clear();
@@ -369,6 +380,7 @@ void QAndroidAudioDecoder::durationChanged(qint64 duration)
void QAndroidAudioDecoder::error(const QAudioDecoder::Error err, const QString &errorString)
{
+ stop();
emit QPlatformAudioDecoder::error(err, errorString);
}
diff --git a/src/multimedia/platform/android/audio/qandroidaudiodecoder_p.h b/src/multimedia/platform/android/audio/qandroidaudiodecoder_p.h
index d6e1bf32e..efb7cdc24 100644
--- a/src/multimedia/platform/android/audio/qandroidaudiodecoder_p.h
+++ b/src/multimedia/platform/android/audio/qandroidaudiodecoder_p.h
@@ -144,6 +144,8 @@ private:
int m_buffersAvailable = 0;
QByteArray m_deviceBuffer;
+
+ QThread *m_threadDecoder;
};
QT_END_NAMESPACE