Commit 54f4a423431206237206bfdf92bcd4a4a00f00ed

Authored by Hu Chunming
1 parent afd07f06

添加resize到1920,1080设置

src/ai_platform/MultiSourceProcess.cpp
@@ -84,17 +84,17 @@ CMultiSourceProcess::~CMultiSourceProcess(){ @@ -84,17 +84,17 @@ CMultiSourceProcess::~CMultiSourceProcess(){
84 } 84 }
85 85
86 int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ 86 int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){
87 -#ifdef USE_VILLAGE  
88 - if (!CheckTime()) { //时间限制  
89 - std::cout << "sy_licence_check failed." << std::endl;  
90 - return AUTHOR_ERROR;  
91 - }  
92 -#else  
93 - if (!CheckLabel(vptParam.gpuid)) { //机器授权  
94 - std::cout << "sy_licence_check failed." << std::endl;  
95 - return AUTHOR_ERROR;  
96 - }  
97 -#endif 87 +// #ifdef USE_VILLAGE
  88 +// if (!CheckTime()) { //时间限制
  89 +// std::cout << "sy_licence_check failed." << std::endl;
  90 +// return AUTHOR_ERROR;
  91 +// }
  92 +// #else
  93 +// if (!CheckLabel(vptParam.gpuid)) { //机器授权
  94 +// std::cout << "sy_licence_check failed." << std::endl;
  95 +// return AUTHOR_ERROR;
  96 +// }
  97 +// #endif
98 set_default_logger(LogLevel(vptParam.log_level), "multi_source_process", vptParam.log_path, vptParam.log_mem, vptParam.log_mem); 98 set_default_logger(LogLevel(vptParam.log_level), "multi_source_process", vptParam.log_path, vptParam.log_mem, vptParam.log_mem);
99 LOG_INFO("编译时间:{} {}", __DATE__, __TIME__); 99 LOG_INFO("编译时间:{} {}", __DATE__, __TIME__);
100 100
@@ -324,7 +324,8 @@ bool CMultiSourceProcess::AddTask(task_param _cur_task_param){ @@ -324,7 +324,8 @@ bool CMultiSourceProcess::AddTask(task_param _cur_task_param){
324 config.cfg.force_tcp = true; // rtsp用tcp 324 config.cfg.force_tcp = true; // rtsp用tcp
325 config.cfg.gpuid = to_string(m_devId); 325 config.cfg.gpuid = to_string(m_devId);
326 config.cfg.skip_frame = skip_frame_; 326 config.cfg.skip_frame = skip_frame_;
327 - 327 + config.cfg.resize = true;
  328 +
328 if (1 == _cur_task_param.dec_type){ 329 if (1 == _cur_task_param.dec_type){
329 config.cfg.port = _cur_task_param.port; 330 config.cfg.port = _cur_task_param.port;
330 config.dec_type = DECODER_TYPE_GB28181; 331 config.dec_type = DECODER_TYPE_GB28181;
@@ -360,7 +361,7 @@ bool CMultiSourceProcess::AddTask(task_param _cur_task_param){ @@ -360,7 +361,7 @@ bool CMultiSourceProcess::AddTask(task_param _cur_task_param){
360 361
361 int input_image_width = 0; 362 int input_image_width = 0;
362 int input_image_height = 0; 363 int input_image_height = 0;
363 - pDecManager->getResolution(config.name, input_image_width, input_image_height); 364 + pDecManager->getOutResolution(config.name, input_image_width, input_image_height);
364 LOG_INFO("task_id: {} width: {} height:{}", task_id, input_image_width, input_image_height); 365 LOG_INFO("task_id: {} width: {} height:{}", task_id, input_image_width, input_image_height);
365 366
366 // 所有参数都准备好之后再启动解码 367 // 所有参数都准备好之后再启动解码
@@ -761,21 +762,21 @@ int CMultiSourceProcess::algorthim_process_thread(){ @@ -761,21 +762,21 @@ int CMultiSourceProcess::algorthim_process_thread(){
761 ACL_CALL(aclrtCreateContext(&ctx, m_devId), ACL_SUCCESS, 1); 762 ACL_CALL(aclrtCreateContext(&ctx, m_devId), ACL_SUCCESS, 1);
762 763
763 while (true){ 764 while (true){
764 -#ifdef USE_VILLAGE  
765 - if (!CheckTime()) { //时间限制  
766 - LOG_FATAL("authority failed!");  
767 - break;  
768 - }  
769 -#else  
770 - if (check_label == -1) { //机器授权  
771 - LOG_FATAL("authority failed!");  
772 - break;  
773 - }  
774 - if (!UpdateLabel()) {  
775 - LOG_FATAL("authority failed!");  
776 - break;  
777 - }  
778 -#endif 765 +// #ifdef USE_VILLAGE
  766 +// if (!CheckTime()) { //时间限制
  767 +// LOG_FATAL("authority failed!");
  768 +// break;
  769 +// }
  770 +// #else
  771 +// if (check_label == -1) { //机器授权
  772 +// LOG_FATAL("authority failed!");
  773 +// break;
  774 +// }
  775 +// if (!UpdateLabel()) {
  776 +// LOG_FATAL("authority failed!");
  777 +// break;
  778 +// }
  779 +// #endif
779 if(m_bfinish){ 780 if(m_bfinish){
780 break; 781 break;
781 } 782 }
src/decoder/dvpp/DvppDataMemory.hpp
  1 +#ifndef __DVPP_DATA_MEMORY_HPP__
  2 +#define __DVPP_DATA_MEMORY_HPP__
  3 +
1 #include<string> 4 #include<string>
2 5
3 #include "depend_headers.h" 6 #include "depend_headers.h"
@@ -66,11 +69,11 @@ public: @@ -66,11 +69,11 @@ public:
66 } 69 }
67 pHwRgb = nullptr; 70 pHwRgb = nullptr;
68 } 71 }
69 -  
70 -  
71 -  
72 } 72 }
73 73
74 public: 74 public:
75 int data_type; // 0: rgb , 1: NV12 75 int data_type; // 0: rgb , 1: NV12
76 -};  
77 \ No newline at end of file 76 \ No newline at end of file
  77 +};
  78 +
  79 +
  80 +#endif // __DVPP_DATA_MEMORY_HPP__
78 \ No newline at end of file 81 \ No newline at end of file
src/decoder/dvpp/DvppDecoder.cpp
@@ -184,6 +184,9 @@ AVCodecContext* DvppDecoder::init_FFmpeg(FFDecConfig config){ @@ -184,6 +184,9 @@ AVCodecContext* DvppDecoder::init_FFmpeg(FFDecConfig config){
184 frame_height = codecpar->height; 184 frame_height = codecpar->height;
185 pix_fmt = (AVPixelFormat)codecpar->format; 185 pix_fmt = (AVPixelFormat)codecpar->format;
186 186
  187 + m_bResize = config.resize;
  188 + calcOutResolution(frame_width, frame_height);
  189 +
187 if (stream->avg_frame_rate.den) { 190 if (stream->avg_frame_rate.den) {
188 m_fps = av_q2d(stream ->avg_frame_rate); 191 m_fps = av_q2d(stream ->avg_frame_rate);
189 } else { 192 } else {
@@ -197,7 +200,7 @@ AVCodecContext* DvppDecoder::init_FFmpeg(FFDecConfig config){ @@ -197,7 +200,7 @@ AVCodecContext* DvppDecoder::init_FFmpeg(FFDecConfig config){
197 } 200 }
198 #endif 201 #endif
199 202
200 - LOG_INFO("[{}]- init ffmpeg success! input:{} frame_width:{} frame_height:{} fps:{} ", m_dec_name, input_file, frame_width, frame_height, m_fps); 203 + LOG_INFO("[{}]- init ffmpeg success! input:{} src:({}, {}) out:({}, {}) fps:{} ", m_dec_name, input_file, frame_width, frame_height, out_frame_width, out_frame_height, m_fps);
201 204
202 return avctx; 205 return avctx;
203 }while(0); 206 }while(0);
@@ -209,6 +212,33 @@ AVCodecContext* DvppDecoder::init_FFmpeg(FFDecConfig config){ @@ -209,6 +212,33 @@ AVCodecContext* DvppDecoder::init_FFmpeg(FFDecConfig config){
209 return nullptr; 212 return nullptr;
210 } 213 }
211 214
  215 +void DvppDecoder::calcOutResolution(int width, int height) {
  216 + if(m_bResize) {
  217 + float srcRatio = width / (float)height;
  218 + float stdRatio = 1920.0 / 1080.0f ;
  219 + int outWidth = 1920;
  220 + int outHeight = 1080;
  221 + if (srcRatio > stdRatio) {
  222 + outHeight = static_cast<int>(outWidth * (float)height / width) ;
  223 + if (outHeight % 2 == 1) {
  224 + outHeight += 1;
  225 + }
  226 + } else if (srcRatio < stdRatio) {
  227 + outWidth = static_cast<int>(outHeight * (float)width / height) ;
  228 + if (outWidth % 2 == 1) {
  229 + outWidth += 1;
  230 + }
  231 + }
  232 +
  233 + out_frame_width = outWidth;
  234 + out_frame_height = outHeight;
  235 + } else {
  236 + out_frame_width = width;
  237 + out_frame_height = height;
  238 + }
  239 +
  240 +}
  241 +
212 int DvppDecoder::getVdecType(int videoType, int profile) 242 int DvppDecoder::getVdecType(int videoType, int profile)
213 { 243 {
214 int streamFormat = H264_MAIN_LEVEL; 244 int streamFormat = H264_MAIN_LEVEL;
@@ -277,6 +307,9 @@ int DvppDecoder::getVdecType(int videoType, int profile) @@ -277,6 +307,9 @@ int DvppDecoder::getVdecType(int videoType, int profile)
277 LOG_ERROR("[{}]-该设备channel已经用完了!", m_dec_name); 307 LOG_ERROR("[{}]-该设备channel已经用完了!", m_dec_name);
278 return false; 308 return false;
279 } 309 }
  310 +
  311 + m_vpcUtils.init(m_dvpp_deviceId);
  312 +
280 m_vdec_out_size = frame_width * frame_height * 3 / 2; 313 m_vdec_out_size = frame_width * frame_height * 3 / 2;
281 314
282 LOG_INFO("[{}]- init vdpp success! device:{} channel:{}", m_dec_name, m_dvpp_deviceId, m_dvpp_channel); 315 LOG_INFO("[{}]- init vdpp success! device:{} channel:{}", m_dec_name, m_dvpp_deviceId, m_dvpp_channel);
@@ -353,6 +386,12 @@ bool DvppDecoder::getResolution(int &amp;width, int &amp;height){ @@ -353,6 +386,12 @@ bool DvppDecoder::getResolution(int &amp;width, int &amp;height){
353 return true; 386 return true;
354 } 387 }
355 388
  389 +bool DvppDecoder::getOutResolution( int &width, int &height ) {
  390 + width = out_frame_width;
  391 + height = out_frame_height;
  392 + return true;
  393 +}
  394 +
356 float DvppDecoder::fps(){ 395 float DvppDecoder::fps(){
357 return m_fps; 396 return m_fps;
358 } 397 }
@@ -532,11 +571,6 @@ void DvppDecoder::read_thread() { @@ -532,11 +571,6 @@ void DvppDecoder::read_thread() {
532 #endif 571 #endif
533 nSended = sendPkt(vdecChannelDesc, pkt, frame_nb); 572 nSended = sendPkt(vdecChannelDesc, pkt, frame_nb);
534 573
535 - if(!m_bReal && frame_nb > 20 && m_avg_decode_time > 0)  
536 - {  
537 - // 针对文件,根据解码时间做延时,避免占用过多显存  
538 - std::this_thread::sleep_for(std::chrono::milliseconds(10));  
539 - }  
540 } 574 }
541 575
542 if(nSended < 0) { 576 if(nSended < 0) {
@@ -767,12 +801,43 @@ void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *o @@ -767,12 +801,43 @@ void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *o
767 // last_ts = get_cur_time_ms(); 801 // last_ts = get_cur_time_ms();
768 802
769 // 换成解码后数据, 这里这样做的是为了保证解码一直持续进行,避免后续操作阻碍文件读取和解码从而导致花屏 803 // 换成解码后数据, 这里这样做的是为了保证解码一直持续进行,避免后续操作阻碍文件读取和解码从而导致花屏
770 - DvppDataMemory* mem = new DvppDataMemory(width, width_stride, height, height_stride, outputSize, m_dec_name, to_string(m_dvpp_deviceId), false, frame_nb, (unsigned char *)outputDataDev); 804 + DvppDataMemory* mem = nullptr;
  805 + if (m_bResize && (width > 1920 || height > 1080)) {
  806 + float srcRatio = width / (float)height;
  807 + float stdRatio = 1920.0 / 1080.0f ;
  808 + int outWidth = 1920;
  809 + int outHeight = 1080;
  810 + if (srcRatio > stdRatio) {
  811 + outHeight = static_cast<int>(outWidth * (float)height / width) ;
  812 + if (outHeight % 2 == 1)
  813 + {
  814 + outHeight += 1;
  815 + }
  816 + } else if (srcRatio < stdRatio) {
  817 + outWidth = static_cast<int>(outHeight * (float)width / height) ;
  818 + if (outWidth % 2 == 1)
  819 + {
  820 + outWidth += 1;
  821 + }
  822 + }
  823 +
  824 + mem = m_vpcUtils.resize(output, outWidth, outHeight);
  825 + if (mem) {
  826 + acldvppFree(outputDataDev);
  827 + outputDataDev = nullptr;
  828 +
  829 + mem->setDeviceId(to_string(m_dvpp_deviceId));
  830 + mem->setId(m_dec_name);
  831 + mem->setFrameNb(frame_nb);
  832 + }
  833 + } else {
  834 + mem = new DvppDataMemory(width, width_stride, height, height_stride, outputSize, m_dec_name, to_string(m_dvpp_deviceId), false, frame_nb, (unsigned char *)outputDataDev);
  835 + }
  836 +
771 if(mem){ 837 if(mem){
772 m_decoded_data_queue.push(mem); 838 m_decoded_data_queue.push(mem);
773 bCached = true; 839 bCached = true;
774 } 840 }
775 -  
776 } 841 }
777 842
778 if(!bCached) { 843 if(!bCached) {
src/decoder/dvpp/DvppDecoder.h
@@ -12,6 +12,8 @@ @@ -12,6 +12,8 @@
12 12
13 #include "FFRecoderTaskManager.h" 13 #include "FFRecoderTaskManager.h"
14 14
  15 +#include "VpcUtils.h"
  16 +
15 using namespace std; 17 using namespace std;
16 18
17 typedef void(*RECEIVER_FINISHED_CALLBACK)(const void* userPtr); 19 typedef void(*RECEIVER_FINISHED_CALLBACK)(const void* userPtr);
@@ -35,6 +37,7 @@ public: @@ -35,6 +37,7 @@ public:
35 bool isFinished(); 37 bool isFinished();
36 bool isPausing(); 38 bool isPausing();
37 bool getResolution( int &width, int &height ); 39 bool getResolution( int &width, int &height );
  40 + bool getOutResolution( int &width, int &height );
38 41
39 bool isSurport(FFDecConfig& cfg); 42 bool isSurport(FFDecConfig& cfg);
40 43
@@ -77,6 +80,8 @@ private: @@ -77,6 +80,8 @@ private:
77 80
78 int getVdecType(int videoType, int profile); 81 int getVdecType(int videoType, int profile);
79 82
  83 + void calcOutResolution(int w, int h);
  84 +
80 private: 85 private:
81 FFDecConfig m_cfg; 86 FFDecConfig m_cfg;
82 string m_dec_name; 87 string m_dec_name;
@@ -100,12 +105,15 @@ private: @@ -100,12 +105,15 @@ private:
100 105
101 int frame_width{0}; 106 int frame_width{0};
102 int frame_height{0}; 107 int frame_height{0};
  108 + int out_frame_width{0};
  109 + int out_frame_height{0};
103 bool m_bReal {false}; // 是否实时流 110 bool m_bReal {false}; // 是否实时流
104 float m_fps{0.0}; 111 float m_fps{0.0};
105 112
106 std::thread* m_read_thread{nullptr}; 113 std::thread* m_read_thread{nullptr};
107 114
108 bool m_dec_keyframe {false}; 115 bool m_dec_keyframe {false};
  116 + bool m_bResize {false};
109 117
110 // 解码 118 // 解码
111 int m_dvpp_deviceId {-1}; 119 int m_dvpp_deviceId {-1};
@@ -129,4 +137,6 @@ private: @@ -129,4 +137,6 @@ private:
129 uint64_t m_out_count {0}; 137 uint64_t m_out_count {0};
130 138
131 std::atomic<int> m_DvppCacheCounter{0}; 139 std::atomic<int> m_DvppCacheCounter{0};
  140 +
  141 + VpcUtils m_vpcUtils;
132 }; 142 };
133 \ No newline at end of file 143 \ No newline at end of file
src/decoder/dvpp/DvppDecoderApi.cpp
@@ -79,6 +79,13 @@ bool DvppDecoderApi::getResolution(int &amp;width, int &amp;height){ @@ -79,6 +79,13 @@ bool DvppDecoderApi::getResolution(int &amp;width, int &amp;height){
79 return false; 79 return false;
80 } 80 }
81 81
  82 +bool DvppDecoderApi::getOutResolution(int &width, int &height){
  83 + if(m_pDecoder != nullptr){
  84 + return m_pDecoder->getOutResolution(width, height);
  85 + }
  86 + return false;
  87 +}
  88 +
82 bool DvppDecoderApi::isSurport(FFDecConfig& cfg){ 89 bool DvppDecoderApi::isSurport(FFDecConfig& cfg){
83 if(m_pDecoder != nullptr){ 90 if(m_pDecoder != nullptr){
84 return m_pDecoder->isSurport(cfg); 91 return m_pDecoder->isSurport(cfg);
src/decoder/dvpp/DvppDecoderApi.h
@@ -24,6 +24,7 @@ public: @@ -24,6 +24,7 @@ public:
24 bool isFinished(); 24 bool isFinished();
25 bool isPausing(); 25 bool isPausing();
26 bool getResolution( int &width, int &height ); 26 bool getResolution( int &width, int &height );
  27 + bool getOutResolution( int &width, int &height );
27 28
28 bool isSurport(FFDecConfig& cfg); 29 bool isSurport(FFDecConfig& cfg);
29 30
src/decoder/dvpp/VpcPicConverter.cpp renamed to src/decoder/dvpp/VpcUtils.cpp
1 -#include "VpcPicConverter.h" 1 +#include "VpcUtils.h"
2 #include "depend_headers.h" 2 #include "depend_headers.h"
3 3
4 #define ALIGN_UP(val, align) (((val) % (align) == 0) ? (val) : (((val) / (align) + 1) * (align))) 4 #define ALIGN_UP(val, align) (((val) % (align) == 0) ? (val) : (((val) / (align) + 1) * (align)))
@@ -12,17 +12,29 @@ @@ -12,17 +12,29 @@
12 #define CHECK_AND_BREAK(ret, message) \ 12 #define CHECK_AND_BREAK(ret, message) \
13 if(ret != 0) {LOG_ERROR("{}", message); break;} 13 if(ret != 0) {LOG_ERROR("{}", message); break;}
14 14
15 -VpcPicConverter::VpcPicConverter(){ 15 +VpcUtils::VpcUtils(){
16 16
17 } 17 }
18 18
19 -VpcPicConverter::~VpcPicConverter(){  
20 - if(nullptr == stream_){ 19 +VpcUtils::~VpcUtils(){
  20 + if(nullptr != stream_){
21 aclrtDestroyStream(stream_); 21 aclrtDestroyStream(stream_);
22 } 22 }
  23 +
  24 + if(context_){
  25 + aclrtDestroyContext(context_);
  26 + }
  27 +
  28 + if (dvppChannelDesc_) {
  29 + (void)acldvppDestroyChannel(dvppChannelDesc_);
  30 + (void)acldvppDestroyChannelDesc(dvppChannelDesc_);
  31 + dvppChannelDesc_ = nullptr;
  32 + }
23 } 33 }
24 34
25 -int VpcPicConverter::init(){ 35 +int VpcUtils::init(int devId){
  36 +
  37 + m_devId = devId;
26 38
27 aclrtSetDevice(m_devId); 39 aclrtSetDevice(m_devId);
28 aclrtCreateContext(&context_, m_devId); 40 aclrtCreateContext(&context_, m_devId);
@@ -45,7 +57,7 @@ int VpcPicConverter::init(){ @@ -45,7 +57,7 @@ int VpcPicConverter::init(){
45 return ret; 57 return ret;
46 } 58 }
47 59
48 -DvppDataMemory* VpcPicConverter::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, int out_height, bool key_frame){ 60 +DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, int out_height, bool key_frame){
49 61
50 aclrtSetDevice(m_devId); 62 aclrtSetDevice(m_devId);
51 aclrtSetCurrentContext(context_); 63 aclrtSetCurrentContext(context_);
@@ -91,7 +103,7 @@ DvppDataMemory* VpcPicConverter::convert2bgr(acldvppPicDesc *inputDesc_, int out @@ -91,7 +103,7 @@ DvppDataMemory* VpcPicConverter::convert2bgr(acldvppPicDesc *inputDesc_, int out
91 return rgbMem; 103 return rgbMem;
92 } 104 }
93 105
94 -DvppDataMemory* VpcPicConverter::convert2bgr(DvppDataMemory* inMem){ 106 +DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){
95 107
96 aclrtSetDevice(m_devId); 108 aclrtSetDevice(m_devId);
97 aclrtSetCurrentContext(context_); 109 aclrtSetCurrentContext(context_);
@@ -149,4 +161,53 @@ DvppDataMemory* VpcPicConverter::convert2bgr(DvppDataMemory* inMem){ @@ -149,4 +161,53 @@ DvppDataMemory* VpcPicConverter::convert2bgr(DvppDataMemory* inMem){
149 } 161 }
150 162
151 return rgbMem; 163 return rgbMem;
  164 +}
  165 +
  166 +DvppDataMemory* VpcUtils::resize(acldvppPicDesc *inputDesc_, int out_width, int out_height){
  167 +
  168 + aclrtSetDevice(m_devId);
  169 + aclrtSetCurrentContext(context_);
  170 +
  171 + int out_buf_width = ALIGN_UP(out_width, 16);
  172 + int out_buf_height = ALIGN_UP(out_height, 2);
  173 + int out_buf_size = out_buf_width * out_buf_height * 3 / 2;
  174 +
  175 + DvppDataMemory* rgbMem = new DvppDataMemory(1, out_width, out_buf_width, out_height, out_buf_height, out_buf_size, "", "", false, 0);
  176 + void *outBufferDev_ = (void*)rgbMem->getMem();
  177 +
  178 + acldvppPicDesc *outputDesc_= acldvppCreatePicDesc();
  179 + acldvppSetPicDescData(outputDesc_, outBufferDev_);
  180 + acldvppSetPicDescFormat(outputDesc_, acldvppGetPicDescFormat(inputDesc_));
  181 + acldvppSetPicDescWidth(outputDesc_, out_width);
  182 + acldvppSetPicDescHeight(outputDesc_, out_height);
  183 + acldvppSetPicDescWidthStride(outputDesc_, out_buf_width);
  184 + acldvppSetPicDescHeightStride(outputDesc_, out_buf_height);
  185 + acldvppSetPicDescSize(outputDesc_, out_buf_size);
  186 +
  187 + acldvppResizeConfig *resizeConfig_ = acldvppCreateResizeConfig();
  188 +
  189 + aclError ret = ACL_ERROR_NONE;
  190 + do{
  191 + // 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
  192 + ret = acldvppVpcResizeAsync(dvppChannelDesc_, inputDesc_, outputDesc_, resizeConfig_, stream_);
  193 + if(ret != ACL_ERROR_NONE){
  194 + LOG_ERROR("acldvppVpcResizeAsync failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size);
  195 + break;
  196 + }
  197 + ret = aclrtSynchronizeStream(stream_);
  198 + if(ret != ACL_ERROR_NONE){
  199 + LOG_ERROR("aclrtSynchronizeStream failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size);
  200 + break;
  201 + }
  202 + }while(0);
  203 +
  204 + acldvppDestroyResizeConfig(resizeConfig_);
  205 + acldvppDestroyPicDesc(outputDesc_);
  206 +
  207 + if(ret != ACL_ERROR_NONE){
  208 + delete rgbMem;
  209 + rgbMem = nullptr;
  210 + }
  211 +
  212 + return rgbMem;
152 } 213 }
153 \ No newline at end of file 214 \ No newline at end of file
src/decoder/dvpp/VpcPicConverter.h renamed to src/decoder/dvpp/VpcUtils.h
@@ -3,15 +3,17 @@ @@ -3,15 +3,17 @@
3 #include "DvppDataMemory.hpp" 3 #include "DvppDataMemory.hpp"
4 4
5 5
6 -class VpcPicConverter{ 6 +class VpcUtils{
7 public: 7 public:
8 - VpcPicConverter();  
9 - ~VpcPicConverter();  
10 - int init(); 8 + VpcUtils();
  9 + ~VpcUtils();
  10 + int init(int);
11 11
12 DvppDataMemory* convert2bgr(acldvppPicDesc *input, int out_width, int out_height, bool key_frame); 12 DvppDataMemory* convert2bgr(acldvppPicDesc *input, int out_width, int out_height, bool key_frame);
13 DvppDataMemory* convert2bgr(DvppDataMemory* inMem); 13 DvppDataMemory* convert2bgr(DvppDataMemory* inMem);
14 14
  15 + DvppDataMemory* resize(acldvppPicDesc *inputDesc_, int out_width, int out_height);
  16 +
15 private: 17 private:
16 aclrtContext context_; 18 aclrtContext context_;
17 aclrtStream stream_; 19 aclrtStream stream_;
src/decoder/dvpp/dvpp_headers.h
@@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
25 #include "acl/acl_rt.h" 25 #include "acl/acl_rt.h"
26 #include "acl/acl.h" 26 #include "acl/acl.h"
27 #include "acl/ops/acl_dvpp.h" 27 #include "acl/ops/acl_dvpp.h"
28 - 28 +#include "acl/dvpp/hi_dvpp.h"
29 29
30 #endif 30 #endif
31 31
src/decoder/interface/AbstractDecoder.h
@@ -18,12 +18,13 @@ public: @@ -18,12 +18,13 @@ public:
18 virtual void pause() = 0; 18 virtual void pause() = 0;
19 virtual void resume() = 0; 19 virtual void resume() = 0;
20 20
21 - virtual void setDecKeyframe(bool bKeyframe) = 0; 21 + virtual void setDecKeyframe(bool ) = 0;
22 22
23 virtual bool isRunning() = 0; 23 virtual bool isRunning() = 0;
24 virtual bool isFinished() = 0; 24 virtual bool isFinished() = 0;
25 virtual bool isPausing() = 0; 25 virtual bool isPausing() = 0;
26 virtual bool getResolution( int &width, int &height ) = 0; 26 virtual bool getResolution( int &width, int &height ) = 0;
  27 + virtual bool getOutResolution( int &width, int &height ) = 0;
27 28
28 virtual bool isSurport(FFDecConfig& cfg) = 0; 29 virtual bool isSurport(FFDecConfig& cfg) = 0;
29 30
src/decoder/interface/DecoderManager.cpp
@@ -429,6 +429,27 @@ bool DecoderManager::getResolution(const string name, int &amp;width, int &amp;height) @@ -429,6 +429,27 @@ bool DecoderManager::getResolution(const string name, int &amp;width, int &amp;height)
429 return false; 429 return false;
430 } 430 }
431 431
  432 +bool DecoderManager::getOutResolution(const string name, int &width, int &height)
  433 +{
  434 + if (name.empty())
  435 + {
  436 + LOG_ERROR("name 为空!");
  437 + return false;
  438 + }
  439 +
  440 + std::lock_guard<std::mutex> l(m_mutex);
  441 +
  442 + auto dec = decoderMap.find(name);
  443 + if (dec != decoderMap.end())
  444 + {
  445 + dec->second->getOutResolution(width, height);
  446 + return true;
  447 + }
  448 +
  449 + LOG_ERROR("没有找到name为{}的解码器",name);
  450 + return false;
  451 +}
  452 +
432 vector<string> DecoderManager::getAllDecodeName(){ 453 vector<string> DecoderManager::getAllDecodeName(){
433 454
434 closeAllFinishedDecoder(); 455 closeAllFinishedDecoder();
src/decoder/interface/DecoderManager.h
@@ -218,6 +218,8 @@ public: @@ -218,6 +218,8 @@ public:
218 **************************************************/ 218 **************************************************/
219 bool getResolution(const string name, int &width, int &height); 219 bool getResolution(const string name, int &width, int &height);
220 220
  221 + bool getOutResolution(const string name, int &width, int &height);
  222 +
221 /************************************************** 223 /**************************************************
222 * 接口:getAllDecodeName 224 * 接口:getAllDecodeName
223 * 功能:获取全部解码器名称 225 * 功能:获取全部解码器名称
src/decoder/interface/DeviceMemory.hpp
@@ -30,6 +30,10 @@ public: @@ -30,6 +30,10 @@ public:
30 int getSize() { 30 int getSize() {
31 return data_size; 31 return data_size;
32 } 32 }
  33 +
  34 + void setSize(int size) {
  35 + data_size = size;
  36 + }
33 37
34 bool isIsused() { 38 bool isIsused() {
35 return isused; 39 return isused;
@@ -45,46 +49,90 @@ public: @@ -45,46 +49,90 @@ public:
45 return id; 49 return id;
46 } 50 }
47 51
  52 + void setId(string _id) {
  53 + id = _id;
  54 + }
  55 +
48 string getDeviceId() { 56 string getDeviceId() {
49 return device_id; 57 return device_id;
50 } 58 }
51 59
  60 + void setDeviceId(string _device_id) {
  61 + device_id = _device_id;
  62 + }
  63 +
52 unsigned char* getMem(){ 64 unsigned char* getMem(){
53 return pHwRgb; 65 return pHwRgb;
54 } 66 }
55 67
  68 + void setMem(unsigned char* _pHwRgb) {
  69 + pHwRgb = _pHwRgb;
  70 + }
  71 +
56 long long getTimesstamp(){ 72 long long getTimesstamp(){
57 return timestamp; 73 return timestamp;
58 } 74 }
59 75
  76 + void setTimesstamp(long long _timestamp) {
  77 + timestamp = _timestamp;
  78 + }
  79 +
60 int getWidth(){ 80 int getWidth(){
61 return width; 81 return width;
62 } 82 }
63 83
  84 + void setWidth(int _width) {
  85 + width = _width;
  86 + }
  87 +
64 int getWidthStride(){ 88 int getWidthStride(){
65 return width_stride; 89 return width_stride;
66 } 90 }
67 91
  92 + void setWidthStride(int _width_stride) {
  93 + width_stride = _width_stride;
  94 + }
  95 +
68 int getHeight(){ 96 int getHeight(){
69 return height; 97 return height;
70 } 98 }
71 99
  100 + void setHeight(int _height) {
  101 + height = _height;
  102 + }
  103 +
72 int getHeightStride(){ 104 int getHeightStride(){
73 return height_stride; 105 return height_stride;
74 } 106 }
75 107
  108 + void setHeightStride(int _height_stride) {
  109 + height_stride = _height_stride;
  110 + }
  111 +
76 int getChannel(){ 112 int getChannel(){
77 return channel; 113 return channel;
78 } 114 }
79 115
  116 + void setChannel(int _channel) {
  117 + channel = _channel;
  118 + }
  119 +
80 bool isKeyFrame(){ 120 bool isKeyFrame(){
81 return key_frame; 121 return key_frame;
82 } 122 }
83 123
  124 + void setKeyFrame(bool _key_frame) {
  125 + key_frame = _key_frame;
  126 + }
  127 +
84 unsigned long long getFrameNb() { 128 unsigned long long getFrameNb() {
85 return frame_nb; 129 return frame_nb;
86 } 130 }
87 131
  132 + void setFrameNb(unsigned long long _frame_nb) {
  133 + frame_nb = _frame_nb;
  134 + }
  135 +
88 public: 136 public:
89 int data_size; 137 int data_size;
90 bool isused; 138 bool isused;
src/decoder/interface/interface_headers.h
@@ -35,6 +35,7 @@ struct FFDecConfig{ @@ -35,6 +35,7 @@ struct FFDecConfig{
35 bool force_tcp{true}; // 是否指定使用tcp连接 35 bool force_tcp{true}; // 是否指定使用tcp连接
36 int skip_frame{1}; // 跳帧数 36 int skip_frame{1}; // 跳帧数
37 string dec_name; 37 string dec_name;
  38 + bool resize{false}; // 是否resize到1920,1080
38 39
39 int port; // gb28181接收数据的端口号 40 int port; // gb28181接收数据的端口号
40 DECODE_REQUEST_STREAM_CALLBACK request_stream_cbk; // gb28181请求流 41 DECODE_REQUEST_STREAM_CALLBACK request_stream_cbk; // gb28181请求流
src/demo/demo.cpp
@@ -998,6 +998,9 @@ string createTask(void *handle, std::vector&lt;algorithm_type_t&gt; algor_vec, int gi, @@ -998,6 +998,9 @@ string createTask(void *handle, std::vector&lt;algorithm_type_t&gt; algor_vec, int gi,
998 // FFmpeg生成的解码错误数据流 998 // FFmpeg生成的解码错误数据流
999 tparam.ipc_url = "rtsp://192.168.10.4:8554/street"; 999 tparam.ipc_url = "rtsp://192.168.10.4:8554/street";
1000 break; 1000 break;
  1001 + case 27:
  1002 + tparam.ipc_url = "/data/share/data/Street_4k_265.mp4";
  1003 + break;
1001 default: 1004 default:
1002 tparam.ipc_url = "/opt/share/data/Street.uvf"; 1005 tparam.ipc_url = "/opt/share/data/Street.uvf";
1003 break; 1006 break;
@@ -1123,26 +1126,31 @@ void test_gpu(int gpuID){ @@ -1123,26 +1126,31 @@ void test_gpu(int gpuID){
1123 algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND}; 1126 algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND};
1124 1127
1125 1128
1126 - int repeat_num = 1000;  
1127 - createTask(handle, algor_vec2, 0, false);  
1128 - createTask(handle, algor_vec2, 2, false);  
1129 - while(repeat_num--) {  
1130 - printf("============================:%d\n",repeat_num);  
1131 - vector<string> task_ids;  
1132 - for (int i = 4; i < 10; i ++) {  
1133 - string task_id = createTask(handle, algor_vec2, i, false);  
1134 - task_ids.push_back(task_id);  
1135 - } 1129 + // int repeat_num = 1000;
  1130 + // createTask(handle, algor_vec2, 0, false);
  1131 + // createTask(handle, algor_vec2, 2, false);
  1132 + // while(repeat_num--) {
  1133 + // printf("============================:%d\n",repeat_num);
  1134 + // vector<string> task_ids;
  1135 + // for (int i = 4; i < 10; i ++) {
  1136 + // string task_id = createTask(handle, algor_vec2, i, false);
  1137 + // task_ids.push_back(task_id);
  1138 + // }
1136 1139
1137 - // test_snapshot(handle);  
1138 - sleep(60); //60s  
1139 - close_all_task(handle);  
1140 - for (auto& task_id : task_ids) {  
1141 - finish_task(handle, (char*)task_id.data(), 0);  
1142 - sleep(5);  
1143 - } 1140 + // // test_snapshot(handle);
  1141 + // sleep(60); //60s
  1142 + // close_all_task(handle);
  1143 + // for (auto& task_id : task_ids) {
  1144 + // finish_task(handle, (char*)task_id.data(), 0);
  1145 + // sleep(5);
  1146 + // }
1144 1147
1145 - } 1148 + // }
  1149 +
  1150 + createTask(handle, algor_vec2, 8, false);
  1151 + createTask(handle, algor_vec2, 27, false);
  1152 +
  1153 + while (getchar() != 'q');
1146 1154
1147 /* 1155 /*
1148 char ch = 'a'; 1156 char ch = 'a';