Commit 06cc4794a4 for ffmpeg

commit 06cc4794a4e3c6898d62238ff0bca42bd1599232
Author: Kacper Michajłow <kasper93@gmail.com>
Date:   Tue Nov 10 12:04:31 2026 +0100

    avcodec/dxva2_h264: mark missing RefPicList references not available

    For a RefPicList entry with Index7Bits 127 the DXVA H.264 specification
    reads AssociatedFlag as a non-existing (1) or a not available (0)
    picture, and references to a not available picture decode from mid-gray
    samples. get_refpic_index() returns 127 for a reference that
    RefFrameList does not hold, such as the one h264_refs.c substitutes for
    a missing reference, and the bottom field flag turned it into a
    non-existing picture in field pictures. Always use 0 for such entries.

    Signed-off-by: Kacper Michajłow <kasper93@gmail.com>

diff --git a/libavcodec/dxva2_h264.c b/libavcodec/dxva2_h264.c
index 4bf5f560d9..daed437816 100644
--- a/libavcodec/dxva2_h264.c
+++ b/libavcodec/dxva2_h264.c
@@ -255,10 +255,12 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice,
                 unsigned plane;
                 unsigned index = ff_dxva2_get_surface_index(avctx, ctx, r->f, 0);
                 unsigned flag = sl->ref_list[list][i].reference == PICT_BOTTOM_FIELD;
-                if (DXVA_CONTEXT_WORKAROUND(avctx, ctx) & FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO)
+                if (DXVA_CONTEXT_WORKAROUND(avctx, ctx) & FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO) {
                     fill_picture_entry(&slice->RefPicList[list][i], index, flag);
-                else
-                    slice->RefPicList[list][i].bPicEntry = get_refpic_index(pp, index) | (flag << 7);
+                } else {
+                    unsigned pos = get_refpic_index(pp, index);
+                    slice->RefPicList[list][i].bPicEntry = pos == 0x7f ? 0x7f : pos | (flag << 7);
+                }
                 for (plane = 0; plane < 3; plane++) {
                     int w, o;
                     if (plane == 0 && sl->pwt.luma_weight_flag[list]) {