1// Copyright (C) 2016 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 QAUDIODECODER_H
5#define QAUDIODECODER_H
6
7#include <QtCore/qobject.h>
8#include <QtMultimedia/qmediaenumdebug.h>
9
10#include <QtMultimedia/qaudiobuffer.h>
11
12QT_BEGIN_NAMESPACE
13
14class QPlatformAudioDecoder;
15class Q_MULTIMEDIA_EXPORT QAudioDecoder : public QObject
16{
17 Q_OBJECT
18 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
19 Q_PROPERTY(bool isDecoding READ isDecoding NOTIFY isDecodingChanged)
20 Q_PROPERTY(QString error READ errorString)
21 Q_PROPERTY(bool bufferAvailable READ bufferAvailable NOTIFY bufferAvailableChanged)
22
23public:
24 enum Error
25 {
26 NoError,
27 ResourceError,
28 FormatError,
29 AccessDeniedError,
30 NotSupportedError
31 };
32 Q_ENUM(Error)
33
34 explicit QAudioDecoder(QObject *parent = nullptr);
35 ~QAudioDecoder();
36
37 bool isSupported() const;
38 bool isDecoding() const;
39
40 QUrl source() const;
41 void setSource(const QUrl &fileName);
42
43 QIODevice* sourceDevice() const;
44 void setSourceDevice(QIODevice *device);
45
46 QAudioFormat audioFormat() const;
47 void setAudioFormat(const QAudioFormat &format);
48
49 Error error() const;
50 QString errorString() const;
51
52 QAudioBuffer read() const;
53 bool bufferAvailable() const;
54
55 qint64 position() const;
56 qint64 duration() const;
57
58public Q_SLOTS:
59 void start();
60 void stop();
61
62Q_SIGNALS:
63 void bufferAvailableChanged(bool);
64 void bufferReady();
65 void finished();
66 void isDecodingChanged(bool);
67
68 void formatChanged(const QAudioFormat &format);
69
70 void error(QAudioDecoder::Error error);
71
72 void sourceChanged();
73
74 void positionChanged(qint64 position);
75 void durationChanged(qint64 duration);
76
77private:
78 Q_DISABLE_COPY(QAudioDecoder)
79 QPlatformAudioDecoder *decoder = nullptr;
80};
81
82QT_END_NAMESPACE
83
84Q_MEDIA_ENUM_DEBUG(QAudioDecoder, Error)
85
86#endif // QAUDIODECODER_H
87

source code of qtmultimedia/src/multimedia/audio/qaudiodecoder.h