Commit 1b57a1c5eb097e9b97a01345ddda5e86862b9266

Authored by Hu Chunming
1 parent aaf743dc

代码优化,避免可能的崩溃

src/ai_engine_module/pedestrian_vehicle_retrograde.cpp
... ... @@ -387,7 +387,9 @@ bool PedestrianVehicleRetrograde::update_mstreams(const std::vector<task_id_t> &
387 387 }
388 388 }
389 389  
390   - LOG_DEBUG("obj_to_alarm_boxes_ size: {}", obj_to_alarm_boxes_.size());
  390 + if(obj_to_alarm_boxes_.size() > 0) {
  391 + LOG_DEBUG("obj_to_alarm_boxes_ size: {}", obj_to_alarm_boxes_.size());
  392 + }
391 393  
392 394 return true;
393 395 }
... ...
src/decoder/dvpp/DvppDecoder.cpp
... ... @@ -151,7 +151,10 @@ AVCodecContext* DvppDecoder::init_FFmpeg(FFDecConfig config){
151 151 m_fps = av_q2d(stream ->avg_frame_rate);
152 152  
153 153 #ifdef USE_VILLAGE
154   - m_recoderManager.init(stream, avctx);
  154 + bool bRet = m_recoderManager.init(stream, avctx);
  155 + if (!bRet){
  156 + LOG_ERROR("[{}]- m_recoderManager 初始化失败!", m_dec_name);
  157 + }
155 158 #endif
156 159  
157 160 LOG_INFO("[{}]- init ffmpeg success! input:{} frame_width:{} frame_height:{} fps:{} ", m_dec_name, input_file, frame_width, frame_height, m_fps);
... ...
src/decoder/dvpp/FFRecoderTaskManager.cpp
... ... @@ -38,6 +38,10 @@ FFRecoderTaskManager::~FFRecoderTaskManager(){
38 38 }
39 39  
40 40 bool FFRecoderTaskManager::init(AVStream* stream, AVCodecContext* avctx){
  41 + if(stream == nullptr || avctx == nullptr) {
  42 + return false;
  43 + }
  44 +
41 45 m_time_base = stream->time_base;
42 46 m_avctx = avctx;
43 47 m_inStream = stream;
... ... @@ -368,7 +372,6 @@ void FFRecoderTaskManager::recode_thread2() {
368 372 }
369 373 m_pkt_list_mtx.unlock();
370 374  
371   - std::string id = recoderinfo.task_id + "_" + recoderinfo.object_id + "_" + std::to_string(recoderinfo.frame_nb);
372 375 string file_name = recoderinfo.recoderPath;
373 376 FFRecoder ffrecoder;
374 377 bool bInit = ffrecoder.init(m_inStream, m_avctx, file_name.c_str());
... ... @@ -389,6 +392,14 @@ void FFRecoderTaskManager::recode_thread2() {
389 392 break;
390 393 }
391 394 AVPacket* pkt = dataPkt->pkt;
  395 + if(pkt == nullptr) {
  396 + LOG_ERROR("{} pkt is nullptr", recoderinfo.task_id);
  397 + continue;
  398 + } else if (pkt->data == nullptr || pkt->size <= 0){
  399 + LOG_ERROR("{} pkt data is nullptr", recoderinfo.task_id);
  400 + continue;
  401 + }
  402 +
392 403 ffrecoder.write_pkt(pkt);
393 404 count++;
394 405 end_frame_nb = (*it_save)->frame_nb;
... ...
src/demo/demo.cpp
... ... @@ -634,7 +634,9 @@ static long long get_cur_time(){
634 634 return tpMicro.time_since_epoch().count();
635 635 }
636 636  
637   -string createTask(void *handle, std::vector<algorithm_type_t> algor_vec, int gi){
  637 +static int nTaskId = 0;
  638 +
  639 +string createTask(void *handle, std::vector<algorithm_type_t> algor_vec, int gi, bool bFlag = true){
638 640 task_param tparam;
639 641  
640 642 switch(gi){
... ... @@ -692,6 +694,13 @@ string createTask(void *handle, std::vector&lt;algorithm_type_t&gt; algor_vec, int gi)
692 694 case 17:
693 695 tparam.ipc_url = "/opt/share/data/diedao.mp4";
694 696 break;
  697 + case 18:
  698 + tparam.ipc_url = "rtsp://122.97.218.170:8604/openUrl/LBBYTra?params=eyJwcm90b2NhbCI6InJ0c3AiLCJjbGllbnRUeXBlIjoib3Blbl9hcGkiLCJleHByaWVUaW1lIjotMSwicHJvdG9jb2wiOiJydHNwIiwiZXhwaXJlVGltZSI6MzAwLCJlbmFibGVNR0MiOnRydWUsImV4cGFuZCI6InN0YW5kYXJkPXJ0c3Amc3RyZWFtZm9ybT1ydHAiLCJhIjoiOTgzYjRjMmUxMThlNGU1OTlkYThmMTI3NTkyMGViODV8MXwwfDEiLCJ0IjoxfQ==";
  699 + break;
  700 + case 19:
  701 + // 公安内网
  702 + tparam.ipc_url = "http://192.168.51.200:8554/320202202308231001001002";
  703 + break;
695 704 default:
696 705 tparam.ipc_url = "/opt/share/data/Street.uvf";
697 706 break;
... ... @@ -700,9 +709,15 @@ string createTask(void *handle, std::vector&lt;algorithm_type_t&gt; algor_vec, int gi)
700 709 tparam.algor_counts = algor_vec.size();
701 710 tparam.dec_type = 2;
702 711  
703   - std::string task_id_str = "test_task_id_" + std::to_string(gi);
  712 + if (bFlag){
  713 + nTaskId = gi;
  714 + }
  715 +
  716 + std::string task_id_str = "test_task_id_" + std::to_string(nTaskId);
704 717 tparam.task_id = task_id_str.c_str();
705 718  
  719 + nTaskId++;
  720 +
706 721 tparam.algor_config_params = new algor_config_param[tparam.algor_counts];
707 722  
708 723 for (size_t idx = 0; idx < algor_vec.size(); ++idx)
... ... @@ -774,21 +789,26 @@ void test_gpu(int gpuID){
774 789  
775 790 // string task_id = createTask(handle, algor_vec, 3 + gpuID * 10);
776 791 // string task_id1 = createTask(handle, algor_vec2, 5);
777   - createTask(handle, algor_vec, 3);
778   - createTask(handle, algor_vec, 4);
779   - createTask(handle, algor_vec, 5);
780   - createTask(handle, algor_vec, 6);
781   - createTask(handle, algor_vec, 7);
782   - createTask(handle, algor_vec, 8);
783   - createTask(handle, algor_vec, 9);
784   - createTask(handle, algor_vec, 10);
785   - createTask(handle, algor_vec, 11);
786   - createTask(handle, algor_vec, 12);
787   - createTask(handle, algor_vec, 13);
788   - createTask(handle, algor_vec, 14);
789   - createTask(handle, algor_vec, 15);
790   - createTask(handle, algor_vec, 16);
791   - createTask(handle, algor_vec, 17);
  792 + createTask(handle, algor_vec, 18, false);
  793 + createTask(handle, algor_vec, 18, false);
  794 + createTask(handle, algor_vec, 18, false);
  795 + createTask(handle, algor_vec, 18, false);
  796 + createTask(handle, algor_vec, 18, false);
  797 + // createTask(handle, algor_vec, 3);
  798 + // createTask(handle, algor_vec, 4);
  799 + // createTask(handle, algor_vec, 5);
  800 + // createTask(handle, algor_vec, 6);
  801 + // createTask(handle, algor_vec, 7);
  802 + // createTask(handle, algor_vec, 8);
  803 + // createTask(handle, algor_vec, 9);
  804 + // createTask(handle, algor_vec, 10);
  805 + // createTask(handle, algor_vec, 11);
  806 + // createTask(handle, algor_vec, 12);
  807 + // createTask(handle, algor_vec, 13);
  808 + // createTask(handle, algor_vec, 14);
  809 + // createTask(handle, algor_vec, 15);
  810 + // createTask(handle, algor_vec, 16);
  811 + // createTask(handle, algor_vec, 17);
792 812 // createTask(handle, algor_vec, 18);
793 813 // createTask(handle, algor_vec, 19);
794 814  
... ... @@ -804,16 +824,16 @@ void test_gpu(int gpuID){
804 824 int main(int argc, char *argv[]) {
805 825 printf("new test\n");
806 826  
807   - if (argc < 4) {
808   - fprintf(stderr, "./xxx 0 2 10 1 ## [start_ai_id, end_ai_id) repeat_num gpu_id\n");
809   - return -1;
810   - }
  827 + // if (argc < 4) {
  828 + // fprintf(stderr, "./xxx 0 2 10 1 ## [start_ai_id, end_ai_id) repeat_num gpu_id\n");
  829 + // return -1;
  830 + // }
811 831  
812   - //! load params.
813   - int start_id = atoi(argv[1]);
814   - int end_id = atoi(argv[2]);
815   - int repeat_num = atoi(argv[3]);
816   - int gpuID = atoi(argv[4]);
  832 + // //! load params.
  833 + // int start_id = atoi(argv[1]);
  834 + // int end_id = atoi(argv[2]);
  835 + // int repeat_num = atoi(argv[3]);
  836 + // int gpuID = atoi(argv[4]);
817 837  
818 838 test_gpu(0);
819 839 // test_gpu(1);
... ...
src/reprocessing_module/snapshot_reprocessing.cpp
... ... @@ -549,11 +549,12 @@ int snapshot_reprocessing::update_face_bestsnapshot(vector&lt;DeviceMemory*&gt; vec_de
549 549 int frame_height = memPtr->getHeight();
550 550 int frame_width = memPtr->getWidth();
551 551  
552   - LOG_DEBUG("{}: {}",task_id,ol_det_result[idx].obj_count);
553 552 if (0 == ol_det_result[idx].obj_count) {
554 553 continue;
555 554 }
556 555  
  556 + LOG_DEBUG("{}: {}",task_id,ol_det_result[idx].obj_count);
  557 +
557 558 int copy_obj_count = 0; //用于记录该路有多少个目标需要进行显存图像的更新
558 559 vector<video_object_info> vec_obj_info;
559 560 for (int c = 0; c < ol_det_result[idx].obj_count; c++) {
... ...
src/util/vpc_util.cpp
... ... @@ -192,10 +192,10 @@ vector&lt;vpc_img_info&gt; VPCUtil::crop_batch(DeviceMemory *devMem, vector&lt;video_obje
192 192 for (uint32_t i = 0; i < outputBatchSize_; i++) {
193 193 video_object_info obj = objs[i];
194 194  
195   - // uint32_t cropSizeWidth = (obj.right - obj.left) / 16 * 16;
196   - // uint32_t cropSizeHeight = (obj.bottom - obj.top) / 2 * 2;
197   - uint32_t cropSizeWidth = (obj.right - obj.left + 15) / 16 * 16; //debug by zsh
198   - uint32_t cropSizeHeight = (obj.bottom - obj.top + 1) / 2 * 2;
  195 + uint32_t cropSizeWidth = (obj.right - obj.left) / 16 * 16;
  196 + uint32_t cropSizeHeight = (obj.bottom - obj.top) / 2 * 2;
  197 + // uint32_t cropSizeWidth = (obj.right - obj.left + 15) / 16 * 16; //debug by zsh
  198 + // uint32_t cropSizeHeight = (obj.bottom - obj.top + 1) / 2 * 2;
199 199  
200 200 uint32_t oddNum = 1;
201 201 uint32_t cropLeftOffset = (obj.left + 1) / 2 * 2; // must even
... ...