Commit 8dc2e2240e26fcbfce63b3482307387c6166ed79
1 parent
08c1b61e
根据解码用时优化数据送给解码器的频率,避免解码器内部占用过多的显存
Showing
3 changed files
with
43 additions
and
14 deletions
src/decoder/dvpp/DvppDecoder.cpp
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 | |
17 | 17 | struct Vdec_CallBack_UserData { |
18 | 18 | uint64_t frameId; |
19 | - unsigned long long frame_nb; | |
19 | + uint64_t frame_nb; | |
20 | 20 | long startTime; |
21 | 21 | long sendTime; |
22 | 22 | DvppDecoder* self; |
... | ... | @@ -49,7 +49,7 @@ static void VdecCallback(acldvppStreamDesc *input, acldvppPicDesc *output, void |
49 | 49 | if(nullptr != userData){ |
50 | 50 | DvppDecoder* self = userData->self; |
51 | 51 | if(self != nullptr){ |
52 | - self->doVdppVdecCallBack(input, output, userData->frame_nb); | |
52 | + self->doVdppVdecCallBack(input, output, userData); | |
53 | 53 | } |
54 | 54 | delete userData; |
55 | 55 | userData = nullptr; |
... | ... | @@ -387,8 +387,8 @@ DeviceMemory* DvppDecoder::snapshot(){ |
387 | 387 | snapshot_mem = new DvppDataMemory(mem); |
388 | 388 | m_decoded_data_queue_mtx.unlock(); |
389 | 389 | |
390 | - snap_count++; | |
391 | - LOG_INFO("[{}]- snap_count:{} ", m_dec_name, snap_count); | |
390 | + // snap_count++; | |
391 | + // LOG_INFO("[{}]- snap_count:{} ", m_dec_name, snap_count); | |
392 | 392 | break; |
393 | 393 | } |
394 | 394 | |
... | ... | @@ -518,6 +518,12 @@ void DvppDecoder::read_thread() { |
518 | 518 | m_recoderManager.cache_pkt(pkt, frame_nb); |
519 | 519 | #endif |
520 | 520 | nSended = sendPkt(vdecChannelDesc, pkt, frame_nb); |
521 | + | |
522 | + if(!m_bReal && frame_nb > 20 && m_avg_decode_time > 0) | |
523 | + { | |
524 | + // 针对文件,根据解码时间做延时,避免占用过多显存 | |
525 | + std::this_thread::sleep_for(std::chrono::milliseconds(10)); | |
526 | + } | |
521 | 527 | } |
522 | 528 | |
523 | 529 | if(nSended < 0) { |
... | ... | @@ -542,8 +548,6 @@ void DvppDecoder::read_thread() { |
542 | 548 | |
543 | 549 | } while (0); |
544 | 550 | |
545 | - LOG_INFO("[{}]- release.", m_dec_name); | |
546 | - | |
547 | 551 | if (vdecChannelDesc) { |
548 | 552 | CHECK_NOT_RETURN(aclvdecDestroyChannel(vdecChannelDesc), "aclvdecDestroyChannel failed"); |
549 | 553 | CHECK_NOT_RETURN(aclvdecDestroyChannelDesc(vdecChannelDesc), "aclvdecDestroyChannelDesc failed"); |
... | ... | @@ -691,10 +695,31 @@ void DvppDecoder::doProcessReport(){ |
691 | 695 | LOG_INFO("doProcessReport exit."); |
692 | 696 | } |
693 | 697 | |
694 | -void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *output, unsigned long long frame_nb){ | |
698 | +void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *output, void *pUserData){ | |
699 | + | |
700 | + if(nullptr == pUserData){ | |
701 | + return; | |
702 | + } | |
703 | + | |
704 | + Vdec_CallBack_UserData *userData = (Vdec_CallBack_UserData *) pUserData; | |
705 | + uint64_t frame_nb = userData->frame_nb; | |
695 | 706 | |
696 | 707 | m_out_count++; |
697 | 708 | |
709 | + if (m_out_count % 20 == 0) | |
710 | + { | |
711 | + m_decode_20_time -= m_avg_decode_time*20; // 减去等待用的时间就是实际解码用时 | |
712 | + m_avg_decode_time = m_decode_20_time / 20; | |
713 | + // LOG_INFO("[{}]- m_avg_decode_time: {}", m_dec_name, m_avg_decode_time); | |
714 | + if (m_avg_decode_time <= 0) { | |
715 | + m_avg_decode_time = 1; | |
716 | + } | |
717 | + m_decode_20_time = 0; | |
718 | + } | |
719 | + m_decode_20_time += UtilTools::get_cur_time_ms() - userData->sendTime; | |
720 | + // LOG_INFO("[{}]- m_decode_20_time: {}", m_dec_name, m_decode_20_time); | |
721 | + | |
722 | + | |
698 | 723 | CHECK_AND_RETURN_NOVALUE(aclrtSetCurrentContext(m_context), "aclrtSetCurrentContext failed"); |
699 | 724 | |
700 | 725 | void *inputDataDev = acldvppGetStreamDescData(input); | ... | ... |
src/decoder/dvpp/DvppDecoder.h
... | ... | @@ -59,7 +59,7 @@ public: |
59 | 59 | void set_mq_callback(mq_callback_t cb); |
60 | 60 | |
61 | 61 | public: |
62 | - void doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *output, unsigned long long frame_nb); | |
62 | + void doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *output, void *pUserData); | |
63 | 63 | void doProcessReport(); |
64 | 64 | |
65 | 65 | private: |
... | ... | @@ -124,6 +124,9 @@ private: |
124 | 124 | |
125 | 125 | long long last_ts {0}; |
126 | 126 | |
127 | - int m_in_count {0}; | |
128 | - int m_out_count {0}; | |
127 | + uint64_t m_in_count {0}; | |
128 | + uint64_t m_out_count {0}; | |
129 | + | |
130 | + int m_avg_decode_time{1}; | |
131 | + int m_decode_20_time{0}; | |
129 | 132 | }; |
130 | 133 | \ No newline at end of file | ... | ... |
src/demo/demo.cpp
... | ... | @@ -63,9 +63,10 @@ void init_mq_conn(void *handle) { |
63 | 63 | #endif // #ifdef POST_USE_RABBITMQ |
64 | 64 | |
65 | 65 | void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_type_t &algor_type) { |
66 | - switch (algor_type) { | |
67 | 66 | auto algor_init_params = new algor_init_config_param_t; |
68 | 67 | |
68 | + switch (algor_type) { | |
69 | + | |
69 | 70 | case algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET: { |
70 | 71 | auto algor_params = new algor_config_param_manned_incident; |
71 | 72 | { |
... | ... | @@ -1135,7 +1136,7 @@ void test_gpu(int gpuID){ |
1135 | 1136 | // createTask(handle, algor_vec, 20, false); |
1136 | 1137 | // createTask(handle, algor_vec, 20, false); |
1137 | 1138 | // createTask(handle, algor_vec, 20, false); |
1138 | - // createTask(handle, algor_vec, 0); | |
1139 | + createTask(handle, algor_vec, 0); | |
1139 | 1140 | // createTask(handle, algor_vec, 1); |
1140 | 1141 | // createTask(handle, algor_vec, 2); |
1141 | 1142 | // createTask(handle, algor_vec, 3); |
... | ... | @@ -1189,9 +1190,9 @@ void test_gpu(int gpuID){ |
1189 | 1190 | switch (ch) |
1190 | 1191 | { |
1191 | 1192 | case 'a': |
1192 | - createTask(handle, algor_vec3, 4, false); | |
1193 | + // createTask(handle, algor_vec3, 4, false); | |
1193 | 1194 | // createTask(handle, algor_vec3, 5, false); |
1194 | - createTask(handle, algor_vec3, 6, false); | |
1195 | + // createTask(handle, algor_vec3, 6, false); | |
1195 | 1196 | // createTask(handle, algor_vec3, 7, false); |
1196 | 1197 | // createTask(handle, algor_vec3, 8, false); |
1197 | 1198 | break; | ... | ... |