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