blob: 5b519f8febaefb0464211a5930456530ea5b9fab [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"
19#include "test/y4m_video_source.h"
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080020
21namespace {
Yaowu Xuf883b422016-08-30 14:01:10 -070022class AVxEncoderThreadTest
Yaowu Xuc27fc142016-08-22 16:08:15 -070023 : public ::libaom_test::EncoderTest,
24 public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int> {
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;
33 decoder_ = codec_->CreateDecoder(cfg, 0);
Yaowu Xuf883b422016-08-30 14:01:10 -070034#if CONFIG_AV1 && CONFIG_EXT_TILE
35 if (decoder_->IsAV1()) {
36 decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
37 decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070038 }
39#endif
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080040
Geza Lore688f9ed2016-05-04 11:25:01 +010041 size_enc_.clear();
42 md5_dec_.clear();
43 md5_enc_.clear();
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080044 }
Yaowu Xuf883b422016-08-30 14:01:10 -070045 virtual ~AVxEncoderThreadTest() { delete decoder_; }
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080046
47 virtual void SetUp() {
48 InitializeConfig();
49 SetMode(encoding_mode_);
50
Yaowu Xuc27fc142016-08-22 16:08:15 -070051 if (encoding_mode_ != ::libaom_test::kRealTime) {
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080052 cfg_.g_lag_in_frames = 3;
Yaowu Xuf883b422016-08-30 14:01:10 -070053 cfg_.rc_end_usage = AOM_VBR;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080054 cfg_.rc_2pass_vbr_minsection_pct = 5;
hui sub1a38712016-03-14 16:32:41 -070055 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080056 } else {
57 cfg_.g_lag_in_frames = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -070058 cfg_.rc_end_usage = AOM_CBR;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080059 cfg_.g_error_resilient = 1;
60 }
61 cfg_.rc_max_quantizer = 56;
62 cfg_.rc_min_quantizer = 0;
63 }
64
Alex Converse587a0b32015-03-05 11:47:21 -080065 virtual void BeginPassHook(unsigned int /*pass*/) {
66 encoder_initialized_ = false;
67 }
68
Yaowu Xuc27fc142016-08-22 16:08:15 -070069 virtual void PreEncodeFrameHook(::libaom_test::VideoSource * /*video*/,
70 ::libaom_test::Encoder *encoder) {
Alex Converse587a0b32015-03-05 11:47:21 -080071 if (!encoder_initialized_) {
Yaowu Xuf883b422016-08-30 14:01:10 -070072#if CONFIG_AV1 && CONFIG_EXT_TILE
73 encoder->Control(AV1E_SET_TILE_COLUMNS, 1);
74 if (codec_ == &libaom_test::kAV1) {
Geza Lore855b6d72016-05-06 13:27:52 +010075 // TODO(geza): Start using multiple tile rows when the multi-threaded
76 // encoder can handle them
Yaowu Xuf883b422016-08-30 14:01:10 -070077 encoder->Control(AV1E_SET_TILE_ROWS, 32);
Geza Lore855b6d72016-05-06 13:27:52 +010078 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -070079 encoder->Control(AV1E_SET_TILE_ROWS, 0);
Geza Lore855b6d72016-05-06 13:27:52 +010080 }
Geza Lore688f9ed2016-05-04 11:25:01 +010081#else
82 // Encode 4 tile columns.
Yaowu Xuf883b422016-08-30 14:01:10 -070083 encoder->Control(AV1E_SET_TILE_COLUMNS, 2);
84 encoder->Control(AV1E_SET_TILE_ROWS, 0);
85#endif // CONFIG_AV1 && CONFIG_EXT_TILE
Ryan Lei9b02b0e2017-01-30 15:52:20 -080086#if CONFIG_LOOPFILTERING_ACROSS_TILES
Ryan Lei7386eda2016-12-08 21:08:31 -080087 encoder->Control(AV1E_SET_TILE_LOOPFILTER, 0);
Ryan Lei9b02b0e2017-01-30 15:52:20 -080088#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
Yaowu Xuf883b422016-08-30 14:01:10 -070089 encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
Yaowu Xuc27fc142016-08-22 16:08:15 -070090 if (encoding_mode_ != ::libaom_test::kRealTime) {
Yaowu Xuf883b422016-08-30 14:01:10 -070091 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
92 encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
93 encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
Yunqing Wang8c1e57c2016-10-25 15:15:23 -070094 encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 0);
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080095 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -070096 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0);
97 encoder->Control(AV1E_SET_AQ_MODE, 3);
Yunqing Wang7c2c2be2014-12-16 11:10:20 -080098 }
Alex Converse587a0b32015-03-05 11:47:21 -080099 encoder_initialized_ = true;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800100 }
101 }
102
Yaowu Xuf883b422016-08-30 14:01:10 -0700103 virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
Geza Lore688f9ed2016-05-04 11:25:01 +0100104 size_enc_.push_back(pkt->data.frame.sz);
105
Yaowu Xuc27fc142016-08-22 16:08:15 -0700106 ::libaom_test::MD5 md5_enc;
clang-format3a826f12016-08-11 17:46:05 -0700107 md5_enc.Add(reinterpret_cast<uint8_t *>(pkt->data.frame.buf),
Geza Lore688f9ed2016-05-04 11:25:01 +0100108 pkt->data.frame.sz);
109 md5_enc_.push_back(md5_enc.Get());
110
Yaowu Xuf883b422016-08-30 14:01:10 -0700111 const aom_codec_err_t res = decoder_->DecodeFrame(
clang-format3a826f12016-08-11 17:46:05 -0700112 reinterpret_cast<uint8_t *>(pkt->data.frame.buf), pkt->data.frame.sz);
Yaowu Xuf883b422016-08-30 14:01:10 -0700113 if (res != AOM_CODEC_OK) {
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800114 abort_ = true;
Yaowu Xuf883b422016-08-30 14:01:10 -0700115 ASSERT_EQ(AOM_CODEC_OK, res);
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800116 }
Yaowu Xuf883b422016-08-30 14:01:10 -0700117 const aom_image_t *img = decoder_->GetDxData().Next();
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800118
119 if (img) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700120 ::libaom_test::MD5 md5_res;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800121 md5_res.Add(img);
Geza Lore688f9ed2016-05-04 11:25:01 +0100122 md5_dec_.push_back(md5_res.Get());
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800123 }
124 }
125
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700126 void DoTest() {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700127 ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 15, 18);
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700128 cfg_.rc_target_bitrate = 1000;
129
130 // Encode using single thread.
131 cfg_.g_threads = 1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700132 init_flags_ = AOM_CODEC_USE_PSNR;
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700133 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
134 std::vector<size_t> single_thr_size_enc;
135 std::vector<std::string> single_thr_md5_enc;
136 std::vector<std::string> single_thr_md5_dec;
137 single_thr_size_enc = size_enc_;
138 single_thr_md5_enc = md5_enc_;
139 single_thr_md5_dec = md5_dec_;
140 size_enc_.clear();
141 md5_enc_.clear();
142 md5_dec_.clear();
143
144 // Encode using multiple threads.
145 cfg_.g_threads = 4;
146 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
147 std::vector<size_t> multi_thr_size_enc;
148 std::vector<std::string> multi_thr_md5_enc;
149 std::vector<std::string> multi_thr_md5_dec;
150 multi_thr_size_enc = size_enc_;
151 multi_thr_md5_enc = md5_enc_;
152 multi_thr_md5_dec = md5_dec_;
153 size_enc_.clear();
154 md5_enc_.clear();
155 md5_dec_.clear();
156
157 // Check that the vectors are equal.
158 ASSERT_EQ(single_thr_size_enc, multi_thr_size_enc);
159 ASSERT_EQ(single_thr_md5_enc, multi_thr_md5_enc);
160 ASSERT_EQ(single_thr_md5_dec, multi_thr_md5_dec);
161 }
162
Alex Converse587a0b32015-03-05 11:47:21 -0800163 bool encoder_initialized_;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700164 ::libaom_test::TestMode encoding_mode_;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800165 int set_cpu_used_;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700166 ::libaom_test::Decoder *decoder_;
Geza Lore688f9ed2016-05-04 11:25:01 +0100167 std::vector<size_t> size_enc_;
168 std::vector<std::string> md5_enc_;
169 std::vector<std::string> md5_dec_;
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800170};
171
Yaowu Xuf883b422016-08-30 14:01:10 -0700172TEST_P(AVxEncoderThreadTest, EncoderResultTest) { DoTest(); }
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
Yaowu Xuf883b422016-08-30 14:01:10 -0700176TEST_P(AVxEncoderThreadTestLarge, EncoderResultTest) { DoTest(); }
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800177
Yunqing Wang840b2be2016-12-13 15:15:28 -0800178// For AV1, only test speed 0 to 3.
Yaowu Xuf883b422016-08-30 14:01:10 -0700179AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTest,
180 ::testing::Values(::libaom_test::kTwoPassGood,
181 ::libaom_test::kOnePassGood),
Yunqing Wang840b2be2016-12-13 15:15:28 -0800182 ::testing::Range(2, 4));
Jingning Han41be09a2015-08-19 14:13:18 -0700183
Yaowu Xuf883b422016-08-30 14:01:10 -0700184AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTestLarge,
185 ::testing::Values(::libaom_test::kTwoPassGood,
186 ::libaom_test::kOnePassGood),
Yunqing Wang840b2be2016-12-13 15:15:28 -0800187 ::testing::Range(0, 2));
Yunqing Wang7c2c2be2014-12-16 11:10:20 -0800188} // namespace