Commit 4dd159d947 for aom
commit 4dd159d947fb3a44745b2cbf876f33edb7aec389
Author: Ihor Buhaiov <freedbrt@gmail.com>
Date: Fri Nov 13 09:00:34 2026 +0100
rtc: Check chroma of zero mv skip blocks
In nonrd pickmode a skipped block with zero motion gets no chroma check
after the mode search. Color sensitivity is supposed to cover that, but
it can stay off for a block whose chroma changed. The superblock test
compares the chroma SAD with the luma SAD of the whole superblock, so
luma motion elsewhere in it hides the change, and the block test needs
a mean chroma difference above 2.5, which a change in a few pixels does
not reach. With color sensitivity on, the uv model still averages the
error over the whole block, so a big block can skip with one bad 8x8
area. On screen content a block whose color changes while its luma does
not (a highlight, a text color) then keeps the old color.
For a skipped single reference block with zero mv, check each chroma
plane in parts of 8x8 (4 wide or high at small blocks and frame edges)
and drop the skip if a part has an error above half the squared
quantizer step per pixel. The step follows the bit depth, so the check
also works in 10 bit. Moved blocks keep the existing check.
Keep the skip when the chroma source of the block is the same as the
source LAST was coded from. Its error is then old, and coding it again
at a lower q only spends bits. Without this, CBR lowers q on static
content, old errors fail the check, and the same blocks are coded again
every frame. Without SVC the last source is the previous frame, so LAST
has to be the previous frame too.
On static content almost every block takes this path, so skip the
check where the answer is already known. Variance based partitioning
computes the chroma SAD of each superblock against LAST at zero mv.
Keep it for the next frame. If a plane's SAD is the same as in the
previous frame, and every block of the superblock was a zero mv LAST
skip in that frame, then LAST did not change there and the chroma
source almost surely did not either, so the plane keeps the skip. LAST
has to be the previous frame here too. The test is off with SVC.
The whole block check used for moved blocks does not fit here. Run on
zero mv planes with color sensitivity off it adds 5% to 7% bytes on
some screen clips and still misses planes with it on. Gated on the mean
error per pixel it misses the small changes.
Screen content repro cases, 8 bit, speed 10 and 11, with and without
the active map, worst chroma 16x16 block per clip (Apple M3 Pro):
4:2:0 and 4:4:4, 36 clips: min(U,V) under 25 dB in 10 clips, now
none; under 30 dB in 17 clips, now 11. No mismatch.
The superblock SAD test does not change these results. 57 screen repro
cases (8 and 10 bit, 4:2:0, 4:4:4, monochrome and gray chroma) give the
same streams with and without it.
Encode time, instructions and size against main, aomenc screen speed 11
CBR line from review (min-q 2, aq-mode 3, palette on), 7 screen
captures 1080p, 300 frames, 400, 1000 and 2000 kbps, median of 7 runs
(instructions: min), geomean, with an A/A run of main against itself,
Apple M3 Pro, clang. Static is the 2 captures with little motion:
4:2:0 4:4:4
all static all static
time +0.89 +1.77 +0.48 -0.15
A/A +0.30 +0.70 +0.01 -0.30
instructions +0.31 +0.33 +0.65 +0.52
A/A +0.01 +0.02 +0.00 +0.00
Bytes on the static captures equal main at all three rates.
10 bit: the AOM clips park_joy_90p and screendata 1080p, 4:2:0 and
4:4:4, no recon mismatch. Monochrome and gray chroma screen cases, 8
and 10 bit, no mismatch.
Test: EncodeAPI.ChromaOnlyChangeRealtime fails without the fix and
passes with it. EncodeAPI.ChromaOnlyChangeHoldLastRealtime, where the
frame with the change does not refresh LAST, fails without the check of
LAST. EncodeAPI, ActiveMap, InactiveArea and ROIMap tests pass in a
default and a realtime only build.
Bug: 585649103
Change-Id: Ifa104250637c5df8f13b5278f02b97ab200a2907
diff --git a/av1/encoder/block.h b/av1/encoder/block.h
index 24531ed27b..c4a34d9c4f 100644
--- a/av1/encoder/block.h
+++ b/av1/encoder/block.h
@@ -1379,6 +1379,11 @@ typedef struct macroblock {
* of moving color objects.
*/
uint8_t color_sensitivity_sb[MAX_MB_PLANE - 1];
+ /*!
+ * Set for a chroma plane whose superblock SAD against LAST at zero mv is
+ * the same as in the previous frame, see SbUvSad.
+ */
+ bool uv_unchanged_sb[MAX_MB_PLANE - 1];
//! Color sensitivity flag for the superblock for golden reference.
uint8_t color_sensitivity_sb_g[MAX_MB_PLANE - 1];
//! Color sensitivity flag for the superblock for altref reference.
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 3429af1c3d..652b91a0f8 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -1426,6 +1426,7 @@ static inline void encode_sb_row(AV1_COMP *cpi, ThreadData *td,
// Reset color coding related parameters
av1_zero(x->color_sensitivity_sb);
+ av1_zero(x->uv_unchanged_sb);
av1_zero(x->color_sensitivity_sb_g);
av1_zero(x->color_sensitivity_sb_alt);
av1_zero(x->color_sensitivity);
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 2913303d95..91782344d6 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -3199,6 +3199,21 @@ static int encode_without_recode(AV1_COMP *cpi) {
memset(cpi->consec_zero_mv, 0, current_size * sizeof(*cpi->consec_zero_mv));
}
+ if (cpi->oxcf.mode == REALTIME && sf->rt_sf.use_nonrd_pick_mode &&
+ sf->part_sf.partition_search_type == VAR_BASED_PARTITION) {
+ // A size change also scales LAST, so old entries are never used.
+ const int sb_log2 = cm->seq_params->mib_size_log2;
+ const int sb_count = CEIL_POWER_OF_TWO(cm->mi_params.mi_rows, sb_log2) *
+ CEIL_POWER_OF_TWO(cm->mi_params.mi_cols, sb_log2);
+ if (cpi->sb_uv_sad_alloc_size < sb_count) {
+ aom_free(cpi->sb_uv_sad);
+ cpi->sb_uv_sad_alloc_size = 0;
+ CHECK_MEM_ERROR(cm, cpi->sb_uv_sad,
+ aom_calloc(sb_count, sizeof(*cpi->sb_uv_sad)));
+ cpi->sb_uv_sad_alloc_size = sb_count;
+ }
+ }
+
if (cpi->scaled_last_source_available) {
cpi->last_source = &cpi->scaled_last_source;
cpi->scaled_last_source_available = 0;
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index 01c5b835f1..36c75e0cb7 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -2922,6 +2922,26 @@ typedef struct AV1_PRIMARY {
int b_freeze_internal_state;
} AV1_PRIMARY;
+/*!
+ * \brief Chroma SAD of a superblock against LAST at zero mv, kept for the
+ * next frame.
+ */
+typedef struct {
+ /*!
+ * SAD of each chroma plane.
+ */
+ unsigned int uv_sad[MAX_MB_PLANE - 1];
+ /*!
+ * Frame number plus one of the frame that measured the SAD, 0 if none did.
+ */
+ unsigned int frame;
+ /*!
+ * Set when a block of the superblock was coded as anything but a zero mv
+ * LAST skip in that frame.
+ */
+ bool coded;
+} SbUvSad;
+
/*!
* \brief Top level encoder structure.
*/
@@ -3555,6 +3575,16 @@ typedef struct AV1_COMP {
*/
int consec_zero_mv_alloc_size;
+ /*!
+ * Chroma SAD of each superblock in the previous frame.
+ */
+ SbUvSad *sb_uv_sad;
+
+ /*!
+ * Allocated number of entries in |sb_uv_sad|.
+ */
+ int sb_uv_sad_alloc_size;
+
/*!
* Block size of first pass encoding
*/
@@ -4234,6 +4264,17 @@ static inline int is_one_pass_rt_lag_params(const AV1_COMP *cpi) {
cpi->oxcf.gf_cfg.lag_in_frames > 0 && cpi->oxcf.mode == REALTIME;
}
+// Returns the chroma SAD entry of the superblock at mi_row, mi_col, or NULL
+// when the table does not cover the frame.
+static inline SbUvSad *av1_get_sb_uv_sad(const AV1_COMP *cpi, int mi_row,
+ int mi_col) {
+ const AV1_COMMON *const cm = &cpi->common;
+ const int sb_log2 = cm->seq_params->mib_size_log2;
+ const int sb_cols = CEIL_POWER_OF_TWO(cm->mi_params.mi_cols, sb_log2);
+ const int index = (mi_row >> sb_log2) * sb_cols + (mi_col >> sb_log2);
+ return index < cpi->sb_uv_sad_alloc_size ? &cpi->sb_uv_sad[index] : NULL;
+}
+
static inline int is_one_pass_rt_params(const AV1_COMP *cpi) {
return has_no_stats_stage(cpi) && cpi->oxcf.gf_cfg.lag_in_frames == 0 &&
(cpi->oxcf.mode == REALTIME || cpi->svc.number_spatial_layers > 1);
diff --git a/av1/encoder/encoder_alloc.h b/av1/encoder/encoder_alloc.h
index 84c4c52fca..7574ce83ad 100644
--- a/av1/encoder/encoder_alloc.h
+++ b/av1/encoder/encoder_alloc.h
@@ -469,6 +469,10 @@ static inline void dealloc_compressor_data(AV1_COMP *cpi) {
cpi->consec_zero_mv = NULL;
cpi->consec_zero_mv_alloc_size = 0;
+ aom_free(cpi->sb_uv_sad);
+ cpi->sb_uv_sad = NULL;
+ cpi->sb_uv_sad_alloc_size = 0;
+
aom_free(cpi->src_sad_blk_64x64);
cpi->src_sad_blk_64x64 = NULL;
diff --git a/av1/encoder/nonrd_pickmode.c b/av1/encoder/nonrd_pickmode.c
index 9267a6a178..c33ca8d950 100644
--- a/av1/encoder/nonrd_pickmode.c
+++ b/av1/encoder/nonrd_pickmode.c
@@ -617,6 +617,83 @@ static bool is_uv_plane_skippable(const AV1_COMP *cpi, MACROBLOCK *x,
return (var < uv_ac_thr || var == 0) && (sse - var < uv_dc_thr || sse == var);
}
+// Checks the zero mv residual of one chroma plane in parts of 8x8 or less, so
+// a small change in a big block is not averaged out. A part fails when its
+// error is above half the squared quantizer step per pixel.
+static bool is_zero_mv_uv_plane_skippable(const AV1_COMP *cpi,
+ const MACROBLOCK *x, BLOCK_SIZE bsize,
+ int plane) {
+ const MACROBLOCKD *const xd = &x->e_mbd;
+ const struct macroblock_plane *const p = &x->plane[plane];
+ const struct macroblockd_plane *const pd = &xd->plane[plane];
+ const BLOCK_SIZE uv_bsize =
+ get_plane_block_size(bsize, pd->subsampling_x, pd->subsampling_y);
+ int bw = block_size_wide[uv_bsize];
+ int bh = block_size_high[uv_bsize];
+ if (xd->mb_to_right_edge < 0)
+ bw += xd->mb_to_right_edge >> (3 + pd->subsampling_x);
+ if (xd->mb_to_bottom_edge < 0)
+ bh += xd->mb_to_bottom_edge >> (3 + pd->subsampling_y);
+ bw = AOMMAX(ALIGN_POWER_OF_TWO(bw, 2), 4);
+ bh = AOMMAX(ALIGN_POWER_OF_TWO(bh, 2), 4);
+ // The variance functions return the error in 8 bit scale.
+ const uint64_t qstep = p->dequant_QTX[1] >> (xd->bd - 5);
+ const uint64_t thr_pel = qstep * qstep;
+ const uint8_t *const pred = pd->pre[0].buf;
+ const int pred_stride = pd->pre[0].stride;
+ unsigned int sse;
+ cpi->ppi->fn_ptr[uv_bsize].vf(p->src.buf, p->src.stride, pred, pred_stride,
+ &sse);
+ // No part can fail when the whole block is below the smallest part limit.
+ const int min_w = (bw & 7) ? 4 : 8;
+ const int min_h = (bh & 7) ? 4 : 8;
+ if (sse <= (thr_pel * min_w * min_h) >> 1) return true;
+ for (int r = 0; r < bh; r += 8) {
+ const int h = AOMMIN(bh - r, 8);
+ for (int c = 0; c < bw; c += 8) {
+ const int w = AOMMIN(bw - c, 8);
+ const BLOCK_SIZE sub_bsize = w == 8 ? (h == 8 ? BLOCK_8X8 : BLOCK_8X4)
+ : (h == 8 ? BLOCK_4X8 : BLOCK_4X4);
+ cpi->ppi->fn_ptr[sub_bsize].vf(p->src.buf + r * p->src.stride + c,
+ p->src.stride, pred + r * pred_stride + c,
+ pred_stride, &sse);
+ if (sse > (thr_pel * w * h) >> 1) return false;
+ }
+ }
+ return true;
+}
+
+// Returns true when the source of a chroma plane of the block did not change
+// since LAST was coded. Its error is then old, and coding the block again at
+// a lower q only spends bits.
+static bool is_uv_source_unchanged(const AV1_COMP *cpi, const MACROBLOCK *x,
+ BLOCK_SIZE bsize, int plane) {
+ const AV1_COMMON *const cm = &cpi->common;
+ const MACROBLOCKD *const xd = &x->e_mbd;
+ const YV12_BUFFER_CONFIG *const last_src = cpi->last_source;
+ if (xd->mi[0]->ref_frame[0] != LAST_FRAME || last_src == NULL ||
+ last_src->y_width != cpi->source->y_width ||
+ last_src->y_height != cpi->source->y_height)
+ return false;
+ // Without SVC the last source is the previous frame, so LAST has to be the
+ // previous frame too.
+ if (!cpi->ppi->use_svc &&
+ get_ref_frame_buf(cm, LAST_FRAME)->display_order_hint + 1 !=
+ cm->current_frame.display_order_hint)
+ return false;
+ const struct macroblock_plane *const p = &x->plane[plane];
+ const struct macroblockd_plane *const pd = &xd->plane[plane];
+ const BLOCK_SIZE uv_bsize =
+ get_plane_block_size(bsize, pd->subsampling_x, pd->subsampling_y);
+ struct buf_2d last;
+ setup_pred_plane(&last, bsize, last_src->buffers[plane],
+ last_src->uv_crop_width, last_src->uv_crop_height,
+ last_src->uv_stride, xd->mi_row, xd->mi_col, NULL,
+ pd->subsampling_x, pd->subsampling_y);
+ return cpi->ppi->fn_ptr[uv_bsize].sdf(p->src.buf, p->src.stride, last.buf,
+ last.stride) == 0;
+}
+
// Sets early_term flag based on chroma planes prediction
static inline void set_early_term_based_on_uv_plane(
AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, int mi_row, int mi_col,
@@ -3989,18 +4066,26 @@ void av1_nonrd_pick_inter_mode_sb(AV1_COMP *cpi, TileDataEnc *tile_data,
txfm_info->skip_txfm = best_pickmode->best_mode_skip_txfm;
}
// Color sensitivity is set from the zero mv chroma, so a skipped block with
- // motion may still have a chroma plane that was never checked.
+ // motion may still have a chroma plane that was never checked. At zero mv
+ // it can still miss a small change, and the uv model averages the error
+ // over the whole block, so every chroma plane gets a local check there.
const int num_planes = av1_num_planes(cm);
if (txfm_info->skip_txfm && num_planes > 1 && xd->is_chroma_ref &&
- is_inter_block(mi) && !has_second_ref(mi) && mi->mv[0].as_int != 0) {
+ is_inter_block(mi) && !has_second_ref(mi)) {
const MV_REFERENCE_FRAME ref = mi->ref_frame[0];
+ const bool zero_mv = mi->mv[0].as_int == 0;
set_ref_ptrs(cm, xd, ref, NONE_FRAME);
if (search_state.use_scaled_ref_frame[ref])
xd->block_ref_scale_factors[0] = &sf_no_scale;
for (int plane = AOM_PLANE_U; plane < num_planes; ++plane) {
- if (x->color_sensitivity[COLOR_SENS_IDX(plane)]) continue;
+ if (!zero_mv && x->color_sensitivity[COLOR_SENS_IDX(plane)]) continue;
xd->plane[plane].pre[0] = search_state.yv12_mb[ref][plane];
- if (!is_uv_plane_skippable(cpi, x, bsize, mi_row, mi_col, plane)) {
+ const bool skippable =
+ zero_mv ? (ref == LAST_FRAME && x->uv_unchanged_sb[plane - 1]) ||
+ is_zero_mv_uv_plane_skippable(cpi, x, bsize, plane) ||
+ is_uv_source_unchanged(cpi, x, bsize, plane)
+ : is_uv_plane_skippable(cpi, x, bsize, mi_row, mi_col, plane);
+ if (!skippable) {
txfm_info->skip_txfm = 0;
best_pickmode->best_mode_skip_txfm = 0;
search_state.best_rdc.skip_txfm = 0;
diff --git a/av1/encoder/partition_search.c b/av1/encoder/partition_search.c
index d3d522ab46..c635137895 100644
--- a/av1/encoder/partition_search.c
+++ b/av1/encoder/partition_search.c
@@ -2190,6 +2190,13 @@ static void encode_b_nonrd(const AV1_COMP *const cpi, TileDataEnc *tile_data,
encode_superblock(cpi, tile_data, td, tp, dry_run, bsize, rate);
if (!dry_run) {
update_cb_offsets(x, bsize, subsampling_x, subsampling_y);
+ // A coded block can change LAST for the next frame, see SbUvSad.
+ SbUvSad *const sb_uv_sad = av1_get_sb_uv_sad(cpi, mi_row, mi_col);
+ if (sb_uv_sad != NULL &&
+ !(is_inter_block(mbmi) && mbmi->ref_frame[0] == LAST_FRAME &&
+ mbmi->ref_frame[1] == NONE_FRAME && mbmi->mv[0].as_int == 0 &&
+ mbmi->motion_mode == SIMPLE_TRANSLATION && mbmi->skip_txfm))
+ sb_uv_sad->coded = true;
if (has_second_ref(mbmi)) {
if (mbmi->compound_idx == 0 ||
mbmi->interinter_comp.type == COMPOUND_AVERAGE)
diff --git a/av1/encoder/var_based_part.c b/av1/encoder/var_based_part.c
index dc92fdf0c3..c24617e481 100644
--- a/av1/encoder/var_based_part.c
+++ b/av1/encoder/var_based_part.c
@@ -984,6 +984,31 @@ void av1_set_variance_partition_thresholds(AV1_COMP *cpi, int qindex,
}
}
+// Marks the chroma planes whose superblock SAD against LAST at zero mv is the
+// same as in the previous frame, where every block was a zero mv LAST skip.
+// LAST did not change there, so the chroma source most likely did not change
+// either. Without SVC LAST has to be the previous frame.
+static inline void set_uv_unchanged_sb(AV1_COMP *cpi, MACROBLOCK *x, int mi_row,
+ int mi_col, const unsigned int *uv_sad,
+ bool zero_mv_last) {
+ const AV1_COMMON *const cm = &cpi->common;
+ if (cpi->ppi->use_svc) return;
+ SbUvSad *const sb = av1_get_sb_uv_sad(cpi, mi_row, mi_col);
+ if (sb == NULL) return;
+ const unsigned int frame = cm->current_frame.frame_number;
+ const bool valid =
+ zero_mv_last &&
+ get_ref_frame_buf(cm, LAST_FRAME)->display_order_hint + 1 ==
+ cm->current_frame.display_order_hint;
+ const bool prev_valid = valid && sb->frame == frame && !sb->coded;
+ for (int i = 0; i < MAX_MB_PLANE - 1; ++i) {
+ x->uv_unchanged_sb[i] = prev_valid && sb->uv_sad[i] == uv_sad[i];
+ sb->uv_sad[i] = uv_sad[i];
+ }
+ sb->frame = valid ? frame + 1 : 0;
+ sb->coded = false;
+}
+
static inline void chroma_check(AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize,
unsigned int y_sad, unsigned int y_sad_g,
unsigned int y_sad_alt, bool is_key_frame,
@@ -1755,6 +1780,8 @@ int av1_choose_var_based_partitioning(AV1_COMP *cpi, const TileInfo *const tile,
av1_zero(uv_sad);
chroma_check(cpi, x, bsize, y_sad_last, y_sad_g, y_sad_alt, is_key_frame,
is_zero_motion, uv_sad);
+ set_uv_unchanged_sb(cpi, x, mi_row, mi_col, uv_sad,
+ !is_key_frame && is_zero_motion && !scaled_ref_last);
x->force_zeromv_skip_for_sb = 0;
diff --git a/test/encode_api_test.cc b/test/encode_api_test.cc
index c9c3afd0c5..5ce821287e 100644
--- a/test/encode_api_test.cc
+++ b/test/encode_api_test.cc
@@ -2180,6 +2180,122 @@ TEST(EncodeAPI, IntraBCKeyFrameCodesChroma) {
ASSERT_EQ(aom_codec_destroy(&dec), AOM_CODEC_OK);
ASSERT_EQ(aom_codec_destroy(&enc), AOM_CODEC_OK);
}
+
+// Fills the luma with a static text like pattern and the chroma with gray.
+void FillStaticScreen(aom_image_t *img) {
+ for (unsigned int y = 0; y < img->d_h; ++y) {
+ uint8_t *row = img->planes[0] + y * img->stride[0];
+ for (unsigned int x = 0; x < img->d_w; ++x) {
+ row[x] = ((x * 7 + y * 3) % 11 < 3 && ((x ^ y) & 4)) ? 32 : 224;
+ }
+ }
+ const unsigned int uv_w = (img->d_w + 1) >> 1;
+ const unsigned int uv_h = (img->d_h + 1) >> 1;
+ for (int plane = 1; plane < 3; ++plane) {
+ for (unsigned int y = 0; y < uv_h; ++y) {
+ memset(img->planes[plane] + y * img->stride[plane], 128, uv_w);
+ }
+ }
+}
+
+// Encodes a static screen in realtime mode. In the second frame new luma in
+// the left half of the first superblock hides the color change of an 8x8
+// chroma area in its static right half from the superblock chroma check. The
+// block there keeps zero motion and the same luma, and its decoded chroma
+// must still follow the source. With hold_last the second frame does not
+// refresh LAST and a third frame repeats its source.
+void TestChromaOnlyChange(bool hold_last) {
+ constexpr int kWidth = 128;
+ constexpr int kHeight = 128;
+ // Chroma position and size of the area that changes color.
+ constexpr int kPatchX = 20;
+ constexpr int kPatchY = 8;
+ constexpr int kPatchSize = 8;
+ constexpr int kPatchU = 192;
+ aom_codec_iface_t *iface = aom_codec_av1_cx();
+ aom_codec_enc_cfg_t cfg;
+ ASSERT_EQ(aom_codec_enc_config_default(iface, &cfg, AOM_USAGE_REALTIME),
+ AOM_CODEC_OK);
+ cfg.g_w = kWidth;
+ cfg.g_h = kHeight;
+ cfg.g_lag_in_frames = 0;
+ cfg.g_threads = 1;
+ cfg.rc_min_quantizer = 20;
+ cfg.rc_max_quantizer = 20;
+
+ aom_codec_ctx_t enc;
+ ASSERT_EQ(aom_codec_enc_init(&enc, iface, &cfg, 0), AOM_CODEC_OK);
+ ASSERT_EQ(aom_codec_control(&enc, AOME_SET_CPUUSED, 11), AOM_CODEC_OK);
+ ASSERT_EQ(aom_codec_control(&enc, AV1E_SET_TUNE_CONTENT, AOM_CONTENT_SCREEN),
+ AOM_CODEC_OK);
+ // Decode to 8 bit buffers even when FORCE_HIGHBITDEPTH_DECODING is on.
+ aom_codec_dec_cfg_t dec_cfg = {};
+ dec_cfg.allow_lowbitdepth = 1;
+ aom_codec_ctx_t dec;
+ ASSERT_EQ(aom_codec_dec_init(&dec, aom_codec_av1_dx(), &dec_cfg, 0),
+ AOM_CODEC_OK);
+
+ aom_image_t *img =
+ aom_img_alloc(nullptr, AOM_IMG_FMT_I420, kWidth, kHeight, 1);
+ ASSERT_NE(img, nullptr);
+ FillStaticScreen(img);
+ ::libaom_test::ACMRandom rnd(::libaom_test::ACMRandom::DeterministicSeed());
+ const int num_frames = hold_last ? 3 : 2;
+ for (int frame = 0; frame < num_frames; ++frame) {
+ if (frame == 1) {
+ for (int y = 0; y < 64; ++y) {
+ for (int x = 0; x < 32; ++x) {
+ img->planes[0][y * img->stride[0] + x] = rnd.Rand8();
+ }
+ }
+ for (int y = kPatchY; y < kPatchY + kPatchSize; ++y) {
+ memset(img->planes[1] + y * img->stride[1] + kPatchX, kPatchU,
+ kPatchSize);
+ }
+ }
+ if (hold_last) {
+ aom_svc_ref_frame_config_t ref_frame_config = {};
+ ref_frame_config.reference[0] = 1;
+ ref_frame_config.refresh[0] = frame != 1;
+ ASSERT_EQ(aom_codec_control(&enc, AV1E_SET_SVC_REF_FRAME_CONFIG,
+ &ref_frame_config),
+ AOM_CODEC_OK);
+ }
+ ASSERT_EQ(aom_codec_encode(&enc, img, frame, 1, 0), AOM_CODEC_OK);
+ aom_codec_iter_t iter = nullptr;
+ while (const aom_codec_cx_pkt_t *pkt = aom_codec_get_cx_data(&enc, &iter)) {
+ if (pkt->kind != AOM_CODEC_CX_FRAME_PKT) continue;
+ ASSERT_EQ(aom_codec_decode(
+ &dec, static_cast<const uint8_t *>(pkt->data.frame.buf),
+ pkt->data.frame.sz, nullptr),
+ AOM_CODEC_OK);
+ aom_codec_iter_t dec_iter = nullptr;
+ const aom_image_t *decoded = aom_codec_get_frame(&dec, &dec_iter);
+ ASSERT_NE(decoded, nullptr);
+ if (frame == 0) continue;
+ int sse = 0;
+ for (int y = kPatchY; y < kPatchY + kPatchSize; ++y) {
+ const uint8_t *row = decoded->planes[1] + y * decoded->stride[1];
+ for (int x = kPatchX; x < kPatchX + kPatchSize; ++x) {
+ const int diff = row[x] - kPatchU;
+ sse += diff * diff;
+ }
+ }
+ // 30 dB or better. The old color gives about 12 dB.
+ EXPECT_LT(sse, 65 * kPatchSize * kPatchSize);
+ }
+ }
+
+ aom_img_free(img);
+ ASSERT_EQ(aom_codec_destroy(&dec), AOM_CODEC_OK);
+ ASSERT_EQ(aom_codec_destroy(&enc), AOM_CODEC_OK);
+}
+
+TEST(EncodeAPI, ChromaOnlyChangeRealtime) { TestChromaOnlyChange(false); }
+
+TEST(EncodeAPI, ChromaOnlyChangeHoldLastRealtime) {
+ TestChromaOnlyChange(true);
+}
#endif // CONFIG_AV1_DECODER
#if !CONFIG_REALTIME_ONLY