2 * Copyright (c) 2016 The WebM project authors. All Rights Reserved.
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.
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"
20 const int kVideoSourceWidth = 320;
21 const int kVideoSourceHeight = 240;
22 const int kFramesToEncode = 2;
25 : public ::libvpx_test::EncoderTest,
26 public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
28 RealtimeTest() : EncoderTest(GET_PARAM(0)), frame_packets_(0) {}
29 ~RealtimeTest() override {}
31 void SetUp() override {
33 cfg_.g_lag_in_frames = 0;
34 SetMode(::libvpx_test::kRealTime);
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;
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);
53 void FramePktHook(const vpx_codec_cx_pkt_t * /*pkt*/) override {
58 #if CONFIG_VP9_ENCODER
59 return codec_ == &libvpx_test::kVP9;
65 void TestIntegerOverflow(unsigned int width, unsigned int height) {
66 ::libvpx_test::RandomVideoSource video;
67 video.SetSize(width, height);
69 cfg_.rc_target_bitrate = UINT_MAX;
70 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
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_);
84 TEST_P(RealtimeTest, IntegerOverflow) { TestIntegerOverflow(2048, 2048); }
86 TEST_P(RealtimeTest, IntegerOverflowLarge) {
89 TestIntegerOverflow(16384, 16384);
91 TestIntegerOverflow(4096, 4096);
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);
102 VP8_INSTANTIATE_TEST_SUITE(RealtimeTest,
103 ::testing::Values(::libvpx_test::kRealTime));
104 VP9_INSTANTIATE_TEST_SUITE(RealtimeTest,
105 ::testing::Values(::libvpx_test::kRealTime));