MutliSourceVideoProcess.h
8.16 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
//#pragma once
#ifndef __MutliSourceVideoProcess_H__
#define __MutliSourceVideoProcess_H__
#include <stdlib.h>
#include <iostream>
#include "../FFNvDecoder/DxDecoderWrap.h"
#include "nvml.h"
#include "time.h"
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "VPTProcess.h"
#include <queue>
#include <set>
#include <boost/thread/thread.hpp>
#include "common.h"
#include "../FFNvDecoder/ImageSaveGPU.h"
#include "mvpt_process_assist.h"
#include <boost/thread/thread_pool.hpp>
#include "snapshot_helper.h"
#include "FaceDetModule.h"
#include <atomic>
//#include "DxLogInterface.h"
#ifdef _MSC_VER
#ifdef _DEBUG
#pragma comment(lib, "opencv_world310d.lib")
#else
#pragma comment(lib, "opencv_world310.lib")
#endif
#endif
using namespace cv;
using namespace std;
#ifndef _MSC_VER
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define Sleep(a) usleep((a)*1000)
//typedef int BOOL;
#define BOOL bool
typedef unsigned int DWORD;
typedef void* LPVOID;
#endif
#ifdef _DEBUG
#define DEBUG_MSG(msg,...) \
{ \
printf("%s %s [%d]: ", __FILE__, __FUNCTION__, __LINE__); \
printf(msg,##__VA_ARGS__); \
printf("\n"); \
}
#else
#define DEBUG_MSG(msg,...)
#endif
#define MAXLENGTH 416
#define MINLENGTH 224
//#define PROCESSHEIGHT 224
//#define PROCESSWIDTH 416
//#define DATASIZE PROCESSWIDTH * PROCESSHEIGHT * 3
#define THREAD_COUNT 30
#define SNAPSHOTFRAME 15
#define LOSTMAXFRAMECCOUNT 4
#define SCALE_OUT 10 //�ж�Ŀ����ʼλ��ʱ������С����Ļ������ʵ�����
#define MAX_BATCH 10
extern int minDistance[];
enum TaskState
{
PLAY,
PAUSE,
FINISH,
DECODEERROR //�����߳̿��ܱ���������֮��ֱ�ӽ�������·����
};
struct VideoHeightWidth{
double height;
double width;
};
struct VideoObjectSS
{
unsigned char * obj_person;
unsigned char * obj_bike;
unsigned char * obj_car;
VideoObjectSS() : obj_person(NULL), obj_bike(NULL), obj_car(NULL){}
};
template <typename T> class MyAtomic;
template<typename T>
bool operator == (MyAtomic<T> & d1, T &d2);
template<typename T>
bool operator == (MyAtomic<T> & d1, MyAtomic<T> &d2);
template <typename T>
class MyAtomic
{
public:
MyAtomic() {};
MyAtomic(const T & d) { data.store(d); };
MyAtomic(const MyAtomic & d) { data.store(d.data.load()); };
MyAtomic& operator =(T d) { data.store(d); return *this; };
MyAtomic& operator =(MyAtomic & d) { data.store(d.data.load()); return *this; };
MyAtomic& operator +=(T d) { data.fetch_add(d); return *this; };
MyAtomic& operator +=(MyAtomic & d) { data.fetch_add(d); return *this; };
operator int() { return data.load(); }
friend bool operator ==<T> (MyAtomic<T> &d1, T &d2);
friend bool operator ==<T> (MyAtomic<T> &d1, MyAtomic<T> &d2);
private:
std::atomic<T> data;
};
template<typename T>
bool operator == (MyAtomic<T> & d1, T &d2)
{
if (d1.data.load() == d2)
return true;
else
return false;
}
template<typename T>
bool operator == (MyAtomic<T> & d1, MyAtomic<T> & d2)
{
if (d1.data.load() == d2.load())
return true;
else
return false;
}
struct Task{
int taskID;
const char *taskFileSource;
TaskState taskState;
DxDecoderWrap *taskTcuvid;
DxGPUFrame task_algorithm_data; //����¿�ܲ���resize�Ĵ���������ʱ��backup��ԭͼ��С��ͼƬ�ͽ��㷨�������
float* taskDataToRT;
bool taskHasBackup;
//VideoHeightWidth taskHeightWidthRatio;
VideoHeightWidth taskHeightWidth;
MyAtomic<int> taskFrameCount;
MyAtomic<int> taskLastFrameCount;
int taskTotalFrameCount;
SNAPSHOT_CALLBACK taskObjCallbackFunc;
REALTIME_CALLBACK taskRealTimeCallbackFunc;
cv::Mat frameImage;
char* folderNameLittle;
char* folderName;
char* folderNameFace;
sy_rect task_min_boxsize[DETECTTYPE];
};
enum TaskOperator
{
ADDTASK,
PAUSETASK,
RESTARTTASK,
FINISHTASK
};
struct Operator{
int changeTaskID;
char videoFileName[256];
char resultFolderLittleName[256];
char resultFolderName[256];
char result_folder_face[256];
bool on_image_display;
int jpeg_quality;
int decMode;
TaskOperator changeTaskOperator;
VIDEO_OBJECT_SNAPSHOT_CALLBACK taskObjCallbackFunc;
VIDEO_REALTIME_CALLBACK taskRealTimeCallbackFunc;
sy_rect minBoxsize[DETECTTYPE];
};
struct CUVID_USERDATA{
int id;
void *opaque;
};
struct CUVID_DATA{
float* pData;
int nWidth;
int nHeight;
int nDatasize;
};
struct SNAPSHOT_PROCESS_UNIT{
vector<DxGPUFrame> imgBig;
vector<DxGPUFrame> imgSmall;
vector<VPT_Result> imgVPTResult;
};
class CMutliSourceVideoProcess
{
public:
CMutliSourceVideoProcess();
~CMutliSourceVideoProcess();
int InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_INFO_CALLBACK tObjInfoCallbackFunc, VIDEO_FINISH_CALLBACK tFinishCallbackFunc);
void* GetVPT_Handle(){ return VPT_Handle; };
int get_task_progress(int taskid, double & progress);
void OperatorTask();
bool HasNewTask() {
return !TaskOperatorQ.empty();
}
void AddOperator(int taskID, int taskOper);
int AddOperator(task_param tparam);
void callTaskObjInfoCallbackFunc(int objCount, VPT_ObjInfo *obj, int taskFrameCount, int taskId);
bool AddTask(task_param tparam);
void PauseTask(const int taskID);
void RestartTask(const int taskID);
void FinishTask(const int taskID);
void ViewTask(const int taskID);
void FinishViewTask();
int FinishProcessThread();
int SaveResultInFile(const OBJ_KEY & obj_key, const OBJ_VALUE & obj_value);
void FinishDecode(const int taskID);
int GetRuningNb();
private:
//bool ChangeTask;
//HANDLE handle_process;
boost::thread ProcessThread;
std::mutex _tx_add_task;
//DWORD dwThreadID;
deque<Operator> TaskOperatorQ;
int capacity;
//cv::Mat objSnapshot;
double gpu_total_memory;
boost::thread thrd;
void* authority_handle;
public: /*��������Ӧ����public�� �������̺߳����л��õ����µ����� ÿ����дһ��get����̫������*/
//fstream fout[THREAD_COUNT]; //����������
void * VPT_Handle;
face_det_module* m_face_det_module;
int section_batch_size;
int licence_status;
int thrd_status;
int mgpuid;
int skip_frame_ {5}; // 控制跳帧参数
vector<Task> tasks;
int AddTaskSucFlag; //0:��ʼ��״̬ 1����������ɹ� -1����������ʧ��
int TaskinPlay;
int TotalTask;
set<int> TaskinPlayID;
// float* pDataToVPT;
vector<VPT_Result> VPTResult;
std::atomic<bool> ProcessFlag;
bool SourceFlag;
//float* imgDataHost;
//float* snapshotDataHost;
unsigned char* imgDataDecive;
// void * FrameTemp;
char* mModeSnapshotVideo;
char* mModeSnapshotLittle;
int viewTaskID;
map<int, set<int>> objDelete;
FINISH_CALLBACK taskFinishCallbackFunc;
OBJECT_INFO_CALLBACK taskObjInfoCallbackFunc;
queue<SNAPSHOT_PROCESS_UNIT> snapshotProcessQueue;
//CUcontext cuCtx;
//int PROCESSHEIGHT;
//int PROCESSWIDTH;
//int DATASIZE;
bool beginSaveSnapshot;
boost::thread_group saveSnapshotsThreadGroup;
//boost::mutex process_thread_mutex;
std::mutex taskMutex;
std::condition_variable taskCondVar;
bool AttributionAnalysis; //���ڿ��ƣ�ÿ֡����ֻ����һ���������Է���
//�㷨���ò���
sy_command m_hp_analysis_config; //�Ƿ���������ʶ��
sy_command m_hcp_analysis_config; //�Ƿ��������Ƽ��ʶ��
sy_command m_vehicle_analysis_config; //�Ƿ�����������ɫʶ��
sy_command m_vehicle_recg_config; //�Ƿ�������������ʶ��
sy_command m_vehicle_plate_det_recg_config; //�Ƿ�������Υ����Ϊ���
sy_command m_hf_recg_config; //�Ƿ�����������ʶ��
sy_command m_hcf_recg_config; //�Ƿ������ﳵ����ʶ��
sy_command m_vcf_recg_config; //�Ƿ�����������ʶ��
sy_command m_face_det_config; //�Ƿ����������
snapshot_helper m_snaphot_helper;
};
static CMutliSourceVideoProcess mainProcess;
#endif