mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-03-08 22:39:44 +02:00
lavfi/dnn_backend_common: Return specific error codes
Switch to returning specific error codes or DNN_GENERIC_ERROR when an error is encountered in the common DNN backend functions. Signed-off-by: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
This commit is contained in:
parent
515ff6b4f8
commit
1df77bab08
@ -47,19 +47,19 @@ int ff_check_exec_params(void *ctx, DNNBackendType backend, DNNFunctionType func
|
|||||||
// currently, the filter does not need multiple outputs,
|
// currently, the filter does not need multiple outputs,
|
||||||
// so we just pending the support until we really need it.
|
// so we just pending the support until we really need it.
|
||||||
avpriv_report_missing_feature(ctx, "multiple outputs");
|
avpriv_report_missing_feature(ctx, "multiple outputs");
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(ENOSYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DNNReturnType ff_dnn_fill_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int async, int do_ioproc) {
|
int ff_dnn_fill_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int async, int do_ioproc) {
|
||||||
if (task == NULL || exec_params == NULL || backend_model == NULL)
|
if (task == NULL || exec_params == NULL || backend_model == NULL)
|
||||||
return DNN_ERROR;
|
return AVERROR(EINVAL);
|
||||||
if (do_ioproc != 0 && do_ioproc != 1)
|
if (do_ioproc != 0 && do_ioproc != 1)
|
||||||
return DNN_ERROR;
|
return AVERROR(EINVAL);
|
||||||
if (async != 0 && async != 1)
|
if (async != 0 && async != 1)
|
||||||
return DNN_ERROR;
|
return AVERROR(EINVAL);
|
||||||
|
|
||||||
task->do_ioproc = do_ioproc;
|
task->do_ioproc = do_ioproc;
|
||||||
task->async = async;
|
task->async = async;
|
||||||
@ -89,17 +89,17 @@ static void *async_thread_routine(void *args)
|
|||||||
return DNN_ASYNC_SUCCESS;
|
return DNN_ASYNC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
DNNReturnType ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module)
|
int ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module)
|
||||||
{
|
{
|
||||||
void *status = 0;
|
void *status = 0;
|
||||||
if (!async_module) {
|
if (!async_module) {
|
||||||
return DNN_ERROR;
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
#if HAVE_PTHREAD_CANCEL
|
#if HAVE_PTHREAD_CANCEL
|
||||||
pthread_join(async_module->thread_id, &status);
|
pthread_join(async_module->thread_id, &status);
|
||||||
if (status == DNN_ASYNC_FAIL) {
|
if (status == DNN_ASYNC_FAIL) {
|
||||||
av_log(NULL, AV_LOG_ERROR, "Last Inference Failed.\n");
|
av_log(NULL, AV_LOG_ERROR, "Last Inference Failed.\n");
|
||||||
return DNN_ERROR;
|
return DNN_GENERIC_ERROR;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
async_module->start_inference = NULL;
|
async_module->start_inference = NULL;
|
||||||
@ -108,30 +108,31 @@ DNNReturnType ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module)
|
|||||||
return DNN_SUCCESS;
|
return DNN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
DNNReturnType ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_module)
|
int ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_module)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
void *status = 0;
|
void *status = 0;
|
||||||
|
|
||||||
if (!async_module) {
|
if (!async_module) {
|
||||||
av_log(ctx, AV_LOG_ERROR, "async_module is null when starting async inference.\n");
|
av_log(ctx, AV_LOG_ERROR, "async_module is null when starting async inference.\n");
|
||||||
return DNN_ERROR;
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_PTHREAD_CANCEL
|
#if HAVE_PTHREAD_CANCEL
|
||||||
pthread_join(async_module->thread_id, &status);
|
pthread_join(async_module->thread_id, &status);
|
||||||
if (status == DNN_ASYNC_FAIL) {
|
if (status == DNN_ASYNC_FAIL) {
|
||||||
av_log(ctx, AV_LOG_ERROR, "Unable to start inference as previous inference failed.\n");
|
av_log(ctx, AV_LOG_ERROR, "Unable to start inference as previous inference failed.\n");
|
||||||
return DNN_ERROR;
|
return DNN_GENERIC_ERROR;
|
||||||
}
|
}
|
||||||
ret = pthread_create(&async_module->thread_id, NULL, async_thread_routine, async_module);
|
ret = pthread_create(&async_module->thread_id, NULL, async_thread_routine, async_module);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
av_log(ctx, AV_LOG_ERROR, "Unable to start async inference.\n");
|
av_log(ctx, AV_LOG_ERROR, "Unable to start async inference.\n");
|
||||||
return DNN_ERROR;
|
return ret;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (async_module->start_inference(async_module->args) != DNN_SUCCESS) {
|
ret = async_module->start_inference(async_module->args);
|
||||||
return DNN_ERROR;
|
if (ret != DNN_SUCCESS) {
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
async_module->callback(async_module->args);
|
async_module->callback(async_module->args);
|
||||||
#endif
|
#endif
|
||||||
@ -158,7 +159,7 @@ DNNAsyncStatusType ff_dnn_get_result_common(Queue *task_queue, AVFrame **in, AVF
|
|||||||
return DAST_SUCCESS;
|
return DAST_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
DNNReturnType ff_dnn_fill_gettingoutput_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int input_height, int input_width, void *ctx)
|
int ff_dnn_fill_gettingoutput_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int input_height, int input_width, void *ctx)
|
||||||
{
|
{
|
||||||
AVFrame *in_frame = NULL;
|
AVFrame *in_frame = NULL;
|
||||||
AVFrame *out_frame = NULL;
|
AVFrame *out_frame = NULL;
|
||||||
@ -166,14 +167,14 @@ DNNReturnType ff_dnn_fill_gettingoutput_task(TaskItem *task, DNNExecBaseParams *
|
|||||||
in_frame = av_frame_alloc();
|
in_frame = av_frame_alloc();
|
||||||
if (!in_frame) {
|
if (!in_frame) {
|
||||||
av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for input frame\n");
|
av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for input frame\n");
|
||||||
return DNN_ERROR;
|
return AVERROR(ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
out_frame = av_frame_alloc();
|
out_frame = av_frame_alloc();
|
||||||
if (!out_frame) {
|
if (!out_frame) {
|
||||||
av_frame_free(&in_frame);
|
av_frame_free(&in_frame);
|
||||||
av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for output frame\n");
|
av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for output frame\n");
|
||||||
return DNN_ERROR;
|
return AVERROR(ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
in_frame->width = input_width;
|
in_frame->width = input_width;
|
||||||
|
@ -60,7 +60,7 @@ typedef struct DNNAsyncExecModule {
|
|||||||
* Synchronous inference function for the backend
|
* Synchronous inference function for the backend
|
||||||
* with corresponding request item as the argument.
|
* with corresponding request item as the argument.
|
||||||
*/
|
*/
|
||||||
DNNReturnType (*start_inference)(void *request);
|
int (*start_inference)(void *request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Completion Callback for the backend.
|
* Completion Callback for the backend.
|
||||||
@ -92,20 +92,18 @@ int ff_check_exec_params(void *ctx, DNNBackendType backend, DNNFunctionType func
|
|||||||
* @param async flag for async execution. Must be 0 or 1
|
* @param async flag for async execution. Must be 0 or 1
|
||||||
* @param do_ioproc flag for IO processing. Must be 0 or 1
|
* @param do_ioproc flag for IO processing. Must be 0 or 1
|
||||||
*
|
*
|
||||||
* @retval DNN_SUCCESS if successful
|
* @returns DNN_SUCCESS if successful or error code otherwise.
|
||||||
* @retval DNN_ERROR if flags are invalid or any parameter is NULL
|
|
||||||
*/
|
*/
|
||||||
DNNReturnType ff_dnn_fill_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int async, int do_ioproc);
|
int ff_dnn_fill_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int async, int do_ioproc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Join the Async Execution thread and set module pointers to NULL.
|
* Join the Async Execution thread and set module pointers to NULL.
|
||||||
*
|
*
|
||||||
* @param async_module pointer to DNNAsyncExecModule module
|
* @param async_module pointer to DNNAsyncExecModule module
|
||||||
*
|
*
|
||||||
* @retval DNN_SUCCESS if successful
|
* @returns DNN_SUCCESS if successful or error code otherwise.
|
||||||
* @retval DNN_ERROR if async_module is NULL
|
|
||||||
*/
|
*/
|
||||||
DNNReturnType ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module);
|
int ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start asynchronous inference routine for the TensorFlow
|
* Start asynchronous inference routine for the TensorFlow
|
||||||
@ -119,10 +117,9 @@ DNNReturnType ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module);
|
|||||||
* @param ctx pointer to the backend context
|
* @param ctx pointer to the backend context
|
||||||
* @param async_module pointer to DNNAsyncExecModule module
|
* @param async_module pointer to DNNAsyncExecModule module
|
||||||
*
|
*
|
||||||
* @retval DNN_SUCCESS on the start of async inference.
|
* @returns DNN_SUCCESS on the start of async inference or error code otherwise.
|
||||||
* @retval DNN_ERROR in case async inference cannot be started
|
|
||||||
*/
|
*/
|
||||||
DNNReturnType ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_module);
|
int ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_module);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract input and output frame from the Task Queue after
|
* Extract input and output frame from the Task Queue after
|
||||||
@ -149,9 +146,8 @@ DNNAsyncStatusType ff_dnn_get_result_common(Queue *task_queue, AVFrame **in, AVF
|
|||||||
* @param input_width width of input frame
|
* @param input_width width of input frame
|
||||||
* @param ctx pointer to the backend context
|
* @param ctx pointer to the backend context
|
||||||
*
|
*
|
||||||
* @retval DNN_SUCCESS if successful
|
* @returns DNN_SUCCESS if successful or error code otherwise.
|
||||||
* @retval DNN_ERROR if allocation fails
|
|
||||||
*/
|
*/
|
||||||
DNNReturnType ff_dnn_fill_gettingoutput_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int input_height, int input_width, void *ctx);
|
int ff_dnn_fill_gettingoutput_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int input_height, int input_width, void *ctx);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user