Commit c2833d08ba for aom
commit c2833d08ba174cd710742cb3ec623bfa47c8c01c
Author: Ihor Buhaiov <freedbrt@gmail.com>
Date: Mon Nov 16 12:10:50 2026 +0100
rtc: Keep the map with under 1% inactive blocks
av1_set_active_map() stores the share of inactive 16x16 blocks as an
integer percent, rounded down, and av1_apply_active_map() turns the
map off when it is 0. So a map with only a few inactive blocks, under
1% of the frame, is ignored for that frame and those blocks are coded
from the source. An app that sends its viewer only the active area
then leaves stale pixels there.
Round a share under 1% up to 1 when any block is inactive. The other
readers of the percent (the source SAD in rate control and cyclic
refresh) then treat such a map like one at 1%.
Screen recordings with tile maps, main and this change, 8 bit, 43
cases: 9 had decoded changes outside the active area, now none. Bytes
4:2:0 (27 cases) -2.17% to +0.08%, 4:4:4 (16 cases) -0.01% to +0.00%.
The worst 16x16 block got lower in one case, by 0.01 dB.
Encode time, release -O3, 1080p browser scroll capture, 60 frames, 1
thread, median of 7, base and change alternating:
map from frame differences, same streams:
Apple M3 Pro 4:2:0 +0.75% (A/A -0.10%), 4:4:4 +0.10% (A/A +0.22%)
Ryzen 5900X 4:2:0 -0.07% (A/A -0.03%), 4:4:4 -0.38% (A/A +0.08%)
only the top left 64x64 inactive (0.2%), so the map now applies:
Apple M3 Pro 4:2:0 +1.64%, 4:4:4 +2.91%
Ryzen 5900X 4:2:0 +3.03%, 4:4:4 +1.88%
bytes -0.00% (4:2:0), +0.00% (4:4:4)
Main coded these frames with the map off.
10 bit, screendata 1920x1080 and park_joy_90p, 4:2:0 and 4:4:4, 1
and 4 threads: maps from frame differences give the same streams. With
only the top left 64x64 inactive and noise in it, 86k to 159k inactive
pixels changed before and none now. No recon mismatch in any run.
Test: FewInactiveBlocksTest fails on main in a default and an RT only
build and passes with this change.
Change-Id: I404c32e330eb15107252de1f2b0a71c2d76c3634
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 2b151a5f1e..786c899bd9 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -257,8 +257,9 @@ int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows,
cpi->active_map.mi_rows = mi_rows;
cpi->active_map.mi_cols = mi_cols;
assert(num_samples);
- cpi->rc.percent_blocks_inactive =
- (num_blocks_inactive * 100) / num_samples;
+ // Round a share under 1% up, since 0 turns the map off.
+ cpi->rc.percent_blocks_inactive = AOMMAX(
+ (num_blocks_inactive * 100) / num_samples, num_blocks_inactive > 0);
}
return 0;
}
diff --git a/test/active_map_test.cc b/test/active_map_test.cc
index 32db7100ac..f89e9f6e16 100644
--- a/test/active_map_test.cc
+++ b/test/active_map_test.cc
@@ -665,6 +665,118 @@ AV1_INSTANTIATE_TEST_SUITE(
::testing::Range(7, 12), ::testing::Values(0, 3), ::testing::Values(1, 4),
::testing::Values(AOM_CONTENT_DEFAULT, AOM_CONTENT_SCREEN));
+constexpr int kFewWidth = 1024;
+constexpr int kFewHeight = 448;
+constexpr int kFewMapCols = kFewWidth / 16;
+constexpr int kFewMapRows = kFewHeight / 16;
+constexpr int kNoiseSize = 64;
+
+// A still gradient with new noise in the top left superblock on every frame.
+class CornerNoiseSource : public ::libaom_test::DummyVideoSource {
+ public:
+ CornerNoiseSource() {
+ SetSize(kFewWidth, kFewHeight);
+ set_limit(10);
+ }
+
+ protected:
+ void FillFrame() override {
+ memset(img_->img_data, 128, raw_sz_);
+ ::libaom_test::ACMRandom rnd(static_cast<int>(frame_) + 1);
+ for (int y = 0; y < kFewHeight; ++y) {
+ uint8_t *const row =
+ img_->planes[AOM_PLANE_Y] + y * img_->stride[AOM_PLANE_Y];
+ for (int x = 0; x < kFewWidth; ++x) {
+ row[x] = (x < kNoiseSize && y < kNoiseSize)
+ ? rnd.Rand8()
+ : static_cast<uint8_t>(x / 8 + y / 4);
+ }
+ }
+ }
+};
+
+// Marks only the noisy superblock inactive, 16 of the 1792 blocks, so under 1%
+// of the frame. Its pixels away from the active blocks must not change.
+// Params: test mode, speed, aq_mode and content type.
+class FewInactiveBlocksTest
+ : public ::libaom_test::CodecTestWith4Params<libaom_test::TestMode, int,
+ int, int>,
+ public ::libaom_test::EncoderTest {
+ protected:
+ static constexpr int kCheckSize = kNoiseSize - kEdgeMargin;
+
+ FewInactiveBlocksTest() : EncoderTest(GET_PARAM(0)) {}
+ ~FewInactiveBlocksTest() override = default;
+
+ void SetUp() override {
+ InitializeConfig(GET_PARAM(1));
+ cpu_used_ = GET_PARAM(2);
+ aq_mode_ = GET_PARAM(3);
+ content_ = GET_PARAM(4);
+ cfg_.g_lag_in_frames = 0;
+ cfg_.rc_target_bitrate = 1000;
+ cfg_.rc_end_usage = AOM_CBR;
+ cfg_.g_pass = AOM_RC_ONE_PASS;
+ cfg_.kf_max_dist = 90000;
+ }
+
+ void PreEncodeFrameHook(::libaom_test::VideoSource *video,
+ ::libaom_test::Encoder *encoder) override {
+ if (video->frame() == 0) {
+ encoder->Control(AOME_SET_CPUUSED, cpu_used_);
+ encoder->Control(AV1E_SET_AQ_MODE, aq_mode_);
+ encoder->Control(AV1E_SET_TUNE_CONTENT, content_);
+ return;
+ }
+ uint8_t map[kFewMapRows * kFewMapCols];
+ memset(map, 1, sizeof(map));
+ for (int r = 0; r < kNoiseSize / 16; ++r) {
+ memset(&map[r * kFewMapCols], 0, kNoiseSize / 16);
+ }
+ aom_active_map_t active_map = {};
+ active_map.rows = kFewMapRows;
+ active_map.cols = kFewMapCols;
+ active_map.active_map = map;
+ encoder->Control(AOME_SET_ACTIVEMAP, &active_map);
+ }
+
+ void DecompressedFrameHook(const aom_image_t &img,
+ aom_codec_pts_t pts) override {
+ const int frame = static_cast<int>(pts);
+ int changed = 0;
+ for (int plane = 0; plane < 3; ++plane) {
+ const int size = kCheckSize >> (plane ? 1 : 0);
+ std::vector<uint8_t> &prev = prev_[plane];
+ if (prev.empty()) prev.resize(size * size);
+ for (int y = 0; y < size; ++y) {
+ for (int x = 0; x < size; ++x) {
+ const uint8_t pixel =
+ static_cast<uint8_t>(GetPixel(img, plane, x, y));
+ changed += frame > 0 && pixel != prev[y * size + x];
+ prev[y * size + x] = pixel;
+ }
+ }
+ }
+ EXPECT_EQ(changed, 0) << "Inactive pixels changed in frame " << frame;
+ }
+
+ int cpu_used_;
+ int aq_mode_;
+ int content_;
+ std::vector<uint8_t> prev_[3];
+};
+
+TEST_P(FewInactiveBlocksTest, InactivePixelsKept) {
+ CornerNoiseSource video;
+ ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
+}
+
+AV1_INSTANTIATE_TEST_SUITE(FewInactiveBlocksTest,
+ ::testing::Values(::libaom_test::kRealTime),
+ ::testing::Range(7, 12), ::testing::Values(0, 3),
+ ::testing::Values(AOM_CONTENT_DEFAULT,
+ AOM_CONTENT_SCREEN));
+
constexpr int kSmallFrame = 10;
// Puts new noise in every luma pixel of every frame. From frame kSmallFrame on