mirror of
https://github.com/nyanmisaka/ffmpeg-rockchip.git
synced 2025-10-06 01:07:36 +08:00
dnn: change dnn interface to replace DNNData* with AVFrame*
Currently, every filter needs to provide code to transfer data from AVFrame* to model input (DNNData*), and also from model output (DNNData*) to AVFrame*. Actually, such transfer can be implemented within DNN module, and so filter can focus on its own business logic. DNN module also exports the function pointer pre_proc and post_proc in struct DNNModel, just in case that a filter has its special logic to transfer data between AVFrame* and DNNData*. The default implementation within DNN module is used if the filter does not set pre/post_proc.
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#define AVFILTER_DNN_INTERFACE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "libavutil/frame.h"
|
||||
|
||||
typedef enum {DNN_SUCCESS, DNN_ERROR} DNNReturnType;
|
||||
|
||||
@@ -50,17 +51,23 @@ typedef struct DNNModel{
|
||||
// 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);
|
||||
// Sets model input and output.
|
||||
// Should be called at least once before model execution.
|
||||
DNNReturnType (*set_input)(void *model, DNNData *input, const char *input_name);
|
||||
// Sets model input.
|
||||
// Should be called every time before model execution.
|
||||
DNNReturnType (*set_input)(void *model, AVFrame *frame, const char *input_name);
|
||||
// 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);
|
||||
// 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);
|
||||
} 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);
|
||||
// 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);
|
||||
// Executes model with specified output. Returns DNN_ERROR otherwise.
|
||||
DNNReturnType (*execute_model)(const DNNModel *model, const char **output_names, uint32_t nb_output, AVFrame *out_frame);
|
||||
// Frees memory allocated for model.
|
||||
void (*free_model)(DNNModel **model);
|
||||
} DNNModule;
|
||||
|
Reference in New Issue
Block a user