chiyotsai | b4410d8 | 2020-01-06 16:24:46 -0800 | [diff] [blame] | 1 | /* |
James Zern | b7c05bd | 2024-06-11 19:15:10 -0700 | [diff] [blame] | 2 | * Copyright (c) 2020, Alliance for Open Media. All rights reserved. |
chiyotsai | b4410d8 | 2020-01-06 16:24:46 -0800 | [diff] [blame] | 3 | * |
| 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 | */ |
| 11 | |
| 12 | #include <initializer_list> |
| 13 | #include <string> |
| 14 | #include <vector> |
Wan-Teh Chang | c8b1fc2 | 2024-08-01 12:09:28 -0700 | [diff] [blame] | 15 | #include "gtest/gtest.h" |
chiyotsai | b4410d8 | 2020-01-06 16:24:46 -0800 | [diff] [blame] | 16 | #include "test/codec_factory.h" |
| 17 | #include "test/encode_test_driver.h" |
| 18 | #include "test/md5_helper.h" |
| 19 | #include "test/util.h" |
| 20 | #include "test/yuv_video_source.h" |
| 21 | |
| 22 | namespace { |
Wan-Teh Chang | 9d68e63 | 2020-01-18 08:30:45 -0800 | [diff] [blame] | 23 | class AV1SBMultipassTest |
| 24 | : public ::libaom_test::CodecTestWith2Params<int, bool>, |
| 25 | public ::libaom_test::EncoderTest { |
chiyotsai | b4410d8 | 2020-01-06 16:24:46 -0800 | [diff] [blame] | 26 | protected: |
| 27 | AV1SBMultipassTest() |
| 28 | : EncoderTest(GET_PARAM(0)), set_cpu_used_(GET_PARAM(1)), |
| 29 | row_mt_(GET_PARAM(2)) { |
| 30 | init_flags_ = AOM_CODEC_USE_PSNR; |
| 31 | aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t(); |
| 32 | cfg.w = 1280; |
| 33 | cfg.h = 720; |
| 34 | cfg.allow_lowbitdepth = 1; |
| 35 | decoder_ = codec_->CreateDecoder(cfg, 0); |
| 36 | if (decoder_->IsAV1()) { |
| 37 | decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1); |
| 38 | decoder_->Control(AV1_SET_DECODE_TILE_COL, -1); |
| 39 | } |
| 40 | |
| 41 | size_enc_.clear(); |
| 42 | md5_dec_.clear(); |
| 43 | md5_enc_.clear(); |
| 44 | } |
James Zern | faa2dcf | 2023-07-24 18:29:51 -0700 | [diff] [blame] | 45 | ~AV1SBMultipassTest() override { delete decoder_; } |
chiyotsai | b4410d8 | 2020-01-06 16:24:46 -0800 | [diff] [blame] | 46 | |
James Zern | faa2dcf | 2023-07-24 18:29:51 -0700 | [diff] [blame] | 47 | void SetUp() override { |
Wan-Teh Chang | fddea51 | 2021-02-18 17:08:38 -0800 | [diff] [blame] | 48 | InitializeConfig(::libaom_test::kTwoPassGood); |
chiyotsai | b4410d8 | 2020-01-06 16:24:46 -0800 | [diff] [blame] | 49 | |
| 50 | cfg_.g_lag_in_frames = 5; |
| 51 | cfg_.rc_end_usage = AOM_VBR; |
| 52 | cfg_.rc_2pass_vbr_minsection_pct = 5; |
| 53 | cfg_.rc_2pass_vbr_maxsection_pct = 2000; |
| 54 | |
| 55 | cfg_.rc_max_quantizer = 56; |
| 56 | cfg_.rc_min_quantizer = 0; |
| 57 | } |
| 58 | |
James Zern | faa2dcf | 2023-07-24 18:29:51 -0700 | [diff] [blame] | 59 | void PreEncodeFrameHook(::libaom_test::VideoSource *video, |
| 60 | ::libaom_test::Encoder *encoder) override { |
chiyotsai | b4410d8 | 2020-01-06 16:24:46 -0800 | [diff] [blame] | 61 | if (video->frame() == 0) { |
| 62 | SetTileSize(encoder); |
| 63 | encoder->Control(AOME_SET_CPUUSED, set_cpu_used_); |
| 64 | encoder->Control(AV1E_ENABLE_SB_MULTIPASS_UNIT_TEST, use_multipass_); |
| 65 | encoder->Control(AV1E_SET_ROW_MT, row_mt_); |
| 66 | |
| 67 | encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1); |
| 68 | encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7); |
| 69 | encoder->Control(AOME_SET_ARNR_STRENGTH, 5); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | virtual void SetTileSize(libaom_test::Encoder *encoder) { |
| 74 | encoder->Control(AV1E_SET_TILE_COLUMNS, 1); |
| 75 | encoder->Control(AV1E_SET_TILE_ROWS, 1); |
| 76 | } |
| 77 | |
James Zern | faa2dcf | 2023-07-24 18:29:51 -0700 | [diff] [blame] | 78 | void FramePktHook(const aom_codec_cx_pkt_t *pkt) override { |
chiyotsai | b4410d8 | 2020-01-06 16:24:46 -0800 | [diff] [blame] | 79 | size_enc_.push_back(pkt->data.frame.sz); |
| 80 | |
| 81 | ::libaom_test::MD5 md5_enc; |
| 82 | md5_enc.Add(reinterpret_cast<uint8_t *>(pkt->data.frame.buf), |
| 83 | pkt->data.frame.sz); |
| 84 | md5_enc_.push_back(md5_enc.Get()); |
| 85 | |
| 86 | const aom_codec_err_t res = decoder_->DecodeFrame( |
| 87 | reinterpret_cast<uint8_t *>(pkt->data.frame.buf), pkt->data.frame.sz); |
| 88 | if (res != AOM_CODEC_OK) { |
| 89 | abort_ = true; |
| 90 | ASSERT_EQ(AOM_CODEC_OK, res); |
| 91 | } |
| 92 | const aom_image_t *img = decoder_->GetDxData().Next(); |
| 93 | |
| 94 | if (img) { |
| 95 | ::libaom_test::MD5 md5_res; |
| 96 | md5_res.Add(img); |
| 97 | md5_dec_.push_back(md5_res.Get()); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | void DoTest() { |
| 102 | ::libaom_test::YUVVideoSource video( |
| 103 | "niklas_640_480_30.yuv", AOM_IMG_FMT_I420, 640, 480, 30, 1, 0, 6); |
| 104 | cfg_.rc_target_bitrate = 1000; |
| 105 | |
| 106 | // Encode while coding each sb once |
| 107 | use_multipass_ = false; |
| 108 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 109 | std::vector<size_t> single_pass_size_enc; |
| 110 | std::vector<std::string> single_pass_md5_enc; |
| 111 | std::vector<std::string> single_pass_md5_dec; |
| 112 | single_pass_size_enc = size_enc_; |
| 113 | single_pass_md5_enc = md5_enc_; |
| 114 | single_pass_md5_dec = md5_dec_; |
| 115 | size_enc_.clear(); |
| 116 | md5_enc_.clear(); |
| 117 | md5_dec_.clear(); |
| 118 | |
| 119 | // Encode while coding each sb twice |
| 120 | use_multipass_ = true; |
| 121 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 122 | std::vector<size_t> multi_pass_size_enc; |
| 123 | std::vector<std::string> multi_pass_md5_enc; |
| 124 | std::vector<std::string> multi_pass_md5_dec; |
| 125 | multi_pass_size_enc = size_enc_; |
| 126 | multi_pass_md5_enc = md5_enc_; |
| 127 | multi_pass_md5_dec = md5_dec_; |
| 128 | size_enc_.clear(); |
| 129 | md5_enc_.clear(); |
| 130 | md5_dec_.clear(); |
| 131 | |
| 132 | // Check that the vectors are equal. |
| 133 | ASSERT_EQ(single_pass_size_enc, multi_pass_size_enc); |
| 134 | ASSERT_EQ(single_pass_md5_enc, multi_pass_md5_enc); |
| 135 | ASSERT_EQ(single_pass_md5_dec, multi_pass_md5_dec); |
| 136 | } |
| 137 | |
| 138 | bool use_multipass_; |
| 139 | int set_cpu_used_; |
| 140 | bool row_mt_; |
| 141 | ::libaom_test::Decoder *decoder_; |
| 142 | std::vector<size_t> size_enc_; |
| 143 | std::vector<std::string> md5_enc_; |
| 144 | std::vector<std::string> md5_dec_; |
| 145 | }; |
| 146 | |
| 147 | TEST_P(AV1SBMultipassTest, TwoPassMatchTest) { DoTest(); } |
| 148 | |
chiyotsai | 33531e5 | 2020-08-03 09:15:04 -0700 | [diff] [blame] | 149 | AV1_INSTANTIATE_TEST_SUITE(AV1SBMultipassTest, ::testing::Range(4, 6), |
chiyotsai | 9dfac72 | 2020-07-07 17:43:02 -0700 | [diff] [blame] | 150 | ::testing::Bool()); |
chiyotsai | b4410d8 | 2020-01-06 16:24:46 -0800 | [diff] [blame] | 151 | |
| 152 | } // namespace |