main.cpp
3.53 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
#include "FFNvDecoderManager.h"
#include <iostream>
#include "cuda_kernels.h"
#include "NvJpegEncoder.h"
unsigned char *pHwRgb = nullptr;
void postDecoded(const void * userPtr, AVFrame * gpuFrame){
FFNvDecoder* decoder = (FFNvDecoder*)userPtr;
if (decoder!= nullptr)
{
cout << decoder->getName() << endl;
const char* gpu_pixfmt = av_get_pix_fmt_name((AVPixelFormat)gpuFrame->format);
cout << "pixfmt: " << gpu_pixfmt << endl;
cout << "keyframe: " << gpuFrame->key_frame << " width: " << gpuFrame->width << " height: "<< gpuFrame->height << endl;
cout << "decode successed ✿✿ヽ(°▽°)ノ✿ " << endl;
if (gpuFrame->format == AV_PIX_FMT_CUDA)
{
cout << "gpuid = " << atoi(decoder->m_cfg.gpuid.c_str()) << endl;
// cudaSetDevice(atoi(decoder->m_cfg.gpuid.c_str()));
// cudaError_t cudaStatus;
// if(pHwRgb == nullptr){
// cuda_common::setColorSpace2( ITU709, 0 );
// cudaStatus = cudaMalloc((void **)&pHwRgb, 3 * gpuFrame->width * gpuFrame->height * sizeof(unsigned char));
// }
// cudaStatus = cuda_common::CUDAToBGR((CUdeviceptr)gpuFrame->data[0],(CUdeviceptr)gpuFrame->data[1], gpuFrame->linesize[0], gpuFrame->linesize[1], pHwRgb, gpuFrame->width, gpuFrame->height);
// cudaDeviceSynchronize();
// if (cudaStatus != cudaSuccess) {
// cout << "CUDAToBGR failed !!!" << endl;
// return;
// }
// string path = "/home/cmhu/FFNvDecoder/" + decoder->m_cfg.gpuid + ".jpg";
// saveJpeg(path.c_str(), pHwRgb, gpuFrame->width, gpuFrame->height); // 验证 CUDAToRGB
}
}
}
int main(){
FFNvDecoderManager* pDecManager = FFNvDecoderManager::getInstance();
MgrDecConfig config;
config.name = "dec1";
config.cfg.uri = "rtmp://192.168.10.56:1935/objecteye/1";
config.cfg.post_decoded_cbk = postDecoded;
config.cfg.force_tcp = true;
config.cfg.gpuid = "1";
FFNvDecoder* decoder = pDecManager->createDecoder(config);
if (!decoder)
{
return 1;
}
pDecManager->setUserPtr(config.name, decoder);
pDecManager->startDecodeByName(config.name);
config.name = "dec2";
config.cfg.uri = "rtmp://192.168.10.56:1935/objecteye/1";
config.cfg.gpuid = "2";
FFNvDecoder* dec2 = pDecManager->createDecoder(config);
if (!dec2)
{
return 1;
}
pDecManager->setUserPtr(config.name, dec2);
pDecManager->startDecodeByName(config.name);
config.name = "dec0";
config.cfg.uri = "rtmp://192.168.10.56:1935/objecteye/1";
config.cfg.gpuid = "0";
FFNvDecoder* dec0 = pDecManager->createDecoder(config);
if (!dec0)
{
return 1;
}
pDecManager->setUserPtr(config.name, dec0);
pDecManager->startDecodeByName(config.name);
config.name = "dec01";
config.cfg.uri = "rtmp://192.168.10.56:1935/objecteye/1";
config.cfg.gpuid = "0";
FFNvDecoder* dec01 = pDecManager->createDecoder(config);
if (!dec01)
{
return 1;
}
pDecManager->setUserPtr(config.name, dec01);
pDecManager->startDecodeByName(config.name);
// while (getchar() != 'q');
// // pDecManager->closeDecoderByName("dec1");
// // pDecManager->pauseDecoder("dec1");
// pDecManager->pauseDecoder("dec2");
// while (getchar() != 'q');
// // pDecManager->resumeDecoder("dec1");
// pDecManager->resumeDecoder("dec2");
while (getchar() != 'q');
pDecManager->closeAllDecoder();
}