xref: /aosp_15_r20/external/libaom/test/active_map_test.cc (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker  *
4*77c1e3ccSAndroid Build Coastguard Worker  * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker  * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker  * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker  */
11*77c1e3ccSAndroid Build Coastguard Worker 
12*77c1e3ccSAndroid Build Coastguard Worker #include <climits>
13*77c1e3ccSAndroid Build Coastguard Worker #include <vector>
14*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
15*77c1e3ccSAndroid Build Coastguard Worker #include "test/codec_factory.h"
16*77c1e3ccSAndroid Build Coastguard Worker #include "test/encode_test_driver.h"
17*77c1e3ccSAndroid Build Coastguard Worker #include "test/i420_video_source.h"
18*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
19*77c1e3ccSAndroid Build Coastguard Worker 
20*77c1e3ccSAndroid Build Coastguard Worker namespace {
21*77c1e3ccSAndroid Build Coastguard Worker 
22*77c1e3ccSAndroid Build Coastguard Worker // Params: test mode, speed, aq_mode and screen_content mode.
23*77c1e3ccSAndroid Build Coastguard Worker class ActiveMapTest
24*77c1e3ccSAndroid Build Coastguard Worker     : public ::libaom_test::CodecTestWith4Params<libaom_test::TestMode, int,
25*77c1e3ccSAndroid Build Coastguard Worker                                                  int, int>,
26*77c1e3ccSAndroid Build Coastguard Worker       public ::libaom_test::EncoderTest {
27*77c1e3ccSAndroid Build Coastguard Worker  protected:
28*77c1e3ccSAndroid Build Coastguard Worker   static const int kWidth = 208;
29*77c1e3ccSAndroid Build Coastguard Worker   static const int kHeight = 144;
30*77c1e3ccSAndroid Build Coastguard Worker 
ActiveMapTest()31*77c1e3ccSAndroid Build Coastguard Worker   ActiveMapTest() : EncoderTest(GET_PARAM(0)) {}
32*77c1e3ccSAndroid Build Coastguard Worker   ~ActiveMapTest() override = default;
33*77c1e3ccSAndroid Build Coastguard Worker 
SetUp()34*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override {
35*77c1e3ccSAndroid Build Coastguard Worker     InitializeConfig(GET_PARAM(1));
36*77c1e3ccSAndroid Build Coastguard Worker     cpu_used_ = GET_PARAM(2);
37*77c1e3ccSAndroid Build Coastguard Worker     aq_mode_ = GET_PARAM(3);
38*77c1e3ccSAndroid Build Coastguard Worker     screen_mode_ = GET_PARAM(4);
39*77c1e3ccSAndroid Build Coastguard Worker   }
40*77c1e3ccSAndroid Build Coastguard Worker 
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)41*77c1e3ccSAndroid Build Coastguard Worker   void PreEncodeFrameHook(::libaom_test::VideoSource *video,
42*77c1e3ccSAndroid Build Coastguard Worker                           ::libaom_test::Encoder *encoder) override {
43*77c1e3ccSAndroid Build Coastguard Worker     if (video->frame() == 0) {
44*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AOME_SET_CPUUSED, cpu_used_);
45*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AV1E_SET_ALLOW_WARPED_MOTION, 0);
46*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AV1E_SET_ENABLE_GLOBAL_MOTION, 0);
47*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AV1E_SET_ENABLE_OBMC, 0);
48*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AV1E_SET_AQ_MODE, aq_mode_);
49*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AV1E_SET_TUNE_CONTENT, screen_mode_);
50*77c1e3ccSAndroid Build Coastguard Worker       if (screen_mode_) encoder->Control(AV1E_SET_ENABLE_PALETTE, 1);
51*77c1e3ccSAndroid Build Coastguard Worker     } else if (video->frame() == 3) {
52*77c1e3ccSAndroid Build Coastguard Worker       aom_active_map_t map = aom_active_map_t();
53*77c1e3ccSAndroid Build Coastguard Worker       /* clang-format off */
54*77c1e3ccSAndroid Build Coastguard Worker       uint8_t active_map[9 * 13] = {
55*77c1e3ccSAndroid Build Coastguard Worker         1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
56*77c1e3ccSAndroid Build Coastguard Worker         1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
57*77c1e3ccSAndroid Build Coastguard Worker         1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
58*77c1e3ccSAndroid Build Coastguard Worker         1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
59*77c1e3ccSAndroid Build Coastguard Worker         0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1,
60*77c1e3ccSAndroid Build Coastguard Worker         0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1,
61*77c1e3ccSAndroid Build Coastguard Worker         0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1,
62*77c1e3ccSAndroid Build Coastguard Worker         0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1,
63*77c1e3ccSAndroid Build Coastguard Worker         1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0,
64*77c1e3ccSAndroid Build Coastguard Worker       };
65*77c1e3ccSAndroid Build Coastguard Worker       /* clang-format on */
66*77c1e3ccSAndroid Build Coastguard Worker       map.cols = (kWidth + 15) / 16;
67*77c1e3ccSAndroid Build Coastguard Worker       map.rows = (kHeight + 15) / 16;
68*77c1e3ccSAndroid Build Coastguard Worker       ASSERT_EQ(map.cols, 13u);
69*77c1e3ccSAndroid Build Coastguard Worker       ASSERT_EQ(map.rows, 9u);
70*77c1e3ccSAndroid Build Coastguard Worker       map.active_map = active_map;
71*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AOME_SET_ACTIVEMAP, &map);
72*77c1e3ccSAndroid Build Coastguard Worker     } else if (video->frame() == 15) {
73*77c1e3ccSAndroid Build Coastguard Worker       aom_active_map_t map = aom_active_map_t();
74*77c1e3ccSAndroid Build Coastguard Worker       map.cols = (kWidth + 15) / 16;
75*77c1e3ccSAndroid Build Coastguard Worker       map.rows = (kHeight + 15) / 16;
76*77c1e3ccSAndroid Build Coastguard Worker       map.active_map = nullptr;
77*77c1e3ccSAndroid Build Coastguard Worker       encoder->Control(AOME_SET_ACTIVEMAP, &map);
78*77c1e3ccSAndroid Build Coastguard Worker     }
79*77c1e3ccSAndroid Build Coastguard Worker   }
80*77c1e3ccSAndroid Build Coastguard Worker 
DoTest()81*77c1e3ccSAndroid Build Coastguard Worker   void DoTest() {
82*77c1e3ccSAndroid Build Coastguard Worker     // Validate that this non multiple of 64 wide clip encodes
83*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_lag_in_frames = 0;
84*77c1e3ccSAndroid Build Coastguard Worker     cfg_.rc_target_bitrate = 400;
85*77c1e3ccSAndroid Build Coastguard Worker     cfg_.rc_resize_mode = 0;
86*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_pass = AOM_RC_ONE_PASS;
87*77c1e3ccSAndroid Build Coastguard Worker     cfg_.rc_end_usage = AOM_CBR;
88*77c1e3ccSAndroid Build Coastguard Worker     cfg_.kf_max_dist = 90000;
89*77c1e3ccSAndroid Build Coastguard Worker     ::libaom_test::I420VideoSource video("hantro_odd.yuv", kWidth, kHeight, 100,
90*77c1e3ccSAndroid Build Coastguard Worker                                          1, 0, 100);
91*77c1e3ccSAndroid Build Coastguard Worker 
92*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
93*77c1e3ccSAndroid Build Coastguard Worker   }
94*77c1e3ccSAndroid Build Coastguard Worker 
95*77c1e3ccSAndroid Build Coastguard Worker   int cpu_used_;
96*77c1e3ccSAndroid Build Coastguard Worker   int aq_mode_;
97*77c1e3ccSAndroid Build Coastguard Worker   int screen_mode_;
98*77c1e3ccSAndroid Build Coastguard Worker };
99*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(ActiveMapTest,Test)100*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ActiveMapTest, Test) { DoTest(); }
101*77c1e3ccSAndroid Build Coastguard Worker 
102*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(ActiveMapTest,
103*77c1e3ccSAndroid Build Coastguard Worker                            ::testing::Values(::libaom_test::kRealTime),
104*77c1e3ccSAndroid Build Coastguard Worker                            ::testing::Range(5, 12), ::testing::Values(0, 3),
105*77c1e3ccSAndroid Build Coastguard Worker                            ::testing::Values(0, 1));
106*77c1e3ccSAndroid Build Coastguard Worker 
107*77c1e3ccSAndroid Build Coastguard Worker }  // namespace
108