summaryrefslogtreecommitdiff
path: root/libavfilter/dnn
diff options
context:
space:
mode:
authorShubhanshu Saxena <shubhanshu.e01@gmail.com>2021-06-05 23:38:06 +0530
committerGuo Yejun <yejun.guo@intel.com>2021-06-12 15:18:58 +0800
commit55092358189b98682d133c7b05bfcbb7ab6c750f (patch)
treecd5b0409a2ebcf54a8399354f62eea0abc7a8eb2 /libavfilter/dnn
parent6b961f74096aff114d32480670943ce4d6d66826 (diff)
lavfi/dnn: Fill Task using Common Function
This commit adds a common function for filling the TaskItems in all three backends. Signed-off-by: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
Diffstat (limited to 'libavfilter/dnn')
-rw-r--r--libavfilter/dnn/dnn_backend_common.c20
-rw-r--r--libavfilter/dnn/dnn_backend_common.h15
-rw-r--r--libavfilter/dnn/dnn_backend_openvino.c23
3 files changed, 42 insertions, 16 deletions
diff --git a/libavfilter/dnn/dnn_backend_common.c b/libavfilter/dnn/dnn_backend_common.c
index a522ab5650..4d9d3f79b1 100644
--- a/libavfilter/dnn/dnn_backend_common.c
+++ b/libavfilter/dnn/dnn_backend_common.c
@@ -49,3 +49,23 @@ int ff_check_exec_params(void *ctx, DNNBackendType backend, DNNFunctionType func
return 0;
}
+
+DNNReturnType ff_dnn_fill_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int async, int do_ioproc) {
+ if (task == NULL || exec_params == NULL || backend_model == NULL)
+ return DNN_ERROR;
+ if (do_ioproc != 0 && do_ioproc != 1)
+ return DNN_ERROR;
+ if (async != 0 && async != 1)
+ return DNN_ERROR;
+
+ task->do_ioproc = do_ioproc;
+ task->async = async;
+ task->input_name = exec_params->input_name;
+ task->in_frame = exec_params->in_frame;
+ task->out_frame = exec_params->out_frame;
+ task->model = backend_model;
+ task->nb_output = exec_params->nb_output;
+ task->output_names = exec_params->output_names;
+
+ return DNN_SUCCESS;
+}
diff --git a/libavfilter/dnn/dnn_backend_common.h b/libavfilter/dnn/dnn_backend_common.h
index d962312c16..df59615f40 100644
--- a/libavfilter/dnn/dnn_backend_common.h
+++ b/libavfilter/dnn/dnn_backend_common.h
@@ -48,4 +48,19 @@ typedef struct InferenceItem {
int ff_check_exec_params(void *ctx, DNNBackendType backend, DNNFunctionType func_type, DNNExecBaseParams *exec_params);
+/**
+ * Fill the Task for Backend Execution. It should be called after
+ * checking execution parameters using ff_check_exec_params.
+ *
+ * @param task pointer to the allocated task
+ * @param exec_param pointer to execution parameters
+ * @param backend_model void pointer to the backend model
+ * @param async flag for async execution. Must be 0 or 1
+ * @param do_ioproc flag for IO processing. Must be 0 or 1
+ *
+ * @retval DNN_SUCCESS if successful
+ * @retval DNN_ERROR if flags are invalid or any parameter is NULL
+ */
+DNNReturnType ff_dnn_fill_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int async, int do_ioproc);
+
#endif
diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c
index c2487c35be..709a772a4d 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -793,14 +793,9 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams *
}
}
- task.do_ioproc = 1;
- task.async = 0;
- task.input_name = exec_params->input_name;
- task.in_frame = exec_params->in_frame;
- task.output_names = &exec_params->output_names[0];
- task.out_frame = exec_params->out_frame ? exec_params->out_frame : exec_params->in_frame;
- task.nb_output = exec_params->nb_output;
- task.model = ov_model;
+ if (ff_dnn_fill_task(&task, exec_params, ov_model, 0, 1) != DNN_SUCCESS) {
+ return DNN_ERROR;
+ }
if (extract_inference_from_task(ov_model->model->func_type, &task, ov_model->inference_queue, exec_params) != DNN_SUCCESS) {
av_log(ctx, AV_LOG_ERROR, "unable to extract inference from task.\n");
@@ -841,14 +836,10 @@ DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, DNNExecBasePa
return DNN_ERROR;
}
- task->do_ioproc = 1;
- task->async = 1;
- task->input_name = exec_params->input_name;
- task->in_frame = exec_params->in_frame;
- task->output_names = &exec_params->output_names[0];
- task->out_frame = exec_params->out_frame ? exec_params->out_frame : exec_params->in_frame;
- task->nb_output = exec_params->nb_output;
- task->model = ov_model;
+ if (ff_dnn_fill_task(task, exec_params, ov_model, 1, 1) != DNN_SUCCESS) {
+ return DNN_ERROR;
+ }
+
if (ff_queue_push_back(ov_model->task_queue, task) < 0) {
av_freep(&task);
av_log(ctx, AV_LOG_ERROR, "unable to push back task_queue.\n");