History

lavfi/dnn_backend_openvino: Return Specific Error Codes

Switch to returning specific error codes or DNN_GENERIC_ERROR when an error is encountered. For OpenVINO API errors, currently DNN_GENERIC_ERROR is returned.

Shubhanshu Saxena committed 4 years ago

Commit 91af38f1 parent d0587da3 files · +89 −63Browse files

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

Unified · Split

3 files
  1. libavfilter/dnn/dnn_backend_openvino.c +82 −56
  2. libavfilter/dnn/dnn_backend_openvino.h +2 −2
  3. libavfilter/dnn_interface.h +5 −5
libavfilter/dnn/dnn_backend_openvino.c+82−56
@@ -112,7 +112,7 @@ static int get_datatype_size(DNNDataType dt) · 111 unmodified lines
112 }112 }
113}113}
114 114
115static DNNReturnType fill_model_input_ov(OVModel *ov_model, OVRequestItem *request)115static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request)
116{116{
117 dimensions_t dims;117 dimensions_t dims;
118 precision_e precision;118 precision_e precision;
@@ -131,7 +131,7 @@ static DNNReturnType fill_model_input_ov(OVModel *ov_model, OVRequestItem *reque · 12 unmodified lines
131 status = ie_infer_request_get_blob(request->infer_request, task->input_name, &input_blob);131 status = ie_infer_request_get_blob(request->infer_request, task->input_name, &input_blob);
132 if (status != OK) {132 if (status != OK) {
133 av_log(ctx, AV_LOG_ERROR, "Failed to get input blob with name %s\n", task->input_name);133 av_log(ctx, AV_LOG_ERROR, "Failed to get input blob with name %s\n", task->input_name);
134 return DNN_ERROR;134 return DNN_GENERIC_ERROR;
135 }135 }
136 136
137 status |= ie_blob_get_dims(input_blob, &dims);137 status |= ie_blob_get_dims(input_blob, &dims);
@@ -139,14 +139,14 @@ static DNNReturnType fill_model_input_ov(OVModel *ov_model, OVRequestItem *reque · 1 unmodified line
139 if (status != OK) {139 if (status != OK) {
140 ie_blob_free(&input_blob);140 ie_blob_free(&input_blob);
141 av_log(ctx, AV_LOG_ERROR, "Failed to get input blob dims/precision\n");141 av_log(ctx, AV_LOG_ERROR, "Failed to get input blob dims/precision\n");
142 return DNN_ERROR;142 return DNN_GENERIC_ERROR;
143 }143 }
144 144
145 status = ie_blob_get_buffer(input_blob, &blob_buffer);145 status = ie_blob_get_buffer(input_blob, &blob_buffer);
146 if (status != OK) {146 if (status != OK) {
147 ie_blob_free(&input_blob);147 ie_blob_free(&input_blob);
148 av_log(ctx, AV_LOG_ERROR, "Failed to get input blob buffer\n");148 av_log(ctx, AV_LOG_ERROR, "Failed to get input blob buffer\n");
149 return DNN_ERROR;149 return DNN_GENERIC_ERROR;
150 }150 }
151 151
152 input.height = dims.dims[2];152 input.height = dims.dims[2];
@@ -301,8 +301,9 @@ static void infer_completion_callback(void *args) · 148 unmodified lines
301 }301 }
302}302}
303 303
304static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, const char *output_name)304static int init_model_ov(OVModel *ov_model, const char *input_name, const char *output_name)
305{305{
306 int ret = DNN_SUCCESS;
306 OVContext *ctx = &ov_model->ctx;307 OVContext *ctx = &ov_model->ctx;
307 IEStatusCode status;308 IEStatusCode status;
308 ie_available_devices_t a_dev;309 ie_available_devices_t a_dev;
@@ -317,14 +318,18 @@ static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, co · 8 unmodified lines
317 if (ctx->options.batch_size > 1) {318 if (ctx->options.batch_size > 1) {
318 input_shapes_t input_shapes;319 input_shapes_t input_shapes;
319 status = ie_network_get_input_shapes(ov_model->network, &input_shapes);320 status = ie_network_get_input_shapes(ov_model->network, &input_shapes);
320 if (status != OK)321 if (status != OK) {
322 ret = DNN_GENERIC_ERROR;
321 goto err;323 goto err;
324 }
322 for (int i = 0; i < input_shapes.shape_num; i++)325 for (int i = 0; i < input_shapes.shape_num; i++)
323 input_shapes.shapes[i].shape.dims[0] = ctx->options.batch_size;326 input_shapes.shapes[i].shape.dims[0] = ctx->options.batch_size;
324 status = ie_network_reshape(ov_model->network, input_shapes);327 status = ie_network_reshape(ov_model->network, input_shapes);
325 ie_network_input_shapes_free(&input_shapes);328 ie_network_input_shapes_free(&input_shapes);
326 if (status != OK)329 if (status != OK) {
330 ret = DNN_GENERIC_ERROR;
327 goto err;331 goto err;
332 }
328 }333 }
329 334
330 // The order of dims in the openvino is fixed and it is always NCHW for 4-D data.335 // The order of dims in the openvino is fixed and it is always NCHW for 4-D data.
@@ -332,11 +337,13 @@ static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, co · 1 unmodified line
332 status = ie_network_set_input_layout(ov_model->network, input_name, NHWC);337 status = ie_network_set_input_layout(ov_model->network, input_name, NHWC);
333 if (status != OK) {338 if (status != OK) {
334 av_log(ctx, AV_LOG_ERROR, "Failed to set layout as NHWC for input %s\n", input_name);339 av_log(ctx, AV_LOG_ERROR, "Failed to set layout as NHWC for input %s\n", input_name);
340 ret = DNN_GENERIC_ERROR;
335 goto err;341 goto err;
336 }342 }
337 status = ie_network_set_output_layout(ov_model->network, output_name, NHWC);343 status = ie_network_set_output_layout(ov_model->network, output_name, NHWC);
338 if (status != OK) {344 if (status != OK) {
339 av_log(ctx, AV_LOG_ERROR, "Failed to set layout as NHWC for output %s\n", output_name);345 av_log(ctx, AV_LOG_ERROR, "Failed to set layout as NHWC for output %s\n", output_name);
346 ret = DNN_GENERIC_ERROR;
340 goto err;347 goto err;
341 }348 }
342 349
@@ -350,6 +357,7 @@ static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, co · 7 unmodified lines
350 status = ie_network_set_input_precision(ov_model->network, input_name, U8);357 status = ie_network_set_input_precision(ov_model->network, input_name, U8);
351 if (status != OK) {358 if (status != OK) {
352 av_log(ctx, AV_LOG_ERROR, "Failed to set input precision as U8 for %s\n", input_name);359 av_log(ctx, AV_LOG_ERROR, "Failed to set input precision as U8 for %s\n", input_name);
360 ret = DNN_GENERIC_ERROR;
353 goto err;361 goto err;
354 }362 }
355 }363 }
@@ -360,6 +368,7 @@ static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, co · 4 unmodified lines
360 status = ie_core_get_available_devices(ov_model->core, &a_dev);368 status = ie_core_get_available_devices(ov_model->core, &a_dev);
361 if (status != OK) {369 if (status != OK) {
362 av_log(ctx, AV_LOG_ERROR, "Failed to get available devices\n");370 av_log(ctx, AV_LOG_ERROR, "Failed to get available devices\n");
371 ret = DNN_GENERIC_ERROR;
363 goto err;372 goto err;
364 }373 }
365 for (int i = 0; i < a_dev.num_devices; i++) {374 for (int i = 0; i < a_dev.num_devices; i++) {
@@ -367,6 +376,7 @@ static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, co · 1 unmodified line
367 }376 }
368 av_log(ctx, AV_LOG_ERROR,"device %s may not be supported, all available devices are: \"%s\"\n",377 av_log(ctx, AV_LOG_ERROR,"device %s may not be supported, all available devices are: \"%s\"\n",
369 ctx->options.device_type, all_dev_names);378 ctx->options.device_type, all_dev_names);
379 ret = AVERROR(ENODEV);
370 goto err;380 goto err;
371 }381 }
372 382
@@ -378,12 +388,14 @@ static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, co · 5 unmodified lines
378 388
379 ov_model->request_queue = ff_safe_queue_create();389 ov_model->request_queue = ff_safe_queue_create();
380 if (!ov_model->request_queue) {390 if (!ov_model->request_queue) {
391 ret = AVERROR(ENOMEM);
381 goto err;392 goto err;
382 }393 }
383 394
384 for (int i = 0; i < ctx->options.nireq; i++) {395 for (int i = 0; i < ctx->options.nireq; i++) {
385 OVRequestItem *item = av_mallocz(sizeof(*item));396 OVRequestItem *item = av_mallocz(sizeof(*item));
386 if (!item) {397 if (!item) {
398 ret = AVERROR(ENOMEM);
387 goto err;399 goto err;
388 }400 }
389 401
@@ -391,16 +403,19 @@ static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, co · 1 unmodified line
391 item->callback.args = item;403 item->callback.args = item;
392 if (ff_safe_queue_push_back(ov_model->request_queue, item) < 0) {404 if (ff_safe_queue_push_back(ov_model->request_queue, item) < 0) {
393 av_freep(&item);405 av_freep(&item);
406 ret = AVERROR(ENOMEM);
394 goto err;407 goto err;
395 }408 }
396 409
397 status = ie_exec_network_create_infer_request(ov_model->exe_network, &item->infer_request);410 status = ie_exec_network_create_infer_request(ov_model->exe_network, &item->infer_request);
398 if (status != OK) {411 if (status != OK) {
412 ret = DNN_GENERIC_ERROR;
399 goto err;413 goto err;
400 }414 }
401 415
402 item->lltasks = av_malloc_array(ctx->options.batch_size, sizeof(*item->lltasks));416 item->lltasks = av_malloc_array(ctx->options.batch_size, sizeof(*item->lltasks));
403 if (!item->lltasks) {417 if (!item->lltasks) {
418 ret = AVERROR(ENOMEM);
404 goto err;419 goto err;
405 }420 }
406 item->lltask_count = 0;421 item->lltask_count = 0;
@@ -408,11 +423,13 @@ static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, co · 1 unmodified line
408 423
409 ov_model->task_queue = ff_queue_create();424 ov_model->task_queue = ff_queue_create();
410 if (!ov_model->task_queue) {425 if (!ov_model->task_queue) {
426 ret = AVERROR(ENOMEM);
411 goto err;427 goto err;
412 }428 }
413 429
414 ov_model->lltask_queue = ff_queue_create();430 ov_model->lltask_queue = ff_queue_create();
415 if (!ov_model->lltask_queue) {431 if (!ov_model->lltask_queue) {
432 ret = AVERROR(ENOMEM);
416 goto err;433 goto err;
417 }434 }
418 435
@@ -420,14 +437,14 @@ static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, co · 1 unmodified line
420 437
421err:438err:
422 ff_dnn_free_model_ov(&ov_model->model);439 ff_dnn_free_model_ov(&ov_model->model);
423 return DNN_ERROR;440 return ret;
424}441}
425 442
426static DNNReturnType execute_model_ov(OVRequestItem *request, Queue *inferenceq)443static int execute_model_ov(OVRequestItem *request, Queue *inferenceq)
427{444{
428 IEStatusCode status;445 IEStatusCode status;
429 DNNReturnType ret;
430 LastLevelTaskItem *lltask;446 LastLevelTaskItem *lltask;
447 int ret = DNN_SUCCESS;
431 TaskItem *task;448 TaskItem *task;
432 OVContext *ctx;449 OVContext *ctx;
433 OVModel *ov_model;450 OVModel *ov_model;
@@ -451,11 +468,13 @@ static DNNReturnType execute_model_ov(OVRequestItem *request, Queue *inferenceq) · 17 unmodified lines
451 status = ie_infer_set_completion_callback(request->infer_request, &request->callback);468 status = ie_infer_set_completion_callback(request->infer_request, &request->callback);
452 if (status != OK) {469 if (status != OK) {
453 av_log(ctx, AV_LOG_ERROR, "Failed to set completion callback for inference\n");470 av_log(ctx, AV_LOG_ERROR, "Failed to set completion callback for inference\n");
471 ret = DNN_GENERIC_ERROR;
454 goto err;472 goto err;
455 }473 }
456 status = ie_infer_request_infer_async(request->infer_request);474 status = ie_infer_request_infer_async(request->infer_request);
457 if (status != OK) {475 if (status != OK) {
458 av_log(ctx, AV_LOG_ERROR, "Failed to start async inference\n");476 av_log(ctx, AV_LOG_ERROR, "Failed to start async inference\n");
477 ret = DNN_GENERIC_ERROR;
459 goto err;478 goto err;
460 }479 }
461 return DNN_SUCCESS;480 return DNN_SUCCESS;
@@ -467,20 +486,21 @@ static DNNReturnType execute_model_ov(OVRequestItem *request, Queue *inferenceq) · 5 unmodified lines
467 status = ie_infer_request_infer(request->infer_request);486 status = ie_infer_request_infer(request->infer_request);
468 if (status != OK) {487 if (status != OK) {
469 av_log(ctx, AV_LOG_ERROR, "Failed to start synchronous model inference\n");488 av_log(ctx, AV_LOG_ERROR, "Failed to start synchronous model inference\n");
489 ret = DNN_GENERIC_ERROR;
470 goto err;490 goto err;
471 }491 }
472 infer_completion_callback(request);492 infer_completion_callback(request);
473 return (task->inference_done == task->inference_todo) ? DNN_SUCCESS : DNN_ERROR;493 return (task->inference_done == task->inference_todo) ? DNN_SUCCESS : DNN_GENERIC_ERROR;
474 }494 }
475err:495err:
476 if (ff_safe_queue_push_back(ov_model->request_queue, request) < 0) {496 if (ff_safe_queue_push_back(ov_model->request_queue, request) < 0) {
477 ie_infer_request_free(&request->infer_request);497 ie_infer_request_free(&request->infer_request);
478 av_freep(&request);498 av_freep(&request);
479 }499 }
480 return DNN_ERROR;500 return ret;
481}501}
482 502
483static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input_name)503static int get_input_ov(void *model, DNNData *input, const char *input_name)
484{504{
485 OVModel *ov_model = model;505 OVModel *ov_model = model;
486 OVContext *ctx = &ov_model->ctx;506 OVContext *ctx = &ov_model->ctx;
@@ -495,14 +515,14 @@ static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input · 8 unmodified lines
495 status = ie_network_get_inputs_number(ov_model->network, &model_input_count);515 status = ie_network_get_inputs_number(ov_model->network, &model_input_count);
496 if (status != OK) {516 if (status != OK) {
497 av_log(ctx, AV_LOG_ERROR, "Failed to get input count\n");517 av_log(ctx, AV_LOG_ERROR, "Failed to get input count\n");
498 return DNN_ERROR;518 return DNN_GENERIC_ERROR;
499 }519 }
500 520
501 for (size_t i = 0; i < model_input_count; i++) {521 for (size_t i = 0; i < model_input_count; i++) {
502 status = ie_network_get_input_name(ov_model->network, i, &model_input_name);522 status = ie_network_get_input_name(ov_model->network, i, &model_input_name);
503 if (status != OK) {523 if (status != OK) {
504 av_log(ctx, AV_LOG_ERROR, "Failed to get No.%d input's name\n", (int)i);524 av_log(ctx, AV_LOG_ERROR, "Failed to get No.%d input's name\n", (int)i);
505 return DNN_ERROR;525 return DNN_GENERIC_ERROR;
506 }526 }
507 if (strcmp(model_input_name, input_name) == 0) {527 if (strcmp(model_input_name, input_name) == 0) {
508 ie_network_name_free(&model_input_name);528 ie_network_name_free(&model_input_name);
@@ -510,7 +530,7 @@ static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input · 1 unmodified line
510 status |= ie_network_get_input_precision(ov_model->network, input_name, &precision);530 status |= ie_network_get_input_precision(ov_model->network, input_name, &precision);
511 if (status != OK) {531 if (status != OK) {
512 av_log(ctx, AV_LOG_ERROR, "Failed to get No.%d input's dims or precision\n", (int)i);532 av_log(ctx, AV_LOG_ERROR, "Failed to get No.%d input's dims or precision\n", (int)i);
513 return DNN_ERROR;533 return DNN_GENERIC_ERROR;
514 }534 }
515 535
516 input->channels = dims.dims[1];536 input->channels = dims.dims[1];
@@ -527,7 +547,7 @@ static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input · 10 unmodified lines
527 }547 }
528 548
529 av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model, all input(s) are: \"%s\"\n", input_name, all_input_names);549 av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model, all input(s) are: \"%s\"\n", input_name, all_input_names);
530 return DNN_ERROR;550 return AVERROR(EINVAL);
531}551}
532 552
533static int contain_valid_detection_bbox(AVFrame *frame)553static int contain_valid_detection_bbox(AVFrame *frame)
@@ -567,7 +587,7 @@ static int contain_valid_detection_bbox(AVFrame *frame) · 33 unmodified lines
567 return 1;587 return 1;
568}588}
569 589
570static DNNReturnType extract_lltask_from_task(DNNFunctionType func_type, TaskItem *task, Queue *lltask_queue, DNNExecBaseParams *exec_params)590static int extract_lltask_from_task(DNNFunctionType func_type, TaskItem *task, Queue *lltask_queue, DNNExecBaseParams *exec_params)
571{591{
572 switch (func_type) {592 switch (func_type) {
573 case DFT_PROCESS_FRAME:593 case DFT_PROCESS_FRAME:
@@ -575,14 +595,14 @@ static DNNReturnType extract_lltask_from_task(DNNFunctionType func_type, TaskIte · 1 unmodified line
575 {595 {
576 LastLevelTaskItem *lltask = av_malloc(sizeof(*lltask));596 LastLevelTaskItem *lltask = av_malloc(sizeof(*lltask));
577 if (!lltask) {597 if (!lltask) {
578 return DNN_ERROR;598 return AVERROR(ENOMEM);
579 }599 }
580 task->inference_todo = 1;600 task->inference_todo = 1;
581 task->inference_done = 0;601 task->inference_done = 0;
582 lltask->task = task;602 lltask->task = task;
583 if (ff_queue_push_back(lltask_queue, lltask) < 0) {603 if (ff_queue_push_back(lltask_queue, lltask) < 0) {
584 av_freep(&lltask);604 av_freep(&lltask);
585 return DNN_ERROR;605 return AVERROR(ENOMEM);
586 }606 }
587 return DNN_SUCCESS;607 return DNN_SUCCESS;
588 }608 }
@@ -615,28 +635,28 @@ static DNNReturnType extract_lltask_from_task(DNNFunctionType func_type, TaskIte · 26 unmodified lines
615 635
616 lltask = av_malloc(sizeof(*lltask));636 lltask = av_malloc(sizeof(*lltask));
617 if (!lltask) {637 if (!lltask) {
618 return DNN_ERROR;638 return AVERROR(ENOMEM);
619 }639 }
620 task->inference_todo++;640 task->inference_todo++;
621 lltask->task = task;641 lltask->task = task;
622 lltask->bbox_index = i;642 lltask->bbox_index = i;
623 if (ff_queue_push_back(lltask_queue, lltask) < 0) {643 if (ff_queue_push_back(lltask_queue, lltask) < 0) {
624 av_freep(&lltask);644 av_freep(&lltask);
625 return DNN_ERROR;645 return AVERROR(ENOMEM);
626 }646 }
627 }647 }
628 return DNN_SUCCESS;648 return DNN_SUCCESS;
629 }649 }
630 default:650 default:
631 av_assert0(!"should not reach here");651 av_assert0(!"should not reach here");
632 return DNN_ERROR;652 return AVERROR(EINVAL);
633 }653 }
634}654}
635 655
636static DNNReturnType get_output_ov(void *model, const char *input_name, int input_width, int input_height,656static int get_output_ov(void *model, const char *input_name, int input_width, int input_height,
637 const char *output_name, int *output_width, int *output_height)657 const char *output_name, int *output_width, int *output_height)
638{658{
639 DNNReturnType ret;659 int ret;
640 OVModel *ov_model = model;660 OVModel *ov_model = model;
641 OVContext *ctx = &ov_model->ctx;661 OVContext *ctx = &ov_model->ctx;
642 TaskItem task;662 TaskItem task;
@@ -653,7 +673,7 @@ static DNNReturnType get_output_ov(void *model, const char *input_name, int inpu · 10 unmodified lines
653 673
654 if (ov_model->model->func_type != DFT_PROCESS_FRAME) {674 if (ov_model->model->func_type != DFT_PROCESS_FRAME) {
655 av_log(ctx, AV_LOG_ERROR, "Get output dim only when processing frame.\n");675 av_log(ctx, AV_LOG_ERROR, "Get output dim only when processing frame.\n");
656 return DNN_ERROR;676 return AVERROR(EINVAL);
657 }677 }
658 678
659 if (ctx->options.input_resizable) {679 if (ctx->options.input_resizable) {
@@ -664,31 +684,33 @@ static DNNReturnType get_output_ov(void *model, const char *input_name, int inpu · 4 unmodified lines
664 ie_network_input_shapes_free(&input_shapes);684 ie_network_input_shapes_free(&input_shapes);
665 if (status != OK) {685 if (status != OK) {
666 av_log(ctx, AV_LOG_ERROR, "Failed to reshape input size for %s\n", input_name);686 av_log(ctx, AV_LOG_ERROR, "Failed to reshape input size for %s\n", input_name);
667 return DNN_ERROR;687 return DNN_GENERIC_ERROR;
668 }688 }
669 }689 }
670 690
671 if (!ov_model->exe_network) {691 if (!ov_model->exe_network) {
672 if (init_model_ov(ov_model, input_name, output_name) != DNN_SUCCESS) {692 ret = init_model_ov(ov_model, input_name, output_name);
693 if (ret != DNN_SUCCESS) {
673 av_log(ctx, AV_LOG_ERROR, "Failed init OpenVINO exectuable network or inference request\n");694 av_log(ctx, AV_LOG_ERROR, "Failed init OpenVINO exectuable network or inference request\n");
674 return DNN_ERROR;695 return ret;
675 }696 }
676 }697 }
677 698
678 if (ff_dnn_fill_gettingoutput_task(&task, &exec_params, ov_model, input_height, input_width, ctx) != DNN_SUCCESS) {699 ret = ff_dnn_fill_gettingoutput_task(&task, &exec_params, ov_model, input_height, input_width, ctx);
679 return DNN_ERROR;700 if (ret != DNN_SUCCESS) {
701 goto err;
680 }702 }
681 703
682 if (extract_lltask_from_task(ov_model->model->func_type, &task, ov_model->lltask_queue, NULL) != DNN_SUCCESS) {704 ret = extract_lltask_from_task(ov_model->model->func_type, &task, ov_model->lltask_queue, NULL);
683 av_log(ctx, AV_LOG_ERROR, "unable to extract last level task from task.\n");705 if (ret != DNN_SUCCESS) {
684 ret = DNN_ERROR;706 av_log(ctx, AV_LOG_ERROR, "unable to extract inference from task.\n");
685 goto err;707 goto err;
686 }708 }
687 709
688 request = ff_safe_queue_pop_front(ov_model->request_queue);710 request = ff_safe_queue_pop_front(ov_model->request_queue);
689 if (!request) {711 if (!request) {
690 av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n");712 av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n");
691 ret = DNN_ERROR;713 ret = AVERROR(EINVAL);
692 goto err;714 goto err;
693 }715 }
694 716
@@ -758,45 +780,49 @@ err: · 63 unmodified lines
758 return NULL;780 return NULL;
759}781}
760 782
761DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams *exec_params)783int ff_dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams *exec_params)
762{784{
763 OVModel *ov_model = model->model;785 OVModel *ov_model = model->model;
764 OVContext *ctx = &ov_model->ctx;786 OVContext *ctx = &ov_model->ctx;
765 OVRequestItem *request;787 OVRequestItem *request;
766 TaskItem *task;788 TaskItem *task;
767 DNNReturnType ret;789 int ret;
768 790
769 if (ff_check_exec_params(ctx, DNN_OV, model->func_type, exec_params) != 0) {791 ret = ff_check_exec_params(ctx, DNN_OV, model->func_type, exec_params);
770 return DNN_ERROR;792 if (ret != 0) {
793 return ret;
771 }794 }
772 795
773 if (!ov_model->exe_network) {796 if (!ov_model->exe_network) {
774 if (init_model_ov(ov_model, exec_params->input_name, exec_params->output_names[0]) != DNN_SUCCESS) {797 ret = init_model_ov(ov_model, exec_params->input_name, exec_params->output_names[0]);
798 if (ret != DNN_SUCCESS) {
775 av_log(ctx, AV_LOG_ERROR, "Failed init OpenVINO exectuable network or inference request\n");799 av_log(ctx, AV_LOG_ERROR, "Failed init OpenVINO exectuable network or inference request\n");
776 return DNN_ERROR;800 return ret;
777 }801 }
778 }802 }
779 803
780 task = av_malloc(sizeof(*task));804 task = av_malloc(sizeof(*task));
781 if (!task) {805 if (!task) {
782 av_log(ctx, AV_LOG_ERROR, "unable to alloc memory for task item.\n");806 av_log(ctx, AV_LOG_ERROR, "unable to alloc memory for task item.\n");
783 return DNN_ERROR;807 return AVERROR(ENOMEM);
784 }808 }
785 809
786 if (ff_dnn_fill_task(task, exec_params, ov_model, ctx->options.async, 1) != DNN_SUCCESS) {810 ret = ff_dnn_fill_task(task, exec_params, ov_model, ctx->options.async, 1);
811 if (ret != DNN_SUCCESS) {
787 av_freep(&task);812 av_freep(&task);
788 return DNN_ERROR;813 return ret;
789 }814 }
790 815
791 if (ff_queue_push_back(ov_model->task_queue, task) < 0) {816 if (ff_queue_push_back(ov_model->task_queue, task) < 0) {
792 av_freep(&task);817 av_freep(&task);
793 av_log(ctx, AV_LOG_ERROR, "unable to push back task_queue.\n");818 av_log(ctx, AV_LOG_ERROR, "unable to push back task_queue.\n");
794 return DNN_ERROR;819 return AVERROR(ENOMEM);
795 }820 }
796 821
797 if (extract_lltask_from_task(model->func_type, task, ov_model->lltask_queue, exec_params) != DNN_SUCCESS) {822 ret = extract_lltask_from_task(model->func_type, task, ov_model->lltask_queue, exec_params);
823 if (ret != DNN_SUCCESS) {
798 av_log(ctx, AV_LOG_ERROR, "unable to extract inference from task.\n");824 av_log(ctx, AV_LOG_ERROR, "unable to extract inference from task.\n");
799 return DNN_ERROR;825 return ret;
800 }826 }
801 827
802 if (ctx->options.async) {828 if (ctx->options.async) {
@@ -804,7 +830,7 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams * · 1 unmodified line
804 request = ff_safe_queue_pop_front(ov_model->request_queue);830 request = ff_safe_queue_pop_front(ov_model->request_queue);
805 if (!request) {831 if (!request) {
806 av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n");832 av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n");
807 return DNN_ERROR;833 return AVERROR(EINVAL);
808 }834 }
809 835
810 ret = execute_model_ov(request, ov_model->lltask_queue);836 ret = execute_model_ov(request, ov_model->lltask_queue);
@@ -820,18 +846,18 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams * · 9 unmodified lines
820 // Classification filter has not been completely846 // Classification filter has not been completely
821 // tested with the sync mode. So, do not support now.847 // tested with the sync mode. So, do not support now.
822 avpriv_report_missing_feature(ctx, "classify for sync execution");848 avpriv_report_missing_feature(ctx, "classify for sync execution");
823 return DNN_ERROR;849 return AVERROR(ENOSYS);
824 }850 }
825 851
826 if (ctx->options.batch_size > 1) {852 if (ctx->options.batch_size > 1) {
827 avpriv_report_missing_feature(ctx, "batch mode for sync execution");853 avpriv_report_missing_feature(ctx, "batch mode for sync execution");
828 return DNN_ERROR;854 return AVERROR(ENOSYS);
829 }855 }
830 856
831 request = ff_safe_queue_pop_front(ov_model->request_queue);857 request = ff_safe_queue_pop_front(ov_model->request_queue);
832 if (!request) {858 if (!request) {
833 av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n");859 av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n");
834 return DNN_ERROR;860 return AVERROR(EINVAL);
835 }861 }
836 return execute_model_ov(request, ov_model->lltask_queue);862 return execute_model_ov(request, ov_model->lltask_queue);
837 }863 }
@@ -843,13 +869,13 @@ DNNAsyncStatusType ff_dnn_get_result_ov(const DNNModel *model, AVFrame **in, AVF · 5 unmodified lines
843 return ff_dnn_get_result_common(ov_model->task_queue, in, out);869 return ff_dnn_get_result_common(ov_model->task_queue, in, out);
844}870}
845 871
846DNNReturnType ff_dnn_flush_ov(const DNNModel *model)872int ff_dnn_flush_ov(const DNNModel *model)
847{873{
848 OVModel *ov_model = model->model;874 OVModel *ov_model = model->model;
849 OVContext *ctx = &ov_model->ctx;875 OVContext *ctx = &ov_model->ctx;
850 OVRequestItem *request;876 OVRequestItem *request;
851 IEStatusCode status;877 IEStatusCode status;
852 DNNReturnType ret;878 int ret;
853 879
854 if (ff_queue_size(ov_model->lltask_queue) == 0) {880 if (ff_queue_size(ov_model->lltask_queue) == 0) {
855 // no pending task need to flush881 // no pending task need to flush
@@ -859,7 +885,7 @@ DNNReturnType ff_dnn_flush_ov(const DNNModel *model) · 3 unmodified lines
859 request = ff_safe_queue_pop_front(ov_model->request_queue);885 request = ff_safe_queue_pop_front(ov_model->request_queue);
860 if (!request) {886 if (!request) {
861 av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n");887 av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n");
862 return DNN_ERROR;888 return AVERROR(EINVAL);
863 }889 }
864 890
865 ret = fill_model_input_ov(ov_model, request);891 ret = fill_model_input_ov(ov_model, request);
@@ -870,12 +896,12 @@ DNNReturnType ff_dnn_flush_ov(const DNNModel *model) · 4 unmodified lines
870 status = ie_infer_set_completion_callback(request->infer_request, &request->callback);896 status = ie_infer_set_completion_callback(request->infer_request, &request->callback);
871 if (status != OK) {897 if (status != OK) {
872 av_log(ctx, AV_LOG_ERROR, "Failed to set completion callback for inference\n");898 av_log(ctx, AV_LOG_ERROR, "Failed to set completion callback for inference\n");
873 return DNN_ERROR;899 return DNN_GENERIC_ERROR;
874 }900 }
875 status = ie_infer_request_infer_async(request->infer_request);901 status = ie_infer_request_infer_async(request->infer_request);
876 if (status != OK) {902 if (status != OK) {
877 av_log(ctx, AV_LOG_ERROR, "Failed to start async inference\n");903 av_log(ctx, AV_LOG_ERROR, "Failed to start async inference\n");
878 return DNN_ERROR;904 return DNN_GENERIC_ERROR;
879 }905 }
880 906
881 return DNN_SUCCESS;907 return DNN_SUCCESS;
libavfilter/dnn/dnn_backend_openvino.h+2−2
@@ -31,9 +31,9 @@ · 30 unmodified lines
31 31
32DNNModel *ff_dnn_load_model_ov(const char *model_filename, DNNFunctionType func_type, const char *options, AVFilterContext *filter_ctx);32DNNModel *ff_dnn_load_model_ov(const char *model_filename, DNNFunctionType func_type, const char *options, AVFilterContext *filter_ctx);
33 33
34DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams *exec_params);34int ff_dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams *exec_params);
35DNNAsyncStatusType ff_dnn_get_result_ov(const DNNModel *model, AVFrame **in, AVFrame **out);35DNNAsyncStatusType ff_dnn_get_result_ov(const DNNModel *model, AVFrame **in, AVFrame **out);
36DNNReturnType ff_dnn_flush_ov(const DNNModel *model);36int ff_dnn_flush_ov(const DNNModel *model);
37 37
38void ff_dnn_free_model_ov(DNNModel **model);38void ff_dnn_free_model_ov(DNNModel **model);
39 39
libavfilter/dnn_interface.h+5−5
@@ -94,9 +94,9 @@ typedef struct DNNModel{ · 93 unmodified lines
94 DNNFunctionType func_type;94 DNNFunctionType func_type;
95 // Gets model input information95 // Gets model input information
96 // Just reuse struct DNNData here, actually the DNNData.data field is not needed.96 // Just reuse struct DNNData here, actually the DNNData.data field is not needed.
97 DNNReturnType (*get_input)(void *model, DNNData *input, const char *input_name);97 int (*get_input)(void *model, DNNData *input, const char *input_name);
98 // Gets model output width/height with given input w/h98 // Gets model output width/height with given input w/h
99 DNNReturnType (*get_output)(void *model, const char *input_name, int input_width, int input_height,99 int (*get_output)(void *model, const char *input_name, int input_width, int input_height,
100 const char *output_name, int *output_width, int *output_height);100 const char *output_name, int *output_width, int *output_height);
101 // set the pre process to transfer data from AVFrame to DNNData101 // set the pre process to transfer data from AVFrame to DNNData
102 // the default implementation within DNN is used if it is not provided by the filter102 // the default implementation within DNN is used if it is not provided by the filter
@@ -114,12 +114,12 @@ typedef struct DNNModel{ · 11 unmodified lines
114typedef struct DNNModule{114typedef struct DNNModule{
115 // Loads model and parameters from given file. Returns NULL if it is not possible.115 // Loads model and parameters from given file. Returns NULL if it is not possible.
116 DNNModel *(*load_model)(const char *model_filename, DNNFunctionType func_type, const char *options, AVFilterContext *filter_ctx);116 DNNModel *(*load_model)(const char *model_filename, DNNFunctionType func_type, const char *options, AVFilterContext *filter_ctx);
117 // Executes model with specified input and output. Returns DNN_ERROR otherwise.117 // Executes model with specified input and output. Returns the error code otherwise.
118 DNNReturnType (*execute_model)(const DNNModel *model, DNNExecBaseParams *exec_params);118 int (*execute_model)(const DNNModel *model, DNNExecBaseParams *exec_params);
119 // Retrieve inference result.119 // Retrieve inference result.
120 DNNAsyncStatusType (*get_result)(const DNNModel *model, AVFrame **in, AVFrame **out);120 DNNAsyncStatusType (*get_result)(const DNNModel *model, AVFrame **in, AVFrame **out);
121 // Flush all the pending tasks.121 // Flush all the pending tasks.
122 DNNReturnType (*flush)(const DNNModel *model);122 int (*flush)(const DNNModel *model);
123 // Frees memory allocated for model.123 // Frees memory allocated for model.
124 void (*free_model)(DNNModel **model);124 void (*free_model)(DNNModel **model);
125} DNNModule;125} DNNModule;

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