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