Go to the documentation of this file.
33 #define OFFSET(x) offsetof(NativeContext, x)
34 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM
80 if (strcmp(oprd->
name, input_name) == 0) {
100 const char *output_name,
int *output_width,
int *output_height)
108 .output_names = &output_name,
141 #define DNN_NATIVE_MAGIC "FFMPEGDNNNATIVE"
145 int version, header_size, major_version_expected = 1;
148 int file_size, dnn_size, parsed_size;
155 file_size =
avio_size(model_file_context);
165 if (
avio_read(model_file_context, buf,
sizeof(buf)) !=
sizeof(buf) ||
168 dnn_size =
sizeof(buf);
172 if (
version != major_version_expected) {
179 header_size = dnn_size;
185 model->
model = native_model;
191 native_model->
model = model;
198 #if !HAVE_PTHREAD_CANCEL
201 "on this build (pthread support is required)\n");
205 avio_seek(model_file_context, file_size - 8, SEEK_SET);
209 avio_seek(model_file_context, header_size, SEEK_SET);
212 if (!native_model->
layers){
231 for (layer = 0; layer < native_model->
layers_num; ++layer){
239 native_model->
layers[layer].
type = layer_type;
244 dnn_size += parsed_size;
257 oprd = &native_model->
operands[operand_index];
262 dnn_size += name_len;
282 if (dnn_size != file_size){
318 native_model = task->
model;
383 for (layer = 0; layer < native_model->
layers_num; ++layer){
400 if (strcmp(native_model->
operands[j].
name, output_name) == 0) {
493 for (
int i = 0;
i < 4; ++
i)
502 uint64_t
len =
sizeof(float);
503 for (
int i = 0;
i < 4;
i++) {
519 if ((*model)->model) {
520 native_model = (*model)->
model;
521 if (native_model->
layers) {
522 for (layer = 0; layer < native_model->
layers_num; ++layer){
534 for (uint32_t operand = 0; operand < native_model->
operands_num; ++operand)
#define AV_LOG_WARNING
Something somehow does not look correct.
DNNReturnType ff_dnn_fill_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int async, int do_ioproc)
Fill the Task for Backend Execution.
static FilteringContext * filter_ctx
int8_t isNHWC
NHWC if 1, otherwise NCHW.
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
void * ff_queue_pop_front(Queue *q)
Remove and free first element from the Queue.
int ff_check_exec_params(void *ctx, DNNBackendType backend, DNNFunctionType func_type, DNNExecBaseParams *exec_params)
size_t ff_queue_size(Queue *q)
Return the length of the Queue.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
DNNModel * ff_dnn_load_model_native(const char *model_filename, DNNFunctionType func_type, const char *options, AVFilterContext *filter_ctx)
FramePrePostProc frame_pre_proc
static DNNReturnType get_input_native(void *model, DNNData *input, const char *input_name)
int64_t avio_size(AVIOContext *s)
Get the filesize.
DNNAsyncStatusType ff_dnn_get_result_native(const DNNModel *model, AVFrame **in, AVFrame **out)
AVFilterContext * filter_ctx
Queue * ff_queue_create(void)
Create a Queue instance.
const LayerFunc ff_layer_funcs[DLT_COUNT]
DNNReturnType ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx)
DNNReturnType ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx)
DNNReturnType(* get_output)(void *model, const char *input_name, int input_width, int input_height, const char *output_name, int *output_width, int *output_height)
int32_t ff_calculate_operand_data_length(const DnnOperand *oprd)
DNNLayerType
the enum value of DNNLayerType should not be changed, the same values are used in convert_from_tensor...
Linear double-ended data structure.
int ff_queue_push_back(Queue *q, void *v)
Add data to the tail of the queue.
DNNOperandType type
input/output/intermediate operand of the network
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static DNNReturnType extract_lltask_from_task(TaskItem *task, Queue *lltask_queue)
void ff_queue_destroy(Queue *q)
Destroy the Queue instance.
char name[128]
to avoid possible memory leak, do not use char *name
void * data
data pointer with data length in bytes.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
DNNDataType data_type
support different kinds of data type such as float, half float, int8 etc, first support float now.
DNNReturnType(* get_input)(void *model, DNNData *input, const char *input_name)
void ff_dnn_free_model_native(DNNModel **model)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
and forward the result(frame or status change) to the corresponding input. If nothing is possible
FramePrePostProc frame_post_proc
int av_opt_set_from_string(void *ctx, const char *opts, const char *const *shorthand, const char *key_val_sep, const char *pairs_sep)
Parse the key-value pairs list in opts.
int32_t dims[4]
there are two memory layouts, NHWC or NCHW, so we use dims, dims[0] is Number.
const char * av_default_item_name(void *ptr)
Return the context name.
static const AVOption dnn_native_options[]
@ AV_CLASS_CATEGORY_FILTER
const OptionDef options[]
unsigned int avio_rl32(AVIOContext *s)
int32_t output_operand_index
DNNReturnType ff_dnn_fill_gettingoutput_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int input_height, int input_width, void *ctx)
Allocate input and output frames and fill the Task with execution parameters.
int32_t input_operand_indexes[4]
a layer can have multiple inputs and one output.
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
DNNFunctionType func_type
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
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
static DNNReturnType get_output_native(void *model, const char *input_name, int input_width, int input_height, const char *output_name, int *output_width, int *output_height)
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
#define i(width, name, range_min, range_max)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char ** output_names
static const AVClass dnn_native_class
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNExecBaseParams *exec_params)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int32_t ff_calculate_operand_dims_count(const DnnOperand *oprd)
DNNAsyncStatusType ff_dnn_get_result_common(Queue *task_queue, AVFrame **in, AVFrame **out)
Extract input and output frame from the Task Queue after asynchronous inference.
int avio_open(AVIOContext **s, const char *url, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
#define AVIO_FLAG_READ
read-only
static DNNReturnType execute_model_native(Queue *lltask_queue)
DNNReturnType ff_dnn_flush_native(const DNNModel *model)