diff --git a/src/decoder/dvpp/DvppStreamDecoder.cpp b/src/decoder/dvpp/DvppStreamDecoder.cpp index 5b00f77..03ce395 100644 --- a/src/decoder/dvpp/DvppStreamDecoder.cpp +++ b/src/decoder/dvpp/DvppStreamDecoder.cpp @@ -67,13 +67,7 @@ bool DvppStreamDecoder::Init(FFDecConfig cfg) { m_deviceId = atoi(cfg.gpuid.c_str()); do{ - aclError ret = aclrtSetDevice(m_deviceId); - if(ret != ACL_ERROR_NONE){ - LOG_ERROR("[{}]-aclrtSetDevice failed !", m_dec_name); - return false; - } - - ret = aclrtCreateContext(&m_context, m_deviceId); + aclError ret = aclrtCreateContext(&m_context, m_deviceId); if (ret != ACL_ERROR_NONE) { LOG_ERROR("[{}]-aclrtCreateContext failed !", m_dec_name); return false; @@ -138,15 +132,8 @@ int DvppStreamDecoder::getVdecType(int videoType) void DvppStreamDecoder::doProcessReport(){ - aclError ret = aclrtSetDevice(m_deviceId); - if(ret != ACL_ERROR_NONE){ - // cout << "aclrtSetDevice failed" << endl; - LOG_ERROR("aclrtSetDevice failed !"); - return ; - } - aclrtContext ctx; - ret = aclrtCreateContext(&ctx, m_deviceId); + aclError ret = aclrtCreateContext(&ctx, m_deviceId); if (ret != ACL_ERROR_NONE) { // cout << "aclrtCreateContext failed " << endl; LOG_ERROR("aclrtCreateContext failed !"); diff --git a/src/decoder/dvpp/VpcUtils.cpp b/src/decoder/dvpp/VpcUtils.cpp index bb8e332..834cdc9 100644 --- a/src/decoder/dvpp/VpcUtils.cpp +++ b/src/decoder/dvpp/VpcUtils.cpp @@ -17,30 +17,23 @@ VpcUtils::VpcUtils(){ } VpcUtils::~VpcUtils(){ - if(context_){ - aclrtDestroyContext(context_); - } - - if (dvppChannelDesc_) { - (void)acldvppDestroyChannel(dvppChannelDesc_); - (void)acldvppDestroyChannelDesc(dvppChannelDesc_); - dvppChannelDesc_ = nullptr; - } + release(); } int VpcUtils::init(int devId){ m_devId = devId; - aclrtCreateContext(&context_, m_devId); - - CHECK_AND_RETURN(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed"); - - dvppChannelDesc_ = acldvppCreateChannelDesc(); + aclError ret = aclrtCreateContext(&context_, m_devId); + if (ret != ACL_ERROR_NONE) { + LOG_ERROR("[{}]-aclrtCreateContext failed !", m_dec_name); + return false; + } - int ret = ACL_ERROR_NONE; do { + dvppChannelDesc_ = acldvppCreateChannelDesc(); + ret = acldvppCreateChannel(dvppChannelDesc_); CHECK_AND_BREAK(ret, "acldvppCreateChannel failed !"); @@ -51,6 +44,21 @@ int VpcUtils::init(int devId){ return ret; } +void VpcUtils::release() { + + if(context_){ + aclrtSetCurrentContext(context_); + + if (dvppChannelDesc_) { + (void)acldvppDestroyChannel(dvppChannelDesc_); + (void)acldvppDestroyChannelDesc(dvppChannelDesc_); + dvppChannelDesc_ = nullptr; + } + + aclrtDestroyContext(context_); + } +} + DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, int out_height, bool key_frame){ aclrtSetCurrentContext(context_); diff --git a/src/decoder/dvpp/VpcUtils.h b/src/decoder/dvpp/VpcUtils.h index 2c5e781..e7a2e78 100644 --- a/src/decoder/dvpp/VpcUtils.h +++ b/src/decoder/dvpp/VpcUtils.h @@ -13,7 +13,8 @@ public: DvppDataMemory* convert2bgr(DvppDataMemory* inMem); DvppDataMemory* resize(acldvppPicDesc *inputDesc_, int out_width, int out_height); - +private: + void release(); private: aclrtContext context_{nullptr}; int m_devId; diff --git a/src/decoder/interface/Makefile b/src/decoder/interface/Makefile deleted file mode 100644 index a856501..0000000 --- a/src/decoder/interface/Makefile +++ /dev/null @@ -1,76 +0,0 @@ -# 各项目录 -LIB_DIR:=$(BUILD_DIR)/$(MODULE)/lib -DEP_DIR:=$(BUILD_DIR)/$(MODULE)/.dep -OBJ_DIR:=$(BUILD_DIR)/$(MODULE)/obj -SRC_DIR:=$(TOP_DIR)/$(MODULE) - -# 源文件以及中间目标文件和依赖文件 -SRCS:=$(notdir $(wildcard $(SRC_DIR)/*.cpp)) -OBJS:=$(addprefix $(OBJ_DIR)/, $(patsubst %.cpp, %.o, $(SRCS))) -DEPS:=$(addprefix $(DEP_DIR)/, $(patsubst %.cpp, %.d,a $(SRCS))) - -# 自动生成头文件依赖选项 -DEPFLAGS=-MT $@ -MMD -MP -MF $(DEP_DIR)/$*.d - -JRTP_ROOT = $(THIRDPARTY_ROOT)/jrtp_export - -INCLUDE= -I $(TOP_DIR)/common/inc \ - -I $(TOP_DIR)/common/UtilNPP \ - -I $(TOP_DIR)/ \ - -I $(JRTP_ROOT)/jrtplib/include/jrtplib3 \ - -I $(JRTP_ROOT)/jthread/include/jthread \ - -I $(TOP_DIR)/src/gb28181 \ - -I $(TOP_DIR)/src/nvdec \ - -I $(CUDA_ROOT)/include \ - -LIBSPATH= -L $(JRTP_ROOT)/jthread/lib -l:libjthread.a \ - -L $(JRTP_ROOT)/jrtplib/lib -l:libjrtp.a \ - -L $(CUDA_ROOT)/lib64 -lcuda -lcudart -lnvcuvid -lcurand -lcublas -lnvjpeg \ - - -CXXFLAGS= -g -O0 -fPIC $(INCLUDE) $(LIBSPATH) $(DEFS) -lpthread -lrt -lz -fexceptions -std=c++11 -fvisibility=hidden -Wl,-Bsymbolic -ldl -Wwrite-strings - - -# 最终目标文件 -TARGET:=$(LIB_DIR)/$(MODULE).a - - -# 默认最终目标 -.PHONY:all -all:$(TARGET) - -# 生成最终目标 -$(TARGET):$(OBJS) | $(LIB_DIR) - @echo -e "\e[32m""Linking static library $(TARGET)""\e[0m" - @echo -e "ar -rc $@ $^" - @ar -rc $@ $^ - -# 若没有lib目录则自动生成 -$(LIB_DIR): - @mkdir -p $@ - -# 生成中间目标文件 -$(OBJ_DIR)/%.o:$(SRC_DIR)/%.cpp $(DEP_DIR)/%.d | $(OBJ_DIR) $(DEP_DIR) - @echo -e "\e[33m""Building object $@""\e[0m" - @echo -e "$(CXX) -c $(DEPFLAGS) $(CXXFLAGS) $(INCS) $(LIBS) $(MACROS) -o $@ $<" -# @$(CXX) -c $(DEPFLAGS) $(CXXFLAGS) $(INCS) $(LIBSPATH) $(MACROS) -o $@ $(MODULE_LIBS) $< - @$(CXX) -c $(DEPFLAGS) $(CXXFLAGS) $(INCS) $(LIBS) $(MACROS) -o $@ $< - -# 若没有obj目录则自动生成 -$(OBJ_DIR): - @mkdir -p $@ - -# 若没有.dep目录则自动生成 -$(DEP_DIR): - @mkdir -p $@ - -# 依赖文件会在生成中间文件的时候自动生成,这里只是为了防止报错 -$(DEPS): - -# 引入中间目标文件头文件依赖关系 -include $(wildcard $(DEPS)) - -# 直接删除组件build目录 -.PHONY:clean -clean: - @rm -rf $(BUILD_DIR)/$(MODULE) diff --git a/src/demo/demo.cpp b/src/demo/demo.cpp index 022e4ad..9e535a6 100755 --- a/src/demo/demo.cpp +++ b/src/demo/demo.cpp @@ -1,5 +1,6 @@ #include "../ai_platform/stl_aiplatform.h" #include +#include #include #include #include @@ -1330,6 +1331,26 @@ init_mq_conn(handle); + int status = -1; + while (true) + { + status = get_task_status(handle,"34020000001320000207"); + if (status == 0) + { + createTask_dvpp28181(handle, algor_vec, 4, false); + } + + status = get_task_status(handle,"34020000001310000176"); + if (status == 0) + { + createTask_dvpp28181(handle, algor_vec, 5, false); + } + + std::this_thread::sleep_for(std::chrono::seconds(5)); + } + + + char ch = 'a'; while (ch != 'q') { ch = getchar(); @@ -1389,12 +1410,12 @@ int main(int argc, char *argv[]) { // int repeat_num = atoi(argv[3]); // int gpuID = atoi(argv[4]); - test_gpu(0); + // test_gpu(0); // test_gpu(1); // test_gpu(2); // test_gpu(3); - // test_dvpp28181(0); + test_dvpp28181(0); printf("Done.\n");