diff mbox series

[FFmpeg-devel,7/8] dnn_interface: change from 'void *userdata' to 'AVFilterContext *filter_ctx'

Message ID 20201222074708.6459-1-yejun.guo@intel.com
State Accepted
Commit 5024286465acc35ae005715e0152a135df30ad0a
Headers show
Series [FFmpeg-devel,1/8] vf_dnn_processing.c: replace filter_frame with activate func
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Guo, Yejun Dec. 22, 2020, 7:47 a.m. UTC
'void *' is too flexible, since we can derive info from
AVFilterContext*, so we just unify the interface with this data
structure.

Signed-off-by: Xie, Lin <lin.xie@intel.com>
Signed-off-by: Wu Zhiwen <zhiwen.wu@intel.com>
Signed-off-by: Guo, Yejun <yejun.guo@intel.com>
---
 libavfilter/dnn/dnn_backend_native.c   |  8 ++++----
 libavfilter/dnn/dnn_backend_native.h   |  2 +-
 libavfilter/dnn/dnn_backend_openvino.c |  8 ++++----
 libavfilter/dnn/dnn_backend_openvino.h |  2 +-
 libavfilter/dnn/dnn_backend_tf.c       |  8 ++++----
 libavfilter/dnn/dnn_backend_tf.h       |  2 +-
 libavfilter/dnn_interface.h            | 11 ++++++-----
 libavfilter/vf_dnn_processing.c        |  2 +-
 8 files changed, 22 insertions(+), 21 deletions(-)
diff mbox series

Patch

diff --git a/libavfilter/dnn/dnn_backend_native.c b/libavfilter/dnn/dnn_backend_native.c
index 4fc3ba2044..5e7fc0f10c 100644
--- a/libavfilter/dnn/dnn_backend_native.c
+++ b/libavfilter/dnn/dnn_backend_native.c
@@ -112,7 +112,7 @@  static DNNReturnType get_output_native(void *model, const char *input_name, int
 // 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, void *userdata)
+DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *options, AVFilterContext *filter_ctx)
 {
     DNNModel *model = NULL;
     char header_expected[] = "FFMPEGDNNNATIVE";
@@ -255,7 +255,7 @@  DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *optio
 
     model->get_input = &get_input_native;
     model->get_output = &get_output_native;
-    model->userdata = userdata;
+    model->filter_ctx = filter_ctx;
 
     return model;
 
@@ -318,7 +318,7 @@  static DNNReturnType execute_model_native(const DNNModel *model, const char *inp
     input.dt = oprd->data_type;
     if (do_ioproc) {
         if (native_model->model->pre_proc != NULL) {
-            native_model->model->pre_proc(in_frame, &input, native_model->model->userdata);
+            native_model->model->pre_proc(in_frame, &input, native_model->model->filter_ctx);
         } else {
             proc_from_frame_to_dnn(in_frame, &input, ctx);
         }
@@ -366,7 +366,7 @@  static DNNReturnType execute_model_native(const DNNModel *model, const char *inp
 
         if (do_ioproc) {
             if (native_model->model->post_proc != NULL) {
-                native_model->model->post_proc(out_frame, &output, native_model->model->userdata);
+                native_model->model->post_proc(out_frame, &output, native_model->model->filter_ctx);
             } else {
                 proc_from_dnn_to_frame(out_frame, &output, ctx);
             }
diff --git a/libavfilter/dnn/dnn_backend_native.h b/libavfilter/dnn/dnn_backend_native.h
index 2d02c063d4..5acdbe0da7 100644
--- a/libavfilter/dnn/dnn_backend_native.h
+++ b/libavfilter/dnn/dnn_backend_native.h
@@ -128,7 +128,7 @@  typedef struct NativeModel{
     int32_t operands_num;
 } NativeModel;
 
-DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *options, void *userdata);
+DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *options, AVFilterContext *filter_ctx);
 
 DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, const char *input_name, AVFrame *in_frame,
                                           const char **output_names, uint32_t nb_output, AVFrame *out_frame);
diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c
index 8c3ba8a6a8..a35d72a38c 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -136,7 +136,7 @@  static DNNReturnType fill_model_input_ov(OVModel *ov_model, TaskItem *task, Requ
     input.dt = precision_to_datatype(precision);
     if (task->do_ioproc) {
         if (ov_model->model->pre_proc != NULL) {
-            ov_model->model->pre_proc(task->in_frame, &input, ov_model->model->userdata);
+            ov_model->model->pre_proc(task->in_frame, &input, ov_model->model->filter_ctx);
         } else {
             proc_from_frame_to_dnn(task->in_frame, &input, ctx);
         }
@@ -196,7 +196,7 @@  static void infer_completion_callback(void *args)
     output.data     = blob_buffer.buffer;
     if (task->do_ioproc) {
         if (task->ov_model->model->post_proc != NULL) {
-            task->ov_model->model->post_proc(task->out_frame, &output, task->ov_model->model->userdata);
+            task->ov_model->model->post_proc(task->out_frame, &output, task->ov_model->model->filter_ctx);
         } else {
             proc_from_dnn_to_frame(task->out_frame, &output, ctx);
         }
@@ -350,7 +350,7 @@  static DNNReturnType get_output_ov(void *model, const char *input_name, int inpu
     return ret;
 }
 
-DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options, void *userdata)
+DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options, AVFilterContext *filter_ctx)
 {
     char *all_dev_names = NULL;
     DNNModel *model = NULL;
@@ -447,7 +447,7 @@  DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options,
     model->get_input = &get_input_ov;
     model->get_output = &get_output_ov;
     model->options = options;
-    model->userdata = userdata;
+    model->filter_ctx = filter_ctx;
 
     return model;
 
diff --git a/libavfilter/dnn/dnn_backend_openvino.h b/libavfilter/dnn/dnn_backend_openvino.h
index 2f88e49a08..1b70150040 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, void *userdata);
+DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options, AVFilterContext *filter_ctx);
 
 DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, const char *input_name, AVFrame *in_frame,
                                       const char **output_names, uint32_t nb_output, AVFrame *out_frame);
diff --git a/libavfilter/dnn/dnn_backend_tf.c b/libavfilter/dnn/dnn_backend_tf.c
index 76cc037b94..b9fe01693b 100644
--- a/libavfilter/dnn/dnn_backend_tf.c
+++ b/libavfilter/dnn/dnn_backend_tf.c
@@ -664,7 +664,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, void *userdata)
+DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options, AVFilterContext *filter_ctx)
 {
     DNNModel *model = NULL;
     TFModel *tf_model = NULL;
@@ -704,7 +704,7 @@  DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options,
     model->get_input = &get_input_tf;
     model->get_output = &get_output_tf;
     model->options = options;
-    model->userdata = userdata;
+    model->filter_ctx = filter_ctx;
 
     return model;
 }
@@ -741,7 +741,7 @@  static DNNReturnType execute_model_tf(const DNNModel *model, const char *input_n
 
     if (do_ioproc) {
         if (tf_model->model->pre_proc != NULL) {
-            tf_model->model->pre_proc(in_frame, &input, tf_model->model->userdata);
+            tf_model->model->pre_proc(in_frame, &input, tf_model->model->filter_ctx);
         } else {
             proc_from_frame_to_dnn(in_frame, &input, ctx);
         }
@@ -798,7 +798,7 @@  static DNNReturnType execute_model_tf(const DNNModel *model, const char *input_n
 
         if (do_ioproc) {
             if (tf_model->model->post_proc != NULL) {
-                tf_model->model->post_proc(out_frame, &output, tf_model->model->userdata);
+                tf_model->model->post_proc(out_frame, &output, tf_model->model->filter_ctx);
             } else {
                 proc_from_dnn_to_frame(out_frame, &output, ctx);
             }
diff --git a/libavfilter/dnn/dnn_backend_tf.h b/libavfilter/dnn/dnn_backend_tf.h
index 1e00669736..cac8936729 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, void *userdata);
+DNNModel *ff_dnn_load_model_tf(const char *model_filename, const char *options, AVFilterContext *filter_ctx);
 
 DNNReturnType ff_dnn_execute_model_tf(const DNNModel *model, const char *input_name, AVFrame *in_frame,
                                       const char **output_names, uint32_t nb_output, AVFrame *out_frame);
diff --git a/libavfilter/dnn_interface.h b/libavfilter/dnn_interface.h
index 33d55703d2..1e2842425a 100644
--- a/libavfilter/dnn_interface.h
+++ b/libavfilter/dnn_interface.h
@@ -28,6 +28,7 @@ 
 
 #include <stdint.h>
 #include "libavutil/frame.h"
+typedef struct AVFilterContext AVFilterContext;
 
 typedef enum {DNN_SUCCESS, DNN_ERROR} DNNReturnType;
 
@@ -53,8 +54,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;
+    // Stores FilterContext used for the interaction between AVFrame and DNNData
+    AVFilterContext *filter_ctx;
     // 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);
@@ -63,16 +64,16 @@  typedef struct DNNModel{
                                 const char *output_name, int *output_width, int *output_height);
     // set the pre process to transfer data from AVFrame to DNNData
     // the default implementation within DNN is used if it is not provided by the filter
-    int (*pre_proc)(AVFrame *frame_in, DNNData *model_input, void *user_data);
+    int (*pre_proc)(AVFrame *frame_in, DNNData *model_input, AVFilterContext *filter_ctx);
     // set the post process to transfer data from DNNData to AVFrame
     // the default implementation within DNN is used if it is not provided by the filter
-    int (*post_proc)(AVFrame *frame_out, DNNData *model_output, void *user_data);
+    int (*post_proc)(AVFrame *frame_out, DNNData *model_output, AVFilterContext *filter_ctx);
 } 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, void *userdata);
+    DNNModel *(*load_model)(const char *model_filename, const char *options, AVFilterContext *filter_ctx);
     // Executes model with specified input and output. Returns DNN_ERROR otherwise.
     DNNReturnType (*execute_model)(const DNNModel *model, const char *input_name, AVFrame *in_frame,
                                    const char **output_names, uint32_t nb_output, AVFrame *out_frame);
diff --git a/libavfilter/vf_dnn_processing.c b/libavfilter/vf_dnn_processing.c
index 5aad899dd0..342b06e6ae 100644
--- a/libavfilter/vf_dnn_processing.c
+++ b/libavfilter/vf_dnn_processing.c
@@ -97,7 +97,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);
+    ctx->model = (ctx->dnn_module->load_model)(ctx->model_filename, ctx->backend_options, context);
     if (!ctx->model) {
         av_log(ctx, AV_LOG_ERROR, "could not load DNN model\n");
         return AVERROR(EINVAL);