OLD | NEW |
(Empty) | |
| 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 <climits> |
| 11 #include <vector> |
| 12 #include "third_party/googletest/src/include/gtest/gtest.h" |
| 13 #include "test/codec_factory.h" |
| 14 #include "test/encode_test_driver.h" |
| 15 #include "test/i420_video_source.h" |
| 16 #include "test/util.h" |
| 17 |
| 18 namespace { |
| 19 |
| 20 class VP9FrameSizeTestsLarge |
| 21 : public ::libvpx_test::EncoderTest, |
| 22 public ::testing::Test { |
| 23 protected: |
| 24 VP9FrameSizeTestsLarge() : EncoderTest(&::libvpx_test::kVP9), |
| 25 expected_res_(VPX_CODEC_OK) {} |
| 26 virtual ~VP9FrameSizeTestsLarge() {} |
| 27 |
| 28 virtual void SetUp() { |
| 29 InitializeConfig(); |
| 30 SetMode(::libvpx_test::kRealTime); |
| 31 } |
| 32 |
| 33 virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec, |
| 34 const libvpx_test::VideoSource &video, |
| 35 libvpx_test::Decoder *decoder) { |
| 36 EXPECT_EQ(expected_res_, res_dec) |
| 37 << "Expected " << expected_res_ |
| 38 << "but got " << res_dec; |
| 39 |
| 40 return !::testing::Test::HasFailure(); |
| 41 } |
| 42 |
| 43 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, |
| 44 ::libvpx_test::Encoder *encoder) { |
| 45 if (video->frame() == 1) { |
| 46 encoder->Control(VP8E_SET_CPUUSED, 7); |
| 47 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1); |
| 48 encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7); |
| 49 encoder->Control(VP8E_SET_ARNR_STRENGTH, 5); |
| 50 encoder->Control(VP8E_SET_ARNR_TYPE, 3); |
| 51 } |
| 52 } |
| 53 |
| 54 int expected_res_; |
| 55 }; |
| 56 |
| 57 TEST_F(VP9FrameSizeTestsLarge, TestInvalidSizes) { |
| 58 ::libvpx_test::RandomVideoSource video; |
| 59 |
| 60 #if CONFIG_SIZE_LIMIT |
| 61 video.SetSize(DECODE_WIDTH_LIMIT + 16, DECODE_HEIGHT_LIMIT + 16); |
| 62 video.set_limit(2); |
| 63 expected_res_ = VPX_CODEC_CORRUPT_FRAME; |
| 64 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 65 #else |
| 66 // If we are on a 32 bit platform we can't possibly allocate enough memory |
| 67 // for the largest video frame size (64kx64k). This test checks that we |
| 68 // properly return a memory error. |
| 69 if (sizeof(size_t) == 4) { |
| 70 video.SetSize(65535, 65535); |
| 71 video.set_limit(2); |
| 72 expected_res_ = VPX_CODEC_MEM_ERROR; |
| 73 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 74 } |
| 75 #endif |
| 76 } |
| 77 |
| 78 TEST_F(VP9FrameSizeTestsLarge, ValidSizes) { |
| 79 ::libvpx_test::RandomVideoSource video; |
| 80 |
| 81 #if CONFIG_SIZE_LIMIT |
| 82 video.SetSize(DECODE_WIDTH_LIMIT, DECODE_HEIGHT_LIMIT); |
| 83 video.set_limit(2); |
| 84 expected_res_ = VPX_CODEC_OK; |
| 85 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 86 #else |
| 87 // This test produces a pretty large single frame allocation, (roughly |
| 88 // 25 megabits). The encoder allocates a good number of these frames |
| 89 // one for each lag in frames (for 2 pass), and then one for each possible |
| 90 // reference buffer (8) - we can end up with up to 30 buffers of roughly this |
| 91 // size or almost 1 gig of memory. |
| 92 video.SetSize(4096, 4096); |
| 93 video.set_limit(2); |
| 94 expected_res_ = VPX_CODEC_OK; |
| 95 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 96 #endif |
| 97 } |
| 98 } // namespace |
OLD | NEW |