summaryrefslogtreecommitdiffstats
path: root/src/plugins/multimedia/android/audio
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/multimedia/android/audio')
-rw-r--r--src/plugins/multimedia/android/audio/qandroidaudiodecoder.cpp92
-rw-r--r--src/plugins/multimedia/android/audio/qandroidaudiodecoder_p.h42
2 files changed, 35 insertions, 99 deletions
diff --git a/src/plugins/multimedia/android/audio/qandroidaudiodecoder.cpp b/src/plugins/multimedia/android/audio/qandroidaudiodecoder.cpp
index 7239d7292..5a8eb5f2d 100644
--- a/src/plugins/multimedia/android/audio/qandroidaudiodecoder.cpp
+++ b/src/plugins/multimedia/android/audio/qandroidaudiodecoder.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qandroidaudiodecoder_p.h"
#include <QtCore/qcoreapplication.h>
@@ -55,7 +19,7 @@ QT_BEGIN_NAMESPACE
static const char tempFile[] = "encoded.wav";
constexpr int dequeueTimeout = 5000;
-Q_LOGGING_CATEGORY(adLogger, "QAndroidAudioDecoder")
+Q_STATIC_LOGGING_CATEGORY(adLogger, "QAndroidAudioDecoder");
Decoder::Decoder()
: m_format(AMediaFormat_new())
@@ -95,37 +59,32 @@ void Decoder::setSource(const QUrl &source)
"org/qtproject/qt/android/multimedia/QtMultimediaUtils",
"getMimeType",
"(Landroid/content/Context;Ljava/lang/String;)Ljava/lang/String;",
- QNativeInterface::QAndroidApplication::context(),
+ QNativeInterface::QAndroidApplication::context().object(),
QJniObject::fromString(source.path()).object());
const QString mime = path.isValid() ? path.toString() : "";
if (!mime.isEmpty() && !mime.contains("audio", Qt::CaseInsensitive)) {
- emit error(QAudioDecoder::FormatError,
- tr("Cannot set source, invalid mime type for the provided source."));
+ m_formatError = tr("Cannot set source, invalid mime type for the source provided.");
return;
}
if (!m_extractor)
m_extractor = AMediaExtractor_new();
- int fd = -1;
- if (source.path().contains(QLatin1String("content"))) {
- fd = QJniObject::callStaticMethod<jint>("org/qtproject/qt/android/QtNative",
- "openFdForContentUrl",
- "(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)I",
- QNativeInterface::QAndroidApplication::context(),
- QJniObject::fromString(source.path()).object(),
- QJniObject::fromString(QLatin1String("r")).object());
- } else {
- fd = open(source.path().toStdString().c_str(), O_RDONLY);
- }
+ QFile file(source.path());
+ if (!file.open(QFile::ReadOnly)) {
+ emit error(QAudioDecoder::ResourceError, tr("Cannot open the file"));
+ return;
+ }
+
+ const int fd = file.handle();
if (fd < 0) {
- emit error(QAudioDecoder::ResourceError, tr("Invalid fileDescriptor for source."));
- return;
- }
- const int size = QFile(source.toString()).size();
+ emit error(QAudioDecoder::ResourceError, tr("Invalid fileDescriptor for source."));
+ return;
+ }
+ const int size = file.size();
media_status_t status = AMediaExtractor_setDataSourceFd(m_extractor, fd, 0,
size > 0 ? size : LONG_MAX);
close(fd);
@@ -135,7 +94,7 @@ void Decoder::setSource(const QUrl &source)
AMediaExtractor_delete(m_extractor);
m_extractor = nullptr;
}
- emit error(QAudioDecoder::ResourceError, tr("Setting source for Audio Decoder failed."));
+ m_formatError = tr("Setting source for Audio Decoder failed.");
}
}
@@ -176,6 +135,11 @@ void Decoder::createDecoder()
void Decoder::doDecode()
{
+ if (!m_formatError.isEmpty()) {
+ emit error(QAudioDecoder::FormatError, m_formatError);
+ return;
+ }
+
if (!m_extractor) {
emit error(QAudioDecoder::ResourceError, tr("Cannot decode, source not set."));
return;
@@ -326,6 +290,12 @@ void QAndroidAudioDecoder::start()
m_position = -1;
+ if (m_device && (!m_device->isOpen() || !m_device->isReadable())) {
+ emit error(QAudioDecoder::ResourceError,
+ QString::fromUtf8("Unable to read from the specified device"));
+ return;
+ }
+
if (!m_threadDecoder) {
m_threadDecoder = new QThread(this);
m_decoder->moveToThread(m_threadDecoder);
@@ -435,11 +405,11 @@ bool QAndroidAudioDecoder::createTempFile()
bool success = file.open(QIODevice::QIODevice::ReadWrite);
if (!success)
- emit error(QAudioDecoder::ResourceError, tr("Error while opening tmp file"));
+ emit error(QAudioDecoder::ResourceError, tr("Error opening temporary file: %1").arg(file.errorString()));
success &= (file.write(m_deviceBuffer) == m_deviceBuffer.size());
if (!success)
- emit error(QAudioDecoder::ResourceError, tr("Error while writing data to tmp file"));
+ emit error(QAudioDecoder::ResourceError, tr("Error while writing data to temporary file"));
file.close();
m_deviceBuffer.clear();
@@ -463,3 +433,5 @@ void QAndroidAudioDecoder::readDevice() {
}
QT_END_NAMESPACE
+
+#include "moc_qandroidaudiodecoder_p.cpp"
diff --git a/src/plugins/multimedia/android/audio/qandroidaudiodecoder_p.h b/src/plugins/multimedia/android/audio/qandroidaudiodecoder_p.h
index a1795e39b..65a0f1855 100644
--- a/src/plugins/multimedia/android/audio/qandroidaudiodecoder_p.h
+++ b/src/plugins/multimedia/android/audio/qandroidaudiodecoder_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QANDROIDAUDIODECODER_P_H
#define QANDROIDAUDIODECODER_P_H
@@ -90,6 +54,7 @@ private:
AMediaFormat *m_format = nullptr;
QAudioFormat m_outputFormat;
+ QString m_formatError;
bool m_inputEOS;
};
@@ -142,7 +107,6 @@ private:
qint64 m_position = -1;
qint64 m_duration = -1;
- long long m_presentationTimeUs = 0;
QByteArray m_deviceBuffer;