blob: e3b0ef18ca96db0574ed4744f1f77c7038f5024f [file] [log] [blame]
Hui Su5aae7132019-03-15 15:07:15 -07001/*
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
13#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
14
15#include "test/codec_factory.h"
16#include "test/encode_test_driver.h"
17#include "test/util.h"
18#include "test/y4m_video_source.h"
19#include "test/yuv_video_source.h"
20
21namespace {
22// Speed settings tested
23static const int kCpuUsedVectors[] = {
24 1,
25 2,
26 3,
27 4,
28};
29
30class LevelTest
31 : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>,
32 public ::libaom_test::EncoderTest {
33 protected:
34 LevelTest()
35 : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
36 cpu_used_(GET_PARAM(2)), target_level_(31) {}
37
38 virtual ~LevelTest() {}
39
40 virtual void SetUp() {
41 InitializeConfig();
42 SetMode(encoding_mode_);
43 if (encoding_mode_ != ::libaom_test::kRealTime) {
44 cfg_.g_lag_in_frames = 5;
45 cfg_.rc_end_usage = AOM_VBR;
46 } else {
47 cfg_.g_lag_in_frames = 0;
48 cfg_.rc_end_usage = AOM_CBR;
49 cfg_.rc_buf_sz = 1000;
50 cfg_.rc_buf_initial_sz = 500;
51 cfg_.rc_buf_optimal_sz = 600;
52 }
53 }
54
55 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
56 ::libaom_test::Encoder *encoder) {
57 if (video->frame() == 0) {
58 encoder->Control(AOME_SET_CPUUSED, cpu_used_);
Hui Suecf5a3c2019-03-27 16:41:31 -070059 encoder->Control(AV1E_SET_TARGET_SEQ_LEVEL_IDX, target_level_);
Hui Su5aae7132019-03-15 15:07:15 -070060 if (encoding_mode_ != ::libaom_test::kRealTime) {
61 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
62 encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
63 encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
64 }
65 }
66 }
67
68 libaom_test::TestMode encoding_mode_;
69 int cpu_used_;
70 int target_level_;
71};
72
73TEST_P(LevelTest, TestTargetLevelApi) {
74 static const aom_codec_iface_t *codec = &aom_codec_av1_cx_algo;
75 aom_codec_ctx_t enc;
76 aom_codec_enc_cfg_t cfg;
77 EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_config_default(codec, &cfg, 0));
78 EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_init(&enc, codec, &cfg, 0));
79 for (int operating_point = 0; operating_point <= 32; ++operating_point) {
80 for (int level = 0; level <= 32; ++level) {
81 const int target_level = operating_point * 100 + level;
82 if ((level >= 0 && level <= 23) || level == 31 || operating_point > 31) {
83 EXPECT_EQ(AOM_CODEC_OK,
84 aom_codec_control(&enc, AV1E_SET_TARGET_SEQ_LEVEL_IDX,
85 target_level));
86 } else {
87 EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
88 aom_codec_control(&enc, AV1E_SET_TARGET_SEQ_LEVEL_IDX,
89 target_level));
90 }
91 }
92 }
93 EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
94}
95
Hui Suecf5a3c2019-03-27 16:41:31 -070096TEST_P(LevelTest, TestTargetLevel19) {
97 std::unique_ptr<libaom_test::VideoSource> video;
98 video.reset(new libaom_test::Y4mVideoSource("park_joy_90p_8_420.y4m", 0, 10));
99 ASSERT_TRUE(video.get() != NULL);
100 // Level index 19 corresponding to level 6.3.
101 target_level_ = 19;
102 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
103}
104
Hui Su5aae7132019-03-15 15:07:15 -0700105AV1_INSTANTIATE_TEST_CASE(LevelTest,
106 ::testing::Values(::libaom_test::kTwoPassGood),
107 ::testing::ValuesIn(kCpuUsedVectors));
108} // namespace