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