Commit 9e3f3176e70e79ded15912019cbefa1507496b31
1 parent
95ee08f6
修复关闭任务崩溃的问题
Showing
9 changed files
with
106 additions
and
32 deletions
src/ai_platform/det_obj_header.h
src/ai_platform/header.h
src/ai_platform/mvpt.cpp
@@ -245,7 +245,7 @@ bool CMultiSourceProcess::RestartTask(const string taskID){ | @@ -245,7 +245,7 @@ bool CMultiSourceProcess::RestartTask(const string taskID){ | ||
245 | } | 245 | } |
246 | 246 | ||
247 | bool CMultiSourceProcess::FinishTask(const string taskID){ | 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 | int CMultiSourceProcess::snapshot_task(std::string& uri_or_name, const std::string& file_name, bool bInTask) { | 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& uri_or_name, const std::stri | @@ -290,13 +290,13 @@ int CMultiSourceProcess::snapshot_task(std::string& uri_or_name, const std::stri | ||
290 | return FAILED; | 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 | LOG_INFO("begin SnapShot task: {}", _cur_task_param.task_id); | 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 | } else { | 300 | } else { |
301 | result_folder = ""; | 301 | result_folder = ""; |
302 | } | 302 | } |
@@ -321,10 +321,19 @@ int CMultiSourceProcess::SnapShot(task_param _cur_task_param, char* result_folde | @@ -321,10 +321,19 @@ int CMultiSourceProcess::SnapShot(task_param _cur_task_param, char* result_folde | ||
321 | } | 321 | } |
322 | 322 | ||
323 | void CMultiSourceProcess::CloseAllTask(){ | 323 | void CMultiSourceProcess::CloseAllTask(){ |
324 | - m_bfinish = true; | 324 | + m_task_manager.CloseAllDecoder(); |
325 | +} | ||
326 | + | ||
327 | +void CMultiSourceProcess::Release() { | ||
328 | + | ||
325 | atlas_licence_close(&(skt_handle)); //授权 | 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 | if(m_pAlgorthimThread){ | 338 | if(m_pAlgorthimThread){ |
330 | m_pAlgorthimThread->join(); | 339 | m_pAlgorthimThread->join(); |
@@ -342,14 +351,12 @@ void CMultiSourceProcess::CloseAllTask(){ | @@ -342,14 +351,12 @@ void CMultiSourceProcess::CloseAllTask(){ | ||
342 | 351 | ||
343 | int size = m_RgbDataList.size(); | 352 | int size = m_RgbDataList.size(); |
344 | bool bEmpty = m_RgbDataList.empty(); | 353 | bool bEmpty = m_RgbDataList.empty(); |
354 | + | ||
355 | + m_task_manager.Release(); | ||
345 | 356 | ||
346 | LOG_INFO("CloseAllTask exit."); | 357 | LOG_INFO("CloseAllTask exit."); |
347 | } | 358 | } |
348 | 359 | ||
349 | -void CMultiSourceProcess::CloseAllTask2() { | ||
350 | - m_task_manager.Release(); | ||
351 | -} | ||
352 | - | ||
353 | void CMultiSourceProcess::clear_finished_task(){// 清理已经结束的任务 | 360 | void CMultiSourceProcess::clear_finished_task(){// 清理已经结束的任务 |
354 | 361 | ||
355 | std::lock_guard<std::mutex> l1(m_FinishedTaskMtx); | 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,6 +396,15 @@ bool CMultiSourceProcess::finish_task(const string taskID, const bool delete_sna | ||
389 | 396 | ||
390 | m_snapshot_reprocessing->release_finished_locus_snapshot(taskID); | 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 | return true; | 408 | return true; |
393 | } | 409 | } |
394 | 410 |
src/ai_platform/mvpt.h
@@ -34,12 +34,11 @@ public: | @@ -34,12 +34,11 @@ public: | ||
34 | bool PauseTask(const string taskID); | 34 | bool PauseTask(const string taskID); |
35 | bool RestartTask(const string taskID); | 35 | bool RestartTask(const string taskID); |
36 | bool FinishTask(const string taskID); | 36 | bool FinishTask(const string taskID); |
37 | + void Release(); | ||
37 | void CloseAllTask(); | 38 | void CloseAllTask(); |
38 | - int SnapShot(task_param param, char* result_folder); | 39 | + int SnapShot(task_param param, string result_folder); |
39 | int CountRunningTask(); | 40 | int CountRunningTask(); |
40 | 41 | ||
41 | - void CloseAllTask2(); | ||
42 | - | ||
43 | int GetTaskStatus(const string taskID); | 42 | int GetTaskStatus(const string taskID); |
44 | 43 | ||
45 | public: | 44 | public: |
src/ai_platform/stl_aiplatform.cpp
@@ -17,7 +17,7 @@ int tsl_aiplatform_init(void **handle, tsl_aiplatform_param param) | @@ -17,7 +17,7 @@ int tsl_aiplatform_init(void **handle, tsl_aiplatform_param param) | ||
17 | return tools->InitAlgorthim(param); | 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 | CMultiSourceProcess* tools = (CMultiSourceProcess*)handle; | 22 | CMultiSourceProcess* tools = (CMultiSourceProcess*)handle; |
23 | return tools->GetTaskStatus(task_id); | 23 | return tools->GetTaskStatus(task_id); |
@@ -34,7 +34,7 @@ int add_task(void *handle, task_param param) | @@ -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 | int error_code = FAILED; | 39 | int error_code = FAILED; |
40 | CMultiSourceProcess* tools = (CMultiSourceProcess*)handle; | 40 | CMultiSourceProcess* tools = (CMultiSourceProcess*)handle; |
@@ -45,7 +45,7 @@ int pause_task(void *handle, char * task_id, const int max_timeout_ms) | @@ -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 | int error_code = FAILED; | 50 | int error_code = FAILED; |
51 | CMultiSourceProcess* tools = (CMultiSourceProcess*)handle; | 51 | CMultiSourceProcess* tools = (CMultiSourceProcess*)handle; |
@@ -55,7 +55,7 @@ int restart_task(void *handle, char * task_id, const int max_timeout_ms) | @@ -55,7 +55,7 @@ int restart_task(void *handle, char * task_id, const int max_timeout_ms) | ||
55 | return error_code; | 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 | int error_code = FAILED; | 60 | int error_code = FAILED; |
61 | CMultiSourceProcess* tools = (CMultiSourceProcess*)handle; | 61 | CMultiSourceProcess* tools = (CMultiSourceProcess*)handle; |
@@ -66,7 +66,7 @@ int finish_task(void *handle, char * task_id, const int max_timeout_ms) | @@ -66,7 +66,7 @@ int finish_task(void *handle, char * task_id, const int max_timeout_ms) | ||
66 | } | 66 | } |
67 | 67 | ||
68 | // added by zsh 220801 | 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 | CMultiSourceProcess* tools = (CMultiSourceProcess*)handle; | 71 | CMultiSourceProcess* tools = (CMultiSourceProcess*)handle; |
72 | return tools->SnapShot(param, result_folder); | 72 | return tools->SnapShot(param, result_folder); |
@@ -77,7 +77,7 @@ int tsl_aiplatform_release(void **handle) | @@ -77,7 +77,7 @@ int tsl_aiplatform_release(void **handle) | ||
77 | if (*handle) | 77 | if (*handle) |
78 | { | 78 | { |
79 | CMultiSourceProcess* tools = (CMultiSourceProcess*)*handle; | 79 | CMultiSourceProcess* tools = (CMultiSourceProcess*)*handle; |
80 | - tools->CloseAllTask(); | 80 | + tools->Release(); |
81 | 81 | ||
82 | delete tools; | 82 | delete tools; |
83 | tools = NULL; | 83 | tools = NULL; |
@@ -94,7 +94,7 @@ int count_running_task(void *handle) | @@ -94,7 +94,7 @@ int count_running_task(void *handle) | ||
94 | void close_all_task(void *handle) | 94 | void close_all_task(void *handle) |
95 | { | 95 | { |
96 | CMultiSourceProcess* tools = (CMultiSourceProcess*)handle; | 96 | CMultiSourceProcess* tools = (CMultiSourceProcess*)handle; |
97 | - tools->CloseAllTask2(); | 97 | + tools->CloseAllTask(); |
98 | } | 98 | } |
99 | 99 | ||
100 | const char* get_tsl_aiplatform_version() | 100 | const char* get_tsl_aiplatform_version() |
src/ai_platform/stl_aiplatform.h
@@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
16 | #else | 16 | #else |
17 | #define TSL_AIPLATFORM_API __attribute__ ((visibility ("default"))) | 17 | #define TSL_AIPLATFORM_API __attribute__ ((visibility ("default"))) |
18 | #endif | 18 | #endif |
19 | + | ||
19 | #include "header.h" | 20 | #include "header.h" |
20 | 21 | ||
21 | 22 | ||
@@ -33,7 +34,7 @@ extern "C" | @@ -33,7 +34,7 @@ extern "C" | ||
33 | TSL_AIPLATFORM_API int tsl_aiplatform_init(void **handle, tsl_aiplatform_param param); | 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 | * FUNCTION: add_task | 40 | * FUNCTION: add_task |
@@ -56,7 +57,7 @@ extern "C" | @@ -56,7 +57,7 @@ extern "C" | ||
56 | * RETURN: | 57 | * RETURN: |
57 | * NOTES: | 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 "C" | @@ -68,7 +69,7 @@ extern "C" | ||
68 | * RETURN: | 69 | * RETURN: |
69 | * NOTES: | 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 "C" | @@ -80,7 +81,7 @@ extern "C" | ||
80 | * RETURN: | 81 | * RETURN: |
81 | * NOTES: | 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 "C" | @@ -92,7 +93,7 @@ extern "C" | ||
92 | * RETURN: 成功/失败 | 93 | * RETURN: 成功/失败 |
93 | * NOTES: | 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& task_id){ | @@ -119,6 +119,28 @@ bool task_manager::FinishTask(const string& task_id){ | ||
119 | return true; | 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 | bool task_manager::GetResolution(const string& task_id, int &width, int &height ) { | 144 | bool task_manager::GetResolution(const string& task_id, int &width, int &height ) { |
123 | auto it = task_info_map.find(task_id); | 145 | auto it = task_info_map.find(task_id); |
124 | if(it == task_info_map.end()) { | 146 | if(it == task_info_map.end()) { |
@@ -172,7 +194,17 @@ bool task_manager::IsFinished(const string& task_id){ | @@ -172,7 +194,17 @@ bool task_manager::IsFinished(const string& task_id){ | ||
172 | } | 194 | } |
173 | 195 | ||
174 | int task_manager::GetRunningTaskCount() { | 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 | void task_manager::Release() { | 210 | void task_manager::Release() { |
src/ai_platform/task_manager.h
@@ -35,6 +35,9 @@ public: | @@ -35,6 +35,9 @@ public: | ||
35 | bool FinishTask(const string& task_id); | 35 | bool FinishTask(const string& task_id); |
36 | bool StartTask(const string& task_id); | 36 | bool StartTask(const string& task_id); |
37 | 37 | ||
38 | + bool CloseDecoder(const string& task_id); | ||
39 | + bool CloseAllDecoder(); | ||
40 | + | ||
38 | bool GetResolution(const string& task_id, int &width, int &height ); | 41 | bool GetResolution(const string& task_id, int &width, int &height ); |
39 | bool SetDecKeyframe(const string& task_id, bool bKeyframe); | 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,7 +150,7 @@ string createTask(void *handle, int gi, bool bFlag = true){ | ||
150 | nTaskId = gi; | 150 | nTaskId = gi; |
151 | } | 151 | } |
152 | std::string task_id_str = "test_task_id_" + std::to_string(nTaskId); | 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 | nTaskId++; | 154 | nTaskId++; |
155 | 155 | ||
156 | tparam.result_folder_little = "./res"; //目标快照抠图保存地址 | 156 | tparam.result_folder_little = "./res"; //目标快照抠图保存地址 |
@@ -159,7 +159,7 @@ string createTask(void *handle, int gi, bool bFlag = true){ | @@ -159,7 +159,7 @@ string createTask(void *handle, int gi, bool bFlag = true){ | ||
159 | const int result_code = add_task(handle, tparam); | 159 | const int result_code = add_task(handle, tparam); |
160 | if (result_code != 0) | 160 | if (result_code != 0) |
161 | printf("[Error]: "); | 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 | return task_id_str; | 164 | return task_id_str; |
165 | } | 165 | } |
@@ -283,11 +283,32 @@ void test_gpu(int gpuID){ | @@ -283,11 +283,32 @@ void test_gpu(int gpuID){ | ||
283 | // createTask(handle, algor_vec2, 24, false); | 283 | // createTask(handle, algor_vec2, 24, false); |
284 | // createTask(handle, algor_vec2, 30, false); | 284 | // createTask(handle, algor_vec2, 30, false); |
285 | // createTask(handle, algor_vec2, 31, false); | 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 | int main(int argc, char *argv[]) { | 314 | int main(int argc, char *argv[]) { |