Commit 8a3c293203b42fb7241207206dcb30a7c734ed43

Authored by Hu Chunming
1 parent fdaddb92

修复任务创建失败造成的内存泄漏问题

bin/gb28181_cfg.xml
1 1 <?xml version="1.0" encoding="GB2312"?>
2 2 <ROOT>
3 3 <WsIP>192.168.60.179</WsIP>
4   - <WsPort>9006</WsPort>
  4 + <WsPort>9007</WsPort>
5 5 <MinRtpPort>20000</MinRtpPort>
6 6 <MaxRtpPort>20400</MaxRtpPort>
7 7 </ROOT>
... ...
src/ai_engine_module/VPTProcess.cpp
... ... @@ -46,7 +46,7 @@ int VPTProcess::init(VPTProcess_PARAM vparam){
46 46  
47 47 int ret = vpt_init(&m_det_handle, param);
48 48 if(ret != 0){
49   - LOG_DEBUG("vpt init error.");
  49 + LOG_ERROR("vpt init error.");
50 50 return -1;
51 51 }
52 52  
... ...
src/decoder/dvpp/DvppDecoder.cpp
... ... @@ -102,23 +102,30 @@ bool DvppDecoder::init(FFDecConfig cfg){
102 102 m_dec_name = cfg.dec_name;
103 103 m_frameSkip = cfg.skip_frame;
104 104  
  105 + m_cfg = cfg;
  106 +
  107 + decode_finished_cbk = cfg.decode_finished_cbk;
  108 +
105 109 AVCodecContext* avctx = init_FFmpeg(cfg);
106 110 if(avctx == nullptr){
107 111 return false;
108 112 }
109 113  
110   - bool bRet = init_dvpp(cfg);
111   - if(!bRet){
112   - return false;
113   - }
114   -
115   - m_cfg = cfg;
  114 + do
  115 + {
  116 + bool bRet = init_dvpp(cfg);
  117 + if(!bRet){
  118 + break;
  119 + }
116 120  
117   - decode_finished_cbk = cfg.decode_finished_cbk;
  121 + m_bFinished = false;
118 122  
119   - m_bFinished = false;
  123 + return true;
  124 + } while (0);
  125 +
  126 + release_ffmpeg();
120 127  
121   - return true;
  128 + return false;
122 129 }
123 130  
124 131 AVCodecContext* DvppDecoder::init_FFmpeg(FFDecConfig config){
... ... @@ -328,13 +335,13 @@ int DvppDecoder::getVdecType(int videoType, int profile)
328 335 aclError ret = aclrtSetDevice(m_dvpp_deviceId);
329 336 if(ret != ACL_ERROR_NONE){
330 337 LOG_ERROR("[{}]-aclrtSetDevice failed !", m_dec_name);
331   - return false;
  338 + break;
332 339 }
333 340  
334 341 ret = aclrtCreateContext(&m_context, m_dvpp_deviceId);
335 342 if (ret != ACL_ERROR_NONE) {
336 343 LOG_ERROR("[{}]-aclrtCreateContext failed !", m_dec_name);
337   - return false;
  344 + break;
338 345 }
339 346  
340 347 // DvppSourceManager 创建时包含 aclInit,析构时包含 aclFinalize
... ... @@ -342,7 +349,7 @@ int DvppDecoder::getVdecType(int videoType, int profile)
342 349 m_dvpp_channel = pSrcMgr->getChannel(m_dvpp_deviceId);
343 350 if(m_dvpp_channel < 0){
344 351 LOG_ERROR("[{}]-该设备channel已经用完了!", m_dec_name);
345   - return false;
  352 + break;
346 353 }
347 354  
348 355 m_vpcUtils.init(m_dvpp_deviceId);
... ...
src/decoder/dvpp/DvppStreamDecoder.cpp
... ... @@ -55,7 +55,7 @@ DvppStreamDecoder::~DvppStreamDecoder()
55 55 {
56 56 Close();
57 57  
58   - LOG_DEBUG("[{}]- ~DvppDecoder() in_count:{} out_count:{}", m_dec_name, m_in_count, m_out_count);
  58 + LOG_DEBUG("[{}]- ~DvppStreamDecoder() in_count:{} out_count:{}", m_dec_name, m_in_count, m_out_count);
59 59 }
60 60  
61 61 bool DvppStreamDecoder::Init(FFDecConfig cfg) {
... ...
src/decoder/dvpp/VpcUtils.cpp
... ... @@ -17,10 +17,6 @@ VpcUtils::VpcUtils(){
17 17 }
18 18  
19 19 VpcUtils::~VpcUtils(){
20   - if(nullptr != stream_){
21   - aclrtDestroyStream(stream_);
22   - }
23   -
24 20 if(context_){
25 21 aclrtDestroyContext(context_);
26 22 }
... ... @@ -40,7 +36,6 @@ int VpcUtils::init(int devId){
40 36 aclrtCreateContext(&context_, m_devId);
41 37  
42 38 CHECK_AND_RETURN(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed");
43   - CHECK_AND_RETURN(aclrtCreateStream(&stream_), "aclrtCreateStream failed! ");
44 39  
45 40 dvppChannelDesc_ = acldvppCreateChannelDesc();
46 41  
... ... @@ -79,6 +74,10 @@ DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width,
79 74 acldvppSetPicDescSize(outputDesc_, out_buf_size);
80 75  
81 76 aclError ret = ACL_ERROR_NONE;
  77 +
  78 + aclrtStream stream_ = nullptr;
  79 + aclrtCreateStream(&stream_);
  80 +
82 81 do{
83 82 // 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
84 83 ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_);
... ... @@ -93,6 +92,10 @@ DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width,
93 92 }
94 93 }while(0);
95 94  
  95 + if (stream_ != nullptr) {
  96 + aclrtDestroyStream(stream_);
  97 + }
  98 +
96 99 acldvppDestroyPicDesc(outputDesc_);
97 100  
98 101 if(ret != ACL_ERROR_NONE){
... ... @@ -138,6 +141,9 @@ DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){
138 141 acldvppSetPicDescSize(outputDesc_, out_buf_size);
139 142  
140 143 aclError ret = ACL_ERROR_NONE;
  144 +
  145 + aclrtStream stream_ = nullptr;
  146 + aclrtCreateStream(&stream_);
141 147 do{
142 148 // 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
143 149 ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_);
... ... @@ -152,6 +158,10 @@ DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){
152 158 }
153 159 }while(0);
154 160  
  161 + if (stream_ != nullptr) {
  162 + aclrtDestroyStream(stream_);
  163 + }
  164 +
155 165 acldvppDestroyPicDesc(outputDesc_);
156 166 acldvppDestroyPicDesc(inputDesc_);
157 167  
... ... @@ -187,6 +197,8 @@ DvppDataMemory* VpcUtils::resize(acldvppPicDesc *inputDesc_, int out_width, int
187 197 acldvppResizeConfig *resizeConfig_ = acldvppCreateResizeConfig();
188 198  
189 199 aclError ret = ACL_ERROR_NONE;
  200 + aclrtStream stream_ = nullptr;
  201 + aclrtCreateStream(&stream_);
190 202 do{
191 203 // 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
192 204 ret = acldvppVpcResizeAsync(dvppChannelDesc_, inputDesc_, outputDesc_, resizeConfig_, stream_);
... ... @@ -201,6 +213,10 @@ DvppDataMemory* VpcUtils::resize(acldvppPicDesc *inputDesc_, int out_width, int
201 213 }
202 214 }while(0);
203 215  
  216 + if (stream_ != nullptr) {
  217 + aclrtDestroyStream(stream_);
  218 + }
  219 +
204 220 acldvppDestroyResizeConfig(resizeConfig_);
205 221 acldvppDestroyPicDesc(outputDesc_);
206 222  
... ...
src/decoder/dvpp/VpcUtils.h
... ... @@ -16,7 +16,6 @@ public:
16 16  
17 17 private:
18 18 aclrtContext context_{nullptr};
19   - aclrtStream stream_{nullptr};
20 19 int m_devId;
21 20 acldvppChannelDesc *dvppChannelDesc_ {nullptr};
22 21 string m_dec_name;
... ...