diff --git a/src/decoder/dvpp/DvppDecoder.cpp b/src/decoder/dvpp/DvppDecoder.cpp index dc3577a..e7b26d2 100755 --- a/src/decoder/dvpp/DvppDecoder.cpp +++ b/src/decoder/dvpp/DvppDecoder.cpp @@ -16,7 +16,7 @@ struct Vdec_CallBack_UserData { uint64_t frameId; - unsigned long long frame_nb; + uint64_t frame_nb; long startTime; long sendTime; DvppDecoder* self; @@ -49,7 +49,7 @@ static void VdecCallback(acldvppStreamDesc *input, acldvppPicDesc *output, void if(nullptr != userData){ DvppDecoder* self = userData->self; if(self != nullptr){ - self->doVdppVdecCallBack(input, output, userData->frame_nb); + self->doVdppVdecCallBack(input, output, userData); } delete userData; userData = nullptr; @@ -387,8 +387,8 @@ DeviceMemory* DvppDecoder::snapshot(){ snapshot_mem = new DvppDataMemory(mem); m_decoded_data_queue_mtx.unlock(); - snap_count++; - LOG_INFO("[{}]- snap_count:{} ", m_dec_name, snap_count); + // snap_count++; + // LOG_INFO("[{}]- snap_count:{} ", m_dec_name, snap_count); break; } @@ -518,6 +518,12 @@ void DvppDecoder::read_thread() { m_recoderManager.cache_pkt(pkt, frame_nb); #endif nSended = sendPkt(vdecChannelDesc, pkt, frame_nb); + + if(!m_bReal && frame_nb > 20 && m_avg_decode_time > 0) + { + // 针对文件,根据解码时间做延时,避免占用过多显存 + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } } if(nSended < 0) { @@ -542,8 +548,6 @@ void DvppDecoder::read_thread() { } while (0); - LOG_INFO("[{}]- release.", m_dec_name); - if (vdecChannelDesc) { CHECK_NOT_RETURN(aclvdecDestroyChannel(vdecChannelDesc), "aclvdecDestroyChannel failed"); CHECK_NOT_RETURN(aclvdecDestroyChannelDesc(vdecChannelDesc), "aclvdecDestroyChannelDesc failed"); @@ -691,10 +695,31 @@ void DvppDecoder::doProcessReport(){ LOG_INFO("doProcessReport exit."); } -void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *output, unsigned long long frame_nb){ +void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *output, void *pUserData){ + + if(nullptr == pUserData){ + return; + } + + Vdec_CallBack_UserData *userData = (Vdec_CallBack_UserData *) pUserData; + uint64_t frame_nb = userData->frame_nb; m_out_count++; + if (m_out_count % 20 == 0) + { + m_decode_20_time -= m_avg_decode_time*20; // 减去等待用的时间就是实际解码用时 + m_avg_decode_time = m_decode_20_time / 20; + // LOG_INFO("[{}]- m_avg_decode_time: {}", m_dec_name, m_avg_decode_time); + if (m_avg_decode_time <= 0) { + m_avg_decode_time = 1; + } + m_decode_20_time = 0; + } + m_decode_20_time += UtilTools::get_cur_time_ms() - userData->sendTime; + // LOG_INFO("[{}]- m_decode_20_time: {}", m_dec_name, m_decode_20_time); + + CHECK_AND_RETURN_NOVALUE(aclrtSetCurrentContext(m_context), "aclrtSetCurrentContext failed"); void *inputDataDev = acldvppGetStreamDescData(input); diff --git a/src/decoder/dvpp/DvppDecoder.h b/src/decoder/dvpp/DvppDecoder.h index a4b7faf..c4fb312 100755 --- a/src/decoder/dvpp/DvppDecoder.h +++ b/src/decoder/dvpp/DvppDecoder.h @@ -59,7 +59,7 @@ public: void set_mq_callback(mq_callback_t cb); public: - void doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *output, unsigned long long frame_nb); + void doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *output, void *pUserData); void doProcessReport(); private: @@ -124,6 +124,9 @@ private: long long last_ts {0}; - int m_in_count {0}; - int m_out_count {0}; + uint64_t m_in_count {0}; + uint64_t m_out_count {0}; + + int m_avg_decode_time{1}; + int m_decode_20_time{0}; }; \ No newline at end of file diff --git a/src/demo/demo.cpp b/src/demo/demo.cpp index db2390a..99d8a8e 100755 --- a/src/demo/demo.cpp +++ b/src/demo/demo.cpp @@ -63,9 +63,10 @@ void init_mq_conn(void *handle) { #endif // #ifdef POST_USE_RABBITMQ void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_type_t &algor_type) { - switch (algor_type) { auto algor_init_params = new algor_init_config_param_t; + switch (algor_type) { + case algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET: { auto algor_params = new algor_config_param_manned_incident; { @@ -1135,7 +1136,7 @@ void test_gpu(int gpuID){ // createTask(handle, algor_vec, 20, false); // createTask(handle, algor_vec, 20, false); // createTask(handle, algor_vec, 20, false); - // createTask(handle, algor_vec, 0); + createTask(handle, algor_vec, 0); // createTask(handle, algor_vec, 1); // createTask(handle, algor_vec, 2); // createTask(handle, algor_vec, 3); @@ -1189,9 +1190,9 @@ void test_gpu(int gpuID){ switch (ch) { case 'a': - createTask(handle, algor_vec3, 4, false); + // createTask(handle, algor_vec3, 4, false); // createTask(handle, algor_vec3, 5, false); - createTask(handle, algor_vec3, 6, false); + // createTask(handle, algor_vec3, 6, false); // createTask(handle, algor_vec3, 7, false); // createTask(handle, algor_vec3, 8, false); break;