From patchwork Thu Feb 24 08:22:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shubhanshu Saxena X-Patchwork-Id: 34511 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1616749nkx; Thu, 24 Feb 2022 00:24:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJzV+x/r/Cacn1p8kD+u0jQTBQm19y+uiRTsvzd9yQCRglgG4HAJSGtN5F4VyxRzTzPF8co2 X-Received: by 2002:a05:6402:2055:b0:40f:6a63:2625 with SMTP id bc21-20020a056402205500b0040f6a632625mr1256940edb.329.1645691065320; Thu, 24 Feb 2022 00:24:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645691065; cv=none; d=google.com; s=arc-20160816; b=wOKRhXWyu/GzjwwXuxPMAjl+aSKdeOWBBFvWPTFIZrdFBgr8X0wJ1w18/RIyaWG9eC i4E5SrqWT5hNuHqWQ4RlTq0Cit4ZfF4xXhIF59gOkhgp4r9KG1Y3d0xWuS5h9wxUCpOA OMxcSsK/DKNOAV21/3YnelX8dhdfxhbcY0XlSqUsF1hC6rLxhaV+H48FK6Fix0CvVF8g gHAyuS/Q3ZO3s6eF2IyYFXSaHglCATJFIWjUUsSuJzUtyuAhvKkvpwH0uvAZO5f71WJR XgGfWsGh4XtIpjEZdHbv6Oc7kGb+t9zhsoQMrv7UvC472aq03hRezaL9hOI92UFaRrwY 9GRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=8lU7fHoD/cf26r1Qtr38DerdJw+YC8ycFSBgRPwJ2Uc=; b=YflD/EDHZ6lH4JWkmQ7YiLmW0PFwmvCc9SC1+gZVtjzJlkfR8BiftwdUk5GjsWnLXW 0BE5UEYnDu4eZRBkRPa5mlOs5gBy237mxey4Q4IjQ1dNjjTYsRyexgZTp07lR8HgG0Wd A9Hxp7naLf2UkQ9FeudJ7zAOgwqOkcKYb2iIPtfQ72nzaCkyVsaJT6MAmRjKn2pWzBOe JxzBi/TrTCyDFemOmuKjiHHoPKl5KRgnZo/588iU9sub0mP6leAeedI+/Hfrr94KvzKA inxXP/7T5+aWcdG1jPAIIUQmQmpk2uMG0QSOJUabF8wxHM9Njtg9Wp9WtRMgHO6bhFw2 nBSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=d19sazD8; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k22si1210442ejx.887.2022.02.24.00.24.24; Thu, 24 Feb 2022 00:24:25 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=d19sazD8; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2981C68B314; Thu, 24 Feb 2022 10:23:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3BF6A68B2EB for ; Thu, 24 Feb 2022 10:23:48 +0200 (EET) Received: by mail-pl1-f177.google.com with SMTP id bd1so1032082plb.13 for ; Thu, 24 Feb 2022 00:23:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zA9dZfNiCxkf07h65Gr2RV3lpZDU8IOBV0rDlBQzc+Y=; b=d19sazD83IFQCva04lZ1UYNjjyxjzFlXoDv584iRLX5za0Gl95OSa0OAGRG0zvHmwy saegUPaNRFlaH6nberJzu7gYRZii+MFIoKxyAWzaYfjY7mm2CTnmdgbMk1uv0/bT4fll wRr6j416o/IcoiZJHWf+UUaq/jfUpb93Rg+yvaCMb/XikGEGll7ErxaAMHaWego2A4yR 6NX9m9KrJHDdnLxW3hJPMoAUVf56S3EpL/K0ATyeJP7uqTDOupJKyUIufeFF5v0cNKwg BzrWFXFh1ls7MBjvye/1UieQ/cAb4ZakU2CqJaFSW/tYupWxjJCwEFYEDVlbwaDtTS/j Zc2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zA9dZfNiCxkf07h65Gr2RV3lpZDU8IOBV0rDlBQzc+Y=; b=IOWDLiXSvpXLnGstauh+RIIbHWIAiIqTLGpxyFzao381cYOxtmqnD42kj+arvJigKU trlqbl6/xue2lUTUm6ilIXqXDU4c7hxeqyIwElNxTHuOkJS+hMiMi9JyAa2ungaNFcs8 UTBovEBaZj0BsI3hvXDQCQTLTLPngG8nbJ7jeHFefd+f54+mWj9V5yqkiUe5syI0y3uM PI6QLt4Av15tZfzo5yoGPAC9tT6Tx8NQR/1H9yrP7radsVJOzUl1r0QTwXHEeHpUMXtt IpLb656HKRXVP8t3bP9w1tPfUtVw28LFyK922ICCG7O66/B2nzvP80e2dwcN/6+HU1dt 36GA== X-Gm-Message-State: AOAM533+g3o0Nq1FlkcIF9Uc039wQ8HEiJOw/vlPilmMwo0aracpX6MA tZfTffeKoPtXYN69c70ZPClkcna6GrXHXg== X-Received: by 2002:a17:90b:1b07:b0:1b8:af50:5c0f with SMTP id nu7-20020a17090b1b0700b001b8af505c0fmr13368876pjb.184.1645691026100; Thu, 24 Feb 2022 00:23:46 -0800 (PST) Received: from Pavilion-x360.bbrouter ([103.133.123.155]) by smtp.googlemail.com with ESMTPSA id k11sm2174503pff.169.2022.02.24.00.23.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 00:23:45 -0800 (PST) From: Shubhanshu Saxena To: ffmpeg-devel@ffmpeg.org Date: Thu, 24 Feb 2022 13:52:43 +0530 Message-Id: <20220224082243.11208-8-shubhanshu.e01@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220224082243.11208-1-shubhanshu.e01@gmail.com> References: <20220224082243.11208-1-shubhanshu.e01@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 8/8] libavfilter: Remove DNNReturnType from DNN Module X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Shubhanshu Saxena Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: KM6H60gLjb93 This patch removes all occurences of DNNReturnType from the DNN module. This commit replaces DNN_SUCCESS by 0 (essentially the same), so the functions with DNNReturnType now return 0 in case of success, the negative values otherwise. Signed-off-by: Shubhanshu Saxena --- libavfilter/dnn/dnn_backend_common.c | 10 ++-- libavfilter/dnn/dnn_backend_common.h | 8 +-- libavfilter/dnn/dnn_backend_native.c | 16 +++--- .../dnn/dnn_backend_native_layer_avgpool.c | 2 +- .../dnn/dnn_backend_native_layer_conv2d.c | 4 +- .../dnn/dnn_backend_native_layer_dense.c | 2 +- .../dnn_backend_native_layer_depth2space.c | 2 +- libavfilter/dnn/dnn_backend_openvino.c | 48 ++++++++-------- libavfilter/dnn/dnn_backend_tf.c | 56 +++++++++---------- libavfilter/dnn/dnn_io_proc.c | 14 ++--- libavfilter/dnn_interface.h | 2 - libavfilter/vf_derain.c | 2 +- libavfilter/vf_dnn_classify.c | 4 +- libavfilter/vf_dnn_detect.c | 4 +- libavfilter/vf_dnn_processing.c | 8 +-- libavfilter/vf_sr.c | 4 +- 16 files changed, 92 insertions(+), 94 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_common.c b/libavfilter/dnn/dnn_backend_common.c index 64ed441415..91a4a3c4bf 100644 --- a/libavfilter/dnn/dnn_backend_common.c +++ b/libavfilter/dnn/dnn_backend_common.c @@ -70,7 +70,7 @@ int ff_dnn_fill_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backe task->nb_output = exec_params->nb_output; task->output_names = exec_params->output_names; - return DNN_SUCCESS; + return 0; } /** @@ -82,7 +82,7 @@ static void *async_thread_routine(void *args) DNNAsyncExecModule *async_module = args; void *request = async_module->args; - if (async_module->start_inference(request) != DNN_SUCCESS) { + if (async_module->start_inference(request) != 0) { return DNN_ASYNC_FAIL; } async_module->callback(request); @@ -105,7 +105,7 @@ int ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module) async_module->start_inference = NULL; async_module->callback = NULL; async_module->args = NULL; - return DNN_SUCCESS; + return 0; } int ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_module) @@ -131,12 +131,12 @@ int ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_module) } #else ret = async_module->start_inference(async_module->args); - if (ret != DNN_SUCCESS) { + if (ret != 0) { return ret; } async_module->callback(async_module->args); #endif - return DNN_SUCCESS; + return 0; } DNNAsyncStatusType ff_dnn_get_result_common(Queue *task_queue, AVFrame **in, AVFrame **out) diff --git a/libavfilter/dnn/dnn_backend_common.h b/libavfilter/dnn/dnn_backend_common.h index fa79caee1f..42c67c7040 100644 --- a/libavfilter/dnn/dnn_backend_common.h +++ b/libavfilter/dnn/dnn_backend_common.h @@ -92,7 +92,7 @@ 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 * - * @returns DNN_SUCCESS if successful or error code otherwise. + * @returns 0 if successful or error code otherwise. */ int ff_dnn_fill_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int async, int do_ioproc); @@ -101,7 +101,7 @@ int ff_dnn_fill_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backe * * @param async_module pointer to DNNAsyncExecModule module * - * @returns DNN_SUCCESS if successful or error code otherwise. + * @returns 0 if successful or error code otherwise. */ int ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module); @@ -117,7 +117,7 @@ int ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module); * @param ctx pointer to the backend context * @param async_module pointer to DNNAsyncExecModule module * - * @returns DNN_SUCCESS on the start of async inference or error code otherwise. + * @returns 0 on the start of async inference or error code otherwise. */ int ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_module); @@ -146,7 +146,7 @@ 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 * - * @returns DNN_SUCCESS if successful or error code otherwise. + * @returns 0 if successful or error code otherwise. */ int ff_dnn_fill_gettingoutput_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int input_height, int input_width, void *ctx); diff --git a/libavfilter/dnn/dnn_backend_native.c b/libavfilter/dnn/dnn_backend_native.c index f29e0e06bd..b53799f04d 100644 --- a/libavfilter/dnn/dnn_backend_native.c +++ b/libavfilter/dnn/dnn_backend_native.c @@ -67,7 +67,7 @@ static int extract_lltask_from_task(TaskItem *task, Queue *lltask_queue) av_freep(&lltask); return AVERROR(ENOMEM); } - return DNN_SUCCESS; + return 0; } static int get_input_native(void *model, DNNData *input, const char *input_name) @@ -87,7 +87,7 @@ static int get_input_native(void *model, DNNData *input, const char *input_name) input->height = oprd->dims[1]; input->width = oprd->dims[2]; input->channels = oprd->dims[3]; - return DNN_SUCCESS; + return 0; } } @@ -112,12 +112,12 @@ static int get_output_native(void *model, const char *input_name, int input_widt }; ret = ff_dnn_fill_gettingoutput_task(&task, &exec_params, native_model, input_height, input_width, ctx); - if (ret != DNN_SUCCESS) { + if (ret != 0) { goto err; } ret = extract_lltask_from_task(&task, native_model->lltask_queue); - if (ret != DNN_SUCCESS) { + if (ret != 0) { av_log(ctx, AV_LOG_ERROR, "unable to extract last level task from task.\n"); goto err; } @@ -387,7 +387,7 @@ static int execute_model_native(Queue *lltask_queue) native_model->layers[layer].output_operand_index, native_model->layers[layer].params, &native_model->ctx); - if (ret != DNN_SUCCESS) { + if (ret != 0) { av_log(ctx, AV_LOG_ERROR, "Failed to execute model\n"); goto err; } @@ -451,7 +451,7 @@ int ff_dnn_execute_model_native(const DNNModel *model, DNNExecBaseParams *exec_p } ret = ff_dnn_fill_task(task, exec_params, native_model, ctx->options.async, 1); - if (ret != DNN_SUCCESS) { + if (ret != 0) { av_freep(&task); return ret; } @@ -463,7 +463,7 @@ int ff_dnn_execute_model_native(const DNNModel *model, DNNExecBaseParams *exec_p } ret = extract_lltask_from_task(task, native_model->lltask_queue); - if (ret != DNN_SUCCESS) { + if (ret != 0) { av_log(ctx, AV_LOG_ERROR, "unable to extract last level task from task.\n"); return ret; } @@ -477,7 +477,7 @@ int ff_dnn_flush_native(const DNNModel *model) if (ff_queue_size(native_model->lltask_queue) == 0) { // no pending task need to flush - return DNN_SUCCESS; + return 0; } // for now, use sync node with flush operation diff --git a/libavfilter/dnn/dnn_backend_native_layer_avgpool.c b/libavfilter/dnn/dnn_backend_native_layer_avgpool.c index 510a28a8c9..d6fcac8a35 100644 --- a/libavfilter/dnn/dnn_backend_native_layer_avgpool.c +++ b/libavfilter/dnn/dnn_backend_native_layer_avgpool.c @@ -143,5 +143,5 @@ int ff_dnn_execute_layer_avg_pool(DnnOperand *operands, const int32_t *input_ope } } - return DNN_SUCCESS; + return 0; } diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c index dfa0d1ed36..2ac37d8855 100644 --- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c +++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c @@ -190,7 +190,7 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera #if HAVE_PTHREAD_CANCEL int thread_num = (ctx->options.conv2d_threads <= 0 || ctx->options.conv2d_threads > av_cpu_count()) ? (av_cpu_count() + 1) : (ctx->options.conv2d_threads); - int ret = DNN_SUCCESS, thread_stride; + int ret = 0, thread_stride; ThreadParam *thread_param; #else ThreadParam thread_param = { 0 }; @@ -260,6 +260,6 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera thread_param.thread_end = height - pad_size; dnn_execute_layer_conv2d_thread(&thread_param); - return DNN_SUCCESS; + return 0; #endif } diff --git a/libavfilter/dnn/dnn_backend_native_layer_dense.c b/libavfilter/dnn/dnn_backend_native_layer_dense.c index a22a484464..dff342c1f3 100644 --- a/libavfilter/dnn/dnn_backend_native_layer_dense.c +++ b/libavfilter/dnn/dnn_backend_native_layer_dense.c @@ -147,5 +147,5 @@ int ff_dnn_execute_layer_dense(DnnOperand *operands, const int32_t *input_operan output += dense_params->output_num; } } - return DNN_SUCCESS; + return 0; } diff --git a/libavfilter/dnn/dnn_backend_native_layer_depth2space.c b/libavfilter/dnn/dnn_backend_native_layer_depth2space.c index 82b1a52be2..358ac3bcaa 100644 --- a/libavfilter/dnn/dnn_backend_native_layer_depth2space.c +++ b/libavfilter/dnn/dnn_backend_native_layer_depth2space.c @@ -98,5 +98,5 @@ int ff_dnn_execute_layer_depth2space(DnnOperand *operands, const int32_t *input_ } output += output_linesize; } - return DNN_SUCCESS; + return 0; } diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c index 2f140e996b..cf012aca4c 100644 --- a/libavfilter/dnn/dnn_backend_openvino.c +++ b/libavfilter/dnn/dnn_backend_openvino.c @@ -191,7 +191,7 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) } ie_blob_free(&input_blob); - return DNN_SUCCESS; + return 0; } static void infer_completion_callback(void *args) @@ -303,7 +303,7 @@ static void infer_completion_callback(void *args) static int init_model_ov(OVModel *ov_model, const char *input_name, const char *output_name) { - int ret = DNN_SUCCESS; + int ret = 0; OVContext *ctx = &ov_model->ctx; IEStatusCode status; ie_available_devices_t a_dev; @@ -433,7 +433,7 @@ static int init_model_ov(OVModel *ov_model, const char *input_name, const char * goto err; } - return DNN_SUCCESS; + return 0; err: ff_dnn_free_model_ov(&ov_model->model); @@ -444,7 +444,7 @@ static int execute_model_ov(OVRequestItem *request, Queue *inferenceq) { IEStatusCode status; LastLevelTaskItem *lltask; - int ret = DNN_SUCCESS; + int ret = 0; TaskItem *task; OVContext *ctx; OVModel *ov_model; @@ -452,7 +452,7 @@ static int execute_model_ov(OVRequestItem *request, Queue *inferenceq) if (ff_queue_size(inferenceq) == 0) { ie_infer_request_free(&request->infer_request); av_freep(&request); - return DNN_SUCCESS; + return 0; } lltask = ff_queue_peek_front(inferenceq); @@ -462,7 +462,7 @@ static int execute_model_ov(OVRequestItem *request, Queue *inferenceq) if (task->async) { ret = fill_model_input_ov(ov_model, request); - if (ret != DNN_SUCCESS) { + if (ret != 0) { goto err; } status = ie_infer_set_completion_callback(request->infer_request, &request->callback); @@ -477,10 +477,10 @@ static int execute_model_ov(OVRequestItem *request, Queue *inferenceq) ret = DNN_GENERIC_ERROR; goto err; } - return DNN_SUCCESS; + return 0; } else { ret = fill_model_input_ov(ov_model, request); - if (ret != DNN_SUCCESS) { + if (ret != 0) { goto err; } status = ie_infer_request_infer(request->infer_request); @@ -490,7 +490,7 @@ static int execute_model_ov(OVRequestItem *request, Queue *inferenceq) goto err; } infer_completion_callback(request); - return (task->inference_done == task->inference_todo) ? DNN_SUCCESS : DNN_GENERIC_ERROR; + return (task->inference_done == task->inference_todo) ? 0 : DNN_GENERIC_ERROR; } err: if (ff_safe_queue_push_back(ov_model->request_queue, request) < 0) { @@ -537,7 +537,7 @@ static int get_input_ov(void *model, DNNData *input, const char *input_name) input->height = input_resizable ? -1 : dims.dims[2]; input->width = input_resizable ? -1 : dims.dims[3]; input->dt = precision_to_datatype(precision); - return DNN_SUCCESS; + return 0; } else { //incorrect input name APPEND_STRING(all_input_names, model_input_name) @@ -604,7 +604,7 @@ static int extract_lltask_from_task(DNNFunctionType func_type, TaskItem *task, Q av_freep(&lltask); return AVERROR(ENOMEM); } - return DNN_SUCCESS; + return 0; } case DFT_ANALYTICS_CLASSIFY: { @@ -617,7 +617,7 @@ static int extract_lltask_from_task(DNNFunctionType func_type, TaskItem *task, Q task->inference_done = 0; if (!contain_valid_detection_bbox(frame)) { - return DNN_SUCCESS; + return 0; } sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DETECTION_BBOXES); @@ -645,7 +645,7 @@ static int extract_lltask_from_task(DNNFunctionType func_type, TaskItem *task, Q return AVERROR(ENOMEM); } } - return DNN_SUCCESS; + return 0; } default: av_assert0(!"should not reach here"); @@ -690,19 +690,19 @@ static int get_output_ov(void *model, const char *input_name, int input_width, i if (!ov_model->exe_network) { ret = init_model_ov(ov_model, input_name, output_name); - if (ret != DNN_SUCCESS) { + if (ret != 0) { av_log(ctx, AV_LOG_ERROR, "Failed init OpenVINO exectuable network or inference request\n"); return ret; } } ret = ff_dnn_fill_gettingoutput_task(&task, &exec_params, ov_model, input_height, input_width, ctx); - if (ret != DNN_SUCCESS) { + if (ret != 0) { goto err; } ret = extract_lltask_from_task(ov_model->model->func_type, &task, ov_model->lltask_queue, NULL); - if (ret != DNN_SUCCESS) { + if (ret != 0) { av_log(ctx, AV_LOG_ERROR, "unable to extract inference from task.\n"); goto err; } @@ -795,7 +795,7 @@ int ff_dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams *exec_param if (!ov_model->exe_network) { ret = init_model_ov(ov_model, exec_params->input_name, exec_params->output_names[0]); - if (ret != DNN_SUCCESS) { + if (ret != 0) { av_log(ctx, AV_LOG_ERROR, "Failed init OpenVINO exectuable network or inference request\n"); return ret; } @@ -808,7 +808,7 @@ int ff_dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams *exec_param } ret = ff_dnn_fill_task(task, exec_params, ov_model, ctx->options.async, 1); - if (ret != DNN_SUCCESS) { + if (ret != 0) { av_freep(&task); return ret; } @@ -820,7 +820,7 @@ int ff_dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams *exec_param } ret = extract_lltask_from_task(model->func_type, task, ov_model->lltask_queue, exec_params); - if (ret != DNN_SUCCESS) { + if (ret != 0) { av_log(ctx, AV_LOG_ERROR, "unable to extract inference from task.\n"); return ret; } @@ -834,12 +834,12 @@ int ff_dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams *exec_param } ret = execute_model_ov(request, ov_model->lltask_queue); - if (ret != DNN_SUCCESS) { + if (ret != 0) { return ret; } } - return DNN_SUCCESS; + return 0; } else { if (model->func_type == DFT_ANALYTICS_CLASSIFY) { @@ -879,7 +879,7 @@ int ff_dnn_flush_ov(const DNNModel *model) if (ff_queue_size(ov_model->lltask_queue) == 0) { // no pending task need to flush - return DNN_SUCCESS; + return 0; } request = ff_safe_queue_pop_front(ov_model->request_queue); @@ -889,7 +889,7 @@ int ff_dnn_flush_ov(const DNNModel *model) } ret = fill_model_input_ov(ov_model, request); - if (ret != DNN_SUCCESS) { + if (ret != 0) { av_log(ctx, AV_LOG_ERROR, "Failed to fill model input.\n"); return ret; } @@ -904,7 +904,7 @@ int ff_dnn_flush_ov(const DNNModel *model) return DNN_GENERIC_ERROR; } - return DNN_SUCCESS; + return 0; } void ff_dnn_free_model_ov(DNNModel **model) diff --git a/libavfilter/dnn/dnn_backend_tf.c b/libavfilter/dnn/dnn_backend_tf.c index d021e3c3bb..94d9533296 100644 --- a/libavfilter/dnn/dnn_backend_tf.c +++ b/libavfilter/dnn/dnn_backend_tf.c @@ -151,7 +151,7 @@ static TFInferRequest *tf_create_inference_request(void) * Start synchronous inference for the TensorFlow model. * * @param request pointer to the TFRequestItem for inference - * @retval DNN_SUCCESS if execution is successful + * @retval 0 if execution is successful * @retval AVERROR(EINVAL) if request is NULL * @retval DNN_GENERIC_ERROR if execution fails */ @@ -181,7 +181,7 @@ static int tf_start_inference(void *args) } return DNN_GENERIC_ERROR; } - return DNN_SUCCESS; + return 0; } /** @@ -220,7 +220,7 @@ static int extract_lltask_from_task(TaskItem *task, Queue *lltask_queue) av_freep(&lltask); return AVERROR(ENOMEM); } - return DNN_SUCCESS; + return 0; } static TF_Buffer *read_graph(const char *model_filename) @@ -311,7 +311,7 @@ static int get_input_tf(void *model, DNNData *input, const char *input_name) input->width = dims[2]; input->channels = dims[3]; - return DNN_SUCCESS; + return 0; } static int get_output_tf(void *model, const char *input_name, int input_width, int input_height, @@ -331,12 +331,12 @@ static int get_output_tf(void *model, const char *input_name, int input_width, i }; ret = ff_dnn_fill_gettingoutput_task(&task, &exec_params, tf_model, input_height, input_width, ctx); - if (ret != DNN_SUCCESS) { + if (ret != 0) { goto err; } ret = extract_lltask_from_task(&task, tf_model->lltask_queue); - if (ret != DNN_SUCCESS) { + if (ret != 0) { av_log(ctx, AV_LOG_ERROR, "unable to extract inference from task.\n"); goto err; } @@ -487,7 +487,7 @@ static int load_tf_model(TFModel *tf_model, const char *model_filename) } } - return DNN_SUCCESS; + return 0; } #define NAME_BUFFER_SIZE 256 @@ -606,7 +606,7 @@ static int add_conv_layer(TFModel *tf_model, TF_Operation *transpose_op, TF_Oper goto err; } - return DNN_SUCCESS; + return 0; err: TF_DeleteTensor(kernel_tensor); TF_DeleteTensor(biases_tensor); @@ -635,7 +635,7 @@ static int add_depth_to_space_layer(TFModel *tf_model, TF_Operation **cur_op, return DNN_GENERIC_ERROR; } - return DNN_SUCCESS; + return 0; } static int add_pad_layer(TFModel *tf_model, TF_Operation **cur_op, @@ -693,7 +693,7 @@ static int add_pad_layer(TFModel *tf_model, TF_Operation **cur_op, return DNN_GENERIC_ERROR; } - return DNN_SUCCESS; + return 0; } static int add_maximum_layer(TFModel *tf_model, TF_Operation **cur_op, @@ -742,7 +742,7 @@ static int add_maximum_layer(TFModel *tf_model, TF_Operation **cur_op, return DNN_GENERIC_ERROR; } - return DNN_SUCCESS; + return 0; } static int load_native_model(TFModel *tf_model, const char *model_filename) @@ -808,7 +808,7 @@ static int load_native_model(TFModel *tf_model, const char *model_filename) for (layer = 0; layer < native_model->layers_num; ++layer){ switch (native_model->layers[layer].type){ case DLT_INPUT: - layer_add_res = DNN_SUCCESS; + layer_add_res = 0; break; case DLT_CONV2D: layer_add_res = add_conv_layer(tf_model, transpose_op, &op, @@ -830,7 +830,7 @@ static int load_native_model(TFModel *tf_model, const char *model_filename) CLEANUP_ON_ERROR(tf_model); } - if (layer_add_res != DNN_SUCCESS){ + if (layer_add_res != 0){ CLEANUP_ON_ERROR(tf_model); } } @@ -846,7 +846,7 @@ static int load_native_model(TFModel *tf_model, const char *model_filename) ff_dnn_free_model_native(&model); - return DNN_SUCCESS; + return 0; } DNNModel *ff_dnn_load_model_tf(const char *model_filename, DNNFunctionType func_type, const char *options, AVFilterContext *filter_ctx) @@ -876,8 +876,8 @@ DNNModel *ff_dnn_load_model_tf(const char *model_filename, DNNFunctionType func_ goto err; } - if (load_tf_model(tf_model, model_filename) != DNN_SUCCESS){ - if (load_native_model(tf_model, model_filename) != DNN_SUCCESS){ + if (load_tf_model(tf_model, model_filename) != 0){ + if (load_native_model(tf_model, model_filename) != 0){ goto err; } } @@ -957,7 +957,7 @@ static int fill_model_input_tf(TFModel *tf_model, TFRequestItem *request) { request->lltask = lltask; ret = get_input_tf(tf_model, &input, task->input_name); - if (ret != DNN_SUCCESS) { + if (ret != 0) { goto err; } @@ -1031,7 +1031,7 @@ static int fill_model_input_tf(TFModel *tf_model, TFRequestItem *request) { infer_request->tf_outputs[i].index = 0; } - return DNN_SUCCESS; + return 0; err: tf_free_request(infer_request); return ret; @@ -1105,7 +1105,7 @@ static int execute_model_tf(TFRequestItem *request, Queue *lltask_queue) if (ff_queue_size(lltask_queue) == 0) { destroy_request_item(&request); - return DNN_SUCCESS; + return 0; } lltask = ff_queue_peek_front(lltask_queue); @@ -1114,23 +1114,23 @@ static int execute_model_tf(TFRequestItem *request, Queue *lltask_queue) ctx = &tf_model->ctx; ret = fill_model_input_tf(tf_model, request); - if (ret != DNN_SUCCESS) { + if (ret != 0) { goto err; } if (task->async) { - if (ff_dnn_start_inference_async(ctx, &request->exec_module) != DNN_SUCCESS) { + if (ff_dnn_start_inference_async(ctx, &request->exec_module) != 0) { goto err; } - return DNN_SUCCESS; + return 0; } else { ret = tf_start_inference(request); - if (ret != DNN_SUCCESS) { + if (ret != 0) { goto err; } infer_completion_callback(request); - return (task->inference_done == task->inference_todo) ? DNN_SUCCESS : DNN_GENERIC_ERROR; + return (task->inference_done == task->inference_todo) ? 0 : DNN_GENERIC_ERROR; } err: tf_free_request(request->infer_request); @@ -1160,7 +1160,7 @@ int ff_dnn_execute_model_tf(const DNNModel *model, DNNExecBaseParams *exec_param } ret = ff_dnn_fill_task(task, exec_params, tf_model, ctx->options.async, 1); - if (ret != DNN_SUCCESS) { + if (ret != 0) { av_freep(&task); return ret; } @@ -1172,7 +1172,7 @@ int ff_dnn_execute_model_tf(const DNNModel *model, DNNExecBaseParams *exec_param } ret = extract_lltask_from_task(task, tf_model->lltask_queue); - if (ret != DNN_SUCCESS) { + if (ret != 0) { av_log(ctx, AV_LOG_ERROR, "unable to extract last level task from task.\n"); return ret; } @@ -1200,7 +1200,7 @@ int ff_dnn_flush_tf(const DNNModel *model) if (ff_queue_size(tf_model->lltask_queue) == 0) { // no pending task need to flush - return DNN_SUCCESS; + return 0; } request = ff_safe_queue_pop_front(tf_model->request_queue); @@ -1210,7 +1210,7 @@ int ff_dnn_flush_tf(const DNNModel *model) } ret = fill_model_input_tf(tf_model, request); - if (ret != DNN_SUCCESS) { + if (ret != 0) { av_log(ctx, AV_LOG_ERROR, "Failed to fill model input.\n"); if (ff_safe_queue_push_back(tf_model->request_queue, request) < 0) { destroy_request_item(&request); diff --git a/libavfilter/dnn/dnn_io_proc.c b/libavfilter/dnn/dnn_io_proc.c index 36cc051e5e..7961bf6b95 100644 --- a/libavfilter/dnn/dnn_io_proc.c +++ b/libavfilter/dnn/dnn_io_proc.c @@ -57,12 +57,12 @@ int ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx) (const int[4]){frame->width * 3 * sizeof(float), 0, 0, 0}, 0, frame->height, (uint8_t * const*)frame->data, frame->linesize); sws_freeContext(sws_ctx); - return DNN_SUCCESS; + return 0; case AV_PIX_FMT_GRAYF32: av_image_copy_plane(frame->data[0], frame->linesize[0], output->data, bytewidth, bytewidth, frame->height); - return DNN_SUCCESS; + return 0; case AV_PIX_FMT_YUV420P: case AV_PIX_FMT_YUV422P: case AV_PIX_FMT_YUV444P: @@ -88,13 +88,13 @@ int ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx) (const int[4]){frame->width * sizeof(float), 0, 0, 0}, 0, frame->height, (uint8_t * const*)frame->data, frame->linesize); sws_freeContext(sws_ctx); - return DNN_SUCCESS; + return 0; default: avpriv_report_missing_feature(log_ctx, "%s", av_get_pix_fmt_name(frame->format)); return AVERROR(ENOSYS); } - return DNN_SUCCESS; + return 0; } int ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx) @@ -169,7 +169,7 @@ int ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx) return AVERROR(ENOSYS); } - return DNN_SUCCESS; + return 0; } static enum AVPixelFormat get_pixel_format(DNNData *data) @@ -197,7 +197,7 @@ int ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t bbox_index uint8_t *bbox_data[4]; struct SwsContext *sws_ctx; int linesizes[4]; - int ret = DNN_SUCCESS; + int ret = 0; enum AVPixelFormat fmt; int left, top, width, height; const AVDetectionBBoxHeader *header; @@ -255,7 +255,7 @@ int ff_frame_to_dnn_detect(AVFrame *frame, DNNData *input, void *log_ctx) { struct SwsContext *sws_ctx; int linesizes[4]; - int ret = DNN_SUCCESS; + int ret = 0; enum AVPixelFormat fmt = get_pixel_format(input); sws_ctx = sws_getContext(frame->width, frame->height, frame->format, input->width, input->height, fmt, diff --git a/libavfilter/dnn_interface.h b/libavfilter/dnn_interface.h index 06e71f7946..ef8d7ae66f 100644 --- a/libavfilter/dnn_interface.h +++ b/libavfilter/dnn_interface.h @@ -32,8 +32,6 @@ #define DNN_GENERIC_ERROR FFERRTAG('D','N','N','!') -typedef enum {DNN_SUCCESS, DNN_ERROR} DNNReturnType; - typedef enum {DNN_NATIVE, DNN_TF, DNN_OV} DNNBackendType; typedef enum {DNN_FLOAT = 1, DNN_UINT8 = 4} DNNDataType; diff --git a/libavfilter/vf_derain.c b/libavfilter/vf_derain.c index 6758cc05d2..86e9eb8752 100644 --- a/libavfilter/vf_derain.c +++ b/libavfilter/vf_derain.c @@ -74,7 +74,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) av_frame_copy_props(out, in); dnn_result = ff_dnn_execute_model(&dr_context->dnnctx, in, out); - if (dnn_result != DNN_SUCCESS){ + if (dnn_result != 0){ av_log(ctx, AV_LOG_ERROR, "failed to execute model\n"); av_frame_free(&in); return dnn_result; diff --git a/libavfilter/vf_dnn_classify.c b/libavfilter/vf_dnn_classify.c index 5c6942d86a..c612ba8e80 100644 --- a/libavfilter/vf_dnn_classify.c +++ b/libavfilter/vf_dnn_classify.c @@ -213,7 +213,7 @@ static int dnn_classify_flush_frame(AVFilterLink *outlink, int64_t pts, int64_t DNNAsyncStatusType async_state; ret = ff_dnn_flush(&ctx->dnnctx); - if (ret != DNN_SUCCESS) { + if (ret != 0) { return -1; } @@ -253,7 +253,7 @@ static int dnn_classify_activate(AVFilterContext *filter_ctx) if (ret < 0) return ret; if (ret > 0) { - if (ff_dnn_execute_model_classification(&ctx->dnnctx, in, NULL, ctx->target) != DNN_SUCCESS) { + if (ff_dnn_execute_model_classification(&ctx->dnnctx, in, NULL, ctx->target) != 0) { return AVERROR(EIO); } } diff --git a/libavfilter/vf_dnn_detect.c b/libavfilter/vf_dnn_detect.c index 51f8b430df..dd4507250f 100644 --- a/libavfilter/vf_dnn_detect.c +++ b/libavfilter/vf_dnn_detect.c @@ -356,7 +356,7 @@ static int dnn_detect_flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *o DNNAsyncStatusType async_state; ret = ff_dnn_flush(&ctx->dnnctx); - if (ret != DNN_SUCCESS) { + if (ret != 0) { return -1; } @@ -396,7 +396,7 @@ static int dnn_detect_activate(AVFilterContext *filter_ctx) if (ret < 0) return ret; if (ret > 0) { - if (ff_dnn_execute_model(&ctx->dnnctx, in, NULL) != DNN_SUCCESS) { + if (ff_dnn_execute_model(&ctx->dnnctx, in, NULL) != 0) { return AVERROR(EIO); } } diff --git a/libavfilter/vf_dnn_processing.c b/libavfilter/vf_dnn_processing.c index 4a1ff5898f..cac096a19f 100644 --- a/libavfilter/vf_dnn_processing.c +++ b/libavfilter/vf_dnn_processing.c @@ -139,7 +139,7 @@ static int config_input(AVFilterLink *inlink) int check; result = ff_dnn_get_input(&ctx->dnnctx, &model_input); - if (result != DNN_SUCCESS) { + if (result != 0) { av_log(ctx, AV_LOG_ERROR, "could not get input from the model\n"); return result; } @@ -199,7 +199,7 @@ static int config_output(AVFilterLink *outlink) // have a try run in case that the dnn model resize the frame result = ff_dnn_get_output(&ctx->dnnctx, inlink->w, inlink->h, &outlink->w, &outlink->h); - if (result != DNN_SUCCESS) { + if (result != 0) { av_log(ctx, AV_LOG_ERROR, "could not get output from the model\n"); return result; } @@ -247,7 +247,7 @@ static int flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *out_pts) DNNAsyncStatusType async_state; ret = ff_dnn_flush(&ctx->dnnctx); - if (ret != DNN_SUCCESS) { + if (ret != 0) { return -1; } @@ -296,7 +296,7 @@ static int activate(AVFilterContext *filter_ctx) return AVERROR(ENOMEM); } av_frame_copy_props(out, in); - if (ff_dnn_execute_model(&ctx->dnnctx, in, out) != DNN_SUCCESS) { + if (ff_dnn_execute_model(&ctx->dnnctx, in, out) != 0) { return AVERROR(EIO); } } diff --git a/libavfilter/vf_sr.c b/libavfilter/vf_sr.c index 02d9452681..0890c8ba18 100644 --- a/libavfilter/vf_sr.c +++ b/libavfilter/vf_sr.c @@ -82,7 +82,7 @@ static int config_output(AVFilterLink *outlink) // have a try run in case that the dnn model resize the frame result = ff_dnn_get_output(&ctx->dnnctx, inlink->w, inlink->h, &out_width, &out_height); - if (result != DNN_SUCCESS) { + if (result != 0) { av_log(ctx, AV_LOG_ERROR, "could not get output from the model\n"); return result; } @@ -139,7 +139,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) dnn_result = ff_dnn_execute_model(&ctx->dnnctx, in, out); } - if (dnn_result != DNN_SUCCESS){ + if (dnn_result != 0){ av_log(ctx, AV_LOG_ERROR, "failed to execute loaded model\n"); av_frame_free(&in); av_frame_free(&out);