diff --git a/.gitignore b/.gitignore index 7cc22e6..e994d4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ bin/test_recoder .vscode/launch.json bin/logs/* -bin/res/* \ No newline at end of file +bin/res/* +bin/vpt_proj +bin/libvpt_ascend.so diff --git a/bin/libvpt_ascend.so b/bin/libvpt_ascend.so deleted file mode 100755 index c1318ed..0000000 --- a/bin/libvpt_ascend.so +++ /dev/null diff --git a/bin/vpt_proj b/bin/vpt_proj deleted file mode 100755 index e4022fb..0000000 --- a/bin/vpt_proj +++ /dev/null diff --git a/src/ai_engine_module/motocycle_hs_process.cpp b/src/ai_engine_module/motocycle_hs_process.cpp index ed16cb5..ef486fc 100644 --- a/src/ai_engine_module/motocycle_hs_process.cpp +++ b/src/ai_engine_module/motocycle_hs_process.cpp @@ -81,11 +81,11 @@ namespace ai_engine_module } } - bool MotorHsProcess::init(int gpu_id) + bool MotorHsProcess::init(int gpu_id, string models_dir) { init_ = false; - string model_path = "./models/hs/hs_motor_310p.om" ; + string model_path = models_dir + "/models/hs/hs_motor_310p.om" ; LOG_INFO("hs_motor 版本:{} 模型路径:{}", hs_motor_getversion(), model_path); hs_motor_param param; diff --git a/src/ai_engine_module/motocycle_hs_process.h b/src/ai_engine_module/motocycle_hs_process.h index 3f491f7..3103549 100644 --- a/src/ai_engine_module/motocycle_hs_process.h +++ b/src/ai_engine_module/motocycle_hs_process.h @@ -84,7 +84,7 @@ namespace ai_engine_module ~MotorHsProcess(); bool check_initied(); - bool init(int gpu_id); + bool init(int gpu_id, string models_dir); bool update_mstreams(const std::vector& taskIds, vector vec_det_input_images, const std::vector &det_results); std::shared_ptr get_result_by_objectid(const id_t& id, bool do_erase = true); diff --git a/src/ai_engine_module/tricycle_manned_process.cpp b/src/ai_engine_module/tricycle_manned_process.cpp index 5fb2507..65ae125 100644 --- a/src/ai_engine_module/tricycle_manned_process.cpp +++ b/src/ai_engine_module/tricycle_manned_process.cpp @@ -29,11 +29,11 @@ namespace ai_engine_module } } - bool TricycleMannedProcess::init(int gpu_id) + bool TricycleMannedProcess::init(int gpu_id, string models_dir) { init_ = false; - string model_path = "./models/hs/hs_tricycle_310p.om" ; + string model_path = models_dir + "/models/hs/hs_tricycle_310p.om" ; LOG_INFO("hs_tri 版本:{} 模型路径:{}", hs_tri_getversion(), model_path); hs_tri_param param; diff --git a/src/ai_engine_module/tricycle_manned_process.h b/src/ai_engine_module/tricycle_manned_process.h index 3374f92..f49c60f 100644 --- a/src/ai_engine_module/tricycle_manned_process.h +++ b/src/ai_engine_module/tricycle_manned_process.h @@ -75,7 +75,7 @@ namespace ai_engine_module ~TricycleMannedProcess(); bool check_initied(); - bool init(int gpu_id); + bool init(int gpu_id, string models_dir); bool update_mstreams(const std::vector& taskIds, vector vec_det_input_images, const std::vector &det_results); std::shared_ptr get_result_by_objectid(const id_t& id, bool do_erase = true); diff --git a/src/ai_engine_module/truck_manned_process.cpp b/src/ai_engine_module/truck_manned_process.cpp index 845b963..c1c7a78 100644 --- a/src/ai_engine_module/truck_manned_process.cpp +++ b/src/ai_engine_module/truck_manned_process.cpp @@ -29,11 +29,11 @@ namespace ai_engine_module } } - bool TruckMannedProcess::init(int gpu_id) + bool TruckMannedProcess::init(int gpu_id, string models_dir) { init_ = false; - string model_path = "./models/hs/hs_truck_310p.om" ; + string model_path = models_dir + "/models/hs/hs_truck_310p.om" ; LOG_INFO("hs_truck 版本:{} 模型路径:{}", hs_truck_getversion(), model_path); hs_truck_param param; diff --git a/src/ai_engine_module/truck_manned_process.h b/src/ai_engine_module/truck_manned_process.h index 7472060..b19b860 100644 --- a/src/ai_engine_module/truck_manned_process.h +++ b/src/ai_engine_module/truck_manned_process.h @@ -75,7 +75,7 @@ namespace ai_engine_module ~TruckMannedProcess(); bool check_initied(); - bool init(int gpu_id); + bool init(int gpu_id, string models_dir); bool update_mstreams(const std::vector& taskIds, vector vec_det_input_images, const std::vector &det_results); std::shared_ptr get_result_by_objectid(const id_t& id, bool do_erase = true); diff --git a/src/ai_platform/MultiSourceProcess.cpp b/src/ai_platform/MultiSourceProcess.cpp index 959703f..6b93648 100755 --- a/src/ai_platform/MultiSourceProcess.cpp +++ b/src/ai_platform/MultiSourceProcess.cpp @@ -109,19 +109,19 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ } //三轮车头肩检测 - if (!tricycle_manned_.init(vptParam.gpuid)) { + if (!tricycle_manned_.init(vptParam.gpuid, models_dir)) { LOG_FATAL("Init tricycle_hs failed"); return -1; } //货车头肩检测 - if (!truck_manned_.init(vptParam.gpuid)) { + if (!truck_manned_.init(vptParam.gpuid, models_dir)) { LOG_FATAL("Init truck_hs failed"); return -1; } //二轮车头肩检测 - if (!motor_hsprocess_.init(vptParam.gpuid)) { + if (!motor_hsprocess_.init(vptParam.gpuid, models_dir)) { LOG_FATAL("Init motor_hs failed"); return -1; } @@ -1303,7 +1303,7 @@ void CMultiSourceProcess::manned_snapshot(vector& vpt_interest_task_id, RecoderInfo recoderInfo; recoderInfo.task_id = task_id; recoderInfo.object_id = std::to_string(j); - recoderInfo.recoderDir = "./res/recode"; + recoderInfo.recoderPath = "./res/recode"; recoderInfo.frame_nb = mem->getFrameNb(); m_recoderinfo_queue_mtx.lock(); diff --git a/src/ai_platform/common_header.h b/src/ai_platform/common_header.h index 5c465a7..81d5f61 100755 --- a/src/ai_platform/common_header.h +++ b/src/ai_platform/common_header.h @@ -32,7 +32,7 @@ struct box_t { }; struct RecoderInfo { - std::string recoderDir; + std::string recoderPath; std::string task_id; std::string object_id; unsigned long long frame_nb; diff --git a/src/decoder/dvpp/FFRecoder.cpp b/src/decoder/dvpp/FFRecoder.cpp index 3f14288..f3c8d78 100644 --- a/src/decoder/dvpp/FFRecoder.cpp +++ b/src/decoder/dvpp/FFRecoder.cpp @@ -39,13 +39,13 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx, // [1] 创建解码器 const AVCodec* encoder = avcodec_find_encoder(AV_CODEC_ID_HEVC); if (!encoder) { - fprintf(stderr, "Find encoder AV_CODEC_ID_H264 failed!\n"); + LOG_ERROR("Find encoder AV_CODEC_ID_H264 failed!"); return false; } // 获取解码器上下文 codec_ctx_ = avcodec_alloc_context3(encoder); if (!codec_ctx_) { - fprintf(stderr, "Alloc context for encoder contx failed!\n"); + LOG_ERROR("Alloc context for encoder contx failed!"); return false; } // 设置解码器上下文参数 @@ -68,7 +68,7 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx, // 打开解码器 int ret = avcodec_open2(codec_ctx_, encoder, nullptr); if (ret < 0) { - fprintf(stderr, "Open encoder failed!\n"); + LOG_ERROR("Open encoder failed!"); return false; } @@ -93,17 +93,17 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx, if (av_frame_get_buffer(yuv_frame_, 0) < 0) { av_frame_free(&yuv_frame_); yuv_frame_ = nullptr; - fprintf(stderr, "Frame get buffer failed!\n"); + LOG_ERROR("Frame get buffer failed!"); return false; } // [5] 打开输出视频文件并写入视频头信息 if (avio_open(&fmt_ctx_->pb, outfile_name, AVIO_FLAG_WRITE) < 0) { - fprintf(stderr, "avio_open failed!\n"); + LOG_ERROR("avio_open failed!"); return false; } if (avformat_write_header(fmt_ctx_, nullptr) < 0) { - fprintf(stderr, "Write header failed!\n"); + LOG_ERROR("Write header failed!"); return false; } @@ -150,11 +150,11 @@ bool FFRecoder::init(AVStream* stream, AVCodecContext* avctx, const char* outfil // [5] 打开输出视频文件并写入视频头信息 if (avio_open(&fmt_ctx_->pb, outfile_name, AVIO_FLAG_WRITE) < 0) { - fprintf(stderr, "avio_open failed!\n"); + LOG_ERROR("avio_open failed!"); return false; } if (avformat_write_header(fmt_ctx_, nullptr) < 0) { - fprintf(stderr, "Write header failed!\n"); + LOG_ERROR("Write header failed!"); return false; } @@ -270,7 +270,7 @@ bool FFRecoder::write_pkt(AVPacket *pkt) { // pkt->stream_index = out_stream_->index; if(pkt->pts==AV_NOPTS_VALUE) { - // printf("frame_index:%d\n", frame_index); + // printf("frame_index:%d", frame_index); //Write PTS AVRational time_base1 = codec_ctx_->time_base; //Duration between 2 frames (us) @@ -293,7 +293,7 @@ bool FFRecoder::write_pkt(AVPacket *pkt) { // 将数据写入到输出流 int ret = av_write_frame(fmt_ctx_, pkt); if (ret < 0) { - fprintf(stderr, "Error while writing output packet: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret)); + LOG_ERROR("Error while writing output packet: {}", av_make_error_string(errbuf, sizeof(errbuf), ret)); return false; } return true; @@ -316,7 +316,7 @@ bool FFRecoder::write_frame(AVFrame* frame) int ret = avcodec_send_frame(codec_ctx_, pFrameOut); av_frame_free(&pFrameOut); if (ret < 0) { - fprintf(stderr, "Error sending a frame to the encoder: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret)); + LOG_ERROR("Error sending a frame to the encoder: {}", av_make_error_string(errbuf, sizeof(errbuf), ret)); return false; } @@ -327,7 +327,7 @@ bool FFRecoder::write_frame(AVFrame* frame) if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) return true; else if (ret < 0) { - fprintf(stderr, "Error encoding a frame: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret)); + LOG_ERROR("Error encoding a frame: {}", av_make_error_string(errbuf, sizeof(errbuf), ret)); return false; } // 将pts缩放到输出流的time_base上 @@ -339,7 +339,7 @@ bool FFRecoder::write_frame(AVFrame* frame) //ret = av_write_frame(fmt_ctx_, &pkt); av_packet_unref(&pkt); if (ret < 0) { - fprintf(stderr, "Error while writing output packet: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret)); + LOG_ERROR("Error while writing output packet: {}", av_make_error_string(errbuf, sizeof(errbuf), ret)); return false; } /* av_interleaved_write_frame(fmt_ctx_, nullptr); diff --git a/src/decoder/dvpp/FFRecoder.h b/src/decoder/dvpp/FFRecoder.h index ec99c15..dfee0e4 100644 --- a/src/decoder/dvpp/FFRecoder.h +++ b/src/decoder/dvpp/FFRecoder.h @@ -1,14 +1,7 @@ #pragma once #include -extern "C" { - #include - #include - #include - #include - #include - #include -} +#include "depend_headers.h" class FFRecoder { diff --git a/src/decoder/dvpp/FFRecoderTaskManager.cpp b/src/decoder/dvpp/FFRecoderTaskManager.cpp index 77b2c50..61b3cd1 100644 --- a/src/decoder/dvpp/FFRecoderTaskManager.cpp +++ b/src/decoder/dvpp/FFRecoderTaskManager.cpp @@ -198,14 +198,6 @@ list::iterator FFRecoderTaskManager::getStartIterator(unsigned long return it_first; } - // auto it_second = m_pkt_list.begin(); - // for(;it_second != m_pkt_list.end(); it_second++) { - // DataPacket* dataPkt = *it_second; - // if (dataPkt->frame_nb >= start_frame_nb){ - // return it_second; - // } - // } - auto it_second = m_pkt_list.begin(); for(;it_second != m_pkt_list.end(); it_second++) { DataPacket* dataPkt = *it_second; @@ -308,7 +300,7 @@ void FFRecoderTaskManager::recode_thread(RecodeParam recodeParam){ RecoderInfo recoderInfo; recoderInfo = recodeParam.recoderInfo; std::string id = recoderInfo.task_id + "_" + recoderInfo.object_id + "_" + std::to_string(recoderInfo.frame_nb); - string file_name = recoderInfo.recoderDir + "/recoder_" + id + "_" + std::to_string(get_cur_time()) + ".mp4"; + string file_name = recoderInfo.recoderPath; FFRecoder ffrecoder; bool bInit = ffrecoder.init(m_inStream, recodeParam.avctx, file_name.c_str()); if (!bInit) { @@ -359,8 +351,6 @@ void FFRecoderTaskManager::recode_thread2() { continue; } - auto it_end = getEndIterator(recoderinfo.frame_nb); - LOG_INFO("start frame_nb: {}", (*it_data)->frame_nb); m_pkt_list_mtx.lock(); @@ -379,7 +369,7 @@ void FFRecoderTaskManager::recode_thread2() { m_pkt_list_mtx.unlock(); std::string id = recoderinfo.task_id + "_" + recoderinfo.object_id + "_" + std::to_string(recoderinfo.frame_nb); - string file_name = recoderinfo.recoderDir + "/recoder_" + id + "_" + std::to_string(get_cur_time()) + ".mp4"; + string file_name = recoderinfo.recoderPath; FFRecoder ffrecoder; bool bInit = ffrecoder.init(m_inStream, m_avctx, file_name.c_str()); if (!bInit) { @@ -387,7 +377,7 @@ void FFRecoderTaskManager::recode_thread2() { ffrecoder.uninit(); continue; } - LOG_INFO("record start, pkt_list size: {} id: {}", m_pkt_list.size(), id); + 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); int count = 0; auto it_save = it_data; @@ -420,7 +410,7 @@ void FFRecoderTaskManager::recode_thread2() { } void FFRecoderTaskManager::recode_thread3() { - LOG_INFO("recode_thread2 start..."); + LOG_INFO("recode_thread3 start..."); while(true) { if(m_bExit) { break; @@ -458,7 +448,7 @@ void FFRecoderTaskManager::recode_thread3() { m_frame_list_mtx.unlock(); std::string id = recoderinfo.task_id + "_" + recoderinfo.object_id + "_" + std::to_string(recoderinfo.frame_nb); - string file_name = recoderinfo.recoderDir + "/recoder_" + id + "_" + std::to_string(get_cur_time()) + ".mp4"; + string file_name = recoderinfo.recoderPath; FFRecoder ffrecoder; bool bInit = ffrecoder.init(m_avctx->width, m_avctx->height, m_time_base, m_avctx, file_name.c_str()); if (!bInit) { @@ -491,11 +481,11 @@ void FFRecoderTaskManager::recode_thread3() { LOG_INFO("record end, total save: {} start_frame_nb: {} end_frame_nb: {} file_path: {}", count, start_frame_nb, end_frame_nb, file_name); } - LOG_INFO("recode_thread2 end."); + LOG_INFO("recode_thread3 end."); } void FFRecoderTaskManager::recode_thread4() { - LOG_INFO("recode_thread2 start..."); + LOG_INFO("recode_thread4 start..."); while(true) { if(m_bExit) { break; @@ -533,7 +523,7 @@ void FFRecoderTaskManager::recode_thread4() { m_pkt_list_mtx.unlock(); std::string id = recoderinfo.task_id + "_" + recoderinfo.object_id + "_" + std::to_string(recoderinfo.frame_nb); - string file_name = recoderinfo.recoderDir + "/recoder_" + id + "_" + std::to_string(get_cur_time()) + ".mp4"; + string file_name = recoderinfo.recoderPath; FFRecoder ffrecoder; bool bInit = ffrecoder.init(m_inStream, m_avctx, file_name.c_str()); if (!bInit) { @@ -566,7 +556,7 @@ void FFRecoderTaskManager::recode_thread4() { LOG_INFO("record end, total save: {} start_frame_nb: {} end_frame_nb: {} file_path: {}", count, start_frame_nb, end_frame_nb, file_name); } - LOG_INFO("recode_thread2 end."); + LOG_INFO("recode_thread4 end."); } void FFRecoderTaskManager::close() { diff --git a/src/decoder/dvpp/depend_headers.h b/src/decoder/dvpp/depend_headers.h index 562a3b9..92064d3 100755 --- a/src/decoder/dvpp/depend_headers.h +++ b/src/decoder/dvpp/depend_headers.h @@ -27,6 +27,9 @@ extern "C" { #include "libavutil/samplefmt.h" #include "libavformat/avformat.h" #include "libavcodec/avcodec.h" + #include + #include + #include } diff --git a/src/decoder/test_recoder.cpp b/src/decoder/test_recoder.cpp index 448b8fb..d373aa8 100644 --- a/src/decoder/test_recoder.cpp +++ b/src/decoder/test_recoder.cpp @@ -179,7 +179,7 @@ void algorthim_face_detect(vector vec_gpuMem) { RecoderInfo recoderInfo; recoderInfo.task_id = task_id; recoderInfo.object_id = std::to_string(obj_id); - recoderInfo.recoderDir = "./res/recode"; + recoderInfo.recoderPath = "./res/recode"; recoderInfo.frame_nb = mem->getFrameNb(); m_recoderinfo_queue_mtx.lock(); @@ -211,7 +211,7 @@ void test_recode_thread() { RecoderInfo recoderInfo; recoderInfo.task_id = gpuMem->getId(); recoderInfo.object_id = std::to_string(obj_id); - recoderInfo.recoderDir = "./res/recode"; + recoderInfo.recoderPath = "./res/recode"; recoderInfo.frame_nb = gpuMem->getFrameNb(); DecoderManager* pDecManager = DecoderManager::getInstance();