AbstractDecoder.h
3.64 KB
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
#ifndef _ABSTRACT_DECODER_H_
#define _ABSTRACT_DECODER_H_
#include<string>
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavdevice/avdevice.h>
#include <libavformat/avformat.h>
#include <libavfilter/avfilter.h>
#include <libavutil/avutil.h>
#include <libavutil/pixdesc.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
}
#include <queue>
#include <mutex>
using namespace std;
struct GPUFrame {
AVFrame * gpuFrame {nullptr};
unsigned long long ts;
~GPUFrame() {
if(gpuFrame != nullptr) {
av_frame_free(&gpuFrame);
gpuFrame = nullptr;
}
}
};
/**************************************************
* 接口:DXDECODER_CALLBACK
* 功能:解码数据回调接口
* 参数:const dx_void * userPtr 用户自定义数据
* GPUFrame * gpuFrame 解码结果帧数据,在设置的对应的gpu上,要十分注意这一点,尤其是多线程情况
* 返回:无
* 备注:当解码库数据源为实时流时(RTSP/GB28181),本接
* 口内不可进行阻塞/耗时操作。当解码库数据源为
* 非实时流时(本地/网络文件),本接口可以进行
* 阻塞/耗时操作
**************************************************/
typedef void(*POST_DECODE_CALLBACK)(const void * userPtr, GPUFrame * gpuFrame);
typedef void(*DECODE_FINISHED_CALLBACK)(const void* userPtr);
typedef bool(*DECODE_REQUEST_STREAM_CALLBACK)(const char* deviceId);
struct FFDecConfig{
string uri; // 视频地址
POST_DECODE_CALLBACK post_decoded_cbk; // 解码数据回调接口
DECODE_FINISHED_CALLBACK decode_finished_cbk; // 解码线程结束后的回调接口
string gpuid; // gpu id
bool force_tcp{true}; // 是否指定使用tcp连接
int skip_frame{1}; // 跳帧数
bool keyframe_decode_mod; // 关键帧模式解码
int port; // gb28181接收数据的端口号
DECODE_REQUEST_STREAM_CALLBACK request_stream_cbk; // gb28181请求流
};
enum DECODER_TYPE{
DECODER_TYPE_GB28181,
DECODER_TYPE_FFMPEG
};
struct FFImgInfo{
string dec_name;
int width;
int height;
unsigned char * pData;
long timestamp;
long index;
};
class AbstractDecoder {
public:
virtual ~AbstractDecoder(){};
virtual bool init(FFDecConfig& cfg) = 0;
virtual void close() = 0;
virtual bool start() = 0;
virtual void pause() = 0;
virtual void resume() = 0;
virtual void setDecKeyframe(bool bKeyframe) = 0;
virtual bool isRunning() = 0;
virtual bool isFinished() = 0;
virtual bool isPausing() = 0;
virtual bool getResolution( int &width, int &height ) = 0;
virtual bool isSurport(FFDecConfig& cfg) = 0;
virtual int getCachedQueueLength() = 0;
virtual float fps() = 0;
virtual DECODER_TYPE getDecoderType() = 0;
void setName(string nm){
m_dec_name = nm;
}
string getName(){
return m_dec_name;
}
FFImgInfo* snapshot();
bool isSnapTime();
void updateLastSnapTime();
void setSnapTimeInterval(long interval);
public:
const void * m_postDecArg;
POST_DECODE_CALLBACK post_decoded_cbk;
const void * m_finishedDecArg;
DECODE_FINISHED_CALLBACK decode_finished_cbk;
public:
string m_dec_name;
bool m_dec_keyframe;
FFDecConfig m_cfg;
queue<GPUFrame*> mFrameQueue;
mutex m_queue_mutex;
mutex m_snapshot_mutex;
long m_snap_time_interval{-1};
long m_last_snap_time;
long m_index{0};
};
#endif // _ABSTRACT_DECODER_H_