Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 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. |
| 10 | */ |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 11 | |
| 12 | #include <string> |
| 13 | #include <vector> |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 14 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 15 | #include "test/codec_factory.h" |
| 16 | #include "test/encode_test_driver.h" |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 17 | #include "test/md5_helper.h" |
James Zern | 7839d03 | 2015-02-25 19:09:59 -0800 | [diff] [blame] | 18 | #include "test/util.h" |
| 19 | #include "test/y4m_video_source.h" |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 20 | |
| 21 | namespace { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 22 | class AVxEncoderThreadTest |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 23 | : public ::libaom_test::EncoderTest, |
| 24 | public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int> { |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 25 | protected: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 26 | AVxEncoderThreadTest() |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 27 | : EncoderTest(GET_PARAM(0)), encoder_initialized_(false), |
| 28 | encoding_mode_(GET_PARAM(1)), set_cpu_used_(GET_PARAM(2)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 29 | init_flags_ = AOM_CODEC_USE_PSNR; |
| 30 | aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t(); |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 31 | cfg.w = 1280; |
| 32 | cfg.h = 720; |
| 33 | decoder_ = codec_->CreateDecoder(cfg, 0); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 34 | #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 Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 38 | } |
| 39 | #endif |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 40 | |
Geza Lore | 688f9ed | 2016-05-04 11:25:01 +0100 | [diff] [blame] | 41 | size_enc_.clear(); |
| 42 | md5_dec_.clear(); |
| 43 | md5_enc_.clear(); |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 44 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 45 | virtual ~AVxEncoderThreadTest() { delete decoder_; } |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 46 | |
| 47 | virtual void SetUp() { |
| 48 | InitializeConfig(); |
| 49 | SetMode(encoding_mode_); |
| 50 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 51 | if (encoding_mode_ != ::libaom_test::kRealTime) { |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 52 | cfg_.g_lag_in_frames = 3; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 53 | cfg_.rc_end_usage = AOM_VBR; |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 54 | cfg_.rc_2pass_vbr_minsection_pct = 5; |
hui su | b1a3871 | 2016-03-14 16:32:41 -0700 | [diff] [blame] | 55 | cfg_.rc_2pass_vbr_maxsection_pct = 2000; |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 56 | } else { |
| 57 | cfg_.g_lag_in_frames = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 58 | cfg_.rc_end_usage = AOM_CBR; |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 59 | cfg_.g_error_resilient = 1; |
| 60 | } |
| 61 | cfg_.rc_max_quantizer = 56; |
| 62 | cfg_.rc_min_quantizer = 0; |
| 63 | } |
| 64 | |
Alex Converse | 587a0b3 | 2015-03-05 11:47:21 -0800 | [diff] [blame] | 65 | virtual void BeginPassHook(unsigned int /*pass*/) { |
| 66 | encoder_initialized_ = false; |
| 67 | } |
| 68 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 69 | virtual void PreEncodeFrameHook(::libaom_test::VideoSource * /*video*/, |
| 70 | ::libaom_test::Encoder *encoder) { |
Alex Converse | 587a0b3 | 2015-03-05 11:47:21 -0800 | [diff] [blame] | 71 | if (!encoder_initialized_) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 72 | #if CONFIG_AV1 && CONFIG_EXT_TILE |
| 73 | encoder->Control(AV1E_SET_TILE_COLUMNS, 1); |
| 74 | if (codec_ == &libaom_test::kAV1) { |
Geza Lore | 855b6d7 | 2016-05-06 13:27:52 +0100 | [diff] [blame] | 75 | // TODO(geza): Start using multiple tile rows when the multi-threaded |
| 76 | // encoder can handle them |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 77 | encoder->Control(AV1E_SET_TILE_ROWS, 32); |
Geza Lore | 855b6d7 | 2016-05-06 13:27:52 +0100 | [diff] [blame] | 78 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 79 | encoder->Control(AV1E_SET_TILE_ROWS, 0); |
Geza Lore | 855b6d7 | 2016-05-06 13:27:52 +0100 | [diff] [blame] | 80 | } |
Geza Lore | 688f9ed | 2016-05-04 11:25:01 +0100 | [diff] [blame] | 81 | #else |
| 82 | // Encode 4 tile columns. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 83 | encoder->Control(AV1E_SET_TILE_COLUMNS, 2); |
| 84 | encoder->Control(AV1E_SET_TILE_ROWS, 0); |
| 85 | #endif // CONFIG_AV1 && CONFIG_EXT_TILE |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 86 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 87 | encoder->Control(AV1E_SET_TILE_LOOPFILTER, 0); |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 88 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 89 | encoder->Control(AOME_SET_CPUUSED, set_cpu_used_); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 90 | if (encoding_mode_ != ::libaom_test::kRealTime) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 91 | encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1); |
| 92 | encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7); |
| 93 | encoder->Control(AOME_SET_ARNR_STRENGTH, 5); |
Yunqing Wang | 8c1e57c | 2016-10-25 15:15:23 -0700 | [diff] [blame] | 94 | encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 0); |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 95 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 96 | encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0); |
| 97 | encoder->Control(AV1E_SET_AQ_MODE, 3); |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 98 | } |
Alex Converse | 587a0b3 | 2015-03-05 11:47:21 -0800 | [diff] [blame] | 99 | encoder_initialized_ = true; |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 103 | virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) { |
Geza Lore | 688f9ed | 2016-05-04 11:25:01 +0100 | [diff] [blame] | 104 | size_enc_.push_back(pkt->data.frame.sz); |
| 105 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 106 | ::libaom_test::MD5 md5_enc; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 107 | md5_enc.Add(reinterpret_cast<uint8_t *>(pkt->data.frame.buf), |
Geza Lore | 688f9ed | 2016-05-04 11:25:01 +0100 | [diff] [blame] | 108 | pkt->data.frame.sz); |
| 109 | md5_enc_.push_back(md5_enc.Get()); |
| 110 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 111 | const aom_codec_err_t res = decoder_->DecodeFrame( |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 112 | reinterpret_cast<uint8_t *>(pkt->data.frame.buf), pkt->data.frame.sz); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 113 | if (res != AOM_CODEC_OK) { |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 114 | abort_ = true; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 115 | ASSERT_EQ(AOM_CODEC_OK, res); |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 116 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 117 | const aom_image_t *img = decoder_->GetDxData().Next(); |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 118 | |
| 119 | if (img) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 120 | ::libaom_test::MD5 md5_res; |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 121 | md5_res.Add(img); |
Geza Lore | 688f9ed | 2016-05-04 11:25:01 +0100 | [diff] [blame] | 122 | md5_dec_.push_back(md5_res.Get()); |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Debargha Mukherjee | 6abddf3 | 2016-06-14 14:50:30 -0700 | [diff] [blame] | 126 | void DoTest() { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 127 | ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 15, 18); |
Debargha Mukherjee | 6abddf3 | 2016-06-14 14:50:30 -0700 | [diff] [blame] | 128 | cfg_.rc_target_bitrate = 1000; |
| 129 | |
| 130 | // Encode using single thread. |
| 131 | cfg_.g_threads = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 132 | init_flags_ = AOM_CODEC_USE_PSNR; |
Debargha Mukherjee | 6abddf3 | 2016-06-14 14:50:30 -0700 | [diff] [blame] | 133 | 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 Converse | 587a0b3 | 2015-03-05 11:47:21 -0800 | [diff] [blame] | 163 | bool encoder_initialized_; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 164 | ::libaom_test::TestMode encoding_mode_; |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 165 | int set_cpu_used_; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 166 | ::libaom_test::Decoder *decoder_; |
Geza Lore | 688f9ed | 2016-05-04 11:25:01 +0100 | [diff] [blame] | 167 | std::vector<size_t> size_enc_; |
| 168 | std::vector<std::string> md5_enc_; |
| 169 | std::vector<std::string> md5_dec_; |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 170 | }; |
| 171 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 172 | TEST_P(AVxEncoderThreadTest, EncoderResultTest) { DoTest(); } |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 173 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 174 | class AVxEncoderThreadTestLarge : public AVxEncoderThreadTest {}; |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 175 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 176 | TEST_P(AVxEncoderThreadTestLarge, EncoderResultTest) { DoTest(); } |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 177 | |
Yunqing Wang | 840b2be | 2016-12-13 15:15:28 -0800 | [diff] [blame] | 178 | // For AV1, only test speed 0 to 3. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 179 | AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTest, |
| 180 | ::testing::Values(::libaom_test::kTwoPassGood, |
| 181 | ::libaom_test::kOnePassGood), |
Yunqing Wang | 840b2be | 2016-12-13 15:15:28 -0800 | [diff] [blame] | 182 | ::testing::Range(2, 4)); |
Jingning Han | 41be09a | 2015-08-19 14:13:18 -0700 | [diff] [blame] | 183 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 184 | AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTestLarge, |
| 185 | ::testing::Values(::libaom_test::kTwoPassGood, |
| 186 | ::libaom_test::kOnePassGood), |
Yunqing Wang | 840b2be | 2016-12-13 15:15:28 -0800 | [diff] [blame] | 187 | ::testing::Range(0, 2)); |
Yunqing Wang | 7c2c2be | 2014-12-16 11:10:20 -0800 | [diff] [blame] | 188 | } // namespace |