1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-28 20:53:54 +02:00

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>
This commit is contained in:
Zhao Zhili 2024-05-08 00:08:09 +08:00 committed by Guo Yejun
parent fa3b153cb1
commit 4f051c746b
5 changed files with 12 additions and 18 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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)

View File

@ -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.