blob: 12f3918179e603aa4382bad46dd91613555c6453 [file] [log] [blame]
hui sucafbf632016-05-10 10:59:33 -07001/*
Yaowu Xubde4ac82016-11-28 15:26:06 -08002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
hui sucafbf632016-05-10 10:59:33 -07003 *
Yaowu Xubde4ac82016-11-28 15:26:06 -08004 * 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.
hui sucafbf632016-05-10 10:59:33 -070010 */
Yaowu Xubde4ac82016-11-28 15:26:06 -080011
Tom Finegan7a07ece2017-02-07 17:14:05 -080012#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
hui sucafbf632016-05-10 10:59:33 -070013#include "test/codec_factory.h"
14#include "test/encode_test_driver.h"
15#include "test/i420_video_source.h"
16#include "test/util.h"
17
18namespace {
19class LevelTest
Sebastien Alaiwan4322bc12017-06-05 10:18:28 +020020 : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>,
21 public ::libaom_test::EncoderTest {
hui sucafbf632016-05-10 10:59:33 -070022 protected:
23 LevelTest()
clang-format3a826f12016-08-11 17:46:05 -070024 : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
25 cpu_used_(GET_PARAM(2)), min_gf_internal_(24), target_level_(0),
26 level_(0) {}
hui sucafbf632016-05-10 10:59:33 -070027 virtual ~LevelTest() {}
28
29 virtual void SetUp() {
30 InitializeConfig();
31 SetMode(encoding_mode_);
Yaowu Xuc27fc142016-08-22 16:08:15 -070032 if (encoding_mode_ != ::libaom_test::kRealTime) {
hui sucafbf632016-05-10 10:59:33 -070033 cfg_.g_lag_in_frames = 25;
Yaowu Xuf883b422016-08-30 14:01:10 -070034 cfg_.rc_end_usage = AOM_VBR;
hui sucafbf632016-05-10 10:59:33 -070035 } else {
36 cfg_.g_lag_in_frames = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -070037 cfg_.rc_end_usage = AOM_CBR;
hui sucafbf632016-05-10 10:59:33 -070038 }
39 cfg_.rc_2pass_vbr_minsection_pct = 5;
40 cfg_.rc_2pass_vbr_maxsection_pct = 2000;
41 cfg_.rc_target_bitrate = 400;
42 cfg_.rc_max_quantizer = 63;
43 cfg_.rc_min_quantizer = 0;
44 }
45
Yaowu Xuc27fc142016-08-22 16:08:15 -070046 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
47 ::libaom_test::Encoder *encoder) {
hui sucafbf632016-05-10 10:59:33 -070048 if (video->frame() == 0) {
Yaowu Xuf883b422016-08-30 14:01:10 -070049 encoder->Control(AOME_SET_CPUUSED, cpu_used_);
50 encoder->Control(AV1E_SET_TARGET_LEVEL, target_level_);
51 encoder->Control(AV1E_SET_MIN_GF_INTERVAL, min_gf_internal_);
Yaowu Xuc27fc142016-08-22 16:08:15 -070052 if (encoding_mode_ != ::libaom_test::kRealTime) {
Yaowu Xuf883b422016-08-30 14:01:10 -070053 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
54 encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
55 encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
hui sucafbf632016-05-10 10:59:33 -070056 }
57 }
Yaowu Xuf883b422016-08-30 14:01:10 -070058 encoder->Control(AV1E_GET_LEVEL, &level_);
hui su72d48902016-05-05 12:04:42 -070059 ASSERT_LE(level_, 51);
60 ASSERT_GE(level_, 0);
hui sucafbf632016-05-10 10:59:33 -070061 }
62
Yaowu Xuc27fc142016-08-22 16:08:15 -070063 ::libaom_test::TestMode encoding_mode_;
hui sucafbf632016-05-10 10:59:33 -070064 int cpu_used_;
hui su72d48902016-05-05 12:04:42 -070065 int min_gf_internal_;
hui sucafbf632016-05-10 10:59:33 -070066 int target_level_;
hui su72d48902016-05-05 12:04:42 -070067 int level_;
hui sucafbf632016-05-10 10:59:33 -070068};
69
hui su72d48902016-05-05 12:04:42 -070070// Test for keeping level stats only
hui sucafbf632016-05-10 10:59:33 -070071TEST_P(LevelTest, TestTargetLevel0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -070072 ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
hui su72d48902016-05-05 12:04:42 -070073 40);
hui sucafbf632016-05-10 10:59:33 -070074 target_level_ = 0;
hui su72d48902016-05-05 12:04:42 -070075 min_gf_internal_ = 4;
hui sucafbf632016-05-10 10:59:33 -070076 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
hui su72d48902016-05-05 12:04:42 -070077 ASSERT_EQ(11, level_);
78
79 cfg_.rc_target_bitrate = 1600;
80 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
81 ASSERT_EQ(20, level_);
hui sucafbf632016-05-10 10:59:33 -070082}
83
hui su72d48902016-05-05 12:04:42 -070084// Test for level control being turned off
hui sucafbf632016-05-10 10:59:33 -070085TEST_P(LevelTest, TestTargetLevel255) {
Yaowu Xuc27fc142016-08-22 16:08:15 -070086 ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
hui sucafbf632016-05-10 10:59:33 -070087 30);
88 target_level_ = 255;
89 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
90}
91
92TEST_P(LevelTest, TestTargetLevelApi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -070093 ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0, 1);
Yaowu Xuf883b422016-08-30 14:01:10 -070094 static const aom_codec_iface_t *codec = &aom_codec_av1_cx_algo;
95 aom_codec_ctx_t enc;
96 aom_codec_enc_cfg_t cfg;
97 EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_config_default(codec, &cfg, 0));
98 EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_init(&enc, codec, &cfg, 0));
hui sucafbf632016-05-10 10:59:33 -070099 for (int level = 0; level <= 256; ++level) {
100 if (level == 10 || level == 11 || level == 20 || level == 21 ||
101 level == 30 || level == 31 || level == 40 || level == 41 ||
102 level == 50 || level == 51 || level == 52 || level == 60 ||
103 level == 61 || level == 62 || level == 0 || level == 255)
Yaowu Xuf883b422016-08-30 14:01:10 -0700104 EXPECT_EQ(AOM_CODEC_OK,
105 aom_codec_control(&enc, AV1E_SET_TARGET_LEVEL, level));
hui sucafbf632016-05-10 10:59:33 -0700106 else
Yaowu Xuf883b422016-08-30 14:01:10 -0700107 EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
108 aom_codec_control(&enc, AV1E_SET_TARGET_LEVEL, level));
hui sucafbf632016-05-10 10:59:33 -0700109 }
Yaowu Xuf883b422016-08-30 14:01:10 -0700110 EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
hui sucafbf632016-05-10 10:59:33 -0700111}
112
Yaowu Xuf883b422016-08-30 14:01:10 -0700113AV1_INSTANTIATE_TEST_CASE(LevelTest,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700114 ::testing::Values(::libaom_test::kTwoPassGood,
115 ::libaom_test::kOnePassGood),
hui sucafbf632016-05-10 10:59:33 -0700116 ::testing::Range(0, 9));
117} // namespace