]> git.sesse.net Git - ffmpeg/commitdiff
dnn_interface: change from 'void *userdata' to 'AVFilterContext *filter_ctx'
authorGuo, Yejun <yejun.guo@intel.com>
Wed, 18 Nov 2020 06:54:10 +0000 (14:54 +0800)
committerGuo, Yejun <yejun.guo@intel.com>
Tue, 29 Dec 2020 01:31:06 +0000 (09:31 +0800)
'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
libavfilter/dnn/dnn_backend_native.h
libavfilter/dnn/dnn_backend_openvino.c
libavfilter/dnn/dnn_backend_openvino.h
libavfilter/dnn/dnn_backend_tf.c
libavfilter/dnn/dnn_backend_tf.h
libavfilter/dnn_interface.h
libavfilter/vf_dnn_processing.c

index 4fc3ba2044b5fdc02ed5e44dc52bfa0b6b4b2a00..5e7fc0f10c589dbef72f575229682dd090f30f25 100644 (file)
@@ -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);
             }
index 2d02c063d477392632ba594d3dd5325a88b70762..5acdbe0da7d3442d02575a76c19ced60e87fef6e 100644 (file)
@@ -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);
index 8c3ba8a6a881633c9cfbce76f7b352d24f75e753..a35d72a38cde999349483db578cc5b3c90a82f06 100644 (file)
@@ -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;
 
index 2f88e49a08a5322dbf7ad79968674d8084ff7e2f..1b70150040a58b45cf398ba195d035676b833564 100644 (file)
@@ -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);
index 76cc037b940b7a43f606954389227835e42cad19..b9fe01693be3b8dee22c6209b83b1020eeee3c54 100644 (file)
@@ -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);
             }
index 1e006697360eeba3b414e0ed8ec96748678352d9..cac893672954497b500002f1df12ad0cc4fc4621 100644 (file)
@@ -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);
index 33d55703d260be3c96111b50860e12033f1bf111..1e2842425a38407e2a214e1fdd5dd518669b7b8b 100644 (file)
@@ -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);
index 5aad899dd02088a8e4190bff7302208d5a8d19b9..342b06e6ae165b414417c3e1d07284cd424379b4 100644 (file)
@@ -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);