1 /*
2 * Copyright (c) 2012 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 <climits>
11 #include <vector>
12 #include "third_party/googletest/src/include/gtest/gtest.h"
13 #include "test/codec_factory.h"
14 #include "test/encode_test_driver.h"
15 #include "test/i420_video_source.h"
16 #include "test/util.h"
17
18 namespace {
19
20 class CpuSpeedTest : public ::libvpx_test::EncoderTest,
21 public ::libvpx_test::CodecTestWith2Params<
22 libvpx_test::TestMode, int> {
23 protected:
CpuSpeedTest()24 CpuSpeedTest() : EncoderTest(GET_PARAM(0)) {}
~CpuSpeedTest()25 virtual ~CpuSpeedTest() {}
26
SetUp()27 virtual void SetUp() {
28 InitializeConfig();
29 SetMode(GET_PARAM(1));
30 set_cpu_used_ = GET_PARAM(2);
31 }
32
PreEncodeFrameHook(::libvpx_test::VideoSource * video,::libvpx_test::Encoder * encoder)33 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
34 ::libvpx_test::Encoder *encoder) {
35 if (video->frame() == 1) {
36 encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_);
37 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
38 encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
39 encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
40 encoder->Control(VP8E_SET_ARNR_TYPE, 3);
41 }
42 }
43
FramePktHook(const vpx_codec_cx_pkt_t * pkt)44 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
45 if (pkt->data.frame.flags & VPX_FRAME_IS_KEY) {
46 }
47 }
48 int set_cpu_used_;
49 };
50
TEST_P(CpuSpeedTest,TestQ0)51 TEST_P(CpuSpeedTest, TestQ0) {
52 // Validate that this non multiple of 64 wide clip encodes and decodes
53 // without a mismatch when passing in a very low max q. This pushes
54 // the encoder to producing lots of big partitions which will likely
55 // extend into the border and test the border condition.
56 cfg_.g_lag_in_frames = 25;
57 cfg_.rc_2pass_vbr_minsection_pct = 5;
58 cfg_.rc_2pass_vbr_minsection_pct = 2000;
59 cfg_.rc_target_bitrate = 400;
60 cfg_.rc_max_quantizer = 0;
61 cfg_.rc_min_quantizer = 0;
62
63 ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
64 20);
65
66 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
67 }
68
69
TEST_P(CpuSpeedTest,TestEncodeHighBitrate)70 TEST_P(CpuSpeedTest, TestEncodeHighBitrate) {
71 // Validate that this non multiple of 64 wide clip encodes and decodes
72 // without a mismatch when passing in a very low max q. This pushes
73 // the encoder to producing lots of big partitions which will likely
74 // extend into the border and test the border condition.
75 cfg_.g_lag_in_frames = 25;
76 cfg_.rc_2pass_vbr_minsection_pct = 5;
77 cfg_.rc_2pass_vbr_minsection_pct = 2000;
78 cfg_.rc_target_bitrate = 12000;
79 cfg_.rc_max_quantizer = 10;
80 cfg_.rc_min_quantizer = 0;
81
82 ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
83 20);
84
85 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
86 }
TEST_P(CpuSpeedTest,TestLowBitrate)87 TEST_P(CpuSpeedTest, TestLowBitrate) {
88 // Validate that this clip encodes and decodes without a mismatch
89 // when passing in a very high min q. This pushes the encoder to producing
90 // lots of small partitions which might will test the other condition.
91
92 cfg_.g_lag_in_frames = 25;
93 cfg_.rc_2pass_vbr_minsection_pct = 5;
94 cfg_.rc_2pass_vbr_minsection_pct = 2000;
95 cfg_.rc_target_bitrate = 200;
96 cfg_.rc_min_quantizer = 40;
97
98 ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
99 20);
100
101 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
102 }
103
104 using std::tr1::make_tuple;
105
106 #define VP9_FACTORY \
107 static_cast<const libvpx_test::CodecFactory*> (&libvpx_test::kVP9)
108
109 VP9_INSTANTIATE_TEST_CASE(
110 CpuSpeedTest,
111 ::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood),
112 ::testing::Range(0, 8));
113 } // namespace
114