task_manager.cpp
5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#include "task_manager.h"
#include "mvpt_process_assist.h"
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "../common/logger.hpp"
task_manager::task_manager(/* args */)
{
}
task_manager::~task_manager()
{
Release();
}
bool task_manager::AddTask(const task_param& task_param, FFDecConfig& cfg) {
TaskInfo info;
info.ipc_url = task_param.ipc_url;
info.task_id = task_param.task_id;
info.result_folder = task_param.result_folder;
info.result_folder_little = task_param.result_folder_little;
DvppDecoder* dec = create_decoder(cfg);
if(dec == nullptr) {
return false;
}
info.dec = dec;
task_info_map[info.task_id] = info;
return true;
}
DvppDecoder* task_manager::create_decoder(FFDecConfig& cfg) {
DvppDecoder* dec = new DvppDecoder();
if(dec == nullptr) {
LOG_ERROR("解码器创建失败");
return nullptr;
}
bool bRet= dec->init(cfg);
if (bRet) {
LOG_INFO("[{}][{}]- 解码器初始化成功",cfg.dec_name, cfg.uri);
return dec;
}
LOG_ERROR("[{}][{}]- 解码器初始化失败!",cfg.dec_name, cfg.uri);
return nullptr;
}
TaskInfo* task_manager::GetTaskInfo(string task_id) {
auto it = task_info_map.find(task_id);
if(it == task_info_map.end()) {
return nullptr;
}
return &(it->second);
}
bool task_manager::StartTask(const string& task_id) {
auto it = task_info_map.find(task_id);
if(it == task_info_map.end()) {
return false;
}
TaskInfo& info = task_info_map[task_id];
info.dec->start();
return true;
}
bool task_manager::PauseTask(const string& task_id) {
auto it = task_info_map.find(task_id);
if(it == task_info_map.end()) {
return false;
}
TaskInfo& info = task_info_map[task_id];
info.dec->pause();
return true;
}
bool task_manager::RestartTask(const string& task_id){
auto it = task_info_map.find(task_id);
if(it == task_info_map.end()) {
return false;
}
TaskInfo& info = task_info_map[task_id];
info.dec->resume();
return true;
}
bool task_manager::FinishTask(const string& task_id){
LOG_INFO("task finish:{}",task_id);
auto it = task_info_map.find(task_id);
if(it == task_info_map.end()) {
return false;
}
TaskInfo& info = task_info_map[task_id];
info.dec->close();
delete info.dec;
info.dec = nullptr;
task_info_map.erase(task_id);
LOG_INFO("task record erase:{}",task_id);
return true;
}
bool task_manager::CloseDecoder(const string& task_id){
LOG_INFO("CloseDecoder:{}",task_id);
auto it = task_info_map.find(task_id);
if(it == task_info_map.end()) {
return false;
}
TaskInfo& info = task_info_map[task_id];
info.dec->close();
return true;
}
bool task_manager::CloseAllDecoder() {
for (auto it = task_info_map.begin(); it != task_info_map.end(); it++)
{
TaskInfo& info = it->second;
info.dec->close();
}
return true;
}
bool task_manager::GetResolution(const string& task_id, int &width, int &height ) {
auto it = task_info_map.find(task_id);
if(it == task_info_map.end()) {
return false;
}
TaskInfo& info = task_info_map[task_id];
return info.dec->getResolution(width, height);
}
bool task_manager::SetDecKeyframe(const string& task_id, bool bKeyframe) {
auto it = task_info_map.find(task_id);
if(it == task_info_map.end()) {
return false;
}
TaskInfo& info = task_info_map[task_id];
info.dec->setDecKeyframe(bKeyframe);
return true;
}
bool task_manager::IsPausing(const string& task_id){
auto it = task_info_map.find(task_id);
if(it == task_info_map.end()) {
return false;
}
TaskInfo& info = task_info_map[task_id];
return info.dec->isPausing();
}
bool task_manager::IsRunning(const string& task_id){
auto it = task_info_map.find(task_id);
if(it == task_info_map.end()) {
return false;
}
TaskInfo& info = task_info_map[task_id];
return info.dec->isRunning();
}
bool task_manager::IsFinished(const string& task_id){
auto it = task_info_map.find(task_id);
if(it == task_info_map.end()) {
return false;
}
TaskInfo& info = task_info_map[task_id];
return info.dec->isFinished();
}
int task_manager::GetRunningTaskCount() {
int count = 0;
for (auto it = task_info_map.begin(); it != task_info_map.end(); it++)
{
TaskInfo& info = it->second;
if (!info.dec->isFinished())
{
count++;
}
}
return count;
}
void task_manager::Release() {
for (auto it = task_info_map.begin(); it != task_info_map.end(); it++)
{
TaskInfo& info = it->second;
info.dec->close();
delete info.dec;
info.dec = nullptr;
}
task_info_map.clear();
}
DeviceMemory* task_manager::SnapShot(const string& task_id) {
auto it = task_info_map.find(task_id);
if(it == task_info_map.end()) {
return nullptr;
}
TaskInfo& info = task_info_map[task_id];
return info.dec->snapshot();
// return make_shared<DvppDataMemory>(0, 0, 0, 0, 0, "m_dec_name", "1", false, 0, nullptr); // todo
}