Commit 44a5c5b02ab3d878b7da5a25a8e2186ece032f04

Authored by Hu Chunming
1 parent edde45f5

优化stream_

.vscode/launch.json
... ... @@ -115,6 +115,25 @@
115 115 "ignoreFailures": true
116 116 }
117 117 ]
  118 + },
  119 + {
  120 + "name": "test_xl",
  121 + "type": "cppdbg",
  122 + "request": "launch",
  123 + "args": [],
  124 + "stopAtEntry": false,
  125 + "externalConsole": false,
  126 + "cwd": "/home/cmhu/vpt_ascend_arm/build/test",
  127 + "program": "/home/cmhu/vpt_ascend_arm/build/test/test",
  128 + "MIMode": "gdb",
  129 + "miDebuggerPath": "gdb",
  130 + "setupCommands": [
  131 + {
  132 + "description": "Enable pretty-printing for gdb",
  133 + "text": "-enable-pretty-printing",
  134 + "ignoreFailures": true
  135 + }
  136 + ]
118 137 }
119 138 ]
120 139 }
121 140 \ No newline at end of file
... ...
bin/gb28181_cfg.xml
1 1 <?xml version="1.0" encoding="GB2312"?>
2 2 <ROOT>
3 3 <WsIP>192.168.60.179</WsIP>
4   - <WsPort>9006</WsPort>
  4 + <WsPort>9007</WsPort>
5 5 <MinRtpPort>20000</MinRtpPort>
6 6 <MaxRtpPort>20400</MaxRtpPort>
7 7 </ROOT>
... ...
build/test_xl/Makefile 0 → 100755
  1 +XX = g++
  2 +
  3 +
  4 +PROJECT_ROOT= /home/cmhu/vpt_ascend_arm/build/test_xl
  5 +
  6 +SRC_ROOT = $(PROJECT_ROOT)
  7 +
  8 +
  9 +TARGET= $(PROJECT_ROOT)/test_xl
  10 +
  11 +
  12 +DEFS = -DENABLE_DVPP_INTERFACE
  13 +
  14 +include_dir=-I/usr/local/Ascend/ascend-toolkit/latest/aarch64-linux/include \
  15 +
  16 +
  17 +
  18 +LIBS= -L/usr/local/Ascend/ascend-toolkit/latest/runtime/lib64 -lacl_dvpp -lascendcl \
  19 +
  20 +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
  21 +
  22 +
  23 +
  24 +SRCS:=$(wildcard $(SRC_ROOT)/*.cpp) \
  25 +
  26 +OBJS = $(patsubst %.cpp, %.o, $(notdir $(SRCS)))
  27 +
  28 +
  29 +$(TARGET):$(OBJS)
  30 + rm -f $(TARGET)
  31 + $(XX) -o $@ $^ $(CXXFLAGS)
  32 + rm -f *.o
  33 +
  34 +%.o:$(SRC_ROOT)/%.cpp
  35 + $(XX) $(CXXFLAGS) -c $<
  36 +
  37 +clean:
  38 + rm -f *.o $(TARGET)
... ...
build/test_xl/test 0 → 100755
No preview for this file type
build/test_xl/test.cpp 0 → 100644
  1 +#include <iostream>
  2 +#include <string>
  3 +
  4 +#include "acl/acl_mdl.h"
  5 +#include "acl/acl_base.h"
  6 +#include "acl/acl_rt.h"
  7 +#include "acl/acl.h"
  8 +#include "acl/ops/acl_dvpp.h"
  9 +#include "acl/dvpp/hi_dvpp.h"
  10 +
  11 +
  12 +using namespace std;
  13 +
  14 +
  15 +bool test() {
  16 + aclrtContext context_{nullptr};
  17 + acldvppChannelDesc *dvppChannelDesc_ {nullptr};
  18 +
  19 + aclError ret = aclrtCreateContext(&context_, 0);
  20 + if (ret != ACL_ERROR_NONE) {
  21 + return false;
  22 + }
  23 +
  24 + do
  25 + {
  26 + dvppChannelDesc_ = acldvppCreateChannelDesc();
  27 +
  28 + ret = acldvppCreateChannel(dvppChannelDesc_);
  29 + if (ret != ACL_ERROR_NONE) {
  30 + return false;
  31 + }
  32 +
  33 + ret = acldvppSetChannelDescMode(dvppChannelDesc_, DVPP_CHNMODE_VPC);
  34 + if (ret != ACL_ERROR_NONE) {
  35 + return false;
  36 + }
  37 + } while (0);
  38 +
  39 + if(context_){
  40 + aclrtSetCurrentContext(context_);
  41 +
  42 + if (dvppChannelDesc_) {
  43 + (void)acldvppDestroyChannel(dvppChannelDesc_);
  44 + (void)acldvppDestroyChannelDesc(dvppChannelDesc_);
  45 + dvppChannelDesc_ = nullptr;
  46 + }
  47 +
  48 + aclrtDestroyContext(context_);
  49 + }
  50 +
  51 + printf("end.\n");
  52 +
  53 + return true;
  54 +}
  55 +
  56 +int main() {
  57 +
  58 + printf("start....\n");
  59 +
  60 + aclInit(nullptr);
  61 +
  62 + char ch = 'a';
  63 + while (ch != 'q') {
  64 + ch = getchar();
  65 + switch (ch)
  66 + {
  67 + case 'a':
  68 + test();
  69 + break;
  70 + case 'c':
  71 + test();
  72 + break;
  73 + default:
  74 + break;
  75 + }
  76 + }
  77 +
  78 + aclFinalize();
  79 +
  80 + return 0;
  81 +}
0 82 \ No newline at end of file
... ...
src/decoder/dvpp/DvppDecoder.cpp
... ... @@ -509,7 +509,7 @@ void DvppDecoder::read_thread() {
509 509 }
510 510  
511 511 m_bExitDisplayThd = false;
512   - std::thread display_thread(
  512 + std::thread display_thread_(
513 513 [](void* arg)
514 514 {
515 515 DvppDecoder* a=(DvppDecoder*)arg;
... ... @@ -649,7 +649,7 @@ void DvppDecoder::read_thread() {
649 649 CHECK_NOT_RETURN(pthread_join(report_thread, nullptr), "report_thread join failed");
650 650  
651 651 m_bExitDisplayThd = true;
652   - display_thread.join();
  652 + display_thread_.join();
653 653  
654 654 m_recoderManager.close();
655 655  
... ...
src/decoder/dvpp/VpcUtils.cpp
... ... @@ -32,6 +32,8 @@ int VpcUtils::init(int devId){
32 32  
33 33 do
34 34 {
  35 + aclrtCreateStream(&stream_);
  36 +
35 37 dvppChannelDesc_ = acldvppCreateChannelDesc();
36 38  
37 39 ret = acldvppCreateChannel(dvppChannelDesc_);
... ... @@ -55,6 +57,11 @@ void VpcUtils::release() {
55 57 dvppChannelDesc_ = nullptr;
56 58 }
57 59  
  60 + if(nullptr != stream_){
  61 + aclrtDestroyStream(stream_);
  62 + stream_ = nullptr;
  63 + }
  64 +
58 65 aclrtDestroyContext(context_);
59 66 }
60 67 }
... ... @@ -80,8 +87,6 @@ DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width,
80 87 acldvppSetPicDescSize(outputDesc_, out_buf_size);
81 88  
82 89 aclError ret = ACL_ERROR_NONE;
83   - aclrtStream stream_{nullptr};
84   - aclrtCreateStream(&stream_);
85 90 do{
86 91 // 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
87 92 ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_);
... ... @@ -96,11 +101,6 @@ DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width,
96 101 }
97 102 }while(0);
98 103  
99   - if(nullptr != stream_){
100   - aclrtDestroyStream(stream_);
101   - stream_ = nullptr;
102   - }
103   -
104 104 acldvppDestroyPicDesc(outputDesc_);
105 105  
106 106 if(ret != ACL_ERROR_NONE){
... ... @@ -145,8 +145,6 @@ DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){
145 145 acldvppSetPicDescSize(outputDesc_, out_buf_size);
146 146  
147 147 aclError ret = ACL_ERROR_NONE;
148   - aclrtStream stream_{nullptr};
149   - aclrtCreateStream(&stream_);
150 148 do{
151 149 // 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
152 150 ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_);
... ... @@ -161,11 +159,6 @@ DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){
161 159 }
162 160 }while(0);
163 161  
164   - if(nullptr != stream_){
165   - aclrtDestroyStream(stream_);
166   - stream_ = nullptr;
167   - }
168   -
169 162 acldvppDestroyPicDesc(outputDesc_);
170 163 acldvppDestroyPicDesc(inputDesc_);
171 164  
... ... @@ -200,8 +193,6 @@ DvppDataMemory* VpcUtils::resize(acldvppPicDesc *inputDesc_, int out_width, int
200 193 acldvppResizeConfig *resizeConfig_ = acldvppCreateResizeConfig();
201 194  
202 195 aclError ret = ACL_ERROR_NONE;
203   - aclrtStream stream_{nullptr};
204   - aclrtCreateStream(&stream_);
205 196 do{
206 197 // 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
207 198 ret = acldvppVpcResizeAsync(dvppChannelDesc_, inputDesc_, outputDesc_, resizeConfig_, stream_);
... ... @@ -216,11 +207,6 @@ DvppDataMemory* VpcUtils::resize(acldvppPicDesc *inputDesc_, int out_width, int
216 207 }
217 208 }while(0);
218 209  
219   - if(nullptr != stream_){
220   - aclrtDestroyStream(stream_);
221   - stream_ = nullptr;
222   - }
223   -
224 210 acldvppDestroyResizeConfig(resizeConfig_);
225 211 acldvppDestroyPicDesc(outputDesc_);
226 212  
... ...
src/decoder/dvpp/VpcUtils.h
... ... @@ -17,6 +17,7 @@ private:
17 17 void release();
18 18 private:
19 19 aclrtContext context_{nullptr};
  20 + aclrtStream stream_{nullptr};
20 21 int m_devId;
21 22 acldvppChannelDesc *dvppChannelDesc_ {nullptr};
22 23 string m_dec_name;
... ...
src/demo/demo.cpp
... ... @@ -1237,7 +1237,7 @@ void test_gpu(int gpuID){
1237 1237  
1238 1238 // }
1239 1239  
1240   - // createTask(handle, algor_vec2, 0, false);
  1240 + createTask(handle, algor_vec2, 0, false);
1241 1241 // createTask(handle, algor_vec2, 2, false);
1242 1242 // createTask(handle, algor_vec2, 0, false);
1243 1243 // createTask(handle, algor_vec2, 2, false);
... ... @@ -1347,23 +1347,23 @@ init_mq_conn(handle);
1347 1347  
1348 1348  
1349 1349  
1350   - int status = -1;
1351   - while (true)
1352   - {
1353   - status = get_task_status(handle,"34020000001320000207");
1354   - if (status == 0)
1355   - {
1356   - createTask_dvpp28181(handle, algor_vec, 4, false);
1357   - }
  1350 + // int status = -1;
  1351 + // while (true)
  1352 + // {
  1353 + // status = get_task_status(handle,"34020000001320000207");
  1354 + // if (status == 0)
  1355 + // {
  1356 + // createTask_dvpp28181(handle, algor_vec, 4, false);
  1357 + // }
1358 1358  
1359   - status = get_task_status(handle,"34020000001310000176");
1360   - if (status == 0)
1361   - {
1362   - createTask_dvpp28181(handle, algor_vec, 5, false);
1363   - }
  1359 + // status = get_task_status(handle,"34020000001310000176");
  1360 + // if (status == 0)
  1361 + // {
  1362 + // createTask_dvpp28181(handle, algor_vec, 5, false);
  1363 + // }
1364 1364  
1365   - std::this_thread::sleep_for(std::chrono::seconds(5));
1366   - }
  1365 + // std::this_thread::sleep_for(std::chrono::seconds(5));
  1366 + // }
1367 1367  
1368 1368  
1369 1369  
... ... @@ -1426,12 +1426,12 @@ int main(int argc, char *argv[]) {
1426 1426 // int repeat_num = atoi(argv[3]);
1427 1427 // int gpuID = atoi(argv[4]);
1428 1428  
1429   - test_gpu(0);
  1429 + // test_gpu(0);
1430 1430 // test_gpu(1);
1431 1431 // test_gpu(2);
1432 1432 // test_gpu(3);
1433 1433  
1434   - // test_dvpp28181(0);
  1434 + test_dvpp28181(0);
1435 1435  
1436 1436 printf("Done.\n");
1437 1437  
... ...
src/util/vpc_util.cpp
... ... @@ -34,6 +34,11 @@ void VPCUtil::release()
34 34 aclError ret = acldvppDestroyChannel(dvppChannelDesc_);
35 35 ret = acldvppDestroyChannelDesc(dvppChannelDesc_);
36 36  
  37 + if (stream_ != nullptr) {
  38 + aclrtDestroyStream(stream_);
  39 + stream_ = nullptr;
  40 + }
  41 +
37 42 ret = aclrtDestroyContext(context_);
38 43 if (ret != ACL_SUCCESS) {
39 44 LOG_ERROR("destroy context failed");
... ... @@ -44,6 +49,19 @@ void VPCUtil::release()
44 49 LOG_INFO("end to reset device is %d", deviceId_);
45 50 }
46 51  
  52 +int VPCUtil::init(int32_t devId){
  53 + deviceId_ = devId;
  54 +
  55 + aclError ret;
  56 + aclrtCreateContext(&context_, deviceId_);
  57 +
  58 + aclrtCreateStream(&stream_);
  59 +
  60 + // channel 准备
  61 + dvppChannelDesc_ = acldvppCreateChannelDesc();
  62 + ret = acldvppCreateChannel(dvppChannelDesc_);
  63 +}
  64 +
47 65 static void adjustCoordinate(uint32_t& left, uint32_t& right, uint32_t& top, uint32_t& bottom, const uint32_t& width, const uint32_t& height) {
48 66 uint32_t cropWidth = right - left;
49 67 uint32_t cropHeight = bottom - top;
... ... @@ -133,8 +151,6 @@ vpc_img_info VPCUtil::crop(DeviceMemory *devMem, video_object_info obj) {
133 151 acldvppSetPicDescHeightStride(vpcOutputDesc_, cropSizeHeight);
134 152 acldvppSetPicDescSize(vpcOutputDesc_, vpcOutBufferSize_);
135 153  
136   - aclrtStream stream_;
137   - aclrtCreateStream(&stream_);
138 154 bool bRet = false;
139 155 do
140 156 {
... ... @@ -158,10 +174,6 @@ vpc_img_info VPCUtil::crop(DeviceMemory *devMem, video_object_info obj) {
158 174  
159 175 bRet = true;
160 176 } while (0);
161   -
162   - if (stream_ != nullptr) {
163   - aclrtDestroyStream(stream_);
164   - }
165 177  
166 178 acldvppDestroyPicDesc(vpcInputDesc_);
167 179  
... ... @@ -182,17 +194,6 @@ vpc_img_info VPCUtil::crop(DeviceMemory *devMem, video_object_info obj) {
182 194 return img_info;
183 195 }
184 196  
185   -int VPCUtil::init(int32_t devId){
186   - deviceId_ = devId;
187   -
188   - aclError ret;
189   - aclrtCreateContext(&context_, deviceId_);
190   -
191   - // channel 准备
192   - dvppChannelDesc_ = acldvppCreateChannelDesc();
193   - ret = acldvppCreateChannel(dvppChannelDesc_);
194   -}
195   -
196 197 vector<vpc_img_info> VPCUtil::crop_batch(DeviceMemory *devMem, vector<video_object_info> objs){
197 198  
198 199 vector<vpc_img_info> vec_img_info;
... ... @@ -294,9 +295,6 @@ vector&lt;vpc_img_info&gt; VPCUtil::crop_batch(DeviceMemory *devMem, vector&lt;video_obje
294 295 (void)acldvppSetPicDescSize(vpcOutputDesc, vpcOutBufferSize_);
295 296 }
296 297  
297   - aclrtStream stream_;
298   - aclrtCreateStream(&stream_);
299   -
300 298 bool bRet = false;
301 299 do {
302 300 uint32_t roiNums[] = { outputBatchSize_ };
... ... @@ -348,12 +346,6 @@ vector&lt;vpc_img_info&gt; VPCUtil::crop_batch(DeviceMemory *devMem, vector&lt;video_obje
348 346  
349 347 bRet = true;
350 348 } while (0);
351   -
352   - if (stream_ != nullptr) {
353   - aclrtDestroyStream(stream_);
354   - }
355   -
356   - aclrtSetCurrentContext(context_);
357 349  
358 350 if (vpcInputBatchDesc_ != nullptr) {
359 351 (void)acldvppDestroyBatchPicDesc(vpcInputBatchDesc_);
... ...
src/util/vpc_util.h
... ... @@ -58,6 +58,7 @@ public:
58 58 private:
59 59 int32_t deviceId_;
60 60 aclrtContext context_;
  61 + aclrtStream stream_;
61 62  
62 63 acldvppChannelDesc *dvppChannelDesc_;
63 64 };
... ...