xref: /aosp_15_r20/external/libvpx/test/decode_svc_test.cc (revision fb1b10ab9aebc7c7068eedab379b749d7e3900be)
1 /*
2  *  Copyright (c) 2016 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include <memory>
12 #include <string>
13 
14 #include "test/codec_factory.h"
15 #include "test/decode_test_driver.h"
16 #include "test/ivf_video_source.h"
17 #include "test/test_vectors.h"
18 #include "test/util.h"
19 
20 namespace {
21 
22 const unsigned int kNumFrames = 19;
23 
24 class DecodeSvcTest : public ::libvpx_test::DecoderTest,
25                       public ::libvpx_test::CodecTestWithParam<const char *> {
26  protected:
DecodeSvcTest()27   DecodeSvcTest() : DecoderTest(GET_PARAM(::libvpx_test::kCodecFactoryParam)) {}
28   ~DecodeSvcTest() override = default;
29 
PreDecodeFrameHook(const libvpx_test::CompressedVideoSource & video,libvpx_test::Decoder * decoder)30   void PreDecodeFrameHook(const libvpx_test::CompressedVideoSource &video,
31                           libvpx_test::Decoder *decoder) override {
32     if (video.frame_number() == 0)
33       decoder->Control(VP9_DECODE_SVC_SPATIAL_LAYER, spatial_layer_);
34   }
35 
DecompressedFrameHook(const vpx_image_t & img,const unsigned int frame_number)36   void DecompressedFrameHook(const vpx_image_t &img,
37                              const unsigned int frame_number) override {
38     ASSERT_EQ(img.d_w, width_);
39     ASSERT_EQ(img.d_h, height_);
40     total_frames_ = frame_number;
41   }
42 
43   int spatial_layer_;
44   unsigned int width_;
45   unsigned int height_;
46   unsigned int total_frames_;
47 };
48 
49 // SVC test vector is 1280x720, with 3 spatial layers, and 20 frames.
50 
51 // Decode the SVC test vector, which has 3 spatial layers, and decode up to
52 // spatial layer 0. Verify the resolution of each decoded frame and the total
53 // number of frames decoded. This results in 1/4x1/4 resolution (320x180).
TEST_P(DecodeSvcTest,DecodeSvcTestUpToSpatialLayer0)54 TEST_P(DecodeSvcTest, DecodeSvcTestUpToSpatialLayer0) {
55   const std::string filename = GET_PARAM(1);
56   std::unique_ptr<libvpx_test::CompressedVideoSource> video;
57   video.reset(new libvpx_test::IVFVideoSource(filename));
58   ASSERT_NE(video.get(), nullptr);
59   video->Init();
60   total_frames_ = 0;
61   spatial_layer_ = 0;
62   width_ = 320;
63   height_ = 180;
64   ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
65   ASSERT_EQ(total_frames_, kNumFrames);
66 }
67 
68 // Decode the SVC test vector, which has 3 spatial layers, and decode up to
69 // spatial layer 1. Verify the resolution of each decoded frame and the total
70 // number of frames decoded. This results in 1/2x1/2 resolution (640x360).
TEST_P(DecodeSvcTest,DecodeSvcTestUpToSpatialLayer1)71 TEST_P(DecodeSvcTest, DecodeSvcTestUpToSpatialLayer1) {
72   const std::string filename = GET_PARAM(1);
73   std::unique_ptr<libvpx_test::CompressedVideoSource> video;
74   video.reset(new libvpx_test::IVFVideoSource(filename));
75   ASSERT_NE(video.get(), nullptr);
76   video->Init();
77   total_frames_ = 0;
78   spatial_layer_ = 1;
79   width_ = 640;
80   height_ = 360;
81   ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
82   ASSERT_EQ(total_frames_, kNumFrames);
83 }
84 
85 // Decode the SVC test vector, which has 3 spatial layers, and decode up to
86 // spatial layer 2. Verify the resolution of each decoded frame and the total
87 // number of frames decoded. This results in the full resolution (1280x720).
TEST_P(DecodeSvcTest,DecodeSvcTestUpToSpatialLayer2)88 TEST_P(DecodeSvcTest, DecodeSvcTestUpToSpatialLayer2) {
89   const std::string filename = GET_PARAM(1);
90   std::unique_ptr<libvpx_test::CompressedVideoSource> video;
91   video.reset(new libvpx_test::IVFVideoSource(filename));
92   ASSERT_NE(video.get(), nullptr);
93   video->Init();
94   total_frames_ = 0;
95   spatial_layer_ = 2;
96   width_ = 1280;
97   height_ = 720;
98   ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
99   ASSERT_EQ(total_frames_, kNumFrames);
100 }
101 
102 // Decode the SVC test vector, which has 3 spatial layers, and decode up to
103 // spatial layer 10. Verify the resolution of each decoded frame and the total
104 // number of frames decoded. This is beyond the number of spatial layers, so
105 // the decoding should result in the full resolution (1280x720).
TEST_P(DecodeSvcTest,DecodeSvcTestUpToSpatialLayer10)106 TEST_P(DecodeSvcTest, DecodeSvcTestUpToSpatialLayer10) {
107   const std::string filename = GET_PARAM(1);
108   std::unique_ptr<libvpx_test::CompressedVideoSource> video;
109   video.reset(new libvpx_test::IVFVideoSource(filename));
110   ASSERT_NE(video.get(), nullptr);
111   video->Init();
112   total_frames_ = 0;
113   spatial_layer_ = 10;
114   width_ = 1280;
115   height_ = 720;
116   ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
117   ASSERT_EQ(total_frames_, kNumFrames);
118 }
119 
120 VP9_INSTANTIATE_TEST_SUITE(
121     DecodeSvcTest, ::testing::ValuesIn(libvpx_test::kVP9TestVectorsSvc,
122                                        libvpx_test::kVP9TestVectorsSvc +
123                                            libvpx_test::kNumVP9TestVectorsSvc));
124 }  // namespace
125