]> granicus.if.org Git - libvpx/blob - test/vp9_ethread_test.cc
Merge "Reduce default overshoot/undershoot params to 25"
[libvpx] / test / vp9_ethread_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 <string>
12 #include <vector>
13 #include "third_party/googletest/src/include/gtest/gtest.h"
14 #include "test/codec_factory.h"
15 #include "test/encode_test_driver.h"
16 #include "test/md5_helper.h"
17 #include "test/util.h"
18 #include "test/y4m_video_source.h"
19
20 namespace {
21 class VP9EncoderThreadTest
22     : public ::libvpx_test::EncoderTest,
23       public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> {
24  protected:
25   VP9EncoderThreadTest()
26       : EncoderTest(GET_PARAM(0)),
27         encoder_initialized_(false),
28         tiles_(2),
29         encoding_mode_(GET_PARAM(1)),
30         set_cpu_used_(GET_PARAM(2)) {
31     init_flags_ = VPX_CODEC_USE_PSNR;
32     vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
33     cfg.w = 1280;
34     cfg.h = 720;
35     decoder_ = codec_->CreateDecoder(cfg, 0);
36
37     md5_.clear();
38   }
39   virtual ~VP9EncoderThreadTest() {
40     delete decoder_;
41   }
42
43   virtual void SetUp() {
44     InitializeConfig();
45     SetMode(encoding_mode_);
46
47     if (encoding_mode_ != ::libvpx_test::kRealTime) {
48       cfg_.g_lag_in_frames = 3;
49       cfg_.rc_end_usage = VPX_VBR;
50       cfg_.rc_2pass_vbr_minsection_pct = 5;
51       cfg_.rc_2pass_vbr_minsection_pct = 2000;
52     } else {
53       cfg_.g_lag_in_frames = 0;
54       cfg_.rc_end_usage = VPX_CBR;
55       cfg_.g_error_resilient = 1;
56     }
57     cfg_.rc_max_quantizer = 56;
58     cfg_.rc_min_quantizer = 0;
59   }
60
61   virtual void BeginPassHook(unsigned int /*pass*/) {
62     encoder_initialized_ = false;
63   }
64
65   virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
66                                   ::libvpx_test::Encoder *encoder) {
67     if (!encoder_initialized_) {
68       // Encode 4 column tiles.
69       encoder->Control(VP9E_SET_TILE_COLUMNS, tiles_);
70       encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_);
71       if (encoding_mode_ != ::libvpx_test::kRealTime) {
72         encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
73         encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
74         encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
75         encoder->Control(VP8E_SET_ARNR_TYPE, 3);
76       } else {
77         encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 0);
78       }
79       encoder_initialized_ = true;
80     }
81   }
82
83   virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
84     const vpx_codec_err_t res = decoder_->DecodeFrame(
85         reinterpret_cast<uint8_t*>(pkt->data.frame.buf), pkt->data.frame.sz);
86     if (res != VPX_CODEC_OK) {
87       abort_ = true;
88       ASSERT_EQ(VPX_CODEC_OK, res);
89     }
90     const vpx_image_t *img = decoder_->GetDxData().Next();
91
92     if (img) {
93       ::libvpx_test::MD5 md5_res;
94       md5_res.Add(img);
95       md5_.push_back(md5_res.Get());
96     }
97   }
98
99   bool encoder_initialized_;
100   int tiles_;
101   ::libvpx_test::TestMode encoding_mode_;
102   int set_cpu_used_;
103   ::libvpx_test::Decoder *decoder_;
104   std::vector<std::string> md5_;
105 };
106
107 TEST_P(VP9EncoderThreadTest, EncoderResultTest) {
108   std::vector<std::string> single_thr_md5, multi_thr_md5;
109
110   ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 15, 20);
111
112   cfg_.rc_target_bitrate = 1000;
113
114   // Encode using single thread.
115   cfg_.g_threads = 1;
116   init_flags_ = VPX_CODEC_USE_PSNR;
117   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
118   single_thr_md5 = md5_;
119   md5_.clear();
120
121   // Encode using multiple threads.
122   cfg_.g_threads = 4;
123   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
124   multi_thr_md5 = md5_;
125   md5_.clear();
126
127   // Compare to check if two vectors are equal.
128   ASSERT_EQ(single_thr_md5, multi_thr_md5);
129 }
130
131 VP9_INSTANTIATE_TEST_CASE(
132     VP9EncoderThreadTest,
133     ::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood,
134                       ::libvpx_test::kRealTime),
135     ::testing::Range(1, 9));
136 }  // namespace