vp9[loongarch]: Optimize fdct4x4/8x8_lsx
[platform/upstream/libvpx.git] / test / realtime_test.cc
1 /*
2  *  Copyright (c) 2016 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 <limits.h>
11
12 #include "test/codec_factory.h"
13 #include "test/encode_test_driver.h"
14 #include "test/util.h"
15 #include "test/video_source.h"
16 #include "third_party/googletest/src/include/gtest/gtest.h"
17
18 namespace {
19
20 const int kVideoSourceWidth = 320;
21 const int kVideoSourceHeight = 240;
22 const int kFramesToEncode = 2;
23
24 class RealtimeTest
25     : public ::libvpx_test::EncoderTest,
26       public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
27  protected:
28   RealtimeTest() : EncoderTest(GET_PARAM(0)), frame_packets_(0) {}
29   ~RealtimeTest() override {}
30
31   void SetUp() override {
32     InitializeConfig();
33     cfg_.g_lag_in_frames = 0;
34     SetMode(::libvpx_test::kRealTime);
35   }
36
37   void BeginPassHook(unsigned int /*pass*/) override {
38     // TODO(tomfinegan): We're changing the pass value here to make sure
39     // we get frames when real time mode is combined with |g_pass| set to
40     // VPX_RC_FIRST_PASS. This is necessary because EncoderTest::RunLoop() sets
41     // the pass value based on the mode passed into EncoderTest::SetMode(),
42     // which overrides the one specified in SetUp() above.
43     cfg_.g_pass = VPX_RC_FIRST_PASS;
44   }
45
46   void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
47                           ::libvpx_test::Encoder *encoder) override {
48     if (video->frame() == 0) {
49       encoder->Control(VP8E_SET_CPUUSED, 8);
50     }
51   }
52
53   void FramePktHook(const vpx_codec_cx_pkt_t * /*pkt*/) override {
54     frame_packets_++;
55   }
56
57   bool IsVP9() const {
58 #if CONFIG_VP9_ENCODER
59     return codec_ == &libvpx_test::kVP9;
60 #else
61     return false;
62 #endif
63   }
64
65   void TestIntegerOverflow(unsigned int width, unsigned int height) {
66     ::libvpx_test::RandomVideoSource video;
67     video.SetSize(width, height);
68     video.set_limit(20);
69     cfg_.rc_target_bitrate = UINT_MAX;
70     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
71   }
72
73   int frame_packets_;
74 };
75
76 TEST_P(RealtimeTest, RealtimeFirstPassProducesFrames) {
77   ::libvpx_test::RandomVideoSource video;
78   video.SetSize(kVideoSourceWidth, kVideoSourceHeight);
79   video.set_limit(kFramesToEncode);
80   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
81   EXPECT_EQ(kFramesToEncode, frame_packets_);
82 }
83
84 TEST_P(RealtimeTest, IntegerOverflow) { TestIntegerOverflow(2048, 2048); }
85
86 TEST_P(RealtimeTest, IntegerOverflowLarge) {
87   if (IsVP9()) {
88 #if VPX_ARCH_X86_64
89     TestIntegerOverflow(16384, 16384);
90 #else
91     TestIntegerOverflow(4096, 4096);
92 #endif
93   } else {
94     GTEST_SKIP()
95         << "TODO(https://crbug.com/webm/1748,https://crbug.com/webm/1751):"
96         << " Enable this test after bitstream errors & undefined sanitizer "
97            "warnings are fixed.";
98     // TestIntegerOverflow(16383, 16383);
99   }
100 }
101
102 VP8_INSTANTIATE_TEST_SUITE(RealtimeTest,
103                            ::testing::Values(::libvpx_test::kRealTime));
104 VP9_INSTANTIATE_TEST_SUITE(RealtimeTest,
105                            ::testing::Values(::libvpx_test::kRealTime));
106
107 }  // namespace