Add dr prediction test
[aom.git] / test / ethread_test.cc
blob3dcc2a707e428b23693c206c5018430c70a94594
1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
12 #include <string>
13 #include <vector>
14 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
15 #include "test/codec_factory.h"
16 #include "test/encode_test_driver.h"
17 #include "test/md5_helper.h"
18 #include "test/util.h"
19 #include "test/yuv_video_source.h"
21 namespace {
22 class AVxEncoderThreadTest
23 : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>,
24 public ::libaom_test::EncoderTest {
25 protected:
26 AVxEncoderThreadTest()
27 : EncoderTest(GET_PARAM(0)), encoder_initialized_(false),
28 encoding_mode_(GET_PARAM(1)), set_cpu_used_(GET_PARAM(2)) {
29 init_flags_ = AOM_CODEC_USE_PSNR;
30 aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
31 cfg.w = 1280;
32 cfg.h = 720;
33 cfg.allow_lowbitdepth = 1;
34 decoder_ = codec_->CreateDecoder(cfg, 0);
35 if (decoder_->IsAV1()) {
36 decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
37 decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
40 size_enc_.clear();
41 md5_dec_.clear();
42 md5_enc_.clear();
44 virtual ~AVxEncoderThreadTest() { delete decoder_; }
46 virtual void SetUp() {
47 InitializeConfig();
48 SetMode(encoding_mode_);
50 if (encoding_mode_ != ::libaom_test::kRealTime) {
51 cfg_.g_lag_in_frames = 3;
52 cfg_.rc_end_usage = AOM_VBR;
53 cfg_.rc_2pass_vbr_minsection_pct = 5;
54 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
55 } else {
56 cfg_.g_lag_in_frames = 0;
57 cfg_.rc_end_usage = AOM_CBR;
58 cfg_.g_error_resilient = 1;
60 cfg_.rc_max_quantizer = 56;
61 cfg_.rc_min_quantizer = 0;
64 virtual void BeginPassHook(unsigned int /*pass*/) {
65 encoder_initialized_ = false;
68 virtual void PreEncodeFrameHook(::libaom_test::VideoSource * /*video*/,
69 ::libaom_test::Encoder *encoder) {
70 if (!encoder_initialized_) {
71 SetTileSize(encoder);
72 encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
73 if (encoding_mode_ != ::libaom_test::kRealTime) {
74 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
75 encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
76 encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
77 encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 0);
78 } else {
79 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0);
80 encoder->Control(AV1E_SET_AQ_MODE, 3);
82 encoder_initialized_ = true;
86 virtual void SetTileSize(libaom_test::Encoder *encoder) {
87 // Encode 4 tile columns.
88 encoder->Control(AV1E_SET_TILE_COLUMNS, 2);
89 encoder->Control(AV1E_SET_TILE_ROWS, 0);
92 virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
93 size_enc_.push_back(pkt->data.frame.sz);
95 ::libaom_test::MD5 md5_enc;
96 md5_enc.Add(reinterpret_cast<uint8_t *>(pkt->data.frame.buf),
97 pkt->data.frame.sz);
98 md5_enc_.push_back(md5_enc.Get());
100 const aom_codec_err_t res = decoder_->DecodeFrame(
101 reinterpret_cast<uint8_t *>(pkt->data.frame.buf), pkt->data.frame.sz);
102 if (res != AOM_CODEC_OK) {
103 abort_ = true;
104 ASSERT_EQ(AOM_CODEC_OK, res);
106 const aom_image_t *img = decoder_->GetDxData().Next();
108 if (img) {
109 ::libaom_test::MD5 md5_res;
110 md5_res.Add(img);
111 md5_dec_.push_back(md5_res.Get());
115 void DoTest() {
116 ::libaom_test::YUVVideoSource video(
117 "niklas_640_480_30.yuv", AOM_IMG_FMT_I420, 640, 480, 30, 1, 15, 18);
118 cfg_.rc_target_bitrate = 1000;
120 // Encode using single thread.
121 cfg_.g_threads = 1;
122 init_flags_ = AOM_CODEC_USE_PSNR;
123 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
124 std::vector<size_t> single_thr_size_enc;
125 std::vector<std::string> single_thr_md5_enc;
126 std::vector<std::string> single_thr_md5_dec;
127 single_thr_size_enc = size_enc_;
128 single_thr_md5_enc = md5_enc_;
129 single_thr_md5_dec = md5_dec_;
130 size_enc_.clear();
131 md5_enc_.clear();
132 md5_dec_.clear();
134 // Encode using multiple threads.
135 cfg_.g_threads = 4;
136 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
137 std::vector<size_t> multi_thr_size_enc;
138 std::vector<std::string> multi_thr_md5_enc;
139 std::vector<std::string> multi_thr_md5_dec;
140 multi_thr_size_enc = size_enc_;
141 multi_thr_md5_enc = md5_enc_;
142 multi_thr_md5_dec = md5_dec_;
143 size_enc_.clear();
144 md5_enc_.clear();
145 md5_dec_.clear();
147 // Check that the vectors are equal.
148 ASSERT_EQ(single_thr_size_enc, multi_thr_size_enc);
149 ASSERT_EQ(single_thr_md5_enc, multi_thr_md5_enc);
150 ASSERT_EQ(single_thr_md5_dec, multi_thr_md5_dec);
153 bool encoder_initialized_;
154 ::libaom_test::TestMode encoding_mode_;
155 int set_cpu_used_;
156 ::libaom_test::Decoder *decoder_;
157 std::vector<size_t> size_enc_;
158 std::vector<std::string> md5_enc_;
159 std::vector<std::string> md5_dec_;
162 TEST_P(AVxEncoderThreadTest, EncoderResultTest) {
163 cfg_.large_scale_tile = 0;
164 decoder_->Control(AV1_SET_TILE_MODE, 0);
165 DoTest();
168 class AVxEncoderThreadTestLarge : public AVxEncoderThreadTest {};
170 TEST_P(AVxEncoderThreadTestLarge, EncoderResultTest) {
171 cfg_.large_scale_tile = 0;
172 decoder_->Control(AV1_SET_TILE_MODE, 0);
173 DoTest();
176 // For AV1, only test speed 0 to 3.
177 AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTest,
178 ::testing::Values(::libaom_test::kTwoPassGood,
179 ::libaom_test::kOnePassGood),
180 ::testing::Range(2, 4));
182 AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTestLarge,
183 ::testing::Values(::libaom_test::kTwoPassGood,
184 ::libaom_test::kOnePassGood),
185 ::testing::Range(0, 2));
187 class AVxEncoderThreadLSTest : public AVxEncoderThreadTest {
188 virtual void SetTileSize(libaom_test::Encoder *encoder) {
189 encoder->Control(AV1E_SET_TILE_COLUMNS, 1);
190 // TODO(geza): Start using multiple tile rows when the multi-threaded
191 // encoder can handle them
192 encoder->Control(AV1E_SET_TILE_ROWS, 32);
196 TEST_P(AVxEncoderThreadLSTest, DISABLED_EncoderResultTest) {
197 cfg_.large_scale_tile = 1;
198 decoder_->Control(AV1_SET_TILE_MODE, 1);
199 DoTest();
202 class AVxEncoderThreadLSTestLarge : public AVxEncoderThreadLSTest {};
204 TEST_P(AVxEncoderThreadLSTestLarge, DISABLED_EncoderResultTest) {
205 cfg_.large_scale_tile = 1;
206 decoder_->Control(AV1_SET_TILE_MODE, 1);
207 DoTest();
210 AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadLSTest,
211 ::testing::Values(::libaom_test::kTwoPassGood,
212 ::libaom_test::kOnePassGood),
213 ::testing::Range(2, 4));
214 AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadLSTestLarge,
215 ::testing::Values(::libaom_test::kTwoPassGood,
216 ::libaom_test::kOnePassGood),
217 ::testing::Range(0, 2));
218 } // namespace