frame_size_tests.cc 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2014 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 "third_party/googletest/src/include/gtest/gtest.h"
  11. #include "test/codec_factory.h"
  12. #include "test/video_source.h"
  13. namespace {
  14. class VP9FrameSizeTestsLarge : public ::libvpx_test::EncoderTest,
  15. public ::testing::Test {
  16. protected:
  17. VP9FrameSizeTestsLarge()
  18. : EncoderTest(&::libvpx_test::kVP9), expected_res_(VPX_CODEC_OK) {}
  19. virtual ~VP9FrameSizeTestsLarge() {}
  20. virtual void SetUp() {
  21. InitializeConfig();
  22. SetMode(::libvpx_test::kRealTime);
  23. }
  24. virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec,
  25. const libvpx_test::VideoSource & /*video*/,
  26. libvpx_test::Decoder *decoder) {
  27. EXPECT_EQ(expected_res_, res_dec) << decoder->DecodeError();
  28. return !::testing::Test::HasFailure();
  29. }
  30. virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
  31. ::libvpx_test::Encoder *encoder) {
  32. if (video->frame() == 0) {
  33. encoder->Control(VP8E_SET_CPUUSED, 7);
  34. encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
  35. encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
  36. encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
  37. encoder->Control(VP8E_SET_ARNR_TYPE, 3);
  38. }
  39. }
  40. int expected_res_;
  41. };
  42. TEST_F(VP9FrameSizeTestsLarge, TestInvalidSizes) {
  43. ::libvpx_test::RandomVideoSource video;
  44. #if CONFIG_SIZE_LIMIT
  45. video.SetSize(DECODE_WIDTH_LIMIT + 16, DECODE_HEIGHT_LIMIT + 16);
  46. video.set_limit(2);
  47. expected_res_ = VPX_CODEC_CORRUPT_FRAME;
  48. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  49. #endif
  50. }
  51. TEST_F(VP9FrameSizeTestsLarge, ValidSizes) {
  52. ::libvpx_test::RandomVideoSource video;
  53. #if CONFIG_SIZE_LIMIT
  54. video.SetSize(DECODE_WIDTH_LIMIT, DECODE_HEIGHT_LIMIT);
  55. video.set_limit(2);
  56. expected_res_ = VPX_CODEC_OK;
  57. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  58. #else
  59. // This test produces a pretty large single frame allocation, (roughly
  60. // 25 megabits). The encoder allocates a good number of these frames
  61. // one for each lag in frames (for 2 pass), and then one for each possible
  62. // reference buffer (8) - we can end up with up to 30 buffers of roughly this
  63. // size or almost 1 gig of memory.
  64. // In total the allocations will exceed 2GiB which may cause a failure with
  65. // mingw + wine, use a smaller size in that case.
  66. #if defined(_WIN32) && !defined(_WIN64) || defined(__OS2__)
  67. video.SetSize(4096, 3072);
  68. #else
  69. video.SetSize(4096, 4096);
  70. #endif
  71. video.set_limit(2);
  72. expected_res_ = VPX_CODEC_OK;
  73. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  74. #endif
  75. }
  76. TEST_F(VP9FrameSizeTestsLarge, OneByOneVideo) {
  77. ::libvpx_test::RandomVideoSource video;
  78. video.SetSize(1, 1);
  79. video.set_limit(2);
  80. expected_res_ = VPX_CODEC_OK;
  81. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  82. }
  83. } // namespace