diff --git a/.vscode/launch.json b/.vscode/launch.json index 1b129be..9ec97c7 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -115,6 +115,25 @@ "ignoreFailures": true } ] + }, + { + "name": "test_xl", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": false, + "cwd": "/home/cmhu/vpt_ascend_arm/build/test", + "program": "/home/cmhu/vpt_ascend_arm/build/test/test", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] } ] } \ No newline at end of file diff --git a/bin/gb28181_cfg.xml b/bin/gb28181_cfg.xml index 0bab184..d2658a6 100644 --- a/bin/gb28181_cfg.xml +++ b/bin/gb28181_cfg.xml @@ -1,7 +1,7 @@ 192.168.60.179 - 9006 + 9007 20000 20400 diff --git a/build/test_xl/Makefile b/build/test_xl/Makefile new file mode 100755 index 0000000..a735316 --- /dev/null +++ b/build/test_xl/Makefile @@ -0,0 +1,38 @@ +XX = g++ + + +PROJECT_ROOT= /home/cmhu/vpt_ascend_arm/build/test_xl + +SRC_ROOT = $(PROJECT_ROOT) + + +TARGET= $(PROJECT_ROOT)/test_xl + + +DEFS = -DENABLE_DVPP_INTERFACE + +include_dir=-I/usr/local/Ascend/ascend-toolkit/latest/aarch64-linux/include \ + + + +LIBS= -L/usr/local/Ascend/ascend-toolkit/latest/runtime/lib64 -lacl_dvpp -lascendcl \ + +CXXFLAGS= -g -O0 -fPIC $(include_dir) $(lib_dir) $(lib) $(LIBS) $(DEFS) -lpthread -lrt -lz -fexceptions -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 -fvisibility=hidden -Wall -Wno-deprecated -Wdeprecated-declarations -Wl,-Bsymbolic -ldl + + + +SRCS:=$(wildcard $(SRC_ROOT)/*.cpp) \ + +OBJS = $(patsubst %.cpp, %.o, $(notdir $(SRCS))) + + +$(TARGET):$(OBJS) + rm -f $(TARGET) + $(XX) -o $@ $^ $(CXXFLAGS) + rm -f *.o + +%.o:$(SRC_ROOT)/%.cpp + $(XX) $(CXXFLAGS) -c $< + +clean: + rm -f *.o $(TARGET) diff --git a/build/test_xl/test b/build/test_xl/test new file mode 100755 index 0000000..30d35f2 --- /dev/null +++ b/build/test_xl/test diff --git a/build/test_xl/test.cpp b/build/test_xl/test.cpp new file mode 100644 index 0000000..63810d4 --- /dev/null +++ b/build/test_xl/test.cpp @@ -0,0 +1,81 @@ +#include +#include + +#include "acl/acl_mdl.h" +#include "acl/acl_base.h" +#include "acl/acl_rt.h" +#include "acl/acl.h" +#include "acl/ops/acl_dvpp.h" +#include "acl/dvpp/hi_dvpp.h" + + +using namespace std; + + +bool test() { + aclrtContext context_{nullptr}; + acldvppChannelDesc *dvppChannelDesc_ {nullptr}; + + aclError ret = aclrtCreateContext(&context_, 0); + if (ret != ACL_ERROR_NONE) { + return false; + } + + do + { + dvppChannelDesc_ = acldvppCreateChannelDesc(); + + ret = acldvppCreateChannel(dvppChannelDesc_); + if (ret != ACL_ERROR_NONE) { + return false; + } + + ret = acldvppSetChannelDescMode(dvppChannelDesc_, DVPP_CHNMODE_VPC); + if (ret != ACL_ERROR_NONE) { + return false; + } + } while (0); + + if(context_){ + aclrtSetCurrentContext(context_); + + if (dvppChannelDesc_) { + (void)acldvppDestroyChannel(dvppChannelDesc_); + (void)acldvppDestroyChannelDesc(dvppChannelDesc_); + dvppChannelDesc_ = nullptr; + } + + aclrtDestroyContext(context_); + } + + printf("end.\n"); + + return true; +} + +int main() { + + printf("start....\n"); + + aclInit(nullptr); + + char ch = 'a'; + while (ch != 'q') { + ch = getchar(); + switch (ch) + { + case 'a': + test(); + break; + case 'c': + test(); + break; + default: + break; + } + } + + aclFinalize(); + + return 0; +} \ No newline at end of file diff --git a/src/decoder/dvpp/DvppDecoder.cpp b/src/decoder/dvpp/DvppDecoder.cpp index 00a60fc..e15d78a 100644 --- a/src/decoder/dvpp/DvppDecoder.cpp +++ b/src/decoder/dvpp/DvppDecoder.cpp @@ -509,7 +509,7 @@ void DvppDecoder::read_thread() { } m_bExitDisplayThd = false; - std::thread display_thread( + std::thread display_thread_( [](void* arg) { DvppDecoder* a=(DvppDecoder*)arg; @@ -649,7 +649,7 @@ void DvppDecoder::read_thread() { CHECK_NOT_RETURN(pthread_join(report_thread, nullptr), "report_thread join failed"); m_bExitDisplayThd = true; - display_thread.join(); + display_thread_.join(); m_recoderManager.close(); diff --git a/src/decoder/dvpp/VpcUtils.cpp b/src/decoder/dvpp/VpcUtils.cpp index 834cdc9..c9d3966 100644 --- a/src/decoder/dvpp/VpcUtils.cpp +++ b/src/decoder/dvpp/VpcUtils.cpp @@ -32,6 +32,8 @@ int VpcUtils::init(int devId){ do { + aclrtCreateStream(&stream_); + dvppChannelDesc_ = acldvppCreateChannelDesc(); ret = acldvppCreateChannel(dvppChannelDesc_); @@ -55,6 +57,11 @@ void VpcUtils::release() { dvppChannelDesc_ = nullptr; } + if(nullptr != stream_){ + aclrtDestroyStream(stream_); + stream_ = nullptr; + } + aclrtDestroyContext(context_); } } @@ -80,8 +87,6 @@ DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, acldvppSetPicDescSize(outputDesc_, out_buf_size); aclError ret = ACL_ERROR_NONE; - aclrtStream stream_{nullptr}; - aclrtCreateStream(&stream_); do{ // 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成 ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_); @@ -96,11 +101,6 @@ DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, } }while(0); - if(nullptr != stream_){ - aclrtDestroyStream(stream_); - stream_ = nullptr; - } - acldvppDestroyPicDesc(outputDesc_); if(ret != ACL_ERROR_NONE){ @@ -145,8 +145,6 @@ DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){ acldvppSetPicDescSize(outputDesc_, out_buf_size); aclError ret = ACL_ERROR_NONE; - aclrtStream stream_{nullptr}; - aclrtCreateStream(&stream_); do{ // 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成 ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_); @@ -161,11 +159,6 @@ DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){ } }while(0); - if(nullptr != stream_){ - aclrtDestroyStream(stream_); - stream_ = nullptr; - } - acldvppDestroyPicDesc(outputDesc_); acldvppDestroyPicDesc(inputDesc_); @@ -200,8 +193,6 @@ DvppDataMemory* VpcUtils::resize(acldvppPicDesc *inputDesc_, int out_width, int acldvppResizeConfig *resizeConfig_ = acldvppCreateResizeConfig(); aclError ret = ACL_ERROR_NONE; - aclrtStream stream_{nullptr}; - aclrtCreateStream(&stream_); do{ // 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成 ret = acldvppVpcResizeAsync(dvppChannelDesc_, inputDesc_, outputDesc_, resizeConfig_, stream_); @@ -216,11 +207,6 @@ DvppDataMemory* VpcUtils::resize(acldvppPicDesc *inputDesc_, int out_width, int } }while(0); - if(nullptr != stream_){ - aclrtDestroyStream(stream_); - stream_ = nullptr; - } - acldvppDestroyResizeConfig(resizeConfig_); acldvppDestroyPicDesc(outputDesc_); diff --git a/src/decoder/dvpp/VpcUtils.h b/src/decoder/dvpp/VpcUtils.h index e7a2e78..dac132f 100644 --- a/src/decoder/dvpp/VpcUtils.h +++ b/src/decoder/dvpp/VpcUtils.h @@ -17,6 +17,7 @@ private: void release(); private: aclrtContext context_{nullptr}; + aclrtStream stream_{nullptr}; int m_devId; acldvppChannelDesc *dvppChannelDesc_ {nullptr}; string m_dec_name; diff --git a/src/demo/demo.cpp b/src/demo/demo.cpp index 25d9178..97d0b3b 100755 --- a/src/demo/demo.cpp +++ b/src/demo/demo.cpp @@ -1237,7 +1237,7 @@ void test_gpu(int gpuID){ // } - // createTask(handle, algor_vec2, 0, false); + createTask(handle, algor_vec2, 0, false); // createTask(handle, algor_vec2, 2, false); // createTask(handle, algor_vec2, 0, false); // createTask(handle, algor_vec2, 2, false); @@ -1347,23 +1347,23 @@ 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); - } + // 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); - } + // 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)); - } + // std::this_thread::sleep_for(std::chrono::seconds(5)); + // } @@ -1426,12 +1426,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"); diff --git a/src/util/vpc_util.cpp b/src/util/vpc_util.cpp index 4423132..a67655a 100755 --- a/src/util/vpc_util.cpp +++ b/src/util/vpc_util.cpp @@ -34,6 +34,11 @@ void VPCUtil::release() aclError ret = acldvppDestroyChannel(dvppChannelDesc_); ret = acldvppDestroyChannelDesc(dvppChannelDesc_); + if (stream_ != nullptr) { + aclrtDestroyStream(stream_); + stream_ = nullptr; + } + ret = aclrtDestroyContext(context_); if (ret != ACL_SUCCESS) { LOG_ERROR("destroy context failed"); @@ -44,6 +49,19 @@ void VPCUtil::release() LOG_INFO("end to reset device is %d", deviceId_); } +int VPCUtil::init(int32_t devId){ + deviceId_ = devId; + + aclError ret; + aclrtCreateContext(&context_, deviceId_); + + aclrtCreateStream(&stream_); + + // channel 准备 + dvppChannelDesc_ = acldvppCreateChannelDesc(); + ret = acldvppCreateChannel(dvppChannelDesc_); +} + static void adjustCoordinate(uint32_t& left, uint32_t& right, uint32_t& top, uint32_t& bottom, const uint32_t& width, const uint32_t& height) { uint32_t cropWidth = right - left; uint32_t cropHeight = bottom - top; @@ -133,8 +151,6 @@ vpc_img_info VPCUtil::crop(DeviceMemory *devMem, video_object_info obj) { acldvppSetPicDescHeightStride(vpcOutputDesc_, cropSizeHeight); acldvppSetPicDescSize(vpcOutputDesc_, vpcOutBufferSize_); - aclrtStream stream_; - aclrtCreateStream(&stream_); bool bRet = false; do { @@ -158,10 +174,6 @@ vpc_img_info VPCUtil::crop(DeviceMemory *devMem, video_object_info obj) { bRet = true; } while (0); - - if (stream_ != nullptr) { - aclrtDestroyStream(stream_); - } acldvppDestroyPicDesc(vpcInputDesc_); @@ -182,17 +194,6 @@ vpc_img_info VPCUtil::crop(DeviceMemory *devMem, video_object_info obj) { return img_info; } -int VPCUtil::init(int32_t devId){ - deviceId_ = devId; - - aclError ret; - aclrtCreateContext(&context_, deviceId_); - - // channel 准备 - dvppChannelDesc_ = acldvppCreateChannelDesc(); - ret = acldvppCreateChannel(dvppChannelDesc_); -} - vector VPCUtil::crop_batch(DeviceMemory *devMem, vector objs){ vector vec_img_info; @@ -294,9 +295,6 @@ vector VPCUtil::crop_batch(DeviceMemory *devMem, vector VPCUtil::crop_batch(DeviceMemory *devMem, vector