From: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
Subject: [FFmpeg-devel] [PATCH V2 6/8] lavfi/dnn_backend_native: Return Specific Error Codes
Date: Wed, 2 Mar 2022 23:35:54 +0530
Message-ID: <20220302180556.19865-6-shubhanshu.e01@gmail.com> (raw)
In-Reply-To: <20220302180556.19865-1-shubhanshu.e01@gmail.com>
Switch to returning specific error codes or DNN_GENERIC_ERROR
when an error is encountered.
Signed-off-by: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
---
libavfilter/dnn/dnn_backend_native.c | 82 +++++++++++++++-------------
libavfilter/dnn/dnn_backend_native.h | 4 +-
2 files changed, 45 insertions(+), 41 deletions(-)
diff --git a/libavfilter/dnn/dnn_backend_native.c b/libavfilter/dnn/dnn_backend_native.c
index 13436c0484..f29e0e06bd 100644
--- a/libavfilter/dnn/dnn_backend_native.c
+++ b/libavfilter/dnn/dnn_backend_native.c
@@ -46,9 +46,9 @@ static const AVClass dnn_native_class = {
.category = AV_CLASS_CATEGORY_FILTER,
};
-static DNNReturnType execute_model_native(Queue *lltask_queue);
+static int execute_model_native(Queue *lltask_queue);
-static DNNReturnType extract_lltask_from_task(TaskItem *task, Queue *lltask_queue)
+static int extract_lltask_from_task(TaskItem *task, Queue *lltask_queue)
{
NativeModel *native_model = task->model;
NativeContext *ctx = &native_model->ctx;
@@ -56,7 +56,7 @@ static DNNReturnType extract_lltask_from_task(TaskItem *task, Queue *lltask_queu
if (!lltask) {
av_log(ctx, AV_LOG_ERROR, "Unable to allocate space for LastLevelTaskItem\n");
- return DNN_ERROR;
+ return AVERROR(ENOMEM);
}
task->inference_todo = 1;
task->inference_done = 0;
@@ -65,12 +65,12 @@ static DNNReturnType extract_lltask_from_task(TaskItem *task, Queue *lltask_queu
if (ff_queue_push_back(lltask_queue, lltask) < 0) {
av_log(ctx, AV_LOG_ERROR, "Failed to push back lltask_queue.\n");
av_freep(&lltask);
- return DNN_ERROR;
+ return AVERROR(ENOMEM);
}
return DNN_SUCCESS;
}
-static DNNReturnType get_input_native(void *model, DNNData *input, const char *input_name)
+static int get_input_native(void *model, DNNData *input, const char *input_name)
{
NativeModel *native_model = model;
NativeContext *ctx = &native_model->ctx;
@@ -80,7 +80,7 @@ static DNNReturnType get_input_native(void *model, DNNData *input, const char *i
if (strcmp(oprd->name, input_name) == 0) {
if (oprd->type != DOT_INPUT) {
av_log(ctx, AV_LOG_ERROR, "Found \"%s\" in model, but it is not input node\n", input_name);
- return DNN_ERROR;
+ return AVERROR(EINVAL);
}
input->dt = oprd->data_type;
av_assert0(oprd->dims[0] == 1);
@@ -93,13 +93,13 @@ static DNNReturnType get_input_native(void *model, DNNData *input, const char *i
// do not find the input operand
av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model\n", input_name);
- return DNN_ERROR;
+ return AVERROR(EINVAL);
}
-static DNNReturnType get_output_native(void *model, const char *input_name, int input_width, int input_height,
+static int 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)
{
- DNNReturnType ret = 0;
+ int ret = 0;
NativeModel *native_model = model;
NativeContext *ctx = &native_model->ctx;
TaskItem task;
@@ -111,14 +111,14 @@ static DNNReturnType get_output_native(void *model, const char *input_name, int
.out_frame = NULL,
};
- if (ff_dnn_fill_gettingoutput_task(&task, &exec_params, native_model, input_height, input_width, ctx) != DNN_SUCCESS) {
- ret = DNN_ERROR;
+ ret = ff_dnn_fill_gettingoutput_task(&task, &exec_params, native_model, input_height, input_width, ctx);
+ if (ret != DNN_SUCCESS) {
goto err;
}
- if (extract_lltask_from_task(&task, native_model->lltask_queue) != DNN_SUCCESS) {
+ ret = extract_lltask_from_task(&task, native_model->lltask_queue);
+ if (ret != DNN_SUCCESS) {
av_log(ctx, AV_LOG_ERROR, "unable to extract last level task from task.\n");
- ret = DNN_ERROR;
goto err;
}
@@ -297,7 +297,7 @@ fail:
return NULL;
}
-static DNNReturnType execute_model_native(Queue *lltask_queue)
+static int execute_model_native(Queue *lltask_queue)
{
NativeModel *native_model = NULL;
NativeContext *ctx = NULL;
@@ -306,12 +306,12 @@ static DNNReturnType execute_model_native(Queue *lltask_queue)
DnnOperand *oprd = NULL;
LastLevelTaskItem *lltask = NULL;
TaskItem *task = NULL;
- DNNReturnType ret = 0;
+ int ret = 0;
lltask = ff_queue_pop_front(lltask_queue);
if (!lltask) {
av_log(NULL, AV_LOG_ERROR, "Failed to get LastLevelTaskItem\n");
- ret = DNN_ERROR;
+ ret = AVERROR(EINVAL);
goto err;
}
task = lltask->task;
@@ -320,7 +320,7 @@ static DNNReturnType execute_model_native(Queue *lltask_queue)
if (native_model->layers_num <= 0 || native_model->operands_num <= 0) {
av_log(ctx, AV_LOG_ERROR, "No operands or layers in model\n");
- ret = DNN_ERROR;
+ ret = AVERROR(EINVAL);
goto err;
}
@@ -329,7 +329,7 @@ static DNNReturnType execute_model_native(Queue *lltask_queue)
if (strcmp(oprd->name, task->input_name) == 0) {
if (oprd->type != DOT_INPUT) {
av_log(ctx, AV_LOG_ERROR, "Found \"%s\" in model, but it is not input node\n", task->input_name);
- ret = DNN_ERROR;
+ ret = AVERROR(EINVAL);
goto err;
}
break;
@@ -338,7 +338,7 @@ static DNNReturnType execute_model_native(Queue *lltask_queue)
}
if (!oprd) {
av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model\n", task->input_name);
- ret = DNN_ERROR;
+ ret = AVERROR(EINVAL);
goto err;
}
@@ -349,13 +349,13 @@ static DNNReturnType execute_model_native(Queue *lltask_queue)
oprd->length = ff_calculate_operand_data_length(oprd);
if (oprd->length <= 0) {
av_log(ctx, AV_LOG_ERROR, "The input data length overflow\n");
- ret = DNN_ERROR;
+ ret = AVERROR(EINVAL);
goto err;
}
oprd->data = av_malloc(oprd->length);
if (!oprd->data) {
av_log(ctx, AV_LOG_ERROR, "Failed to malloc memory for input data\n");
- ret = DNN_ERROR;
+ ret = AVERROR(ENOMEM);
goto err;
}
@@ -376,19 +376,19 @@ static DNNReturnType execute_model_native(Queue *lltask_queue)
// 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");
- ret = DNN_ERROR;
+ ret = AVERROR(ENOSYS);
goto err;
}
for (layer = 0; layer < native_model->layers_num; ++layer){
DNNLayerType layer_type = native_model->layers[layer].type;
- if (ff_layer_funcs[layer_type].pf_exec(native_model->operands,
- native_model->layers[layer].input_operand_indexes,
- native_model->layers[layer].output_operand_index,
- native_model->layers[layer].params,
- &native_model->ctx) == DNN_ERROR) {
+ ret = ff_layer_funcs[layer_type].pf_exec(native_model->operands,
+ native_model->layers[layer].input_operand_indexes,
+ native_model->layers[layer].output_operand_index,
+ native_model->layers[layer].params,
+ &native_model->ctx);
+ if (ret != DNN_SUCCESS) {
av_log(ctx, AV_LOG_ERROR, "Failed to execute model\n");
- ret = DNN_ERROR;
goto err;
}
}
@@ -405,7 +405,7 @@ static DNNReturnType execute_model_native(Queue *lltask_queue)
if (oprd == NULL) {
av_log(ctx, AV_LOG_ERROR, "Could not find output in model\n");
- ret = DNN_ERROR;
+ ret = AVERROR(EINVAL);
goto err;
}
@@ -432,42 +432,46 @@ err:
return ret;
}
-DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNExecBaseParams *exec_params)
+int ff_dnn_execute_model_native(const DNNModel *model, DNNExecBaseParams *exec_params)
{
NativeModel *native_model = model->model;
NativeContext *ctx = &native_model->ctx;
TaskItem *task;
+ int ret = 0;
- if (ff_check_exec_params(ctx, DNN_NATIVE, model->func_type, exec_params) != 0) {
- return DNN_ERROR;
+ ret = ff_check_exec_params(ctx, DNN_NATIVE, model->func_type, exec_params);
+ if (ret != 0) {
+ return ret;
}
task = av_malloc(sizeof(*task));
if (!task) {
av_log(ctx, AV_LOG_ERROR, "unable to alloc memory for task item.\n");
- return DNN_ERROR;
+ return AVERROR(ENOMEM);
}
- if (ff_dnn_fill_task(task, exec_params, native_model, ctx->options.async, 1) != DNN_SUCCESS) {
+ ret = ff_dnn_fill_task(task, exec_params, native_model, ctx->options.async, 1);
+ if (ret != DNN_SUCCESS) {
av_freep(&task);
- return DNN_ERROR;
+ return ret;
}
if (ff_queue_push_back(native_model->task_queue, task) < 0) {
av_freep(&task);
av_log(ctx, AV_LOG_ERROR, "unable to push back task_queue.\n");
- return DNN_ERROR;
+ return AVERROR(ENOMEM);
}
- if (extract_lltask_from_task(task, native_model->lltask_queue) != DNN_SUCCESS) {
+ ret = extract_lltask_from_task(task, native_model->lltask_queue);
+ if (ret != DNN_SUCCESS) {
av_log(ctx, AV_LOG_ERROR, "unable to extract last level task from task.\n");
- return DNN_ERROR;
+ return ret;
}
return execute_model_native(native_model->lltask_queue);
}
-DNNReturnType ff_dnn_flush_native(const DNNModel *model)
+int ff_dnn_flush_native(const DNNModel *model)
{
NativeModel *native_model = model->model;
diff --git a/libavfilter/dnn/dnn_backend_native.h b/libavfilter/dnn/dnn_backend_native.h
index e8017ee4b4..75bd9a44f7 100644
--- a/libavfilter/dnn/dnn_backend_native.h
+++ b/libavfilter/dnn/dnn_backend_native.h
@@ -134,11 +134,11 @@ typedef struct NativeModel{
DNNModel *ff_dnn_load_model_native(const char *model_filename, DNNFunctionType func_type, const char *options, AVFilterContext *filter_ctx);
-DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNExecBaseParams *exec_params);
+int ff_dnn_execute_model_native(const DNNModel *model, DNNExecBaseParams *exec_params);
DNNAsyncStatusType ff_dnn_get_result_native(const DNNModel *model, AVFrame **in, AVFrame **out);
-DNNReturnType ff_dnn_flush_native(const DNNModel *model);
+int ff_dnn_flush_native(const DNNModel *model);
void ff_dnn_free_model_native(DNNModel **model);
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-03-02 18:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-02 18:05 [FFmpeg-devel] [PATCH V2 1/8] libavfilter: Prepare to handle specific error codes in DNN Filters Shubhanshu Saxena
2022-03-02 18:05 ` [FFmpeg-devel] [PATCH V2 2/8] lavfi/dnn: Error Specificity in Native Backend Layers Shubhanshu Saxena
2022-03-02 18:05 ` [FFmpeg-devel] [PATCH V2 3/8] lavfi/dnn_io_proc: Return Specific Error Codes Shubhanshu Saxena
2022-03-02 18:05 ` [FFmpeg-devel] [PATCH V2 4/8] lavfi/dnn_backend_openvino: " Shubhanshu Saxena
2022-03-02 18:05 ` [FFmpeg-devel] [PATCH V2 5/8] lavfi/dnn_backend_tf: " Shubhanshu Saxena
2022-03-02 18:05 ` Shubhanshu Saxena [this message]
2022-03-02 18:05 ` [FFmpeg-devel] [PATCH V2 7/8] lavfi/dnn_backend_common: Return specific error codes Shubhanshu Saxena
2022-03-02 18:05 ` [FFmpeg-devel] [PATCH V2 8/8] libavfilter: Remove DNNReturnType from DNN Module Shubhanshu Saxena
2022-03-08 14:18 ` Guo, Yejun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220302180556.19865-6-shubhanshu.e01@gmail.com \
--to=shubhanshu.e01@gmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git