1 /*
2  * Copyright (c) 2018, 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 "third_party/googletest/src/googletest/include/gtest/gtest.h"
13 #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 
18 namespace {
19 
20 const int kCpuUsed = 8;
21 const int kBaseLayerQp = 55;
22 const int kEnhancementLayerQp = 20;
23 
24 class ScalabilityTest
25     : public ::libaom_test::CodecTestWithParam<libaom_test::TestMode>,
26       public ::libaom_test::EncoderTest {
27  protected:
ScalabilityTest()28   ScalabilityTest() : EncoderTest(GET_PARAM(0)) {}
~ScalabilityTest()29   virtual ~ScalabilityTest() {}
30 
SetUp()31   virtual void SetUp() {
32     InitializeConfig();
33     SetMode(GET_PARAM(1));
34     num_spatial_layers_ = 2;
35   }
36 
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)37   virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
38                                   ::libaom_test::Encoder *encoder) {
39     if (video->frame() == 0) {
40       encoder->Control(AOME_SET_CPUUSED, kCpuUsed);
41       encoder->Control(AOME_SET_NUMBER_SPATIAL_LAYERS, num_spatial_layers_);
42     } else if (video->frame() % num_spatial_layers_) {
43       frame_flags_ = AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 |
44                      AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF |
45                      AOM_EFLAG_NO_REF_BWD | AOM_EFLAG_NO_REF_ARF2 |
46                      AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF |
47                      AOM_EFLAG_NO_UPD_ARF | AOM_EFLAG_NO_UPD_ENTROPY;
48       encoder->Control(AOME_SET_SPATIAL_LAYER_ID, 1);
49       encoder->Control(AOME_SET_CQ_LEVEL, kEnhancementLayerQp);
50     } else {
51       frame_flags_ = AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 |
52                      AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF |
53                      AOM_EFLAG_NO_REF_BWD | AOM_EFLAG_NO_REF_ARF2 |
54                      AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF |
55                      AOM_EFLAG_NO_UPD_ENTROPY;
56       encoder->Control(AOME_SET_SPATIAL_LAYER_ID, 0);
57       encoder->Control(AOME_SET_CQ_LEVEL, kBaseLayerQp);
58     }
59   }
60 
DoTest(int num_spatial_layers)61   void DoTest(int num_spatial_layers) {
62     num_spatial_layers_ = num_spatial_layers;
63     cfg_.rc_end_usage = AOM_Q;
64     cfg_.g_lag_in_frames = 0;
65 
66     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
67                                          288, 30, 1, 0, 18);
68     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
69   }
70 
71   int num_spatial_layers_;
72 };
73 
TEST_P(ScalabilityTest,TestNoMismatch2SpatialLayers)74 TEST_P(ScalabilityTest, TestNoMismatch2SpatialLayers) { DoTest(2); }
75 
TEST_P(ScalabilityTest,TestNoMismatch3SpatialLayers)76 TEST_P(ScalabilityTest, TestNoMismatch3SpatialLayers) { DoTest(3); }
77 
78 AV1_INSTANTIATE_TEST_CASE(ScalabilityTest,
79                           ::testing::Values(::libaom_test::kRealTime));
80 
81 }  // namespace
82