FFmpeg
dnn_interface.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Sergey Lavrushkin
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * DNN inference engine interface.
24  */
25 
26 #ifndef AVFILTER_DNN_INTERFACE_H
27 #define AVFILTER_DNN_INTERFACE_H
28 
29 #include <stdint.h>
30 #include "libavutil/frame.h"
31 
33 
35 
36 typedef enum {DNN_FLOAT = 1, DNN_UINT8 = 4} DNNDataType;
37 
38 typedef struct DNNData{
39  void *data;
42 } DNNData;
43 
44 typedef struct DNNModel{
45  // Stores model that can be different for different backends.
46  void *model;
47  // Stores options when the model is executed by the backend
48  const char *options;
49  // Stores userdata used for the interaction between AVFrame and DNNData
50  void *userdata;
51  // Gets model input information
52  // Just reuse struct DNNData here, actually the DNNData.data field is not needed.
53  DNNReturnType (*get_input)(void *model, DNNData *input, const char *input_name);
54  // Gets model output width/height with given input w/h
55  DNNReturnType (*get_output)(void *model, const char *input_name, int input_width, int input_height,
56  const char *output_name, int *output_width, int *output_height);
57  // set the pre process to transfer data from AVFrame to DNNData
58  // the default implementation within DNN is used if it is not provided by the filter
59  int (*pre_proc)(AVFrame *frame_in, DNNData *model_input, void *user_data);
60  // set the post process to transfer data from DNNData to AVFrame
61  // the default implementation within DNN is used if it is not provided by the filter
62  int (*post_proc)(AVFrame *frame_out, DNNData *model_output, void *user_data);
63 } DNNModel;
64 
65 // Stores pointers to functions for loading, executing, freeing DNN models for one of the backends.
66 typedef struct DNNModule{
67  // Loads model and parameters from given file. Returns NULL if it is not possible.
68  DNNModel *(*load_model)(const char *model_filename, const char *options, void *userdata);
69  // Executes model with specified input and output. Returns DNN_ERROR otherwise.
70  DNNReturnType (*execute_model)(const DNNModel *model, const char *input_name, AVFrame *in_frame,
71  const char **output_names, uint32_t nb_output, AVFrame *out_frame);
72  // Frees memory allocated for model.
73  void (*free_model)(DNNModel **model);
74 } DNNModule;
75 
76 // Initializes DNNModule depending on chosen backend.
78 
79 #endif
void * model
Definition: dnn_interface.h:46
This structure describes decoded (raw) audio or video data.
Definition: frame.h:308
int channels
Definition: dnn_interface.h:41
static int get_input(AVFrame *frame, int frame_num)
Definition: filter_audio.c:242
const char * options
Definition: dnn_interface.h:48
DNNBackendType
Definition: dnn_interface.h:34
DNNDataType
Definition: dnn_interface.h:36
int height
Definition: dnn_interface.h:41
void * data
Definition: dnn_interface.h:39
reference-counted frame API
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
static int FUNC() user_data(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawUserData *current)
DNNReturnType
Definition: dnn_interface.h:32
void * userdata
Definition: dnn_interface.h:50
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
int
const OptionDef options[]
Definition: ffmpeg_opt.c:3400
static void get_output(ConvolveContext *s, FFTComplex *input, AVFrame *out, int w, int h, int n, int plane, float scale)
Definition: vf_convolve.c:329
DNNModule * ff_get_dnn_module(DNNBackendType backend_type)
Definition: dnn_interface.c:32
DNNDataType dt
Definition: dnn_interface.h:40