From patchwork Thu Feb 24 08:22:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shubhanshu Saxena X-Patchwork-Id: 34510 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1616647nkx; Thu, 24 Feb 2022 00:24:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJy4y7yOky3aztYb9QpGDpC1EBtV94YB11MMyNHtVLeETDhy0iZpTcZtnG5PRlBUQZ6XCubB X-Received: by 2002:a05:6402:c90:b0:410:a0a7:ca5b with SMTP id cm16-20020a0564020c9000b00410a0a7ca5bmr1170543edb.417.1645691055634; Thu, 24 Feb 2022 00:24:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645691055; cv=none; d=google.com; s=arc-20160816; b=02GNnQgzooJzvtqzhzfzDeSUMs+IOh+IZ3saMHiZ5zFJivVU5HlZOvTPxoHumSKzsv f3hTZTqjH6KOm2iBrIwQDrqW0IZgTFL1dGiD5sebNydSp4RoSMnLCMfnuVc04VoiIqOo ygzgtOH/hXBgtdnmyWCPfZCxIduE3CBoIijRBZ0LPbn3Z8m9AK8gmtoaXHBLDWFUkgSR 82rx8F8jug8e3LaL7w2Ou6zyPG6bCImcR/mEPxw++TJk+ZOGO7LouI48NRJ0p4cdzCil FHSWd/vTi7W7CEYwiCd6wq/jObW4rbxOSUj6ajF/uBi7th3bFA140Y6hC2Sar4X3AN7L dR3w== 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=JfAy3Uk48Z2tqkMdfkPbFEcGdAJFKV25Bf/kGT3S8BA=; b=GnzuUPKEDdrG8qWMdi4Lwfp9SYYizSTIKEa7glbVJdsenG5VKtLLXwj0ptt77KJ9nX ItJGkO5OtWUOhto91spCRoMKp1JNbYY85jFjPTcirYoXZgP8mrqx//atZE+FcyRE2Nm4 MYa0YRClcOgxXDzfi6DzGzCTROS+RPVUlmUDtiu5zsgGB9VK8kSzo+iMz8wxrb1Cczsx 2wkj6FhF9Fx7E8kuix9mRr6p+U2AiHSDXLHzqVIBf4nJsg+AYW5/OLJbdJJ09hqM3/If zY/vbzEy7Vu7N5l+F5/5iUa4TN+l73Uz2LSjQrmcYO0B8iWW8/BY+N2mhPBHa+UstMXW p76w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=CH9zwohJ; 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 fy11si1118509ejb.767.2022.02.24.00.24.15; Thu, 24 Feb 2022 00:24:15 -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=CH9zwohJ; 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 394D968B2F8; Thu, 24 Feb 2022 10:23:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D1D0968B2F6 for ; Thu, 24 Feb 2022 10:23:43 +0200 (EET) Received: by mail-pf1-f170.google.com with SMTP id u16so1199222pfg.12 for ; Thu, 24 Feb 2022 00:23:43 -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=7U03ylJHJwNhh93s0vk095oo0Qwt2EqdokV2h7t41IY=; b=CH9zwohJCIugFmJRm2rh14ZKPmTf5RHwJ8FT3gE7KsT/TddVyC5UNsVMof95jTlnus K0HCLQGmj777GIxsi0uovCqRs+WRLpCcbOd0dvYOKvTZ1im0pUNjC6d7uZyOqDh8ol4X a+4/rZtCDvNGkNI7HXYX8i3Nxp6wCgGjacHOWeCtzQ99fEHISt5zpa0sDiEv9RGjllqC tSXk9Jegz5hc5IFWapYTaS1Sf6wKtx18ncn+pUVqgLXihVN4YEpM37T6jRj1rsjQH4/f rNi4INFW/MXZ92oOG4gTXjMdo4AHs1qvvBD1J+pEnch50GJKK4B6dkwObmyBioptCFU5 5ZOA== 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=7U03ylJHJwNhh93s0vk095oo0Qwt2EqdokV2h7t41IY=; b=SYdUVjQx3nWpG8UsKblboz0pr9uTCL6o4i5CNdTrWamf9poHjKcpyz6VTd3oZketL3 YkAVfKdzm5UABAGYe8JdPnqNEcWMuAY8tblD6dmGV36hKAZZAHLNAMOd5lEmj7gTbFJu ZCvhgjdUa5RxRaveaVzWhF9Mt88bYFXNwc7dZvQMMTGUmRFZ5iKDgh6Fm4SK9zZYxvPp gAV8UPkE1zyh6QzbCFUQ4qYFGa8EFns+VHFlzZIim7BdRnYcr9Cl7k83sKyLU/wqhTWt tm4YXuvzSsXqepf471VqsJw1TLWjGT/ApPgQphiQ5GGF4wsgliPp9+yoimI2nlfPHITW KjOw== X-Gm-Message-State: AOAM530t+XwXfvNi5cqSLMdhNIlI8YitYBpuwkzX55DXfctiCXXXIW/h 1buBda6FV5uqN3IGCAYtsKrKVO8OislzOA== X-Received: by 2002:a65:6246:0:b0:363:396a:a00f with SMTP id q6-20020a656246000000b00363396aa00fmr1442220pgv.28.1645691022024; Thu, 24 Feb 2022 00:23:42 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 00:23:41 -0800 (PST) From: Shubhanshu Saxena To: ffmpeg-devel@ffmpeg.org Date: Thu, 24 Feb 2022 13:52:42 +0530 Message-Id: <20220224082243.11208-7-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 7/8] lavfi/dnn_backend_common: Return specific error codes 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: aEcgEGqa6Zwc 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 --- 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