From patchwork Mon Jan 24 14:46:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 33790 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:e71a:0:0:0:0:0 with SMTP id b26csp389464ioh; Mon, 24 Jan 2022 06:51:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJzYYX4PhX18CgPA7Lp/bifEiGuh5e2I80CHH8/5v1dFYxoZpCvmL2TDhowVrYINdFuDMU2U X-Received: by 2002:a17:906:fa85:: with SMTP id lt5mr12860835ejb.690.1643035874333; Mon, 24 Jan 2022 06:51:14 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id do6si8611545ejc.516.2022.01.24.06.51.13; Mon, 24 Jan 2022 06:51:14 -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=@outlook.com header.s=selector1 header.b=oW3xeJSo; arc=fail (body hash mismatch); 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=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1BC5968B18E; Mon, 24 Jan 2022 16:48:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-oln040092065052.outbound.protection.outlook.com [40.92.65.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1D58968B05B for ; Mon, 24 Jan 2022 16:48:48 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EeTUI3JC7WyUXtfF+HlKv/t3B6GJtI0YZevuu1b6ScX1TvV03rqlGFEzY3AsplDeuADocJ2tXHsr8kUhonJiYSspND16qXJbXcD582o5yWRsiHQaEW9mZlz9WlA+p7WGxB4LzlV6XeHaEJkSoqSP43JNqG/yuWwiIJHWR7ifhcQB7L0CYtGLbfJpFKHbmRIDiCpokhtLoLI74mNG61w6KUKamwgB7GBXx81Uh+cPvPUCvZhL/NBaf8vyH5TdG0ql+1c1aElj6070aBIzanvr+AnsXH/Gp3FQst5cXhU3JtJjWfkcTNbjA8KE+OudxYNzzx7ZNsMjg/pFgOCZbZGUFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ph2ynH92c5pDNjbrC0NjqxCkjr4ze+BiSlTHbYUGHQM=; b=huv6Bh73JKP0qFIWA6F8cL2yfW2bkrZfx+GZvToEeuxrc0C3Da4bU7cXsB3WejRPyZo4JwCWpl34ZzngafhTbIVvb/lRsDtVW09Hx2IHOZ9QXgaGybdzbUwooA5k2Ldd5ArXDwuRfuMvf7Bndwm0O/JP/bNqsL8DXPwBn7Z6Yte7TGxcGRLvOMAnknohYrXW15KYWCLC9o/tPg3+h4fsxTSQUJOX6iCe9ASJcXIMIX0l3wGpb6tnu64+Vchn0XWfj0sTuYMfYsQblzrHPJtc/7dPnXNv2Y0nJh/fXdhWZXuD2J6rTzh85AvRuPr5YG9cpad3KKd/TLDBSSGhPqwW7w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ph2ynH92c5pDNjbrC0NjqxCkjr4ze+BiSlTHbYUGHQM=; b=oW3xeJSo319zExJMtpgC7NNTjAvx/BWv1c4aoTvZlAztx4hnn1kfmU5NEhX5uG0R7DduTHRecW7NdUPMwVhZF2B2uImNd6yoShBMBJakd1Z4J7uG87ZJJf+YZx0TApYoTNKuDsqe0dfWWhymxd1k57M8VzZ1WB5HxHkNspvwYZUSVq8dNVU+iNBhrEoWxD1VcDiGRISyRYfpbVacz0+OKnQPMmBy1YcCSqtBFhDPiYg5yD2u4RIcNdXtWef+cEJ9g2ekptalonW+dE+APeE5M/Jqy6yhUxHI3SAtK9KBCd1obZD9gpT7LVfmJ4zAsKjxemQVbEvRHLgtrX3cL/eWCw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by VI1PR03MB4397.eurprd03.prod.outlook.com (2603:10a6:803:51::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.17; Mon, 24 Jan 2022 14:48:47 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22%4]) with mapi id 15.20.4909.017; Mon, 24 Jan 2022 14:48:47 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 24 Jan 2022 15:46:12 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [jmRrWGZAIL+XPKN/U3KFWKKo6q7qyiyu] X-ClientProxiedBy: AM5PR0201CA0016.eurprd02.prod.outlook.com (2603:10a6:203:3d::26) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20220124144616.559446-27-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: de352b92-d24c-4533-cc1f-08d9df48a078 X-MS-TrafficTypeDiagnostic: VI1PR03MB4397:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GiSz43dDQCmhJHS2/nBVNCvYkuC4HIherujtr8l58GILWMIyUuGopgDDyrhfejv4hhwQsxtI3TJIkbZ/aKDvuLsfdkNEPGX5DHLzYbGub8ZQ/4GGLZiPCYB7Jkr7lBbkFQCNouC81aWHJNjwh6JKIA4qHiJOIXVctq0FoUzLRFSqzFzOAorJhJS9wptlf+gjLJ/NClwWO9M4KUbu1Mey+gV0NwUSUmsBwywiYP1NBvZhA1pPmnQyp34T4XMBbsg3mmkG5qPmrgV4EjYgUWDzeFT6FPTtcSGmphpArU9E/u5gbfcGDH35q0mIgpZjbZzaT5EZMCczXytbwH94QXd9msOIUFQ5VhO3qPHDufr4JvTdAtB3jMLbNof6ZvoHChweIswyzdolpczJ5nHvKSio1ftQ5nFAW7gwYJ6OnpsFN2Ja65IslhTcKtPwP9uOQSfCEPWgrKg2kkQnM33PPvuDMqvDm2SAFacqu3ghF6vfcHHMwOABpEQjcrcsXC33Y7xW2fk7DlYvl74Neg71JSLzc9FYvJVidK1M3IP/+iSIzoZd+RTVKhzfi2VDc3gUA/LM/0ioBlYpseqLA+gMV0J4rQ== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PrgpC8/blsV3wBHqCsn+NHinhfA6rRQO++0VpzMpxp7xPO/fKgA2QC1bM78L18YsTDjRTlFdn+RIzv+Ho2fCEImnw4qyuKehCq2bEJE9Mjtp9Q8td0VfqoBaPHNmEFcdE3USYBYJ2GzgiiCY4N+9ZVjM7FJuiaGyewUBzN6yUfcbFkgqy2qmlNxJfy5BhcKekEa2MODQq6ouIJmENox/xuZQDZetA2PEP6gqWN8tnsmgLFqSxBrZeWmtUYxTJkTafXXbFm0rxfETzCWwQyYP+a7g4V1H7bbkqYUUxqu8kCf3SXBxLdSg2toW7eF13uHqiM7D+Z3LS5W2/vJ9VJojR8I933yeJo30beizK4uOPQKVqzZp5/nWQVu5WMvKAaUwLkmFQNOAW3opfX6wPjR+U4PFpms/836laObkHSmHednMjlEua8jUDqEn9Zdis6IvKACMCh4dVn7RbJef5p7LyCCilHUpEWGrqQ8Z9kg8GyEridWn57iw0QbtTo+u3aqKK1gsMK0SeG9tX3Q5Gj4irRd0Tw6wDD4PTbkPx6lK4bM+JcBdP6E3JZkThKS5aKXvIiRqiYcy72eUWpNmNFxh0Srw4bkCbHxjRSw5jgrRzuXLzXgkdcg9hb2U8tEpXDafUTLeXaw8YWJ7qGv2NuiWiQmRVhm/OYAIOgRwj0NNGwv8EVEF5SK67yB0lXje8h8P5pOfNKSF073kzwNhbDtLHHpN91XR1BUPhX0ZyUk9CWrKKXjKbVTKL27Jmg3syKzfoR/nDNIFzyR4Dk68vQXwBMJdEvZiPHTHkViRkRzrMGrz3B9OBGe8VWzaQTDugOfBAew6dXogrMt3XdJjVMibrMR5fA9Ooh27r3dRa3YOdghSEMSVyBBl3i/eAPNZ8+0zAGYl0hkmgI6reemk+HzjkCgErxtPb2Esg8A+slRneRlrgL58OrjYtnR4FojI5z5Gt2DbRZmcYNzO/H26p8QlGw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: de352b92-d24c-4533-cc1f-08d9df48a078 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2022 14:48:47.4421 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR03MB4397 Subject: [FFmpeg-devel] [PATCH v2 27/31] 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 Cc: Anton Khirnov Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: +N0nSPoAcrmN From: Anton Khirnov --- libavfilter/qsvvpp.c | 46 ++++++++++++++++++-------------------------- libavfilter/qsvvpp.h | 2 +- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c index d1218355c7..35769dfd60 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); @@ -789,7 +784,7 @@ int ff_qsvvpp_free(QSVVPPContext **vpp) av_freep(&s->surface_ptrs_out); av_freep(&s->ext_buffers); av_freep(&s->frame_infos); - av_fifo_free(s->async_fifo); + av_fifo_freep2(&s->async_fifo); av_freep(vpp); return 0; @@ -799,24 +794,23 @@ 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_read(s->async_fifo, &aframe, 1) >= 0) { + 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 +847,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); diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h index e0f4c8f5bb..4fe07ab1f7 100644 --- a/libavfilter/qsvvpp.h +++ b/libavfilter/qsvvpp.h @@ -73,7 +73,7 @@ typedef struct QSVVPPContext { int async_depth; int eof; /** order with frame_out, sync */ - AVFifoBuffer *async_fifo; + AVFifo *async_fifo; } QSVVPPContext; typedef struct QSVVPPCrop {