Commit c4e50858604d927a3467ae4d0c3b3c63b4a35afb

Authored by Hu Chunming
2 parents aeb77c80 af3f87b8

Merge branch 'dev-cmhu' into 'master'

Dev cmhu

See merge request !5
.gitignore
1 1 bin/test_recoder
2 2 .vscode/launch.json
3 3 bin/logs/*
4   -bin/res/*
5 4 \ No newline at end of file
  5 +bin/res/*
  6 +bin/vpt_proj
  7 +bin/libvpt_ascend.so
... ...
bin/libvpt_ascend.so deleted
No preview for this file type
bin/vpt_proj deleted
No preview for this file type
src/ai_engine_module/motocycle_hs_process.cpp
... ... @@ -81,11 +81,11 @@ namespace ai_engine_module
81 81 }
82 82 }
83 83  
84   - bool MotorHsProcess::init(int gpu_id)
  84 + bool MotorHsProcess::init(int gpu_id, string models_dir)
85 85 {
86 86 init_ = false;
87 87  
88   - string model_path = "./models/hs/hs_motor_310p.om" ;
  88 + string model_path = models_dir + "/models/hs/hs_motor_310p.om" ;
89 89 LOG_INFO("hs_motor 版本:{} 模型路径:{}", hs_motor_getversion(), model_path);
90 90  
91 91 hs_motor_param param;
... ...
src/ai_engine_module/motocycle_hs_process.h
... ... @@ -84,7 +84,7 @@ namespace ai_engine_module
84 84 ~MotorHsProcess();
85 85  
86 86 bool check_initied();
87   - bool init(int gpu_id);
  87 + bool init(int gpu_id, string models_dir);
88 88 bool update_mstreams(const std::vector<task_id_t>& taskIds, vector<DeviceMemory*> vec_det_input_images, const std::vector<onelevel_det_result> &det_results);
89 89 std::shared_ptr<results_data_t> get_result_by_objectid(const id_t& id, bool do_erase = true);
90 90  
... ...
src/ai_engine_module/tricycle_manned_process.cpp
... ... @@ -29,11 +29,11 @@ namespace ai_engine_module
29 29 }
30 30 }
31 31  
32   - bool TricycleMannedProcess::init(int gpu_id)
  32 + bool TricycleMannedProcess::init(int gpu_id, string models_dir)
33 33 {
34 34 init_ = false;
35 35  
36   - string model_path = "./models/hs/hs_tricycle_310p.om" ;
  36 + string model_path = models_dir + "/models/hs/hs_tricycle_310p.om" ;
37 37 LOG_INFO("hs_tri 版本:{} 模型路径:{}", hs_tri_getversion(), model_path);
38 38  
39 39 hs_tri_param param;
... ...
src/ai_engine_module/tricycle_manned_process.h
... ... @@ -75,7 +75,7 @@ namespace ai_engine_module
75 75 ~TricycleMannedProcess();
76 76  
77 77 bool check_initied();
78   - bool init(int gpu_id);
  78 + bool init(int gpu_id, string models_dir);
79 79 bool update_mstreams(const std::vector<task_id_t>& taskIds, vector<DeviceMemory*> vec_det_input_images, const std::vector<onelevel_det_result> &det_results);
80 80 std::shared_ptr<results_data_t> get_result_by_objectid(const id_t& id, bool do_erase = true);
81 81  
... ...
src/ai_engine_module/truck_manned_process.cpp
... ... @@ -29,11 +29,11 @@ namespace ai_engine_module
29 29 }
30 30 }
31 31  
32   - bool TruckMannedProcess::init(int gpu_id)
  32 + bool TruckMannedProcess::init(int gpu_id, string models_dir)
33 33 {
34 34 init_ = false;
35 35  
36   - string model_path = "./models/hs/hs_truck_310p.om" ;
  36 + string model_path = models_dir + "/models/hs/hs_truck_310p.om" ;
37 37 LOG_INFO("hs_truck 版本:{} 模型路径:{}", hs_truck_getversion(), model_path);
38 38  
39 39 hs_truck_param param;
... ...
src/ai_engine_module/truck_manned_process.h
... ... @@ -75,7 +75,7 @@ namespace ai_engine_module
75 75 ~TruckMannedProcess();
76 76  
77 77 bool check_initied();
78   - bool init(int gpu_id);
  78 + bool init(int gpu_id, string models_dir);
79 79 bool update_mstreams(const std::vector<task_id_t>& taskIds, vector<DeviceMemory*> vec_det_input_images, const std::vector<onelevel_det_result> &det_results);
80 80 std::shared_ptr<results_data_t> get_result_by_objectid(const id_t& id, bool do_erase = true);
81 81  
... ...
src/ai_platform/MultiSourceProcess.cpp
... ... @@ -109,19 +109,19 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){
109 109 }
110 110  
111 111 //三轮车头肩检测
112   - if (!tricycle_manned_.init(vptParam.gpuid)) {
  112 + if (!tricycle_manned_.init(vptParam.gpuid, models_dir)) {
113 113 LOG_FATAL("Init tricycle_hs failed");
114 114 return -1;
115 115 }
116 116  
117 117 //货车头肩检测
118   - if (!truck_manned_.init(vptParam.gpuid)) {
  118 + if (!truck_manned_.init(vptParam.gpuid, models_dir)) {
119 119 LOG_FATAL("Init truck_hs failed");
120 120 return -1;
121 121 }
122 122  
123 123 //二轮车头肩检测
124   - if (!motor_hsprocess_.init(vptParam.gpuid)) {
  124 + if (!motor_hsprocess_.init(vptParam.gpuid, models_dir)) {
125 125 LOG_FATAL("Init motor_hs failed");
126 126 return -1;
127 127 }
... ... @@ -1303,7 +1303,7 @@ void CMultiSourceProcess::manned_snapshot(vector&lt;string&gt;&amp; vpt_interest_task_id,
1303 1303 RecoderInfo recoderInfo;
1304 1304 recoderInfo.task_id = task_id;
1305 1305 recoderInfo.object_id = std::to_string(j);
1306   - recoderInfo.recoderDir = "./res/recode";
  1306 + recoderInfo.recoderPath = "./res/recode";
1307 1307 recoderInfo.frame_nb = mem->getFrameNb();
1308 1308  
1309 1309 m_recoderinfo_queue_mtx.lock();
... ...
src/ai_platform/common_header.h
... ... @@ -32,7 +32,7 @@ struct box_t {
32 32 };
33 33  
34 34 struct RecoderInfo {
35   - std::string recoderDir;
  35 + std::string recoderPath;
36 36 std::string task_id;
37 37 std::string object_id;
38 38 unsigned long long frame_nb;
... ...
src/decoder/dvpp/FFRecoder.cpp
... ... @@ -39,13 +39,13 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx,
39 39 // [1] 创建解码器
40 40 const AVCodec* encoder = avcodec_find_encoder(AV_CODEC_ID_HEVC);
41 41 if (!encoder) {
42   - fprintf(stderr, "Find encoder AV_CODEC_ID_H264 failed!\n");
  42 + LOG_ERROR("Find encoder AV_CODEC_ID_H264 failed!");
43 43 return false;
44 44 }
45 45 // 获取解码器上下文
46 46 codec_ctx_ = avcodec_alloc_context3(encoder);
47 47 if (!codec_ctx_) {
48   - fprintf(stderr, "Alloc context for encoder contx failed!\n");
  48 + LOG_ERROR("Alloc context for encoder contx failed!");
49 49 return false;
50 50 }
51 51 // 设置解码器上下文参数
... ... @@ -68,7 +68,7 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx,
68 68 // 打开解码器
69 69 int ret = avcodec_open2(codec_ctx_, encoder, nullptr);
70 70 if (ret < 0) {
71   - fprintf(stderr, "Open encoder failed!\n");
  71 + LOG_ERROR("Open encoder failed!");
72 72 return false;
73 73 }
74 74  
... ... @@ -93,17 +93,17 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx,
93 93 if (av_frame_get_buffer(yuv_frame_, 0) < 0) {
94 94 av_frame_free(&yuv_frame_);
95 95 yuv_frame_ = nullptr;
96   - fprintf(stderr, "Frame get buffer failed!\n");
  96 + LOG_ERROR("Frame get buffer failed!");
97 97 return false;
98 98 }
99 99  
100 100 // [5] 打开输出视频文件并写入视频头信息
101 101 if (avio_open(&fmt_ctx_->pb, outfile_name, AVIO_FLAG_WRITE) < 0) {
102   - fprintf(stderr, "avio_open failed!\n");
  102 + LOG_ERROR("avio_open failed!");
103 103 return false;
104 104 }
105 105 if (avformat_write_header(fmt_ctx_, nullptr) < 0) {
106   - fprintf(stderr, "Write header failed!\n");
  106 + LOG_ERROR("Write header failed!");
107 107 return false;
108 108 }
109 109  
... ... @@ -150,11 +150,11 @@ bool FFRecoder::init(AVStream* stream, AVCodecContext* avctx, const char* outfil
150 150  
151 151 // [5] 打开输出视频文件并写入视频头信息
152 152 if (avio_open(&fmt_ctx_->pb, outfile_name, AVIO_FLAG_WRITE) < 0) {
153   - fprintf(stderr, "avio_open failed!\n");
  153 + LOG_ERROR("avio_open failed!");
154 154 return false;
155 155 }
156 156 if (avformat_write_header(fmt_ctx_, nullptr) < 0) {
157   - fprintf(stderr, "Write header failed!\n");
  157 + LOG_ERROR("Write header failed!");
158 158 return false;
159 159 }
160 160  
... ... @@ -270,7 +270,7 @@ bool FFRecoder::write_pkt(AVPacket *pkt) {
270 270 // pkt->stream_index = out_stream_->index;
271 271  
272 272 if(pkt->pts==AV_NOPTS_VALUE) {
273   - // printf("frame_index:%d\n", frame_index);
  273 + // printf("frame_index:%d", frame_index);
274 274 //Write PTS
275 275 AVRational time_base1 = codec_ctx_->time_base;
276 276 //Duration between 2 frames (us)
... ... @@ -293,7 +293,7 @@ bool FFRecoder::write_pkt(AVPacket *pkt) {
293 293 // 将数据写入到输出流
294 294 int ret = av_write_frame(fmt_ctx_, pkt);
295 295 if (ret < 0) {
296   - fprintf(stderr, "Error while writing output packet: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret));
  296 + LOG_ERROR("Error while writing output packet: {}", av_make_error_string(errbuf, sizeof(errbuf), ret));
297 297 return false;
298 298 }
299 299 return true;
... ... @@ -316,7 +316,7 @@ bool FFRecoder::write_frame(AVFrame* frame)
316 316 int ret = avcodec_send_frame(codec_ctx_, pFrameOut);
317 317 av_frame_free(&pFrameOut);
318 318 if (ret < 0) {
319   - fprintf(stderr, "Error sending a frame to the encoder: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret));
  319 + LOG_ERROR("Error sending a frame to the encoder: {}", av_make_error_string(errbuf, sizeof(errbuf), ret));
320 320 return false;
321 321 }
322 322  
... ... @@ -327,7 +327,7 @@ bool FFRecoder::write_frame(AVFrame* frame)
327 327 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
328 328 return true;
329 329 else if (ret < 0) {
330   - fprintf(stderr, "Error encoding a frame: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret));
  330 + LOG_ERROR("Error encoding a frame: {}", av_make_error_string(errbuf, sizeof(errbuf), ret));
331 331 return false;
332 332 }
333 333 // 将pts缩放到输出流的time_base上
... ... @@ -339,7 +339,7 @@ bool FFRecoder::write_frame(AVFrame* frame)
339 339 //ret = av_write_frame(fmt_ctx_, &pkt);
340 340 av_packet_unref(&pkt);
341 341 if (ret < 0) {
342   - fprintf(stderr, "Error while writing output packet: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret));
  342 + LOG_ERROR("Error while writing output packet: {}", av_make_error_string(errbuf, sizeof(errbuf), ret));
343 343 return false;
344 344 }
345 345 /* av_interleaved_write_frame(fmt_ctx_, nullptr);
... ...
src/decoder/dvpp/FFRecoder.h
1 1 #pragma once
2 2 #include <memory>
3 3  
4   -extern "C" {
5   - #include <libavcodec/avcodec.h>
6   - #include <libavformat/avformat.h>
7   - #include <libavutil/opt.h>
8   - #include <libavutil/timestamp.h>
9   - #include <libavutil/imgutils.h>
10   - #include <libswscale/swscale.h>
11   -}
  4 +#include "depend_headers.h"
12 5  
13 6 class FFRecoder
14 7 {
... ...
src/decoder/dvpp/FFRecoderTaskManager.cpp
... ... @@ -198,14 +198,6 @@ list&lt;DataPacket*&gt;::iterator FFRecoderTaskManager::getStartIterator(unsigned long
198 198 return it_first;
199 199 }
200 200  
201   - // auto it_second = m_pkt_list.begin();
202   - // for(;it_second != m_pkt_list.end(); it_second++) {
203   - // DataPacket* dataPkt = *it_second;
204   - // if (dataPkt->frame_nb >= start_frame_nb){
205   - // return it_second;
206   - // }
207   - // }
208   -
209 201 auto it_second = m_pkt_list.begin();
210 202 for(;it_second != m_pkt_list.end(); it_second++) {
211 203 DataPacket* dataPkt = *it_second;
... ... @@ -308,7 +300,7 @@ void FFRecoderTaskManager::recode_thread(RecodeParam recodeParam){
308 300 RecoderInfo recoderInfo;
309 301 recoderInfo = recodeParam.recoderInfo;
310 302 std::string id = recoderInfo.task_id + "_" + recoderInfo.object_id + "_" + std::to_string(recoderInfo.frame_nb);
311   - string file_name = recoderInfo.recoderDir + "/recoder_" + id + "_" + std::to_string(get_cur_time()) + ".mp4";
  303 + string file_name = recoderInfo.recoderPath;
312 304 FFRecoder ffrecoder;
313 305 bool bInit = ffrecoder.init(m_inStream, recodeParam.avctx, file_name.c_str());
314 306 if (!bInit) {
... ... @@ -359,8 +351,6 @@ void FFRecoderTaskManager::recode_thread2() {
359 351 continue;
360 352 }
361 353  
362   - auto it_end = getEndIterator(recoderinfo.frame_nb);
363   -
364 354 LOG_INFO("start frame_nb: {}", (*it_data)->frame_nb);
365 355  
366 356 m_pkt_list_mtx.lock();
... ... @@ -379,7 +369,7 @@ void FFRecoderTaskManager::recode_thread2() {
379 369 m_pkt_list_mtx.unlock();
380 370  
381 371 std::string id = recoderinfo.task_id + "_" + recoderinfo.object_id + "_" + std::to_string(recoderinfo.frame_nb);
382   - string file_name = recoderinfo.recoderDir + "/recoder_" + id + "_" + std::to_string(get_cur_time()) + ".mp4";
  372 + string file_name = recoderinfo.recoderPath;
383 373 FFRecoder ffrecoder;
384 374 bool bInit = ffrecoder.init(m_inStream, m_avctx, file_name.c_str());
385 375 if (!bInit) {
... ... @@ -387,7 +377,7 @@ void FFRecoderTaskManager::recode_thread2() {
387 377 ffrecoder.uninit();
388 378 continue;
389 379 }
390   - LOG_INFO("record start, pkt_list size: {} id: {}", m_pkt_list.size(), id);
  380 + LOG_DEBUG("record start, pkt_list size: {} task_id: {} object_id:{} frame_nb: {}", m_pkt_list.size(), recoderinfo.task_id, recoderinfo.object_id, recoderinfo.frame_nb);
391 381  
392 382 int count = 0;
393 383 auto it_save = it_data;
... ... @@ -420,7 +410,7 @@ void FFRecoderTaskManager::recode_thread2() {
420 410 }
421 411  
422 412 void FFRecoderTaskManager::recode_thread3() {
423   - LOG_INFO("recode_thread2 start...");
  413 + LOG_INFO("recode_thread3 start...");
424 414 while(true) {
425 415 if(m_bExit) {
426 416 break;
... ... @@ -458,7 +448,7 @@ void FFRecoderTaskManager::recode_thread3() {
458 448 m_frame_list_mtx.unlock();
459 449  
460 450 std::string id = recoderinfo.task_id + "_" + recoderinfo.object_id + "_" + std::to_string(recoderinfo.frame_nb);
461   - string file_name = recoderinfo.recoderDir + "/recoder_" + id + "_" + std::to_string(get_cur_time()) + ".mp4";
  451 + string file_name = recoderinfo.recoderPath;
462 452 FFRecoder ffrecoder;
463 453 bool bInit = ffrecoder.init(m_avctx->width, m_avctx->height, m_time_base, m_avctx, file_name.c_str());
464 454 if (!bInit) {
... ... @@ -491,11 +481,11 @@ void FFRecoderTaskManager::recode_thread3() {
491 481 LOG_INFO("record end, total save: {} start_frame_nb: {} end_frame_nb: {} file_path: {}", count, start_frame_nb, end_frame_nb, file_name);
492 482 }
493 483  
494   - LOG_INFO("recode_thread2 end.");
  484 + LOG_INFO("recode_thread3 end.");
495 485 }
496 486  
497 487 void FFRecoderTaskManager::recode_thread4() {
498   - LOG_INFO("recode_thread2 start...");
  488 + LOG_INFO("recode_thread4 start...");
499 489 while(true) {
500 490 if(m_bExit) {
501 491 break;
... ... @@ -533,7 +523,7 @@ void FFRecoderTaskManager::recode_thread4() {
533 523 m_pkt_list_mtx.unlock();
534 524  
535 525 std::string id = recoderinfo.task_id + "_" + recoderinfo.object_id + "_" + std::to_string(recoderinfo.frame_nb);
536   - string file_name = recoderinfo.recoderDir + "/recoder_" + id + "_" + std::to_string(get_cur_time()) + ".mp4";
  526 + string file_name = recoderinfo.recoderPath;
537 527 FFRecoder ffrecoder;
538 528 bool bInit = ffrecoder.init(m_inStream, m_avctx, file_name.c_str());
539 529 if (!bInit) {
... ... @@ -566,7 +556,7 @@ void FFRecoderTaskManager::recode_thread4() {
566 556 LOG_INFO("record end, total save: {} start_frame_nb: {} end_frame_nb: {} file_path: {}", count, start_frame_nb, end_frame_nb, file_name);
567 557 }
568 558  
569   - LOG_INFO("recode_thread2 end.");
  559 + LOG_INFO("recode_thread4 end.");
570 560 }
571 561  
572 562 void FFRecoderTaskManager::close() {
... ...
src/decoder/dvpp/depend_headers.h
... ... @@ -27,6 +27,9 @@ extern &quot;C&quot; {
27 27 #include "libavutil/samplefmt.h"
28 28 #include "libavformat/avformat.h"
29 29 #include "libavcodec/avcodec.h"
  30 + #include <libavutil/opt.h>
  31 + #include <libavutil/timestamp.h>
  32 + #include <libswscale/swscale.h>
30 33 }
31 34  
32 35  
... ...
src/decoder/test_recoder.cpp
... ... @@ -179,7 +179,7 @@ void algorthim_face_detect(vector&lt;DeviceMemory*&gt; vec_gpuMem) {
179 179 RecoderInfo recoderInfo;
180 180 recoderInfo.task_id = task_id;
181 181 recoderInfo.object_id = std::to_string(obj_id);
182   - recoderInfo.recoderDir = "./res/recode";
  182 + recoderInfo.recoderPath = "./res/recode";
183 183 recoderInfo.frame_nb = mem->getFrameNb();
184 184  
185 185 m_recoderinfo_queue_mtx.lock();
... ... @@ -211,7 +211,7 @@ void test_recode_thread() {
211 211 RecoderInfo recoderInfo;
212 212 recoderInfo.task_id = gpuMem->getId();
213 213 recoderInfo.object_id = std::to_string(obj_id);
214   - recoderInfo.recoderDir = "./res/recode";
  214 + recoderInfo.recoderPath = "./res/recode";
215 215 recoderInfo.frame_nb = gpuMem->getFrameNb();
216 216  
217 217 DecoderManager* pDecManager = DecoderManager::getInstance();
... ...