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 "test/codec_factory.h"
12 #include "test/encode_test_driver.h"
13 #include "test/y4m_video_source.h"
14 #include "test/yuv_video_source.h"
15 #include "test/util.h"
16 #include "third_party/googletest/src/include/gtest/gtest.h"
20 const unsigned int kWidth = 160;
21 const unsigned int kHeight = 90;
22 const unsigned int kFramerate = 50;
23 const unsigned int kFrames = 10;
24 const int kBitrate = 500;
25 // List of psnr thresholds for speed settings 0-7 and 5 encoding modes
26 const double kPsnrThreshold[][5] = {
27 { 36.0, 37.0, 37.0, 37.0, 37.0 },
28 { 35.0, 36.0, 36.0, 36.0, 36.0 },
29 { 34.0, 35.0, 35.0, 35.0, 35.0 },
30 { 33.0, 34.0, 34.0, 34.0, 34.0 },
31 { 32.0, 33.0, 33.0, 33.0, 33.0 },
32 { 31.0, 32.0, 32.0, 32.0, 32.0 },
33 { 30.0, 31.0, 31.0, 31.0, 31.0 },
34 { 29.0, 30.0, 30.0, 30.0, 30.0 },
39 unsigned int input_bit_depth;
41 vpx_bit_depth_t bit_depth;
45 const TestVideoParam kTestVectors[] = {
46 {"park_joy_90p_8_420.y4m", 8, VPX_IMG_FMT_I420, VPX_BITS_8, 0},
47 {"park_joy_90p_8_422.y4m", 8, VPX_IMG_FMT_I422, VPX_BITS_8, 1},
48 {"park_joy_90p_8_444.y4m", 8, VPX_IMG_FMT_I444, VPX_BITS_8, 1},
49 {"park_joy_90p_8_440.yuv", 8, VPX_IMG_FMT_I440, VPX_BITS_8, 1},
50 #if CONFIG_VP9_HIGHBITDEPTH
51 {"park_joy_90p_10_420.y4m", 10, VPX_IMG_FMT_I42016, VPX_BITS_10, 2},
52 {"park_joy_90p_10_422.y4m", 10, VPX_IMG_FMT_I42216, VPX_BITS_10, 3},
53 {"park_joy_90p_10_444.y4m", 10, VPX_IMG_FMT_I44416, VPX_BITS_10, 3},
54 {"park_joy_90p_10_440.yuv", 10, VPX_IMG_FMT_I44016, VPX_BITS_10, 3},
55 {"park_joy_90p_12_420.y4m", 12, VPX_IMG_FMT_I42016, VPX_BITS_12, 2},
56 {"park_joy_90p_12_422.y4m", 12, VPX_IMG_FMT_I42216, VPX_BITS_12, 3},
57 {"park_joy_90p_12_444.y4m", 12, VPX_IMG_FMT_I44416, VPX_BITS_12, 3},
58 {"park_joy_90p_12_440.yuv", 12, VPX_IMG_FMT_I44016, VPX_BITS_12, 3},
59 #endif // CONFIG_VP9_HIGHBITDEPTH
62 // Encoding modes tested
63 const libvpx_test::TestMode kEncodingModeVectors[] = {
64 ::libvpx_test::kTwoPassGood,
65 ::libvpx_test::kOnePassGood,
66 ::libvpx_test::kRealTime,
69 // Speed settings tested
70 const int kCpuUsedVectors[] = {1, 2, 3, 5, 6};
72 int is_extension_y4m(const char *filename) {
73 const char *dot = strrchr(filename, '.');
74 if (!dot || dot == filename)
77 return !strcmp(dot, ".y4m");
80 class EndToEndTestLarge
81 : public ::libvpx_test::EncoderTest,
82 public ::libvpx_test::CodecTestWith3Params<libvpx_test::TestMode, \
83 TestVideoParam, int> {
86 : EncoderTest(GET_PARAM(0)),
87 test_video_param_(GET_PARAM(2)),
88 cpu_used_(GET_PARAM(3)),
91 encoding_mode_(GET_PARAM(1)) {
94 virtual ~EndToEndTestLarge() {}
96 virtual void SetUp() {
98 SetMode(encoding_mode_);
99 if (encoding_mode_ != ::libvpx_test::kRealTime) {
100 cfg_.g_lag_in_frames = 5;
101 cfg_.rc_end_usage = VPX_VBR;
103 cfg_.g_lag_in_frames = 0;
104 cfg_.rc_end_usage = VPX_CBR;
105 cfg_.rc_buf_sz = 1000;
106 cfg_.rc_buf_initial_sz = 500;
107 cfg_.rc_buf_optimal_sz = 600;
109 dec_cfg_.threads = 4;
112 virtual void BeginPassHook(unsigned int) {
117 virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
118 psnr_ += pkt->data.psnr.psnr[0];
122 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
123 ::libvpx_test::Encoder *encoder) {
124 if (video->frame() == 1) {
125 encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING, 1);
126 encoder->Control(VP9E_SET_TILE_COLUMNS, 4);
127 encoder->Control(VP8E_SET_CPUUSED, cpu_used_);
128 if (encoding_mode_ != ::libvpx_test::kRealTime) {
129 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
130 encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
131 encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
132 encoder->Control(VP8E_SET_ARNR_TYPE, 3);
137 double GetAveragePsnr() const {
139 return psnr_ / nframes_;
143 double GetPsnrThreshold() {
144 return kPsnrThreshold[cpu_used_][encoding_mode_];
147 TestVideoParam test_video_param_;
152 unsigned int nframes_;
153 libvpx_test::TestMode encoding_mode_;
156 TEST_P(EndToEndTestLarge, EndtoEndPSNRTest) {
157 cfg_.rc_target_bitrate = kBitrate;
158 cfg_.g_error_resilient = 0;
159 cfg_.g_profile = test_video_param_.profile;
160 cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
161 cfg_.g_bit_depth = test_video_param_.bit_depth;
162 init_flags_ = VPX_CODEC_USE_PSNR;
163 if (cfg_.g_bit_depth > 8)
164 init_flags_ |= VPX_CODEC_USE_HIGHBITDEPTH;
166 libvpx_test::VideoSource *video;
167 if (is_extension_y4m(test_video_param_.filename)) {
168 video = new libvpx_test::Y4mVideoSource(test_video_param_.filename,
171 video = new libvpx_test::YUVVideoSource(test_video_param_.filename,
172 test_video_param_.fmt,
174 kFramerate, 1, 0, kFrames);
177 ASSERT_NO_FATAL_FAILURE(RunLoop(video));
178 const double psnr = GetAveragePsnr();
179 EXPECT_GT(psnr, GetPsnrThreshold());
183 VP9_INSTANTIATE_TEST_CASE(
185 ::testing::ValuesIn(kEncodingModeVectors),
186 ::testing::ValuesIn(kTestVectors),
187 ::testing::ValuesIn(kCpuUsedVectors));