]> granicus.if.org Git - libvpx/blob - test/vp9_end_to_end_test.cc
Adds a set of end-to-end encode tests
[libvpx] / test / vp9_end_to_end_test.cc
1 /*
2  *  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
3  *
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.
9  */
10
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"
17
18 namespace {
19
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 const int kCpuUsed = 2;
26 const double psnr_threshold = 35.0;
27
28 typedef struct {
29   const char *filename;
30   unsigned int input_bit_depth;
31   vpx_img_fmt fmt;
32   vpx_bit_depth_t bit_depth;
33   unsigned int profile;
34 } TestVideoParam;
35
36 const TestVideoParam TestVectors[] = {
37   {"park_joy_90p_8_420.y4m", 8, VPX_IMG_FMT_I420, VPX_BITS_8, 0},
38   {"park_joy_90p_8_422.y4m", 8, VPX_IMG_FMT_I422, VPX_BITS_8, 1},
39   {"park_joy_90p_8_444.y4m", 8, VPX_IMG_FMT_I444, VPX_BITS_8, 1},
40   {"park_joy_90p_8_440.yuv", 8, VPX_IMG_FMT_I440, VPX_BITS_8, 1},
41 #if CONFIG_VP9_HIGHBITDEPTH
42   {"park_joy_90p_10_420.y4m", 10, VPX_IMG_FMT_I42016, VPX_BITS_10, 2},
43   {"park_joy_90p_10_422.y4m", 10, VPX_IMG_FMT_I42216, VPX_BITS_10, 3},
44   {"park_joy_90p_10_444.y4m", 10, VPX_IMG_FMT_I44416, VPX_BITS_10, 3},
45   {"park_joy_90p_10_440.yuv", 10, VPX_IMG_FMT_I44016, VPX_BITS_10, 3},
46   {"park_joy_90p_12_420.y4m", 12, VPX_IMG_FMT_I42016, VPX_BITS_12, 2},
47   {"park_joy_90p_12_422.y4m", 12, VPX_IMG_FMT_I42216, VPX_BITS_12, 3},
48   {"park_joy_90p_12_444.y4m", 12, VPX_IMG_FMT_I44416, VPX_BITS_12, 3},
49   {"park_joy_90p_12_440.yuv", 12, VPX_IMG_FMT_I44016, VPX_BITS_12, 3},
50 #endif  // CONFIG_VP9_HIGHBITDEPTH
51 };
52
53 int is_extension_y4m(const char *filename) {
54   const char *dot = strrchr(filename, '.');
55   if (!dot || dot == filename)
56     return 0;
57   else
58     return !strcmp(dot, ".y4m");
59 }
60
61 class EndToEndTestLarge
62     : public ::libvpx_test::EncoderTest,
63       public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, \
64                                                  TestVideoParam> {
65  protected:
66   EndToEndTestLarge()
67       : EncoderTest(GET_PARAM(0)),
68         psnr_(0.0),
69         nframes_(0),
70         encoding_mode_(GET_PARAM(1)) {
71   }
72
73   virtual ~EndToEndTestLarge() {}
74
75   virtual void SetUp() {
76     InitializeConfig();
77     SetMode(encoding_mode_);
78     if (encoding_mode_ != ::libvpx_test::kRealTime) {
79       cfg_.g_lag_in_frames = 5;
80       cfg_.rc_end_usage = VPX_VBR;
81     } else {
82       cfg_.g_lag_in_frames = 0;
83       cfg_.rc_end_usage = VPX_CBR;
84     }
85     test_video_param_ = GET_PARAM(2);
86   }
87
88   virtual void BeginPassHook(unsigned int) {
89     psnr_ = 0.0;
90     nframes_ = 0;
91   }
92
93   virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
94     psnr_ += pkt->data.psnr.psnr[0];
95     nframes_++;
96   }
97
98   virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
99                                   ::libvpx_test::Encoder *encoder) {
100     if (video->frame() == 1) {
101       encoder->Control(VP8E_SET_CPUUSED, kCpuUsed);
102       if (encoding_mode_ != ::libvpx_test::kRealTime) {
103         encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
104         encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
105         encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
106         encoder->Control(VP8E_SET_ARNR_TYPE, 3);
107       }
108     }
109   }
110
111   double GetAveragePsnr() const {
112     if (nframes_)
113       return psnr_ / nframes_;
114     return 0.0;
115   }
116
117   TestVideoParam test_video_param_;
118
119  private:
120   double psnr_;
121   unsigned int nframes_;
122   libvpx_test::TestMode encoding_mode_;
123 };
124
125 TEST_P(EndToEndTestLarge, EndtoEndPSNRTest) {
126   cfg_.rc_target_bitrate = kBitrate;
127   cfg_.g_error_resilient = 0;
128   cfg_.g_profile = test_video_param_.profile;
129   cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
130   cfg_.g_bit_depth = test_video_param_.bit_depth;
131   init_flags_ = VPX_CODEC_USE_PSNR;
132
133   libvpx_test::VideoSource *video;
134   if (is_extension_y4m(test_video_param_.filename)) {
135     video = new libvpx_test::Y4mVideoSource(test_video_param_.filename,
136                                             0, kFrames);
137   } else {
138     video = new libvpx_test::YUVVideoSource(test_video_param_.filename,
139                                             test_video_param_.fmt,
140                                             kWidth, kHeight,
141                                             kFramerate, 1, 0, kFrames);
142   }
143
144   ASSERT_NO_FATAL_FAILURE(RunLoop(video));
145   const double psnr = GetAveragePsnr();
146   EXPECT_GT(psnr, psnr_threshold);
147   delete(video);
148 }
149
150 VP9_INSTANTIATE_TEST_CASE(
151     EndToEndTestLarge,
152     ::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood),
153     ::testing::ValuesIn(TestVectors));
154
155 }  // namespace