From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id ED33849BEE for ; Wed, 3 Apr 2024 19:01:26 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9881968CFDA; Wed, 3 Apr 2024 22:01:23 +0300 (EEST) Received: from wrqvqshf.outbound-mail.sendgrid.net (wrqvqshf.outbound-mail.sendgrid.net [149.72.70.15]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5E1DC68CD3F for ; Wed, 3 Apr 2024 22:01:16 +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=0XPtwqxi3DDCN4kLedlMfA1aqsSuTmSUqKF/Qe5TNdw=; b=RS9NefzWdE7l2mKFvqkzClo8TGnj+ncKhcMcbgwihNhv2VCVWn2V7yb1lhlXuqkTSiR3 74ZYx5D8ik6rB14mgXHe8jpTWs/bR9x4MJsBEyFU+w/PzRzHKrorSAvq7YJcIKdcfvpbIt hafNKJL/zxXHqfcnAHdVaLxu61/VyYHjEGNa5j3J7LmJH8ozxwdckxFD1ifCT34iGncMi+ ld6KDWnrNkN/c2BNBlgUcc6yveF1x85qLpEDA1Ldm2HVU/gBB72n/H2KCPJLjp58q1AZtK 21UqsKIfddKT0cKI7/JytE41Xh+9byDee9GxwcA3pNHkOcUVNt/zLhcKfYeTyKYw== Received: by recvd-75c664ffc8-x27pj with SMTP id recvd-75c664ffc8-x27pj-1-660DA77A-2D 2024-04-03 19:01:14.716932746 +0000 UTC m=+1375317.794549960 Received: from localhost.localdomain (unknown) by geopod-ismtpd-1 (SG) with ESMTP id 0Gb7kV54S-2M5wOF4RWYDA Wed, 03 Apr 2024 19:01:14.364 +0000 (UTC) From: Frank Plowman Date: Wed, 03 Apr 2024 19:01:14 +0000 (UTC) Message-ID: <20240403190053.86712-1-post@frankplowman.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-SG-EID: =?us-ascii?Q?u001=2EZ0KJCHpts8tvDq7PHgz5cpqJ+vJcSmdTtST=2Fg91WT3qAbNxUpEMGIDQq9?= =?us-ascii?Q?1mXy3Yjvepp8fYsFUJzGsyhT1EwBWaGvlUUI=2Fgm?= =?us-ascii?Q?33v7dzWQ19ww+k5Ym111A3h9p1ToKbwF6sExlaR?= =?us-ascii?Q?KEfExv3ea5veGC2WJAPp8s2YJznJ6iCKu9E9M2h?= =?us-ascii?Q?Z2cL7Se3QYTcbOaJYBbUjXGapE8aVppl=2Fv8f1DF?= =?us-ascii?Q?kcfGJhPXQwmzEV7nItXmCT1y6EgSuKfK1mJtHVI?= =?us-ascii?Q?ioZw?= To: ffmpeg-devel@ffmpeg.org X-Entity-ID: u001.qzljkbu34TNIX4NwfTiKWA== Subject: [FFmpeg-devel] [PATCH] 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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. --- libavcodec/vvc/vvc_ps.c | 29 +++++++++++++++++++++-------- libavcodec/vvc/vvc_ps.h | 1 + 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/libavcodec/vvc/vvc_ps.c b/libavcodec/vvc/vvc_ps.c index 301fa16400..7a8daaa6ad 100644 --- a/libavcodec/vvc/vvc_ps.c +++ b/libavcodec/vvc/vvc_ps.c @@ -219,14 +219,23 @@ 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) { + for (int sps_id = 0; sps_id < VVC_MAX_SPS_COUNT; ++sps_id) + ps->sps_id_used[sps_id] = 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[sps_id]) + return AVERROR_INVALIDDATA; + sps = sps_alloc(rsps, log_ctx); if (!sps) @@ -234,6 +243,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[sps_id] = 1; return 0; } @@ -610,7 +620,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 +638,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 +877,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; - ret = decode_ps(ps, h266, s->avctx); + decode_recovery_flag(s); + is_clvss = IS_CLVSS(s); + + 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..b293043de8 100644 --- a/libavcodec/vvc/vvc_ps.h +++ b/libavcodec/vvc/vvc_ps.h @@ -210,6 +210,7 @@ typedef struct VVCLMCS { typedef struct VVCParamSets { const VVCSPS *sps_list[VVC_MAX_SPS_COUNT]; ///< RefStruct reference + int sps_id_used[VVC_MAX_SPS_COUNT]; const VVCPPS *pps_list[VVC_MAX_PPS_COUNT]; ///< RefStruct reference const VVCALF *alf_list[VVC_MAX_ALF_COUNT]; ///< RefStruct reference const H266RawAPS *lmcs_list[VVC_MAX_LMCS_COUNT]; ///< RefStruct reference -- 2.44.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".