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