blob: 306cc2f3a85802ada61261d998b0a13a4faa9cdc [file] [log] [blame]
Yunqing Wang7c2c2be2014-12-16 11:10:20 -08001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yunqing Wang7c2c2be2014-12-16 11:10:20 -08003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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.
Johann123e8a62017-12-28 14:40:49 -080010 */
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080011
12#include <string>
13#include <vector>
Tom Finegan7a07ece2017-02-07 17:14:05 -080014#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080015#include "test/codec_factory.h"
16#include "test/encode_test_driver.h"
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080017#include "test/md5_helper.h"
James Zern7839d032015-02-25 19:09:59 -080018#include "test/util.h"
Debargha Mukherjee27738722017-10-13 16:27:09 -070019#include "test/yuv_video_source.h"
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080020
21namespace {
Yaowu Xuf883b422016-08-30 14:01:10 -070022class AVxEncoderThreadTest
Ravi Chaudhary2aaeed82018-09-27 11:45:55 +053023 : public ::libaom_test::CodecTestWith5Params<libaom_test::TestMode, int,
24 int, int, int>,
Sebastien Alaiwan4322bc12017-06-05 10:18:28 +020025 public ::libaom_test::EncoderTest {
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080026 protected:
Yaowu Xuf883b422016-08-30 14:01:10 -070027 AVxEncoderThreadTest()
clang-format3a826f12016-08-11 17:46:05 -070028 : EncoderTest(GET_PARAM(0)), encoder_initialized_(false),
Ravi Chaudharye426b012018-07-18 17:56:35 +053029 encoding_mode_(GET_PARAM(1)), set_cpu_used_(GET_PARAM(2)),
Ravi Chaudhary2aaeed82018-09-27 11:45:55 +053030 tile_cols_(GET_PARAM(3)), tile_rows_(GET_PARAM(4)),
31 row_mt_(GET_PARAM(5)) {
Yaowu Xuf883b422016-08-30 14:01:10 -070032 init_flags_ = AOM_CODEC_USE_PSNR;
33 aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080034 cfg.w = 1280;
35 cfg.h = 720;
Sebastien Alaiwan8a65f9f2017-06-23 07:28:44 +020036 cfg.allow_lowbitdepth = 1;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080037 decoder_ = codec_->CreateDecoder(cfg, 0);
Yaowu Xuf883b422016-08-30 14:01:10 -070038 if (decoder_->IsAV1()) {
39 decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
40 decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070041 }
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080042
Geza Lore688f9ed2016-05-04 11:25:01 +010043 size_enc_.clear();
44 md5_dec_.clear();
45 md5_enc_.clear();
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080046 }
Yaowu Xuf883b422016-08-30 14:01:10 -070047 virtual ~AVxEncoderThreadTest() { delete decoder_; }
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080048
49 virtual void SetUp() {
50 InitializeConfig();
51 SetMode(encoding_mode_);
52
Yaowu Xuc27fc142016-08-22 16:08:15 -070053 if (encoding_mode_ != ::libaom_test::kRealTime) {
Yunqing Wang7d447f52018-09-10 17:22:11 -070054 cfg_.g_lag_in_frames = 5;
Yaowu Xuf883b422016-08-30 14:01:10 -070055 cfg_.rc_end_usage = AOM_VBR;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080056 cfg_.rc_2pass_vbr_minsection_pct = 5;
hui sub1a38712016-03-14 16:32:41 -070057 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080058 } else {
59 cfg_.g_lag_in_frames = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -070060 cfg_.rc_end_usage = AOM_CBR;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080061 cfg_.g_error_resilient = 1;
62 }
63 cfg_.rc_max_quantizer = 56;
64 cfg_.rc_min_quantizer = 0;
65 }
66
Alex Converse587a0b32015-03-05 11:47:21 -080067 virtual void BeginPassHook(unsigned int /*pass*/) {
68 encoder_initialized_ = false;
69 }
70
Yaowu Xuc27fc142016-08-22 16:08:15 -070071 virtual void PreEncodeFrameHook(::libaom_test::VideoSource * /*video*/,
72 ::libaom_test::Encoder *encoder) {
Alex Converse587a0b32015-03-05 11:47:21 -080073 if (!encoder_initialized_) {
Yunqing Wangeeb08a92017-07-07 21:25:18 -070074 SetTileSize(encoder);
Yaowu Xuf883b422016-08-30 14:01:10 -070075 encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
Ravi Chaudhary0ec03a42018-08-17 18:53:28 +053076 encoder->Control(AV1E_SET_ROW_MT, row_mt_);
Yaowu Xuc27fc142016-08-22 16:08:15 -070077 if (encoding_mode_ != ::libaom_test::kRealTime) {
Yaowu Xuf883b422016-08-30 14:01:10 -070078 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
79 encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
80 encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
Yunqing Wang8c1e57c2016-10-25 15:15:23 -070081 encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 0);
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080082 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -070083 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0);
84 encoder->Control(AV1E_SET_AQ_MODE, 3);
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080085 }
Alex Converse587a0b32015-03-05 11:47:21 -080086 encoder_initialized_ = true;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080087 }
88 }
89
Yunqing Wangeeb08a92017-07-07 21:25:18 -070090 virtual void SetTileSize(libaom_test::Encoder *encoder) {
Ravi Chaudharye426b012018-07-18 17:56:35 +053091 encoder->Control(AV1E_SET_TILE_COLUMNS, tile_cols_);
92 encoder->Control(AV1E_SET_TILE_ROWS, tile_rows_);
Yunqing Wangeeb08a92017-07-07 21:25:18 -070093 }
94
Yaowu Xuf883b422016-08-30 14:01:10 -070095 virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
Geza Lore688f9ed2016-05-04 11:25:01 +010096 size_enc_.push_back(pkt->data.frame.sz);
97
Yaowu Xuc27fc142016-08-22 16:08:15 -070098 ::libaom_test::MD5 md5_enc;
clang-format3a826f12016-08-11 17:46:05 -070099 md5_enc.Add(reinterpret_cast<uint8_t *>(pkt->data.frame.buf),
Geza Lore688f9ed2016-05-04 11:25:01 +0100100 pkt->data.frame.sz);
101 md5_enc_.push_back(md5_enc.Get());
102
Yaowu Xuf883b422016-08-30 14:01:10 -0700103 const aom_codec_err_t res = decoder_->DecodeFrame(
clang-format3a826f12016-08-11 17:46:05 -0700104 reinterpret_cast<uint8_t *>(pkt->data.frame.buf), pkt->data.frame.sz);
Yaowu Xuf883b422016-08-30 14:01:10 -0700105 if (res != AOM_CODEC_OK) {
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800106 abort_ = true;
Yaowu Xuf883b422016-08-30 14:01:10 -0700107 ASSERT_EQ(AOM_CODEC_OK, res);
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800108 }
Yaowu Xuf883b422016-08-30 14:01:10 -0700109 const aom_image_t *img = decoder_->GetDxData().Next();
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800110
111 if (img) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700112 ::libaom_test::MD5 md5_res;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800113 md5_res.Add(img);
Geza Lore688f9ed2016-05-04 11:25:01 +0100114 md5_dec_.push_back(md5_res.Get());
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800115 }
116 }
117
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700118 void DoTest() {
Debargha Mukherjee27738722017-10-13 16:27:09 -0700119 ::libaom_test::YUVVideoSource video(
Yunqing Wang7d447f52018-09-10 17:22:11 -0700120 "niklas_640_480_30.yuv", AOM_IMG_FMT_I420, 640, 480, 30, 1, 15, 21);
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700121 cfg_.rc_target_bitrate = 1000;
122
Ravi Chaudhary2aaeed82018-09-27 11:45:55 +0530123 if (row_mt_ == 0) {
124 // Encode using single thread.
125 cfg_.g_threads = 1;
126 init_flags_ = AOM_CODEC_USE_PSNR;
127 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
128 std::vector<size_t> single_thr_size_enc;
129 std::vector<std::string> single_thr_md5_enc;
130 std::vector<std::string> single_thr_md5_dec;
131 single_thr_size_enc = size_enc_;
132 single_thr_md5_enc = md5_enc_;
133 single_thr_md5_dec = md5_dec_;
134 size_enc_.clear();
135 md5_enc_.clear();
136 md5_dec_.clear();
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700137
Ravi Chaudhary2aaeed82018-09-27 11:45:55 +0530138 // Encode using multiple threads.
139 cfg_.g_threads = 4;
140 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
141 std::vector<size_t> multi_thr_size_enc;
142 std::vector<std::string> multi_thr_md5_enc;
143 std::vector<std::string> multi_thr_md5_dec;
144 multi_thr_size_enc = size_enc_;
145 multi_thr_md5_enc = md5_enc_;
146 multi_thr_md5_dec = md5_dec_;
147 size_enc_.clear();
148 md5_enc_.clear();
149 md5_dec_.clear();
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700150
Ravi Chaudhary2aaeed82018-09-27 11:45:55 +0530151 // Check that the vectors are equal.
152 ASSERT_EQ(single_thr_size_enc, multi_thr_size_enc);
153 ASSERT_EQ(single_thr_md5_enc, multi_thr_md5_enc);
154 ASSERT_EQ(single_thr_md5_dec, multi_thr_md5_dec);
155 } else if (row_mt_ == 1) {
156 // Encode using multiple threads row-mt enabled.
157 cfg_.g_threads = 2;
158 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
159 std::vector<size_t> multi_thr2_row_mt_size_enc;
160 std::vector<std::string> multi_thr2_row_mt_md5_enc;
161 std::vector<std::string> multi_thr2_row_mt_md5_dec;
162 multi_thr2_row_mt_size_enc = size_enc_;
163 multi_thr2_row_mt_md5_enc = md5_enc_;
164 multi_thr2_row_mt_md5_dec = md5_dec_;
165 size_enc_.clear();
166 md5_enc_.clear();
167 md5_dec_.clear();
Ravi Chaudhary0ec03a42018-08-17 18:53:28 +0530168
Ravi Chaudhary2aaeed82018-09-27 11:45:55 +0530169 // Disable threads=3 test for now to reduce the time so that the nightly
170 // test would not time out.
171 // cfg_.g_threads = 3;
172 // ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
173 // std::vector<size_t> multi_thr3_row_mt_size_enc;
174 // std::vector<std::string> multi_thr3_row_mt_md5_enc;
175 // std::vector<std::string> multi_thr3_row_mt_md5_dec;
176 // multi_thr3_row_mt_size_enc = size_enc_;
177 // multi_thr3_row_mt_md5_enc = md5_enc_;
178 // multi_thr3_row_mt_md5_dec = md5_dec_;
179 // size_enc_.clear();
180 // md5_enc_.clear();
181 // md5_dec_.clear();
182 // Check that the vectors are equal.
183 // ASSERT_EQ(multi_thr3_row_mt_size_enc, multi_thr2_row_mt_size_enc);
184 // ASSERT_EQ(multi_thr3_row_mt_md5_enc, multi_thr2_row_mt_md5_enc);
185 // ASSERT_EQ(multi_thr3_row_mt_md5_dec, multi_thr2_row_mt_md5_dec);
Ravi Chaudhary0ec03a42018-08-17 18:53:28 +0530186
Ravi Chaudhary2aaeed82018-09-27 11:45:55 +0530187 cfg_.g_threads = 4;
188 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
189 std::vector<size_t> multi_thr4_row_mt_size_enc;
190 std::vector<std::string> multi_thr4_row_mt_md5_enc;
191 std::vector<std::string> multi_thr4_row_mt_md5_dec;
192 multi_thr4_row_mt_size_enc = size_enc_;
193 multi_thr4_row_mt_md5_enc = md5_enc_;
194 multi_thr4_row_mt_md5_dec = md5_dec_;
195 size_enc_.clear();
196 md5_enc_.clear();
197 md5_dec_.clear();
Ravi Chaudhary0ec03a42018-08-17 18:53:28 +0530198
Ravi Chaudhary2aaeed82018-09-27 11:45:55 +0530199 // Check that the vectors are equal.
200 ASSERT_EQ(multi_thr4_row_mt_size_enc, multi_thr2_row_mt_size_enc);
201 ASSERT_EQ(multi_thr4_row_mt_md5_enc, multi_thr2_row_mt_md5_enc);
202 ASSERT_EQ(multi_thr4_row_mt_md5_dec, multi_thr2_row_mt_md5_dec);
203 }
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700204 }
205
Alex Converse587a0b32015-03-05 11:47:21 -0800206 bool encoder_initialized_;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700207 ::libaom_test::TestMode encoding_mode_;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800208 int set_cpu_used_;
Ravi Chaudharye426b012018-07-18 17:56:35 +0530209 int tile_cols_;
210 int tile_rows_;
Ravi Chaudhary0ec03a42018-08-17 18:53:28 +0530211 int row_mt_;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700212 ::libaom_test::Decoder *decoder_;
Geza Lore688f9ed2016-05-04 11:25:01 +0100213 std::vector<size_t> size_enc_;
214 std::vector<std::string> md5_enc_;
215 std::vector<std::string> md5_dec_;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800216};
217
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700218TEST_P(AVxEncoderThreadTest, EncoderResultTest) {
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700219 cfg_.large_scale_tile = 0;
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800220 decoder_->Control(AV1_SET_TILE_MODE, 0);
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700221 DoTest();
222}
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800223
Yaowu Xuf883b422016-08-30 14:01:10 -0700224class AVxEncoderThreadTestLarge : public AVxEncoderThreadTest {};
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800225
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700226TEST_P(AVxEncoderThreadTestLarge, EncoderResultTest) {
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700227 cfg_.large_scale_tile = 0;
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800228 decoder_->Control(AV1_SET_TILE_MODE, 0);
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700229 DoTest();
230}
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800231
Yunqing Wang840b2be2016-12-13 15:15:28 -0800232// For AV1, only test speed 0 to 3.
Yunqing Wangb18fd062018-09-04 15:55:45 -0700233// Here test cpu_used 2 and 3
Yaowu Xuf883b422016-08-30 14:01:10 -0700234AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTest,
Yunqing Wang7d447f52018-09-10 17:22:11 -0700235 ::testing::Values(::libaom_test::kTwoPassGood),
236 ::testing::Range(2, 4), ::testing::Values(0, 2),
Ravi Chaudhary2aaeed82018-09-27 11:45:55 +0530237 ::testing::Values(0, 1), ::testing::Values(0, 1));
Jingning Han41be09a2015-08-19 14:13:18 -0700238
Yunqing Wangb18fd062018-09-04 15:55:45 -0700239// Test cpu_used 0 and 1.
Yaowu Xuf883b422016-08-30 14:01:10 -0700240AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTestLarge,
241 ::testing::Values(::libaom_test::kTwoPassGood,
242 ::libaom_test::kOnePassGood),
Yunqing Wangb18fd062018-09-04 15:55:45 -0700243 ::testing::Range(0, 2), ::testing::Values(0, 1, 2, 6),
Ravi Chaudhary2aaeed82018-09-27 11:45:55 +0530244 ::testing::Values(0, 1, 2, 6),
245 ::testing::Values(0, 1));
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700246
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700247class AVxEncoderThreadLSTest : public AVxEncoderThreadTest {
248 virtual void SetTileSize(libaom_test::Encoder *encoder) {
Ravi Chaudharye426b012018-07-18 17:56:35 +0530249 encoder->Control(AV1E_SET_TILE_COLUMNS, tile_cols_);
250 encoder->Control(AV1E_SET_TILE_ROWS, tile_rows_);
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700251 }
252};
253
Yunqing Wangce8f4812018-06-25 15:17:44 -0700254TEST_P(AVxEncoderThreadLSTest, EncoderResultTest) {
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700255 cfg_.large_scale_tile = 1;
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800256 decoder_->Control(AV1_SET_TILE_MODE, 1);
Yunqing Wangce8f4812018-06-25 15:17:44 -0700257 decoder_->Control(AV1D_EXT_TILE_DEBUG, 1);
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700258 DoTest();
259}
260
261class AVxEncoderThreadLSTestLarge : public AVxEncoderThreadLSTest {};
262
Yunqing Wangce8f4812018-06-25 15:17:44 -0700263TEST_P(AVxEncoderThreadLSTestLarge, EncoderResultTest) {
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700264 cfg_.large_scale_tile = 1;
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800265 decoder_->Control(AV1_SET_TILE_MODE, 1);
Yunqing Wangce8f4812018-06-25 15:17:44 -0700266 decoder_->Control(AV1D_EXT_TILE_DEBUG, 1);
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700267 DoTest();
268}
269
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700270AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadLSTestLarge,
271 ::testing::Values(::libaom_test::kTwoPassGood,
272 ::libaom_test::kOnePassGood),
Yunqing Wangb18fd062018-09-04 15:55:45 -0700273 ::testing::Range(0, 4), ::testing::Values(0, 6),
Ravi Chaudhary2aaeed82018-09-27 11:45:55 +0530274 ::testing::Values(0, 6), ::testing::Values(0, 1));
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800275} // namespace