From patchwork Fri Apr 19 16:07:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 48173 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c906:b0:1a9:af23:56c1 with SMTP id gx6csp728312pzb; Fri, 19 Apr 2024 09:08:34 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVgRtL7929v/+iBTZx8FheAT0xhYT0CbeVHjALDgTNzU/lPC48jUeUbF4gmy986ap5rsQudIrwwADn5xtyYhxTggpr5meo3DHa8Sg== X-Google-Smtp-Source: AGHT+IHJ7pNjlapR/FkodaZbSnYPc1q/Wy2KqqZgoLhJw/ftjAHSLmNYj1DILdQJFSllwl/Q7ycS X-Received: by 2002:ac2:5f81:0:b0:518:956d:82cf with SMTP id r1-20020ac25f81000000b00518956d82cfmr1661642lfe.4.1713542914543; Fri, 19 Apr 2024 09:08:34 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id bl20-20020a056402211400b00571d7acd844si613293edb.609.2024.04.19.09.08.23; Fri, 19 Apr 2024 09:08:34 -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=@outlook.com header.s=selector1 header.b=eD4d0DVu; 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 9F14768D40A; Fri, 19 Apr 2024 19:08:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02olkn2075.outbound.protection.outlook.com [40.92.48.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 094C468D3AE for ; Fri, 19 Apr 2024 19:08:00 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iYkvWMnUknhSUA6jn/7vFDn+IoVwOzqK0WUsDTgMYQnbExDA8yytA+jkuS6a28ldI/jXUeQdJjP8lj+PYFRqtkGc5Yr9eajqoXS57istulWAFVl5TIXz9rmt9FbxRRomp+d4nkgQeDrA5Xwj896RWLnhcgXArdhyQvmTtwUzEG9GN3yKtwd8X45fJwg1OLx/a51fGrqfty6+bAUMihrwxjhawKb0+/ZhTIVDMltiltYsoxeEggSNkeRXCjnivxku62J9jo4hsR2dokDV3Tjul4zusvgNSItatoD1oIXMlFxPhYCL2A4yj46QFU1pSrZo2e/valWAY1TwRb2MkZCnMA== 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=pHHUtAiCa5JOiGV7EXV23/h27n0Pk62g2dj60faThDw=; b=QPAEkCrP2eItsDoWYJmVpYxFKY0BmX3Ktgd1TAsN/qAZgR7oX/JylW1ONQ/pz3jJ2YSXtyfzXx+sRgs5vXg5zAkSBxfpbkod/zWNN3mg955YugDKKpyQ27bKFYdGKM0/BHW/33jdFIYoCy0pwcxkJOd1UaqUs8HUhxlBfqZvjpqAHsYrx+7MUpmzxEXKURQmKqcmicWAHNUbiBKq6dsyD0M0y651vtokk1/7c0PJf0NZPtTw+7ikHA1lfHYXQe/0GlLmuhlcAIOGTzqBRvBg+1WKJkTPRAJAav6pKzHVrLcx1v6X4NvsiHyVwNObzm/+wlCL7fTWS1yWgJvUZqirkw== 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=pHHUtAiCa5JOiGV7EXV23/h27n0Pk62g2dj60faThDw=; b=eD4d0DVuNuTbPNGNasLXvVfQ3JQoRN18QRzNeLN8QJHMfnyqntMXpzcLDK5TGvIiv/JDyZ2uNGU8a//jVEByeYrlEJYFfOF36RUdaBi7x+GDTSl2YtQ9OTKy19XaLe64CRFAVANFXVfvg1xX77Pkxbqg9FV/7WUP0JXXaV41jyCsdWwY7XiDtv8Q1lvYlHUBYOOWynKSkGwNAEJQFpI3jZ1wWcEnjdMGMA/HylTi8SsyMwFVhZ5wNowHWLSHN1+bBktwvVS+wBjHp0JfdS9dX9/08i6FtQpNDqbLaXZ9PIlZ4aO8jpI1D7YrbMmfaxqGGofxh4MGGICKndeHYYxZPw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AM8P250MB0138.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:321::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.41; Fri, 19 Apr 2024 16:07:50 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::1f29:8206:b8c3:45bb]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::1f29:8206:b8c3:45bb%3]) with mapi id 15.20.7409.042; Fri, 19 Apr 2024 16:07:50 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 19 Apr 2024 18:07:34 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [MGip+pNaOtuo931ERWRJ1jJvcoi52YW2kbTZUuiL5Bo=] X-ClientProxiedBy: ZR2P278CA0006.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:50::12) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20240419160734.1104837-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AM8P250MB0138:EE_ X-MS-Office365-Filtering-Correlation-Id: 9bbc0556-bd5f-4afb-edf0-08dc608adc9c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dFY3K6ZDWcpfO78zZECiy+R/pDDuqLj21jwCEiMiL8dq7eM2KHPonS6RoS7iLIqO9YurFYf/qQpUFq4JfthcdNYe6v9DNeolkVTiXJkQQdU7fgiGcusjl8lh3+xOuaSI9JSZB1ruUlA0FHLgbOVGXChnb6ALuj69a2yKiVDsDvHIqVvGMQ9rgzyG1UeY0bseyOyJbC+Qteqb6ZCK1TJq3GK8pdQonQ25nfZOABTwAF7MzYBkYQiA3MZsUu6v9la1yP7Ou8V7OlT4NmA3CD1nGq/Sj/sP4JtkfvD75DJtm3+72ERDW28UMVUVWejphtbYA+SXq2YWq4vOiuy8phyNTdY6hDSiw772V5E+8MwpdRU4ayhI3mqRZPheJMuzN03/8b2JtRXDbPtk5oFVEAIwCkXLrWxt9H1cB0a6v2mLa0qPCE1AZGX8q0Md2WZ7oiE6W+idmk8ILKCr1VUrWmA2wd1GRCpzmSVxWBSCz1b+26xL4TF8jcxaGR1v+Tz/xnNdSZZNABROIVEnYJd2IeDB53V7pt8ApkwMSiq9Q/QN2BOeCDFff7LUzAIjaDbi3QNmXjy0emp30+BUTQF/EPbDHWEpchBf7CSY2x6Oa35J6VyV9QlGMn6Aze5P4w7igoJE X-MS-Exchange-AntiSpam-MessageData-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qqKLKUNhtiA5scr600K9TIYHYcuCmHWEPW4VnOkwqeNmEbVRIHLZvntyzTFZhUp4E/uFh9vzjPrrxQrFeGC3g5rLtojycrLpxgeox6ygw7F4ii19/6BfNKFPpTwxZ5fKfyOZ/TDfJM8hZAhTqCWZoWmE9k1ay2wYw5G0w4vzjB2LSS0LnqzPc/7MIskADLwHWPV5nWmyWwwo6PwIHQk80UVuM5CXodnv1G/SJPRP/8qc6MZ04rWUMZPw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9bbc0556-bd5f-4afb-edf0-08dc608adc9c X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2024 16:07:50.4528 (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: AM8P250MB0138 Subject: [FFmpeg-devel] [PATCH 5/5] avcodec/vaapi_av1: Use ProgressFrames 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: aFMQ/v1xkoQf The rationale here is exactly the same as for using them for AV1: It avoids av_frame_ref() when putting the same frame into multiple reference slots. (In case av_frame_ref() failed, the context would be left in an inconsistent state that claimed that an AVFrame was valid (i.e. not blank), when in fact it was not valid.) Signed-off-by: Andreas Rheinhardt --- libavcodec/vaapi_av1.c | 61 +++++++++++------------------------------- 1 file changed, 15 insertions(+), 46 deletions(-) diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c index 1f563483b9..20651a0ac2 100644 --- a/libavcodec/vaapi_av1.c +++ b/libavcodec/vaapi_av1.c @@ -18,17 +18,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/frame.h" #include "hwaccel_internal.h" #include "vaapi_decode.h" #include "internal.h" #include "av1dec.h" -#include "thread.h" - -typedef struct VAAPIAV1FrameRef { - AVFrame *frame; - int valid; -} VAAPIAV1FrameRef; +#include "progressframe.h" typedef struct VAAPIAV1DecContext { VAAPIDecodeContext base; @@ -40,8 +34,8 @@ typedef struct VAAPIAV1DecContext { * applying film grain here. And current_display_picture will be * used to apply film grain and push to downstream. */ - VAAPIAV1FrameRef ref_tab[AV1_NUM_REF_FRAMES]; - AVFrame *tmp_frame; + ProgressFrame ref_tab[AV1_NUM_REF_FRAMES]; + ProgressFrame tmp_frame; } VAAPIAV1DecContext; static VASurfaceID vaapi_av1_surface_id(AV1Frame *vf) @@ -70,32 +64,14 @@ static int8_t vaapi_av1_get_bit_depth_idx(AVCodecContext *avctx) return bit_depth == 8 ? 0 : bit_depth == 10 ? 1 : 2; } -static int vaapi_av1_decode_init(AVCodecContext *avctx) -{ - VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data; - - ctx->tmp_frame = av_frame_alloc(); - if (!ctx->tmp_frame) - return AVERROR(ENOMEM); - - for (int i = 0; i < FF_ARRAY_ELEMS(ctx->ref_tab); i++) { - ctx->ref_tab[i].frame = av_frame_alloc(); - if (!ctx->ref_tab[i].frame) - return AVERROR(ENOMEM); - ctx->ref_tab[i].valid = 0; - } - - return ff_vaapi_decode_init(avctx); -} - static int vaapi_av1_decode_uninit(AVCodecContext *avctx) { VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data; - av_frame_free(&ctx->tmp_frame); + ff_progress_frame_unref(&ctx->tmp_frame); for (int i = 0; i < FF_ARRAY_ELEMS(ctx->ref_tab); i++) - av_frame_free(&ctx->ref_tab[i].frame); + ff_progress_frame_unref(&ctx->ref_tab[i]); return ff_vaapi_decode_uninit(avctx); } @@ -125,12 +101,12 @@ static int vaapi_av1_start_frame(AVCodecContext *avctx, goto fail; if (apply_grain) { - if (ctx->tmp_frame->buf[0]) - av_frame_unref(ctx->tmp_frame); - err = ff_thread_get_buffer(avctx, ctx->tmp_frame, AV_GET_BUFFER_FLAG_REF); + ff_progress_frame_unref(&ctx->tmp_frame); + err = ff_progress_frame_get_buffer(avctx, &ctx->tmp_frame, + AV_GET_BUFFER_FLAG_REF); if (err < 0) goto fail; - pic->output_surface = ff_vaapi_get_surface_id(ctx->tmp_frame); + pic->output_surface = ff_vaapi_get_surface_id(ctx->tmp_frame.f); } else { pic->output_surface = ff_vaapi_get_surface_id(s->cur_frame.f); } @@ -265,8 +241,8 @@ static int vaapi_av1_start_frame(AVCodecContext *avctx, if (pic_param.pic_info_fields.bits.frame_type == AV1_FRAME_KEY && frame_header->show_frame) pic_param.ref_frame_map[i] = VA_INVALID_ID; else - pic_param.ref_frame_map[i] = ctx->ref_tab[i].valid ? - ff_vaapi_get_surface_id(ctx->ref_tab[i].frame) : + pic_param.ref_frame_map[i] = ctx->ref_tab[i].f ? + ff_vaapi_get_surface_id(ctx->ref_tab[i].f) : vaapi_av1_surface_id(&s->ref[i]); } for (int i = 0; i < AV1_REFS_PER_FRAME; i++) { @@ -370,17 +346,10 @@ static int vaapi_av1_end_frame(AVCodecContext *avctx) for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) { if (header->refresh_frame_flags & (1 << i)) { - if (ctx->ref_tab[i].frame->buf[0]) - av_frame_unref(ctx->ref_tab[i].frame); + ff_progress_frame_unref(&ctx->ref_tab[i]); - if (apply_grain) { - ret = av_frame_ref(ctx->ref_tab[i].frame, ctx->tmp_frame); - if (ret < 0) - return ret; - ctx->ref_tab[i].valid = 1; - } else { - ctx->ref_tab[i].valid = 0; - } + if (apply_grain) + ff_progress_frame_ref(&ctx->ref_tab[i], &ctx->tmp_frame); } } @@ -431,7 +400,7 @@ const FFHWAccel ff_av1_vaapi_hwaccel = { .end_frame = vaapi_av1_end_frame, .decode_slice = vaapi_av1_decode_slice, .frame_priv_data_size = sizeof(VAAPIDecodePicture), - .init = vaapi_av1_decode_init, + .init = ff_vaapi_decode_init, .uninit = vaapi_av1_decode_uninit, .frame_params = ff_vaapi_common_frame_params, .priv_data_size = sizeof(VAAPIAV1DecContext),