| 181 | static task_manager_t task_mgr; |
| 182 | |
| 183 | capture_task_t *capture_task_new(TasksAllConfig *tasks_cfg, TaskConfig *task_cfg, task_stats_summary_t *stats, |
| 184 | char *errbuf) |
| 185 | { |
| 186 | capture_task_t *task = (capture_task_t *)calloc(1, sizeof(capture_task_t)); |
| 187 | if (!task) |
| 188 | { |
| 189 | error_format(errbuf, "failed to allocate memory for capture_task_t"); |
| 190 | return NULL; |
| 191 | } |
| 192 | |
| 193 | CapturerFactory factory = find_capturer_factory(task_cfg->capturer.type); |
| 194 | if (!factory) |
| 195 | { |
| 196 | error_format(errbuf, "unsupport capturer type %s", task_cfg->capturer.type); |
| 197 | goto error; |
| 198 | } |
| 199 | task->capturer = factory(tasks_cfg, task_cfg, &stats->capture, errbuf); |
| 200 | if (!task->capturer) |
| 201 | goto error; |
| 202 | |
| 203 | task->outputs = (output_base_t **)calloc(task_cfg->num_outputs, sizeof(output_base_t *)); |
| 204 | if (!task->outputs && task_cfg->num_outputs > 0) |
| 205 | { |
| 206 | error_format(errbuf, "failed to allocate memory for outputs"); |
| 207 | goto error; |
| 208 | } |
| 209 | |
| 210 | for (int i = 0; i < task_cfg->num_outputs; ++i) |
| 211 | { |
| 212 | OutputConfig *output_cfg = task_cfg->outputs[i]; |
| 213 | OutputFactory factory = find_output_factory(output_cfg->type); |
| 214 | if (!factory) |
| 215 | { |
| 216 | error_format(errbuf, "unsupport output type: %s", output_cfg->type); |
| 217 | goto error; |
| 218 | } |
| 219 | |
| 220 | output_base_t *output = factory(task_cfg, output_cfg, &stats->output, errbuf); |
| 221 | if (!output) |
| 222 | goto error; |
| 223 | |
| 224 | task->outputs[task->num_outputs++] = output; |
| 225 | } |
| 226 | return task; |
| 227 | |
| 228 | error: |
| 229 | capture_task_destroy(task); |
| 230 | return NULL; |
| 231 | } |
| 232 | |
| 233 | void capture_task_destroy(capture_task_t *task) |
| 234 | { |
no test coverage detected