xref: /aosp_15_r20/external/libvpx/test/realtime_test.cc (revision fb1b10ab9aebc7c7068eedab379b749d7e3900be)
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 "gtest/gtest.h"
13 #include "test/codec_factory.h"
14 #include "test/encode_test_driver.h"
15 #include "test/util.h"
16 #include "test/video_source.h"
17 #include "vpx_config.h"
18 
19 namespace {
20 
21 const int kVideoSourceWidth = 320;
22 const int kVideoSourceHeight = 240;
23 const int kFramesToEncode = 2;
24 
25 class RealtimeTest
26     : public ::libvpx_test::EncoderTest,
27       public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
28  protected:
RealtimeTest()29   RealtimeTest() : EncoderTest(GET_PARAM(0)), frame_packets_(0) {}
30   ~RealtimeTest() override = default;
31 
SetUp()32   void SetUp() override {
33     InitializeConfig();
34     cfg_.g_lag_in_frames = 0;
35     SetMode(::libvpx_test::kRealTime);
36   }
37 
BeginPassHook(unsigned int)38   void BeginPassHook(unsigned int /*pass*/) override {
39 #if !CONFIG_REALTIME_ONLY
40     // TODO(tomfinegan): We're changing the pass value here to make sure
41     // we get frames when real time mode is combined with |g_pass| set to
42     // VPX_RC_FIRST_PASS. This is necessary because EncoderTest::RunLoop() sets
43     // the pass value based on the mode passed into EncoderTest::SetMode(),
44     // which overrides the one specified in SetUp() above.
45     cfg_.g_pass = VPX_RC_FIRST_PASS;
46 #endif
47   }
48 
PreEncodeFrameHook(::libvpx_test::VideoSource * video,::libvpx_test::Encoder * encoder)49   void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
50                           ::libvpx_test::Encoder *encoder) override {
51     if (video->frame() == 0 && set_cpu_used_) {
52       encoder->Control(VP8E_SET_CPUUSED, 8);
53     }
54   }
55 
FramePktHook(const vpx_codec_cx_pkt_t *)56   void FramePktHook(const vpx_codec_cx_pkt_t * /*pkt*/) override {
57     frame_packets_++;
58   }
59 
IsVP9() const60   bool IsVP9() const {
61 #if CONFIG_VP9_ENCODER
62     return codec_ == &libvpx_test::kVP9;
63 #else
64     return false;
65 #endif
66   }
67 
TestIntegerOverflow(unsigned int width,unsigned int height)68   void TestIntegerOverflow(unsigned int width, unsigned int height) {
69     ::libvpx_test::RandomVideoSource video;
70     video.SetSize(width, height);
71     video.set_limit(20);
72     cfg_.rc_target_bitrate = UINT_MAX;
73     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
74   }
75 
TestEncode()76   void TestEncode() {
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   int frame_packets_;
85   bool set_cpu_used_ = true;
86 };
87 
TEST_P(RealtimeTest,RealtimeFirstPassProducesFrames)88 TEST_P(RealtimeTest, RealtimeFirstPassProducesFrames) { TestEncode(); }
89 
TEST_P(RealtimeTest,RealtimeDefaultCpuUsed)90 TEST_P(RealtimeTest, RealtimeDefaultCpuUsed) {
91   set_cpu_used_ = false;
92   TestEncode();
93 }
94 
TEST_P(RealtimeTest,IntegerOverflow)95 TEST_P(RealtimeTest, IntegerOverflow) { TestIntegerOverflow(2048, 2048); }
96 
TEST_P(RealtimeTest,IntegerOverflowLarge)97 TEST_P(RealtimeTest, IntegerOverflowLarge) {
98 #ifdef CHROMIUM
99   GTEST_SKIP() << "16K framebuffers are not supported by Chromium's allocator.";
100 #else
101   if (IsVP9()) {
102 #if VPX_ARCH_AARCH64 || VPX_ARCH_X86_64
103     TestIntegerOverflow(16384, 16384);
104 #else
105     TestIntegerOverflow(4096, 4096);
106 #endif
107   } else {
108     GTEST_SKIP()
109         << "TODO(https://crbug.com/webm/1748,https://crbug.com/webm/1751):"
110         << " Enable this test after bitstream errors & undefined sanitizer "
111            "warnings are fixed.";
112     // TestIntegerOverflow(16383, 16383);
113   }
114 #endif  // defined(CHROMIUM)
115 }
116 
117 VP8_INSTANTIATE_TEST_SUITE(RealtimeTest,
118                            ::testing::Values(::libvpx_test::kRealTime));
119 VP9_INSTANTIATE_TEST_SUITE(RealtimeTest,
120                            ::testing::Values(::libvpx_test::kRealTime));
121 
122 }  // namespace
123