1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
13 #include "test/codec_factory.h"
14 #include "test/video_source.h"
15 
16 namespace {
17 
18 class AV1FrameSizeTests : public ::testing::Test,
19                           public ::libaom_test::EncoderTest {
20  protected:
AV1FrameSizeTests()21   AV1FrameSizeTests()
22       : EncoderTest(&::libaom_test::kAV1), expected_res_(AOM_CODEC_OK) {}
~AV1FrameSizeTests()23   virtual ~AV1FrameSizeTests() {}
24 
SetUp()25   virtual void SetUp() {
26     InitializeConfig();
27     SetMode(::libaom_test::kRealTime);
28   }
29 
HandleDecodeResult(const aom_codec_err_t res_dec,libaom_test::Decoder * decoder)30   virtual bool HandleDecodeResult(const aom_codec_err_t res_dec,
31                                   libaom_test::Decoder *decoder) {
32     EXPECT_EQ(expected_res_, res_dec) << decoder->DecodeError();
33     return !::testing::Test::HasFailure();
34   }
35 
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)36   virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
37                                   ::libaom_test::Encoder *encoder) {
38     if (video->frame() == 0) {
39       encoder->Control(AOME_SET_CPUUSED, 7);
40       encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
41       encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
42       encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
43     }
44   }
45 
46   int expected_res_;
47 };
48 
49 #if CONFIG_SIZE_LIMIT
TEST_F(AV1FrameSizeTests,TestInvalidSizes)50 TEST_F(AV1FrameSizeTests, TestInvalidSizes) {
51   ::libaom_test::RandomVideoSource video;
52 
53   video.SetSize(DECODE_WIDTH_LIMIT + 16, DECODE_HEIGHT_LIMIT + 16);
54   video.set_limit(2);
55   expected_res_ = AOM_CODEC_CORRUPT_FRAME;
56   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
57 }
58 
TEST_F(AV1FrameSizeTests,LargeValidSizes)59 TEST_F(AV1FrameSizeTests, LargeValidSizes) {
60   ::libaom_test::RandomVideoSource video;
61 
62   video.SetSize(DECODE_WIDTH_LIMIT, DECODE_HEIGHT_LIMIT);
63   video.set_limit(2);
64   expected_res_ = AOM_CODEC_OK;
65   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
66 }
67 #endif
68 
TEST_F(AV1FrameSizeTests,OneByOneVideo)69 TEST_F(AV1FrameSizeTests, OneByOneVideo) {
70   ::libaom_test::RandomVideoSource video;
71 
72   video.SetSize(1, 1);
73   video.set_limit(2);
74   expected_res_ = AOM_CODEC_OK;
75   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
76 }
77 #undef ONE_BY_ONE_VIDEO_NAME
78 }  // namespace
79