decode_svc_test.cc 4.5 KB

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