Commit 5ef10cee81 for aom

commit 5ef10cee81dc97b393c3b353ea60710187793d59
Author: Marco Paniconi <marpan@google.com>
Date:   Tue Oct 20 22:17:07 2026 +0000

    rtc-svc: Fix initial avg_frame_qindex for VBR mode

    In av1_init_layer_context(), initialize lp_rc->avg_frame_qindex[INTER_FRAME]
    and lp_rc->avg_frame_qindex[KEY_FRAME] to
    (lrc->worst_quality + lrc->best_quality) / 2 when rc_cfg.mode == AOM_VBR,
    matching av1_primary_rc_init().

    Previously, avg_frame_qindex was initialized to lrc->worst_quality even
    in VBR mode. In the tests in the issue below (L1T2 and L1T3), the AV1
    encoder defaults to VBR mode and uses fixed SVC mode. Prior to commit
    b7cd5ffb57 ("rtc-svc: Fix refresh and unused ref_idx in
    set_ref_frame_config"), refresh_frame.golden_frame was inadvertently set
    to 1 on TL0 inter frames, which boosted quality via get_gf_active_quality()
    and masked the worst_quality initialization. After b7cd5ffb57 set
    golden_frame to 0 on TL0 frames, rc_pick_q_and_bounds_no_stats() used
    inter_minq[avg_frame_qindex[INTER_FRAME]] for active_best_quality,
    clamping frame Q near worst_quality (QP 53) and causing the SVC frame validation tests to fail.

    Bug: b:575597357
    Change-Id: I3617f304efa08726eac2220bf66d0abf81b8119c

diff --git a/av1/encoder/svc_layercontext.c b/av1/encoder/svc_layercontext.c
index 732bc22bb9..1420f47edc 100644
--- a/av1/encoder/svc_layercontext.c
+++ b/av1/encoder/svc_layercontext.c
@@ -60,6 +60,14 @@ void av1_init_layer_context(AV1_COMP *const cpi) {
       lp_rc->last_q[INTER_FRAME] = lrc->worst_quality;
       lp_rc->avg_frame_qindex[INTER_FRAME] = lrc->worst_quality;
       lp_rc->avg_frame_qindex[KEY_FRAME] = lrc->worst_quality;
+      if (oxcf->rc_cfg.mode == AOM_VBR) {
+        // Initialize avg_frame_qindex to the midpoint of worst and best
+        // quality for VBR mode, matching av1_primary_rc_init().
+        lp_rc->avg_frame_qindex[INTER_FRAME] =
+            (lrc->worst_quality + lrc->best_quality) / 2;
+        lp_rc->avg_frame_qindex[KEY_FRAME] =
+            (lrc->worst_quality + lrc->best_quality) / 2;
+      }
       lp_rc->buffer_level =
           oxcf->rc_cfg.starting_buffer_level_ms * lc->target_bandwidth / 1000;
       lp_rc->bits_off_target = lp_rc->buffer_level;