From patchwork Sun Aug 8 10:55:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shubhanshu Saxena X-Patchwork-Id: 29344 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6c0f:0:0:0:0:0 with SMTP id a15csp1980820ioh; Sun, 8 Aug 2021 03:56:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMMHoasJcJwTKdpceIVvHnVi2v7jFT4g6Oxs3lddO0i98/d315CDuYh9HkkV/NEQ+thbHI X-Received: by 2002:a05:6402:361:: with SMTP id s1mr23082465edw.172.1628420190085; Sun, 08 Aug 2021 03:56:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628420190; cv=none; d=google.com; s=arc-20160816; b=ZK8tyWG/9djOyEgGkn31e1N/fgW/AQA2eEmfV7ISIx/dfxmBEdI7xrzk/GQ87pAvNp ay63IrlxWxn/+4RuOY9NpNMT19to/NytcAlFn0QO65t9u9MvTPbnJn65OIt0uAVbqTZk mq3nFb0g3maW7YslA4CVrI0KSPSKF3qWQZyuitITHQ2pKV0OpG5KiadNArou07jZ2i9r X0dRxah+qoPQxsASwTKxDk7q7Q0IWH1KVzFt9Ci7WXiabp/bChMEwd7NeJgMBRgPU3vV JRjVVcR5imzQrshz3zlgxyS4oARRyafnpVRjVoWueBlioDeC8U7t16LZiPRa+rHPmyJC i4SQ== 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=2BaZt/nZ8tYkB2dMxu8/Sj+l4fN6MVIaca0p0tqv2lg=; b=tDowgRi/rsjnyGTa1YntKOqeVhfxrJY8sFOq66S2Tuv3wiCC1/h0MCXZhsPUPb4wuR knOGHWEUXFv7Kx+MSX5ga8Dt57QGYZiWZeXu9G7rbIueznP4D2501zwez0Bj4ti6AeEQ idKshiTfpSIzaPmTI3rlWYPppVz0py3R0r5gnljE1l4gMJpWTXei1Qrr96qIEzaII34V H0kG1+RCe750AfqeYhuVdMieJEdqTrQ1BoTMmOORkPQ9uXhggIQ4Ho1OtY6M8g6N6DSs I5CCdA6gOXrmOoK59wF9aZ+0wvGbK0/Q/oaIgd5G37imm6ormK4vgkxbOaGZ5mvAazOC sh/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=OYTWeduB; 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 o13si10950201ejh.129.2021.08.08.03.56.29; Sun, 08 Aug 2021 03:56:30 -0700 (PDT) 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=20161025 header.b=OYTWeduB; 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 A0CA768A451; Sun, 8 Aug 2021 13:56:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4225C68A000 for ; Sun, 8 Aug 2021 13:56:11 +0300 (EEST) Received: by mail-pj1-f52.google.com with SMTP id u21-20020a17090a8915b02901782c36f543so20916743pjn.4 for ; Sun, 08 Aug 2021 03:56:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9+fJlnI+zvoCClE87bRDOXCrcDAq6TMyrQhV785zezY=; b=OYTWeduBk9k3tE6+6ebR5cvSUdwSCWFwD8yMoNTPGoqa1yEj6eAAymaraDyfNbg9Wn KDIxtzXrUsFMJnYUVEHa0iIAoulN9x4G+z4+R9otwJmGgqlwXIFi0JAQwneDk6jJyudI vZAhHZMb86Iwdr0ZUzdIIBAiW8vR5dNaEm9q12lERSMX/X5obMKyP0q2kmci++K4xKmD stuxuwgeEzCvm30yIyYS8AGZn+T23W9mMlQYPOl0hupp5tn5y2VvYvTFnmb1E3/Jz2Di RxZHQ1nP3Cps8S+WAvrxioDPKdpBQyB78K0jdEWGsxIu1nIID++Er2NDqJt5mXGhJHSy WLCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9+fJlnI+zvoCClE87bRDOXCrcDAq6TMyrQhV785zezY=; b=rvWMHbcuu2TFCwuPLkZWQ9Ed2/H0D1jxUmcJyZOKqLvz1AGlAgHh1LfDkyJub2VPg/ F7cea/fWHYTcBKlYQLuNGCNW2QDAEC9GIHfFbvb9D6Ehp9rM8RQT+12qh7hFCOatiBPI a8MdZD27iI4X1eabx1DFCokiBgMpFkEoX6xjXMITShYZM2rIio4MdZkQYsRfjDxAEjun Z/4FhicQrbEg+GRt8GejQApz0zGfZUcN8LGMwqUiaVlmwcs23Kvw0m0Kpf543853/Htj D8wr1Pornbm+QUWmsAqUm0LjesbYEPG518yqoWYyVpiOQFgHL2LxAfFjDKIpzClryFu8 Y9Fg== X-Gm-Message-State: AOAM531YHmTVZskrmDdAK9ppGxutOaimjyw71ZkTBuKP384x5/c9iXK/ S5g0LEhuMbJbqQuT4KZR6E9Tg01MyMaatA== X-Received: by 2002:a17:90a:eb0c:: with SMTP id j12mr30116320pjz.116.1628420169309; Sun, 08 Aug 2021 03:56:09 -0700 (PDT) Received: from localhost.localdomain ([103.133.123.69]) by smtp.googlemail.com with ESMTPSA id r18sm20917405pgk.54.2021.08.08.03.56.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Aug 2021 03:56:09 -0700 (PDT) From: Shubhanshu Saxena To: ffmpeg-devel@ffmpeg.org Date: Sun, 8 Aug 2021 16:25:32 +0530 Message-Id: <20210808105539.18822-2-shubhanshu.e01@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210808105539.18822-1-shubhanshu.e01@gmail.com> References: <20210808105539.18822-1-shubhanshu.e01@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 2/9] [GSoC] lavfi/dnn: Common Function to Get Async Result in DNN Backends 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: Qo1urrMVBSiF This commits refactors the get async result function for common use in all three backends. Signed-off-by: Shubhanshu Saxena --- libavfilter/dnn/dnn_backend_common.c | 20 ++++++++++++++++++++ libavfilter/dnn/dnn_backend_common.h | 15 +++++++++++++++ libavfilter/dnn/dnn_backend_openvino.c | 18 +----------------- libavfilter/dnn/queue.h | 1 + 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_common.c b/libavfilter/dnn/dnn_backend_common.c index 4c9045501f..df4bab85e0 100644 --- a/libavfilter/dnn/dnn_backend_common.c +++ b/libavfilter/dnn/dnn_backend_common.c @@ -122,3 +122,23 @@ DNNReturnType ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_ #endif return DNN_SUCCESS; } + +DNNAsyncStatusType ff_dnn_get_async_result_common(Queue *task_queue, AVFrame **in, AVFrame **out) +{ + TaskItem *task = ff_queue_peek_front(task_queue); + + if (!task) { + return DAST_EMPTY_QUEUE; + } + + if (task->inference_done != task->inference_todo) { + return DAST_NOT_READY; + } + + *in = task->in_frame; + *out = task->out_frame; + ff_queue_pop_front(task_queue); + av_freep(&task); + + return DAST_SUCCESS; +} diff --git a/libavfilter/dnn/dnn_backend_common.h b/libavfilter/dnn/dnn_backend_common.h index 96e4df9676..e1d678b230 100644 --- a/libavfilter/dnn/dnn_backend_common.h +++ b/libavfilter/dnn/dnn_backend_common.h @@ -24,6 +24,7 @@ #ifndef AVFILTER_DNN_DNN_BACKEND_COMMON_H #define AVFILTER_DNN_DNN_BACKEND_COMMON_H +#include "queue.h" #include "../dnn_interface.h" #include "libavutil/thread.h" @@ -122,4 +123,18 @@ DNNReturnType ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module); */ DNNReturnType ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_module); +/** + * Extract input and output frame from the Task Queue after + * asynchronous inference. + * + * @param task_queue pointer to the task queue of the backend + * @param in double pointer to the input frame + * @param out double pointer to the output frame + * + * @retval DAST_EMPTY_QUEUE if task queue is empty + * @retval DAST_NOT_READY if inference not completed yet. + * @retval DAST_SUCCESS if result successfully extracted + */ +DNNAsyncStatusType ff_dnn_get_async_result_common(Queue *task_queue, AVFrame **in, AVFrame **out); + #endif diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c index 8d23446296..47cbd48ba2 100644 --- a/libavfilter/dnn/dnn_backend_openvino.c +++ b/libavfilter/dnn/dnn_backend_openvino.c @@ -32,7 +32,6 @@ #include "libavutil/avstring.h" #include "libavutil/detection_bbox.h" #include "../internal.h" -#include "queue.h" #include "safe_queue.h" #include #include "dnn_backend_common.h" @@ -883,22 +882,7 @@ DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, DNNExecBasePa DNNAsyncStatusType ff_dnn_get_async_result_ov(const DNNModel *model, AVFrame **in, AVFrame **out) { OVModel *ov_model = model->model; - TaskItem *task = ff_queue_peek_front(ov_model->task_queue); - - if (!task) { - return DAST_EMPTY_QUEUE; - } - - if (task->inference_done != task->inference_todo) { - return DAST_NOT_READY; - } - - *in = task->in_frame; - *out = task->out_frame; - ff_queue_pop_front(ov_model->task_queue); - av_freep(&task); - - return DAST_SUCCESS; + return ff_dnn_get_async_result_common(ov_model->task_queue, in, out); } DNNReturnType ff_dnn_flush_ov(const DNNModel *model) diff --git a/libavfilter/dnn/queue.h b/libavfilter/dnn/queue.h index 2524d5fa59..9ab5c89f65 100644 --- a/libavfilter/dnn/queue.h +++ b/libavfilter/dnn/queue.h @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #ifndef AVFILTER_DNN_QUEUE_H #define AVFILTER_DNN_QUEUE_H