Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwavedecoder.h
Go to the documentation of this file.
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// Qt-Security score:critical reason:data-parser
4
5#ifndef WAVEDECODER_H
6#define WAVEDECODER_H
7
8#include <QtCore/qiodevice.h>
9#include <QtMultimedia/qaudioformat.h>
10
11
13
14
15
16class Q_MULTIMEDIA_EXPORT QWaveDecoder : public QIODevice
17{
18 Q_OBJECT
19
20public:
21 explicit QWaveDecoder(QIODevice *device, QObject *parent = nullptr);
22 explicit QWaveDecoder(QIODevice *device, const QAudioFormat &format,
23 QObject *parent = nullptr);
24 ~QWaveDecoder() override;
25
26 QAudioFormat audioFormat() const;
27 QIODevice* getDevice();
28 int duration() const;
29 static qint64 headerLength();
30
31 bool open(QIODevice::OpenMode mode) override;
32 void close() override;
33 bool seek(qint64 pos) override;
34 qint64 pos() const override;
35 void setIODevice(QIODevice *device);
36 qint64 size() const override;
37 bool isSequential() const override;
38 qint64 bytesAvailable() const override;
39
40Q_SIGNALS:
41 void formatKnown();
42 void parsingError();
43
44private Q_SLOTS:
45 void handleData();
46
47private:
48 qint64 readData(char *data, qint64 maxlen) override;
49 qint64 writeData(const char *data, qint64 len) override;
50
51 bool writeHeader();
52 bool writeDataLength();
53 bool enoughDataAvailable();
54 bool findChunk(const char *chunkId);
55 void discardBytes(qint64 numBytes);
56 void parsingFailed();
57
58 enum State {
59 InitialState,
60 WaitingForFormatState,
61 WaitingForDataState
62 };
63
64 struct chunk
65 {
66 char id[4]; // A four-character code that identifies the representation of the chunk data
67 // padded on the right with blank characters (ASCII 32)
68 quint32 size; // Does not include the size of the id or size fields or the pad byte at the end of payload
69 };
70
71 bool peekChunk(chunk* pChunk, bool handleEndianness = true);
72
73 struct RIFFHeader
74 {
75 chunk descriptor;
76 char type[4];
77 };
78 struct WAVEHeader
79 {
80 chunk descriptor;
81 quint16 audioFormat;
82 quint16 numChannels;
83 quint32 sampleRate;
84 quint32 byteRate;
85 quint16 blockAlign;
86 quint16 bitsPerSample;
87 };
88
89 struct DATAHeader
90 {
91 chunk descriptor;
92 };
93
94 struct CombinedHeader
95 {
96 RIFFHeader riff;
97 WAVEHeader wave;
98 DATAHeader data;
99 };
100 static const int HeaderLength = sizeof(CombinedHeader);
101
102 bool haveFormat = false;
103 bool haveHeader = false;
104 qint64 dataSize = 0;
105 QIODevice *device = nullptr;
106 QAudioFormat format;
107 State state = InitialState;
108 quint32 junkToSkip = 0;
109 bool bigEndian = false;
110 bool byteSwap = false;
111 int bps = 0;
112};
113
114QT_END_NAMESPACE
115
116#endif // WAVEDECODER_H
Combined button and popup list for selecting options.
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")