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 "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
27
28QT_USE_NAMESPACE
29
30class Decoder : public QObject
31{
32 Q_OBJECT
33public:
34 Decoder();
35 ~Decoder();
36
37public slots:
38 void setSource(const QUrl &source);
39 void doDecode();
40 void stop();
41
42signals:
43 void positionChanged(const QAudioBuffer &buffer, qint64 position);
44 void durationChanged(const qint64 duration);
45 void error(const QAudioDecoder::Error error, const QString &errorString);
46 void finished();
47 void decodingChanged(bool decoding);
48
49private:
50 void createDecoder();
51
52 AMediaCodec *m_codec = nullptr;
53 AMediaExtractor *m_extractor = nullptr;
54 AMediaFormat *m_format = nullptr;
55
56 QAudioFormat m_outputFormat;
57 QString m_formatError;
58 bool m_inputEOS;
59};
60
61
63{
65public:
67 virtual ~QAndroidAudioDecoder();
68
69 QUrl source() const override { return m_source; }
70 void setSource(const QUrl &fileName) override;
71
72 QIODevice *sourceDevice() const override { return m_device; }
73 void setSourceDevice(QIODevice *device) override;
74
75 void start() override;
76 void stop() override;
77
78 QAudioFormat audioFormat() const override { return {}; }
79 void setAudioFormat(const QAudioFormat &/*format*/) override {}
80
81 QAudioBuffer read() override;
82 bool bufferAvailable() const override;
83
84 qint64 position() const override;
85 qint64 duration() const override;
86
88 void setSourceUrl(const QUrl &source);
89
90private slots:
92 void durationChanged(qint64 duration);
93 void error(const QAudioDecoder::Error error, const QString &errorString);
94 void readDevice();
95 void finished();
96
97private:
98 bool requestPermissions();
99 bool createTempFile();
100 void decode();
101
102 QIODevice *m_device = nullptr;
103 Decoder *m_decoder = nullptr;
104
106 QUrl m_source;
107
108 qint64 m_position = -1;
109 qint64 m_duration = -1;
110
111 QByteArray m_deviceBuffer;
112
113 QThread *m_threadDecoder = nullptr;
114};
115
116QT_END_NAMESPACE
117
118#endif // QANDROIDAUDIODECODER_P_H
bool bufferAvailable() const override
QAudioFormat audioFormat() const override
QUrl source() const override
QAudioBuffer read() override
qint64 duration() const override
qint64 position() const 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,...)