aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhao Zhili <zhilizhao@tencent.com>2024-05-08 00:08:09 +0800
committerGuo Yejun <yejun.guo@intel.com>2024-05-30 18:13:29 +0800
commit4f051c746be90e130c7b61a3ba2f15f2e832774d (patch)
tree73a91b3a25c6d013a71dcc112d8ea1a3b8803e76
parentfa3b153cb1eba0d68327c716842c9a38f95c1667 (diff)
downloadffmpeg-4f051c746be90e130c7b61a3ba2f15f2e832774d.tar.gz
avfilter/dnn: Use dnn_backend_info_list to search for dnn module
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> Reviewed-by: Wenbin Chen <wenbin.chen@intel.com> Reviewed-by: Guo Yejun <yejun.guo@intel.com>
-rw-r--r--libavfilter/dnn/dnn_backend_openvino.c1
-rw-r--r--libavfilter/dnn/dnn_backend_tf.c1
-rw-r--r--libavfilter/dnn/dnn_backend_torch.cpp1
-rw-r--r--libavfilter/dnn/dnn_interface.c26
-rw-r--r--libavfilter/dnn_interface.h1
5 files changed, 12 insertions, 18 deletions
diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c
index c4b0682f11..5ea8fb8d1f 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -1622,6 +1622,7 @@ static int dnn_flush_ov(const DNNModel *model)
const DNNModule ff_dnn_backend_openvino = {
.clazz = DNN_DEFINE_CLASS(dnn_openvino),
+ .type = DNN_OV,
.load_model = dnn_load_model_ov,
.execute_model = dnn_execute_model_ov,
.get_result = dnn_get_result_ov,
diff --git a/libavfilter/dnn/dnn_backend_tf.c b/libavfilter/dnn/dnn_backend_tf.c
index d24591b90b..0ab3bd13ed 100644
--- a/libavfilter/dnn/dnn_backend_tf.c
+++ b/libavfilter/dnn/dnn_backend_tf.c
@@ -893,6 +893,7 @@ static int dnn_flush_tf(const DNNModel *model)
const DNNModule ff_dnn_backend_tf = {
.clazz = DNN_DEFINE_CLASS(dnn_tensorflow),
+ .type = DNN_TF,
.load_model = dnn_load_model_tf,
.execute_model = dnn_execute_model_tf,
.get_result = dnn_get_result_tf,
diff --git a/libavfilter/dnn/dnn_backend_torch.cpp b/libavfilter/dnn/dnn_backend_torch.cpp
index abdef1f178..b70e4db600 100644
--- a/libavfilter/dnn/dnn_backend_torch.cpp
+++ b/libavfilter/dnn/dnn_backend_torch.cpp
@@ -569,6 +569,7 @@ static int dnn_flush_th(const DNNModel *model)
extern const DNNModule ff_dnn_backend_torch = {
.clazz = DNN_DEFINE_CLASS(dnn_th),
+ .type = DNN_TH,
.load_model = dnn_load_model_th,
.execute_model = dnn_execute_model_th,
.get_result = dnn_get_result_th,
diff --git a/libavfilter/dnn/dnn_interface.c b/libavfilter/dnn/dnn_interface.c
index e7453f1bb1..e9c3619abd 100644
--- a/libavfilter/dnn/dnn_interface.c
+++ b/libavfilter/dnn/dnn_interface.c
@@ -81,25 +81,15 @@ static const DnnBackendInfo dnn_backend_info_list[] = {
const DNNModule *ff_get_dnn_module(DNNBackendType backend_type, void *log_ctx)
{
- switch(backend_type){
- #if (CONFIG_LIBTENSORFLOW == 1)
- case DNN_TF:
- return &ff_dnn_backend_tf;
- #endif
- #if (CONFIG_LIBOPENVINO == 1)
- case DNN_OV:
- return &ff_dnn_backend_openvino;
- #endif
- #if (CONFIG_LIBTORCH == 1)
- case DNN_TH:
- return &ff_dnn_backend_torch;
- #endif
- default:
- av_log(log_ctx, AV_LOG_ERROR,
- "Module backend_type %d is not supported or enabled.\n",
- backend_type);
- return NULL;
+ for (int i = 1; i < FF_ARRAY_ELEMS(dnn_backend_info_list); i++) {
+ if (dnn_backend_info_list[i].module->type == backend_type)
+ return dnn_backend_info_list[i].module;
}
+
+ av_log(log_ctx, AV_LOG_ERROR,
+ "Module backend_type %d is not supported or enabled.\n",
+ backend_type);
+ return NULL;
}
void ff_dnn_init_child_class(DnnContext *ctx)
diff --git a/libavfilter/dnn_interface.h b/libavfilter/dnn_interface.h
index 4e544486cc..dd603534b2 100644
--- a/libavfilter/dnn_interface.h
+++ b/libavfilter/dnn_interface.h
@@ -172,6 +172,7 @@ typedef struct DnnContext {
// Stores pointers to functions for loading, executing, freeing DNN models for one of the backends.
struct DNNModule {
const AVClass clazz;
+ DNNBackendType type;
// Loads model and parameters from given file. Returns NULL if it is not possible.
DNNModel *(*load_model)(DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *filter_ctx);
// Executes model with specified input and output. Returns the error code otherwise.