History

libavfilter/dnn: add batch mode for async execution

the default number of batch_size is 1

Guo, Yejun committed 5 years ago

Commit 64ea15f1 parent 57dae575 files · +196 −35Browse files

Showing the changes to libavfilter (5 of 5 files). Show all

Unified · Split

5 files
  1. libavfilter/dnn/dnn_backend_openvino.c +155 −32
  2. libavfilter/dnn/dnn_backend_openvino.h +1 −0
  3. libavfilter/dnn/dnn_interface.c +1 −0
  4. libavfilter/dnn_interface.h +2 −0
  5. libavfilter/vf_dnn_processing.c +37 −3
libavfilter/dnn/dnn_backend_openvino.c+155−32
@@ -37,6 +37,7 @@ · 36 unmodified lines
37typedef struct OVOptions{37typedef struct OVOptions{
38 char *device_type;38 char *device_type;
39 int nireq;39 int nireq;
40 int batch_size;
40} OVOptions;41} OVOptions;
41 42
42typedef struct OVContext {43typedef struct OVContext {
@@ -70,7 +71,8 @@ typedef struct TaskItem { · 27 unmodified lines
70 71
71typedef struct RequestItem {72typedef struct RequestItem {
72 ie_infer_request_t *infer_request;73 ie_infer_request_t *infer_request;
73 TaskItem *task;74 TaskItem **tasks;
75 int task_count;
74 ie_complete_call_back_t callback;76 ie_complete_call_back_t callback;
75} RequestItem;77} RequestItem;
76 78
@@ -83,6 +85,7 @@ typedef struct RequestItem { · 6 unmodified lines
83static const AVOption dnn_openvino_options[] = {85static const AVOption dnn_openvino_options[] = {
84 { "device", "device to run model", OFFSET(options.device_type), AV_OPT_TYPE_STRING, { .str = "CPU" }, 0, 0, FLAGS },86 { "device", "device to run model", OFFSET(options.device_type), AV_OPT_TYPE_STRING, { .str = "CPU" }, 0, 0, FLAGS },
85 { "nireq", "number of request", OFFSET(options.nireq), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },87 { "nireq", "number of request", OFFSET(options.nireq), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
88 { "batch_size", "batch size per request", OFFSET(options.batch_size), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 1000, FLAGS},
86 { NULL }89 { NULL }
87};90};
88 91
@@ -100,7 +103,19 @@ static DNNDataType precision_to_datatype(precision_e precision) · 11 unmodified lines
100 }103 }
101}104}
102 105
103static DNNReturnType fill_model_input_ov(OVModel *ov_model, TaskItem *task, RequestItem *request)106static int get_datatype_size(DNNDataType dt)
107{
108 switch (dt)
109 {
110 case DNN_FLOAT:
111 return sizeof(float);
112 default:
113 av_assert0(!"not supported yet.");
114 return 1;
115 }
116}
117
118static DNNReturnType fill_model_input_ov(OVModel *ov_model, RequestItem *request)
104{119{
105 dimensions_t dims;120 dimensions_t dims;
106 precision_e precision;121 precision_e precision;
@@ -109,6 +124,7 @@ static DNNReturnType fill_model_input_ov(OVModel *ov_model, TaskItem *task, Requ · 2 unmodified lines
109 IEStatusCode status;124 IEStatusCode status;
110 DNNData input;125 DNNData input;
111 ie_blob_t *input_blob = NULL;126 ie_blob_t *input_blob = NULL;
127 TaskItem *task = request->tasks[0];
112 128
113 status = ie_infer_request_get_blob(request->infer_request, task->input_name, &input_blob);129 status = ie_infer_request_get_blob(request->infer_request, task->input_name, &input_blob);
114 if (status != OK) {130 if (status != OK) {
@@ -134,12 +150,19 @@ static DNNReturnType fill_model_input_ov(OVModel *ov_model, TaskItem *task, Requ · 19 unmodified lines
134 input.channels = dims.dims[1];150 input.channels = dims.dims[1];
135 input.data = blob_buffer.buffer;151 input.data = blob_buffer.buffer;
136 input.dt = precision_to_datatype(precision);152 input.dt = precision_to_datatype(precision);
137 if (task->do_ioproc) {153
138 if (ov_model->model->pre_proc != NULL) {154 av_assert0(request->task_count <= dims.dims[0]);
139 ov_model->model->pre_proc(task->in_frame, &input, ov_model->model->filter_ctx);155 for (int i = 0; i < request->task_count; ++i) {
140 } else {156 task = request->tasks[i];
141 proc_from_frame_to_dnn(task->in_frame, &input, ctx);157 if (task->do_ioproc) {
158 if (ov_model->model->pre_proc != NULL) {
159 ov_model->model->pre_proc(task->in_frame, &input, ov_model->model->filter_ctx);
160 } else {
161 proc_from_frame_to_dnn(task->in_frame, &input, ctx);
162 }
142 }163 }
164 input.data = (uint8_t *)input.data
165 + input.width * input.height * input.channels * get_datatype_size(input.dt);
143 }166 }
144 ie_blob_free(&input_blob);167 ie_blob_free(&input_blob);
145 168
@@ -152,7 +175,7 @@ static void infer_completion_callback(void *args) · 6 unmodified lines
152 precision_e precision;175 precision_e precision;
153 IEStatusCode status;176 IEStatusCode status;
154 RequestItem *request = args;177 RequestItem *request = args;
155 TaskItem *task = request->task;178 TaskItem *task = request->tasks[0];
156 ie_blob_t *output_blob = NULL;179 ie_blob_t *output_blob = NULL;
157 ie_blob_buffer_t blob_buffer;180 ie_blob_buffer_t blob_buffer;
158 DNNData output;181 DNNData output;
@@ -194,41 +217,56 @@ static void infer_completion_callback(void *args) · 35 unmodified lines
194 output.width = dims.dims[3];217 output.width = dims.dims[3];
195 output.dt = precision_to_datatype(precision);218 output.dt = precision_to_datatype(precision);
196 output.data = blob_buffer.buffer;219 output.data = blob_buffer.buffer;
197 if (task->do_ioproc) {220
198 if (task->ov_model->model->post_proc != NULL) {221 av_assert0(request->task_count <= dims.dims[0]);
199 task->ov_model->model->post_proc(task->out_frame, &output, task->ov_model->model->filter_ctx);222 av_assert0(request->task_count >= 1);
223 for (int i = 0; i < request->task_count; ++i) {
224 task = request->tasks[i];
225 if (task->do_ioproc) {
226 if (task->ov_model->model->post_proc != NULL) {
227 task->ov_model->model->post_proc(task->out_frame, &output, task->ov_model->model->filter_ctx);
228 } else {
229 proc_from_dnn_to_frame(task->out_frame, &output, ctx);
230 }
200 } else {231 } else {
201 proc_from_dnn_to_frame(task->out_frame, &output, ctx);232 task->out_frame->width = output.width;
233 task->out_frame->height = output.height;
202 }234 }
203 } else {235 task->done = 1;
204 task->out_frame->width = output.width;236 output.data = (uint8_t *)output.data
205 task->out_frame->height = output.height;237 + output.width * output.height * output.channels * get_datatype_size(output.dt);
206 }238 }
207 ie_blob_free(&output_blob);239 ie_blob_free(&output_blob);
208 240
241 request->task_count = 0;
242
209 if (task->async) {243 if (task->async) {
210 request->task = NULL;
211 if (ff_safe_queue_push_back(task->ov_model->request_queue, request) < 0) {244 if (ff_safe_queue_push_back(task->ov_model->request_queue, request) < 0) {
212 av_log(ctx, AV_LOG_ERROR, "Failed to push back request_queue.\n");245 av_log(ctx, AV_LOG_ERROR, "Failed to push back request_queue.\n");
213 return;246 return;
214 }247 }
215 }248 }
216
217 task->done = 1;
218}249}
219 250
220static DNNReturnType execute_model_ov(TaskItem *task, RequestItem *request)251static DNNReturnType execute_model_ov(RequestItem *request)
221{252{
222 IEStatusCode status;253 IEStatusCode status;
254 DNNReturnType ret;
255 TaskItem *task = request->tasks[0];
223 OVContext *ctx = &task->ov_model->ctx;256 OVContext *ctx = &task->ov_model->ctx;
224 257
225 DNNReturnType ret = fill_model_input_ov(task->ov_model, task, request);
226 if (ret != DNN_SUCCESS) {
227 return ret;
228 }
229
230 if (task->async) {258 if (task->async) {
231 request->task = task;259 if (request->task_count < ctx->options.batch_size) {
260 if (ff_safe_queue_push_front(task->ov_model->request_queue, request) < 0) {
261 av_log(ctx, AV_LOG_ERROR, "Failed to push back request_queue.\n");
262 return DNN_ERROR;
263 }
264 return DNN_SUCCESS;
265 }
266 ret = fill_model_input_ov(task->ov_model, request);
267 if (ret != DNN_SUCCESS) {
268 return ret;
269 }
232 status = ie_infer_set_completion_callback(request->infer_request, &request->callback);270 status = ie_infer_set_completion_callback(request->infer_request, &request->callback);
233 if (status != OK) {271 if (status != OK) {
234 av_log(ctx, AV_LOG_ERROR, "Failed to set completion callback for inference\n");272 av_log(ctx, AV_LOG_ERROR, "Failed to set completion callback for inference\n");
@@ -241,12 +279,15 @@ static DNNReturnType execute_model_ov(TaskItem *task, RequestItem *request) · 6 unmodified lines
241 }279 }
242 return DNN_SUCCESS;280 return DNN_SUCCESS;
243 } else {281 } else {
282 ret = fill_model_input_ov(task->ov_model, request);
283 if (ret != DNN_SUCCESS) {
284 return ret;
285 }
244 status = ie_infer_request_infer(request->infer_request);286 status = ie_infer_request_infer(request->infer_request);
245 if (status != OK) {287 if (status != OK) {
246 av_log(ctx, AV_LOG_ERROR, "Failed to start synchronous model inference\n");288 av_log(ctx, AV_LOG_ERROR, "Failed to start synchronous model inference\n");
247 return DNN_ERROR;289 return DNN_ERROR;
248 }290 }
249 request->task = task;
250 infer_completion_callback(request);291 infer_completion_callback(request);
251 return task->done ? DNN_SUCCESS : DNN_ERROR;292 return task->done ? DNN_SUCCESS : DNN_ERROR;
252 }293 }
@@ -319,6 +360,7 @@ static DNNReturnType get_output_ov(void *model, const char *input_name, int inpu · 66 unmodified lines
319 RequestItem request;360 RequestItem request;
320 AVFrame *in_frame = av_frame_alloc();361 AVFrame *in_frame = av_frame_alloc();
321 AVFrame *out_frame = NULL;362 AVFrame *out_frame = NULL;
363 TaskItem *ptask = &task;
322 364
323 if (!in_frame) {365 if (!in_frame) {
324 av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for input frame\n");366 av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for input frame\n");
@@ -343,8 +385,10 @@ static DNNReturnType get_output_ov(void *model, const char *input_name, int inpu · 18 unmodified lines
343 task.ov_model = ov_model;385 task.ov_model = ov_model;
344 386
345 request.infer_request = ov_model->infer_request;387 request.infer_request = ov_model->infer_request;
388 request.task_count = 1;
389 request.tasks = &ptask;
346 390
347 ret = execute_model_ov(&task, &request);391 ret = execute_model_ov(&request);
348 *output_width = out_frame->width;392 *output_width = out_frame->width;
349 *output_height = out_frame->height;393 *output_height = out_frame->height;
350 394
@@ -393,6 +437,24 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options, · 42 unmodified lines
393 if (status != OK)437 if (status != OK)
394 goto err;438 goto err;
395 439
440 // batch size
441 if (ctx->options.batch_size <= 0) {
442 ctx->options.batch_size = 1;
443 }
444
445 if (ctx->options.batch_size > 1) {
446 input_shapes_t input_shapes;
447 status = ie_network_get_input_shapes(ov_model->network, &input_shapes);
448 if (status != OK)
449 goto err;
450 for (int i = 0; i < input_shapes.shape_num; i++)
451 input_shapes.shapes[i].shape.dims[0] = ctx->options.batch_size;
452 status = ie_network_reshape(ov_model->network, input_shapes);
453 ie_network_input_shapes_free(&input_shapes);
454 if (status != OK)
455 goto err;
456 }
457
396 status = ie_core_load_network(ov_model->core, ov_model->network, ctx->options.device_type, &config, &ov_model->exe_network);458 status = ie_core_load_network(ov_model->core, ov_model->network, ctx->options.device_type, &config, &ov_model->exe_network);
397 if (status != OK) {459 if (status != OK) {
398 av_log(ctx, AV_LOG_ERROR, "Failed to init OpenVINO model\n");460 av_log(ctx, AV_LOG_ERROR, "Failed to init OpenVINO model\n");
@@ -426,17 +488,24 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options, · 27 unmodified lines
426 }488 }
427 489
428 for (int i = 0; i < ctx->options.nireq; i++) {490 for (int i = 0; i < ctx->options.nireq; i++) {
429 ie_infer_request_t *request;
430 RequestItem *item = av_mallocz(sizeof(*item));491 RequestItem *item = av_mallocz(sizeof(*item));
431 if (!item) {492 if (!item) {
432 goto err;493 goto err;
433 }494 }
434 status = ie_exec_network_create_infer_request(ov_model->exe_network, &request);495
496 status = ie_exec_network_create_infer_request(ov_model->exe_network, &item->infer_request);
435 if (status != OK) {497 if (status != OK) {
436 av_freep(&item);498 av_freep(&item);
437 goto err;499 goto err;
438 }500 }
439 item->infer_request = request;501
502 item->tasks = av_malloc_array(ctx->options.batch_size, sizeof(*item->tasks));
503 if (!item->tasks) {
504 av_freep(&item);
505 goto err;
506 }
507 item->task_count = 0;
508
440 item->callback.completeCallBackFunc = infer_completion_callback;509 item->callback.completeCallBackFunc = infer_completion_callback;
441 item->callback.args = item;510 item->callback.args = item;
442 if (ff_safe_queue_push_back(ov_model->request_queue, item) < 0) {511 if (ff_safe_queue_push_back(ov_model->request_queue, item) < 0) {
@@ -469,6 +538,7 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, const char *input_n · 26 unmodified lines
469 OVContext *ctx = &ov_model->ctx;538 OVContext *ctx = &ov_model->ctx;
470 TaskItem task;539 TaskItem task;
471 RequestItem request;540 RequestItem request;
541 TaskItem *ptask = &task;
472 542
473 if (!in_frame) {543 if (!in_frame) {
474 av_log(ctx, AV_LOG_ERROR, "in frame is NULL when execute model.\n");544 av_log(ctx, AV_LOG_ERROR, "in frame is NULL when execute model.\n");
@@ -487,6 +557,11 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, const char *input_n · 12 unmodified lines
487 return DNN_ERROR;557 return DNN_ERROR;
488 }558 }
489 559
560 if (ctx->options.batch_size > 1) {
561 av_log(ctx, AV_LOG_ERROR, "do not support batch mode for sync execution.\n");
562 return DNN_ERROR;
563 }
564
490 task.done = 0;565 task.done = 0;
491 task.do_ioproc = 1;566 task.do_ioproc = 1;
492 task.async = 0;567 task.async = 0;
@@ -497,8 +572,10 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, const char *input_n · 4 unmodified lines
497 task.ov_model = ov_model;572 task.ov_model = ov_model;
498 573
499 request.infer_request = ov_model->infer_request;574 request.infer_request = ov_model->infer_request;
575 request.task_count = 1;
576 request.tasks = &ptask;
500 577
501 return execute_model_ov(&task, &request);578 return execute_model_ov(&request);
502}579}
503 580
504DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, const char *input_name, AVFrame *in_frame,581DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, const char *input_name, AVFrame *in_frame,
@@ -545,7 +622,8 @@ DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, const char *i · 40 unmodified lines
545 return DNN_ERROR;622 return DNN_ERROR;
546 }623 }
547 624
548 return execute_model_ov(task, request);625 request->tasks[request->task_count++] = task;
626 return execute_model_ov(request);
549}627}
550 628
551DNNAsyncStatusType ff_dnn_get_async_result_ov(const DNNModel *model, AVFrame **in, AVFrame **out)629DNNAsyncStatusType ff_dnn_get_async_result_ov(const DNNModel *model, AVFrame **in, AVFrame **out)
@@ -569,6 +647,48 @@ DNNAsyncStatusType ff_dnn_get_async_result_ov(const DNNModel *model, AVFrame **i · 17 unmodified lines
569 return DAST_SUCCESS;647 return DAST_SUCCESS;
570}648}
571 649
650DNNReturnType ff_dnn_flush_ov(const DNNModel *model)
651{
652 OVModel *ov_model = (OVModel *)model->model;
653 OVContext *ctx = &ov_model->ctx;
654 RequestItem *request;
655 IEStatusCode status;
656 DNNReturnType ret;
657
658 request = ff_safe_queue_pop_front(ov_model->request_queue);
659 if (!request) {
660 av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n");
661 return DNN_ERROR;
662 }
663
664 if (request->task_count == 0) {
665 // no pending task need to flush
666 if (ff_safe_queue_push_back(ov_model->request_queue, request) < 0) {
667 av_log(ctx, AV_LOG_ERROR, "Failed to push back request_queue.\n");
668 return DNN_ERROR;
669 }
670 return DNN_SUCCESS;
671 }
672
673 ret = fill_model_input_ov(ov_model, request);
674 if (ret != DNN_SUCCESS) {
675 av_log(ctx, AV_LOG_ERROR, "Failed to fill model input.\n");
676 return ret;
677 }
678 status = ie_infer_set_completion_callback(request->infer_request, &request->callback);
679 if (status != OK) {
680 av_log(ctx, AV_LOG_ERROR, "Failed to set completion callback for inference\n");
681 return DNN_ERROR;
682 }
683 status = ie_infer_request_infer_async(request->infer_request);
684 if (status != OK) {
685 av_log(ctx, AV_LOG_ERROR, "Failed to start async inference\n");
686 return DNN_ERROR;
687 }
688
689 return DNN_SUCCESS;
690}
691
572void ff_dnn_free_model_ov(DNNModel **model)692void ff_dnn_free_model_ov(DNNModel **model)
573{693{
574 if (*model){694 if (*model){
@@ -578,12 +698,15 @@ void ff_dnn_free_model_ov(DNNModel **model) · 3 unmodified lines
578 if (item && item->infer_request) {698 if (item && item->infer_request) {
579 ie_infer_request_free(&item->infer_request);699 ie_infer_request_free(&item->infer_request);
580 }700 }
701 av_freep(&item->tasks);
581 av_freep(&item);702 av_freep(&item);
582 }703 }
583 ff_safe_queue_destroy(ov_model->request_queue);704 ff_safe_queue_destroy(ov_model->request_queue);
584 705
585 while (ff_queue_size(ov_model->task_queue) != 0) {706 while (ff_queue_size(ov_model->task_queue) != 0) {
586 TaskItem *item = ff_queue_pop_front(ov_model->task_queue);707 TaskItem *item = ff_queue_pop_front(ov_model->task_queue);
708 av_frame_free(&item->in_frame);
709 av_frame_free(&item->out_frame);
587 av_freep(&item);710 av_freep(&item);
588 }711 }
589 ff_queue_destroy(ov_model->task_queue);712 ff_queue_destroy(ov_model->task_queue);
libavfilter/dnn/dnn_backend_openvino.h+1−0
@@ -36,6 +36,7 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, const char *input_n · 35 unmodified lines
36DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, const char *input_name, AVFrame *in_frame,36DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, const char *input_name, AVFrame *in_frame,
37 const char **output_names, uint32_t nb_output, AVFrame *out_frame);37 const char **output_names, uint32_t nb_output, AVFrame *out_frame);
38DNNAsyncStatusType ff_dnn_get_async_result_ov(const DNNModel *model, AVFrame **in, AVFrame **out);38DNNAsyncStatusType ff_dnn_get_async_result_ov(const DNNModel *model, AVFrame **in, AVFrame **out);
39DNNReturnType ff_dnn_flush_ov(const DNNModel *model);
39 40
40void ff_dnn_free_model_ov(DNNModel **model);41void ff_dnn_free_model_ov(DNNModel **model);
41 42
libavfilter/dnn/dnn_interface.c+1−0
@@ -60,6 +60,7 @@ DNNModule *ff_get_dnn_module(DNNBackendType backend_type) · 59 unmodified lines
60 dnn_module->execute_model = &ff_dnn_execute_model_ov;60 dnn_module->execute_model = &ff_dnn_execute_model_ov;
61 dnn_module->execute_model_async = &ff_dnn_execute_model_async_ov;61 dnn_module->execute_model_async = &ff_dnn_execute_model_async_ov;
62 dnn_module->get_async_result = &ff_dnn_get_async_result_ov;62 dnn_module->get_async_result = &ff_dnn_get_async_result_ov;
63 dnn_module->flush = &ff_dnn_flush_ov;
63 dnn_module->free_model = &ff_dnn_free_model_ov;64 dnn_module->free_model = &ff_dnn_free_model_ov;
64 #else65 #else
65 av_freep(&dnn_module);66 av_freep(&dnn_module);
libavfilter/dnn_interface.h+2−0
@@ -82,6 +82,8 @@ typedef struct DNNModule{ · 81 unmodified lines
82 const char **output_names, uint32_t nb_output, AVFrame *out_frame);82 const char **output_names, uint32_t nb_output, AVFrame *out_frame);
83 // Retrieve inference result.83 // Retrieve inference result.
84 DNNAsyncStatusType (*get_async_result)(const DNNModel *model, AVFrame **in, AVFrame **out);84 DNNAsyncStatusType (*get_async_result)(const DNNModel *model, AVFrame **in, AVFrame **out);
85 // Flush all the pending tasks.
86 DNNReturnType (*flush)(const DNNModel *model);
85 // Frees memory allocated for model.87 // Frees memory allocated for model.
86 void (*free_model)(DNNModel **model);88 void (*free_model)(DNNModel **model);
87} DNNModule;89} DNNModule;
libavfilter/vf_dnn_processing.c+37−3
@@ -33,6 +33,7 @@ · 32 unmodified lines
33#include "formats.h"33#include "formats.h"
34#include "internal.h"34#include "internal.h"
35#include "libswscale/swscale.h"35#include "libswscale/swscale.h"
36#include "libavutil/time.h"
36 37
37typedef struct DnnProcessingContext {38typedef struct DnnProcessingContext {
38 const AVClass *class;39 const AVClass *class;
@@ -369,6 +370,37 @@ static int activate_sync(AVFilterContext *filter_ctx) · 330 unmodified lines
369 return FFERROR_NOT_READY;370 return FFERROR_NOT_READY;
370}371}
371 372
373static int flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *out_pts)
374{
375 DnnProcessingContext *ctx = outlink->src->priv;
376 int ret;
377 DNNAsyncStatusType async_state;
378
379 ret = (ctx->dnn_module->flush)(ctx->model);
380 if (ret != DNN_SUCCESS) {
381 return -1;
382 }
383
384 do {
385 AVFrame *in_frame = NULL;
386 AVFrame *out_frame = NULL;
387 async_state = (ctx->dnn_module->get_async_result)(ctx->model, &in_frame, &out_frame);
388 if (out_frame) {
389 if (isPlanarYUV(in_frame->format))
390 copy_uv_planes(ctx, out_frame, in_frame);
391 av_frame_free(&in_frame);
392 ret = ff_filter_frame(outlink, out_frame);
393 if (ret < 0)
394 return ret;
395 if (out_pts)
396 *out_pts = out_frame->pts + pts;
397 }
398 av_usleep(5000);
399 } while (async_state >= DAST_NOT_READY);
400
401 return 0;
402}
403
372static int activate_async(AVFilterContext *filter_ctx)404static int activate_async(AVFilterContext *filter_ctx)
373{405{
374 AVFilterLink *inlink = filter_ctx->inputs[0];406 AVFilterLink *inlink = filter_ctx->inputs[0];
@@ -396,7 +428,7 @@ static int activate_async(AVFilterContext *filter_ctx) · 21 unmodified lines
396 av_frame_copy_props(out, in);428 av_frame_copy_props(out, in);
397 if ((ctx->dnn_module->execute_model_async)(ctx->model, ctx->model_inputname, in,429 if ((ctx->dnn_module->execute_model_async)(ctx->model, ctx->model_inputname, in,
398 (const char **)&ctx->model_outputname, 1, out) != DNN_SUCCESS) {430 (const char **)&ctx->model_outputname, 1, out) != DNN_SUCCESS) {
399 return FFERROR_NOT_READY;431 return AVERROR(EIO);
400 }432 }
401 }433 }
402 } while (ret > 0);434 } while (ret > 0);
@@ -423,14 +455,16 @@ static int activate_async(AVFilterContext *filter_ctx) · 20 unmodified lines
423 455
424 if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {456 if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
425 if (status == AVERROR_EOF) {457 if (status == AVERROR_EOF) {
426 ff_outlink_set_status(outlink, status, pts);458 int64_t out_pts = pts;
459 ret = flush_frame(outlink, pts, &out_pts);
460 ff_outlink_set_status(outlink, status, out_pts);
427 return ret;461 return ret;
428 }462 }
429 }463 }
430 464
431 FF_FILTER_FORWARD_WANTED(outlink, inlink);465 FF_FILTER_FORWARD_WANTED(outlink, inlink);
432 466
433 return FFERROR_NOT_READY;467 return 0;
434}468}
435 469
436static int activate(AVFilterContext *filter_ctx)470static int activate(AVFilterContext *filter_ctx)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t