Commit 34f25197c6 for aom

commit 34f25197c6e9efef129992bb763aefa6036119fd
Author: Wan-Teh Chang <wtc@google.com>
Date:   Thu Mar 12 17:58:23 2026 -0700

    Allocate original source buffer for psnr correctly

    Correct the condition for allocating the cpi->orig_source buffer.

    The use_rtc_tf speed feature and the cpi->orig_source buffer were added
    in https://aomedia-review.git.corp.google.com/c/aom/+/153083.

    The condition for allocating the cpi->orig_source buffer was modified in
    https://aomedia-review.git.corp.google.com/c/aom/+/186721. The
    cpi->rc.prev_coded_width and cpi->rc.prev_coded_height variables used in
    the new condition were added in
    https://aomedia-review.git.corp.google.com/c/aom/+/167241.

    Bug: 491358681
    Change-Id: Ibfc88491bc2e293f56394dc201fccab7786de02b

diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 6182f1d781..b1c02e4f02 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -3157,20 +3157,24 @@ static int encode_without_recode(AV1_COMP *cpi) {

   // This is for rtc temporal filtering case.
   if (is_psnr_calc_enabled(cpi) && cpi->sf.rt_sf.use_rtc_tf) {
-    const SequenceHeader *seq_params = cm->seq_params;
-
     if (cpi->orig_source.buffer_alloc_sz == 0 ||
-        cpi->rc.prev_coded_width != cpi->oxcf.frm_dim_cfg.width ||
-        cpi->rc.prev_coded_height != cpi->oxcf.frm_dim_cfg.height) {
-      // Allocate a source buffer to store the true source for psnr calculation.
-      if (aom_alloc_frame_buffer(
-              &cpi->orig_source, cpi->oxcf.frm_dim_cfg.width,
-              cpi->oxcf.frm_dim_cfg.height, seq_params->subsampling_x,
-              seq_params->subsampling_y, seq_params->use_highbitdepth,
-              cpi->oxcf.border_in_pixels, cm->features.byte_alignment, false,
-              0))
+        cpi->orig_source.y_crop_width != cpi->source->y_crop_width ||
+        cpi->orig_source.y_crop_height != cpi->source->y_crop_height ||
+        cpi->orig_source.subsampling_x != cpi->source->subsampling_x ||
+        cpi->orig_source.subsampling_y != cpi->source->subsampling_y ||
+        cpi->orig_source.flags != cpi->source->flags) {
+      // Allocate a source buffer to store the original source for psnr
+      // calculation.
+      const int use_highbitdepth =
+          (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) != 0;
+      if (aom_alloc_frame_buffer(&cpi->orig_source, cpi->source->y_crop_width,
+                                 cpi->source->y_crop_height,
+                                 cpi->source->subsampling_x,
+                                 cpi->source->subsampling_y, use_highbitdepth,
+                                 cpi->oxcf.border_in_pixels,
+                                 cm->features.byte_alignment, false, 0))
         aom_internal_error(cm->error, AOM_CODEC_MEM_ERROR,
-                           "Failed to allocate scaled buffer");
+                           "Failed to allocate cpi->orig_source buffer");
     }

     aom_yv12_copy_y(cpi->source, &cpi->orig_source, 1);