tor-browser

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

datarate_test.cc (24049B)


      1 /*
      2 * Copyright (c) 2016, 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 "config/aom_config.h"
     13 
     14 #include "gtest/gtest.h"
     15 #include "test/acm_random.h"
     16 #include "test/codec_factory.h"
     17 #include "test/datarate_test.h"
     18 #include "test/encode_test_driver.h"
     19 #include "test/i420_video_source.h"
     20 #include "test/util.h"
     21 #include "test/y4m_video_source.h"
     22 #include "aom/aom_codec.h"
     23 
     24 #if CONFIG_LIBYUV
     25 #include "third_party/libyuv/include/libyuv/scale.h"
     26 #endif
     27 
     28 namespace datarate_test {
     29 namespace {
     30 
     31 #if CONFIG_LIBYUV
     32 class ResizingVideoSource : public ::libaom_test::DummyVideoSource {
     33 public:
     34  ResizingVideoSource(const int width, const int height, const int input_width,
     35                      const int input_height, const std::string file_name,
     36                      int limit)
     37      : width_(width), height_(height), input_width_(input_width),
     38        input_height_(input_height), limit_(limit) {
     39    SetSize(width_, height_);
     40    img_input_ = aom_img_alloc(nullptr, AOM_IMG_FMT_I420, input_width_,
     41                               input_height_, 32);
     42    raw_size_ = input_width_ * input_height_ * 3 / 2;
     43    input_file_ = ::libaom_test::OpenTestDataFile(file_name);
     44  }
     45 
     46  ~ResizingVideoSource() override {
     47    aom_img_free(img_input_);
     48    fclose(input_file_);
     49  }
     50 
     51 protected:
     52  void FillFrame() override {
     53    // Read frame from input_file and scale up.
     54    ASSERT_NE(input_file_, nullptr);
     55    fread(img_input_->img_data, raw_size_, 1, input_file_);
     56    libyuv::I420Scale(
     57        img_input_->planes[AOM_PLANE_Y], img_input_->stride[AOM_PLANE_Y],
     58        img_input_->planes[AOM_PLANE_U], img_input_->stride[AOM_PLANE_U],
     59        img_input_->planes[AOM_PLANE_V], img_input_->stride[AOM_PLANE_V],
     60        input_width_, input_height_, img_->planes[AOM_PLANE_Y],
     61        img_->stride[AOM_PLANE_Y], img_->planes[AOM_PLANE_U],
     62        img_->stride[AOM_PLANE_U], img_->planes[AOM_PLANE_V],
     63        img_->stride[AOM_PLANE_V], width_, height_, libyuv::kFilterBox);
     64  }
     65 
     66  const int width_;
     67  const int height_;
     68  const int input_width_;
     69  const int input_height_;
     70  const int limit_;
     71  aom_image_t *img_input_;
     72  size_t raw_size_;
     73  FILE *input_file_;
     74 };
     75 #endif  // CONFIG_LIBYUV
     76 
     77 // Params: test mode, speed, aq mode and index for bitrate array.
     78 class DatarateTestLarge
     79    : public ::libaom_test::CodecTestWith4Params<libaom_test::TestMode, int,
     80                                                 unsigned int, int>,
     81      public DatarateTest {
     82 public:
     83  DatarateTestLarge() : DatarateTest(GET_PARAM(0)) {
     84    set_cpu_used_ = GET_PARAM(2);
     85    aq_mode_ = GET_PARAM(3);
     86  }
     87 
     88 protected:
     89  ~DatarateTestLarge() override = default;
     90 
     91  void SetUp() override {
     92    InitializeConfig(GET_PARAM(1));
     93    ResetModel();
     94  }
     95 
     96  virtual void BasicRateTargetingVBRTest() {
     97    cfg_.rc_min_quantizer = 0;
     98    cfg_.rc_max_quantizer = 63;
     99    cfg_.g_error_resilient = 0;
    100    cfg_.rc_end_usage = AOM_VBR;
    101    cfg_.g_lag_in_frames = 0;
    102 
    103    ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
    104                                         288, 30, 1, 0, 140);
    105    const int bitrate_array[2] = { 400, 800 };
    106    RunBasicRateTargetingTest(&video, bitrate_array[GET_PARAM(4)], 0.7, 1.45);
    107  }
    108 
    109  virtual void BasicRateTargetingCBRTest() {
    110    SetUpCBR();
    111    ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
    112                                         288, 30, 1, 0, 140);
    113    const int bitrate_array[2] = { 150, 550 };
    114    RunBasicRateTargetingTest(&video, bitrate_array[GET_PARAM(4)], 0.85, 1.19);
    115  }
    116 
    117 #if CONFIG_LIBYUV
    118  // Test for an encoding mode that triggers an assert in nonrd_pickmode
    119  // (in av1_is_subpelmv_in_range), issue b:396169342.
    120  // The assert is triggered on a 2456x2054 resolution with settings defined
    121  // with the flag avif_mode_. This test upsamples a QVGA clip to the target
    122  // resolution, using libyuv for the scaling.
    123  virtual void BasicRateTargetingCBRAssertAvifModeTest() {
    124    SetUpCBR();
    125    cfg_.rc_dropframe_thresh = 0;
    126    ResizingVideoSource video(2456, 2054, 320, 240,
    127                              "pixel_capture_w320h240.yuv", 100);
    128    const int bitrate_array[2] = { 1000, 2000 };
    129    cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
    130 #ifdef AOM_VALGRIND_BUILD
    131    if (cfg_.rc_target_bitrate == 2000) {
    132      GTEST_SKIP() << "No need to run this test for 2 bitrates, the issue for "
    133                      "this test occurs at first bitrate = 1000.";
    134    }
    135 #endif  // AOM_VALGRIND_BUILD
    136    ResetModel();
    137    avif_mode_ = 1;
    138    ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
    139  }
    140 #endif  // CONFIG_LIBYUV
    141 
    142  virtual void BasicRateTargetingCBRSpikeTest() {
    143    SetUpCBR();
    144    cfg_.rc_dropframe_thresh = 0;
    145    cfg_.rc_min_quantizer = 2;
    146    cfg_.rc_max_quantizer = 56;
    147    cfg_.kf_max_dist = 3000;
    148    cfg_.kf_min_dist = 3000;
    149 
    150    ::libaom_test::I420VideoSource video("desktopqvga2.320_240.yuv", 320, 240,
    151                                         30, 1, 0, 800);
    152    const int bitrate_array[2] = { 100, 200 };
    153    cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
    154    ResetModel();
    155    max_perc_spike_ = 3.0;
    156    max_perc_spike_high_ = 8.0;
    157    ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
    158    ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.85)
    159        << " The datarate for the file is lower than target by too much!";
    160    ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.19)
    161        << " The datarate for the file is greater than target by too much!";
    162    ASSERT_LE(num_spikes_, 10);
    163    ASSERT_LT(num_spikes_high_, 1);
    164  }
    165 
    166  virtual void BasicRateTargetingCBRDynamicBitrateTest() {
    167    SetUpCBR();
    168    cfg_.rc_dropframe_thresh = 0;
    169    cfg_.rc_min_quantizer = 2;
    170    cfg_.rc_max_quantizer = 56;
    171    cfg_.kf_max_dist = 3000;
    172    cfg_.kf_min_dist = 3000;
    173 
    174    ::libaom_test::I420VideoSource video("desktop1.320_180.yuv", 320, 180, 30,
    175                                         1, 0, 800);
    176    const int bitrate_array[2] = { 100, 200 };
    177    cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
    178    ResetModel();
    179    target_bitrate_update_[0] = cfg_.rc_target_bitrate;
    180    target_bitrate_update_[1] = static_cast<int>(1.3 * cfg_.rc_target_bitrate);
    181    target_bitrate_update_[2] = static_cast<int>(0.7 * cfg_.rc_target_bitrate);
    182    frame_update_bitrate_ = 250;
    183    ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
    184    for (int i = 0; i < 3; i++) {
    185      ASSERT_GE(effective_datarate_dynamic_[i],
    186                target_bitrate_update_[i] * 0.85)
    187          << " The datarate for the file is lower than target by too much!";
    188      ASSERT_LE(effective_datarate_dynamic_[i],
    189                target_bitrate_update_[i] * 1.20)
    190          << " The datarate for the file is greater than target by too much!";
    191    }
    192  }
    193 
    194  virtual void BasicRateTargetingMultiThreadCBRTest() {
    195    ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30,
    196                                         1, 0, 400);
    197    SetUpCBR();
    198    cfg_.g_threads = 4;
    199 
    200    const int bitrate_array[2] = { 250, 650 };
    201    ResetModel();
    202    tile_columns_ = 2;
    203    RunBasicRateTargetingTestReversed(&video, bitrate_array[GET_PARAM(4)], 0.85,
    204                                      1.15);
    205  }
    206 
    207  virtual void ErrorResilienceOnSceneCuts() {
    208    if (GET_PARAM(4) > 0) return;
    209    SetUpCBR();
    210    cfg_.rc_dropframe_thresh = 0;
    211    cfg_.g_error_resilient = 1;
    212 
    213    ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
    214                                         288, 30, 1, 0, 300);
    215    RunBasicRateTargetingTest(&video, 500, 0.85, 1.15);
    216  }
    217 
    218  virtual void BasicRateTargetingCBRPeriodicKeyFrameTest() {
    219    SetUpCBR();
    220    // Periodic keyframe
    221    cfg_.kf_max_dist = 50;
    222 
    223    ::libaom_test::I420VideoSource video("pixel_capture_w320h240.yuv", 320, 240,
    224                                         30, 1, 0, 310);
    225    const int bitrate_array[2] = { 150, 550 };
    226    RunBasicRateTargetingTest(&video, bitrate_array[GET_PARAM(4)], 0.85, 1.15);
    227  }
    228 
    229  virtual void CBRPeriodicKeyFrameOnSceneCuts() {
    230    if (GET_PARAM(4) > 0) return;
    231    SetUpCBR();
    232    cfg_.rc_dropframe_thresh = 0;
    233    // Periodic keyframe
    234    cfg_.kf_max_dist = 30;
    235    cfg_.kf_min_dist = 30;
    236 
    237    ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
    238                                         288, 30, 1, 0, 300);
    239    RunBasicRateTargetingTest(&video, 500, 0.85, 1.3);
    240  }
    241 
    242  virtual void BasicRateTargetingAQModeOnOffCBRTest() {
    243    if (GET_PARAM(4) > 0) return;
    244    SetUpCBR();
    245    cfg_.rc_dropframe_thresh = 0;
    246    cfg_.rc_min_quantizer = 2;
    247    cfg_.g_error_resilient = 0;
    248    cfg_.g_pass = AOM_RC_ONE_PASS;
    249    cfg_.g_usage = AOM_USAGE_REALTIME;
    250    cfg_.kf_mode = AOM_KF_DISABLED;
    251 
    252    ::libaom_test::I420VideoSource video("pixel_capture_w320h240.yuv", 320, 240,
    253                                         30, 1, 0, 310);
    254    RunBasicRateTargetingTest(&video, 60, 0.85, 1.15);
    255  }
    256 
    257  virtual void BasicRateTargeting444CBRScreenTest() {
    258    ::libaom_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 140);
    259 
    260    cfg_.g_profile = 1;
    261    cfg_.g_timebase = video.timebase();
    262 
    263    SetUpCBR();
    264 
    265    const int bitrate_array[2] = { 250, 650 };
    266    ResetModel();
    267    screen_mode_ = true;
    268    RunBasicRateTargetingTestReversed(&video, bitrate_array[GET_PARAM(4)], 0.85,
    269                                      1.15);
    270  }
    271 
    272  virtual void BasicRateTargetingSuperresCBR() {
    273    ::libaom_test::I420VideoSource video("desktopqvga2.320_240.yuv", 320, 240,
    274                                         30, 1, 0, 800);
    275 
    276    cfg_.g_profile = 0;
    277    cfg_.g_timebase = video.timebase();
    278 
    279    SetUpCBR();
    280 
    281    cfg_.rc_superres_mode = AOM_SUPERRES_FIXED;
    282    cfg_.rc_superres_denominator = 16;
    283    cfg_.rc_superres_kf_denominator = 16;
    284 
    285    const int bitrate_array[2] = { 250, 650 };
    286    RunBasicRateTargetingTestReversed(&video, bitrate_array[GET_PARAM(4)], 0.85,
    287                                      1.15);
    288  }
    289 
    290  virtual void BasicRateTargetingSuperresCBRMultiThreads() {
    291    ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30,
    292                                         1, 0, 400);
    293 
    294    cfg_.g_profile = 0;
    295    cfg_.g_timebase = video.timebase();
    296 
    297    SetUpCBR();
    298    cfg_.g_threads = 2;
    299 
    300    cfg_.rc_superres_mode = AOM_SUPERRES_FIXED;
    301    cfg_.rc_superres_denominator = 16;
    302    cfg_.rc_superres_kf_denominator = 16;
    303 
    304    const int bitrate_array[2] = { 250, 650 };
    305    ResetModel();
    306    tile_columns_ = 1;
    307    RunBasicRateTargetingTestReversed(&video, bitrate_array[GET_PARAM(4)], 0.85,
    308                                      1.15);
    309  }
    310 };
    311 
    312 // Params: test mode, speed, aq mode.
    313 class DatarateTestFrameDropLarge
    314    : public ::libaom_test::CodecTestWith3Params<libaom_test::TestMode, int,
    315                                                 unsigned int>,
    316      public DatarateTest {
    317 public:
    318  DatarateTestFrameDropLarge() : DatarateTest(GET_PARAM(0)) {
    319    set_cpu_used_ = GET_PARAM(2);
    320    aq_mode_ = GET_PARAM(3);
    321  }
    322 
    323 protected:
    324  ~DatarateTestFrameDropLarge() override = default;
    325 
    326  void SetUp() override {
    327    InitializeConfig(GET_PARAM(1));
    328    ResetModel();
    329  }
    330 
    331  virtual void ChangingDropFrameThreshTest() {
    332    SetUpCBR();
    333    cfg_.rc_undershoot_pct = 20;
    334    cfg_.rc_undershoot_pct = 20;
    335    cfg_.rc_dropframe_thresh = 10;
    336    cfg_.rc_max_quantizer = 50;
    337    cfg_.rc_target_bitrate = 200;
    338    cfg_.g_error_resilient = 1;
    339    // TODO(marpan): Investigate datarate target failures with a smaller
    340    // keyframe interval (128).
    341    cfg_.kf_max_dist = 9999;
    342 
    343    ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
    344                                         288, 30, 1, 0, 100);
    345 
    346    const int kDropFrameThreshTestStep = 30;
    347    aom_codec_pts_t last_drop = 140;
    348    int last_num_drops = 0;
    349    for (int i = 40; i < 100; i += kDropFrameThreshTestStep) {
    350      cfg_.rc_dropframe_thresh = i;
    351      ResetModel();
    352      ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
    353      ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.85)
    354          << " The datarate for the file is lower than target by too much!";
    355      ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.40)
    356          << " The datarate for the file is greater than target by too much!";
    357      if (last_drop > 0) {
    358        ASSERT_LE(first_drop_, last_drop)
    359            << " The first dropped frame for drop_thresh " << i
    360            << " > first dropped frame for drop_thresh "
    361            << i - kDropFrameThreshTestStep;
    362      }
    363      ASSERT_GE(num_drops_, last_num_drops * 0.7)
    364          << " The number of dropped frames for drop_thresh " << i
    365          << " < number of dropped frames for drop_thresh "
    366          << i - kDropFrameThreshTestStep;
    367      last_drop = first_drop_;
    368      last_num_drops = num_drops_;
    369    }
    370  }
    371 };
    372 
    373 // Check basic rate targeting for VBR mode.
    374 TEST_P(DatarateTestLarge, BasicRateTargetingVBR) {
    375  BasicRateTargetingVBRTest();
    376 }
    377 
    378 // Check basic rate targeting for CBR.
    379 TEST_P(DatarateTestLarge, BasicRateTargetingCBR) {
    380  BasicRateTargetingCBRTest();
    381 }
    382 
    383 // Check basic rate targeting for CBR, with 4 threads
    384 TEST_P(DatarateTestLarge, BasicRateTargetingMultiThreadCBR) {
    385  BasicRateTargetingMultiThreadCBRTest();
    386 }
    387 
    388 // Check basic rate targeting for periodic key frame.
    389 TEST_P(DatarateTestLarge, PeriodicKeyFrameCBR) {
    390  BasicRateTargetingCBRPeriodicKeyFrameTest();
    391 }
    392 
    393 // Check basic rate targeting for periodic key frame, aligned with scene change.
    394 TEST_P(DatarateTestLarge, PeriodicKeyFrameCBROnSceneCuts) {
    395  CBRPeriodicKeyFrameOnSceneCuts();
    396 }
    397 
    398 // Check basic rate targeting with error resilience on for scene cuts.
    399 TEST_P(DatarateTestLarge, ErrorResilienceOnSceneCuts) {
    400  ErrorResilienceOnSceneCuts();
    401 }
    402 
    403 // Check basic rate targeting for CBR, for 444 input screen mode.
    404 #if defined(CONFIG_MAX_DECODE_PROFILE) && CONFIG_MAX_DECODE_PROFILE < 1
    405 TEST_P(DatarateTestLarge, DISABLED_BasicRateTargeting444CBRScreen) {
    406 #else
    407 TEST_P(DatarateTestLarge, BasicRateTargeting444CBRScreen) {
    408 #endif
    409  BasicRateTargeting444CBRScreenTest();
    410 }
    411 
    412 // Check basic rate targeting for Superres mode with CBR.
    413 TEST_P(DatarateTestLarge, BasicRateTargetingSuperresCBR) {
    414  BasicRateTargetingSuperresCBR();
    415 }
    416 
    417 // Check basic rate targeting for Superres mode with CBR and multi-threads.
    418 TEST_P(DatarateTestLarge, BasicRateTargetingSuperresCBRMultiThreads) {
    419  BasicRateTargetingSuperresCBRMultiThreads();
    420 }
    421 
    422 // Check that (1) the first dropped frame gets earlier and earlier
    423 // as the drop frame threshold is increased, and (2) that the total number of
    424 // frame drops does not decrease as we increase frame drop threshold.
    425 // Use a lower qp-max to force some frame drops.
    426 TEST_P(DatarateTestFrameDropLarge, ChangingDropFrameThresh) {
    427  ChangingDropFrameThreshTest();
    428 }
    429 
    430 TEST_P(DatarateTestLarge, BasicRateTargetingAQModeOnOffCBR) {
    431  BasicRateTargetingAQModeOnOffCBRTest();
    432 }
    433 
    434 class DatarateTestRealtime : public DatarateTestLarge {};
    435 
    436 class DatarateTestFrameDropRealtime : public DatarateTestFrameDropLarge {};
    437 
    438 // Params: aq mode.
    439 class DatarateTestSpeedChangeRealtime
    440    : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode,
    441                                                 unsigned int>,
    442      public DatarateTest {
    443 public:
    444  DatarateTestSpeedChangeRealtime() : DatarateTest(GET_PARAM(0)) {
    445    aq_mode_ = GET_PARAM(1);
    446    speed_change_test_ = true;
    447  }
    448 
    449 protected:
    450  ~DatarateTestSpeedChangeRealtime() override = default;
    451 
    452  void SetUp() override {
    453    InitializeConfig(GET_PARAM(1));
    454    ResetModel();
    455  }
    456 
    457  virtual void ChangingSpeedTest() {
    458    SetUpCBR();
    459    cfg_.rc_undershoot_pct = 20;
    460    cfg_.rc_undershoot_pct = 20;
    461    cfg_.rc_dropframe_thresh = 10;
    462    cfg_.rc_max_quantizer = 50;
    463    cfg_.rc_target_bitrate = 200;
    464    cfg_.g_error_resilient = 1;
    465    // TODO(marpan): Investigate datarate target failures with a smaller
    466    // keyframe interval (128).
    467    cfg_.kf_max_dist = 9999;
    468    cfg_.rc_dropframe_thresh = 0;
    469    ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
    470                                         288, 30, 1, 0, 100);
    471 
    472    ResetModel();
    473    ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
    474    ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.83)
    475        << " The datarate for the file is lower than target by too much!";
    476    ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.35)
    477        << " The datarate for the file is greater than target by too much!";
    478  }
    479 };
    480 
    481 // Check basic rate targeting for VBR mode.
    482 TEST_P(DatarateTestRealtime, BasicRateTargetingVBR) {
    483  BasicRateTargetingVBRTest();
    484 }
    485 
    486 // Check basic rate targeting for CBR.
    487 TEST_P(DatarateTestRealtime, BasicRateTargetingCBR) {
    488  BasicRateTargetingCBRTest();
    489 }
    490 
    491 #if CONFIG_LIBYUV
    492 // Check basic rate targeting for CBR, special case.
    493 TEST_P(DatarateTestRealtime, BasicRateTargetingCBRAssertAvifMode) {
    494  BasicRateTargetingCBRAssertAvifModeTest();
    495 }
    496 #endif
    497 
    498 // Check basic rate targeting for CBR. Use a longer clip,
    499 // and verify #encode size spikes above threshold.
    500 TEST_P(DatarateTestRealtime, BasicRateTargetingCBRSpike) {
    501  BasicRateTargetingCBRSpikeTest();
    502 }
    503 
    504 // Check basic rate targeting for CBR. Use a longer clip,
    505 // and verify encoder can respnd and hit new bitrates updated
    506 // within the stream.
    507 TEST_P(DatarateTestRealtime, BasicRateTargetingCBRDynamicBitrate) {
    508  BasicRateTargetingCBRDynamicBitrateTest();
    509 }
    510 
    511 // Check basic rate targeting for CBR, with 4 threads
    512 TEST_P(DatarateTestRealtime, BasicRateTargetingMultiThreadCBR) {
    513  BasicRateTargetingMultiThreadCBRTest();
    514 }
    515 
    516 // Check basic rate targeting for periodic key frame.
    517 TEST_P(DatarateTestRealtime, PeriodicKeyFrameCBR) {
    518  BasicRateTargetingCBRPeriodicKeyFrameTest();
    519 }
    520 
    521 // Check basic rate targeting for periodic key frame, aligned with scene change.
    522 TEST_P(DatarateTestRealtime, PeriodicKeyFrameCBROnSceneCuts) {
    523  CBRPeriodicKeyFrameOnSceneCuts();
    524 }
    525 
    526 // Check basic rate targeting with error resilience on for scene cuts.
    527 TEST_P(DatarateTestRealtime, ErrorResilienceOnSceneCuts) {
    528  ErrorResilienceOnSceneCuts();
    529 }
    530 
    531 // Check basic rate targeting for CBR for 444 screen mode.
    532 #if defined(CONFIG_MAX_DECODE_PROFILE) && CONFIG_MAX_DECODE_PROFILE < 1
    533 TEST_P(DatarateTestRealtime, DISABLED_BasicRateTargeting444CBRScreen) {
    534 #else
    535 TEST_P(DatarateTestRealtime, BasicRateTargeting444CBRScreen) {
    536 #endif
    537  BasicRateTargeting444CBRScreenTest();
    538 }
    539 
    540 // Check basic rate targeting for Superres mode with CBR.
    541 TEST_P(DatarateTestRealtime, BasicRateTargetingSuperresCBR) {
    542  BasicRateTargetingSuperresCBR();
    543 }
    544 
    545 // Check basic rate targeting for Superres mode with CBR and multi-threads.
    546 TEST_P(DatarateTestRealtime, BasicRateTargetingSuperresCBRMultiThreads) {
    547  BasicRateTargetingSuperresCBRMultiThreads();
    548 }
    549 
    550 // Check that (1) the first dropped frame gets earlier and earlier
    551 // as the drop frame threshold is increased, and (2) that the total number of
    552 // frame drops does not decrease as we increase frame drop threshold.
    553 // Use a lower qp-max to force some frame drops.
    554 TEST_P(DatarateTestFrameDropRealtime, ChangingDropFrameThresh) {
    555  ChangingDropFrameThreshTest();
    556 }
    557 
    558 TEST_P(DatarateTestSpeedChangeRealtime, ChangingSpeedTest) {
    559  ChangingSpeedTest();
    560 }
    561 
    562 class DatarateTestSetFrameQpRealtime
    563    : public DatarateTest,
    564      public ::testing::TestWithParam<const libaom_test::AV1CodecFactory *> {
    565 public:
    566  DatarateTestSetFrameQpRealtime() : DatarateTest(GetParam()), frame_(0) {}
    567 
    568 protected:
    569  ~DatarateTestSetFrameQpRealtime() override = default;
    570 
    571  void SetUp() override {
    572    InitializeConfig(libaom_test::kRealTime);
    573    ResetModel();
    574  }
    575 
    576  void PreEncodeFrameHook(::libaom_test::VideoSource *video,
    577                          ::libaom_test::Encoder *encoder) override {
    578    set_cpu_used_ = 7;
    579    DatarateTest::PreEncodeFrameHook(video, encoder);
    580    frame_qp_ = rnd_.PseudoUniform(63);
    581    encoder->Control(AV1E_SET_QUANTIZER_ONE_PASS, frame_qp_);
    582    frame_++;
    583  }
    584 
    585  void PostEncodeFrameHook(::libaom_test::Encoder *encoder) override {
    586    if (frame_ >= total_frames_) return;
    587    int qp = 0;
    588    encoder->Control(AOME_GET_LAST_QUANTIZER_64, &qp);
    589    ASSERT_EQ(qp, frame_qp_);
    590  }
    591 
    592 protected:
    593  int total_frames_;
    594 
    595 private:
    596  int frame_qp_;
    597  int frame_;
    598  libaom_test::ACMRandom rnd_;
    599 };
    600 
    601 TEST_P(DatarateTestSetFrameQpRealtime, SetFrameQpOnePass) {
    602  SetUpCBR();
    603  cfg_.rc_undershoot_pct = 20;
    604  cfg_.rc_undershoot_pct = 20;
    605  cfg_.rc_max_quantizer = 50;
    606  cfg_.rc_target_bitrate = 200;
    607  cfg_.g_error_resilient = 1;
    608  cfg_.kf_max_dist = 9999;
    609  cfg_.rc_dropframe_thresh = 0;
    610 
    611  total_frames_ = 100;
    612  ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
    613                                       30, 1, 0, 100);
    614 
    615  ResetModel();
    616  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
    617 }
    618 
    619 class DatarateTestPsnr
    620    : public DatarateTest,
    621      public ::testing::TestWithParam<const libaom_test::AV1CodecFactory *> {
    622 public:
    623  DatarateTestPsnr() : DatarateTest(GetParam()) {}
    624 
    625 protected:
    626  ~DatarateTestPsnr() override = default;
    627 
    628  void SetUp() override {
    629    InitializeConfig(libaom_test::kRealTime);
    630    ResetModel();
    631    set_cpu_used_ = 10;
    632    frame_flags_ = AOM_EFLAG_CALCULATE_PSNR;
    633    expect_psnr_ = true;
    634  }
    635  void PreEncodeFrameHook(::libaom_test::VideoSource *video,
    636                          ::libaom_test::Encoder *encoder) override {
    637    DatarateTest::PreEncodeFrameHook(video, encoder);
    638    frame_flags_ ^= AOM_EFLAG_CALCULATE_PSNR;
    639 #if CONFIG_INTERNAL_STATS
    640    // CONFIG_INTERNAL_STATS unconditionally generates PSNR.
    641    expect_psnr_ = true;
    642 #else
    643    expect_psnr_ = (frame_flags_ & AOM_EFLAG_CALCULATE_PSNR) != 0;
    644 #endif  // CONFIG_INTERNAL_STATS
    645    if (video->img() == nullptr) {
    646      expect_psnr_ = false;
    647    }
    648  }
    649  void PostEncodeFrameHook(::libaom_test::Encoder *encoder) override {
    650    libaom_test::CxDataIterator iter = encoder->GetCxData();
    651 
    652    bool had_psnr = false;
    653    while (const aom_codec_cx_pkt_t *pkt = iter.Next()) {
    654      if (pkt->kind == AOM_CODEC_PSNR_PKT) had_psnr = true;
    655    }
    656 
    657    EXPECT_EQ(had_psnr, expect_psnr_);
    658  }
    659 
    660 private:
    661  bool expect_psnr_;
    662 };
    663 
    664 TEST_P(DatarateTestPsnr, PerFramePsnr) {
    665  ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
    666                                       30, 1, 0, 100);
    667 
    668  ResetModel();
    669  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
    670 }
    671 
    672 AV1_INSTANTIATE_TEST_SUITE(DatarateTestLarge,
    673                           ::testing::Values(::libaom_test::kRealTime),
    674                           ::testing::Range(5, 7), ::testing::Values(0, 3),
    675                           ::testing::Values(0, 1));
    676 
    677 AV1_INSTANTIATE_TEST_SUITE(DatarateTestFrameDropLarge,
    678                           ::testing::Values(::libaom_test::kRealTime),
    679                           ::testing::Range(5, 7), ::testing::Values(0, 3));
    680 
    681 AV1_INSTANTIATE_TEST_SUITE(DatarateTestRealtime,
    682                           ::testing::Values(::libaom_test::kRealTime),
    683                           ::testing::Range(7, 12), ::testing::Values(0, 3),
    684                           ::testing::Values(0, 1));
    685 
    686 AV1_INSTANTIATE_TEST_SUITE(DatarateTestFrameDropRealtime,
    687                           ::testing::Values(::libaom_test::kRealTime),
    688                           ::testing::Range(7, 12), ::testing::Values(0, 3));
    689 
    690 AV1_INSTANTIATE_TEST_SUITE(DatarateTestSpeedChangeRealtime,
    691                           ::testing::Values(::libaom_test::kRealTime),
    692                           ::testing::Values(0, 3));
    693 
    694 INSTANTIATE_TEST_SUITE_P(
    695    AV1, DatarateTestSetFrameQpRealtime,
    696    ::testing::Values(
    697        static_cast<const libaom_test::CodecFactory *>(&libaom_test::kAV1)));
    698 
    699 INSTANTIATE_TEST_SUITE_P(
    700    AV1, DatarateTestPsnr,
    701    ::testing::Values(
    702        static_cast<const libaom_test::CodecFactory *>(&libaom_test::kAV1)));
    703 
    704 }  // namespace
    705 }  // namespace datarate_test