// 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";
model->get_input = &get_input_native;
model->get_output = &get_output_native;
- model->userdata = userdata;
+ model->filter_ctx = filter_ctx;
return model;
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);
}
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);
}
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);
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);
}
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);
}
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;
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;
#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);
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;
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;
}
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);
}
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);
}
#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);
#include <stdint.h>
#include "libavutil/frame.h"
+typedef struct AVFilterContext AVFilterContext;
typedef enum {DNN_SUCCESS, DNN_ERROR} DNNReturnType;
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);
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);
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);