tor-browser

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

level_test.cc (6668B)


      1 /*
      2 * Copyright (c) 2019, 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 #include <memory>
     12 #include <string>
     13 
     14 #include "gtest/gtest.h"
     15 
     16 #include "test/codec_factory.h"
     17 #include "test/encode_test_driver.h"
     18 #include "test/i420_video_source.h"
     19 #include "test/util.h"
     20 #include "test/y4m_video_source.h"
     21 #include "test/yuv_video_source.h"
     22 
     23 namespace {
     24 const int kLevelMin = 0;
     25 const int kLevelMax = 31;
     26 const int kLevelKeepStats = 32;
     27 // Speed settings tested
     28 static const int kCpuUsedVectors[] = {
     29  1,
     30  2,
     31  3,
     32  4,
     33 };
     34 
     35 class LevelTest
     36    : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>,
     37      public ::libaom_test::EncoderTest {
     38 protected:
     39  LevelTest()
     40      : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
     41        cpu_used_(GET_PARAM(2)), target_level_(31) {}
     42 
     43  ~LevelTest() override = default;
     44 
     45  void SetUp() override {
     46    InitializeConfig(encoding_mode_);
     47    if (encoding_mode_ != ::libaom_test::kRealTime) {
     48      cfg_.g_lag_in_frames = 5;
     49    } else {
     50      cfg_.rc_buf_sz = 1000;
     51      cfg_.rc_buf_initial_sz = 500;
     52      cfg_.rc_buf_optimal_sz = 600;
     53    }
     54  }
     55 
     56  void PreEncodeFrameHook(::libaom_test::VideoSource *video,
     57                          ::libaom_test::Encoder *encoder) override {
     58    if (video->frame() == 0) {
     59      encoder->Control(AOME_SET_CPUUSED, cpu_used_);
     60      encoder->Control(AV1E_SET_TARGET_SEQ_LEVEL_IDX, target_level_);
     61      if (encoding_mode_ != ::libaom_test::kRealTime) {
     62        encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
     63        encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
     64        encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
     65      }
     66    }
     67 
     68    int num_operating_points;
     69    encoder->Control(AV1E_GET_NUM_OPERATING_POINTS, &num_operating_points);
     70    ASSERT_EQ(num_operating_points, 1);
     71    encoder->Control(AV1E_GET_SEQ_LEVEL_IDX, level_);
     72    ASSERT_LE(level_[0], kLevelMax);
     73    ASSERT_GE(level_[0], kLevelMin);
     74  }
     75 
     76  libaom_test::TestMode encoding_mode_;
     77  int cpu_used_;
     78  int target_level_;
     79  int level_[32];
     80 };
     81 
     82 TEST(LevelTest, TestTargetLevelApi) {
     83  aom_codec_iface_t *codec = aom_codec_av1_cx();
     84  aom_codec_ctx_t enc;
     85  aom_codec_enc_cfg_t cfg;
     86  EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_config_default(codec, &cfg, 0));
     87  EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_init(&enc, codec, &cfg, 0));
     88  for (int operating_point = 0; operating_point <= 32; ++operating_point) {
     89    for (int level = 0; level <= 32; ++level) {
     90      const int target_level = operating_point * 100 + level;
     91      if (operating_point <= 31 &&
     92          ((level < (CONFIG_CWG_C013 ? 28 : 20) && level != 2 && level != 3 &&
     93            level != 6 && level != 7 && level != 10 && level != 11) ||
     94           level == kLevelMax || level == kLevelKeepStats)) {
     95        EXPECT_EQ(AOM_CODEC_OK,
     96                  AOM_CODEC_CONTROL_TYPECHECKED(
     97                      &enc, AV1E_SET_TARGET_SEQ_LEVEL_IDX, target_level));
     98      } else {
     99        EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
    100                  AOM_CODEC_CONTROL_TYPECHECKED(
    101                      &enc, AV1E_SET_TARGET_SEQ_LEVEL_IDX, target_level));
    102      }
    103    }
    104  }
    105  EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
    106 }
    107 
    108 TEST(LevelTest, InvalidOperatingPointIndexErrorDetail) {
    109  aom_codec_iface_t *codec = aom_codec_av1_cx();
    110  aom_codec_ctx_t enc;
    111  aom_codec_enc_cfg_t cfg;
    112  EXPECT_EQ(aom_codec_enc_config_default(codec, &cfg, 0), AOM_CODEC_OK);
    113  EXPECT_EQ(aom_codec_enc_init(&enc, codec, &cfg, 0), AOM_CODEC_OK);
    114  EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_TARGET_SEQ_LEVEL_IDX, 3219),
    115            AOM_CODEC_INVALID_PARAM);
    116  EXPECT_EQ(aom_codec_error_detail(&enc),
    117            std::string("Invalid operating point index: 32"));
    118  EXPECT_EQ(aom_codec_set_option(&enc, "target-seq-level-idx", "3319"),
    119            AOM_CODEC_INVALID_PARAM);
    120  EXPECT_EQ(aom_codec_error_detail(&enc),
    121            std::string("Invalid operating point index: 33"));
    122  EXPECT_EQ(aom_codec_destroy(&enc), AOM_CODEC_OK);
    123 }
    124 
    125 TEST_P(LevelTest, TestTargetLevel19) {
    126  std::unique_ptr<libaom_test::VideoSource> video;
    127  video.reset(new libaom_test::Y4mVideoSource("park_joy_90p_8_420.y4m", 0, 10));
    128  ASSERT_NE(video, nullptr);
    129  // Level index 19 corresponding to level 6.3.
    130  target_level_ = 19;
    131  ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
    132 }
    133 
    134 TEST_P(LevelTest, TestLevelMonitoringLowBitrate) {
    135  // To save run time, we only test speed 4.
    136  if (cpu_used_ == 4) {
    137    libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
    138                                       30, 1, 0, 40);
    139    target_level_ = kLevelKeepStats;
    140    cfg_.rc_target_bitrate = 1000;
    141    cfg_.g_limit = 40;
    142    ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
    143    ASSERT_EQ(level_[0], 0);
    144  }
    145 }
    146 
    147 TEST_P(LevelTest, TestLevelMonitoringHighBitrate) {
    148  // To save run time, we only test speed 4.
    149  if (cpu_used_ == 4) {
    150    libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
    151                                       30, 1, 0, 40);
    152    target_level_ = kLevelKeepStats;
    153    cfg_.rc_target_bitrate = 4000;
    154    cfg_.g_limit = 40;
    155    ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
    156    ASSERT_EQ(level_[0], 4);
    157  }
    158 }
    159 
    160 TEST_P(LevelTest, TestTargetLevel0) {
    161  // To save run time, we only test speed 4.
    162  if (cpu_used_ == 4) {
    163    libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
    164                                       30, 1, 0, 50);
    165    const int target_level = 0;
    166    target_level_ = target_level;
    167    cfg_.rc_target_bitrate = 4000;
    168    ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
    169    ASSERT_EQ(level_[0], target_level);
    170  }
    171 }
    172 
    173 TEST_P(LevelTest, TestTargetLevelRecode) {
    174  if (cpu_used_ == 4 && encoding_mode_ == ::libaom_test::kTwoPassGood) {
    175    libaom_test::I420VideoSource video("rand_noise_w1280h720.yuv", 1280, 720,
    176                                       25, 1, 0, 10);
    177    const int target_level = 0005;
    178    target_level_ = target_level;
    179    cfg_.rc_target_bitrate = 5000;
    180    ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
    181  }
    182 }
    183 
    184 AV1_INSTANTIATE_TEST_SUITE(LevelTest,
    185                           ::testing::Values(::libaom_test::kTwoPassGood,
    186                                             ::libaom_test::kOnePassGood),
    187                           ::testing::ValuesIn(kCpuUsedVectors));
    188 }  // namespace