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 "config/aom_config.h"
13*77c1e3ccSAndroid Build Coastguard Worker
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 const libaom_test::TestMode kTestModeParams[] =
23*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_REALTIME_ONLY
24*77c1e3ccSAndroid Build Coastguard Worker { ::libaom_test::kRealTime };
25*77c1e3ccSAndroid Build Coastguard Worker #else
26*77c1e3ccSAndroid Build Coastguard Worker { ::libaom_test::kRealTime, ::libaom_test::kOnePassGood };
27*77c1e3ccSAndroid Build Coastguard Worker #endif
28*77c1e3ccSAndroid Build Coastguard Worker
29*77c1e3ccSAndroid Build Coastguard Worker class AqSegmentTest
30*77c1e3ccSAndroid Build Coastguard Worker : public ::libaom_test::CodecTestWith3Params<libaom_test::TestMode, int,
31*77c1e3ccSAndroid Build Coastguard Worker int>,
32*77c1e3ccSAndroid Build Coastguard Worker public ::libaom_test::EncoderTest {
33*77c1e3ccSAndroid Build Coastguard Worker protected:
AqSegmentTest()34*77c1e3ccSAndroid Build Coastguard Worker AqSegmentTest() : EncoderTest(GET_PARAM(0)) {}
35*77c1e3ccSAndroid Build Coastguard Worker ~AqSegmentTest() override = default;
36*77c1e3ccSAndroid Build Coastguard Worker
SetUp()37*77c1e3ccSAndroid Build Coastguard Worker void SetUp() override {
38*77c1e3ccSAndroid Build Coastguard Worker InitializeConfig(GET_PARAM(1));
39*77c1e3ccSAndroid Build Coastguard Worker set_cpu_used_ = GET_PARAM(2);
40*77c1e3ccSAndroid Build Coastguard Worker aq_mode_ = 0;
41*77c1e3ccSAndroid Build Coastguard Worker }
42*77c1e3ccSAndroid Build Coastguard Worker
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)43*77c1e3ccSAndroid Build Coastguard Worker void PreEncodeFrameHook(::libaom_test::VideoSource *video,
44*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Encoder *encoder) override {
45*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() == 0) {
46*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
47*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_AQ_MODE, aq_mode_);
48*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_DELTAQ_MODE, deltaq_mode_);
49*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_MAX_INTRA_BITRATE_PCT, 100);
50*77c1e3ccSAndroid Build Coastguard Worker if (mode_ == ::libaom_test::kRealTime) {
51*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_ALLOW_WARPED_MOTION, 0);
52*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_ENABLE_GLOBAL_MOTION, 0);
53*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_ENABLE_OBMC, 0);
54*77c1e3ccSAndroid Build Coastguard Worker }
55*77c1e3ccSAndroid Build Coastguard Worker }
56*77c1e3ccSAndroid Build Coastguard Worker }
57*77c1e3ccSAndroid Build Coastguard Worker
DoTest(int aq_mode)58*77c1e3ccSAndroid Build Coastguard Worker void DoTest(int aq_mode) {
59*77c1e3ccSAndroid Build Coastguard Worker aq_mode_ = aq_mode;
60*77c1e3ccSAndroid Build Coastguard Worker deltaq_mode_ = 0;
61*77c1e3ccSAndroid Build Coastguard Worker cfg_.kf_max_dist = 12;
62*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_min_quantizer = 8;
63*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_max_quantizer = 56;
64*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_end_usage = AOM_CBR;
65*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_lag_in_frames = 6;
66*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_initial_sz = 500;
67*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_optimal_sz = 500;
68*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_sz = 1000;
69*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 300;
70*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
71*77c1e3ccSAndroid Build Coastguard Worker 288, 30, 1, 0, 15);
72*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
73*77c1e3ccSAndroid Build Coastguard Worker }
74*77c1e3ccSAndroid Build Coastguard Worker
75*77c1e3ccSAndroid Build Coastguard Worker int set_cpu_used_;
76*77c1e3ccSAndroid Build Coastguard Worker int aq_mode_;
77*77c1e3ccSAndroid Build Coastguard Worker int deltaq_mode_;
78*77c1e3ccSAndroid Build Coastguard Worker };
79*77c1e3ccSAndroid Build Coastguard Worker
80*77c1e3ccSAndroid Build Coastguard Worker // Validate that this AQ segmentation mode (1-variance_aq, 2-complexity_aq,
81*77c1e3ccSAndroid Build Coastguard Worker // 3-cyclic_refresh_aq) encodes and decodes without a mismatch.
TEST_P(AqSegmentTest,TestNoMisMatch)82*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AqSegmentTest, TestNoMisMatch) { DoTest(GET_PARAM(3)); }
83*77c1e3ccSAndroid Build Coastguard Worker
84*77c1e3ccSAndroid Build Coastguard Worker #if !CONFIG_REALTIME_ONLY
85*77c1e3ccSAndroid Build Coastguard Worker // Validate that this delta q mode
86*77c1e3ccSAndroid Build Coastguard Worker // encodes and decodes without a mismatch.
TEST_P(AqSegmentTest,TestNoMisMatchExtDeltaQ)87*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AqSegmentTest, TestNoMisMatchExtDeltaQ) {
88*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_end_usage = AOM_CQ;
89*77c1e3ccSAndroid Build Coastguard Worker aq_mode_ = 0;
90*77c1e3ccSAndroid Build Coastguard Worker deltaq_mode_ = 2;
91*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
92*77c1e3ccSAndroid Build Coastguard Worker 30, 1, 0, 15);
93*77c1e3ccSAndroid Build Coastguard Worker
94*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
95*77c1e3ccSAndroid Build Coastguard Worker }
96*77c1e3ccSAndroid Build Coastguard Worker #endif
97*77c1e3ccSAndroid Build Coastguard Worker
98*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(AqSegmentTest, ::testing::ValuesIn(kTestModeParams),
99*77c1e3ccSAndroid Build Coastguard Worker ::testing::Range(5, 9), ::testing::Range(0, 4));
100*77c1e3ccSAndroid Build Coastguard Worker
101*77c1e3ccSAndroid Build Coastguard Worker #if !CONFIG_REALTIME_ONLY
102*77c1e3ccSAndroid Build Coastguard Worker class AqSegmentTestLarge : public AqSegmentTest {};
103*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(AqSegmentTestLarge,TestNoMisMatch)104*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AqSegmentTestLarge, TestNoMisMatch) { DoTest(GET_PARAM(3)); }
105*77c1e3ccSAndroid Build Coastguard Worker
106*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(AqSegmentTestLarge,
107*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(::libaom_test::kOnePassGood),
108*77c1e3ccSAndroid Build Coastguard Worker ::testing::Range(3, 5), ::testing::Range(0, 4));
109*77c1e3ccSAndroid Build Coastguard Worker #endif
110*77c1e3ccSAndroid Build Coastguard Worker } // namespace
111