[FFmpeg-cvslog] lavfi/dnn_backend_common: Return specific error codes
Shubhanshu Saxena
git at videolan.org
Sat Mar 12 09:43:36 EET 2022
ffmpeg | branch: master | Shubhanshu Saxena <shubhanshu.e01 at gmail.com> | Wed Mar 2 23:53:55 2022 +0530| [1df77bab08ac53482f94c4d4be2449cfa50b8e68] | committer: Guo Yejun
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 at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1df77bab08ac53482f94c4d4be2449cfa50b8e68
---
libavfilter/dnn/dnn_backend_common.c | 35 ++++++++++++++++++-----------------
libavfilter/dnn/dnn_backend_common.h | 22 +++++++++-------------
2 files changed, 27 insertions(+), 30 deletions(-)
diff --git a/libavfilter/dnn/dnn_backend_common.c b/libavfilter/dnn/dnn_backend_common.c
index 6a9c4cc87f..64ed441415 100644
--- a/libavfilter/dnn/dnn_backend_common.c
+++ b/libavfilter/dnn/dnn_backend_common.c
@@ -47,19 +47,19 @@ int ff_check_exec_params(void *ctx, DNNBackendType backend, DNNFunctionType func
// currently, the filter does not need multiple outputs,
// so we just pending the support until we really need it.
avpriv_report_missing_feature(ctx, "multiple outputs");
- return AVERROR(EINVAL);
+ return AVERROR(ENOSYS);
}
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)
- return DNN_ERROR;
+ return AVERROR(EINVAL);
if (do_ioproc != 0 && do_ioproc != 1)
- return DNN_ERROR;
+ return AVERROR(EINVAL);
if (async != 0 && async != 1)
- return DNN_ERROR;
+ return AVERROR(EINVAL);
task->do_ioproc = do_ioproc;
task->async = async;
@@ -89,17 +89,17 @@ static void *async_thread_routine(void *args)
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;
if (!async_module) {
- return DNN_ERROR;
+ return AVERROR(EINVAL);
}
#if HAVE_PTHREAD_CANCEL
pthread_join(async_module->thread_id, &status);
if (status == DNN_ASYNC_FAIL) {
av_log(NULL, AV_LOG_ERROR, "Last Inference Failed.\n");
- return DNN_ERROR;
+ return DNN_GENERIC_ERROR;
}
#endif
async_module->start_inference = NULL;
@@ -108,30 +108,31 @@ DNNReturnType ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module)
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;
void *status = 0;
if (!async_module) {
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
pthread_join(async_module->thread_id, &status);
if (status == DNN_ASYNC_FAIL) {
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);
if (ret != 0) {
av_log(ctx, AV_LOG_ERROR, "Unable to start async inference.\n");
- return DNN_ERROR;
+ return ret;
}
#else
- if (async_module->start_inference(async_module->args) != DNN_SUCCESS) {
- return DNN_ERROR;
+ ret = async_module->start_inference(async_module->args);
+ if (ret != DNN_SUCCESS) {
+ return ret;
}
async_module->callback(async_module->args);
#endif
@@ -158,7 +159,7 @@ DNNAsyncStatusType ff_dnn_get_result_common(Queue *task_queue, AVFrame **in, AVF
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 *out_frame = NULL;
@@ -166,14 +167,14 @@ DNNReturnType ff_dnn_fill_gettingoutput_task(TaskItem *task, DNNExecBaseParams *
in_frame = av_frame_alloc();
if (!in_frame) {
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();
if (!out_frame) {
av_frame_free(&in_frame);
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;
diff --git a/libavfilter/dnn/dnn_backend_common.h b/libavfilter/dnn/dnn_backend_common.h
index 6b6a5e21ae..fa79caee1f 100644
--- a/libavfilter/dnn/dnn_backend_common.h
+++ b/libavfilter/dnn/dnn_backend_common.h
@@ -60,7 +60,7 @@ typedef struct DNNAsyncExecModule {
* Synchronous inference function for the backend
* with corresponding request item as the argument.
*/
- DNNReturnType (*start_inference)(void *request);
+ int (*start_inference)(void *request);
/**
* 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 do_ioproc flag for IO processing. Must be 0 or 1
*
- * @retval DNN_SUCCESS if successful
- * @retval DNN_ERROR if flags are invalid or any parameter is NULL
+ * @returns DNN_SUCCESS if successful or error code otherwise.
*/
-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.
*
* @param async_module pointer to DNNAsyncExecModule module
*
- * @retval DNN_SUCCESS if successful
- * @retval DNN_ERROR if async_module is NULL
+ * @returns DNN_SUCCESS if successful or error code otherwise.
*/
-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
@@ -119,10 +117,9 @@ DNNReturnType ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module);
* @param ctx pointer to the backend context
* @param async_module pointer to DNNAsyncExecModule module
*
- * @retval DNN_SUCCESS on the start of async inference.
- * @retval DNN_ERROR in case async inference cannot be started
+ * @returns DNN_SUCCESS on the start of async inference or error code otherwise.
*/
-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
@@ -149,9 +146,8 @@ DNNAsyncStatusType ff_dnn_get_result_common(Queue *task_queue, AVFrame **in, AVF
* @param input_width width of input frame
* @param ctx pointer to the backend context
*
- * @retval DNN_SUCCESS if successful
- * @retval DNN_ERROR if allocation fails
+ * @returns DNN_SUCCESS if successful or error code otherwise.
*/
-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
More information about the ffmpeg-cvslog
mailing list