Commit 9e3f3176e70e79ded15912019cbefa1507496b31

Authored by Hu Chunming
1 parent 95ee08f6

修复关闭任务崩溃的问题

src/ai_platform/det_obj_header.h
... ... @@ -10,6 +10,8 @@
10 10 #include <set>
11 11 #include <bitset>
12 12  
  13 +#include "sy_common.h"
  14 +
13 15 #include "../util/vpc_util.h"
14 16  
15 17 using namespace std;
... ...
src/ai_platform/header.h
... ... @@ -9,7 +9,7 @@
9 9  
10 10 #endif
11 11  
12   -#include "sy_common.h"
  12 +
13 13 #include <map>
14 14 #include <vector>
15 15 #include <string>
... ...
src/ai_platform/mvpt.cpp
... ... @@ -245,7 +245,7 @@ bool CMultiSourceProcess::RestartTask(const string taskID){
245 245 }
246 246  
247 247 bool CMultiSourceProcess::FinishTask(const string taskID){
248   - return m_task_manager.FinishTask(taskID);
  248 + return m_task_manager.CloseDecoder(taskID);
249 249 }
250 250  
251 251 int CMultiSourceProcess::snapshot_task(std::string& uri_or_name, const std::string& file_name, bool bInTask) {
... ... @@ -290,13 +290,13 @@ int CMultiSourceProcess::snapshot_task(std::string&amp; uri_or_name, const std::stri
290 290 return FAILED;
291 291 }
292 292  
293   -int CMultiSourceProcess::SnapShot(task_param _cur_task_param, char* result_folder)
  293 +int CMultiSourceProcess::SnapShot(task_param _cur_task_param, string result_folder)
294 294 {
295 295 LOG_INFO("begin SnapShot task: {}", _cur_task_param.task_id);
296 296  
297 297 /* 拷贝通用的算法参数 */
298   - if (result_folder) {
299   - CreateResultFolder(result_folder, "");
  298 + if (!result_folder.empty()) {
  299 + CreateResultFolder(result_folder.c_str(), "");
300 300 } else {
301 301 result_folder = "";
302 302 }
... ... @@ -321,10 +321,19 @@ int CMultiSourceProcess::SnapShot(task_param _cur_task_param, char* result_folde
321 321 }
322 322  
323 323 void CMultiSourceProcess::CloseAllTask(){
324   - m_bfinish = true;
  324 + m_task_manager.CloseAllDecoder();
  325 +}
  326 +
  327 +void CMultiSourceProcess::Release() {
  328 +
325 329 atlas_licence_close(&(skt_handle)); //授权
326 330  
327   - m_task_manager.Release();
  331 + m_task_manager.CloseAllDecoder();
  332 + while (m_task_manager.GetRunningTaskCount() > 0) {
  333 + std::this_thread::sleep_for(std::chrono::milliseconds(100));
  334 + }
  335 +
  336 + m_bfinish = true;
328 337  
329 338 if(m_pAlgorthimThread){
330 339 m_pAlgorthimThread->join();
... ... @@ -342,14 +351,12 @@ void CMultiSourceProcess::CloseAllTask(){
342 351  
343 352 int size = m_RgbDataList.size();
344 353 bool bEmpty = m_RgbDataList.empty();
  354 +
  355 + m_task_manager.Release();
345 356  
346 357 LOG_INFO("CloseAllTask exit.");
347 358 }
348 359  
349   -void CMultiSourceProcess::CloseAllTask2() {
350   - m_task_manager.Release();
351   -}
352   -
353 360 void CMultiSourceProcess::clear_finished_task(){// 清理已经结束的任务
354 361  
355 362 std::lock_guard<std::mutex> l1(m_FinishedTaskMtx);
... ... @@ -389,6 +396,15 @@ bool CMultiSourceProcess::finish_task(const string taskID, const bool delete_sna
389 396  
390 397 m_snapshot_reprocessing->release_finished_locus_snapshot(taskID);
391 398  
  399 + m_task_manager.FinishTask(taskID);
  400 +
  401 + for (auto iter = m_RgbDataList.begin(); iter!=m_RgbDataList.end(); ++ iter){
  402 + DeviceMemory* gpuMem = *iter;
  403 + if(taskID == gpuMem->getId()){
  404 + m_RgbDataList.erase(iter);
  405 + }
  406 + }
  407 +
392 408 return true;
393 409 }
394 410  
... ...
src/ai_platform/mvpt.h
... ... @@ -34,12 +34,11 @@ public:
34 34 bool PauseTask(const string taskID);
35 35 bool RestartTask(const string taskID);
36 36 bool FinishTask(const string taskID);
  37 + void Release();
37 38 void CloseAllTask();
38   - int SnapShot(task_param param, char* result_folder);
  39 + int SnapShot(task_param param, string result_folder);
39 40 int CountRunningTask();
40 41  
41   - void CloseAllTask2();
42   -
43 42 int GetTaskStatus(const string taskID);
44 43  
45 44 public:
... ...
src/ai_platform/stl_aiplatform.cpp
... ... @@ -17,7 +17,7 @@ int tsl_aiplatform_init(void **handle, tsl_aiplatform_param param)
17 17 return tools->InitAlgorthim(param);
18 18 }
19 19  
20   -int get_task_status(void *handle, char *task_id)
  20 +int get_task_status(void *handle, string task_id)
21 21 {
22 22 CMultiSourceProcess* tools = (CMultiSourceProcess*)handle;
23 23 return tools->GetTaskStatus(task_id);
... ... @@ -34,7 +34,7 @@ int add_task(void *handle, task_param param)
34 34 }
35 35  
36 36  
37   -int pause_task(void *handle, char * task_id, const int max_timeout_ms)
  37 +int pause_task(void *handle, string task_id, const int max_timeout_ms)
38 38 {
39 39 int error_code = FAILED;
40 40 CMultiSourceProcess* tools = (CMultiSourceProcess*)handle;
... ... @@ -45,7 +45,7 @@ int pause_task(void *handle, char * task_id, const int max_timeout_ms)
45 45 }
46 46  
47 47  
48   -int restart_task(void *handle, char * task_id, const int max_timeout_ms)
  48 +int restart_task(void *handle, string task_id, const int max_timeout_ms)
49 49 {
50 50 int error_code = FAILED;
51 51 CMultiSourceProcess* tools = (CMultiSourceProcess*)handle;
... ... @@ -55,7 +55,7 @@ int restart_task(void *handle, char * task_id, const int max_timeout_ms)
55 55 return error_code;
56 56 }
57 57  
58   -int finish_task(void *handle, char * task_id, const int max_timeout_ms)
  58 +int finish_task(void *handle, string task_id, const int max_timeout_ms)
59 59 {
60 60 int error_code = FAILED;
61 61 CMultiSourceProcess* tools = (CMultiSourceProcess*)handle;
... ... @@ -66,7 +66,7 @@ int finish_task(void *handle, char * task_id, const int max_timeout_ms)
66 66 }
67 67  
68 68 // added by zsh 220801
69   -int screenshot_task(void *handle, task_param param, char* result_folder)
  69 +int screenshot_task(void *handle, task_param param, string result_folder)
70 70 {
71 71 CMultiSourceProcess* tools = (CMultiSourceProcess*)handle;
72 72 return tools->SnapShot(param, result_folder);
... ... @@ -77,7 +77,7 @@ int tsl_aiplatform_release(void **handle)
77 77 if (*handle)
78 78 {
79 79 CMultiSourceProcess* tools = (CMultiSourceProcess*)*handle;
80   - tools->CloseAllTask();
  80 + tools->Release();
81 81  
82 82 delete tools;
83 83 tools = NULL;
... ... @@ -94,7 +94,7 @@ int count_running_task(void *handle)
94 94 void close_all_task(void *handle)
95 95 {
96 96 CMultiSourceProcess* tools = (CMultiSourceProcess*)handle;
97   - tools->CloseAllTask2();
  97 + tools->CloseAllTask();
98 98 }
99 99  
100 100 const char* get_tsl_aiplatform_version()
... ...
src/ai_platform/stl_aiplatform.h
... ... @@ -16,6 +16,7 @@
16 16 #else
17 17 #define TSL_AIPLATFORM_API __attribute__ ((visibility ("default")))
18 18 #endif
  19 +
19 20 #include "header.h"
20 21  
21 22  
... ... @@ -33,7 +34,7 @@ extern &quot;C&quot;
33 34 TSL_AIPLATFORM_API int tsl_aiplatform_init(void **handle, tsl_aiplatform_param param);
34 35  
35 36  
36   - TSL_AIPLATFORM_API int get_task_status(void *handle, char *task_id);
  37 + TSL_AIPLATFORM_API int get_task_status(void *handle, string task_id);
37 38  
38 39 /*************************************************************************
39 40 * FUNCTION: add_task
... ... @@ -56,7 +57,7 @@ extern &quot;C&quot;
56 57 * RETURN:
57 58 * NOTES:
58 59 *************************************************************************/
59   - TSL_AIPLATFORM_API int pause_task(void *handle, char * task_id, const int max_timeout_ms);
  60 + TSL_AIPLATFORM_API int pause_task(void *handle, string task_id, const int max_timeout_ms);
60 61  
61 62  
62 63 /*************************************************************************
... ... @@ -68,7 +69,7 @@ extern &quot;C&quot;
68 69 * RETURN:
69 70 * NOTES:
70 71 *************************************************************************/
71   - TSL_AIPLATFORM_API int restart_task(void *handle, char * task_id, const int max_timeout_ms);
  72 + TSL_AIPLATFORM_API int restart_task(void *handle, string task_id, const int max_timeout_ms);
72 73  
73 74  
74 75 /*************************************************************************
... ... @@ -80,7 +81,7 @@ extern &quot;C&quot;
80 81 * RETURN:
81 82 * NOTES:
82 83 *************************************************************************/
83   - TSL_AIPLATFORM_API int finish_task(void *handle, char * task_id, const int max_timeout_ms);
  84 + TSL_AIPLATFORM_API int finish_task(void *handle, string task_id, const int max_timeout_ms);
84 85  
85 86  
86 87 /*************************************************************************
... ... @@ -92,7 +93,7 @@ extern &quot;C&quot;
92 93 * RETURN: 成功/失败
93 94 * NOTES:
94 95 *************************************************************************/
95   - TSL_AIPLATFORM_API int screenshot_task(void *handle, task_param param, char* result_folder);
  96 + TSL_AIPLATFORM_API int screenshot_task(void *handle, task_param param, string result_folder);
96 97  
97 98  
98 99 /*************************************************************************
... ...
src/ai_platform/task_manager.cpp
... ... @@ -119,6 +119,28 @@ bool task_manager::FinishTask(const string&amp; task_id){
119 119 return true;
120 120 }
121 121  
  122 +bool task_manager::CloseDecoder(const string& task_id){
  123 + LOG_INFO("CloseDecoder:{}",task_id);
  124 + auto it = task_info_map.find(task_id);
  125 + if(it == task_info_map.end()) {
  126 + return false;
  127 + }
  128 +
  129 + TaskInfo& info = task_info_map[task_id];
  130 + info.dec->close();
  131 +
  132 + return true;
  133 +}
  134 +
  135 +bool task_manager::CloseAllDecoder() {
  136 + for (auto it = task_info_map.begin(); it != task_info_map.end(); it++)
  137 + {
  138 + TaskInfo& info = it->second;
  139 + info.dec->close();
  140 + }
  141 + return true;
  142 +}
  143 +
122 144 bool task_manager::GetResolution(const string& task_id, int &width, int &height ) {
123 145 auto it = task_info_map.find(task_id);
124 146 if(it == task_info_map.end()) {
... ... @@ -172,7 +194,17 @@ bool task_manager::IsFinished(const string&amp; task_id){
172 194 }
173 195  
174 196 int task_manager::GetRunningTaskCount() {
175   - return task_info_map.size();
  197 + int count = 0;
  198 + for (auto it = task_info_map.begin(); it != task_info_map.end(); it++)
  199 + {
  200 + TaskInfo& info = it->second;
  201 + if (!info.dec->isFinished())
  202 + {
  203 + count++;
  204 + }
  205 + }
  206 +
  207 + return count;
176 208 }
177 209  
178 210 void task_manager::Release() {
... ...
src/ai_platform/task_manager.h
... ... @@ -35,6 +35,9 @@ public:
35 35 bool FinishTask(const string& task_id);
36 36 bool StartTask(const string& task_id);
37 37  
  38 + bool CloseDecoder(const string& task_id);
  39 + bool CloseAllDecoder();
  40 +
38 41 bool GetResolution(const string& task_id, int &width, int &height );
39 42 bool SetDecKeyframe(const string& task_id, bool bKeyframe);
40 43  
... ...
src/demo/demo.cpp
... ... @@ -150,7 +150,7 @@ string createTask(void *handle, int gi, bool bFlag = true){
150 150 nTaskId = gi;
151 151 }
152 152 std::string task_id_str = "test_task_id_" + std::to_string(nTaskId);
153   - tparam.task_id = task_id_str.c_str();
  153 + tparam.task_id = task_id_str;
154 154 nTaskId++;
155 155  
156 156 tparam.result_folder_little = "./res"; //目标快照抠图保存地址
... ... @@ -159,7 +159,7 @@ string createTask(void *handle, int gi, bool bFlag = true){
159 159 const int result_code = add_task(handle, tparam);
160 160 if (result_code != 0)
161 161 printf("[Error]: ");
162   - printf("--- task_id: %s result code: %d\n", tparam.task_id, result_code);
  162 + printf("--- task_id: %s result code: %d\n", tparam.task_id.c_str(), result_code);
163 163  
164 164 return task_id_str;
165 165 }
... ... @@ -283,11 +283,32 @@ void test_gpu(int gpuID){
283 283 // createTask(handle, algor_vec2, 24, false);
284 284 // createTask(handle, algor_vec2, 30, false);
285 285 // createTask(handle, algor_vec2, 31, false);
286   - createTask(handle, 4, false);
  286 + string task_id = createTask(handle, 4, false);
287 287  
288   - while (getchar() != 'q');
  288 + bool bFlag = true;
  289 + while (bFlag){
  290 + char op = getchar();
  291 + switch (op)
  292 + {
  293 + case 'a':
  294 + task_id = createTask(handle, 4, false);
  295 + break;
  296 + case 'c':
  297 + finish_task(handle, task_id, 0);
  298 + break;
  299 + case 'g':
  300 + close_all_task(handle);
  301 + break;
  302 + case 'q':
  303 + close_all_task(handle);
  304 + bFlag = false;
  305 + break;
  306 + default:
  307 + break;
  308 + }
  309 + }
289 310  
290   - tsl_aiplatform_release(&handle);
  311 + tsl_aiplatform_release(&handle);
291 312 }
292 313  
293 314 int main(int argc, char *argv[]) {
... ...