• 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 "third_party/googletest/src/googletest/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 // List of psnr thresholds for speed settings 0-7 and 5 encoding modes
31 const double kPsnrThreshold[][5] = {
32 // Note:
33 // AV1 HBD average PSNR is slightly lower than AV1.
34 // We make two cases here to enable the testing and
35 // guard picture quality.
36 #if CONFIG_AV1_ENCODER
37   { 36.0, 37.0, 37.0, 37.0, 37.0 }, { 31.0, 36.0, 36.0, 36.0, 36.0 },
38   { 31.0, 35.0, 35.0, 35.0, 35.0 }, { 31.0, 34.0, 34.0, 34.0, 34.0 },
39   { 31.0, 33.0, 33.0, 33.0, 33.0 }, { 31.0, 32.0, 32.0, 32.0, 32.0 },
40   { 30.0, 31.0, 31.0, 31.0, 31.0 }, { 29.0, 30.0, 30.0, 30.0, 30.0 },
41 #else
42   { 36.0, 37.0, 37.0, 37.0, 37.0 }, { 35.0, 36.0, 36.0, 36.0, 36.0 },
43   { 34.0, 35.0, 35.0, 35.0, 35.0 }, { 33.0, 34.0, 34.0, 34.0, 34.0 },
44   { 32.0, 33.0, 33.0, 33.0, 33.0 }, { 31.0, 32.0, 32.0, 32.0, 32.0 },
45   { 30.0, 31.0, 31.0, 31.0, 31.0 }, { 29.0, 30.0, 30.0, 30.0, 30.0 },
46 #endif  // CONFIG_AV1_ENCODER
47 };
48 
49 typedef struct {
50   const char *filename;
51   unsigned int input_bit_depth;
52   aom_img_fmt fmt;
53   aom_bit_depth_t bit_depth;
54   unsigned int profile;
55 } TestVideoParam;
56 
operator <<(std::ostream & os,const TestVideoParam & test_arg)57 std::ostream &operator<<(std::ostream &os, const TestVideoParam &test_arg) {
58   return os << "TestVideoParam { filename:" << test_arg.filename
59             << " input_bit_depth:" << test_arg.input_bit_depth
60             << " fmt:" << test_arg.fmt << " bit_depth:" << test_arg.bit_depth
61             << " profile:" << test_arg.profile << " }";
62 }
63 
64 const TestVideoParam kTestVectors[] = {
65   { "park_joy_90p_8_420.y4m", 8, AOM_IMG_FMT_I420, AOM_BITS_8, 0 },
66   { "park_joy_90p_8_422.y4m", 8, AOM_IMG_FMT_I422, AOM_BITS_8, 2 },
67   { "park_joy_90p_8_444.y4m", 8, AOM_IMG_FMT_I444, AOM_BITS_8, 1 },
68 #if CONFIG_AV1_HIGHBITDEPTH
69   { "park_joy_90p_10_420.y4m", 10, AOM_IMG_FMT_I42016, AOM_BITS_10, 0 },
70   { "park_joy_90p_10_422.y4m", 10, AOM_IMG_FMT_I42216, AOM_BITS_10, 2 },
71   { "park_joy_90p_10_444.y4m", 10, AOM_IMG_FMT_I44416, AOM_BITS_10, 1 },
72   { "park_joy_90p_12_420.y4m", 12, AOM_IMG_FMT_I42016, AOM_BITS_12, 2 },
73   { "park_joy_90p_12_422.y4m", 12, AOM_IMG_FMT_I42216, AOM_BITS_12, 2 },
74   { "park_joy_90p_12_444.y4m", 12, AOM_IMG_FMT_I44416, AOM_BITS_12, 2 },
75 #endif
76 };
77 
78 // Encoding modes tested
79 const libaom_test::TestMode kEncodingModeVectors[] = {
80   ::libaom_test::kTwoPassGood,
81   ::libaom_test::kOnePassGood,
82   ::libaom_test::kRealTime,
83 };
84 
85 // Speed settings tested
86 const int kCpuUsedVectors[] = { 1, 2, 3, 5, 6 };
87 
is_extension_y4m(const char * filename)88 int is_extension_y4m(const char *filename) {
89   const char *dot = strrchr(filename, '.');
90   if (!dot || dot == filename)
91     return 0;
92   else
93     return !strcmp(dot, ".y4m");
94 }
95 
96 class EndToEndTest
97     : public ::libaom_test::CodecTestWith3Params<libaom_test::TestMode,
98                                                  TestVideoParam, int>,
99       public ::libaom_test::EncoderTest {
100  protected:
EndToEndTest()101   EndToEndTest()
102       : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(2)),
103         cpu_used_(GET_PARAM(3)), psnr_(0.0), nframes_(0),
104         encoding_mode_(GET_PARAM(1)) {}
105 
~EndToEndTest()106   virtual ~EndToEndTest() {}
107 
SetUp()108   virtual void SetUp() {
109     InitializeConfig();
110     SetMode(encoding_mode_);
111     if (encoding_mode_ != ::libaom_test::kRealTime) {
112       cfg_.g_lag_in_frames = 5;
113       cfg_.rc_end_usage = AOM_VBR;
114     } else {
115       cfg_.g_lag_in_frames = 0;
116       cfg_.rc_end_usage = AOM_CBR;
117       cfg_.rc_buf_sz = 1000;
118       cfg_.rc_buf_initial_sz = 500;
119       cfg_.rc_buf_optimal_sz = 600;
120     }
121   }
122 
BeginPassHook(unsigned int)123   virtual void BeginPassHook(unsigned int) {
124     psnr_ = 0.0;
125     nframes_ = 0;
126   }
127 
PSNRPktHook(const aom_codec_cx_pkt_t * pkt)128   virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) {
129     psnr_ += pkt->data.psnr.psnr[0];
130     nframes_++;
131   }
132 
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)133   virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
134                                   ::libaom_test::Encoder *encoder) {
135     if (video->frame() == 0) {
136       encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
137       encoder->Control(AV1E_SET_TILE_COLUMNS, 4);
138       encoder->Control(AOME_SET_CPUUSED, cpu_used_);
139       // Test screen coding tools at cpu_used = 1 && encoding mode is two-pass.
140       if (cpu_used_ == 1 && encoding_mode_ == ::libaom_test::kTwoPassGood)
141         encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_SCREEN);
142       else
143         encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_DEFAULT);
144       if (encoding_mode_ != ::libaom_test::kRealTime) {
145         encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
146         encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
147         encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
148       }
149     }
150   }
151 
GetAveragePsnr() const152   double GetAveragePsnr() const {
153     if (nframes_) return psnr_ / nframes_;
154     return 0.0;
155   }
156 
GetPsnrThreshold()157   double GetPsnrThreshold() {
158     return kPsnrThreshold[cpu_used_][encoding_mode_];
159   }
160 
DoTest()161   void DoTest() {
162     cfg_.rc_target_bitrate = kBitrate;
163     cfg_.g_error_resilient = 0;
164     cfg_.g_profile = test_video_param_.profile;
165     cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
166     cfg_.g_bit_depth = test_video_param_.bit_depth;
167     init_flags_ = AOM_CODEC_USE_PSNR;
168     if (cfg_.g_bit_depth > 8) init_flags_ |= AOM_CODEC_USE_HIGHBITDEPTH;
169 
170     std::unique_ptr<libaom_test::VideoSource> video;
171     if (is_extension_y4m(test_video_param_.filename)) {
172       video.reset(new libaom_test::Y4mVideoSource(test_video_param_.filename, 0,
173                                                   kFrames));
174     } else {
175       video.reset(new libaom_test::YUVVideoSource(
176           test_video_param_.filename, test_video_param_.fmt, kWidth, kHeight,
177           kFramerate, 1, 0, kFrames));
178     }
179     ASSERT_TRUE(video.get() != NULL);
180 
181     ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
182     const double psnr = GetAveragePsnr();
183     EXPECT_GT(psnr, GetPsnrThreshold())
184         << "cpu used = " << cpu_used_ << ", encoding mode = " << encoding_mode_;
185   }
186 
187   TestVideoParam test_video_param_;
188   int cpu_used_;
189 
190  private:
191   double psnr_;
192   unsigned int nframes_;
193   libaom_test::TestMode encoding_mode_;
194 };
195 
196 class EndToEndTestLarge : public EndToEndTest {};
197 
TEST_P(EndToEndTestLarge,EndtoEndPSNRTest)198 TEST_P(EndToEndTestLarge, EndtoEndPSNRTest) { DoTest(); }
199 
TEST_P(EndToEndTest,EndtoEndPSNRTest)200 TEST_P(EndToEndTest, EndtoEndPSNRTest) { DoTest(); }
201 
202 AV1_INSTANTIATE_TEST_CASE(EndToEndTestLarge,
203                           ::testing::ValuesIn(kEncodingModeVectors),
204                           ::testing::ValuesIn(kTestVectors),
205                           ::testing::ValuesIn(kCpuUsedVectors));
206 
207 AV1_INSTANTIATE_TEST_CASE(EndToEndTest,
208                           ::testing::Values(kEncodingModeVectors[0]),
209                           ::testing::Values(kTestVectors[2]),  // 444
210                           ::testing::Values(kCpuUsedVectors[2]));
211 }  // namespace
212