From patchwork Tue Jan 11 20:46:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33269 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp4052322iog; Tue, 11 Jan 2022 12:55:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJyoMZohoYfT2/b516aeUQuriBTpIlGUlodxPUqGrmZSsNkvLmPSeAD0YfHwS/l8+SNnUenu X-Received: by 2002:a17:906:99c3:: with SMTP id s3mr5238559ejn.486.1641934545824; Tue, 11 Jan 2022 12:55:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641934545; cv=none; d=google.com; s=arc-20160816; b=PTDFbMTtVznbwDSuzzAOiy9LzpEH2+hdkq0nIcjg8NR6PLmej5rV8s+S7igirZqJxt FAsqelXi6xfxrUhx0p/Pjex2inB2oQH4R8RAQpOE8GEXvpC8CaF6PVSw1I8gSYRqQoaT Tz8YwLWQUDyBWbZMWmzVz9XZS/Ow1DuuRhcU8+UEADFO6CGAJde2Zf4QafTsAYgYUU15 KmvKTLLHlcLdJS9JxfpNpp5MtxNpK5rsrotKrijMDwjVQlMu4yr12o3pNNY94LCIESCL Hcqj9pHRpsgXmHtFyQq0YBhqRT/bbJ6neEHbQL7TGaKKC1LbTzsiLu1aekAYD/DWaNmw uIlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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:delivered-to; bh=C0BfCSsS/rY/QXHs0Zi9RaH3XtwWWz3ZAyoaG1saZn8=; b=GW+V/DK1qMy1MhXJOk0FhZ8zsHoW4QMIh2J+D+pjs8CS7nKJB0b9RN3j2Sw62IUzOt S/gaTlZCE43djedPPEMuRLprJ68HRv/KwpvjXH3RsDslorqEZFHuiGlmQcPeK/jp+nJZ I/inM7OXrk1f8dPyfYyFuMXCHXQEvyXYvT+dMyD1RRCO7WGol+XlWMIKOTfrYXHecjTe KD7ZdBAIj802/X/8gwE3Wmppe+zbdsoidCLxUavrw4Zb/3krOEIgOUp1DrSbpnCc1lra sw6hZ8H3qojmM7wFLwu7AuLRnCXe9oNBZTF0u9qA595B1p+J0UY2qvFhdxIICrZvijnB doag== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ds15si6185291ejc.509.2022.01.11.12.55.45; Tue, 11 Jan 2022 12:55:45 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ACE9868AFD8; Tue, 11 Jan 2022 22:54:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 447D968AF57 for ; Tue, 11 Jan 2022 22:54:49 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B8B122404FE for ; Tue, 11 Jan 2022 21:54:48 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id g4ApduHry6L2 for ; Tue, 11 Jan 2022 21:54:48 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id D9AEB240506 for ; Tue, 11 Jan 2022 21:54:46 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 6C77A3A0E76; Tue, 11 Jan 2022 21:47:25 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 21:46:07 +0100 Message-Id: <20220111204610.14262-32-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220111204610.14262-1-anton@khirnov.net> References: <20220111204610.14262-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 32/35] lavfi/qsvvpp: switch to new FIFO API 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: XatUSxjDyf5W --- libavfilter/qsvvpp.c | 46 +++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c index d1218355c7..60da1d47c5 100644 --- a/libavfilter/qsvvpp.c +++ b/libavfilter/qsvvpp.c @@ -40,6 +40,11 @@ static const AVRational default_tb = { 1, 90000 }; +typedef struct QSVAsyncFrame { + mfxSyncPoint sync; + QSVFrame *frame; +} QSVAsyncFrame; + static const struct { int mfx_iopattern; const char *desc; @@ -642,16 +647,6 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s) return 0; } -static unsigned int qsv_fifo_item_size(void) -{ - return sizeof(mfxSyncPoint) + sizeof(QSVFrame*); -} - -static unsigned int qsv_fifo_size(const AVFifoBuffer* fifo) -{ - return av_fifo_size(fifo)/qsv_fifo_item_size(); -} - int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *param) { int i; @@ -727,7 +722,7 @@ int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *p s->got_frame = 0; /** keep fifo size at least 1. Even when async_depth is 0, fifo is used. */ - s->async_fifo = av_fifo_alloc((param->async_depth + 1) * qsv_fifo_item_size()); + s->async_fifo = av_fifo_alloc2(param->async_depth + 1, sizeof(QSVAsyncFrame), 0); s->async_depth = param->async_depth; if (!s->async_fifo) { ret = AVERROR(ENOMEM); @@ -799,24 +794,25 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr { AVFilterContext *ctx = inlink->dst; AVFilterLink *outlink = ctx->outputs[0]; + QSVAsyncFrame aframe; mfxSyncPoint sync; QSVFrame *in_frame, *out_frame, *tmp; int ret, filter_ret; - while (s->eof && qsv_fifo_size(s->async_fifo)) { - av_fifo_generic_read(s->async_fifo, &tmp, sizeof(tmp), NULL); - av_fifo_generic_read(s->async_fifo, &sync, sizeof(sync), NULL); - if (MFXVideoCORE_SyncOperation(s->session, sync, 1000) < 0) + while (s->eof && av_fifo_can_read(s->async_fifo)) { + av_fifo_read(s->async_fifo, &aframe, 1); + + if (MFXVideoCORE_SyncOperation(s->session, aframe.sync, 1000) < 0) av_log(ctx, AV_LOG_WARNING, "Sync failed.\n"); - filter_ret = s->filter_frame(outlink, tmp->frame); + filter_ret = s->filter_frame(outlink, aframe.frame->frame); if (filter_ret < 0) { - av_frame_free(&tmp->frame); + av_frame_free(&aframe.frame->frame); return filter_ret; } - tmp->queued--; + aframe.frame->queued--; s->got_frame = 1; - tmp->frame = NULL; + aframe.frame->frame = NULL; }; if (!picref) @@ -853,16 +849,14 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr default_tb, outlink->time_base); out_frame->queued++; - av_fifo_generic_write(s->async_fifo, &out_frame, sizeof(out_frame), NULL); - av_fifo_generic_write(s->async_fifo, &sync, sizeof(sync), NULL); - + aframe = (QSVAsyncFrame){ sync, out_frame }; + av_fifo_write(s->async_fifo, &aframe, 1); - if (qsv_fifo_size(s->async_fifo) > s->async_depth) { - av_fifo_generic_read(s->async_fifo, &tmp, sizeof(tmp), NULL); - av_fifo_generic_read(s->async_fifo, &sync, sizeof(sync), NULL); + if (av_fifo_can_read(s->async_fifo) > s->async_depth) { + av_fifo_read(s->async_fifo, &aframe, 1); do { - ret = MFXVideoCORE_SyncOperation(s->session, sync, 1000); + ret = MFXVideoCORE_SyncOperation(s->session, aframe.sync, 1000); } while (ret == MFX_WRN_IN_EXECUTION); filter_ret = s->filter_frame(outlink, tmp->frame);