[FFmpeg-cvslog] dnn: add userdata for load model parameter

Guo, Yejun git at videolan.org
Mon Sep 21 16:44:29 EEST 2020


ffmpeg | branch: master | Guo, Yejun <yejun.guo at intel.com> | Mon Aug 24 16:09:59 2020 +0800| [6918e240d706f7390272976d8b8d502afe426a18] | committer: Guo, Yejun

dnn: add userdata for load model parameter

the userdata will be used for the interaction between AVFrame and DNNData

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6918e240d706f7390272976d8b8d502afe426a18
---

 libavfilter/dnn/dnn_backend_native.c   | 3 ++-
 libavfilter/dnn/dnn_backend_native.h   | 2 +-
 libavfilter/dnn/dnn_backend_openvino.c | 3 ++-
 libavfilter/dnn/dnn_backend_openvino.h | 2 +-
 libavfilter/dnn/dnn_backend_tf.c       | 5 +++--
 libavfilter/dnn/dnn_backend_tf.h       | 2 +-
 libavfilter/dnn_interface.h            | 4 +++-
 libavfilter/vf_derain.c                | 2 +-
 libavfilter/vf_dnn_processing.c        | 2 +-
 libavfilter/vf_sr.c                    | 2 +-
 10 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_native.c b/libavfilter/dnn/dnn_backend_native.c
index a9ecbdc88b..830ec19c80 100644
--- a/libavfilter/dnn/dnn_backend_native.c
+++ b/libavfilter/dnn/dnn_backend_native.c
@@ -123,7 +123,7 @@ static DNNReturnType set_input_native(void *model, DNNData *input, const char *i
 // layers_num,layer_type,layer_parameterss,layer_type,layer_parameters...
 // For CONV layer: activation_function, input_num, output_num, kernel_size, kernel, biases
 // For DEPTH_TO_SPACE layer: block_size
-DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *options)
+DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *options, void *userdata)
 {
     DNNModel *model = NULL;
     char header_expected[] = "FFMPEGDNNNATIVE";
@@ -265,6 +265,7 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *optio
 
     model->set_input = &set_input_native;
     model->get_input = &get_input_native;
+    model->userdata = userdata;
 
     return model;
 
diff --git a/libavfilter/dnn/dnn_backend_native.h b/libavfilter/dnn/dnn_backend_native.h
index b1f8f3d6bf..33634118a8 100644
--- a/libavfilter/dnn/dnn_backend_native.h
+++ b/libavfilter/dnn/dnn_backend_native.h
@@ -125,7 +125,7 @@ typedef struct NativeModel{
     int32_t operands_num;
 } NativeModel;
 
-DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *options);
+DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *options, void *userdata);
 
 DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output);
 
diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c
index e5842906d1..01e1a1d4c8 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -174,7 +174,7 @@ err:
     return DNN_ERROR;
 }
 
-DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options)
+DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options, void *userdata)
 {
     char *all_dev_names = NULL;
     DNNModel *model = NULL;
@@ -230,6 +230,7 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options)
     model->set_input = &set_input_ov;
     model->get_input = &get_input_ov;
     model->options = options;
+    model->userdata = userdata;
 
     return model;
 
diff --git a/libavfilter/dnn/dnn_backend_openvino.h b/libavfilter/dnn/dnn_backend_openvino.h
index b2a86e0125..f69bc5ca0c 100644
--- a/libavfilter/dnn/dnn_backend_openvino.h
+++ b/libavfilter/dnn/dnn_backend_openvino.h
@@ -29,7 +29,7 @@
 
 #include "../dnn_interface.h"
 
-DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options);
+DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options, void *userdata);
 
 DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output);
 
diff --git a/libavfilter/dnn/dnn_backend_tf.c b/libavfilter/dnn/dnn_backend_tf.c
index 5e7f37bb12..bac7d8c420 100644
--- a/libavfilter/dnn/dnn_backend_tf.c
+++ b/libavfilter/dnn/dnn_backend_tf.c
@@ -502,7 +502,7 @@ static DNNReturnType load_native_model(TFModel *tf_model, const char *model_file
     DNNModel *model = NULL;
     NativeModel *native_model;
 
-    model = ff_dnn_load_model_native(model_filename, NULL);
+    model = ff_dnn_load_model_native(model_filename, NULL, NULL);
     if (!model){
         av_log(ctx, AV_LOG_ERROR, "Failed to load native model\n");
         return DNN_ERROR;
@@ -586,7 +586,7 @@ static DNNReturnType load_native_model(TFModel *tf_model, const char *model_file
     return DNN_SUCCESS;
 }
 
-DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options)
+DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options, void *userdata)
 {
     DNNModel *model = NULL;
     TFModel *tf_model = NULL;
@@ -616,6 +616,7 @@ DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options)
     model->set_input = &set_input_tf;
     model->get_input = &get_input_tf;
     model->options = options;
+    model->userdata = userdata;
 
     return model;
 }
diff --git a/libavfilter/dnn/dnn_backend_tf.h b/libavfilter/dnn/dnn_backend_tf.h
index 6c7b6d2590..1cf5cc9e76 100644
--- a/libavfilter/dnn/dnn_backend_tf.h
+++ b/libavfilter/dnn/dnn_backend_tf.h
@@ -29,7 +29,7 @@
 
 #include "../dnn_interface.h"
 
-DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options);
+DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options, void *userdata);
 
 DNNReturnType ff_dnn_execute_model_tf(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output);
 
diff --git a/libavfilter/dnn_interface.h b/libavfilter/dnn_interface.h
index 365c9a4729..702c8306e0 100644
--- a/libavfilter/dnn_interface.h
+++ b/libavfilter/dnn_interface.h
@@ -45,6 +45,8 @@ typedef struct DNNModel{
     void *model;
     // Stores options when the model is executed by the backend
     const char *options;
+    // Stores userdata used for the interaction between AVFrame and DNNData
+    void *userdata;
     // Gets model input information
     // Just reuse struct DNNData here, actually the DNNData.data field is not needed.
     DNNReturnType (*get_input)(void *model, DNNData *input, const char *input_name);
@@ -56,7 +58,7 @@ typedef struct DNNModel{
 // Stores pointers to functions for loading, executing, freeing DNN models for one of the backends.
 typedef struct DNNModule{
     // Loads model and parameters from given file. Returns NULL if it is not possible.
-    DNNModel *(*load_model)(const char *model_filename, const char *options);
+    DNNModel *(*load_model)(const char *model_filename, const char *options, void *userdata);
     // Executes model with specified input and output. Returns DNN_ERROR otherwise.
     DNNReturnType (*execute_model)(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output);
     // Frees memory allocated for model.
diff --git a/libavfilter/vf_derain.c b/libavfilter/vf_derain.c
index ff7d8d6308..c251d55ee7 100644
--- a/libavfilter/vf_derain.c
+++ b/libavfilter/vf_derain.c
@@ -161,7 +161,7 @@ static av_cold int init(AVFilterContext *ctx)
         return AVERROR(EINVAL);
     }
 
-    dr_context->model = (dr_context->dnn_module->load_model)(dr_context->model_filename, NULL);
+    dr_context->model = (dr_context->dnn_module->load_model)(dr_context->model_filename, NULL, NULL);
     if (!dr_context->model) {
         av_log(ctx, AV_LOG_ERROR, "could not load DNN model\n");
         return AVERROR(EINVAL);
diff --git a/libavfilter/vf_dnn_processing.c b/libavfilter/vf_dnn_processing.c
index f78800f7c0..f120bf9df4 100644
--- a/libavfilter/vf_dnn_processing.c
+++ b/libavfilter/vf_dnn_processing.c
@@ -103,7 +103,7 @@ static av_cold int init(AVFilterContext *context)
         return AVERROR(EINVAL);
     }
 
-    ctx->model = (ctx->dnn_module->load_model)(ctx->model_filename, ctx->backend_options);
+    ctx->model = (ctx->dnn_module->load_model)(ctx->model_filename, ctx->backend_options, NULL);
     if (!ctx->model) {
         av_log(ctx, AV_LOG_ERROR, "could not load DNN model\n");
         return AVERROR(EINVAL);
diff --git a/libavfilter/vf_sr.c b/libavfilter/vf_sr.c
index 37e1107145..445777f0c6 100644
--- a/libavfilter/vf_sr.c
+++ b/libavfilter/vf_sr.c
@@ -81,7 +81,7 @@ static av_cold int init(AVFilterContext *context)
         av_log(context, AV_LOG_ERROR, "load_model for network was not specified\n");
         return AVERROR(EIO);
     }
-    sr_context->model = (sr_context->dnn_module->load_model)(sr_context->model_filename, NULL);
+    sr_context->model = (sr_context->dnn_module->load_model)(sr_context->model_filename, NULL, NULL);
     if (!sr_context->model){
         av_log(context, AV_LOG_ERROR, "could not load DNN model\n");
         return AVERROR(EIO);



More information about the ffmpeg-cvslog mailing list