diff options
author | Val Doroshchuk <valentyn.doroshchuk@qt.io> | 2019-04-03 10:24:53 +0200 |
---|---|---|
committer | VaL Doroshchuk <valentyn.doroshchuk@qt.io> | 2019-04-03 11:27:00 +0000 |
commit | 3f8b0a916e9e0ca4e17900e1399ee8ad6bbf35b8 (patch) | |
tree | 45830b04a797b1ba8ccf45176c268ec2ec465fba | |
parent | 49cd7b16b2ae77246da10993958a989753abecb8 (diff) |
Android/AudioTrack: Fix crash when it is unable to get min buffer size
android/media/AudioTrack::getMinBufferSize might return an error instead
of a size.
Task-number: QTBUG-73583
Change-Id: I52e2d214ab7065bcea9d983979bb0b83717428af
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
-rw-r--r-- | src/plugins/opensles/qopenslesaudiooutput.cpp | 6 | ||||
-rw-r--r-- | src/plugins/opensles/qopenslesengine.cpp | 13 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/plugins/opensles/qopenslesaudiooutput.cpp b/src/plugins/opensles/qopenslesaudiooutput.cpp index 0b1f444bd..381ce0ec2 100644 --- a/src/plugins/opensles/qopenslesaudiooutput.cpp +++ b/src/plugins/opensles/qopenslesaudiooutput.cpp @@ -569,6 +569,12 @@ bool QOpenSLESAudioOutput::preparePlayer() const int lowLatencyBufferSize = QOpenSLESEngine::getLowLatencyBufferSize(m_format); const int defaultBufferSize = QOpenSLESEngine::getDefaultBufferSize(m_format); + if (defaultBufferSize <= 0) { + qWarning() << "Unable to get minimum buffer size, returned" << defaultBufferSize; + setError(QAudio::FatalError); + return false; + } + // Buffer size if (m_bufferSize <= 0) { m_bufferSize = defaultBufferSize; diff --git a/src/plugins/opensles/qopenslesengine.cpp b/src/plugins/opensles/qopenslesengine.cpp index 1a16cc2a3..43cdcb276 100644 --- a/src/plugins/opensles/qopenslesengine.cpp +++ b/src/plugins/opensles/qopenslesengine.cpp @@ -239,12 +239,13 @@ int QOpenSLESEngine::getDefaultBufferSize(const QAudioFormat &format) }(); const int sampleRate = format.sampleRate(); - return QJNIObjectPrivate::callStaticMethod<jint>("android/media/AudioTrack", - "getMinBufferSize", - "(III)I", - sampleRate, - channelConfig, - audioFormat); + const int minBufferSize = QJNIObjectPrivate::callStaticMethod<jint>("android/media/AudioTrack", + "getMinBufferSize", + "(III)I", + sampleRate, + channelConfig, + audioFormat); + return minBufferSize > 0 ? minBufferSize : format.bytesForDuration(DEFAULT_PERIOD_TIME_MS); #else return format.bytesForDuration(DEFAULT_PERIOD_TIME_MS); #endif // Q_OS_ANDROID |