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 WAVEDECODER_H |
5 | #define WAVEDECODER_H |
6 | |
7 | #include <QtCore/qiodevice.h> |
8 | #include <QtMultimedia/qaudioformat.h> |
9 | |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | |
14 | |
15 | class Q_MULTIMEDIA_EXPORT QWaveDecoder : public QIODevice |
16 | { |
17 | Q_OBJECT |
18 | |
19 | public: |
20 | explicit QWaveDecoder(QIODevice *device, QObject *parent = nullptr); |
21 | explicit QWaveDecoder(QIODevice *device, const QAudioFormat &format, |
22 | QObject *parent = nullptr); |
23 | ~QWaveDecoder(); |
24 | |
25 | QAudioFormat audioFormat() const; |
26 | QIODevice* getDevice(); |
27 | int duration() const; |
28 | static qint64 (); |
29 | |
30 | bool open(QIODevice::OpenMode mode) override; |
31 | void close() override; |
32 | bool seek(qint64 pos) override; |
33 | qint64 pos() const override; |
34 | void setIODevice(QIODevice *device); |
35 | qint64 size() const override; |
36 | bool isSequential() const override; |
37 | qint64 bytesAvailable() const override; |
38 | |
39 | Q_SIGNALS: |
40 | void formatKnown(); |
41 | void parsingError(); |
42 | |
43 | private Q_SLOTS: |
44 | void handleData(); |
45 | |
46 | private: |
47 | qint64 readData(char *data, qint64 maxlen) override; |
48 | qint64 writeData(const char *data, qint64 len) override; |
49 | |
50 | bool (); |
51 | bool writeDataLength(); |
52 | bool enoughDataAvailable(); |
53 | bool findChunk(const char *chunkId); |
54 | void discardBytes(qint64 numBytes); |
55 | void parsingFailed(); |
56 | |
57 | enum State { |
58 | InitialState, |
59 | WaitingForFormatState, |
60 | WaitingForDataState |
61 | }; |
62 | |
63 | struct chunk |
64 | { |
65 | char id[4]; |
66 | quint32 size; |
67 | }; |
68 | bool peekChunk(chunk* pChunk, bool handleEndianness = true); |
69 | |
70 | struct |
71 | { |
72 | chunk ; |
73 | char [4]; |
74 | }; |
75 | struct |
76 | { |
77 | chunk ; |
78 | quint16 ; |
79 | quint16 ; |
80 | quint32 ; |
81 | quint32 ; |
82 | quint16 ; |
83 | quint16 ; |
84 | }; |
85 | |
86 | struct |
87 | { |
88 | chunk ; |
89 | }; |
90 | |
91 | struct |
92 | { |
93 | RIFFHeader ; |
94 | WAVEHeader ; |
95 | DATAHeader ; |
96 | }; |
97 | static const int = sizeof(CombinedHeader); |
98 | |
99 | bool haveFormat = false; |
100 | bool = false; |
101 | qint64 dataSize = 0; |
102 | QIODevice *device = nullptr; |
103 | QAudioFormat format; |
104 | State state = InitialState; |
105 | quint32 junkToSkip = 0; |
106 | bool bigEndian = false; |
107 | bool byteSwap = false; |
108 | int bps = 0; |
109 | }; |
110 | |
111 | QT_END_NAMESPACE |
112 | |
113 | #endif // WAVEDECODER_H |
114 | |