FFmpeg
dnn_backend_common.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /**
20  * @file
21  * DNN common functions different backends.
22  */
23 
24 #include "dnn_backend_common.h"
25 
26 int ff_check_exec_params(void *ctx, DNNBackendType backend, DNNFunctionType func_type, DNNExecBaseParams *exec_params)
27 {
28  if (!exec_params) {
29  av_log(ctx, AV_LOG_ERROR, "exec_params is null when execute model.\n");
30  return AVERROR(EINVAL);
31  }
32 
33  if (!exec_params->in_frame) {
34  av_log(ctx, AV_LOG_ERROR, "in frame is NULL when execute model.\n");
35  return AVERROR(EINVAL);
36  }
37 
38  if (!exec_params->out_frame) {
39  av_log(ctx, AV_LOG_ERROR, "out frame is NULL when execute model.\n");
40  return AVERROR(EINVAL);
41  }
42 
43  if (exec_params->nb_output != 1 && backend != DNN_TF) {
44  // currently, the filter does not need multiple outputs,
45  // so we just pending the support until we really need it.
46  avpriv_report_missing_feature(ctx, "multiple outputs");
47  return AVERROR(EINVAL);
48  }
49 
50  return 0;
51 }
52 
53 DNNReturnType ff_dnn_fill_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int async, int do_ioproc) {
54  if (task == NULL || exec_params == NULL || backend_model == NULL)
55  return DNN_ERROR;
56  if (do_ioproc != 0 && do_ioproc != 1)
57  return DNN_ERROR;
58  if (async != 0 && async != 1)
59  return DNN_ERROR;
60 
61  task->do_ioproc = do_ioproc;
62  task->async = async;
63  task->input_name = exec_params->input_name;
64  task->in_frame = exec_params->in_frame;
65  task->out_frame = exec_params->out_frame;
66  task->model = backend_model;
67  task->nb_output = exec_params->nb_output;
68  task->output_names = exec_params->output_names;
69 
70  return DNN_SUCCESS;
71 }
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
ff_dnn_fill_task
DNNReturnType ff_dnn_fill_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int async, int do_ioproc)
Fill the Task for Backend Execution.
Definition: dnn_backend_common.c:53
DNNFunctionType
DNNFunctionType
Definition: dnn_interface.h:52
ff_check_exec_params
int ff_check_exec_params(void *ctx, DNNBackendType backend, DNNFunctionType func_type, DNNExecBaseParams *exec_params)
Definition: dnn_backend_common.c:26
DNNExecBaseParams::input_name
const char * input_name
Definition: dnn_interface.h:68
TaskItem
Definition: dnn_backend_common.h:30
DNNExecBaseParams::in_frame
AVFrame * in_frame
Definition: dnn_interface.h:71
TaskItem::model
void * model
Definition: dnn_backend_common.h:31
DNN_SUCCESS
@ DNN_SUCCESS
Definition: dnn_interface.h:33
DNN_TF
@ DNN_TF
Definition: dnn_interface.h:35
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:181
DNNReturnType
DNNReturnType
Definition: dnn_interface.h:33
ctx
AVFormatContext * ctx
Definition: movenc.c:48
NULL
#define NULL
Definition: coverity.c:32
TaskItem::in_frame
AVFrame * in_frame
Definition: dnn_backend_common.h:32
TaskItem::async
uint8_t async
Definition: dnn_backend_common.h:36
DNNBackendType
DNNBackendType
Definition: dnn_interface.h:35
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
DNNExecBaseParams::out_frame
AVFrame * out_frame
Definition: dnn_interface.h:72
DNN_ERROR
@ DNN_ERROR
Definition: dnn_interface.h:33
TaskItem::output_names
const char ** output_names
Definition: dnn_backend_common.h:35
TaskItem::out_frame
AVFrame * out_frame
Definition: dnn_backend_common.h:33
dnn_backend_common.h
DNNExecBaseParams::output_names
const char ** output_names
Definition: dnn_interface.h:69
TaskItem::input_name
const char * input_name
Definition: dnn_backend_common.h:34
DNNExecBaseParams
Definition: dnn_interface.h:67
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
TaskItem::do_ioproc
uint8_t do_ioproc
Definition: dnn_backend_common.h:37
TaskItem::nb_output
uint32_t nb_output
Definition: dnn_backend_common.h:38
DNNExecBaseParams::nb_output
uint32_t nb_output
Definition: dnn_interface.h:70