-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAudioDecoder.h
50 lines (40 loc) · 998 Bytes
/
AudioDecoder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef AUDIODECODER_H
#define AUDIODECODER_H
#include <QAudioDecoder>
#include <QAudioFormat>
#include <QBuffer>
#include <QIODevice>
#include <QPointer>
class AudioDecoder :
public QIODevice
{
Q_OBJECT
public:
enum State { Decoding, Stopped };
explicit AudioDecoder(QObject *parent = 0);
~AudioDecoder();
bool atEnd() const override;
public slots:
void init(const QAudioFormat &format);
void start(const QString &filePath);
void stop();
protected:
qint64 readData(char* data, qint64 maxlen) override;
qint64 writeData(const char* data, qint64 len) override;
private:
State m_state;
QPointer<QAudioDecoder> m_decoder;
QBuffer m_input;
QBuffer m_output;
QByteArray m_data;
bool m_init;
bool m_isDecodingFinished;
private slots:
void bufferReady();
void finished();
void errored(QAudioDecoder::Error);
signals:
void initialized();
void newData(const QByteArray& data);
};
#endif // AUDIODECODER_H