FFmpeg
Loading...
Searching...
No Matches
dnn_backend_common.c File Reference

DNN common functions different backends. More...

#include "libavutil/mem.h"
#include "dnn_backend_common.h"

Go to the source code of this file.

Macros

#define DNN_ASYNC_SUCCESS   (void *)0
 
#define DNN_ASYNC_FAIL   (void *)-1
 

Functions

int ff_check_exec_params (void *ctx, DNNBackendType backend, DNNFunctionType func_type, DNNExecBaseParams *exec_params)
 
int ff_dnn_fill_task (TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int async, int do_ioproc)
 Fill the Task for Backend Execution.
 
static void * async_thread_routine (void *args)
 Thread routine for async execution.
 
int ff_dnn_async_module_cleanup (DNNAsyncExecModule *async_module)
 Join the Async Execution thread and set module pointers to NULL.
 
void ff_dnn_wait_requests (SafeQueue *request_queue, int nireq)
 Wait for all inference requests to complete before teardown.
 
int ff_dnn_start_inference_async (void *ctx, DNNAsyncExecModule *async_module)
 Start asynchronous inference routine for the TensorFlow model on a detached thread.
 
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 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.
 

Detailed Description

DNN common functions different backends.

Definition in file dnn_backend_common.c.

Macro Definition Documentation

◆ DNN_ASYNC_SUCCESS

#define DNN_ASYNC_SUCCESS   (void *)0

Definition at line 27 of file dnn_backend_common.c.

Referenced by async_thread_routine().

◆ DNN_ASYNC_FAIL

#define DNN_ASYNC_FAIL   (void *)-1

Function Documentation

◆ ff_check_exec_params()

int ff_check_exec_params ( void * ctx,
DNNBackendType backend,
DNNFunctionType func_type,
DNNExecBaseParams * exec_params )

◆ ff_dnn_fill_task()

int ff_dnn_fill_task ( TaskItem * task,
DNNExecBaseParams * exec_params,
void * backend_model,
int async,
int do_ioproc )

Fill the Task for Backend Execution.

It should be called after checking execution parameters using ff_check_exec_params.

Parameters
taskpointer to the allocated task
exec_parampointer to execution parameters
backend_modelvoid pointer to the backend model
asyncflag for async execution. Must be 0 or 1
do_ioprocflag for IO processing. Must be 0 or 1
Returns
0 if successful or error code otherwise.

Definition at line 50 of file dnn_backend_common.c.

Referenced by dnn_execute_model_onnx(), dnn_execute_model_ov(), dnn_execute_model_tf(), dnn_execute_model_th(), and ff_dnn_fill_gettingoutput_task().

◆ async_thread_routine()

static void * async_thread_routine ( void * args)
static

Thread routine for async execution.

Parameters
argspointer to DNNAsyncExecModule module

Definition at line 74 of file dnn_backend_common.c.

Referenced by ff_dnn_start_inference_async().

◆ ff_dnn_async_module_cleanup()

int ff_dnn_async_module_cleanup ( DNNAsyncExecModule * async_module)

Join the Async Execution thread and set module pointers to NULL.

Parameters
async_modulepointer to DNNAsyncExecModule module
Returns
0 if successful or error code otherwise.

Definition at line 86 of file dnn_backend_common.c.

Referenced by destroy_request_item(), destroy_request_item(), and destroy_request_item().

◆ ff_dnn_wait_requests()

void ff_dnn_wait_requests ( SafeQueue * request_queue,
int nireq )

Wait for all inference requests to complete before teardown.

This blocks the calling thread until all request items have been returned to the request_queue by the async inference threads.

Parameters
request_queuepointer to the SafeQueue holding request items
nireqtotal number of allocated request items

Definition at line 105 of file dnn_backend_common.c.

Referenced by dnn_free_model_onnx(), dnn_free_model_ov(), dnn_free_model_tf(), and dnn_free_model_th().

◆ ff_dnn_start_inference_async()

int ff_dnn_start_inference_async ( void * ctx,
DNNAsyncExecModule * async_module )

Start asynchronous inference routine for the TensorFlow model on a detached thread.

It calls the completion callback after the inference completes. Completion callback and inference function must be set before calling this function.

If POSIX threads aren't supported, the execution rolls back to synchronous mode, calling completion callback after inference.

Parameters
ctxpointer to the backend context
async_modulepointer to DNNAsyncExecModule module
Returns
0 on the start of async inference or error code otherwise.

Definition at line 113 of file dnn_backend_common.c.

Referenced by dnn_flush_tf(), execute_model_tf(), and execute_model_th().

◆ ff_dnn_get_result_common()

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.

Parameters
task_queuepointer to the task queue of the backend
indouble pointer to the input frame
outdouble pointer to the output frame
Return values
DAST_EMPTY_QUEUEif task queue is empty
DAST_NOT_READYif inference not completed yet.
DAST_SUCCESSif result successfully extracted

Definition at line 144 of file dnn_backend_common.c.

Referenced by dnn_get_result_onnx(), dnn_get_result_ov(), dnn_get_result_tf(), and dnn_get_result_th().

◆ ff_dnn_fill_gettingoutput_task()

int 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.

Parameters
taskpointer to the allocated task
exec_paramspointer to execution parameters
backend_modelvoid pointer to the backend model
input_heightheight of input frame
input_widthwidth of input frame
ctxpointer to the backend context
Returns
0 if successful or error code otherwise.

Definition at line 164 of file dnn_backend_common.c.

Referenced by get_output_onnx(), get_output_ov(), get_output_tf(), and get_output_th().