vp9_cx_iface: set default cpu_used=5 w/CONFIG_REALTIME_ONLY
[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 #if !CONFIG_REALTIME_ONLY
39     // TODO(tomfinegan): We're changing the pass value here to make sure
40     // we get frames when real time mode is combined with |g_pass| set to
41     // VPX_RC_FIRST_PASS. This is necessary because EncoderTest::RunLoop() sets
42     // the pass value based on the mode passed into EncoderTest::SetMode(),
43     // which overrides the one specified in SetUp() above.
44     cfg_.g_pass = VPX_RC_FIRST_PASS;
45 #endif
46   }
47
48   void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
49                           ::libvpx_test::Encoder *encoder) override {
50     if (video->frame() == 0 && set_cpu_used_) {
51       encoder->Control(VP8E_SET_CPUUSED, 8);
52     }
53   }
54
55   void FramePktHook(const vpx_codec_cx_pkt_t * /*pkt*/) override {
56     frame_packets_++;
57   }
58
59   bool IsVP9() const {
60 #if CONFIG_VP9_ENCODER
61     return codec_ == &libvpx_test::kVP9;
62 #else
63     return false;
64 #endif
65   }
66
67   void TestIntegerOverflow(unsigned int width, unsigned int height) {
68     ::libvpx_test::RandomVideoSource video;
69     video.SetSize(width, height);
70     video.set_limit(20);
71     cfg_.rc_target_bitrate = UINT_MAX;
72     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
73   }
74
75   void TestEncode() {
76     ::libvpx_test::RandomVideoSource video;
77     video.SetSize(kVideoSourceWidth, kVideoSourceHeight);
78     video.set_limit(kFramesToEncode);
79     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
80     EXPECT_EQ(kFramesToEncode, frame_packets_);
81   }
82
83   int frame_packets_;
84   bool set_cpu_used_ = true;
85 };
86
87 TEST_P(RealtimeTest, RealtimeFirstPassProducesFrames) { TestEncode(); }
88
89 TEST_P(RealtimeTest, RealtimeDefaultCpuUsed) {
90   set_cpu_used_ = false;
91   TestEncode();
92 }
93
94 TEST_P(RealtimeTest, IntegerOverflow) { TestIntegerOverflow(2048, 2048); }
95
96 TEST_P(RealtimeTest, IntegerOverflowLarge) {
97   if (IsVP9()) {
98 #if VPX_ARCH_X86_64
99     TestIntegerOverflow(16384, 16384);
100 #else
101     TestIntegerOverflow(4096, 4096);
102 #endif
103   } else {
104     GTEST_SKIP()
105         << "TODO(https://crbug.com/webm/1748,https://crbug.com/webm/1751):"
106         << " Enable this test after bitstream errors & undefined sanitizer "
107            "warnings are fixed.";
108     // TestIntegerOverflow(16383, 16383);
109   }
110 }
111
112 VP8_INSTANTIATE_TEST_SUITE(RealtimeTest,
113                            ::testing::Values(::libvpx_test::kRealTime));
114 VP9_INSTANTIATE_TEST_SUITE(RealtimeTest,
115                            ::testing::Values(::libvpx_test::kRealTime));
116
117 }  // namespace