From patchwork Sat Apr 6 13:46:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Plowman X-Patchwork-Id: 47881 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:24a8:b0:1a3:b6bb:3029 with SMTP id m40csp1535111pzd; Sat, 6 Apr 2024 06:46:22 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV4SQNWoUNN5zXj77pMfJSofmQb8K4rwsEEFdO1tTNOvdXN5NFkJ/lSmXKxS4S35GKyhBjg3jCSDMJAY5ZaazStacTT4PYQmoonSA== X-Google-Smtp-Source: AGHT+IFC3W+Kgyhx9cZ7uH9lUkPjKmts8g89PtlNfvtd4QzTqOztAiVqoU6Y4pLXbzK/BlqrUYDf X-Received: by 2002:a17:907:c28a:b0:a51:b666:b372 with SMTP id tk10-20020a170907c28a00b00a51b666b372mr1937062ejc.27.1712411182709; Sat, 06 Apr 2024 06:46:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712411182; cv=none; d=google.com; s=arc-20160816; b=sXhPmvUMTF1HoOvuryczTfOQh6rYf7wE0LQ9tPTKAMoUr5fBHMELmbhXuxJHVlXcu6 gHbS6xa+1u3JuCbxTCymyq/jnENqPD7paKNY9xGG2muxSusXBX5CJ8II6aOhaUSc//h5 0tP2XUmn4DrQ5lB4BlCHqltNLPZHJ5NI7CWoX8IjKVKXhAkoPVtC/qXBvb7Uje0CclNJ SJJLfNdUrB+IHJK6R5BbNLpaaSDrqazogXJa/ik+XN4z59qG5jgqmPmAdeACrSa3tsrP RAcBHqxhjfFvXNSV6Lva42h11xEWHDwaIjs1yzD8vjbPpsI6ODmqU+m1jN9fC5bZCoKh u18g== 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:to:mime-version:message-id:date:from :dkim-signature:delivered-to; bh=YkmHBy96vyiaHX5ZolxkQ9JAQd4K4hhpgd9BusSL+8A=; fh=GABYHefZpsCOOVRn8a1IgmYuOvaCu1oFlwEOjvaxWTE=; b=G0ToRu3HuCMkEUb3xpR/HttzNyRrQS4Bi863wb+pQsGGpsH87MQchazCBBmOppQB3K bDEGcXUNfH33Cf6GC3rILQRzqEdH2LWaP6oR/4H0xGUy4K/iCraonUV3dHH5bh61lda3 p4cJsUarJf63n6sdUlr4WCdjzJnD4OU+2+pIr2crdsKHfCJcr2/kbLolyhIqOp+JRPDZ DT275z2b1vtnQ0QCAckdYpcvc9VrT4MuKswwgIiluKnYCjndDkMa9IU9g1+GWq0R3YPZ uA1cOFaDQzsgufusXZjFuOVr2G+q/4Hr2b/tDVaq8wQRAoj1IMrKXKRgNjqt498pAdVm 9U8g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@frankplowman.com header.s=s1 header.b=sMJgSRy9; 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 j5-20020a170906830500b00a462a5a4948si1714117ejx.276.2024.04.06.06.46.22; Sat, 06 Apr 2024 06:46:22 -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=@frankplowman.com header.s=s1 header.b=sMJgSRy9; 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 B457668CFF4; Sat, 6 Apr 2024 16:46:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from wrqvffvh.outbound-mail.sendgrid.net (wrqvffvh.outbound-mail.sendgrid.net [149.72.255.128]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E501F68CCF9 for ; Sat, 6 Apr 2024 16:46:11 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=frankplowman.com; h=from:subject:mime-version:to:cc:content-transfer-encoding: content-type:cc:content-type:from:subject:to; s=s1; bh=0pfxyPOPXl8piWFi+xau34GpKs6y7PgCiTkyc1Raqic=; b=sMJgSRy9F1SkQjcSVLBE2AryU4FHqEf6YgwGmQbx93ILLbIHP7ERrKnPbZABC1aMRc88 mS7+DqXF4xaa0/QV3BAt4cKnQQ5KnpjvK1uuYA07U5aObn3Qm3e9DT85QngRe0aWdJ5+ce 9luOcvsP0yenZUKG6USeRXbyixoSLtAUO3L3NSThPL+igB5pWJNNAhJqORnSgsFe9V0tdf v7w0nezAOVGbcWI+3scfcOR0TLtpXeczKEW6JtpSPji/kAnesx7tBnOb9iqZoWA/AfIkRN DVnX0NjXgyHDvla9FWs1McIlN5dEA/RDGzPPpLeVRLHnCExPHj80b710XHLc8dfA== Received: by recvd-75c664ffc8-k46bh with SMTP id recvd-75c664ffc8-k46bh-1-66115221-2F 2024-04-06 13:46:09.598487978 +0000 UTC m=+1615575.466159222 Received: from localhost.localdomain (unknown) by geopod-ismtpd-0 (SG) with ESMTP id GApYjDT9S26az5Bqy1w6jA Sat, 06 Apr 2024 13:46:09.389 +0000 (UTC) From: Frank Plowman Date: Sat, 06 Apr 2024 13:46:09 +0000 (UTC) Message-ID: <20240406134546.61454-1-post@frankplowman.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-SG-EID: u001.Z0KJCHpts8tvDq7PHgz5cpqJ+vJcSmdTtST/g91WT3qAbNxUpEMGIDQq91mXy3Yjvepp8fYsFUJzGsyhT1EwBWtef39WL2jwGq8VGHQZqsRmlk2cJQ74YxexX/b1qbJc3korK/bN//xk/oVx508nfKdK77n3Q0rzguwCUce8JYBLOIpwdqCEvcKb/U4sQdXMfnZLi6c+FzeZzE2AQu18tfUglgwRy0yyE4vfjQ+LQijHH1OoDMsxtmjJAz/nGDs2 To: ffmpeg-devel@ffmpeg.org X-Entity-ID: u001.qzljkbu34TNIX4NwfTiKWA== Subject: [FFmpeg-devel] [PATCH v2] lavc/vvc: Error if SPS ID is duplicated within CVS 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: Frank Plowman Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ljyTj+AQHsVj Key line from the spec is: "All SPS NAL units with a particular value of sps_seq_parameter_set_id in a CVS shall have the same content." Prior to this patch, the VVC decoder's behaviour on encountering a duplicated SPS ID (within the entire bitstream, not restricted to a CVS) was simply to replace the entry in the SPS lookup table with the new data. Illegal bitstreams with multiple SPSs in the same CVS sharing an ID but differing elsewhere could cause all manner of issues. The patch tracks which SPS IDs have been used in the given CVS using the new sps_id_used field of VVCParamSets. If it encounters an SPS with an ID already in use and whose content differs from the previous SPS, it throws an AVERROR_INVALIDDATA. Signed-off-by: Frank Plowman --- Changes since v1: * Track which SPS IDs are in use using a bit field rather than a bool array. * Move sps_id_used to the end of VVCParamSets. * Style: remove blank line & add braces for clarity. libavcodec/vvc/vvc_ps.c | 28 ++++++++++++++++++++-------- libavcodec/vvc/vvc_ps.h | 2 ++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/libavcodec/vvc/vvc_ps.c b/libavcodec/vvc/vvc_ps.c index 301fa16400..7e967180d2 100644 --- a/libavcodec/vvc/vvc_ps.c +++ b/libavcodec/vvc/vvc_ps.c @@ -219,14 +219,22 @@ fail: return NULL; } -static int decode_sps(VVCParamSets *ps, const H266RawSPS *rsps, void *log_ctx) +static int decode_sps(VVCParamSets *ps, const H266RawSPS *rsps, void *log_ctx, int is_clvss) { const int sps_id = rsps->sps_seq_parameter_set_id; const VVCSPS *old_sps = ps->sps_list[sps_id]; const VVCSPS *sps; - if (old_sps && old_sps->r == rsps) - return 0; + if (is_clvss) { + ps->sps_id_used = 0; + } + + if (old_sps) { + if (old_sps->r == rsps || !memcmp(old_sps->r, rsps, sizeof(*old_sps->r))) + return 0; + else if (ps->sps_id_used & (1 << sps_id)) + return AVERROR_INVALIDDATA; + } sps = sps_alloc(rsps, log_ctx); if (!sps) @@ -234,6 +242,7 @@ static int decode_sps(VVCParamSets *ps, const H266RawSPS *rsps, void *log_ctx) ff_refstruct_unref(&ps->sps_list[sps_id]); ps->sps_list[sps_id] = sps; + ps->sps_id_used |= (1 << sps_id); return 0; } @@ -610,7 +619,7 @@ static int decode_pps(VVCParamSets *ps, const H266RawPPS *rpps) return ret; } -static int decode_ps(VVCParamSets *ps, const CodedBitstreamH266Context *h266, void *log_ctx) +static int decode_ps(VVCParamSets *ps, const CodedBitstreamH266Context *h266, void *log_ctx, int is_clvss) { const H266RawPictureHeader *ph = h266->ph; const H266RawPPS *rpps; @@ -628,7 +637,7 @@ static int decode_ps(VVCParamSets *ps, const CodedBitstreamH266Context *h266, vo if (!rsps) return AVERROR_INVALIDDATA; - ret = decode_sps(ps, rsps, log_ctx); + ret = decode_sps(ps, rsps, log_ctx, is_clvss); if (ret < 0) return ret; @@ -867,13 +876,16 @@ int ff_vvc_decode_frame_ps(VVCFrameParamSets *fps, struct VVCContext *s) int ret = 0; VVCParamSets *ps = &s->ps; const CodedBitstreamH266Context *h266 = s->cbc->priv_data; + int is_clvss; + + decode_recovery_flag(s); + is_clvss = IS_CLVSS(s); - ret = decode_ps(ps, h266, s->avctx); + ret = decode_ps(ps, h266, s->avctx, is_clvss); if (ret < 0) return ret; - decode_recovery_flag(s); - ret = decode_frame_ps(fps, ps, h266, s->poc_tid0, IS_CLVSS(s)); + ret = decode_frame_ps(fps, ps, h266, s->poc_tid0, is_clvss); decode_recovery_poc(s, &fps->ph); return ret; } diff --git a/libavcodec/vvc/vvc_ps.h b/libavcodec/vvc/vvc_ps.h index f60d8b81c6..710673ebed 100644 --- a/libavcodec/vvc/vvc_ps.h +++ b/libavcodec/vvc/vvc_ps.h @@ -214,6 +214,8 @@ typedef struct VVCParamSets { const VVCALF *alf_list[VVC_MAX_ALF_COUNT]; ///< RefStruct reference const H266RawAPS *lmcs_list[VVC_MAX_LMCS_COUNT]; ///< RefStruct reference const VVCScalingList *scaling_list[VVC_MAX_SL_COUNT]; ///< RefStruct reference + // Bit field of SPS IDs used in the current CVS + uint16_t sps_id_used; } VVCParamSets; typedef struct VVCFrameParamSets {