tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

sb_multipass_test.cc (4872B)


      1 /*
      2 * Copyright (c) 2020, Alliance for Open Media. All rights reserved.
      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>
     15 #include "gtest/gtest.h"
     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 {
     23 class AV1SBMultipassTest
     24    : public ::libaom_test::CodecTestWith2Params<int, bool>,
     25      public ::libaom_test::EncoderTest {
     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  }
     45  ~AV1SBMultipassTest() override { delete decoder_; }
     46 
     47  void SetUp() override {
     48    InitializeConfig(::libaom_test::kTwoPassGood);
     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 
     59  void PreEncodeFrameHook(::libaom_test::VideoSource *video,
     60                          ::libaom_test::Encoder *encoder) override {
     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 
     78  void FramePktHook(const aom_codec_cx_pkt_t *pkt) override {
     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 
    149 AV1_INSTANTIATE_TEST_SUITE(AV1SBMultipassTest, ::testing::Range(4, 6),
    150                           ::testing::Bool());
    151 
    152 }  // namespace