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