level_test.cc 4.2 KB
Newer Older
hui su's avatar
hui su committed
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
hui su's avatar
hui su committed
3
 *
4
5
6
7
8
9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
hui su's avatar
hui su committed
10
 */
11

12
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
hui su's avatar
hui su committed
13
14
15
16
17
18
19
#include "test/codec_factory.h"
#include "test/encode_test_driver.h"
#include "test/i420_video_source.h"
#include "test/util.h"

namespace {
class LevelTest
20
21
    : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>,
      public ::libaom_test::EncoderTest {
hui su's avatar
hui su committed
22
23
 protected:
  LevelTest()
clang-format's avatar
clang-format committed
24
25
26
      : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
        cpu_used_(GET_PARAM(2)), min_gf_internal_(24), target_level_(0),
        level_(0) {}
hui su's avatar
hui su committed
27
28
29
30
31
  virtual ~LevelTest() {}

  virtual void SetUp() {
    InitializeConfig();
    SetMode(encoding_mode_);
32
    if (encoding_mode_ != ::libaom_test::kRealTime) {
hui su's avatar
hui su committed
33
      cfg_.g_lag_in_frames = 25;
Yaowu Xu's avatar
Yaowu Xu committed
34
      cfg_.rc_end_usage = AOM_VBR;
hui su's avatar
hui su committed
35
36
    } else {
      cfg_.g_lag_in_frames = 0;
Yaowu Xu's avatar
Yaowu Xu committed
37
      cfg_.rc_end_usage = AOM_CBR;
hui su's avatar
hui su committed
38
39
40
41
42
43
44
45
    }
    cfg_.rc_2pass_vbr_minsection_pct = 5;
    cfg_.rc_2pass_vbr_maxsection_pct = 2000;
    cfg_.rc_target_bitrate = 400;
    cfg_.rc_max_quantizer = 63;
    cfg_.rc_min_quantizer = 0;
  }

46
47
  virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
                                  ::libaom_test::Encoder *encoder) {
hui su's avatar
hui su committed
48
    if (video->frame() == 0) {
Yaowu Xu's avatar
Yaowu Xu committed
49
50
51
      encoder->Control(AOME_SET_CPUUSED, cpu_used_);
      encoder->Control(AV1E_SET_TARGET_LEVEL, target_level_);
      encoder->Control(AV1E_SET_MIN_GF_INTERVAL, min_gf_internal_);
52
      if (encoding_mode_ != ::libaom_test::kRealTime) {
Yaowu Xu's avatar
Yaowu Xu committed
53
54
55
        encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
        encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
        encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
hui su's avatar
hui su committed
56
57
      }
    }
Yaowu Xu's avatar
Yaowu Xu committed
58
    encoder->Control(AV1E_GET_LEVEL, &level_);
59
60
    ASSERT_LE(level_, 51);
    ASSERT_GE(level_, 0);
hui su's avatar
hui su committed
61
62
  }

63
  ::libaom_test::TestMode encoding_mode_;
hui su's avatar
hui su committed
64
  int cpu_used_;
65
  int min_gf_internal_;
hui su's avatar
hui su committed
66
  int target_level_;
67
  int level_;
hui su's avatar
hui su committed
68
69
};

70
// Test for keeping level stats only
hui su's avatar
hui su committed
71
TEST_P(LevelTest, TestTargetLevel0) {
72
  ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
73
                                       40);
hui su's avatar
hui su committed
74
  target_level_ = 0;
75
76
77
78
79
  min_gf_internal_ = 4;
  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  ASSERT_EQ(11, level_);

  cfg_.rc_target_bitrate = 1600;
hui su's avatar
hui su committed
80
  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
81
  ASSERT_EQ(20, level_);
hui su's avatar
hui su committed
82
83
}

84
// Test for level control being turned off
hui su's avatar
hui su committed
85
TEST_P(LevelTest, TestTargetLevel255) {
86
  ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
hui su's avatar
hui su committed
87
88
89
90
91
92
                                       30);
  target_level_ = 255;
  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
}

TEST_P(LevelTest, TestTargetLevelApi) {
93
  ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0, 1);
Yaowu Xu's avatar
Yaowu Xu committed
94
95
96
97
98
  static const aom_codec_iface_t *codec = &aom_codec_av1_cx_algo;
  aom_codec_ctx_t enc;
  aom_codec_enc_cfg_t cfg;
  EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_config_default(codec, &cfg, 0));
  EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_init(&enc, codec, &cfg, 0));
hui su's avatar
hui su committed
99
100
101
102
103
  for (int level = 0; level <= 256; ++level) {
    if (level == 10 || level == 11 || level == 20 || level == 21 ||
        level == 30 || level == 31 || level == 40 || level == 41 ||
        level == 50 || level == 51 || level == 52 || level == 60 ||
        level == 61 || level == 62 || level == 0 || level == 255)
Yaowu Xu's avatar
Yaowu Xu committed
104
105
      EXPECT_EQ(AOM_CODEC_OK,
                aom_codec_control(&enc, AV1E_SET_TARGET_LEVEL, level));
hui su's avatar
hui su committed
106
    else
Yaowu Xu's avatar
Yaowu Xu committed
107
108
      EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
                aom_codec_control(&enc, AV1E_SET_TARGET_LEVEL, level));
hui su's avatar
hui su committed
109
  }
Yaowu Xu's avatar
Yaowu Xu committed
110
  EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
hui su's avatar
hui su committed
111
112
}

Yaowu Xu's avatar
Yaowu Xu committed
113
AV1_INSTANTIATE_TEST_CASE(LevelTest,
114
115
                          ::testing::Values(::libaom_test::kTwoPassGood,
                                            ::libaom_test::kOnePassGood),
hui su's avatar
hui su committed
116
117
                          ::testing::Range(0, 9));
}  // namespace