Commit 42424bf28af2f9637af2b6b58b100a3e315c0175
1 parent
bb35905f
代码优化
Showing
1 changed file
with
61 additions
and
44 deletions
src/dvpp/DvppDec.cpp
@@ -2,11 +2,13 @@ | @@ -2,11 +2,13 @@ | ||
2 | #include "DvppSourceManager.h" | 2 | #include "DvppSourceManager.h" |
3 | 3 | ||
4 | #define CHECK_AND_RETURN(ret, message) \ | 4 | #define CHECK_AND_RETURN(ret, message) \ |
5 | - if(ret != 0) {cout << "device: " << m_dvpp_deviceId << ", chn: " << m_dvpp_channel << ", ret: " << ret << ", [ERROR] " << message; return ret;} | 5 | + if(ret != 0) {LOG_ERROR("[{}]- {}", m_dec_name, message); return ret;} |
6 | #define CHECK_NOT_RETURN(ret, message) \ | 6 | #define CHECK_NOT_RETURN(ret, message) \ |
7 | - if(ret != 0) {cout << "device: " << m_dvpp_deviceId << ", chn: " << m_dvpp_channel << ", ret: " << ret << ", [ERROR] " << message;} | 7 | + if(ret != 0) {LOG_ERROR("[{}]- {}", m_dec_name, message);} |
8 | #define CHECK_AND_RETURN_NOVALUE(ret, message) \ | 8 | #define CHECK_AND_RETURN_NOVALUE(ret, message) \ |
9 | - if(ret != 0) {cout << "device: " << m_dvpp_deviceId << ", chn: " << m_dvpp_channel << ", ret: " << ret << ", [ERROR] " << message; return;} | 9 | + if(ret != 0) {LOG_ERROR("[{}]- {}", m_dec_name, message); return;} |
10 | +#define CHECK_AND_BREAK(ret, message) \ | ||
11 | + if(ret != 0) {LOG_ERROR("[{}]- {}", m_dec_name, message); break;} | ||
10 | 12 | ||
11 | struct Vdec_CallBack_UserData { | 13 | struct Vdec_CallBack_UserData { |
12 | uint64_t frameId; | 14 | uint64_t frameId; |
@@ -259,7 +261,7 @@ void DvppDec::releaseResource(){ | @@ -259,7 +261,7 @@ void DvppDec::releaseResource(){ | ||
259 | 261 | ||
260 | for(int i = 0; i < m_vec_vdec.size(); i++){ | 262 | for(int i = 0; i < m_vec_vdec.size(); i++){ |
261 | if(m_vec_vdec[i] != nullptr){ | 263 | if(m_vec_vdec[i] != nullptr){ |
262 | - acldvppFree((uint8_t*)m_vec_vdec[i]); | 264 | + acldvppFree(m_vec_vdec[i]); |
263 | m_vec_vdec[i] = nullptr; | 265 | m_vec_vdec[i] = nullptr; |
264 | } | 266 | } |
265 | } | 267 | } |
@@ -316,22 +318,22 @@ void DvppDec::decode_thread(){ | @@ -316,22 +318,22 @@ void DvppDec::decode_thread(){ | ||
316 | } | 318 | } |
317 | 319 | ||
318 | // 尽量保证数据全部解码完成 | 320 | // 尽量保证数据全部解码完成 |
319 | - // int sum = 0; | ||
320 | - // if(!bBreak){ | ||
321 | - // while(!m_pktQueueptr->isEmpty()){ | ||
322 | - // int ret = sentFrame(vdecChannelDesc, frame_count); | ||
323 | - // if(ret == 2){ | ||
324 | - // break; | ||
325 | - // } | ||
326 | - // sum++; | ||
327 | - // if(sum > 10){ | ||
328 | - // // 避免卡死 | ||
329 | - // break; | ||
330 | - // } | ||
331 | - // } | ||
332 | - // } | 321 | + int sum = 0; |
322 | + if(!bBreak){ | ||
323 | + while(!m_pktQueueptr->isEmpty()){ | ||
324 | + int ret = sentFrame(vdecChannelDesc, frame_count); | ||
325 | + if(ret == 2){ | ||
326 | + break; | ||
327 | + } | ||
328 | + std::this_thread::sleep_for(std::chrono::milliseconds(3)); | ||
329 | + sum++; | ||
330 | + if(sum > 40){ | ||
331 | + // 避免卡死 | ||
332 | + break; | ||
333 | + } | ||
334 | + } | ||
335 | + } | ||
333 | 336 | ||
334 | - | ||
335 | sendVdecEos(vdecChannelDesc); | 337 | sendVdecEos(vdecChannelDesc); |
336 | 338 | ||
337 | CHECK_NOT_RETURN(aclvdecDestroyChannel(vdecChannelDesc), "aclvdecDestroyChannel failed"); | 339 | CHECK_NOT_RETURN(aclvdecDestroyChannel(vdecChannelDesc), "aclvdecDestroyChannel failed"); |
@@ -378,33 +380,48 @@ int DvppDec::sentFrame(aclvdecChannelDesc *vdecChannelDesc, uint64_t frame_count | @@ -378,33 +380,48 @@ int DvppDec::sentFrame(aclvdecChannelDesc *vdecChannelDesc, uint64_t frame_count | ||
378 | return 2; | 380 | return 2; |
379 | } | 381 | } |
380 | 382 | ||
381 | - /************ 解码*************/ | ||
382 | - acldvppStreamDesc *input_stream_desc = acldvppCreateStreamDesc(); | 383 | + acldvppStreamDesc *input_stream_desc = nullptr; |
384 | + acldvppPicDesc *output_pic_desc = nullptr; | ||
385 | + do{ | ||
386 | + input_stream_desc = acldvppCreateStreamDesc(); | ||
383 | if (input_stream_desc == nullptr) { cout << "acldvppCreateStreamDesc error" << endl; } | 387 | if (input_stream_desc == nullptr) { cout << "acldvppCreateStreamDesc error" << endl; } |
384 | - acldvppPicDesc *output_pic_desc = acldvppCreatePicDesc(); | 388 | + output_pic_desc = acldvppCreatePicDesc(); |
385 | if (output_pic_desc == nullptr) { cout<< "acldvppCreatePicDesc error" << endl; } | 389 | if (output_pic_desc == nullptr) { cout<< "acldvppCreatePicDesc error" << endl; } |
386 | - CHECK_NOT_RETURN(acldvppSetStreamDescData(input_stream_desc, vdecInputbuf), "acldvppSetStreamDescData failed"); | ||
387 | - CHECK_NOT_RETURN(acldvppSetStreamDescSize(input_stream_desc, pkt->size), "acldvppSetStreamDescSize failed"); | ||
388 | - CHECK_NOT_RETURN(acldvppSetPicDescData(output_pic_desc, vdecOutputBuf), "acldvppSetPicDescData failed"); | ||
389 | - CHECK_NOT_RETURN(acldvppSetPicDescSize(output_pic_desc, m_vdec_out_size), "acldvppSetPicDescSize failed"); | ||
390 | - | ||
391 | - Vdec_CallBack_UserData *user_data = NULL; | ||
392 | - user_data = new Vdec_CallBack_UserData; | ||
393 | - user_data->frameId = frame_count; | ||
394 | - // user_data->startTime = startTime; | ||
395 | - user_data->sendTime = UtilTools::get_cur_time_ms(); | ||
396 | - user_data->self = this; | ||
397 | - // user_data->inBufNode = bufNode; | ||
398 | - cout << "send frame" << endl; | ||
399 | - CHECK_NOT_RETURN(aclvdecSendFrame(vdecChannelDesc, input_stream_desc, output_pic_desc, nullptr, reinterpret_cast<void *>(user_data)), | ||
400 | - "aclvdecSendFrame failed"); | ||
401 | - | ||
402 | - m_vdecQueue.addTail(); | ||
403 | - | ||
404 | - m_pktQueueptr->addHead(); | ||
405 | - av_packet_unref(pkt); | ||
406 | - | ||
407 | - return 0; | 390 | + CHECK_AND_BREAK(acldvppSetStreamDescData(input_stream_desc, vdecInputbuf), "acldvppSetStreamDescData failed"); |
391 | + CHECK_AND_BREAK(acldvppSetStreamDescSize(input_stream_desc, pkt->size), "acldvppSetStreamDescSize failed"); | ||
392 | + CHECK_AND_BREAK(acldvppSetPicDescData(output_pic_desc, vdecOutputBuf), "acldvppSetPicDescData failed"); | ||
393 | + CHECK_AND_BREAK(acldvppSetPicDescSize(output_pic_desc, m_vdec_out_size), "acldvppSetPicDescSize failed"); | ||
394 | + | ||
395 | + Vdec_CallBack_UserData *user_data = NULL; | ||
396 | + user_data = new Vdec_CallBack_UserData; | ||
397 | + user_data->frameId = frame_count; | ||
398 | + // user_data->startTime = startTime; | ||
399 | + user_data->sendTime = UtilTools::get_cur_time_ms(); | ||
400 | + user_data->self = this; | ||
401 | + // user_data->inBufNode = bufNode; | ||
402 | + cout << "send frame" << endl; | ||
403 | + CHECK_NOT_RETURN(aclvdecSendFrame(vdecChannelDesc, input_stream_desc, output_pic_desc, nullptr, reinterpret_cast<void *>(user_data)), | ||
404 | + "aclvdecSendFrame failed"); | ||
405 | + | ||
406 | + m_vdecQueue.addTail(); | ||
407 | + | ||
408 | + m_pktQueueptr->addHead(); | ||
409 | + av_packet_unref(pkt); | ||
410 | + | ||
411 | + return 0; | ||
412 | + }while (0); | ||
413 | + | ||
414 | + if(input_stream_desc){ | ||
415 | + CHECK_NOT_RETURN(acldvppDestroyStreamDesc(input_stream_desc), "acldvppDestroyStreamDesc failed"); | ||
416 | + } | ||
417 | + if(output_pic_desc){ | ||
418 | + CHECK_NOT_RETURN(acldvppDestroyPicDesc(output_pic_desc), "acldvppDestroyPicDesc failed"); | ||
419 | + } | ||
420 | + | ||
421 | + acldvppFree(vdecOutputBuf); | ||
422 | + vdecOutputBuf = nullptr; | ||
423 | + | ||
424 | + return 1; | ||
408 | } | 425 | } |
409 | 426 | ||
410 | 427 |