1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2018, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
13*77c1e3ccSAndroid Build Coastguard Worker #include "test/codec_factory.h"
14*77c1e3ccSAndroid Build Coastguard Worker #include "test/encode_test_driver.h"
15*77c1e3ccSAndroid Build Coastguard Worker #include "test/i420_video_source.h"
16*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
17*77c1e3ccSAndroid Build Coastguard Worker
18*77c1e3ccSAndroid Build Coastguard Worker namespace {
19*77c1e3ccSAndroid Build Coastguard Worker
20*77c1e3ccSAndroid Build Coastguard Worker const int kCpuUsed = 8;
21*77c1e3ccSAndroid Build Coastguard Worker const int kBaseLayerQp = 55;
22*77c1e3ccSAndroid Build Coastguard Worker const int kEnhancementLayerQp = 20;
23*77c1e3ccSAndroid Build Coastguard Worker
24*77c1e3ccSAndroid Build Coastguard Worker class ScalabilityTest
25*77c1e3ccSAndroid Build Coastguard Worker : public ::libaom_test::CodecTestWithParam<libaom_test::TestMode>,
26*77c1e3ccSAndroid Build Coastguard Worker public ::libaom_test::EncoderTest {
27*77c1e3ccSAndroid Build Coastguard Worker protected:
ScalabilityTest()28*77c1e3ccSAndroid Build Coastguard Worker ScalabilityTest() : EncoderTest(GET_PARAM(0)) {}
29*77c1e3ccSAndroid Build Coastguard Worker ~ScalabilityTest() override = default;
30*77c1e3ccSAndroid Build Coastguard Worker
SetUp()31*77c1e3ccSAndroid Build Coastguard Worker void SetUp() override {
32*77c1e3ccSAndroid Build Coastguard Worker InitializeConfig(GET_PARAM(1));
33*77c1e3ccSAndroid Build Coastguard Worker num_spatial_layers_ = 2;
34*77c1e3ccSAndroid Build Coastguard Worker }
35*77c1e3ccSAndroid Build Coastguard Worker
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)36*77c1e3ccSAndroid Build Coastguard Worker void PreEncodeFrameHook(::libaom_test::VideoSource *video,
37*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Encoder *encoder) override {
38*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() == 0) {
39*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_CPUUSED, kCpuUsed);
40*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_NUMBER_SPATIAL_LAYERS, num_spatial_layers_);
41*77c1e3ccSAndroid Build Coastguard Worker }
42*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() % num_spatial_layers_) {
43*77c1e3ccSAndroid Build Coastguard Worker frame_flags_ = AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 |
44*77c1e3ccSAndroid Build Coastguard Worker AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF |
45*77c1e3ccSAndroid Build Coastguard Worker AOM_EFLAG_NO_REF_BWD | AOM_EFLAG_NO_REF_ARF2 |
46*77c1e3ccSAndroid Build Coastguard Worker AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF |
47*77c1e3ccSAndroid Build Coastguard Worker AOM_EFLAG_NO_UPD_ARF | AOM_EFLAG_NO_UPD_ENTROPY;
48*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_SPATIAL_LAYER_ID, 1);
49*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_CQ_LEVEL, kEnhancementLayerQp);
50*77c1e3ccSAndroid Build Coastguard Worker } else {
51*77c1e3ccSAndroid Build Coastguard Worker frame_flags_ = AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 |
52*77c1e3ccSAndroid Build Coastguard Worker AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF |
53*77c1e3ccSAndroid Build Coastguard Worker AOM_EFLAG_NO_REF_BWD | AOM_EFLAG_NO_REF_ARF2 |
54*77c1e3ccSAndroid Build Coastguard Worker AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF |
55*77c1e3ccSAndroid Build Coastguard Worker AOM_EFLAG_NO_UPD_ENTROPY;
56*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_SPATIAL_LAYER_ID, 0);
57*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_CQ_LEVEL, kBaseLayerQp);
58*77c1e3ccSAndroid Build Coastguard Worker }
59*77c1e3ccSAndroid Build Coastguard Worker }
60*77c1e3ccSAndroid Build Coastguard Worker
DoTest(int num_spatial_layers)61*77c1e3ccSAndroid Build Coastguard Worker void DoTest(int num_spatial_layers) {
62*77c1e3ccSAndroid Build Coastguard Worker num_spatial_layers_ = num_spatial_layers;
63*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_end_usage = AOM_Q;
64*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_lag_in_frames = 0;
65*77c1e3ccSAndroid Build Coastguard Worker
66*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
67*77c1e3ccSAndroid Build Coastguard Worker 288, 30, 1, 0, 18);
68*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
69*77c1e3ccSAndroid Build Coastguard Worker }
70*77c1e3ccSAndroid Build Coastguard Worker
71*77c1e3ccSAndroid Build Coastguard Worker int num_spatial_layers_;
72*77c1e3ccSAndroid Build Coastguard Worker };
73*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(ScalabilityTest,TestNoMismatch2SpatialLayers)74*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ScalabilityTest, TestNoMismatch2SpatialLayers) { DoTest(2); }
75*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(ScalabilityTest,TestNoMismatch3SpatialLayers)76*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ScalabilityTest, TestNoMismatch3SpatialLayers) { DoTest(3); }
77*77c1e3ccSAndroid Build Coastguard Worker
78*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(ScalabilityTest,
79*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(::libaom_test::kRealTime));
80*77c1e3ccSAndroid Build Coastguard Worker
81*77c1e3ccSAndroid Build Coastguard Worker } // namespace
82