blob: 2ae3c0d17984a45a9844ff57da0c33ed5b5eedae [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.
10*/
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
Sebastien Alaiwan4322bc12017-06-05 10:18:28 +020023 : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>,
24 public ::libaom_test::EncoderTest {
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080025 protected:
Yaowu Xuf883b422016-08-30 14:01:10 -070026 AVxEncoderThreadTest()
clang-format3a826f12016-08-11 17:46:05 -070027 : EncoderTest(GET_PARAM(0)), encoder_initialized_(false),
28 encoding_mode_(GET_PARAM(1)), set_cpu_used_(GET_PARAM(2)) {
Yaowu Xuf883b422016-08-30 14:01:10 -070029 init_flags_ = AOM_CODEC_USE_PSNR;
30 aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080031 cfg.w = 1280;
32 cfg.h = 720;
Sebastien Alaiwan8a65f9f2017-06-23 07:28:44 +020033 cfg.allow_lowbitdepth = 1;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080034 decoder_ = codec_->CreateDecoder(cfg, 0);
Yunqing Wangeeb08a92017-07-07 21:25:18 -070035#if CONFIG_AV1
Yaowu Xuf883b422016-08-30 14:01:10 -070036 if (decoder_->IsAV1()) {
37 decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
38 decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070039 }
40#endif
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080041
Geza Lore688f9ed2016-05-04 11:25:01 +010042 size_enc_.clear();
43 md5_dec_.clear();
44 md5_enc_.clear();
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080045 }
Yaowu Xuf883b422016-08-30 14:01:10 -070046 virtual ~AVxEncoderThreadTest() { delete decoder_; }
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080047
48 virtual void SetUp() {
49 InitializeConfig();
50 SetMode(encoding_mode_);
51
Yaowu Xuc27fc142016-08-22 16:08:15 -070052 if (encoding_mode_ != ::libaom_test::kRealTime) {
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080053 cfg_.g_lag_in_frames = 3;
Yaowu Xuf883b422016-08-30 14:01:10 -070054 cfg_.rc_end_usage = AOM_VBR;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080055 cfg_.rc_2pass_vbr_minsection_pct = 5;
hui sub1a38712016-03-14 16:32:41 -070056 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080057 } else {
58 cfg_.g_lag_in_frames = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -070059 cfg_.rc_end_usage = AOM_CBR;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080060 cfg_.g_error_resilient = 1;
61 }
62 cfg_.rc_max_quantizer = 56;
63 cfg_.rc_min_quantizer = 0;
64 }
65
Alex Converse587a0b32015-03-05 11:47:21 -080066 virtual void BeginPassHook(unsigned int /*pass*/) {
67 encoder_initialized_ = false;
68 }
69
Yaowu Xuc27fc142016-08-22 16:08:15 -070070 virtual void PreEncodeFrameHook(::libaom_test::VideoSource * /*video*/,
71 ::libaom_test::Encoder *encoder) {
Alex Converse587a0b32015-03-05 11:47:21 -080072 if (!encoder_initialized_) {
Yunqing Wangeeb08a92017-07-07 21:25:18 -070073 SetTileSize(encoder);
Ryan Lei9b02b0e2017-01-30 15:52:20 -080074#if CONFIG_LOOPFILTERING_ACROSS_TILES
Ryan Lei7386eda2016-12-08 21:08:31 -080075 encoder->Control(AV1E_SET_TILE_LOOPFILTER, 0);
Ryan Lei9b02b0e2017-01-30 15:52:20 -080076#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
Yaowu Xuf883b422016-08-30 14:01:10 -070077 encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
Yaowu Xuc27fc142016-08-22 16:08:15 -070078 if (encoding_mode_ != ::libaom_test::kRealTime) {
Yaowu Xuf883b422016-08-30 14:01:10 -070079 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
80 encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
81 encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
Yunqing Wang8c1e57c2016-10-25 15:15:23 -070082 encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 0);
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080083 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -070084 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0);
85 encoder->Control(AV1E_SET_AQ_MODE, 3);
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080086 }
Alex Converse587a0b32015-03-05 11:47:21 -080087 encoder_initialized_ = true;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080088 }
89 }
90
Yunqing Wangeeb08a92017-07-07 21:25:18 -070091 virtual void SetTileSize(libaom_test::Encoder *encoder) {
92 // Encode 4 tile columns.
93 encoder->Control(AV1E_SET_TILE_COLUMNS, 2);
94 encoder->Control(AV1E_SET_TILE_ROWS, 0);
95 }
96
Yaowu Xuf883b422016-08-30 14:01:10 -070097 virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
Geza Lore688f9ed2016-05-04 11:25:01 +010098 size_enc_.push_back(pkt->data.frame.sz);
99
Yaowu Xuc27fc142016-08-22 16:08:15 -0700100 ::libaom_test::MD5 md5_enc;
clang-format3a826f12016-08-11 17:46:05 -0700101 md5_enc.Add(reinterpret_cast<uint8_t *>(pkt->data.frame.buf),
Geza Lore688f9ed2016-05-04 11:25:01 +0100102 pkt->data.frame.sz);
103 md5_enc_.push_back(md5_enc.Get());
104
Yaowu Xuf883b422016-08-30 14:01:10 -0700105 const aom_codec_err_t res = decoder_->DecodeFrame(
clang-format3a826f12016-08-11 17:46:05 -0700106 reinterpret_cast<uint8_t *>(pkt->data.frame.buf), pkt->data.frame.sz);
Yaowu Xuf883b422016-08-30 14:01:10 -0700107 if (res != AOM_CODEC_OK) {
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800108 abort_ = true;
Yaowu Xuf883b422016-08-30 14:01:10 -0700109 ASSERT_EQ(AOM_CODEC_OK, res);
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800110 }
Yaowu Xuf883b422016-08-30 14:01:10 -0700111 const aom_image_t *img = decoder_->GetDxData().Next();
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800112
113 if (img) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700114 ::libaom_test::MD5 md5_res;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800115 md5_res.Add(img);
Geza Lore688f9ed2016-05-04 11:25:01 +0100116 md5_dec_.push_back(md5_res.Get());
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800117 }
118 }
119
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700120 void DoTest() {
Debargha Mukherjee27738722017-10-13 16:27:09 -0700121 ::libaom_test::YUVVideoSource video(
122 "niklas_640_480_30.yuv", AOM_IMG_FMT_I420, 640, 480, 30, 1, 15, 18);
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700123 cfg_.rc_target_bitrate = 1000;
124
125 // Encode using single thread.
126 cfg_.g_threads = 1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700127 init_flags_ = AOM_CODEC_USE_PSNR;
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700128 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
129 std::vector<size_t> single_thr_size_enc;
130 std::vector<std::string> single_thr_md5_enc;
131 std::vector<std::string> single_thr_md5_dec;
132 single_thr_size_enc = size_enc_;
133 single_thr_md5_enc = md5_enc_;
134 single_thr_md5_dec = md5_dec_;
135 size_enc_.clear();
136 md5_enc_.clear();
137 md5_dec_.clear();
138
139 // Encode using multiple threads.
140 cfg_.g_threads = 4;
141 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
142 std::vector<size_t> multi_thr_size_enc;
143 std::vector<std::string> multi_thr_md5_enc;
144 std::vector<std::string> multi_thr_md5_dec;
145 multi_thr_size_enc = size_enc_;
146 multi_thr_md5_enc = md5_enc_;
147 multi_thr_md5_dec = md5_dec_;
148 size_enc_.clear();
149 md5_enc_.clear();
150 md5_dec_.clear();
151
152 // Check that the vectors are equal.
153 ASSERT_EQ(single_thr_size_enc, multi_thr_size_enc);
154 ASSERT_EQ(single_thr_md5_enc, multi_thr_md5_enc);
155 ASSERT_EQ(single_thr_md5_dec, multi_thr_md5_dec);
156 }
157
Alex Converse587a0b32015-03-05 11:47:21 -0800158 bool encoder_initialized_;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700159 ::libaom_test::TestMode encoding_mode_;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800160 int set_cpu_used_;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700161 ::libaom_test::Decoder *decoder_;
Geza Lore688f9ed2016-05-04 11:25:01 +0100162 std::vector<size_t> size_enc_;
163 std::vector<std::string> md5_enc_;
164 std::vector<std::string> md5_dec_;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800165};
166
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700167TEST_P(AVxEncoderThreadTest, EncoderResultTest) {
168#if CONFIG_AV1 && CONFIG_EXT_TILE
169 cfg_.large_scale_tile = 0;
170#endif // CONFIG_AV1 && CONFIG_EXT_TILE
171 DoTest();
172}
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800173
Yaowu Xuf883b422016-08-30 14:01:10 -0700174class AVxEncoderThreadTestLarge : public AVxEncoderThreadTest {};
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800175
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700176TEST_P(AVxEncoderThreadTestLarge, EncoderResultTest) {
177#if CONFIG_AV1 && CONFIG_EXT_TILE
178 cfg_.large_scale_tile = 0;
179#endif // CONFIG_AV1 && CONFIG_EXT_TILE
180 DoTest();
181}
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800182
Yunqing Wang840b2be2016-12-13 15:15:28 -0800183// For AV1, only test speed 0 to 3.
Yaowu Xuf883b422016-08-30 14:01:10 -0700184AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTest,
185 ::testing::Values(::libaom_test::kTwoPassGood,
186 ::libaom_test::kOnePassGood),
Yunqing Wang840b2be2016-12-13 15:15:28 -0800187 ::testing::Range(2, 4));
Jingning Han41be09a2015-08-19 14:13:18 -0700188
Yaowu Xuf883b422016-08-30 14:01:10 -0700189AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTestLarge,
190 ::testing::Values(::libaom_test::kTwoPassGood,
191 ::libaom_test::kOnePassGood),
Yunqing Wang840b2be2016-12-13 15:15:28 -0800192 ::testing::Range(0, 2));
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700193
194#if CONFIG_AV1 && CONFIG_EXT_TILE
195class AVxEncoderThreadLSTest : public AVxEncoderThreadTest {
196 virtual void SetTileSize(libaom_test::Encoder *encoder) {
197 encoder->Control(AV1E_SET_TILE_COLUMNS, 1);
198 // TODO(geza): Start using multiple tile rows when the multi-threaded
199 // encoder can handle them
200 encoder->Control(AV1E_SET_TILE_ROWS, 32);
201 }
202};
203
204TEST_P(AVxEncoderThreadLSTest, EncoderResultTest) {
205 cfg_.large_scale_tile = 1;
206 DoTest();
207}
208
209class AVxEncoderThreadLSTestLarge : public AVxEncoderThreadLSTest {};
210
211TEST_P(AVxEncoderThreadLSTestLarge, EncoderResultTest) {
212 cfg_.large_scale_tile = 1;
213 DoTest();
214}
215
216AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadLSTest,
217 ::testing::Values(::libaom_test::kTwoPassGood,
218 ::libaom_test::kOnePassGood),
219 ::testing::Range(2, 4));
220AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadLSTestLarge,
221 ::testing::Values(::libaom_test::kTwoPassGood,
222 ::libaom_test::kOnePassGood),
223 ::testing::Range(0, 2));
224#endif // CONFIG_AV1 && CONFIG_EXT_TILE
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800225} // namespace