]> granicus.if.org Git - libvpx/blob - test/vp9_end_to_end_test.cc
Merge "Fix PICK_MODE_CONTEXT index in non-RD coding mode"
[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     dec_cfg_.threads = 4;
86     test_video_param_ = GET_PARAM(2);
87   }
88
89   virtual void BeginPassHook(unsigned int) {
90     psnr_ = 0.0;
91     nframes_ = 0;
92   }
93
94   virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
95     psnr_ += pkt->data.psnr.psnr[0];
96     nframes_++;
97   }
98
99   virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
100                                   ::libvpx_test::Encoder *encoder) {
101     if (video->frame() == 1) {
102       encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING, 1);
103       encoder->Control(VP9E_SET_TILE_COLUMNS, 4);
104       encoder->Control(VP8E_SET_CPUUSED, kCpuUsed);
105       if (encoding_mode_ != ::libvpx_test::kRealTime) {
106         encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
107         encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
108         encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
109         encoder->Control(VP8E_SET_ARNR_TYPE, 3);
110       }
111     }
112   }
113
114   double GetAveragePsnr() const {
115     if (nframes_)
116       return psnr_ / nframes_;
117     return 0.0;
118   }
119
120   TestVideoParam test_video_param_;
121
122  private:
123   double psnr_;
124   unsigned int nframes_;
125   libvpx_test::TestMode encoding_mode_;
126 };
127
128 TEST_P(EndToEndTestLarge, EndtoEndPSNRTest) {
129   cfg_.rc_target_bitrate = kBitrate;
130   cfg_.g_error_resilient = 0;
131   cfg_.g_profile = test_video_param_.profile;
132   cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
133   cfg_.g_bit_depth = test_video_param_.bit_depth;
134   init_flags_ = VPX_CODEC_USE_PSNR;
135
136   libvpx_test::VideoSource *video;
137   if (is_extension_y4m(test_video_param_.filename)) {
138     video = new libvpx_test::Y4mVideoSource(test_video_param_.filename,
139                                             0, kFrames);
140   } else {
141     video = new libvpx_test::YUVVideoSource(test_video_param_.filename,
142                                             test_video_param_.fmt,
143                                             kWidth, kHeight,
144                                             kFramerate, 1, 0, kFrames);
145   }
146
147   ASSERT_NO_FATAL_FAILURE(RunLoop(video));
148   const double psnr = GetAveragePsnr();
149   EXPECT_GT(psnr, psnr_threshold);
150   delete(video);
151 }
152
153 VP9_INSTANTIATE_TEST_CASE(
154     EndToEndTestLarge,
155     ::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood),
156     ::testing::ValuesIn(TestVectors));
157
158 }  // namespace