2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "third_party/googletest/src/include/gtest/gtest.h"
13 #include "test/codec_factory.h"
14 #include "test/encode_test_driver.h"
15 #include "test/util.h"
16 #include "test/y4m_video_source.h"
17 #include "test/yuv_video_source.h"
21 const unsigned int kWidth = 160;
22 const unsigned int kHeight = 90;
23 const unsigned int kFramerate = 50;
24 const unsigned int kFrames = 10;
25 const int kBitrate = 500;
26 // List of psnr thresholds for speed settings 0-7 and 5 encoding modes
27 const double kPsnrThreshold[][5] = {
28 { 36.0, 37.0, 37.0, 37.0, 37.0 },
29 { 35.0, 36.0, 36.0, 36.0, 36.0 },
30 { 34.0, 35.0, 35.0, 35.0, 35.0 },
31 { 33.0, 34.0, 34.0, 34.0, 34.0 },
32 { 32.0, 33.0, 33.0, 33.0, 33.0 },
33 { 31.0, 32.0, 32.0, 32.0, 32.0 },
34 { 30.0, 31.0, 31.0, 31.0, 31.0 },
35 { 29.0, 30.0, 30.0, 30.0, 30.0 },
40 unsigned int input_bit_depth;
42 vpx_bit_depth_t bit_depth;
46 const TestVideoParam kTestVectors[] = {
47 {"park_joy_90p_8_420.y4m", 8, VPX_IMG_FMT_I420, VPX_BITS_8, 0},
48 {"park_joy_90p_8_422.y4m", 8, VPX_IMG_FMT_I422, VPX_BITS_8, 1},
49 {"park_joy_90p_8_444.y4m", 8, VPX_IMG_FMT_I444, VPX_BITS_8, 1},
50 {"park_joy_90p_8_440.yuv", 8, VPX_IMG_FMT_I440, VPX_BITS_8, 1},
51 #if CONFIG_VP9_HIGHBITDEPTH
52 {"park_joy_90p_10_420.y4m", 10, VPX_IMG_FMT_I42016, VPX_BITS_10, 2},
53 {"park_joy_90p_10_422.y4m", 10, VPX_IMG_FMT_I42216, VPX_BITS_10, 3},
54 {"park_joy_90p_10_444.y4m", 10, VPX_IMG_FMT_I44416, VPX_BITS_10, 3},
55 {"park_joy_90p_10_440.yuv", 10, VPX_IMG_FMT_I44016, VPX_BITS_10, 3},
56 {"park_joy_90p_12_420.y4m", 12, VPX_IMG_FMT_I42016, VPX_BITS_12, 2},
57 {"park_joy_90p_12_422.y4m", 12, VPX_IMG_FMT_I42216, VPX_BITS_12, 3},
58 {"park_joy_90p_12_444.y4m", 12, VPX_IMG_FMT_I44416, VPX_BITS_12, 3},
59 {"park_joy_90p_12_440.yuv", 12, VPX_IMG_FMT_I44016, VPX_BITS_12, 3},
60 #endif // CONFIG_VP9_HIGHBITDEPTH
63 // Encoding modes tested
64 const libvpx_test::TestMode kEncodingModeVectors[] = {
65 ::libvpx_test::kTwoPassGood,
66 ::libvpx_test::kOnePassGood,
67 ::libvpx_test::kRealTime,
70 // Speed settings tested
71 const int kCpuUsedVectors[] = {1, 2, 3, 5, 6};
73 int is_extension_y4m(const char *filename) {
74 const char *dot = strrchr(filename, '.');
75 if (!dot || dot == filename)
78 return !strcmp(dot, ".y4m");
81 class EndToEndTestLarge
82 : public ::libvpx_test::EncoderTest,
83 public ::libvpx_test::CodecTestWith3Params<libvpx_test::TestMode, \
84 TestVideoParam, int> {
87 : EncoderTest(GET_PARAM(0)),
88 test_video_param_(GET_PARAM(2)),
89 cpu_used_(GET_PARAM(3)),
92 encoding_mode_(GET_PARAM(1)) {
95 virtual ~EndToEndTestLarge() {}
97 virtual void SetUp() {
99 SetMode(encoding_mode_);
100 if (encoding_mode_ != ::libvpx_test::kRealTime) {
101 cfg_.g_lag_in_frames = 5;
102 cfg_.rc_end_usage = VPX_VBR;
104 cfg_.g_lag_in_frames = 0;
105 cfg_.rc_end_usage = VPX_CBR;
106 cfg_.rc_buf_sz = 1000;
107 cfg_.rc_buf_initial_sz = 500;
108 cfg_.rc_buf_optimal_sz = 600;
110 dec_cfg_.threads = 4;
113 virtual void BeginPassHook(unsigned int) {
118 virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
119 psnr_ += pkt->data.psnr.psnr[0];
123 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
124 ::libvpx_test::Encoder *encoder) {
125 if (video->frame() == 1) {
126 encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING, 1);
127 encoder->Control(VP9E_SET_TILE_COLUMNS, 4);
128 encoder->Control(VP8E_SET_CPUUSED, cpu_used_);
129 if (encoding_mode_ != ::libvpx_test::kRealTime) {
130 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
131 encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
132 encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
133 encoder->Control(VP8E_SET_ARNR_TYPE, 3);
138 double GetAveragePsnr() const {
140 return psnr_ / nframes_;
144 double GetPsnrThreshold() {
145 return kPsnrThreshold[cpu_used_][encoding_mode_];
148 TestVideoParam test_video_param_;
153 unsigned int nframes_;
154 libvpx_test::TestMode encoding_mode_;
157 TEST_P(EndToEndTestLarge, EndtoEndPSNRTest) {
158 cfg_.rc_target_bitrate = kBitrate;
159 cfg_.g_error_resilient = 0;
160 cfg_.g_profile = test_video_param_.profile;
161 cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
162 cfg_.g_bit_depth = test_video_param_.bit_depth;
163 init_flags_ = VPX_CODEC_USE_PSNR;
164 if (cfg_.g_bit_depth > 8)
165 init_flags_ |= VPX_CODEC_USE_HIGHBITDEPTH;
167 libvpx_test::VideoSource *video;
168 if (is_extension_y4m(test_video_param_.filename)) {
169 video = new libvpx_test::Y4mVideoSource(test_video_param_.filename,
172 video = new libvpx_test::YUVVideoSource(test_video_param_.filename,
173 test_video_param_.fmt,
175 kFramerate, 1, 0, kFrames);
178 ASSERT_NO_FATAL_FAILURE(RunLoop(video));
179 const double psnr = GetAveragePsnr();
180 EXPECT_GT(psnr, GetPsnrThreshold());
184 VP9_INSTANTIATE_TEST_CASE(
186 ::testing::ValuesIn(kEncodingModeVectors),
187 ::testing::ValuesIn(kTestVectors),
188 ::testing::ValuesIn(kCpuUsedVectors));