summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPekka Gehör <pekka.gehor@qt.io>2022-04-27 14:44:15 +0300
committerPekka Gehör <pekka.gehor@qt.io>2022-04-27 16:06:25 +0300
commit2fb299707f3ddc026f4bd7dec6bda03a858d06e7 (patch)
treecff9fc60903daeab74cc1e7d5a4e20f40acf74f2
parent19b84b2663bee0753ad96b1285437ad2623c5fdd (diff)
Android: fix source device issue
Changed the QDataStream.write to the File.Write, because a QDataStream.write add an extra 4 -bytes to the file. For this reason the AMediaExtractor_setDataSourceFd will fail. Also changed the tempPath to the QDir.tempPath(), because a file creation fails with a tempPath; Task-number: QTBUG-100079 Change-Id: I2357520821ff5b78b8fc24acbf505af753161915 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit 3f880a5c66b5c9e005cff8eee296ef8b8b039563)
-rw-r--r--src/multimedia/platform/android/audio/qandroidaudiodecoder.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/multimedia/platform/android/audio/qandroidaudiodecoder.cpp b/src/multimedia/platform/android/audio/qandroidaudiodecoder.cpp
index 8179de809..15450f0af 100644
--- a/src/multimedia/platform/android/audio/qandroidaudiodecoder.cpp
+++ b/src/multimedia/platform/android/audio/qandroidaudiodecoder.cpp
@@ -53,8 +53,7 @@
QT_BEGIN_NAMESPACE
-static const char tempFile[] = "encoded.tmp";
-static const char tempPath[] = "/storage/emulated/0/data/local/tmp/audiodecoder/";
+static const char tempFile[] = "encoded.wav";
constexpr int dequeueTimeout = 5000;
Q_LOGGING_CATEGORY(adLogger, "QAndroidAudioDecoder")
@@ -406,7 +405,7 @@ void QAndroidAudioDecoder::finished()
{
stop();
// remove temp file when decoding is finished
- QFile(QString::fromUtf8(tempPath).append(QString::fromUtf8(tempFile))).remove();
+ QFile(QString(QDir::tempPath()).append(QString::fromUtf8(tempFile))).remove();
emit QPlatformAudioDecoder::finished();
}
@@ -432,22 +431,22 @@ void QAndroidAudioDecoder::decode()
bool QAndroidAudioDecoder::createTempFile()
{
- QFile file = QFile(QString::fromUtf8(tempPath).append(QString::fromUtf8(tempFile)));
- if (!QDir().mkpath(QString::fromUtf8(tempPath)) || !file.open(QIODevice::WriteOnly)) {
- emit error(QAudioDecoder::ResourceError,
- QString::fromUtf8("Error while creating or opening tmp file"));
- return false;
- }
+ QFile file = QFile(QDir::tempPath().append(QString::fromUtf8(tempFile)), this);
- QDataStream out;
- out.setDevice(&file);
- out << m_deviceBuffer;
- file.close();
+ bool success = file.open(QIODevice::QIODevice::ReadWrite);
+ if (!success)
+ emit error(QAudioDecoder::ResourceError, tr("Error while opening tmp file"));
+ success &= (file.write(m_deviceBuffer) == m_deviceBuffer.size());
+ if (!success)
+ emit error(QAudioDecoder::ResourceError, tr("Error while writing data to tmp file"));
+
+ file.close();
m_deviceBuffer.clear();
- m_decoder->setSource(file.fileName());
+ if (success)
+ m_decoder->setSource(file.fileName());
- return true;
+ return success;
}
void QAndroidAudioDecoder::readDevice() {