diff --git a/.vscode/launch.json b/.vscode/launch.json index cd62d79..1469354 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -20,6 +20,24 @@ } ] },{ + "name": "test_ffnvdecoder", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/Linux_3rdparty/video_structure_sdk_20220512/test", + "args": ["/home/cmhu/data/video/Street.uvf","6","0","./db/mvpt.bin"], + "stopAtEntry": false, + "cwd": "${workspaceFolder}/Linux_3rdparty/video_structure_sdk_20220512", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + },{ "name": "test_face", "type": "cppdbg", "request": "launch", diff --git a/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile b/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile index f22b6ba..bc88b66 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile +++ b/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile @@ -2,6 +2,7 @@ CC = gcc XX = g++ AR = ar +CUDA = /usr/local/cuda NVCC = /usr/local/cuda/bin/nvcc MNT_HOME = /home/cmhu/Project_VideoStructure @@ -11,6 +12,7 @@ DEPEND_DIR = $(MNT_HOME)/Linux_3rdparty SDK_ROOT = $(MNT_HOME)/SDK SRC_ROOT = $(PROJECT_ROOT)/src/VPT +FFNVDECODER_ROOT = $(PROJECT_ROOT)/src/FFNvDecoder UTOOLS_SSD_ROOT = $(DEPEND_DIR)/utools_trt_v1.4.0 HIDE_MODEL_CAFFE2 = $(PROJECT_ROOT)/model/hidemodel_caffe_1108 @@ -19,6 +21,7 @@ AUTHORITY_DIR = $(DEPEND_DIR)/authority_linux_20200114 TRT_ROOT = $(DEPEND_DIR)/TensorRT-8.6.1.6 OPENCV_ROOT = $(DEPEND_DIR)/opencv-4.5.4/release FFMPEG_ROOT = $(DEPEND_DIR)/ffmpeg-5.0.1/release +SPDLOG_ROOT = $(DEPEND_DIR)/spdlog-1.9.2/release TARGET = $(DEPEND_DIR)/video_structure_sdk_20220512/libmvpt.so @@ -34,16 +37,18 @@ INCLUDE= -I $(DEPEND_DIR)/include/boost_linux_x86_64/include \ -I $(DEPEND_DIR)/include/cairo \ -I $(SRC_ROOT)/sort \ -I $(SRC_ROOT)/snapshot_analysis \ - -I $(SRC_ROOT)/../DxDecoder \ - -I /usr/local/cuda/include \ -I $(HIDE_MODEL_CAFFE2) \ -I $(HIDE_MODEL_TRT) \ -I $(AUTHORITY_DIR) \ -I $(FFMPEG_ROOT)/include \ -I $(SDK_ROOT)/face_detect2/face_detect \ + -I $(SPDLOG_ROOT)/include \ + -I $(FFNVDECODER_ROOT) \ + -I $(FFNVDECODER_ROOT)/common/inc \ + -I $(FFNVDECODER_ROOT)/common/UtilNPP \ + -I $(CUDA)/include \ -LIBSPATH= -L ../DxDecoder -l:libDxDecoder.a \ - -L/usr/local/cuda/lib64 -lcuda -lcudart -lcurand -lcublas \ +LIBSPATH=-L/usr/local/cuda/lib64 -lcuda -lcudart -lcurand -lcublas \ -L/usr/lib/x86_64-linux-gnu -lnvcuvid \ -L$(DEPEND_DIR)/video_structure_sdk_20220512 -lSfxDecoder -lSfxStreamHandler -lvpd2 \ -L$(DEPEND_DIR)/video_structure_sdk_20220512 -lface_detect -lvehicle_brand_cls -lvr_vehicle_type_10cls -lvr5905cls -lvehicle_recognize -lvehicle_color -lhuman_parsing -lhuman_car_parsing -lnon_vehicle_fea_trt -lvehicle_rear_recognition -lvf_int8 -lvp2_yolo\ @@ -53,9 +58,10 @@ LIBSPATH= -L ../DxDecoder -l:libDxDecoder.a \ -L $(OPENCV_ROOT)/lib -lopencv_video -lopencv_highgui -lopencv_imgproc -lopencv_core -lopencv_imgcodecs\ -L$(AUTHORITY_DIR) -l:libauthority.a \ -L $(DEPEND_DIR)/include/boost_linux_x86_64/lib -l:libboost_system.a -l:libboost_thread.a \ + -L $(SPDLOG_ROOT)/lib -l:libspdlog.a \ -CFLAGS_LIB=-g -O0 -Wall -Wno-deprecated $(DEFS) -lz -fPIC -fvisibility=hidden -Wl,-Bsymbolic +CFLAGS_LIB=-g -O0 -Wall -Wno-deprecated $(DEFS) -lz -ldl -lpthread -fPIC -fvisibility=hidden -Wl,-Bsymbolic CFLAGS = $(CFLAGS_LIB) $(INCLUDE) -std=c++11 -DUSE_CUDNN # -DUNICODE -D_UNICODE NFLAGS_LIB=-g -c $(DEFS) -shared -Xcompiler -fPIC -Xcompiler -fvisibility=hidden @@ -69,10 +75,13 @@ SRCS:=$(wildcard $(SRC_ROOT)/*.cpp) \ $(wildcard $(HIDE_MODEL_CAFFE2)/*.cpp) \ $(wildcard $(HIDE_MODEL_TRT)/*.cpp) \ $(wildcard $(SRC_ROOT)/snapshot_analysis/*.cpp) \ - + $(wildcard $(FFNVDECODER_ROOT)/*.cpp) + OBJS = $(patsubst %.cpp, %.o, $(notdir $(SRCS))) -CU_SOURCES = $(wildcard ${SRC_ROOT}/snapshot_analysis/*.cu) +CU_SOURCES = $(wildcard ${SRC_ROOT}/snapshot_analysis/*.cu) \ + $(wildcard ${FFNVDECODER_ROOT}/*.cu) + CU_OBJS = $(patsubst %.cu, %.o, $(notdir $(CU_SOURCES))) all:$(TARGET) @@ -97,6 +106,13 @@ $(TARGET):$(OBJS) $(CU_OBJS) %.o:$(SRC_ROOT)/snapshot_analysis/%.cu @echo "#######################CU_OBJS:$@###############" $(NVCC) $(NFLAGS) -o $@ $< + +%.o:$(FFNVDECODER_ROOT)/%.cpp + $(XX) $(CFLAGS) -c $< + +%.o:$(FFNVDECODER_ROOT)/%.cu + @echo "#######################CU_OBJS:$@###############" + $(NVCC) $(NFLAGS) -o $@ $< .PHONY:clean clean: diff --git a/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile.FFNvDecoder b/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile.qx index bc88b66..f22b6ba 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile.FFNvDecoder +++ b/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile.qx @@ -2,7 +2,6 @@ CC = gcc XX = g++ AR = ar -CUDA = /usr/local/cuda NVCC = /usr/local/cuda/bin/nvcc MNT_HOME = /home/cmhu/Project_VideoStructure @@ -12,7 +11,6 @@ DEPEND_DIR = $(MNT_HOME)/Linux_3rdparty SDK_ROOT = $(MNT_HOME)/SDK SRC_ROOT = $(PROJECT_ROOT)/src/VPT -FFNVDECODER_ROOT = $(PROJECT_ROOT)/src/FFNvDecoder UTOOLS_SSD_ROOT = $(DEPEND_DIR)/utools_trt_v1.4.0 HIDE_MODEL_CAFFE2 = $(PROJECT_ROOT)/model/hidemodel_caffe_1108 @@ -21,7 +19,6 @@ AUTHORITY_DIR = $(DEPEND_DIR)/authority_linux_20200114 TRT_ROOT = $(DEPEND_DIR)/TensorRT-8.6.1.6 OPENCV_ROOT = $(DEPEND_DIR)/opencv-4.5.4/release FFMPEG_ROOT = $(DEPEND_DIR)/ffmpeg-5.0.1/release -SPDLOG_ROOT = $(DEPEND_DIR)/spdlog-1.9.2/release TARGET = $(DEPEND_DIR)/video_structure_sdk_20220512/libmvpt.so @@ -37,18 +34,16 @@ INCLUDE= -I $(DEPEND_DIR)/include/boost_linux_x86_64/include \ -I $(DEPEND_DIR)/include/cairo \ -I $(SRC_ROOT)/sort \ -I $(SRC_ROOT)/snapshot_analysis \ + -I $(SRC_ROOT)/../DxDecoder \ + -I /usr/local/cuda/include \ -I $(HIDE_MODEL_CAFFE2) \ -I $(HIDE_MODEL_TRT) \ -I $(AUTHORITY_DIR) \ -I $(FFMPEG_ROOT)/include \ -I $(SDK_ROOT)/face_detect2/face_detect \ - -I $(SPDLOG_ROOT)/include \ - -I $(FFNVDECODER_ROOT) \ - -I $(FFNVDECODER_ROOT)/common/inc \ - -I $(FFNVDECODER_ROOT)/common/UtilNPP \ - -I $(CUDA)/include \ -LIBSPATH=-L/usr/local/cuda/lib64 -lcuda -lcudart -lcurand -lcublas \ +LIBSPATH= -L ../DxDecoder -l:libDxDecoder.a \ + -L/usr/local/cuda/lib64 -lcuda -lcudart -lcurand -lcublas \ -L/usr/lib/x86_64-linux-gnu -lnvcuvid \ -L$(DEPEND_DIR)/video_structure_sdk_20220512 -lSfxDecoder -lSfxStreamHandler -lvpd2 \ -L$(DEPEND_DIR)/video_structure_sdk_20220512 -lface_detect -lvehicle_brand_cls -lvr_vehicle_type_10cls -lvr5905cls -lvehicle_recognize -lvehicle_color -lhuman_parsing -lhuman_car_parsing -lnon_vehicle_fea_trt -lvehicle_rear_recognition -lvf_int8 -lvp2_yolo\ @@ -58,10 +53,9 @@ LIBSPATH=-L/usr/local/cuda/lib64 -lcuda -lcudart -lcurand -lcublas \ -L $(OPENCV_ROOT)/lib -lopencv_video -lopencv_highgui -lopencv_imgproc -lopencv_core -lopencv_imgcodecs\ -L$(AUTHORITY_DIR) -l:libauthority.a \ -L $(DEPEND_DIR)/include/boost_linux_x86_64/lib -l:libboost_system.a -l:libboost_thread.a \ - -L $(SPDLOG_ROOT)/lib -l:libspdlog.a \ -CFLAGS_LIB=-g -O0 -Wall -Wno-deprecated $(DEFS) -lz -ldl -lpthread -fPIC -fvisibility=hidden -Wl,-Bsymbolic +CFLAGS_LIB=-g -O0 -Wall -Wno-deprecated $(DEFS) -lz -fPIC -fvisibility=hidden -Wl,-Bsymbolic CFLAGS = $(CFLAGS_LIB) $(INCLUDE) -std=c++11 -DUSE_CUDNN # -DUNICODE -D_UNICODE NFLAGS_LIB=-g -c $(DEFS) -shared -Xcompiler -fPIC -Xcompiler -fvisibility=hidden @@ -75,13 +69,10 @@ SRCS:=$(wildcard $(SRC_ROOT)/*.cpp) \ $(wildcard $(HIDE_MODEL_CAFFE2)/*.cpp) \ $(wildcard $(HIDE_MODEL_TRT)/*.cpp) \ $(wildcard $(SRC_ROOT)/snapshot_analysis/*.cpp) \ - $(wildcard $(FFNVDECODER_ROOT)/*.cpp) - + OBJS = $(patsubst %.cpp, %.o, $(notdir $(SRCS))) -CU_SOURCES = $(wildcard ${SRC_ROOT}/snapshot_analysis/*.cu) \ - $(wildcard ${FFNVDECODER_ROOT}/*.cu) - +CU_SOURCES = $(wildcard ${SRC_ROOT}/snapshot_analysis/*.cu) CU_OBJS = $(patsubst %.cu, %.o, $(notdir $(CU_SOURCES))) all:$(TARGET) @@ -106,13 +97,6 @@ $(TARGET):$(OBJS) $(CU_OBJS) %.o:$(SRC_ROOT)/snapshot_analysis/%.cu @echo "#######################CU_OBJS:$@###############" $(NVCC) $(NFLAGS) -o $@ $< - -%.o:$(FFNVDECODER_ROOT)/%.cpp - $(XX) $(CFLAGS) -c $< - -%.o:$(FFNVDECODER_ROOT)/%.cu - @echo "#######################CU_OBJS:$@###############" - $(NVCC) $(NFLAGS) -o $@ $< .PHONY:clean clean: diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.cpp index df72bfc..995c17f 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.cpp @@ -40,7 +40,8 @@ FFImgInfo* AbstractDecoder::snapshot(){ } // 队列中数据大于1 - gpuFrame = mFrameQueue.front(); + GPUFrame* frame = mFrameQueue.front(); + gpuFrame = frame->gpuFrame; m_queue_mutex.unlock(); break; } diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.h b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.h index 94b616d..73caa60 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.h @@ -57,6 +57,7 @@ struct FFDecConfig{ string gpuid; // gpu id bool force_tcp{true}; // 是否指定使用tcp连接 int skip_frame{1}; // 跳帧数 + bool keyframe_decode_mod; // 关键帧模式解码 int port; // gb28181接收数据的端口号 DECODE_REQUEST_STREAM_CALLBACK request_stream_cbk; // gb28181请求流 @@ -129,7 +130,7 @@ public: FFDecConfig m_cfg; - queue mFrameQueue; + queue mFrameQueue; mutex m_queue_mutex; mutex m_snapshot_mutex; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp index 54ce35f..25e7d94 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp @@ -21,7 +21,8 @@ void decode_finished_cbk(const void * userPtr){ DxDecoderWrap::DxDecoderWrap( const DxConfig * cfg ) { m_bClose = false; - m_pDec = NULL; + m_pDec = nullptr; + m_pHwData = nullptr; m_cfg.post_decoded_cbk = decoded_cbk; m_cfg.decode_finished_cbk = decode_finished_cbk; @@ -29,6 +30,11 @@ DxDecoderWrap::DxDecoderWrap( const DxConfig * cfg ) m_cfg.gpuid = std::to_string(cfg->devId); m_name = cfg->name; + m_decMode = cfg->decMode; + + CUdevice cuDevice; + cuDeviceGet(&cuDevice, cfg->devId); + cuCtxCreate(&m_cuda_cxt, 0, cuDevice); return; } @@ -60,6 +66,10 @@ int DxDecoderWrap::DxOpenDecoder( const char * uri, unsigned int skip ) m_pDec->setName(m_name) ; m_pDec->m_postDecArg = this; m_pDec->m_finishedDecArg = this; + if(1 == m_decMode) { + m_pDec->setDecKeyframe(true); + } + m_pDec->start(); LOG_INFO("[{}][{}]- 解码器初始化成功", m_name.c_str(), uri); return 0; } @@ -77,16 +87,29 @@ int DxDecoderWrap::DxOpenDecoder( const char * uri, unsigned int skip ) int DxDecoderWrap::DxCloseDecoder() { m_bClose = true; + if(m_pDec) { m_pDec->close(); delete m_pDec; m_pDec = nullptr; } - if(pHwData != nullptr){ - cudaFree(pHwData); + m_queue_frames_mutex.lock(); + while (m_queue_frames.size() > 0) { + GPUFrame * decodedFrame = m_queue_frames.front(); + m_queue_frames.pop(); + delete decodedFrame; + decodedFrame = nullptr; + } + m_queue_frames_mutex.unlock(); + + if(m_pHwData != nullptr){ + cudaFree(m_pHwData); } + cuCtxPopCurrent(nullptr); + cuCtxDestroy(m_cuda_cxt); + return 0; } @@ -112,8 +135,8 @@ int DxDecoderWrap::DxGetResolution( int * width, int * height ) return -1; } -int DxDecoderWrap::DxGetFrameCount(){ - +int DxDecoderWrap::DxGetFrameCount() +{ if(m_pDec != nullptr){ return m_pDec->GetFrameCount(); } @@ -150,9 +173,13 @@ bool DxDecoderWrap::DxDecoderIsRun() const } -bool DxDecoderWrap::DxFrameIsEmpty() const +bool DxDecoderWrap::DxFrameIsEmpty() { - return 0 == m_frames.counts; + m_queue_frames_mutex.lock(); + int count = m_queue_frames.size(); + m_queue_frames_mutex.unlock(); + + return 0 == count; } @@ -164,6 +191,11 @@ int DxDecoderWrap::DxLockFrame( DxGPUFrame * frame ) } m_queue_frames_mutex.lock(); + if(m_queue_frames.size() <= 0) { + m_queue_frames_mutex.unlock(); + return -1; + } + GPUFrame * decodedFrame = m_queue_frames.front(); m_queue_frames.pop(); m_queue_frames_mutex.unlock(); @@ -171,17 +203,18 @@ int DxDecoderWrap::DxLockFrame( DxGPUFrame * frame ) AVFrame* gpuFrame = decodedFrame->gpuFrame; cudaSetDevice(atoi(m_cfg.gpuid.c_str())); + cuCtxPushCurrent(m_cuda_cxt); cudaError_t cudaStatus; size_t rgbSize = 3 * gpuFrame->width * gpuFrame->height * sizeof(unsigned char); - if(pHwData == nullptr){ - cudaStatus = cudaMalloc((void **)&pHwData, rgbSize); + if(m_pHwData == nullptr){ + cudaStatus = cudaMalloc((void **)&m_pHwData, rgbSize); if (cudaStatus != cudaSuccess) { LOG_ERROR("[{}]- cudaMalloc failed !!!", m_name.c_str()); return -1; } } cuda_common::setColorSpace( ITU_709, 0 ); - cudaStatus = cuda_common::CUDAToBGR((CUdeviceptr)gpuFrame->data[0],(CUdeviceptr)gpuFrame->data[1], gpuFrame->linesize[0], gpuFrame->linesize[1], pHwData, gpuFrame->width, gpuFrame->height); + cudaStatus = cuda_common::CUDAToBGR((CUdeviceptr)gpuFrame->data[0],(CUdeviceptr)gpuFrame->data[1], gpuFrame->linesize[0], gpuFrame->linesize[1], m_pHwData, gpuFrame->width, gpuFrame->height); cudaDeviceSynchronize(); if (cudaStatus != cudaSuccess) { LOG_ERROR("[{}]- CUDAToBGR failed !!!", m_name.c_str()); @@ -191,7 +224,7 @@ int DxDecoderWrap::DxLockFrame( DxGPUFrame * frame ) frame->width = gpuFrame->width; frame->height = gpuFrame->height; frame->size = rgbSize; - frame->frame = pHwData; + frame->frame = m_pHwData; frame->timestamp = decodedFrame->ts; delete decodedFrame; @@ -200,12 +233,14 @@ int DxDecoderWrap::DxLockFrame( DxGPUFrame * frame ) return 0; } -void DxDecoderWrap::post_decode_thread(GPUFrame * gpuFrame) { +void DxDecoderWrap::post_decode_thread(GPUFrame * decodedFrame) { while(!m_bClose) { m_queue_frames_mutex.lock(); if(m_queue_frames.size() < 3) { - m_queue_frames.push(gpuFrame); + // 入队 + m_queue_frames.push(decodedFrame); m_queue_frames_mutex.unlock(); + break; } else { m_queue_frames_mutex.unlock(); std::this_thread::sleep_for(std::chrono::milliseconds(10)); @@ -214,5 +249,5 @@ void DxDecoderWrap::post_decode_thread(GPUFrame * gpuFrame) { } void DxDecoderWrap::decode_finished_thread() { - + m_bClose = true; } \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h index 7b4b301..b89448e 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h @@ -16,7 +16,7 @@ typedef struct DxConfig { int devId; // 设备(GPU)ID - int decMode; // 解码模式 + int decMode; // 解码模式: 0 全解码; 1 关键帧解码 int colorFmt; // 颜色空间 bool forceTcp; // 对于实时流,是否强制为TCP取流 std::string name; @@ -58,7 +58,7 @@ public: int DxGetResolution( int * width, int * height ); - bool DxFrameIsEmpty() const; + bool DxFrameIsEmpty(); int DxLockFrame( DxGPUFrame * frame ); int PauseDecoder(); @@ -72,8 +72,6 @@ public: private: bool m_bClose; - DxGPUFrames m_frames; - FFDecConfig m_cfg; string m_name; FFNvDecoder* m_pDec; @@ -81,7 +79,10 @@ private: std::queue m_queue_frames; std::mutex m_queue_frames_mutex; - unsigned char *pHwData {nullptr}; + unsigned char *m_pHwData {nullptr}; + CUcontext m_cuda_cxt; + + int m_decMode{0}; }; #endif \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp index 2873fa3..cf08bd7 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp @@ -59,14 +59,14 @@ bool FFNvDecoder::init(FFDecConfig& cfg) { m_cfg = cfg; - // todo : fstream判断错误 - fstream infile(cfg.uri); - if (infile.is_open()){ + FILE* fp; + fp=fopen(cfg.uri.c_str(),"rb"); + if(fp!=nullptr) { m_bReal = false; - infile.close(); - }else { + } else { m_bReal = true; } + fclose(fp); post_decoded_cbk = cfg.post_decoded_cbk; decode_finished_cbk = cfg.decode_finished_cbk; @@ -119,6 +119,7 @@ bool FFNvDecoder::init(const char* uri, const char* gpuid, bool force_tcp) return false; m_fps = av_q2d(stream ->avg_frame_rate); + m_nb_frames = stream->nb_frames; avctx->opaque = this; // 设置解码器管理器的像素格式回调函数 @@ -197,6 +198,7 @@ void FFNvDecoder::decode_thread() // long start_time = get_cur_time(); + unsigned long long index = 0; while (m_bRunning) { if (!m_bReal) @@ -220,15 +222,10 @@ void FFNvDecoder::decode_thread() if (result == AVERROR_EOF || result < 0) { av_packet_unref(pkt); - LOG_ERROR("Failed to read frame!"); + LOG_INFO("Failed to read frame!"); break; } - if (m_dec_keyframe && !(pkt->flags & AV_PKT_FLAG_KEY)) { - av_packet_unref(pkt); - continue; - } - if (m_bReal) { if (m_bPause) @@ -240,6 +237,14 @@ void FFNvDecoder::decode_thread() } if (stream_index == pkt->stream_index){ + + index++; + + if (m_dec_keyframe && !(pkt->flags & AV_PKT_FLAG_KEY)) { + av_packet_unref(pkt); + continue; + } + result = avcodec_send_packet(avctx, pkt); if (result < 0){ av_packet_unref(pkt); @@ -260,7 +265,10 @@ void FFNvDecoder::decode_thread() if(gpuFrame != nullptr){ m_queue_mutex.lock(); if(mFrameQueue.size() <= 10){ - mFrameQueue.push(gpuFrame); + GPUFrame* frame = new GPUFrame(); + frame->ts = index; + frame->gpuFrame = gpuFrame; + mFrameQueue.push(frame); }else{ av_frame_free(&gpuFrame); } @@ -286,8 +294,9 @@ void FFNvDecoder::decode_thread() // 清空队列 while(mFrameQueue.size() > 0){ - AVFrame * gpuFrame = mFrameQueue.front(); - av_frame_free(&gpuFrame); + GPUFrame * frame = mFrameQueue.front(); + delete frame; + frame = nullptr; mFrameQueue.pop(); } @@ -323,18 +332,15 @@ void FFNvDecoder::post_decode_thread(){ std::lock_guard l(m_snapshot_mutex); // 取队头数据 m_queue_mutex.lock(); - AVFrame * gpuFrame = mFrameQueue.front(); + GPUFrame* frame = mFrameQueue.front(); mFrameQueue.pop(); m_queue_mutex.unlock(); // 跳帧 if (skip_frame == 1 || index % skip_frame == 0){ - GPUFrame* frame = new GPUFrame(); - frame->ts = index; - frame->gpuFrame = gpuFrame; post_decoded_cbk(m_postDecArg, frame); } - av_frame_free(&gpuFrame); + // av_frame_free(&gpuFrame); index++; } @@ -403,6 +409,5 @@ float FFNvDecoder::fps(){ } unsigned long long FFNvDecoder::GetFrameCount() { - // todo - return 1; + return m_nb_frames; } \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.h b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.h index b317d2b..cafc5dd 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.h @@ -60,4 +60,5 @@ private: bool m_bReal; // 是否实时流 float m_fps; + unsigned long long m_nb_frames; }; \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.h index 98cb1d8..0e89424 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.h @@ -3,7 +3,7 @@ #include #include "common.h" #include -#include "../DxDecoder/DxDecoderWrap.h" +#include "../FFNvDecoder/DxDecoderWrap.h" using std::map; using std::vector; class ImageSaveCache diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp index 2b1e6f5..39cbf63 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp @@ -394,7 +394,6 @@ void CMutliSourceVideoProcess::FinishTask(const int taskID) tasks[i].taskObjCallbackFunc = nullptr; tasks[i].taskRealTimeCallbackFunc = nullptr; - m_snaphot_helper.finish_task_ss_analysis(taskID, m_hp_analysis_config, m_hcp_analysis_config, m_vehicle_analysis_config, m_hf_recg_config, m_hcf_recg_config, m_vcf_recg_config); //�Ƿ�����������ʶ��); if (tasks[i].folderName) @@ -488,11 +487,15 @@ void CMutliSourceVideoProcess::FinishViewTask() printf("-----------------------finish view task-----------------------\n"); } - -//bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* resultFolderLittle, const char* resultFolder, const char* resultFolderface, bool on_image_display, sy_rect minBoxsize[DETECTTYPE], VIDEO_OBJECT_SNAPSHOT_CALLBACK objCallbackFunc/* = NULL*/, VIDEO_REALTIME_CALLBACK realTimeCallbackFunc/* = NULL*/) -bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* resultFolderLittle, const char* resultFolder, const char* resultFolderface, bool on_image_display, int jpeg_quality, sy_rect minBoxsize[DETECTTYPE], VIDEO_OBJECT_SNAPSHOT_CALLBACK objCallbackFunc/* = NULL*/, VIDEO_REALTIME_CALLBACK realTimeCallbackFunc/* = NULL*/) //debug by zsh +bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh { - //checkGpuMem(); + const char* videoFileName = tparam.video_filename; + const char* resultFolderLittle = tparam.result_folder_little; + const char* resultFolder = tparam.result_folder; + const char* resultFolderface = tparam.result_folder_face; + VIDEO_OBJECT_SNAPSHOT_CALLBACK objCallbackFunc = tparam.obj_snapshot_callback_func; + VIDEO_REALTIME_CALLBACK realTimeCallbackFunc = tparam.rt_view_callback_func; + std::lock_guard l(_tx_add_task); using std::placeholders::_1; // printf("begin real add task\n"); @@ -503,31 +506,16 @@ bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* re VPTResult.resize(capacity); } - string sVideoFileName = videoFileName; - - string target = "file://"; - int pos = sVideoFileName.find(target); - if (pos == 0) { - int n = target.size(); - sVideoFileName = sVideoFileName.erase(pos, n); - } - pos = sVideoFileName.find_first_of('?'); - if (pos != string::npos) { - sVideoFileName = sVideoFileName.substr(0, pos); - } - Task new_task = {}; new_task.taskID = TotalTask; new_task.taskFileSource = videoFileName; - memcpy(new_task.task_min_boxsize, minBoxsize, sizeof(sy_rect)* DETECTTYPE); - + memcpy(new_task.task_min_boxsize, tparam.minBoxsize, sizeof(sy_rect)* DETECTTYPE); DxConfig cfg = { 0 }; cfg.devId = mgpuid; - cfg.decMode = 0; - cfg.colorFmt = 0; cfg.forceTcp = false; - cfg.type = DX_DECODER_TYPE_SFXLAB; + cfg.decMode = tparam.decMode; + cfg.name = std::to_string(new_task.taskID); new_task.taskTcuvid = new DxDecoderWrap(&cfg); if (NULL == new_task.taskTcuvid) { @@ -631,8 +619,8 @@ bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* re new_task_info.snapshot_folder = new_task.folderNameLittle; new_task_info.snapshot_folder_face = new_task.folderNameFace; new_task_info.task_total_framecount = new_task.taskTotalFrameCount; - new_task_info._on_image_display = on_image_display; - new_task_info.jpeg_quality_ = jpeg_quality; //debug by zsh + new_task_info._on_image_display = tparam.on_image_display; + new_task_info.jpeg_quality_ = tparam.jpeg_quality; //debug by zsh new_task_info.obj_callback = new_task.taskObjCallbackFunc; m_snaphot_helper.add_task_info(new_task.taskID, new_task_info); @@ -640,20 +628,8 @@ bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* re TaskinPlay++; tasks.push_back(new_task); - // printf("finish push tasks\n"); - - //return 1; - //std::cout<<__LINE__<<"of"<<__FILE__<<"debug\n"; - if (!ProcessFlag) - { - /*for (int num = 0; num < 5; ++num) - {*/ - //create_thread()��һ���������������Դ���thead���������̣߳�ͬʱ�����ڲ���list - // group.create_thread(boost::bind(&runchild , num)) ; - //saveSnapshotsThreadGroup.create_thread(boost::bind(SnapshotThreadProcess, this, 0)); - //} + if (!ProcessFlag) { ProcessThread = boost::thread(ThreadProcess, this); - //std::cout << "begin algorithm" << std::endl; ProcessFlag = true; } @@ -668,8 +644,7 @@ int CMutliSourceVideoProcess::AddOperator(task_param tparam) if (!ProcessFlag) { - //AddTask(tparam.video_filename, tparam.result_folder_little, tparam.result_folder, tparam.result_folder_face, tparam.on_image_display, tparam.minBoxsize, tparam.obj_snapshot_callback_func, tparam.rt_view_callback_func); - AddTask(tparam.video_filename, tparam.result_folder_little, tparam.result_folder, tparam.result_folder_face, tparam.on_image_display, tparam.jpeg_quality, tparam.minBoxsize, tparam.obj_snapshot_callback_func, tparam.rt_view_callback_func); //debug by zsh + AddTask(tparam); boost::thread::sleep(boost::get_system_time() + boost::posix_time::microseconds(500)); } else @@ -680,12 +655,14 @@ int CMutliSourceVideoProcess::AddOperator(task_param tparam) Operator newOper; newOper.changeTaskID = 0; newOper.changeTaskOperator = ADDTASK; - newOper.videoFileName = tparam.video_filename; - newOper.resultFolderLittleName = tparam.result_folder_little; - newOper.result_folder_face = tparam.result_folder_face; - newOper.resultFolderName = tparam.result_folder; + + strcpy(newOper.videoFileName, tparam.video_filename); + strcpy(newOper.resultFolderLittleName, tparam.result_folder_little); + strcpy(newOper.resultFolderName, tparam.result_folder); + strcpy(newOper.result_folder_face, tparam.result_folder_face); newOper.on_image_display = tparam.on_image_display; - newOper.jpeg_quality = tparam.jpeg_quality; //debug by zsh + newOper.jpeg_quality = tparam.jpeg_quality; + newOper.decMode = tparam.decMode; newOper.taskObjCallbackFunc = tparam.obj_snapshot_callback_func; newOper.taskRealTimeCallbackFunc = tparam.rt_view_callback_func; memcpy(newOper.minBoxsize, tparam.minBoxsize, sizeof(sy_rect)* DETECTTYPE); @@ -741,7 +718,6 @@ void CMutliSourceVideoProcess::AddOperator(int taskID, int taskOper) Operator newOper = {}; newOper.changeTaskID = taskID; newOper.changeTaskOperator = TaskOperator(taskOper); - newOper.videoFileName = NULL; //TaskOperatorQ.push(newOper); TaskOperatorQ.push_back(newOper); } @@ -757,8 +733,20 @@ void CMutliSourceVideoProcess::OperatorTask() switch (newOperator.changeTaskOperator) { case ADDTASK: - //AddTask(newOperator.videoFileName, newOperator.resultFolderLittleName, newOperator.resultFolderName, newOperator.result_folder_face, newOperator.on_image_display, newOperator.minBoxsize, newOperator.taskObjCallbackFunc, newOperator.taskRealTimeCallbackFunc); - AddTask(newOperator.videoFileName, newOperator.resultFolderLittleName, newOperator.resultFolderName, newOperator.result_folder_face, newOperator.on_image_display, newOperator.jpeg_quality, newOperator.minBoxsize, newOperator.taskObjCallbackFunc, newOperator.taskRealTimeCallbackFunc); //debug by zsh + { + task_param tparam; + strcpy(tparam.video_filename, newOperator.videoFileName); + strcpy(tparam.result_folder_little, newOperator.resultFolderLittleName); + strcpy(tparam.result_folder, newOperator.resultFolderName); + strcpy(tparam.result_folder_face, newOperator.result_folder_face); + tparam.on_image_display = newOperator.on_image_display; + tparam.jpeg_quality = newOperator.jpeg_quality; + memcpy(tparam.minBoxsize, newOperator.minBoxsize, sizeof(sy_rect)* DETECTTYPE); + tparam.obj_snapshot_callback_func = newOperator.taskObjCallbackFunc; + tparam.rt_view_callback_func = newOperator.taskRealTimeCallbackFunc; + tparam.decMode = newOperator.decMode; + AddTask(tparam); + } break; case PAUSETASK: PauseTask(newOperator.changeTaskID); @@ -1031,44 +1019,9 @@ DWORD ThreadProcess(LPVOID param) { if (k.find(i) == k.end() && pThreadParam->tasks[i].taskState == PLAY && pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) { - if (pThreadParam->tasks[i].taskTcuvid->DxLockFrame(&frame) == 0) - { - if (!pThreadParam->tasks[i].task_algorithm_data.frame && frame.width > 0 && frame.height > 0) - { - cudaError_t cudaStatus = cudaMalloc((void**)&pThreadParam->tasks[i].task_algorithm_data.frame, 3 * frame.size * frame.height * sizeof(unsigned char)); - if (cudaStatus != cudaSuccess) { - fprintf(stderr, "here cudaMalloc m_pRGBData[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); - break; - } - - pThreadParam->tasks[i].task_algorithm_data.height = frame.height; - pThreadParam->tasks[i].task_algorithm_data.width = frame.width; - pThreadParam->tasks[i].task_algorithm_data.size = frame.size; - - pThreadParam->tasks[i].frameImage = cv::Mat::zeros(frame.height, frame.width, CV_8UC3); - pThreadParam->tasks[i].taskDataToRT = (float*)malloc(3 * frame.height * frame.width * sizeof(unsigned char)); - AddTaskTracker(pThreadParam->VPT_Handle, pThreadParam->tasks[i].taskID, 1, 1); - } - - //copy decode data - if (pThreadParam->tasks[i].task_algorithm_data.frame) - { - int height = frame.height; - int width = frame.width; - - Nv12ToColor24( (unsigned char *)frame.frame, width, (unsigned char *)pThreadParam->tasks[i].task_algorithm_data.frame, 3 * width, width, height, 0 ); - - pThreadParam->tasks[i].task_algorithm_data.timestamp = frame.timestamp; - - k.insert(i); - pThreadParam->TaskinPlayID.insert(pThreadParam->tasks[i].taskID); - } - else - { - std::cout << "NOT ALLOC: pThreadParam->tasks[i].taskDataToBackup.frame" << pThreadParam->tasks[i].task_algorithm_data.frame << std::endl; - } - - pThreadParam->tasks[i].taskTcuvid->DxUnlockFrame(); + if(pThreadParam->tasks[i].taskTcuvid->DxLockFrame(&pThreadParam->tasks[i].task_algorithm_data) == 0) { + k.insert(i); + pThreadParam->TaskinPlayID.insert(pThreadParam->tasks[i].taskID); } } else if (k.find(i) == k.end() && pThreadParam->tasks[i].taskState == PLAY && !pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) @@ -1756,7 +1709,7 @@ DWORD ThreadProcess(LPVOID param) vector().swap(deleteObjectID[i]); vector>().swap(deleteObjectID); - // pThreadParam->m_snaphot_helper.object_attri_analysis(); + pThreadParam->m_snaphot_helper.object_attri_analysis(); #ifdef LOG_INFO2 long long second_analysis_time2 = get_cur_time_ms(); @@ -1788,7 +1741,7 @@ DWORD ThreadProcess(LPVOID param) } long long costTime1 = get_cur_time_ms() - begintime1; std::cout << "==================== Process Thread is Finished: " << std::endl; - printf("total frame cost time = %lld us, process times: %d \n", costTime1, process_times); + printf("total frame cost time = %lld us, process times: %d total_count: %d \n", costTime1, process_times, total_count); pThreadParam->m_snaphot_helper.snapShotInfo.clear(); pThreadParam->ProcessFlag = false; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.FFNvDecoder b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.qx index 813f94f..2b1e6f5 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.FFNvDecoder +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.qx @@ -524,8 +524,10 @@ bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* re DxConfig cfg = { 0 }; cfg.devId = mgpuid; + cfg.decMode = 0; + cfg.colorFmt = 0; cfg.forceTcp = false; - cfg.name = std::to_string(new_task.taskID); + cfg.type = DX_DECODER_TYPE_SFXLAB; new_task.taskTcuvid = new DxDecoderWrap(&cfg); if (NULL == new_task.taskTcuvid) { @@ -1029,49 +1031,45 @@ DWORD ThreadProcess(LPVOID param) { if (k.find(i) == k.end() && pThreadParam->tasks[i].taskState == PLAY && pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) { - if(pThreadParam->tasks[i].taskTcuvid->DxLockFrame(&pThreadParam->tasks[i].task_algorithm_data) == 0) { - k.insert(i); - pThreadParam->TaskinPlayID.insert(pThreadParam->tasks[i].taskID); + if (pThreadParam->tasks[i].taskTcuvid->DxLockFrame(&frame) == 0) + { + if (!pThreadParam->tasks[i].task_algorithm_data.frame && frame.width > 0 && frame.height > 0) + { + cudaError_t cudaStatus = cudaMalloc((void**)&pThreadParam->tasks[i].task_algorithm_data.frame, 3 * frame.size * frame.height * sizeof(unsigned char)); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "here cudaMalloc m_pRGBData[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); + break; + } + + pThreadParam->tasks[i].task_algorithm_data.height = frame.height; + pThreadParam->tasks[i].task_algorithm_data.width = frame.width; + pThreadParam->tasks[i].task_algorithm_data.size = frame.size; + + pThreadParam->tasks[i].frameImage = cv::Mat::zeros(frame.height, frame.width, CV_8UC3); + pThreadParam->tasks[i].taskDataToRT = (float*)malloc(3 * frame.height * frame.width * sizeof(unsigned char)); + AddTaskTracker(pThreadParam->VPT_Handle, pThreadParam->tasks[i].taskID, 1, 1); + } + + //copy decode data + if (pThreadParam->tasks[i].task_algorithm_data.frame) + { + int height = frame.height; + int width = frame.width; + + Nv12ToColor24( (unsigned char *)frame.frame, width, (unsigned char *)pThreadParam->tasks[i].task_algorithm_data.frame, 3 * width, width, height, 0 ); + + pThreadParam->tasks[i].task_algorithm_data.timestamp = frame.timestamp; + + k.insert(i); + pThreadParam->TaskinPlayID.insert(pThreadParam->tasks[i].taskID); + } + else + { + std::cout << "NOT ALLOC: pThreadParam->tasks[i].taskDataToBackup.frame" << pThreadParam->tasks[i].task_algorithm_data.frame << std::endl; + } + + pThreadParam->tasks[i].taskTcuvid->DxUnlockFrame(); } - // if (pThreadParam->tasks[i].taskTcuvid->DxLockFrame(&frame) == 0) - // { - // if (!pThreadParam->tasks[i].task_algorithm_data.frame && frame.width > 0 && frame.height > 0) - // { - // cudaError_t cudaStatus = cudaMalloc((void**)&pThreadParam->tasks[i].task_algorithm_data.frame, 3 * frame.size * frame.height * sizeof(unsigned char)); - // if (cudaStatus != cudaSuccess) { - // fprintf(stderr, "here cudaMalloc m_pRGBData[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); - // break; - // } - - // pThreadParam->tasks[i].task_algorithm_data.height = frame.height; - // pThreadParam->tasks[i].task_algorithm_data.width = frame.width; - // pThreadParam->tasks[i].task_algorithm_data.size = frame.size; - - // pThreadParam->tasks[i].frameImage = cv::Mat::zeros(frame.height, frame.width, CV_8UC3); - // pThreadParam->tasks[i].taskDataToRT = (float*)malloc(3 * frame.height * frame.width * sizeof(unsigned char)); - // AddTaskTracker(pThreadParam->VPT_Handle, pThreadParam->tasks[i].taskID, 1, 1); - // } - - // //copy decode data - // if (pThreadParam->tasks[i].task_algorithm_data.frame) - // { - // int height = frame.height; - // int width = frame.width; - - // Nv12ToColor24( (unsigned char *)frame.frame, width, (unsigned char *)pThreadParam->tasks[i].task_algorithm_data.frame, 3 * width, width, height, 0 ); - - // pThreadParam->tasks[i].task_algorithm_data.timestamp = frame.timestamp; - - // k.insert(i); - // pThreadParam->TaskinPlayID.insert(pThreadParam->tasks[i].taskID); - // } - // else - // { - // std::cout << "NOT ALLOC: pThreadParam->tasks[i].taskDataToBackup.frame" << pThreadParam->tasks[i].task_algorithm_data.frame << std::endl; - // } - - // pThreadParam->tasks[i].taskTcuvid->DxUnlockFrame(); - // } } else if (k.find(i) == k.end() && pThreadParam->tasks[i].taskState == PLAY && !pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) { diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h index 38a9049..4c8dd4d 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h @@ -5,7 +5,7 @@ #include #include -#include "../DxDecoder/DxDecoderWrap.h" +#include "../FFNvDecoder/DxDecoderWrap.h" #include "nvml.h" #include "time.h" #include "opencv2/opencv.hpp" @@ -15,7 +15,7 @@ #include #include #include "common.h" -#include "../DxDecoder/ImageSaveGPU.h" +#include "../FFNvDecoder/ImageSaveGPU.h" #include "mvpt_process_assist.h" #include @@ -173,12 +173,13 @@ enum TaskOperator struct Operator{ int changeTaskID; - const char* videoFileName; - const char* resultFolderLittleName; - const char* resultFolderName; - const char* result_folder_face; + char videoFileName[256]; + char resultFolderLittleName[256]; + char resultFolderName[256]; + char result_folder_face[256]; bool on_image_display; - int jpeg_quality; //ͼƬ���������IJ���0-100 --debug by zsh + int jpeg_quality; + int decMode; TaskOperator changeTaskOperator; VIDEO_OBJECT_SNAPSHOT_CALLBACK taskObjCallbackFunc; @@ -220,8 +221,7 @@ public: void AddOperator(int taskID, int taskOper); int AddOperator(task_param tparam); void callTaskObjInfoCallbackFunc(int objCount, VPT_ObjInfo *obj, int taskFrameCount, int taskId); - //bool AddTask(const char* videoFileName, const char* resultFolderLittle, const char* resultFolder, const char* resultFolderface, bool on_image_display, sy_rect minBoxsize[DETECTTYPE], VIDEO_OBJECT_SNAPSHOT_CALLBACK objCallbackFunc = NULL, VIDEO_REALTIME_CALLBACK realTimeCallbackFunc = NULL); - bool AddTask(const char* videoFileName, const char* resultFolderLittle, const char* resultFolder, const char* resultFolderface, bool on_image_display, int jpeg_quality, sy_rect minBoxsize[DETECTTYPE], VIDEO_OBJECT_SNAPSHOT_CALLBACK objCallbackFunc = NULL, VIDEO_REALTIME_CALLBACK realTimeCallbackFunc = NULL); //debug by zsh + bool AddTask(task_param tparam); void PauseTask(const int taskID); void RestartTask(const int taskID); void FinishTask(const int taskID); diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/header.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/header.h index 2d9f632..65cd06d 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/header.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/header.h @@ -224,18 +224,19 @@ typedef void(*VIDEO_FINISH_CALLBACK)(void * handle, const int task_id); #define __TASK_PARAM__ typedef struct task_param { - const char* video_filename; - const char* result_folder_little; - const char* result_folder; - const char* result_folder_face; + char video_filename[256]; + char result_folder_little[256]; + char result_folder[256]; + char result_folder_face[256]; bool on_image_display; //是否绘制结果框到保存大图 int jpeg_quality; //图片保存质量的参数0-100 --debug by zsh + int decMode; // 解码模式: 0 全解码; 1 关键帧解码 sy_rect minBoxsize[DETECTTYPE]; //自定义的minBoxsize大小 VIDEO_OBJECT_SNAPSHOT_CALLBACK obj_snapshot_callback_func; VIDEO_REALTIME_CALLBACK rt_view_callback_func; //task_param() : video_filename(0), result_folder_little(0), result_folder(0), result_folder_face(0) {} - task_param() : video_filename(0), result_folder_little(0), result_folder(0), result_folder_face(0), jpeg_quality(30) {} //debug by zsh + task_param() : jpeg_quality(30) {} //debug by zsh }task_param; #endif diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/SnapShotFrameCache.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/SnapShotFrameCache.h index 194afb7..c06cdbb 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/SnapShotFrameCache.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/SnapShotFrameCache.h @@ -1,5 +1,5 @@ #pragma once -#include "../DxDecoder/DxDecoderWrap.h" +#include "../FFNvDecoder/DxDecoderWrap.h" #include #define SHOT_CACHE_SIZE #define VEHICLE_WIDTH 320 diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h index 9893359..a585ccc 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h @@ -1,5 +1,5 @@ #include -#include "../../DxDecoder/DxDecoderWrap.h" +#include "../../FFNvDecoder/DxDecoderWrap.h" #include "common.h" #include #include diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp index 787fa58..beefbc1 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp @@ -667,9 +667,45 @@ void videoFinishCallback(void * handle, const int taskID) // } } - +//操作句柄 +void *handle; static int total_index = 0; +void create_task(const char * videoFileName, int total_index) { + //指定检测目标视频抽帧图片(保存时显存占用很大) + char resultFolder[256]; + sprintf(resultFolder, "snapshots/res_0308/%d", total_index); + //指定检测目标快照抠图保存路径 + char resultFolderLittle[256]; + sprintf(resultFolderLittle, "snapshots/resLittle_0308/%d", total_index); + + char resultFolderLittleface[256]; + sprintf(resultFolderLittleface, "snapshots/resLittle_face/%d", total_index); + + task_param tparam; + strcpy(tparam.result_folder, resultFolder); + strcpy(tparam.result_folder_little, resultFolderLittle); + strcpy(tparam.result_folder_face, resultFolderLittleface); + strcpy(tparam.video_filename, videoFileName); + tparam.on_image_display = false; + tparam.jpeg_quality = 30; //debug by zsh + tparam.decMode = 1; // 关键帧解码 + + //tparam.video_filename = argv[total_index%4]; + memcpy(tparam.minBoxsize, m_boxsize, sizeof(sy_rect)* DETECTTYPE); + tparam.rt_view_callback_func = videoRTViewCallback; + tparam.obj_snapshot_callback_func = videoObjSnapshotCallback; + + for (int tmp = 0; tmp < 10; tmp ++) { + string tmp_path = "results/" + vpt_types[tmp]; + CreateResultFolder((char*)tmp_path.c_str(), ""); + } + + int newTaskID = add_task(handle, tparam); + cout << "==============================开始任务ID: " << newTaskID << " ============================" << endl; + cur_task_status_.insert(make_pair(newTaskID, FALSE)); +} + int main(int argc, char* argv[]) { if (argc<4) @@ -680,26 +716,24 @@ int main(int argc, char* argv[]) const char * videoFileName = argv[1]; addTaskCount = atoi(argv[2]); int gpuID = atoi(argv[3]); - //操作句柄 - void *handle; //初始化参数设置 mvpt_param vptParam; - vptParam.hp_analysis_config = SY_CONFIG_CLOSE; - vptParam.hcp_analysis_config = SY_CONFIG_CLOSE; - vptParam.vehicle_analysis_config = SY_CONFIG_CLOSE; - vptParam.hf_recg_config = SY_CONFIG_CLOSE; - vptParam.hcf_recg_config = SY_CONFIG_CLOSE; - vptParam.vcf_recg_config = SY_CONFIG_CLOSE; - vptParam.face_det_config = SY_CONFIG_CLOSE; - - // vptParam.hp_analysis_config = SY_CONFIG_OPEN; - // vptParam.hcp_analysis_config = SY_CONFIG_OPEN; + // vptParam.hp_analysis_config = SY_CONFIG_CLOSE; + // vptParam.hcp_analysis_config = SY_CONFIG_CLOSE; + // vptParam.vehicle_analysis_config = SY_CONFIG_CLOSE; + // vptParam.hf_recg_config = SY_CONFIG_CLOSE; + // vptParam.hcf_recg_config = SY_CONFIG_CLOSE; + // vptParam.vcf_recg_config = SY_CONFIG_CLOSE; + // vptParam.face_det_config = SY_CONFIG_CLOSE; + + vptParam.hp_analysis_config = SY_CONFIG_OPEN; + vptParam.hcp_analysis_config = SY_CONFIG_OPEN; vptParam.vehicle_analysis_config = SY_CONFIG_OPEN; - // vptParam.hf_recg_config = SY_CONFIG_OPEN; - // vptParam.hcf_recg_config = SY_CONFIG_OPEN; - // vptParam.vcf_recg_config = SY_CONFIG_OPEN; - // vptParam.face_det_config = SY_CONFIG_OPEN; + vptParam.hf_recg_config = SY_CONFIG_OPEN; + vptParam.hcf_recg_config = SY_CONFIG_OPEN; + vptParam.vcf_recg_config = SY_CONFIG_OPEN; + vptParam.face_det_config = SY_CONFIG_OPEN; vptParam.vrdbpath = argv[4]; //vptParam.vrdbpath = "../../db/mvpt.bin"; @@ -730,46 +764,23 @@ int main(int argc, char* argv[]) continue; } + // create_task("/home/cmhu/data/video/duan1.avi", total_index); + + // usleep(40000); + + // create_task("/home/cmhu/data/video/Street.uvf", total_index); + for (int i = 0; i < addTaskCount; i++) { - //指定检测目标视频抽帧图片(保存时显存占用很大) - char resultFolder[260]; - sprintf(resultFolder, "snapshots/res_0308/%d", total_index); - //指定检测目标快照抠图保存路径 - char resultFolderLittle[260]; - sprintf(resultFolderLittle, "snapshots/resLittle_0308/%d", total_index); - - char resultFolderLittleface[260]; - sprintf(resultFolderLittleface, "snapshots/resLittle_face/%d", total_index); - - task_param tparam; - tparam.result_folder = resultFolder; - tparam.result_folder_little = resultFolderLittle; - tparam.result_folder_face = resultFolderLittleface; - tparam.video_filename = videoFileName; - tparam.on_image_display = false; - tparam.jpeg_quality = 30; //debug by zsh - - //tparam.video_filename = argv[total_index%4]; - memcpy(tparam.minBoxsize, m_boxsize, sizeof(sy_rect)* DETECTTYPE); - tparam.rt_view_callback_func = videoRTViewCallback; - tparam.obj_snapshot_callback_func = videoObjSnapshotCallback; - - for (int tmp = 0; tmp < 10; tmp ++) { - string tmp_path = "results/" + vpt_types[tmp]; - CreateResultFolder((char*)tmp_path.c_str(), ""); - } + create_task(videoFileName, total_index); + + total_index++ ; - int newTaskID = add_task(handle, tparam); - cout << "==============================开始任务ID: " << newTaskID << " ============================" << endl; - cur_task_status_.insert(make_pair(newTaskID, FALSE)); #ifdef _MSC_VER Sleep(2000); #else usleep(40000); - #endif - - total_index++ ; + #endif } } while(0) ; @@ -843,20 +854,20 @@ int main(int argc, char* argv[]) itor = cur_task_status_.erase(itor); //指定检测目标视频抽帧图片(保存时显存占用很大) - char resultFolder[260]; + char resultFolder[256]; sprintf(resultFolder, "res/%d", total_index); //指定检测目标快照抠图保存路径 - char resultFolderLittle[260]; + char resultFolderLittle[256]; sprintf(resultFolderLittle, "resLittle/%d", total_index); - char resultFolderLittleface[260]; + char resultFolderLittleface[256]; sprintf(resultFolderLittleface, "resLittle_face/%d", total_index++); task_param tparam; - tparam.result_folder = resultFolder; - tparam.result_folder_little = resultFolderLittle; - tparam.result_folder_face = resultFolderLittleface; - tparam.video_filename = videoFileName; + strcpy(tparam.result_folder, resultFolder); + strcpy(tparam.result_folder_little, resultFolderLittle); + strcpy(tparam.result_folder_face, resultFolderLittleface); + strcpy(tparam.video_filename, videoFileName); memcpy(tparam.minBoxsize, m_boxsize, sizeof(sy_rect)* DETECTTYPE); tparam.rt_view_callback_func = videoRTViewCallback; tparam.obj_snapshot_callback_func = videoObjSnapshotCallback;