-
Notifications
You must be signed in to change notification settings - Fork 8
/
DecodecVideo.h
154 lines (126 loc) · 3.36 KB
/
DecodecVideo.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef DECODECVIDEO_H
#define DECODECVIDEO_H
#include <QString>
#include <QObject>
#include <QThread>
#include <QSemaphore>
#include <QMutex>
#include <atomic>
#include <QTime>
extern "C"{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
#include <libswresample/swresample.h>
}
class OpenGLRender;
class AudioPlayerThread;
class DecodecVideo : public QThread
{
Q_OBJECT
public:
struct DecodecVideInfo
{
// Video Info
int width = 0;
int height = 0;
bool isYUV420P = false;
// Audio Info
int sampleRate = 44100;
int sampleSize = 16;
int channelSize = 2;
bool needToConver = true;
// global infos
qreal totalTime = 0;
};
struct FrameData
{
qreal currentPts = 0.0;
uchar* pImageData;
};
enum PlayStatus
{
Player_Normal,
Player_Playing,
Player_Pause,
Player_Stop
};
public:
DecodecVideo(QObject* parent = nullptr);
~DecodecVideo();
// open video file
bool openVideoFile(const QString& fileName);
// get frame data
void getFrameData(uchar*& imageData);
void getFrameData(AVFrame*& frame);
void freeFrame(AVFrame* frame);
// get current infos
const DecodecVideInfo& getCurrentInfo(void);
// updateToDisplay
void updateToDisplay(qreal currentTime);
void updateToDisplay2(qreal currentTime);
// get Audio BufferData
void getAudioBufferData(QByteArray& byte);
// set Audio Player
void setAudioPlayer(AudioPlayerThread* audioPlayer);
// get Audio output Infos
void getAudioOutputInfos(int& sampleRato, int& sampleSize, int& channelSize);
void run(void) override;
// seek Video
void seekVideo(qreal time);
// set Current Status
void setCurrentPlayerStatus(PlayStatus status);
PlayStatus getCurrentPlayerStatus(void);
// for test
void testCall(void);
private:
AVFormatContext* m_pFormatContext = nullptr;
AVCodecContext* m_pVideoCodecContext = nullptr;
AVCodecContext* m_pAudioCodecContext = nullptr;
AVFrame* m_pFrame = nullptr;
AVFrame* m_pRGBFrame = nullptr;
AVFrame* m_pTempFrame = nullptr;
SwsContext* m_pSwsContext = nullptr;
SwrContext* m_pSwrContext = nullptr;
int m_nVideoIndex = -1;
int m_nAudioIndex = -1;
// Frame To RGB
void frameToRgbImage(AVFrame* pDest, AVFrame* frame);
// Frame To sample size 16bit
int frameSameSampe(AVFrame* frame, uchar* pDest, int size);
// Image Data Buffer
FrameData m_pImageData[60];
AVFrame* m_frameData[60];
uchar* m_pDestBufferData = nullptr;
// info
DecodecVideInfo m_decodecInfo;
private:
static int m_nFrameBufferSize;
// for Video
// sync thread
QSemaphore m_semaphore;
std::atomic<int> m_nHeadIndex;
std::atomic<int> m_nEndIndex;
std::atomic<int> m_nCurrentSize;
std::atomic<int> m_nPlayerStatus;
// open video decodec
bool openVideoCodec(void);
// decodec Video
void decodecVideo(AVPacket* packet);
private:
// for Audio
uchar *m_pTempBuffer = nullptr;
QByteArray m_audioArray;
QMutex m_audioMutex;
AudioPlayerThread* m_pAudioThread = nullptr;
// open audio decodec
bool openAudioCodec(void);
// decodec Audio
void decodecAudio(AVPacket* packet);
// For Test
QTime m_time;
signals:
void updateDisplay(qreal time);
};
#endif