Commit ef43c05ce3 for ffmpeg

commit ef43c05ce34f46b061598f385589f9b68d39f747
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date:   Thu Dec 3 08:53:13 2026 -0600

    avcodec/vvc_parser: report full pictures after GDR pictures

    Track, as the decoder does, whether the pictures parsed so far are
    whole: from an IDR or CRA picture on, except for the RASL pictures of a
    CRA picture decoding starts at, or from the first picture whose POC
    reaches the recovery point of a GDR picture decoding starts at.

    A seek with the pre-roll in MP4 then lands on the GDR picture before
    the target when the one before it recovers after it.

diff --git a/libavcodec/vvc_parser.c b/libavcodec/vvc_parser.c
index 7e4849c41e..c4028928bd 100644
--- a/libavcodec/vvc_parser.c
+++ b/libavcodec/vvc_parser.c
@@ -56,6 +56,12 @@ typedef struct VVCParserContext {
     AuDetector au_detector;

     int parsed_extradata;
+
+    int recovered, picture_recovered;
+    /* Whether the parser started at a CRA picture, whose RASL pictures a
+     * decoder does not output. */
+    int skip_rasl;
+    int recovery_poc;
 } VVCParserContext;

 static const enum AVPixelFormat pix_fmts_8bit[] = {
@@ -343,6 +349,30 @@ error:
     return ret;
 }

+/**
+ * Track recovery as the decoder does: from the first picture on when it is
+ * an IDR or CRA picture, or from the first picture whose POC reaches the
+ * recovery point when it is a GDR picture.
+ */
+static void update_recovery(VVCParserContext *ctx, const PuInfo *info, int poc)
+{
+    int nut = info->slice->header.nal_unit_header.nal_unit_type;
+
+    if (IS_IDR(nut) || nut == VVC_CRA_NUT) {
+        ctx->skip_rasl = nut == VVC_CRA_NUT && ctx->recovered < 0;
+        ctx->recovered = 1;
+    } else if (nut == VVC_GDR_NUT && ctx->recovered < 0) {
+        uint32_t cnt = info->ph->ph_recovery_poc_cnt;
+
+        ctx->recovery_poc = av_sat_add32(poc, FFMIN(cnt, INT_MAX));
+        ctx->recovered    = 0;
+    }
+    if (!ctx->recovered && poc >= ctx->recovery_poc)
+        ctx->recovered = 1;
+    ctx->picture_recovered = ctx->skip_rasl && nut == VVC_RASL_NUT ?
+                             0 : ctx->recovered;
+}
+
 static int append_au(AVPacket *pkt, const uint8_t *buf, int buf_size)
 {
     int offset = pkt->size;
@@ -392,6 +422,7 @@ static int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf,
         goto end;
     }
     if (is_au_start(ctx, &info, avctx)) {
+        update_recovery(ctx, &info, ctx->au_detector.prev_poc);
         set_parser_ctx(s, avctx, &info);
         av_packet_move_ref(&ctx->last_au, &ctx->au);
     } else {
@@ -501,6 +532,13 @@ static const CodedBitstreamUnitType decompose_unit_types[] = {
     VVC_AUD_NUT,
 };

+static int vvc_parser_full_picture(const AVCodecParserContext *s)
+{
+    const VVCParserContext *ctx = s->priv_data;
+
+    return ctx->picture_recovered;
+}
+
 static av_cold int vvc_parser_init(AVCodecParserContext *s)
 {
     VVCParserContext *ctx = s->priv_data;
@@ -510,6 +548,7 @@ static av_cold int vvc_parser_init(AVCodecParserContext *s)
     if (ret < 0)
         return ret;
     au_detector_init(&ctx->au_detector);
+    ctx->recovered = ctx->picture_recovered = -1;

     ctx->cbc->decompose_unit_types    = decompose_unit_types;
     ctx->cbc->nb_decompose_unit_types = FF_ARRAY_ELEMS(decompose_unit_types);
@@ -535,4 +574,5 @@ const FFCodecParser ff_vvc_parser = {
     .init           = vvc_parser_init,
     .close          = vvc_parser_close,
     .parse          = vvc_parser_parse,
+    .full_picture   = vvc_parser_full_picture,
 };
diff --git a/tests/ref/fate/mov-mp4-vvc-gdr-seek b/tests/ref/fate/mov-mp4-vvc-gdr-seek
index 64512cbbb3..cf585f17ad 100644
--- a/tests/ref/fate/mov-mp4-vvc-gdr-seek
+++ b/tests/ref/fate/mov-mp4-vvc-gdr-seek
@@ -5,5 +5,5 @@ b97f12ce6912e0d7bf29af3e02468451 *tests/data/fate/mov-mp4-vvc-gdr-seek.mp4
 #codec_id 0: rawvideo
 #dimensions 0: 416x240
 #sar 0: 0/1
-0,         12,         12,        1,   299520, 0xce45944c
-0,         13,         13,        1,   299520, 0xdb1f85fc
+0,          0,          0,        1,   299520, 0x287b0ea0
+0,          1,          1,        1,   299520, 0x75ac9088