Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qandroidaudiodecoder_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QANDROIDAUDIODECODER_P_H
5#define QANDROIDAUDIODECODER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17#include <QtMultimedia/private/qplatformaudiodecoder_p.h>
18
19#include <QtCore/qurl.h>
20#include <QThread>
21
22#include "media/NdkMediaCodec.h"
23#include "media/NdkMediaExtractor.h"
24#include "media/NdkMediaFormat.h"
25#include "media/NdkMediaError.h"
26
27QT_BEGIN_NAMESPACE
28
29class Decoder : public QObject
30{
31 Q_OBJECT
32public:
33 Decoder();
34 ~Decoder();
35
36public slots:
37 void setSource(const QUrl &source);
38 void doDecode();
39 void stop();
40
41signals:
42 void positionChanged(const QAudioBuffer &buffer, std::chrono::milliseconds position);
43 void durationChanged(std::chrono::milliseconds duration);
44 void error(const QAudioDecoder::Error error, const QString &errorString);
45 void finished();
46 void decodingChanged(bool decoding);
47
48private:
49 void createDecoder();
50
51 AMediaCodec *m_codec = nullptr;
52 AMediaExtractor *m_extractor = nullptr;
53 AMediaFormat *m_format = nullptr;
54
55 QAudioFormat m_outputFormat;
56 QString m_formatError;
57 bool m_inputEOS;
58};
59
60
62{
64public:
66 virtual ~QAndroidAudioDecoder();
67
68 QUrl source() const override { return m_source; }
69 void setSource(const QUrl &fileName) override;
70
71 QIODevice *sourceDevice() const override { return m_device; }
72 void setSourceDevice(QIODevice *device) override;
73
74 void start() override;
75 void stop() override;
76
77 QAudioFormat audioFormat() const override { return {}; }
78 void setAudioFormat(const QAudioFormat &/*format*/) override {}
79
80 QAudioBuffer read() override;
81 bool bufferAvailable() const override;
82
84 void setSourceUrl(const QUrl &source);
85
86private slots:
88 void durationChanged(std::chrono::milliseconds duration);
89 void error(const QAudioDecoder::Error error, const QString &errorString);
90 void readDevice();
91 void finished();
92
93private:
94 bool requestPermissions();
95 bool createTempFile();
96 void decode();
97
98 QIODevice *m_device = nullptr;
99 Decoder *m_decoder = nullptr;
100
102 QUrl m_source;
103
104 QByteArray m_deviceBuffer;
105
106 QThread *m_threadDecoder = nullptr;
107};
108
109QT_END_NAMESPACE
110
111#endif // QANDROIDAUDIODECODER_P_H
bool bufferAvailable() const override
QAudioFormat audioFormat() const override
QUrl source() const override
QAudioBuffer read() override
QIODevice * sourceDevice() const override
void setSourceDevice(QIODevice *device) override
void setSource(const QUrl &fileName) override
void setAudioFormat(const QAudioFormat &) override
static QT_BEGIN_NAMESPACE const char tempFile[]
constexpr int dequeueTimeout
#define qCWarning(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)