PR #20717 opened by frankplow
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20717
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20717.patch

seq_decode is used to ensure that a picture and all of its reference pictures 
use the same SPS. Any time the SPS changes, seq_decode should be incremented. 
Prior to this patch, seq_decode was incremented in frame_context_setup, which 
is called after the SPS is potentially changed in decode_sps. Should the 
decoder encounter an error between changing the SPS and incrementing 
seq_decode, the SPS could be modified while seq_decode was not incremented, 
which could lead to invalid reference pictures and various downstream issues. 
By instead updating seq_decode within the picture set manager, we ensure 
seq_decode and the SPS are always updated in tandem.


>From e611aeff64a15d12cede6da420e0173c665117a7 Mon Sep 17 00:00:00 2001
From: Frank Plowman <[email protected]>
Date: Sun, 19 Oct 2025 12:28:00 +0100
Subject: [PATCH] lavc/vvc: Ensure seq_decode is always updated with SPS

seq_decode is used to ensure that a picture and all of its reference
pictures use the same SPS. Any time the SPS changes, seq_decode should
be incremented. Prior to this patch, seq_decode was incremented in
frame_context_setup, which is called after the SPS is potentially
changed in decode_sps. Should the decoder encounter an error between
changing the SPS and incrementing seq_decode, the SPS could be modified
while seq_decode was not incremented, which could lead to invalid
reference pictures and various downstream issues. By instead updating
seq_decode within the picture set manager, we ensure seq_decode and the
SPS are always updated in tandem.
---
 libavcodec/vvc/dec.c | 1 -
 libavcodec/vvc/ps.c  | 2 ++
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vvc/dec.c b/libavcodec/vvc/dec.c
index bfe330e028..028f34b491 100644
--- a/libavcodec/vvc/dec.c
+++ b/libavcodec/vvc/dec.c
@@ -726,7 +726,6 @@ static int frame_context_setup(VVCFrameContext *fc, 
VVCContext *s)
     }
 
     if (IS_IDR(s)) {
-        s->seq_decode = (s->seq_decode + 1) & 0xff;
         ff_vvc_clear_refs(fc);
     }
 
diff --git a/libavcodec/vvc/ps.c b/libavcodec/vvc/ps.c
index 8faee1d826..a591851238 100644
--- a/libavcodec/vvc/ps.c
+++ b/libavcodec/vvc/ps.c
@@ -279,12 +279,14 @@ fail:
 
 static int decode_sps(VVCParamSets *ps, AVCodecContext *c, const H266RawSPS 
*rsps, int is_clvss)
 {
+    VVCContext *s           = c->priv_data;
     const int sps_id        = rsps->sps_seq_parameter_set_id;
     const VVCSPS *old_sps   = ps->sps_list[sps_id];
     const VVCSPS *sps;
 
     if (is_clvss) {
         ps->sps_id_used = 0;
+        s->seq_decode = (s->seq_decode + 1) & 0xff;
     }
 
     if (old_sps) {
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to