2 * Copyright (c) 2014 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.
10 #include "third_party/googletest/src/include/gtest/gtest.h"
11 #include "./vpx_config.h"
12 #include "./vpx_version.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 #include "test/y4m_video_source.h"
18 #include "vpx_ports/vpx_timer.h"
22 const int kMaxPsnr = 100;
23 const double kUsecsInSec = 1000000.0;
25 struct EncodePerfTestVideo {
26 EncodePerfTestVideo(const char *name_, uint32_t width_, uint32_t height_,
27 uint32_t bitrate_, int frames_)
40 const EncodePerfTestVideo kVP9EncodePerfTestVectors[] = {
41 EncodePerfTestVideo("desktop_640_360_30.yuv", 640, 360, 200, 2484),
42 EncodePerfTestVideo("kirland_640_480_30.yuv", 640, 480, 200, 300),
43 EncodePerfTestVideo("macmarcomoving_640_480_30.yuv", 640, 480, 200, 987),
44 EncodePerfTestVideo("macmarcostationary_640_480_30.yuv", 640, 480, 200, 718),
45 EncodePerfTestVideo("niklas_640_480_30.yuv", 640, 480, 200, 471),
46 EncodePerfTestVideo("tacomanarrows_640_480_30.yuv", 640, 480, 200, 300),
47 EncodePerfTestVideo("tacomasmallcameramovement_640_480_30.yuv",
49 EncodePerfTestVideo("thaloundeskmtg_640_480_30.yuv", 640, 480, 200, 300),
50 EncodePerfTestVideo("niklas_1280_720_30.yuv", 1280, 720, 600, 470),
53 const int kEncodePerfTestSpeeds[] = { 5, 6, 7, 12 };
55 #define NELEMENTS(x) (sizeof((x)) / sizeof((x)[0]))
57 class VP9EncodePerfTest
58 : public ::libvpx_test::EncoderTest,
59 public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
62 : EncoderTest(GET_PARAM(0)),
65 encoding_mode_(GET_PARAM(1)),
68 virtual ~VP9EncodePerfTest() {}
70 virtual void SetUp() {
72 SetMode(encoding_mode_);
74 cfg_.g_lag_in_frames = 0;
75 cfg_.rc_min_quantizer = 2;
76 cfg_.rc_max_quantizer = 56;
77 cfg_.rc_dropframe_thresh = 0;
78 cfg_.rc_undershoot_pct = 50;
79 cfg_.rc_overshoot_pct = 50;
80 cfg_.rc_buf_sz = 1000;
81 cfg_.rc_buf_initial_sz = 500;
82 cfg_.rc_buf_optimal_sz = 600;
83 cfg_.rc_resize_allowed = 0;
84 cfg_.rc_end_usage = VPX_CBR;
87 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
88 ::libvpx_test::Encoder *encoder) {
89 if (video->frame() == 1) {
90 encoder->Control(VP8E_SET_CPUUSED, speed_);
94 virtual void BeginPassHook(unsigned int /*pass*/) {
99 virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
100 if (pkt->data.psnr.psnr[0] < min_psnr_) {
101 min_psnr_= pkt->data.psnr.psnr[0];
105 // for performance reasons don't decode
106 virtual bool DoDecode() { return 0; }
108 double min_psnr() const {
112 void set_speed(unsigned int speed) {
118 unsigned int nframes_;
119 libvpx_test::TestMode encoding_mode_;
123 TEST_P(VP9EncodePerfTest, PerfTest) {
124 for (size_t i = 0; i < NELEMENTS(kVP9EncodePerfTestVectors); ++i) {
125 for (size_t j = 0; j < NELEMENTS(kEncodePerfTestSpeeds); ++j) {
128 const vpx_rational timebase = { 33333333, 1000000000 };
129 cfg_.g_timebase = timebase;
130 cfg_.rc_target_bitrate = kVP9EncodePerfTestVectors[i].bitrate;
132 init_flags_ = VPX_CODEC_USE_PSNR;
134 const unsigned frames = kVP9EncodePerfTestVectors[i].frames;
135 const char *video_name = kVP9EncodePerfTestVectors[i].name;
136 libvpx_test::I420VideoSource video(
138 kVP9EncodePerfTestVectors[i].width,
139 kVP9EncodePerfTestVectors[i].height,
140 timebase.den, timebase.num, 0,
141 kVP9EncodePerfTestVectors[i].frames);
142 set_speed(kEncodePerfTestSpeeds[j]);
145 vpx_usec_timer_start(&t);
147 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
149 vpx_usec_timer_mark(&t);
150 const double elapsed_secs = vpx_usec_timer_elapsed(&t) / kUsecsInSec;
151 const double fps = frames / elapsed_secs;
152 const double minimum_psnr = min_psnr();
155 printf("\t\"type\" : \"encode_perf_test\",\n");
156 printf("\t\"version\" : \"%s\",\n", VERSION_STRING_NOSP);
157 printf("\t\"videoName\" : \"%s\",\n", video_name);
158 printf("\t\"encodeTimeSecs\" : %f,\n", elapsed_secs);
159 printf("\t\"totalFrames\" : %u,\n", frames);
160 printf("\t\"framesPerSecond\" : %f,\n", fps);
161 printf("\t\"minPsnr\" : %f,\n", minimum_psnr);
162 printf("\t\"speed\" : %d\n", kEncodePerfTestSpeeds[j]);
168 VP9_INSTANTIATE_TEST_CASE(
169 VP9EncodePerfTest, ::testing::Values(::libvpx_test::kRealTime));