decode_svc_test.cc 4.5 KB

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