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)) {}
~DecodeSvcTest()28 virtual ~DecodeSvcTest() {}
29
PreDecodeFrameHook(const libvpx_test::CompressedVideoSource & video,libvpx_test::Decoder * decoder)30 virtual void PreDecodeFrameHook(
31 const libvpx_test::CompressedVideoSource &video,
32 libvpx_test::Decoder *decoder) {
33 if (video.frame_number() == 0)
34 decoder->Control(VP9_DECODE_SVC_SPATIAL_LAYER, spatial_layer_);
35 }
36
DecompressedFrameHook(const vpx_image_t & img,const unsigned int frame_number)37 virtual void DecompressedFrameHook(const vpx_image_t &img,
38 const unsigned int frame_number) {
39 ASSERT_EQ(img.d_w, width_);
40 ASSERT_EQ(img.d_h, height_);
41 total_frames_ = frame_number;
42 }
43
44 int spatial_layer_;
45 unsigned int width_;
46 unsigned int height_;
47 unsigned int total_frames_;
48 };
49
50 // SVC test vector is 1280x720, with 3 spatial layers, and 20 frames.
51
52 // Decode the SVC test vector, which has 3 spatial layers, and decode up to
53 // spatial layer 0. Verify the resolution of each decoded frame and the total
54 // number of frames decoded. This results in 1/4x1/4 resolution (320x180).
TEST_P(DecodeSvcTest,DecodeSvcTestUpToSpatialLayer0)55 TEST_P(DecodeSvcTest, DecodeSvcTestUpToSpatialLayer0) {
56 const std::string filename = GET_PARAM(1);
57 std::unique_ptr<libvpx_test::CompressedVideoSource> video;
58 video.reset(new libvpx_test::IVFVideoSource(filename));
59 ASSERT_TRUE(video.get() != NULL);
60 video->Init();
61 total_frames_ = 0;
62 spatial_layer_ = 0;
63 width_ = 320;
64 height_ = 180;
65 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
66 ASSERT_EQ(total_frames_, kNumFrames);
67 }
68
69 // Decode the SVC test vector, which has 3 spatial layers, and decode up to
70 // spatial layer 1. Verify the resolution of each decoded frame and the total
71 // number of frames decoded. This results in 1/2x1/2 resolution (640x360).
TEST_P(DecodeSvcTest,DecodeSvcTestUpToSpatialLayer1)72 TEST_P(DecodeSvcTest, DecodeSvcTestUpToSpatialLayer1) {
73 const std::string filename = GET_PARAM(1);
74 std::unique_ptr<libvpx_test::CompressedVideoSource> video;
75 video.reset(new libvpx_test::IVFVideoSource(filename));
76 ASSERT_TRUE(video.get() != NULL);
77 video->Init();
78 total_frames_ = 0;
79 spatial_layer_ = 1;
80 width_ = 640;
81 height_ = 360;
82 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
83 ASSERT_EQ(total_frames_, kNumFrames);
84 }
85
86 // Decode the SVC test vector, which has 3 spatial layers, and decode up to
87 // spatial layer 2. Verify the resolution of each decoded frame and the total
88 // number of frames decoded. This results in the full resolution (1280x720).
TEST_P(DecodeSvcTest,DecodeSvcTestUpToSpatialLayer2)89 TEST_P(DecodeSvcTest, DecodeSvcTestUpToSpatialLayer2) {
90 const std::string filename = GET_PARAM(1);
91 std::unique_ptr<libvpx_test::CompressedVideoSource> video;
92 video.reset(new libvpx_test::IVFVideoSource(filename));
93 ASSERT_TRUE(video.get() != NULL);
94 video->Init();
95 total_frames_ = 0;
96 spatial_layer_ = 2;
97 width_ = 1280;
98 height_ = 720;
99 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
100 ASSERT_EQ(total_frames_, kNumFrames);
101 }
102
103 // Decode the SVC test vector, which has 3 spatial layers, and decode up to
104 // spatial layer 10. Verify the resolution of each decoded frame and the total
105 // number of frames decoded. This is beyond the number of spatial layers, so
106 // the decoding should result in the full resolution (1280x720).
TEST_P(DecodeSvcTest,DecodeSvcTestUpToSpatialLayer10)107 TEST_P(DecodeSvcTest, DecodeSvcTestUpToSpatialLayer10) {
108 const std::string filename = GET_PARAM(1);
109 std::unique_ptr<libvpx_test::CompressedVideoSource> video;
110 video.reset(new libvpx_test::IVFVideoSource(filename));
111 ASSERT_TRUE(video.get() != NULL);
112 video->Init();
113 total_frames_ = 0;
114 spatial_layer_ = 10;
115 width_ = 1280;
116 height_ = 720;
117 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
118 ASSERT_EQ(total_frames_, kNumFrames);
119 }
120
121 VP9_INSTANTIATE_TEST_CASE(
122 DecodeSvcTest, ::testing::ValuesIn(libvpx_test::kVP9TestVectorsSvc,
123 libvpx_test::kVP9TestVectorsSvc +
124 libvpx_test::kNumVP9TestVectorsSvc));
125 } // namespace
126