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, qint64 position);
43 void durationChanged(const qint64 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
83 qint64 position() const override;
84 qint64 duration() const override;
85
87 void setSourceUrl(const QUrl &source);
88
89private slots:
91 void durationChanged(qint64 duration);
92 void error(const QAudioDecoder::Error error, const QString &errorString);
93 void readDevice();
94 void finished();
95
96private:
97 bool requestPermissions();
98 bool createTempFile();
99 void decode();
100
101 QIODevice *m_device = nullptr;
102 Decoder *m_decoder = nullptr;
103
105 QUrl m_source;
106
107 qint64 m_position = -1;
108 qint64 m_duration = -1;
109
110 QByteArray m_deviceBuffer;
111
112 QThread *m_threadDecoder = nullptr;
113};
114
115QT_END_NAMESPACE
116
117#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,...)