• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, 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 
15 #include "gtest/gtest.h"
16 
17 #include "test/codec_factory.h"
18 #include "test/encode_test_driver.h"
19 #include "test/util.h"
20 #include "test/y4m_video_source.h"
21 #include "test/yuv_video_source.h"
22 
23 namespace {
24 
25 const unsigned int kWidth = 160;
26 const unsigned int kHeight = 90;
27 const unsigned int kFramerate = 50;
28 const unsigned int kFrames = 10;
29 const int kBitrate = 500;
30 const unsigned int kCqLevel = 18;
31 // List of psnr thresholds for speed settings 0-8 and 4 encoding modes
32 const double kPsnrThreshold[][4] = {
33   { 34.9, 44.4, 39.5, 41.9 }, { 34.9, 44.4, 39.5, 41.9 },
34   { 34.9, 44.4, 39.4, 41.9 }, { 34.9, 44.4, 39.1, 41.8 },
35   { 34.9, 44.4, 39.1, 41.8 }, { 34.9, 44.29, 38.5, 41.8 },
36   { 34.9, 44.3, 38.5, 41.3 }, { 34.9, 44.3, 38.5, 40.8 },
37   { 34.9, 44.3, 38.5, 40.8 }
38 };
39 
40 typedef struct {
41   const char *filename;
42   unsigned int input_bit_depth;
43   aom_img_fmt fmt;
44   aom_bit_depth_t bit_depth;
45   unsigned int profile;
46 } TestVideoParam;
47 
operator <<(std::ostream & os,const TestVideoParam & test_arg)48 std::ostream &operator<<(std::ostream &os, const TestVideoParam &test_arg) {
49   return os << "TestVideoParam { filename:" << test_arg.filename
50             << " input_bit_depth:" << test_arg.input_bit_depth
51             << " fmt:" << test_arg.fmt << " bit_depth:" << test_arg.bit_depth
52             << " profile:" << test_arg.profile << " }";
53 }
54 
55 const TestVideoParam kTestVectors[] = {
56   { "park_joy_90p_8_420.y4m", 8, AOM_IMG_FMT_I420, AOM_BITS_8, 0 },
57   { "park_joy_90p_8_422.y4m", 8, AOM_IMG_FMT_I422, AOM_BITS_8, 2 },
58   { "park_joy_90p_8_444.y4m", 8, AOM_IMG_FMT_I444, AOM_BITS_8, 1 },
59 #if CONFIG_AV1_HIGHBITDEPTH
60   { "park_joy_90p_10_420.y4m", 10, AOM_IMG_FMT_I42016, AOM_BITS_10, 0 },
61   { "park_joy_90p_10_422.y4m", 10, AOM_IMG_FMT_I42216, AOM_BITS_10, 2 },
62   { "park_joy_90p_10_444.y4m", 10, AOM_IMG_FMT_I44416, AOM_BITS_10, 1 },
63   { "park_joy_90p_12_420.y4m", 12, AOM_IMG_FMT_I42016, AOM_BITS_12, 2 },
64   { "park_joy_90p_12_422.y4m", 12, AOM_IMG_FMT_I42216, AOM_BITS_12, 2 },
65   { "park_joy_90p_12_444.y4m", 12, AOM_IMG_FMT_I44416, AOM_BITS_12, 2 },
66 #endif
67 };
68 
69 // Encoding modes tested
70 const libaom_test::TestMode kEncodingModeVectors[] = {
71   ::libaom_test::kTwoPassGood,
72   ::libaom_test::kOnePassGood,
73   ::libaom_test::kRealTime,
74 };
75 
76 // Speed settings tested
77 const int kCpuUsedVectors[] = { 1, 2, 3, 5, 6 };
78 
79 class EndToEndTest
80     : public ::libaom_test::CodecTestWith3Params<libaom_test::TestMode,
81                                                  TestVideoParam, int>,
82       public ::libaom_test::EncoderTest {
83  protected:
EndToEndTest()84   EndToEndTest()
85       : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(2)),
86         cpu_used_(GET_PARAM(3)), psnr_(0.0), nframes_(0),
87         encoding_mode_(GET_PARAM(1)) {}
88 
89   ~EndToEndTest() override = default;
90 
SetUp()91   void SetUp() override {
92     InitializeConfig(encoding_mode_);
93     if (encoding_mode_ == ::libaom_test::kOnePassGood ||
94         encoding_mode_ == ::libaom_test::kTwoPassGood) {
95       cfg_.g_lag_in_frames = 5;
96     } else if (encoding_mode_ == ::libaom_test::kRealTime) {
97       cfg_.rc_buf_sz = 1000;
98       cfg_.rc_buf_initial_sz = 500;
99       cfg_.rc_buf_optimal_sz = 600;
100     }
101   }
102 
BeginPassHook(unsigned int)103   void BeginPassHook(unsigned int) override {
104     psnr_ = 0.0;
105     nframes_ = 0;
106   }
107 
PSNRPktHook(const aom_codec_cx_pkt_t * pkt)108   void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) override {
109     psnr_ += pkt->data.psnr.psnr[0];
110     nframes_++;
111   }
112 
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)113   void PreEncodeFrameHook(::libaom_test::VideoSource *video,
114                           ::libaom_test::Encoder *encoder) override {
115     if (video->frame() == 0) {
116       encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
117       encoder->Control(AV1E_SET_TILE_COLUMNS, 4);
118       encoder->Control(AOME_SET_CPUUSED, cpu_used_);
119       // Test screen coding tools at cpu_used = 1 && encoding mode is two-pass.
120       if (cpu_used_ == 1 && encoding_mode_ == ::libaom_test::kTwoPassGood)
121         encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_SCREEN);
122       else
123         encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_DEFAULT);
124       if (encoding_mode_ == ::libaom_test::kOnePassGood ||
125           encoding_mode_ == ::libaom_test::kTwoPassGood) {
126         encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
127         encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
128         encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
129       } else if (encoding_mode_ == ::libaom_test::kAllIntra) {
130         encoder->Control(AOME_SET_CQ_LEVEL, kCqLevel);
131       }
132     }
133   }
134 
GetAveragePsnr() const135   double GetAveragePsnr() const {
136     if (nframes_) return psnr_ / nframes_;
137     return 0.0;
138   }
139 
GetPsnrThreshold()140   double GetPsnrThreshold() {
141     return kPsnrThreshold[cpu_used_][encoding_mode_];
142   }
143 
DoTest()144   void DoTest() {
145     cfg_.rc_target_bitrate = kBitrate;
146     cfg_.g_error_resilient = 0;
147     cfg_.g_profile = test_video_param_.profile;
148     cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
149     cfg_.g_bit_depth = test_video_param_.bit_depth;
150     init_flags_ = AOM_CODEC_USE_PSNR;
151     if (cfg_.g_bit_depth > 8) init_flags_ |= AOM_CODEC_USE_HIGHBITDEPTH;
152 
153     std::unique_ptr<libaom_test::VideoSource> video;
154     if (is_extension_y4m(test_video_param_.filename)) {
155       video.reset(new libaom_test::Y4mVideoSource(test_video_param_.filename, 0,
156                                                   kFrames));
157     } else {
158       video.reset(new libaom_test::YUVVideoSource(
159           test_video_param_.filename, test_video_param_.fmt, kWidth, kHeight,
160           kFramerate, 1, 0, kFrames));
161     }
162     ASSERT_NE(video, nullptr);
163 
164     ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
165     const double psnr = GetAveragePsnr();
166     EXPECT_GT(psnr, GetPsnrThreshold() * 0.98)
167         << "cpu used = " << cpu_used_ << ", encoding mode = " << encoding_mode_;
168   }
169 
170   TestVideoParam test_video_param_;
171   int cpu_used_;
172 
173  private:
174   double psnr_;
175   unsigned int nframes_;
176   libaom_test::TestMode encoding_mode_;
177 };
178 
179 class EndToEndTestLarge : public EndToEndTest {};
180 
181 class EndToEndAllIntraTestLarge : public EndToEndTest {};
182 
183 class EndToEndAllIntraTest : public EndToEndTest {};
184 
TEST_P(EndToEndTestLarge,EndtoEndPSNRTest)185 TEST_P(EndToEndTestLarge, EndtoEndPSNRTest) { DoTest(); }
186 
TEST_P(EndToEndTest,EndtoEndPSNRTest)187 TEST_P(EndToEndTest, EndtoEndPSNRTest) { DoTest(); }
188 
TEST_P(EndToEndAllIntraTestLarge,EndtoEndPSNRTest)189 TEST_P(EndToEndAllIntraTestLarge, EndtoEndPSNRTest) { DoTest(); }
190 
TEST_P(EndToEndAllIntraTest,EndtoEndPSNRTest)191 TEST_P(EndToEndAllIntraTest, EndtoEndPSNRTest) { DoTest(); }
192 
193 AV1_INSTANTIATE_TEST_SUITE(EndToEndTestLarge,
194                            ::testing::ValuesIn(kEncodingModeVectors),
195                            ::testing::ValuesIn(kTestVectors),
196                            ::testing::ValuesIn(kCpuUsedVectors));
197 
198 AV1_INSTANTIATE_TEST_SUITE(EndToEndTest,
199                            ::testing::Values(::libaom_test::kTwoPassGood),
200                            ::testing::Values(kTestVectors[2]),  // 444
201                            ::testing::Values(3));               // cpu_used
202 
203 AV1_INSTANTIATE_TEST_SUITE(EndToEndAllIntraTestLarge,
204                            ::testing::Values(::libaom_test::kAllIntra),
205                            ::testing::ValuesIn(kTestVectors),
206                            ::testing::Values(2, 4, 6, 8));  // cpu_used
207 
208 AV1_INSTANTIATE_TEST_SUITE(EndToEndAllIntraTest,
209                            ::testing::Values(::libaom_test::kAllIntra),
210                            ::testing::Values(kTestVectors[0]),  // 420
211                            ::testing::Values(6));               // cpu_used
212 }  // namespace
213