/
decoder.h
106 lines (81 loc) · 2.03 KB
/
decoder.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
#ifndef DECODER_H
#define DECODER_H
#include <QThread>
#include <QImage>
extern "C"
{
#include "libavfilter/avfiltergraph.h"
#include "libavfilter/buffersink.h"
#include "libavfilter/buffersrc.h"
#include "libswscale/swscale.h"
#include "libavdevice/avdevice.h"
#include "libavutil/pixfmt.h"
#include "libavutil/opt.h"
#include "libavcodec/avfft.h"
#include "libavutil/imgutils.h"
}
#include "audiodecoder.h"
class Decoder : public QThread
{
Q_OBJECT
public:
enum PlayState {
STOP,
PAUSE,
PLAYING,
FINISH
};
explicit Decoder();
~Decoder();
double getCurrentTime();
void seekProgress(qint64 pos);
int getVolume();
void setVolume(int volume);
private:
void run();
void clearData();
void setPlayState(Decoder::PlayState state);
void displayVideo(QImage image);
static int videoThread(void *arg);
double synchronize(AVFrame *frame, double pts);
bool isRealtime(AVFormatContext *pFormatCtx);
int initFilter();
int fileType;
int videoIndex;
int audioIndex;
int subtitleIndex;
QString currentFile;
QString currentType;
qint64 timeTotal;
AVPacket seekPacket;
qint64 seekPos;
double seekTime;
PlayState playState;
bool isStop;
bool gotStop;
bool isPause;
bool isSeek;
bool isReadFinished;
bool isDecodeFinished;
AVFormatContext *pFormatCtx;
AVCodecContext *pCodecCtx; // video codec context
AvPacketQueue videoQueue;
AvPacketQueue subtitleQueue;
AVStream *videoStream;
double videoClk; // video frame timestamp
AudioDecoder *audioDecoder;
AVFilterGraph *filterGraph;
AVFilterContext *filterSinkCxt;
AVFilterContext *filterSrcCxt;
public slots:
void decoderFile(QString file, QString type);
void stopVideo();
void pauseVideo();
void audioFinished();
signals:
void readFinished();
void gotVideo(QImage image);
void gotVideoTime(qint64 time);
void playStateChanged(Decoder::PlayState state);
};
#endif // DECODER_H