Commit ffd1e48aeaf21953e2f98a9d9a9e978522587864

Authored by Hu Chunming
1 parent d5345ee9

实现结果回调,完成第一版

src/ai_platform/header.h
... ... @@ -136,6 +136,8 @@ enum ai_log_level {
136 136 };
137 137  
138 138  
  139 +typedef void(*ResultData_CALLBACK)(ObjectData obj);
  140 +
139 141 //VPT初始化参数
140 142 typedef struct tsl_aiplatform_param {
141 143 int gpuid; //指定显卡id
... ... @@ -145,6 +147,8 @@ typedef struct tsl_aiplatform_param {
145 147 char *log_path; //日志文件路径
146 148 int log_days; //日志保存周期
147 149 double log_mem; //每个日志最大大小
  150 +
  151 + ResultData_CALLBACK result_cbk;
148 152 } tsl_aiplatform_param;
149 153  
150 154 #endif // __AI_PLATFORM_HEADER__
151 155 \ No newline at end of file
... ...
src/ai_platform/mvpt.cpp
... ... @@ -92,6 +92,8 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){
92 92  
93 93 m_devId = vptParam.gpuid;
94 94  
  95 + m_result_cbk = vptParam.result_cbk;
  96 +
95 97 string models_dir = vptParam.models_dir;
96 98  
97 99 VPTProcess_PARAM vparam;
... ... @@ -536,7 +538,7 @@ void CMultiSourceProcess::vehicle_locus_finished(const OBJ_KEY obj_key) {
536 538  
537 539 TaskInfo* info = m_task_manager.GetTaskInfo(obj_key.video_id);
538 540  
539   - string result_folder = info->result_folder + "/snapshot";//todo
  541 + string result_folder = info->result_folder + "/snapshot";
540 542 string result_folder_little = info->result_folder_little + "/snapshot_lite";
541 543  
542 544 if (!result_folder.empty()) {
... ... @@ -578,7 +580,7 @@ void CMultiSourceProcess::vehicle_locus_finished(const OBJ_KEY obj_key) {
578 580 bool bSaved = save_obj_pic(res_obj);
579 581 if (bSaved)
580 582 {
581   - // todo 回调函数抛出结果给上层
  583 + m_result_cbk(res_obj);
582 584 }
583 585  
584 586 m_snapshot_reprocessing->release_finished_locus_snapshot(obj_key.video_id, obj_key.obj_id, true);
... ...
src/ai_platform/mvpt.h
... ... @@ -92,6 +92,8 @@ private:
92 92  
93 93 JpegUtil jpegUtil;
94 94  
  95 + ResultData_CALLBACK m_result_cbk;
  96 +
95 97 void *skt_handle = nullptr;//授权
96 98 atlas_licence_check_param check_param;//授权
97 99 int check_label{-1};//授权 -1=未授权 0=授权 1=授权check日已经check成功(每月一次check)
... ...
src/ai_platform/mvpt_process_assist.h
... ... @@ -30,7 +30,6 @@ bool LegalArea(int maxArea, int lastArea, int left, int top, int right, int bott
30 30 bool LegalMinArea(int width, int height, sy_rect min_box);
31 31 void ExpandMargin(int direction_x, int direction_y, int boundary_w, int boundary_h,
32 32 int &boundary_left, int &boundary_right, int &boundary_top, int &boundary_bottom);
33   -void CreateResultFolder(char* resultFolder, const char* jointFolder);
34 33  
35 34 bool snapshot_legal_inarea(int width, int height);
36 35 bool snapshot_legal_inarea(sy_rect algor_area, int left, int top, int right, int bottom);
... ...
src/ai_platform/vpt_proj.cpp1 deleted
1   -#include <iostream>
2   -#include <string>
3   -#include <queue>
4   -#include <mutex>
5   -#include <chrono>
6   -#include <thread>
7   -
8   -#include "vpt.h"
9   -
10   -#include "acl/acl.h"
11   -#include "acl/ops/acl_dvpp.h"
12   -
13   -#include "../decoder/interface/DecoderManager.h"
14   -#include "../decoder/interface/utiltools.hpp"
15   -
16   -using namespace std;
17   -
18   -#define ACL_CALL(ret, expect, errCode)\
19   - do {\
20   - if (ret != expect) {\
21   - if (errCode == 0)\
22   - return ret;\
23   - else\
24   - return errCode;\
25   - }\
26   - } while(0)
27   -
28   -
29   -string test_uri = "/home/huchunming/data/caishenkezhan.mp4";
30   -
31   -queue<DeviceMemory*> memQueue;
32   -mutex mem_mutex;
33   -
34   -static void postDecoded(const void * userPtr, DeviceMemory* devFrame){
35   - AbstractDecoder* decoder = (AbstractDecoder*)userPtr;
36   - if (decoder!= nullptr)
37   - {
38   - }
39   -
40   - std::lock_guard<std::mutex> l(mem_mutex);
41   - memQueue.push(devFrame);
42   -
43   - // if(devFrame){
44   - // delete devFrame;
45   - // devFrame = nullptr;
46   - // }
47   -}
48   -
49   -static void decode_finished_cbk(const void* userPtr){
50   - cout << "当前时间戳: " << UtilTools::get_cur_time_ms() << endl;
51   -}
52   -
53   -static void createDvppDecoder(int index, char* devId){
54   - DecoderManager* pDecManager = DecoderManager::getInstance();
55   - MgrDecConfig config;
56   - config.name = "dec" + to_string(index);
57   - config.cfg.uri = test_uri;
58   - config.cfg.post_decoded_cbk = postDecoded;
59   - config.cfg.decode_finished_cbk = decode_finished_cbk;
60   - config.cfg.force_tcp = true;
61   - config.dec_type = DECODER_TYPE_DVPP;
62   -
63   - config.cfg.gpuid = devId;
64   -
65   - AbstractDecoder* decoder = pDecManager->createDecoder(config);
66   - if (!decoder)
67   - {
68   - cout << "创建解码器失败" << endl;
69   - return ;
70   - }
71   - pDecManager->setPostDecArg(config.name, decoder);
72   - pDecManager->setFinishedDecArg(config.name, decoder);
73   - pDecManager->startDecodeByName(config.name);
74   -}
75   -
76   -
77   -int main(){
78   - cout << vpt_get_version() << endl;
79   -
80   - vpt_param param;
81   -
82   - // param.modelNames = "vtp0716x.om";
83   - param.modelNames = "../models/vpt0715_310p.om";
84   - param.threshold = 0.4;
85   - param.devId = 0;
86   - param.isTrk = false;
87   -
88   - ACL_CALL(aclInit(nullptr), ACL_ERROR_NONE, 1);
89   - ACL_CALL(aclrtSetDevice(param.devId), ACL_ERROR_NONE, 1);
90   - aclrtContext ctx;
91   - ACL_CALL(aclrtCreateContext(&ctx, param.devId), ACL_ERROR_NONE, 1);
92   -
93   - void* handle = nullptr;
94   - int ret = vpt_init(&handle, param);
95   - if(ret != 0){
96   - printf("init error \n");
97   - return -1;
98   - }
99   -
100   - createDvppDecoder(0,"0");
101   -
102   - DecoderManager* pDecManager = DecoderManager::getInstance();
103   - const int batchsize = 1;
104   - int index = 0;
105   - while (pDecManager->isRunning("dec0"))
106   - {
107   - if(index > 30){
108   - break;
109   - }
110   - if(memQueue.size() <= 0){
111   - std::this_thread::sleep_for(std::chrono::milliseconds(10));
112   - continue;
113   - }
114   -
115   - vector<DeviceMemory*> vec_mem;
116   -
117   - vector<sy_img> imgs;
118   -
119   - std::lock_guard<std::mutex> l(mem_mutex);
120   - for (int b = 0; b < batchsize; b++) {
121   - DeviceMemory* mem = memQueue.front();
122   - sy_img img;
123   - img.w_ = mem->getWidth();
124   - img.h_ = mem->getHeight();
125   - img.data_ = mem->getMem();
126   - imgs.push_back(img);
127   - vec_mem.push_back(mem);
128   - memQueue.pop();
129   - }
130   -
131   - if(vec_mem.size() <= 0){
132   - std::this_thread::sleep_for(std::chrono::milliseconds(3));
133   - continue;
134   - }
135   -
136   - ACL_CALL(aclrtSetCurrentContext(ctx), ACL_ERROR_NONE, 1);
137   - vpt_result* results;
138   - int ret = vpt_batch(handle, imgs.data(), imgs.size(), &results);
139   -
140   - for(int batchIdx = 0; batchIdx < batchsize; batchIdx ++){
141   - printf("debug det num:%d\n",results[batchIdx].obj_count_);
142   - }
143   -
144   - for(int i=0;i < vec_mem.size(); i++){
145   - DeviceMemory* mem = vec_mem[i];
146   - delete mem;
147   - mem = nullptr;
148   - }
149   - vec_mem.clear();
150   -
151   - index ++;
152   - }
153   -
154   - pDecManager->closeDecoderByName("dec0");
155   -
156   - pDecManager->closeAllDecoder();
157   -
158   - ret = aclrtDestroyContext(ctx);
159   - if(ret != ACL_ERROR_NONE){
160   - printf("aclrtDestroyContext failed ! \n");
161   - }
162   -
163   -
164   -
165   - aclFinalize();
166   -}
167 0 \ No newline at end of file
src/demo/demo.cpp
... ... @@ -5,6 +5,7 @@
5 5 #include <string.h>
6 6 #include <stdlib.h>
7 7 #include <unistd.h>
  8 +#include <iostream>
8 9  
9 10 using namespace std;
10 11  
... ... @@ -154,19 +155,10 @@ string createTask(void *handle, int gi, bool bFlag = true){
154 155 return task_id_str;
155 156 }
156 157  
157   -
158   -// void test_snapshot(void *handle){
159   -// task_param tparam;
160   -// tparam.ipc_url = "rtsp://admin:ad123456@192.168.60.165:554/cam/realmonitor?channel=1&subtype=0";
161   -// std::string task_id_str = "test_task_id_default" ;
162   -// tparam.task_id = task_id_str.c_str();
163   -
164   -
165   -// const int result_code = screenshot_task(handle, tparam);
166   -// if (result_code != 0)
167   -// printf("[Error]: ");
168   -// printf("--- task_id: %s result code: %d\n", tparam.task_id, result_code);
169   -// }
  158 +void show_result(ObjectData obj)
  159 +{
  160 + cout << obj.index << endl;
  161 +}
170 162  
171 163 void test_gpu(int gpuID){
172 164 tsl_aiplatform_param vptParam;
... ... @@ -179,6 +171,8 @@ void test_gpu(int gpuID){
179 171 vptParam.log_mem = 64 * 1024 * 1024; // 64MB.
180 172 vptParam.log_path = "logs/main.log";
181 173  
  174 + vptParam.result_cbk = show_result;
  175 +
182 176 void *handle;
183 177 int flag = tsl_aiplatform_init(&handle, vptParam);
184 178 if (0 != flag) {
... ...