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.
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"
22 class AVxEncoderThreadTest
23 : public ::libaom_test::CodecTestWith4Params
<libaom_test::TestMode
, int,
25 public ::libaom_test::EncoderTest
{
27 AVxEncoderThreadTest()
28 : EncoderTest(GET_PARAM(0)), encoder_initialized_(false),
29 encoding_mode_(GET_PARAM(1)), set_cpu_used_(GET_PARAM(2)),
30 tile_cols_(GET_PARAM(3)), tile_rows_(GET_PARAM(4)) {
31 init_flags_
= AOM_CODEC_USE_PSNR
;
32 aom_codec_dec_cfg_t cfg
= aom_codec_dec_cfg_t();
35 cfg
.allow_lowbitdepth
= 1;
36 decoder_
= codec_
->CreateDecoder(cfg
, 0);
37 if (decoder_
->IsAV1()) {
38 decoder_
->Control(AV1_SET_DECODE_TILE_ROW
, -1);
39 decoder_
->Control(AV1_SET_DECODE_TILE_COL
, -1);
46 virtual ~AVxEncoderThreadTest() { delete decoder_
; }
48 virtual void SetUp() {
50 SetMode(encoding_mode_
);
52 if (encoding_mode_
!= ::libaom_test::kRealTime
) {
53 cfg_
.g_lag_in_frames
= 5;
54 cfg_
.rc_end_usage
= AOM_VBR
;
55 cfg_
.rc_2pass_vbr_minsection_pct
= 5;
56 cfg_
.rc_2pass_vbr_maxsection_pct
= 2000;
58 cfg_
.g_lag_in_frames
= 0;
59 cfg_
.rc_end_usage
= AOM_CBR
;
60 cfg_
.g_error_resilient
= 1;
62 cfg_
.rc_max_quantizer
= 56;
63 cfg_
.rc_min_quantizer
= 0;
66 virtual void BeginPassHook(unsigned int /*pass*/) {
67 encoder_initialized_
= false;
70 virtual void PreEncodeFrameHook(::libaom_test::VideoSource
* /*video*/,
71 ::libaom_test::Encoder
*encoder
) {
72 if (!encoder_initialized_
) {
74 encoder
->Control(AOME_SET_CPUUSED
, set_cpu_used_
);
75 encoder
->Control(AV1E_SET_ROW_MT
, row_mt_
);
76 if (encoding_mode_
!= ::libaom_test::kRealTime
) {
77 encoder
->Control(AOME_SET_ENABLEAUTOALTREF
, 1);
78 encoder
->Control(AOME_SET_ARNR_MAXFRAMES
, 7);
79 encoder
->Control(AOME_SET_ARNR_STRENGTH
, 5);
80 encoder
->Control(AV1E_SET_FRAME_PARALLEL_DECODING
, 0);
82 encoder
->Control(AOME_SET_ENABLEAUTOALTREF
, 0);
83 encoder
->Control(AV1E_SET_AQ_MODE
, 3);
85 encoder_initialized_
= true;
89 virtual void SetTileSize(libaom_test::Encoder
*encoder
) {
90 encoder
->Control(AV1E_SET_TILE_COLUMNS
, tile_cols_
);
91 encoder
->Control(AV1E_SET_TILE_ROWS
, tile_rows_
);
94 virtual void FramePktHook(const aom_codec_cx_pkt_t
*pkt
) {
95 size_enc_
.push_back(pkt
->data
.frame
.sz
);
97 ::libaom_test::MD5 md5_enc
;
98 md5_enc
.Add(reinterpret_cast<uint8_t *>(pkt
->data
.frame
.buf
),
100 md5_enc_
.push_back(md5_enc
.Get());
102 const aom_codec_err_t res
= decoder_
->DecodeFrame(
103 reinterpret_cast<uint8_t *>(pkt
->data
.frame
.buf
), pkt
->data
.frame
.sz
);
104 if (res
!= AOM_CODEC_OK
) {
106 ASSERT_EQ(AOM_CODEC_OK
, res
);
108 const aom_image_t
*img
= decoder_
->GetDxData().Next();
111 ::libaom_test::MD5 md5_res
;
113 md5_dec_
.push_back(md5_res
.Get());
118 ::libaom_test::YUVVideoSource
video(
119 "niklas_640_480_30.yuv", AOM_IMG_FMT_I420
, 640, 480, 30, 1, 15, 21);
120 cfg_
.rc_target_bitrate
= 1000;
122 // Encode using single thread.
125 init_flags_
= AOM_CODEC_USE_PSNR
;
126 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
127 std::vector
<size_t> single_thr_size_enc
;
128 std::vector
<std::string
> single_thr_md5_enc
;
129 std::vector
<std::string
> single_thr_md5_dec
;
130 single_thr_size_enc
= size_enc_
;
131 single_thr_md5_enc
= md5_enc_
;
132 single_thr_md5_dec
= md5_dec_
;
137 // Encode using multiple threads.
139 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
140 std::vector
<size_t> multi_thr_size_enc
;
141 std::vector
<std::string
> multi_thr_md5_enc
;
142 std::vector
<std::string
> multi_thr_md5_dec
;
143 multi_thr_size_enc
= size_enc_
;
144 multi_thr_md5_enc
= md5_enc_
;
145 multi_thr_md5_dec
= md5_dec_
;
150 // Check that the vectors are equal.
151 ASSERT_EQ(single_thr_size_enc
, multi_thr_size_enc
);
152 ASSERT_EQ(single_thr_md5_enc
, multi_thr_md5_enc
);
153 ASSERT_EQ(single_thr_md5_dec
, multi_thr_md5_dec
);
155 // Encode using multiple threads row-mt enabled.
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_
;
169 // 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();
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);
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_
;
199 // 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
);
205 bool encoder_initialized_
;
206 ::libaom_test::TestMode encoding_mode_
;
211 ::libaom_test::Decoder
*decoder_
;
212 std::vector
<size_t> size_enc_
;
213 std::vector
<std::string
> md5_enc_
;
214 std::vector
<std::string
> md5_dec_
;
217 TEST_P(AVxEncoderThreadTest
, EncoderResultTest
) {
218 cfg_
.large_scale_tile
= 0;
219 decoder_
->Control(AV1_SET_TILE_MODE
, 0);
223 class AVxEncoderThreadTestLarge
: public AVxEncoderThreadTest
{};
225 TEST_P(AVxEncoderThreadTestLarge
, EncoderResultTest
) {
226 cfg_
.large_scale_tile
= 0;
227 decoder_
->Control(AV1_SET_TILE_MODE
, 0);
231 // For AV1, only test speed 0 to 3.
232 // Here test cpu_used 2 and 3
233 AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTest
,
234 ::testing::Values(::libaom_test::kTwoPassGood
),
235 ::testing::Range(2, 4), ::testing::Values(0, 2),
236 ::testing::Values(0, 1));
238 // Test cpu_used 0 and 1.
239 AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTestLarge
,
240 ::testing::Values(::libaom_test::kTwoPassGood
,
241 ::libaom_test::kOnePassGood
),
242 ::testing::Range(0, 2), ::testing::Values(0, 1, 2, 6),
243 ::testing::Values(0, 1, 2, 6));
245 class AVxEncoderThreadLSTest
: public AVxEncoderThreadTest
{
246 virtual void SetTileSize(libaom_test::Encoder
*encoder
) {
247 encoder
->Control(AV1E_SET_TILE_COLUMNS
, tile_cols_
);
248 encoder
->Control(AV1E_SET_TILE_ROWS
, tile_rows_
);
252 TEST_P(AVxEncoderThreadLSTest
, EncoderResultTest
) {
253 cfg_
.large_scale_tile
= 1;
254 decoder_
->Control(AV1_SET_TILE_MODE
, 1);
255 decoder_
->Control(AV1D_EXT_TILE_DEBUG
, 1);
259 class AVxEncoderThreadLSTestLarge
: public AVxEncoderThreadLSTest
{};
261 TEST_P(AVxEncoderThreadLSTestLarge
, EncoderResultTest
) {
262 cfg_
.large_scale_tile
= 1;
263 decoder_
->Control(AV1_SET_TILE_MODE
, 1);
264 decoder_
->Control(AV1D_EXT_TILE_DEBUG
, 1);
268 AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadLSTestLarge
,
269 ::testing::Values(::libaom_test::kTwoPassGood
,
270 ::libaom_test::kOnePassGood
),
271 ::testing::Range(0, 4), ::testing::Values(0, 6),
272 ::testing::Values(0, 6));