• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2019, 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 #include <ostream>
14 #include <string>
15 #include <unordered_map>
16 
17 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
18 
19 #include "test/codec_factory.h"
20 #include "test/encode_test_driver.h"
21 #include "test/util.h"
22 #include "test/y4m_video_source.h"
23 #include "test/yuv_video_source.h"
24 
25 namespace {
26 
27 const unsigned int kFrames = 10;
28 const int kBitrate = 500;
29 
30 // List of psnr thresholds for speed settings 6-8
31 // keys: video, speed, aq mode.
32 std::unordered_map<std::string,
33                    std::unordered_map<int, std::unordered_map<int, double>>>
34     kPsnrThreshold = { { "park_joy_90p_8_420.y4m",
35                          { { 5, { { 0, 35.4 }, { 3, 36.3 } } },
36                            { 6, { { 0, 35.3 }, { 3, 36.2 } } },
37                            { 7, { { 0, 34.9 }, { 3, 35.8 } } },
38                            { 8, { { 0, 35.0 }, { 3, 35.8 } } },
39                            { 9, { { 0, 34.9 }, { 3, 35.5 } } },
40                            { 10, { { 0, 34.7 }, { 3, 35.3 } } } } },
41                        { "paris_352_288_30.y4m",
42                          { { 5, { { 0, 36.2 }, { 3, 36.7 } } },
43                            { 6, { { 0, 36.1 }, { 3, 36.48 } } },
44                            { 7, { { 0, 35.5 }, { 3, 36.0 } } },
45                            { 8, { { 0, 35.8 }, { 3, 36.48 } } },
46                            { 9, { { 0, 35.5 }, { 3, 36.0 } } },
47                            { 10, { { 0, 35.3 }, { 3, 35.9 } } } } },
48                        { "niklas_1280_720_30.y4m",
49                          { { 5, { { 0, 34.4 }, { 3, 34.30 } } },
50                            { 6, { { 0, 34.2 }, { 3, 34.2 } } },
51                            { 7, { { 0, 33.5 }, { 3, 33.48 } } },
52                            { 8, { { 0, 33.48 }, { 3, 33.48 } } },
53                            { 9, { { 0, 33.4 }, { 3, 33.4 } } },
54                            { 10, { { 0, 33.2 }, { 3, 33.2 } } } } },
55                        { "hantro_collage_w352h288_nv12.yuv",
56                          { { 5, { { 0, 34.4 }, { 3, 34.30 } } },
57                            { 6, { { 0, 34.2 }, { 3, 34.2 } } },
58                            { 7, { { 0, 33.6 }, { 3, 33.6 } } },
59                            { 8, { { 0, 33.48 }, { 3, 33.48 } } },
60                            { 9, { { 0, 33.4 }, { 3, 33.4 } } },
61                            { 10, { { 0, 33.2 }, { 3, 33.2 } } } } } };
62 
63 typedef struct {
64   const char *filename;
65   unsigned int input_bit_depth;
66   aom_img_fmt fmt;
67   aom_bit_depth_t bit_depth;
68   unsigned int profile;
69 } TestVideoParam;
70 
operator <<(std::ostream & os,const TestVideoParam & test_arg)71 std::ostream &operator<<(std::ostream &os, const TestVideoParam &test_arg) {
72   return os << "TestVideoParam { filename:" << test_arg.filename
73             << " input_bit_depth:" << test_arg.input_bit_depth
74             << " fmt:" << test_arg.fmt << " bit_depth:" << test_arg.bit_depth
75             << " profile:" << test_arg.profile << " }";
76 }
77 
78 const TestVideoParam kTestVectors[] = {
79   { "park_joy_90p_8_420.y4m", 8, AOM_IMG_FMT_I420, AOM_BITS_8, 0 },
80   { "paris_352_288_30.y4m", 8, AOM_IMG_FMT_I420, AOM_BITS_8, 0 },
81   { "niklas_1280_720_30.y4m", 8, AOM_IMG_FMT_I420, AOM_BITS_8, 0 },
82   { "hantro_collage_w352h288_nv12.yuv", 8, AOM_IMG_FMT_NV12, AOM_BITS_8, 0 },
83 };
84 
85 // Params: test video, speed, aq mode, threads, tile columns.
86 class RTEndToEndTest
87     : public ::libaom_test::CodecTestWith5Params<TestVideoParam, int,
88                                                  unsigned int, int, int>,
89       public ::libaom_test::EncoderTest {
90  protected:
RTEndToEndTest()91   RTEndToEndTest()
92       : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(1)),
93         cpu_used_(GET_PARAM(2)), psnr_(0.0), nframes_(0),
94         aq_mode_(GET_PARAM(3)), threads_(GET_PARAM(4)),
95         tile_columns_(GET_PARAM(5)) {}
96 
~RTEndToEndTest()97   virtual ~RTEndToEndTest() {}
98 
SetUp()99   virtual void SetUp() {
100     InitializeConfig(::libaom_test::kRealTime);
101 
102     cfg_.g_threads = threads_;
103     cfg_.rc_buf_sz = 1000;
104     cfg_.rc_buf_initial_sz = 500;
105     cfg_.rc_buf_optimal_sz = 600;
106     cfg_.kf_max_dist = 9999;
107     cfg_.kf_min_dist = 9999;
108   }
109 
BeginPassHook(unsigned int)110   virtual void BeginPassHook(unsigned int) {
111     psnr_ = 0.0;
112     nframes_ = 0;
113   }
114 
PSNRPktHook(const aom_codec_cx_pkt_t * pkt)115   virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) {
116     psnr_ += pkt->data.psnr.psnr[0];
117     nframes_++;
118   }
119 
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)120   virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
121                                   ::libaom_test::Encoder *encoder) {
122     if (video->frame() == 0) {
123       encoder->Control(AV1E_SET_ENABLE_RESTORATION, 0);
124       encoder->Control(AV1E_SET_ENABLE_OBMC, 0);
125       encoder->Control(AV1E_SET_ENABLE_GLOBAL_MOTION, 0);
126       encoder->Control(AV1E_SET_ENABLE_WARPED_MOTION, 0);
127       encoder->Control(AV1E_SET_DELTAQ_MODE, 0);
128       encoder->Control(AV1E_SET_ENABLE_TPL_MODEL, 0);
129       encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
130       encoder->Control(AV1E_SET_TILE_COLUMNS, tile_columns_);
131       encoder->Control(AOME_SET_CPUUSED, cpu_used_);
132       encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_DEFAULT);
133       encoder->Control(AV1E_SET_AQ_MODE, aq_mode_);
134       encoder->Control(AV1E_SET_ROW_MT, 1);
135       encoder->Control(AV1E_SET_ENABLE_CDEF, 1);
136       encoder->Control(AV1E_SET_COEFF_COST_UPD_FREQ, 2);
137       encoder->Control(AV1E_SET_MODE_COST_UPD_FREQ, 2);
138       encoder->Control(AV1E_SET_MV_COST_UPD_FREQ, 2);
139       encoder->Control(AV1E_SET_DV_COST_UPD_FREQ, 2);
140     }
141   }
142 
GetAveragePsnr() const143   double GetAveragePsnr() const {
144     if (nframes_) return psnr_ / nframes_;
145     return 0.0;
146   }
147 
GetPsnrThreshold()148   double GetPsnrThreshold() {
149     return kPsnrThreshold[test_video_param_.filename][cpu_used_][aq_mode_];
150   }
151 
DoTest()152   void DoTest() {
153     cfg_.rc_target_bitrate = kBitrate;
154     cfg_.g_error_resilient = 0;
155     cfg_.g_profile = test_video_param_.profile;
156     cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
157     cfg_.g_bit_depth = test_video_param_.bit_depth;
158     init_flags_ = AOM_CODEC_USE_PSNR;
159     if (cfg_.g_bit_depth > 8) init_flags_ |= AOM_CODEC_USE_HIGHBITDEPTH;
160 
161     std::unique_ptr<libaom_test::VideoSource> video;
162     if (is_extension_y4m(test_video_param_.filename))
163       video.reset(new libaom_test::Y4mVideoSource(test_video_param_.filename, 0,
164                                                   kFrames));
165     else
166       video.reset(new libaom_test::YUVVideoSource(test_video_param_.filename,
167                                                   test_video_param_.fmt, 352,
168                                                   288, 30, 1, 0, kFrames));
169     ASSERT_NE(video, nullptr);
170 
171     ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
172     const double psnr = GetAveragePsnr();
173     EXPECT_GT(psnr, GetPsnrThreshold())
174         << "cpu used = " << cpu_used_ << " aq mode = " << aq_mode_;
175   }
176 
177   TestVideoParam test_video_param_;
178   int cpu_used_;
179 
180  private:
181   double psnr_;
182   unsigned int nframes_;
183   unsigned int aq_mode_;
184   int threads_;
185   int tile_columns_;
186 };
187 
188 class RTEndToEndTestThreaded : public RTEndToEndTest {};
189 
TEST_P(RTEndToEndTest,EndtoEndPSNRTest)190 TEST_P(RTEndToEndTest, EndtoEndPSNRTest) { DoTest(); }
191 
TEST_P(RTEndToEndTestThreaded,EndtoEndPSNRTest)192 TEST_P(RTEndToEndTestThreaded, EndtoEndPSNRTest) { DoTest(); }
193 
194 AV1_INSTANTIATE_TEST_SUITE(RTEndToEndTest, ::testing::ValuesIn(kTestVectors),
195                            ::testing::Range(5, 11),
196                            ::testing::Values<unsigned int>(0, 3),
197                            ::testing::Values(1), ::testing::Values(1));
198 
199 AV1_INSTANTIATE_TEST_SUITE(RTEndToEndTestThreaded,
200                            ::testing::ValuesIn(kTestVectors),
201                            ::testing::Range(5, 11),
202                            ::testing::Values<unsigned int>(0, 3),
203                            ::testing::Range(2, 5), ::testing::Range(2, 5));
204 }  // namespace
205