Commit 56eddbccad for aom
commit 56eddbccadaa5472915c6176ecdd988f87305b23
Author: Yuan Tong <tongyuan200097@gmail.com>
Date: Tue Oct 20 20:36:58 2026 +0800
Check the frame buffer type instead of the bit depth
AOM can encode 8-bit video with high bitdepth frame buffers via
AOM_CODEC_USE_HIGHBITDEPTH. Several places chose low bitdepth functions
when the bit depth was 8, and so accessed these buffers as low bitdepth
ones:
- av1_int_pro_motion_estimation() ran the low bitdepth projection
functions.
- av1_nonrd_pick_inter_mode_sb() reused inter predictions, built into a
low bitdepth buffer.
- av1_realloc_and_scale_if_required() and av1_scale_references() used
the optimized low bitdepth scaler.
- av1_rc_scene_detection_onepass_rt() ran estimate_scroll_motion(),
which uses the low bitdepth projection functions.
Check the frame buffer type in these places instead.
Tested: test_libaom --gtest_filter=EncodeAPI.*8BitHighbdBuffers
Change-Id: Ifbc0f7bb274201f2bd30df34bd9a8becbc4f9af2
diff --git a/av1/common/resize.c b/av1/common/resize.c
index 57a89c5f00..3e5d094328 100644
--- a/av1/common/resize.c
+++ b/av1/common/resize.c
@@ -1240,7 +1240,7 @@ YV12_BUFFER_CONFIG *av1_realloc_and_scale_if_required(
#if CONFIG_AV1_HIGHBITDEPTH
if (use_optimized_scaler && has_optimized_scaler &&
- cm->seq_params->bit_depth == AOM_BITS_8) {
+ !(unscaled->flags & YV12_FLAG_HIGHBITDEPTH)) {
av1_resize_and_extend_frame(unscaled, scaled, filter, phase, num_planes);
} else {
if (!av1_resize_and_extend_frame_nonnormative(
diff --git a/av1/encoder/encoder_utils.c b/av1/encoder/encoder_utils.c
index b3cccb30f7..efbdb329d7 100644
--- a/av1/encoder/encoder_utils.c
+++ b/av1/encoder/encoder_utils.c
@@ -941,7 +941,7 @@ void av1_scale_references(AV1_COMP *cpi, const InterpFilter filter,
}
#if CONFIG_AV1_HIGHBITDEPTH
if (use_optimized_scaler && has_optimized_scaler &&
- cm->seq_params->bit_depth == AOM_BITS_8) {
+ !(ref->flags & YV12_FLAG_HIGHBITDEPTH)) {
av1_resize_and_extend_frame(ref, &new_fb->buf, filter, phase,
num_planes);
} else if (!av1_resize_and_extend_frame_nonnormative(
diff --git a/av1/encoder/mcomp.c b/av1/encoder/mcomp.c
index 52b26127a4..d9326dd2d0 100644
--- a/av1/encoder/mcomp.c
+++ b/av1/encoder/mcomp.c
@@ -2198,7 +2198,7 @@ unsigned int av1_int_pro_motion_estimation(
}
const int ref_stride = xd->plane[0].pre[0].stride;
- if (xd->bd != 8) {
+ if (is_cur_buf_hbd(xd)) {
best_int_mv->as_fullmv = kZeroFullMv;
best_sad = cpi->ppi->fn_ptr[bsize].sdf(x->plane[0].src.buf, src_stride,
xd->plane[0].pre[0].buf, ref_stride);
diff --git a/av1/encoder/nonrd_pickmode.c b/av1/encoder/nonrd_pickmode.c
index c33ca8d950..cdc252e635 100644
--- a/av1/encoder/nonrd_pickmode.c
+++ b/av1/encoder/nonrd_pickmode.c
@@ -3711,7 +3711,7 @@ void av1_nonrd_pick_inter_mode_sb(AV1_COMP *cpi, TileDataEnc *tile_data,
DECLARE_ALIGNED(16, uint8_t, pred_buf[MAX_MB_PLANE * MAX_SB_SQUARE]);
PRED_BUFFER *this_mode_pred = NULL;
const int reuse_inter_pred =
- rt_sf->reuse_inter_pred_nonrd && cm->seq_params->bit_depth == AOM_BITS_8;
+ rt_sf->reuse_inter_pred_nonrd && !is_cur_buf_hbd(xd);
InterModeSearchStateNonrd search_state;
av1_zero(search_state.use_ref_frame_mask);
av1_zero(search_state.use_scaled_ref_frame);
diff --git a/av1/encoder/partition_search.c b/av1/encoder/partition_search.c
index c635137895..23444a4c85 100644
--- a/av1/encoder/partition_search.c
+++ b/av1/encoder/partition_search.c
@@ -482,7 +482,7 @@ static void encode_superblock(const AV1_COMP *const cpi, TileDataEnc *tile_data,
// segment blocks are picked without building a prediction.
const int start_plane =
(x->reuse_inter_pred && (!cpi->sf.rt_sf.nonrd_check_partition_split) &&
- !seg_skip && cm->seq_params->bit_depth == AOM_BITS_8)
+ !seg_skip && !is_cur_buf_hbd(xd))
? 1
: 0;
if (!is_prediction_copied(x, mbmi, seg_skip)) {
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c
index 2429263f2b..18912abf0a 100644
--- a/av1/encoder/ratectrl.c
+++ b/av1/encoder/ratectrl.c
@@ -3483,8 +3483,8 @@ void av1_rc_scene_detection_onepass_rt(AV1_COMP *cpi,
// Compute fast coarse/global motion for 128x128 superblock centered
// at middle of frame, and one to the upper left and one to lower right.
// to determine if motion is scroll. Only test 3 points (pts) for now.
- // TODO(marpan): Only allow for 8 bit-depth for now.
- if (cm->seq_params->bit_depth == 8) {
+ // TODO(marpan): Only allow for low bitdepth frame buffers for now.
+ if (!cm->seq_params->use_highbitdepth) {
int sw_row = (cpi->rc.frame_source_sad > 20000) ? 512 : 192;
int sw_col = (cpi->rc.frame_source_sad > 20000) ? 512 : 160;
if (cm->width * cm->height >= 3840 * 2160 &&
diff --git a/test/encode_api_test.cc b/test/encode_api_test.cc
index 85a055c64a..a6a26f55b6 100644
--- a/test/encode_api_test.cc
+++ b/test/encode_api_test.cc
@@ -883,6 +883,92 @@ TEST(EncodeAPI, NonrdPickModeLargeTxSizeVariance) {
}
#endif // CONFIG_AV1_HIGHBITDEPTH
+#if CONFIG_AV1_HIGHBITDEPTH
+// Encodes frames of random 8-bit noise with the realtime encoder at 8-bit
+// depth, using high bitdepth frame buffers. If |halve_size_at_frame| is
+// positive, the frame size is halved from that frame on.
+void Encode8BitNoiseHighbdBuffers(unsigned int width, unsigned int height,
+ int speed, aom_tune_content content,
+ int frames, int halve_size_at_frame = 0) {
+ 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 = width;
+ cfg.g_h = height;
+ cfg.g_forced_max_frame_width = width;
+ cfg.g_forced_max_frame_height = height;
+ cfg.g_lag_in_frames = 0;
+ cfg.rc_end_usage = AOM_CBR;
+
+ aom_codec_ctx_t enc;
+ ASSERT_EQ(aom_codec_enc_init(&enc, iface, &cfg, AOM_CODEC_USE_HIGHBITDEPTH),
+ AOM_CODEC_OK);
+ ASSERT_EQ(aom_codec_control(&enc, AOME_SET_CPUUSED, speed), AOM_CODEC_OK);
+ ASSERT_EQ(aom_codec_control(&enc, AV1E_SET_TUNE_CONTENT, content),
+ AOM_CODEC_OK);
+
+ aom_image_t *image =
+ aom_img_alloc(nullptr, AOM_IMG_FMT_I42016, width, height, 1);
+ ASSERT_NE(image, nullptr);
+ const unsigned int uv_h = (height + 1) / 2;
+ const unsigned int uv_w = (width + 1) / 2;
+ for (unsigned int i = 0; i < uv_h; ++i) {
+ Memset16(image->planes[1] + i * image->stride[1], 128, uv_w);
+ Memset16(image->planes[2] + i * image->stride[2], 128, uv_w);
+ }
+
+ ::libaom_test::ACMRandom rnd;
+ rnd.Reset(::libaom_test::ACMRandom::DeterministicSeed());
+ for (int frame = 0; frame < frames; ++frame) {
+ if (halve_size_at_frame > 0 && frame == halve_size_at_frame) {
+ cfg.g_w = width / 2;
+ cfg.g_h = height / 2;
+ ASSERT_EQ(aom_codec_enc_config_set(&enc, &cfg), AOM_CODEC_OK);
+ image->d_w = cfg.g_w;
+ image->d_h = cfg.g_h;
+ }
+ for (unsigned int i = 0; i < image->d_h; ++i) {
+ uint16_t *row =
+ reinterpret_cast<uint16_t *>(image->planes[0] + i * image->stride[0]);
+ for (unsigned int j = 0; j < image->d_w; ++j) row[j] = rnd.Rand8();
+ }
+ ASSERT_EQ(aom_codec_encode(&enc, image, frame, 1, 0), AOM_CODEC_OK);
+ }
+ ASSERT_EQ(aom_codec_encode(&enc, nullptr, 0, 0, 0), AOM_CODEC_OK);
+
+ aom_img_free(image);
+ ASSERT_EQ(aom_codec_destroy(&enc), AOM_CODEC_OK);
+}
+
+// The following tests encode 8-bit video in high bitdepth frame buffers. Code
+// that chose low bitdepth functions by bit depth instead of by frame buffer
+// type used to access the high bitdepth buffers as low bitdepth ones.
+
+// av1_int_pro_motion_estimation(), called by search_new_mv() for GOLDEN_FRAME.
+TEST(EncodeAPI, IntProMotionEstimation8BitHighbdBuffers) {
+ Encode8BitNoiseHighbdBuffers(64, 64, 9, AOM_CONTENT_DEFAULT, 3);
+}
+
+// Prediction reuse in av1_nonrd_pick_inter_mode_sb(), which is enabled for
+// screen content.
+TEST(EncodeAPI, ReuseInterPred8BitHighbdBuffers) {
+ Encode8BitNoiseHighbdBuffers(64, 64, 9, AOM_CONTENT_SCREEN, 2);
+}
+
+// The optimized scaler, used to scale the source and the references.
+TEST(EncodeAPI, OptimizedScaler8BitHighbdBuffers) {
+ Encode8BitNoiseHighbdBuffers(128, 128, 7, AOM_CONTENT_DEFAULT, 3,
+ /*halve_size_at_frame=*/2);
+}
+
+// estimate_scroll_motion(), which is used for high motion screen content.
+// The estimation code only runs for input at least 720p large.
+TEST(EncodeAPI, ScrollMotionEstimation8BitHighbdBuffers) {
+ Encode8BitNoiseHighbdBuffers(1280, 720, 11, AOM_CONTENT_SCREEN, 16);
+}
+#endif // CONFIG_AV1_HIGHBITDEPTH
+
aom_image_t *CreateGrayImage(aom_img_fmt_t fmt, unsigned int w,
unsigned int h) {
aom_image_t *const image = aom_img_alloc(nullptr, fmt, w, h, 1);