Commit 7ae03d8977 for aom

commit 7ae03d8977c63acfe08f63a6c03418b26c2b871d
Author: Jerome Jiang <jianj@google.com>
Date:   Tue Mar 17 17:25:31 2026 -0400

    RC: Add flag indicating whether to use delta q

    RC library only calculates delta q for key, golden and regular ARF. To
    avoid apply delta q data from RC for intermediate ARF, a flag is added
    to avoid freeing / reallocating memory for delta q repeatedly.

    This flag will be set by RC

    Change-Id: I63d0315ff34dec4e2756227cff39b684c4732b76

diff --git a/aom/aom_ext_ratectrl.h b/aom/aom_ext_ratectrl.h
index dfc9c53f6e..88598a3b80 100644
--- a/aom/aom_ext_ratectrl.h
+++ b/aom/aom_ext_ratectrl.h
@@ -159,6 +159,11 @@ typedef struct aom_sb_parameters {
 typedef struct aom_rc_encodeframe_decision {
   int q_index; /**< Required: Quantizer step index [0..255]*/
   int rdmult;  /**< Required: Frame level Lagrangian multiplier*/
+  // Whether per-superblock delta Q should be used.
+  // The rate control model should set the value pointed to by this member
+  // to 1 if per-superblock delta-Q is used for this frame, or 0 otherwise.
+  // This is a pointer to the flag in cpi->ext_ratectrl.
+  int *use_delta_q;
   /*!
    * Optional: Superblock quantization parameters
    * It is zero initialized by default. It will be set for key and ARF frames
diff --git a/av1/encoder/av1_ext_ratectrl.h b/av1/encoder/av1_ext_ratectrl.h
index 4cab2f0617..bf7c4a9e2a 100644
--- a/av1/encoder/av1_ext_ratectrl.h
+++ b/av1/encoder/av1_ext_ratectrl.h
@@ -20,6 +20,11 @@
 typedef struct AOM_EXT_RATECTRL {
   int ready;
   int ext_rdmult;
+  // Whether per-superblock delta Q should be used. This is set on frame basis.
+  // Key, golden and regular ARF frames use delta Q. All other frames do not.
+  // This flag is added so the sb_params_list array doesn't have to be freed
+  // and allocated repeatedly.
+  int use_delta_q;
   aom_rc_model_t model;
   aom_rc_funcs_t funcs;
   aom_rc_config_t ratectrl_config;
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 76c73aca98..5846e031cd 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -321,9 +321,11 @@ static inline void setup_delta_q(AV1_COMP *const cpi, ThreadData *td,
              (cpi->ext_ratectrl.funcs.rc_type & AOM_RC_QP) != 0 &&
              cpi->ext_ratectrl.funcs.get_encodeframe_decision != NULL &&
              cpi->ext_ratectrl.sb_params_list != NULL) {
-    const int q_index = cpi->ext_ratectrl.sb_params_list[sb_index].q_index;
-    if (q_index != AOM_DEFAULT_Q) {
-      current_qindex = q_index;
+    if (cpi->ext_ratectrl.use_delta_q) {
+      const int q_index = cpi->ext_ratectrl.sb_params_list[sb_index].q_index;
+      if (q_index != AOM_DEFAULT_Q) {
+        current_qindex = q_index;
+      }
     }
   } else if (cpi->oxcf.q_cfg.deltaq_mode == DELTA_Q_PERCEPTUAL) {
     if (DELTA_Q_PERCEPTUAL_MODULATION == 1) {
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index b1c02e4f02..85895ada3d 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -3460,6 +3460,7 @@ static int encode_with_recode_loop(AV1_COMP *cpi, size_t *size, uint8_t *dest,
                 sb_rows * sb_cols, sizeof(*cpi->ext_ratectrl.sb_params_list)));
       }
       encode_frame_decision.sb_params_list = cpi->ext_ratectrl.sb_params_list;
+      encode_frame_decision.use_delta_q = &cpi->ext_ratectrl.use_delta_q;
       codec_status = av1_extrc_get_encodeframe_decision(
           &cpi->ext_ratectrl, cpi->gf_frame_index, &encode_frame_decision);
       if (codec_status != AOM_CODEC_OK) {