Revision control

++ // 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
++
++ //
++ // W A R N I N G
++ // -------------
++ //
++ // This file is not part of the Qt API. It exists purely as an
++ // implementation detail. This header file may change from version to
++ // version without notice, or even be removed.
++ //
++ // We mean it.
++ //
++ #include <QtMultimedia/private/qplatformaudiodecoder_p.h>
++
++ #include <QtCore/qurl.h>
++ #include <QThread>
++
++ #include "media/NdkMediaCodec.h"
++ #include "media/NdkMediaExtractor.h"
++ #include "media/NdkMediaFormat.h"
++ #include "media/NdkMediaError.h"
++
++ QT_BEGIN_NAMESPACE
++
++ class Decoder : public QObject
++ {
++ Q_OBJECT
++ public:
++ Decoder();
++ ~Decoder();
++
++ public Q_SLOTS:
++ void setSource(const QUrl &source);
++ void doDecode();
++ void stop();
++
++ Q_SIGNALS:
++ void positionChanged(const QAudioBuffer &buffer, std::chrono::milliseconds position);
++ void durationChanged(std::chrono::milliseconds duration);
++ void error(const QAudioDecoder::Error error, const QString &errorString);
++ void finished();
++ void decodingChanged(bool decoding);
++
++ private:
++ void createDecoder();
++
++ AMediaCodec *m_codec = nullptr;
++ AMediaExtractor *m_extractor = nullptr;
++ AMediaFormat *m_format = nullptr;
++
++ QAudioFormat m_outputFormat;
++ QString m_formatError;
++ bool m_inputEOS;
++ };
++
++
++ class QAndroidAudioDecoder : public QPlatformAudioDecoder
++ {
++ Q_OBJECT
++ public:
++ QAndroidAudioDecoder(QAudioDecoder *parent);
++ virtual ~QAndroidAudioDecoder();
++
++ QUrl source() const override { return m_source; }
++ void setSource(const QUrl &fileName) override;
++
++ QIODevice *sourceDevice() const override { return m_device; }
++ void setSourceDevice(QIODevice *device) override;
++
++ void start() override;
++ void stop() override;
++
++ QAudioFormat audioFormat() const override { return {}; }
++ void setAudioFormat(const QAudioFormat &/*format*/) override {}
++
++ QAudioBuffer read() override;
++ bool bufferAvailable() const override;
++
++ Q_SIGNALS:
++ void setSourceUrl(const QUrl &source);
++
++ private Q_SLOTS:
++ void positionChanged(QAudioBuffer audioBuffer, std::chrono::milliseconds position);
++ void durationChanged(std::chrono::milliseconds duration);
++ void error(const QAudioDecoder::Error error, const QString &errorString);
++ void readDevice();
++ void finished();
++
++ private:
++ bool requestPermissions();
++ bool createTempFile();
++ void decode();
++
++ QIODevice *m_device = nullptr;
++ Decoder *m_decoder = nullptr;
++
++ QList<std::pair<QAudioBuffer, std::chrono::milliseconds>> m_audioBuffer;
++ QUrl m_source;
++
++ QByteArray m_deviceBuffer;
++
++ QThread *m_threadDecoder = nullptr;
++ };
++
++ QT_END_NAMESPACE
++
++ #endif // QANDROIDAUDIODECODER_P_H