xref: /aosp_15_r20/external/libaom/test/motion_vector_test.cc (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1 /*
2  * Copyright (c) 2017, Alliance for Open Media. All rights reserved.
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #include <memory>
13 
14 #include "gtest/gtest.h"
15 
16 #include "test/codec_factory.h"
17 #include "test/encode_test_driver.h"
18 #include "test/util.h"
19 #include "test/yuv_video_source.h"
20 
21 namespace {
22 #define MAX_EXTREME_MV 1
23 #define MIN_EXTREME_MV 2
24 
25 // Encoding modes
26 const libaom_test::TestMode kEncodingModeVectors[] = {
27   ::libaom_test::kTwoPassGood,
28   ::libaom_test::kOnePassGood,
29 };
30 
31 // Encoding speeds
32 const int kCpuUsedVectors[] = { 1, 5 };
33 
34 // MV test modes: 1 - always use maximum MV; 2 - always use minimum MV.
35 const int kMVTestModes[] = { MAX_EXTREME_MV, MIN_EXTREME_MV };
36 
37 class MotionVectorTestLarge
38     : public ::libaom_test::CodecTestWith3Params<libaom_test::TestMode, int,
39                                                  int>,
40       public ::libaom_test::EncoderTest {
41  protected:
MotionVectorTestLarge()42   MotionVectorTestLarge()
43       : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
44         cpu_used_(GET_PARAM(2)), mv_test_mode_(GET_PARAM(3)) {}
45 
46   ~MotionVectorTestLarge() override = default;
47 
SetUp()48   void SetUp() override {
49     InitializeConfig(encoding_mode_);
50     if (encoding_mode_ != ::libaom_test::kRealTime) {
51       cfg_.g_lag_in_frames = 3;
52     } else {
53       cfg_.rc_buf_sz = 1000;
54       cfg_.rc_buf_initial_sz = 500;
55       cfg_.rc_buf_optimal_sz = 600;
56     }
57   }
58 
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)59   void PreEncodeFrameHook(::libaom_test::VideoSource *video,
60                           ::libaom_test::Encoder *encoder) override {
61     if (video->frame() == 0) {
62       encoder->Control(AOME_SET_CPUUSED, cpu_used_);
63       encoder->Control(AV1E_ENABLE_MOTION_VECTOR_UNIT_TEST, mv_test_mode_);
64       if (encoding_mode_ != ::libaom_test::kRealTime) {
65         encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
66         encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
67         encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
68       }
69     }
70   }
71 
72   libaom_test::TestMode encoding_mode_;
73   int cpu_used_;
74   int mv_test_mode_;
75 };
76 
TEST_P(MotionVectorTestLarge,OverallTest)77 TEST_P(MotionVectorTestLarge, OverallTest) {
78   int width = 3840;
79   int height = 2160;
80 
81   // Reduce the test clip's resolution while testing on 32-bit system.
82   if (sizeof(void *) == 4) {
83     width = 2048;
84     height = 360;
85   }
86 
87   cfg_.rc_target_bitrate = 24000;
88   cfg_.g_profile = 0;
89   init_flags_ = AOM_CODEC_USE_PSNR;
90 
91   std::unique_ptr<libaom_test::VideoSource> video;
92   video.reset(new libaom_test::YUVVideoSource(
93       "niklas_640_480_30.yuv", AOM_IMG_FMT_I420, width, height, 30, 1, 0, 3));
94 
95   ASSERT_NE(video, nullptr);
96   ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
97 }
98 
99 AV1_INSTANTIATE_TEST_SUITE(MotionVectorTestLarge,
100                            ::testing::ValuesIn(kEncodingModeVectors),
101                            ::testing::ValuesIn(kCpuUsedVectors),
102                            ::testing::ValuesIn(kMVTestModes));
103 }  // namespace
104