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