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 QAUDIODECODERCONTROL_H
5#define QAUDIODECODERCONTROL_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
18#include <QtMultimedia/qaudiodecoder.h>
19
20#include <QtCore/qpair.h>
21
22#include <QtMultimedia/qaudiobuffer.h>
23#include <QtMultimedia/qaudiodecoder.h>
24#include <QtCore/private/qglobal_p.h>
25
26QT_BEGIN_NAMESPACE
27
28class QIODevice;
29class Q_MULTIMEDIA_EXPORT QPlatformAudioDecoder : public QObject
30{
31 Q_OBJECT
32
33public:
34 virtual QUrl source() const = 0;
35 virtual void setSource(const QUrl &fileName) = 0;
36
37 virtual QIODevice* sourceDevice() const = 0;
38 virtual void setSourceDevice(QIODevice *device) = 0;
39
40 virtual void start() = 0;
41 virtual void stop() = 0;
42
43 virtual QAudioFormat audioFormat() const = 0;
44 virtual void setAudioFormat(const QAudioFormat &format) = 0;
45
46 virtual QAudioBuffer read() = 0;
47 virtual bool bufferAvailable() const { return m_bufferAvailable; }
48
49 virtual qint64 position() const { return m_position; }
50 virtual qint64 duration() const { return m_duration; }
51
52 void formatChanged(const QAudioFormat &format);
53
54 void sourceChanged();
55
56 void error(int error, const QString &errorString);
57 void clearError() { error(error: QAudioDecoder::NoError, errorString: QString()); }
58
59 void bufferReady();
60 void bufferAvailableChanged(bool available);
61 void setIsDecoding(bool running = true) {
62 if (m_isDecoding == running)
63 return;
64 m_isDecoding = running;
65 emit q->isDecodingChanged(m_isDecoding);
66 }
67 void finished();
68 bool isDecoding() const { return m_isDecoding; }
69
70 void positionChanged(qint64 position);
71 void durationChanged(qint64 duration);
72
73 QAudioDecoder::Error error() const { return m_error; }
74 QString errorString() const { return m_errorString; }
75
76protected:
77 explicit QPlatformAudioDecoder(QAudioDecoder *parent);
78private:
79 QAudioDecoder *q = nullptr;
80
81 qint64 m_duration = -1;
82 qint64 m_position = -1;
83 QAudioDecoder::Error m_error = QAudioDecoder::NoError;
84 QString m_errorString;
85 bool m_isDecoding = false;
86 bool m_bufferAvailable = false;
87};
88
89QT_END_NAMESPACE
90
91#endif // QAUDIODECODERCONTROL_H
92

source code of qtmultimedia/src/multimedia/platform/qplatformaudiodecoder_p.h