From patchwork Fri Apr 19 16:07:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 48171 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c906:b0:1a9:af23:56c1 with SMTP id gx6csp728086pzb; Fri, 19 Apr 2024 09:08:20 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXxvjt7ECKobeYGcSMpD6blpaIqbYWTG73ABTZhLAAW76r1O9r730Sm8b9wQUrhWsWFGVFbhXwYK+PygRoO0K1nm78FUHaDBKQ3LA== X-Google-Smtp-Source: AGHT+IHh/j+BRdC0mK5xC1Cegl0UUMe6kuMz3B23wb4SphA7PvIQYuWB97jlshfXDfIM6QvTujVO X-Received: by 2002:a17:906:1f48:b0:a51:cc51:7931 with SMTP id d8-20020a1709061f4800b00a51cc517931mr1609866ejk.5.1713542899860; Fri, 19 Apr 2024 09:08:19 -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 bm12-20020a170906c04c00b00a521c17dc47si2246637ejb.179.2024.04.19.09.08.04; Fri, 19 Apr 2024 09:08:19 -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="VsSB7/SJ"; 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 5AC4968D3E6; Fri, 19 Apr 2024 19:07:56 +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 CD3FF68D3B4 for ; Fri, 19 Apr 2024 19:07:49 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jjffNKj7HXBOorfjk4cHKy25beKrZNDS8mA9HnlnhYL81DnpkCGt+jRxEJu3rte/sg9xHNAYmHougNem7InDC8mqvbeKLr/DyeD7oCcXZB+3TYqmoshQE/xFXZyAVxOiD/E9eCc3osR+GGZEBsPSDpsLZotoEHs5oNzFol3f4cKYRw7AgAYcDTH+SbLm4k7cEP+s9jPlcZ8u1fIzGU2Zz9PrnUAn7ebF94PdNrKETyPYelTGAsXiXAWaIgHklP1OP9ZVxZv6JxiCPK+DwY9ZlDGQBePTNT6AzzVivf9KDI4adDMm/NVdpmipyrIIkFoZMeSUdzb/bOoFrWLLH6pB+g== 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=q/lqxLOGwPP5H7c/F2A5noxra1PNe485mW7kbjxNZeQ=; b=EsFeufp8+0QZP3POlAeTMMNBfZPTemquWWMDAINqUCwtmD8as5hfo6T54jZ8ncYsAZEWg2P1uDtn3qj41E8r8eNnng8x7lvej8ohVq176oMXPGRENeg3S+nTc1B8pdllj0HiYHtzv9jd+MKirhJ36z5kxyBVu3iPUBTMs7z6hKqFfeYmBqlLWYy6CLqbPkfhAyszZHEj84KgjKucZb1wxBlagrnbDzlojSTbmUxq0ToRBs5CF0XQ48G75yrSYBOtVVXmlFU23AzLf/SffcwnWBADnxHi6dCUK2dHJyWzrTxic/9MRfRriW4QKZKtA85Cav2FhIjEDXnZlJAo43L54g== 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=q/lqxLOGwPP5H7c/F2A5noxra1PNe485mW7kbjxNZeQ=; b=VsSB7/SJZ4X8oV0Ylf73fMbIOc2mlmKiP/qPqCQGTCyPKaM4ScrNWkYneDzKW44/UIr4Qo/T4QFwcpJkY2+2vSuxLi73ZO/WBeAr0pY4K39GPr+gwbRA0TBopkmO5satlrod2aXyHk9n89luvZW5YHMxs2aRu9RWYRaxt4kXxgAtclXcCXTUi85lrzQ3YDA0UI2QJWNWRhZBLMupJ7fFd6RN0Uz+sxB8d3+/1hXRLTDJSd0YHfq/kKIKLnG7299DhrTXSm6q+cINuUa8kSsCXfmCuFfrEJaNpScrWnnPLvlIJDIghJGmxxu0X0UOHHcsq6DIeTIdR2PUf1h8q/nhJQ== 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:48 +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:48 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 19 Apr 2024 18:07:32 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [Ei/z1OrlZde1rR9WrwB+3KnLhfoNFxyqUelu6RngypI=] 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-2-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: f4bed31b-bbcd-43c1-099f-08dc608adb5c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mTbNXnF33qFVI6KWT5Z+8Qo/P0IST3lD8zmR1y4QYLOuUDgnz9rCW65YF8/K8x30G5Rzpc2ZWWKo0QBqJ9qYfou8dP6EzzNGLSHwuMFBfCkL8/IB5wkw2Krt+wduTndDagKeUSk32sFCajt3YLjTDqGv3O9h/dx7sTQnCG2/LIXzXZOzCed68IiTdqHnv0ZW0dNtv1Kn/Qh8wApc6LzoFH2m14lmVdjevItHrFoJQ3sv0MKwnzuetLHaUrslMW9g6XAILuVvlITeyT95wGeQew54Q36501mTdskZeYx/uusEIs3vALzbf+tSqXroHdDz51l+aH+O+PXqP3b1lOvF8h3R22+mNwUBCeRzaMTHfjrqiP53T/16W6o+6lJBmb6k8Z3l9iobI02VqbuK+iXrK/Z6+jW6B4TM0NJqMDZ/lPN7wzLys4bgvPwaYRixL41KJKAkiXmMt5Jsz5+XXncL/gzJyyjOBHtwQimrmUgHSEJQjsQkIvyqnwkLui5WssIAzlRqtnFKXWJS9VTpBB5lRDKRiwF/jCSyCiML3OfQIBvf/Fs/MQ1ouHTaqdXn0shHwJTjRUVGQYw7720mcogxSmOZmFZAUFFt+vdZOziPRqbdXmsS7zt+kyPnBJR0hXwy X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NhyEEsopIKmPfFGCLBgWqK1Mb488PUMndMurZ84TrEquUUgbYMFTb+E0WedLarpc2WLIn2khGUTCZ1Ow2j9yL/v/MWXyz3dbxqckiMj+QX8thKyLbho1nEFYZ92rujGBoPoByFYWaHbIqAK50ZRzOdCwgWVaXgo9FutcsDaTwHEJKrfDWEfyabuef01LHMNz3Fv+azLBqxibHqXr6Yvl4tCnk31F/TU33tZ5hU+Ub77u0Tu/DmY2/FtWW9snXpFeEgOl+PKTfnFykG5hYpd4Qdh7cv6U8RSXI2oPsxliEula1IIxOqZ83Vlg9i9BTPbzIdZE8tXVdilXver3GnT7qXK7vxOTcq5yR0U2L2SJU7ANX31Q7DSwknnmvR1Zq7vtY/1VFkiFkkg1M/Odz1QHtvLiIvSa31GQAap2sTKRhgal1Dpx+a7NjkK0iakZGwEWTOMGIreTB0Lkong3QtNGFiQpL2OGzAWucXoJh8T1YUnQpn6I4MPtja6kqiAswM5bwOnh0I/HMa46y7hzMfGH1y7sFyYEOh5A4Ryc03UZ13XAgyMljOUvlKnE1uP9xuO65GpisGFcvTZkfcx0bCSN3JnQMuRJ0AK96gn2erN/HshPzbeKadWJesMpn3eXjAF3XT7HHftmLQ2+NTtLERE8DYvuDOV+Ykps6iuHFHn9P9K2Es9Qz1mFXqBPUkjTlJtgwDax0QBWpWGB9FSP5t6jDmW8Usfir0Mmx3bcrgc3kVESkDeEIUjxBCq0HE4/fSBYk2XpUnUDPc6C8jmw6Tz1wDM3wzbM05RcXea35baYI0uG1aKjWXJIMpkwkPiZRFthaiLuSXM9Rye7YtqaIGp4lcZQE8/LQMllpQ/Cp869abb4ywk4hp41ByS4gdH2nnSYKS+FuyKMI2P/KkSZv6IhEQiT7TePOFvPBmrjWFIS7/nsSsMFKf1wijmd8EXGf2N7RzjGTOqrDAHlAlVhMkEa5XBmM/uzcnMLE+3XX+X/LszSCc2jKKOfCBw+qxLI6OZ1Wp7ZGKPr+1xmfVPobkyBCEsiX1/46sxgVBvEYb+Hhhh6xzWfHokPNK9DX71l2U/RlSvxeO+HysHyfThxoQgvpi/hnFxni00gBOpTrjEE2+Ux2Rbsan2g79KdIAsnKBOHCFzCUQ7U98ltZ375g66nMMKUPLRHjNycqNw4ILbJY0uek7JOx/VlLVFHwgcJ3jN5/s73UnvrgviJr+Y9oSi2PQWrn07rW+wlVmrUobFY1b6hsTzXF9+qzI6+337T5eNtK8FK/a2YPXIQPBKpES7L6w== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f4bed31b-bbcd-43c1-099f-08dc608adb5c 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:48.3795 (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 3/5] avcodec/av1dec: 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: zBp2DfpaQ+Pe AV1 can put a frame into multiple reference slots; up until now, this involved creating a new reference to the underlying AVFrame; therefore av1_frame_ref() could fail. This commit changes this by using the ProgressFrame API to share the underlying AVFrames. (Hint: vaapi_av1_surface_id() checked whether the AV1Frames contained in the AV1DecContext were NULL or not (of course they were not); this has been changed to actually check for whether said AV1Frame is blank or not.) Signed-off-by: Andreas Rheinhardt --- 1. The AV1 patches are basically untested (apart from FATE and compilation). Could someone please test them? 2. An alternative is to use an array of AV1Frames and an array of pointers to AV1Frames. The former have refcounts where each pointer to an AV1Frame is considered to own a reference. av1_frame_ref() would boil down to incrementing a refcount and setting a pointer. 3. Is there a specific reason that vulkan checked pict_type instead of setting whether e.g. buf[0] or data[0] was set (as is customarily done)? libavcodec/av1dec.c | 92 +++++++++++------------------------------ libavcodec/av1dec.h | 8 +++- libavcodec/dxva2_av1.c | 8 ++-- libavcodec/nvdec_av1.c | 4 +- libavcodec/vaapi_av1.c | 6 +-- libavcodec/vdpau_av1.c | 7 ++-- libavcodec/vulkan_av1.c | 4 +- 7 files changed, 47 insertions(+), 82 deletions(-) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index b4b741054a..2a1a249bc4 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -38,8 +38,8 @@ #include "itut35.h" #include "hwconfig.h" #include "profiles.h" +#include "progressframe.h" #include "refstruct.h" -#include "thread.h" /**< same with Div_Lut defined in spec 7.11.3.7 */ static const uint16_t div_lut[AV1_DIV_LUT_NUM] = { @@ -672,7 +672,7 @@ static int get_pixel_format(AVCodecContext *avctx) static void av1_frame_unref(AV1Frame *f) { - av_frame_unref(f->f); + ff_progress_frame_unref(&f->pf); ff_refstruct_unref(&f->hwaccel_picture_private); ff_refstruct_unref(&f->header_ref); f->raw_frame_header = NULL; @@ -683,20 +683,16 @@ static void av1_frame_unref(AV1Frame *f) f->coded_lossless = 0; } -static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src) +static void av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src) { - int ret; - ff_refstruct_replace(&dst->header_ref, src->header_ref); dst->raw_frame_header = src->raw_frame_header; - if (!src->f->buf[0]) - return 0; + if (!src->f) + return; - ret = av_frame_ref(dst->f, src->f); - if (ret < 0) - goto fail; + ff_progress_frame_ref(&dst->pf, &src->pf); ff_refstruct_replace(&dst->hwaccel_picture_private, src->hwaccel_picture_private); @@ -725,12 +721,6 @@ static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *s sizeof(dst->ref_frame_sign_bias)); memcpy(dst->order_hints, src->order_hints, sizeof(dst->order_hints)); - - return 0; - -fail: - av1_frame_unref(dst); - return AVERROR(ENOMEM); } static av_cold int av1_decode_free(AVCodecContext *avctx) @@ -738,16 +728,9 @@ static av_cold int av1_decode_free(AVCodecContext *avctx) AV1DecContext *s = avctx->priv_data; AV1RawMetadataITUTT35 itut_t35; - for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++) { - if (s->ref[i].f) { - av1_frame_unref(&s->ref[i]); - av_frame_free(&s->ref[i].f); - } - } - if (s->cur_frame.f) { - av1_frame_unref(&s->cur_frame); - av_frame_free(&s->cur_frame.f); - } + for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++) + av1_frame_unref(&s->ref[i]); + av1_frame_unref(&s->cur_frame); av_buffer_unref(&s->seq_data_ref); ff_refstruct_unref(&s->seq_ref); ff_refstruct_unref(&s->header_ref); @@ -863,16 +846,6 @@ static av_cold int av1_decode_init(AVCodecContext *avctx) s->pkt = avctx->internal->in_pkt; s->pix_fmt = AV_PIX_FMT_NONE; - for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++) { - s->ref[i].f = av_frame_alloc(); - if (!s->ref[i].f) - return AVERROR(ENOMEM); - } - - s->cur_frame.f = av_frame_alloc(); - if (!s->cur_frame.f) - return AVERROR(ENOMEM); - ret = ff_cbs_init(&s->cbc, AV_CODEC_ID_AV1, avctx); if (ret < 0) return ret; @@ -934,7 +907,8 @@ static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f) return ret; } - if ((ret = ff_thread_get_buffer(avctx, f->f, AV_GET_BUFFER_FLAG_REF)) < 0) + ret = ff_progress_frame_get_buffer(avctx, &f->pf, AV_GET_BUFFER_FLAG_REF); + if (ret < 0) goto fail; frame = f->f; @@ -1211,23 +1185,17 @@ FF_ENABLE_DEPRECATION_WARNINGS return 0; } -static int update_reference_list(AVCodecContext *avctx) +static void update_reference_list(AVCodecContext *avctx) { AV1DecContext *s = avctx->priv_data; const AV1RawFrameHeader *header = s->raw_frame_header; - int ret; for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) { if (header->refresh_frame_flags & (1 << i)) { av1_frame_unref(&s->ref[i]); - if ((ret = av1_frame_ref(avctx, &s->ref[i], &s->cur_frame)) < 0) { - av_log(avctx, AV_LOG_ERROR, - "Failed to update frame %d in reference list\n", i); - return ret; - } + av1_frame_ref(avctx, &s->ref[i], &s->cur_frame); } } - return 0; } static int get_current_frame(AVCodecContext *avctx) @@ -1358,20 +1326,12 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) if (s->raw_frame_header->show_existing_frame) { av1_frame_unref(&s->cur_frame); - ret = av1_frame_ref(avctx, &s->cur_frame, - &s->ref[s->raw_frame_header->frame_to_show_map_idx]); - if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, "Failed to get reference frame.\n"); - goto end; - } + av1_frame_ref(avctx, &s->cur_frame, + &s->ref[s->raw_frame_header->frame_to_show_map_idx]); - ret = update_reference_list(avctx); - if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, "Failed to update reference list.\n"); - goto end; - } + update_reference_list(avctx); - if (s->cur_frame.f->buf[0]) { + if (s->cur_frame.f) { ret = set_output_frame(avctx, frame); if (ret < 0) av_log(avctx, AV_LOG_ERROR, "Set output frame error.\n"); @@ -1392,7 +1352,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) s->cur_frame.spatial_id = header->spatial_id; s->cur_frame.temporal_id = header->temporal_id; - if (avctx->hwaccel && s->cur_frame.f->buf[0]) { + if (avctx->hwaccel && s->cur_frame.f) { ret = FF_HW_CALL(avctx, start_frame, unit->data, unit->data_size); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "HW accel start frame fail.\n"); @@ -1418,7 +1378,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) if (ret < 0) goto end; - if (avctx->hwaccel && s->cur_frame.f->buf[0]) { + if (avctx->hwaccel && s->cur_frame.f) { ret = FF_HW_CALL(avctx, decode_slice, raw_tile_group->tile_data.data, raw_tile_group->tile_data.data_size); if (ret < 0) { @@ -1469,7 +1429,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) if (raw_tile_group && (s->tile_num == raw_tile_group->tg_end + 1)) { int show_frame = s->raw_frame_header->show_frame; - if (avctx->hwaccel && s->cur_frame.f->buf[0]) { + if (avctx->hwaccel && s->cur_frame.f) { ret = FF_HW_SIMPLE_CALL(avctx, end_frame); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "HW accel end frame fail.\n"); @@ -1477,13 +1437,9 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) } } - ret = update_reference_list(avctx); - if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, "Failed to update reference list.\n"); - goto end; - } + update_reference_list(avctx); - if (s->raw_frame_header->show_frame && s->cur_frame.f->buf[0]) { + if (s->raw_frame_header->show_frame && s->cur_frame.f) { ret = set_output_frame(avctx, frame); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Set output frame error\n"); @@ -1597,7 +1553,9 @@ const FFCodec ff_av1_decoder = { .close = av1_decode_free, FF_CODEC_RECEIVE_FRAME_CB(av1_receive_frame), .p.capabilities = AV_CODEC_CAP_DR1, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | + FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | + FF_CODEC_CAP_USES_PROGRESSFRAMES, .flush = av1_decode_flush, .p.profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles), .p.priv_class = &av1_class, diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h index 79a0be510b..66a732d781 100644 --- a/libavcodec/av1dec.h +++ b/libavcodec/av1dec.h @@ -32,9 +32,15 @@ #include "cbs.h" #include "cbs_av1.h" #include "dovi_rpu.h" +#include "progressframe.h" typedef struct AV1Frame { - AVFrame *f; + union { + struct { + struct AVFrame *f; + }; + ProgressFrame pf; + }; void *hwaccel_picture_private; ///< RefStruct reference diff --git a/libavcodec/dxva2_av1.c b/libavcodec/dxva2_av1.c index 184a922fd8..5b95f99c9b 100644 --- a/libavcodec/dxva2_av1.c +++ b/libavcodec/dxva2_av1.c @@ -138,9 +138,9 @@ int ff_dxva2_av1_fill_picture_parameters(const AVCodecContext *avctx, AVDXVACont int8_t ref_idx = frame_header->ref_frame_idx[i]; AVFrame *ref_frame = h->ref[ref_idx].f; - pp->frame_refs[i].width = ref_frame->width; - pp->frame_refs[i].height = ref_frame->height; - pp->frame_refs[i].Index = ref_frame->buf[0] ? ref_idx : 0xFF; + pp->frame_refs[i].width = ref_frame ? ref_frame->width : 0; + pp->frame_refs[i].height = ref_frame ? ref_frame->height : 0; + pp->frame_refs[i].Index = ref_frame ? ref_idx : 0xFF; /* Global Motion */ pp->frame_refs[i].wminvalid = h->cur_frame.gm_invalid[AV1_REF_FRAME_LAST + i]; @@ -151,7 +151,7 @@ int ff_dxva2_av1_fill_picture_parameters(const AVCodecContext *avctx, AVDXVACont } for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { AVFrame *ref_frame = h->ref[i].f; - if (ref_frame->buf[0]) + if (ref_frame) pp->RefFrameMapTextureIndex[i] = ff_dxva2_get_surface_index(avctx, ctx, ref_frame, 0); } diff --git a/libavcodec/nvdec_av1.c b/libavcodec/nvdec_av1.c index b0b013846e..4efa420e66 100644 --- a/libavcodec/nvdec_av1.c +++ b/libavcodec/nvdec_av1.c @@ -251,8 +251,8 @@ static int nvdec_av1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, u AVFrame *ref_frame = s->ref[ref_idx].f; ppc->ref_frame[i].index = ppc->ref_frame_map[ref_idx]; - ppc->ref_frame[i].width = ref_frame->width; - ppc->ref_frame[i].height = ref_frame->height; + ppc->ref_frame[i].width = ref_frame ? ref_frame->width : 0; + ppc->ref_frame[i].height = ref_frame ? ref_frame->height : 0; /* Global Motion */ ppc->global_motion[i].invalid = !frame_header->is_global[AV1_REF_FRAME_LAST + i]; diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c index 1f9a6071ba..1f563483b9 100644 --- a/libavcodec/vaapi_av1.c +++ b/libavcodec/vaapi_av1.c @@ -46,7 +46,7 @@ typedef struct VAAPIAV1DecContext { static VASurfaceID vaapi_av1_surface_id(AV1Frame *vf) { - if (vf) + if (vf->f) return ff_vaapi_get_surface_id(vf->f); else return VA_INVALID_SURFACE; @@ -132,7 +132,7 @@ static int vaapi_av1_start_frame(AVCodecContext *avctx, goto fail; pic->output_surface = ff_vaapi_get_surface_id(ctx->tmp_frame); } else { - pic->output_surface = vaapi_av1_surface_id(&s->cur_frame); + pic->output_surface = ff_vaapi_get_surface_id(s->cur_frame.f); } memset(&pic_param, 0, sizeof(VADecPictureParameterBufferAV1)); @@ -142,7 +142,7 @@ static int vaapi_av1_start_frame(AVCodecContext *avctx, .bit_depth_idx = bit_depth_idx, .matrix_coefficients = seq->color_config.matrix_coefficients, .current_frame = pic->output_surface, - .current_display_picture = vaapi_av1_surface_id(&s->cur_frame), + .current_display_picture = ff_vaapi_get_surface_id(s->cur_frame.f), .frame_width_minus1 = frame_header->frame_width_minus_1, .frame_height_minus1 = frame_header->frame_height_minus_1, .primary_ref_frame = frame_header->primary_ref_frame, diff --git a/libavcodec/vdpau_av1.c b/libavcodec/vdpau_av1.c index 80923092b9..b74ea6aa0c 100644 --- a/libavcodec/vdpau_av1.c +++ b/libavcodec/vdpau_av1.c @@ -219,7 +219,8 @@ static int vdpau_av1_start_frame(AVCodecContext *avctx, info->loop_filter_ref_deltas[i] = frame_header->loop_filter_ref_deltas[i]; /* Reference Frames */ - info->ref_frame_map[i] = ff_vdpau_get_surface_id(s->ref[i].f) ? ff_vdpau_get_surface_id(s->ref[i].f) : VDP_INVALID_HANDLE; + info->ref_frame_map[i] = s->ref[i].f && ff_vdpau_get_surface_id(s->ref[i].f) ? + ff_vdpau_get_surface_id(s->ref[i].f) : VDP_INVALID_HANDLE; } if (frame_header->primary_ref_frame == AV1_PRIMARY_REF_NONE) { @@ -235,8 +236,8 @@ static int vdpau_av1_start_frame(AVCodecContext *avctx, AVFrame *ref_frame = s->ref[ref_idx].f; info->ref_frame[i].index = info->ref_frame_map[ref_idx]; - info->ref_frame[i].width = ref_frame->width; - info->ref_frame[i].height = ref_frame->height; + info->ref_frame[i].width = ref_frame ? ref_frame->width : 0; + info->ref_frame[i].height = ref_frame ? ref_frame->height : 0; /* Global Motion */ info->global_motion[i].invalid = !frame_header->is_global[AV1_REF_FRAME_LAST + i]; diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c index 49cd69d051..25ab4ecc70 100644 --- a/libavcodec/vulkan_av1.c +++ b/libavcodec/vulkan_av1.c @@ -284,7 +284,7 @@ static int vk_av1_start_frame(AVCodecContext *avctx, AV1VulkanDecodePicture *hp = ref_frame->hwaccel_picture_private; int found = 0; - if (ref_frame->f->pict_type == AV_PICTURE_TYPE_NONE) + if (!ref_frame->f) continue; for (int j = 0; j < ref_count; j++) { @@ -326,7 +326,7 @@ static int vk_av1_start_frame(AVCodecContext *avctx, const AV1Frame *ref_frame = &s->ref[idx]; AV1VulkanDecodePicture *hp = ref_frame->hwaccel_picture_private; - if (ref_frame->f->pict_type == AV_PICTURE_TYPE_NONE) + if (!ref_frame->f) ap->av1_pic_info.referenceNameSlotIndices[i] = AV1_REF_FRAME_NONE; else ap->av1_pic_info.referenceNameSlotIndices[i] = hp->frame_id;