-
Notifications
You must be signed in to change notification settings - Fork 8
/
AudioPlayerThread.h
59 lines (46 loc) · 1.25 KB
/
AudioPlayerThread.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
51
52
53
54
55
56
57
58
59
#ifndef AUDIOPLAYERTHREAD_H
#define AUDIOPLAYERTHREAD_H
#include <QThread>
#include <QAudioFormat>
#include <QAudioOutput>
#include <QByteArray>
#include <QMutex>
#include <QWaitCondition>
#include <atomic>
#include <QTime>
class DecodecVideo;
class AudioPlayerThread : public QThread
{
Q_OBJECT
public:
AudioPlayerThread(QObject* parent = nullptr);
~AudioPlayerThread();
void run(void) override;
// set sample infos
void setSampleInfo(int sampleRate, int sampleSize, int channelCount);
// set Audio Data
void setAudioData(char* audioData, int length);
// get current play time
qreal getCurrentPlayTime(void);
// set decodec
void setDecodec(DecodecVideo* decodec);
// set current time
void setCurrentTimeForce(qreal time);
private:
QAudioFormat m_format;
QAudioOutput* m_pAudioOutput = nullptr;
QByteArray m_audioData;
QIODevice* m_pIODevice = nullptr;
DecodecVideo* m_pDecodecVideo = nullptr;
QMutex m_mutex;
QMutex m_waitMutex;
QWaitCondition m_waitCondition;
bool isAudioEmpty(void);
std::atomic<int> m_nStartPopIndex;
std::atomic<int> m_nEndPushIndex;
std::atomic<int> m_nTotalCanUsed;
std::atomic<qreal> m_nCurrentPlayIndex;
// for test
QTime m_time;
};
#endif