main.cpp
2.61 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
#include "../DxDecoder/DxDecoderWrap.h"
#include "../DxDecoder/ColorSpace.h"
#include <thread>
#include <iostream>
static void process_thread();
DxDecoderWrap *taskTcuvid ;
using namespace std;
int main() {
int AddTaskSucFlag = 0;
DxConfig cfg = { 0 };
cfg.devId = 0;
cfg.decMode = 0;
cfg.colorFmt = 0;
cfg.forceTcp = false;
cfg.type = DX_DECODER_TYPE_SFXLAB;
taskTcuvid = new DxDecoderWrap(&cfg);
if (NULL == taskTcuvid)
{
printf("Add New DxDecoder Failed!");
AddTaskSucFlag = -1;
return false;
}
int skip_frame_ = 0;
if (taskTcuvid->DxOpenDecoder("file:///home/cmhu/data/video/Street.uvf?fastdecode=on", skip_frame_) != 0)
{
cout << "Add Task Failed! Please check you video file name!" << endl;
delete taskTcuvid;
taskTcuvid = NULL;
AddTaskSucFlag = -1;
return false;
}
int tmp_total_frame = taskTcuvid->DxGetFrameCount();
printf("finish add codec. tmp_total_frame: %d \n", tmp_total_frame);
std::thread* m_psThreadPtr = new std::thread(process_thread);
while (getchar() == 'q');
return 0;
}
void process_thread() {
DxGPUFrame frame = {};
DxGPUFrame task_algorithm_data = {};
while (true)
{
if (taskTcuvid->DxLockFrame(&frame) == 0)
{
if (!task_algorithm_data.frame && frame.width > 0 && frame.height > 0)
{
cudaError_t cudaStatus = cudaMalloc((void**)&task_algorithm_data.frame, 3 * frame.size * frame.height * sizeof(unsigned char));
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "here cudaMalloc m_pRGBData[0] failed! error: %s\n", cudaGetErrorString(cudaStatus));
break;
}
task_algorithm_data.height = frame.height;
task_algorithm_data.width = frame.width;
task_algorithm_data.size = frame.size;
}
//copy decode data
if (task_algorithm_data.frame)
{
int height = frame.height;
int width = frame.width;
Nv12ToColor24<BGR24>( (unsigned char *)frame.frame, width, (unsigned char *)task_algorithm_data.frame, 3 * width, width, height, 0 );
task_algorithm_data.timestamp = frame.timestamp;
cout << "帧号:" << task_algorithm_data.timestamp << endl;
}
else
{
std::cout << "NOT ALLOC: taskDataToBackup.frame" << task_algorithm_data.frame << std::endl;
}
taskTcuvid->DxUnlockFrame();
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
}