blob: e2a4f2b71cc47f96120572e52e8852f08299dfa2 [file] [log] [blame]
Joshua Litt83b843f2014-07-21 10:57:16 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Joshua Litt83b843f2014-07-21 10:57:16 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*/
11
Frank Galligand80d9442014-12-19 11:21:52 -080012#include <string>
Tom Finegan7a07ece2017-02-07 17:14:05 -080013#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070014#include "./aom_config.h"
15#include "./aom_version.h"
Joshua Litt83b843f2014-07-21 10:57:16 -070016#include "test/codec_factory.h"
17#include "test/encode_test_driver.h"
18#include "test/i420_video_source.h"
19#include "test/util.h"
20#include "test/y4m_video_source.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070021#include "aom_ports/aom_timer.h"
Joshua Litt83b843f2014-07-21 10:57:16 -070022
23namespace {
24
25const int kMaxPsnr = 100;
26const double kUsecsInSec = 1000000.0;
27
28struct EncodePerfTestVideo {
29 EncodePerfTestVideo(const char *name_, uint32_t width_, uint32_t height_,
30 uint32_t bitrate_, int frames_)
clang-format3a826f12016-08-11 17:46:05 -070031 : name(name_), width(width_), height(height_), bitrate(bitrate_),
Joshua Litt83b843f2014-07-21 10:57:16 -070032 frames(frames_) {}
33 const char *name;
34 uint32_t width;
35 uint32_t height;
36 uint32_t bitrate;
37 int frames;
38};
39
Yaowu Xuf883b422016-08-30 14:01:10 -070040const EncodePerfTestVideo kAV1EncodePerfTestVectors[] = {
Joshua Litt83b843f2014-07-21 10:57:16 -070041 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),
clang-format3a826f12016-08-11 17:46:05 -070047 EncodePerfTestVideo("tacomasmallcameramovement_640_480_30.yuv", 640, 480, 200,
48 300),
Joshua Litt83b843f2014-07-21 10:57:16 -070049 EncodePerfTestVideo("thaloundeskmtg_640_480_30.yuv", 640, 480, 200, 300),
50 EncodePerfTestVideo("niklas_1280_720_30.yuv", 1280, 720, 600, 470),
51};
52
Frank Galligan0f3d3882014-12-18 15:19:21 -080053const int kEncodePerfTestSpeeds[] = { 5, 6, 7, 8 };
Frank Galligand80d9442014-12-19 11:21:52 -080054const int kEncodePerfTestThreads[] = { 1, 2, 4 };
Joshua Litt83b843f2014-07-21 10:57:16 -070055
56#define NELEMENTS(x) (sizeof((x)) / sizeof((x)[0]))
57
Yaowu Xuf883b422016-08-30 14:01:10 -070058class AV1EncodePerfTest
Yaowu Xuc27fc142016-08-22 16:08:15 -070059 : public ::libaom_test::EncoderTest,
60 public ::libaom_test::CodecTestWithParam<libaom_test::TestMode> {
Joshua Litt83b843f2014-07-21 10:57:16 -070061 protected:
Yaowu Xuf883b422016-08-30 14:01:10 -070062 AV1EncodePerfTest()
clang-format3a826f12016-08-11 17:46:05 -070063 : EncoderTest(GET_PARAM(0)), min_psnr_(kMaxPsnr), nframes_(0),
64 encoding_mode_(GET_PARAM(1)), speed_(0), threads_(1) {}
Joshua Litt83b843f2014-07-21 10:57:16 -070065
Yaowu Xuf883b422016-08-30 14:01:10 -070066 virtual ~AV1EncodePerfTest() {}
Joshua Litt83b843f2014-07-21 10:57:16 -070067
68 virtual void SetUp() {
69 InitializeConfig();
70 SetMode(encoding_mode_);
71
72 cfg_.g_lag_in_frames = 0;
73 cfg_.rc_min_quantizer = 2;
74 cfg_.rc_max_quantizer = 56;
75 cfg_.rc_dropframe_thresh = 0;
76 cfg_.rc_undershoot_pct = 50;
77 cfg_.rc_overshoot_pct = 50;
78 cfg_.rc_buf_sz = 1000;
79 cfg_.rc_buf_initial_sz = 500;
80 cfg_.rc_buf_optimal_sz = 600;
81 cfg_.rc_resize_allowed = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -070082 cfg_.rc_end_usage = AOM_CBR;
Frank Galligand80d9442014-12-19 11:21:52 -080083 cfg_.g_error_resilient = 1;
84 cfg_.g_threads = threads_;
Joshua Litt83b843f2014-07-21 10:57:16 -070085 }
86
Yaowu Xuc27fc142016-08-22 16:08:15 -070087 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
88 ::libaom_test::Encoder *encoder) {
Frank Galligand80d9442014-12-19 11:21:52 -080089 if (video->frame() == 0) {
90 const int log2_tile_columns = 3;
Yaowu Xuf883b422016-08-30 14:01:10 -070091 encoder->Control(AOME_SET_CPUUSED, speed_);
92 encoder->Control(AV1E_SET_TILE_COLUMNS, log2_tile_columns);
93 encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
94 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0);
Joshua Litt83b843f2014-07-21 10:57:16 -070095 }
96 }
97
98 virtual void BeginPassHook(unsigned int /*pass*/) {
99 min_psnr_ = kMaxPsnr;
100 nframes_ = 0;
101 }
102
Yaowu Xuf883b422016-08-30 14:01:10 -0700103 virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) {
Joshua Litt83b843f2014-07-21 10:57:16 -0700104 if (pkt->data.psnr.psnr[0] < min_psnr_) {
clang-format3a826f12016-08-11 17:46:05 -0700105 min_psnr_ = pkt->data.psnr.psnr[0];
Joshua Litt83b843f2014-07-21 10:57:16 -0700106 }
107 }
108
109 // for performance reasons don't decode
110 virtual bool DoDecode() { return 0; }
111
clang-format3a826f12016-08-11 17:46:05 -0700112 double min_psnr() const { return min_psnr_; }
Joshua Litt83b843f2014-07-21 10:57:16 -0700113
clang-format3a826f12016-08-11 17:46:05 -0700114 void set_speed(unsigned int speed) { speed_ = speed; }
Joshua Litt83b843f2014-07-21 10:57:16 -0700115
clang-format3a826f12016-08-11 17:46:05 -0700116 void set_threads(unsigned int threads) { threads_ = threads; }
Frank Galligand80d9442014-12-19 11:21:52 -0800117
Joshua Litt83b843f2014-07-21 10:57:16 -0700118 private:
119 double min_psnr_;
120 unsigned int nframes_;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700121 libaom_test::TestMode encoding_mode_;
Joshua Litt83b843f2014-07-21 10:57:16 -0700122 unsigned speed_;
Frank Galligand80d9442014-12-19 11:21:52 -0800123 unsigned int threads_;
Joshua Litt83b843f2014-07-21 10:57:16 -0700124};
125
Yaowu Xuf883b422016-08-30 14:01:10 -0700126TEST_P(AV1EncodePerfTest, PerfTest) {
127 for (size_t i = 0; i < NELEMENTS(kAV1EncodePerfTestVectors); ++i) {
Joshua Litt83b843f2014-07-21 10:57:16 -0700128 for (size_t j = 0; j < NELEMENTS(kEncodePerfTestSpeeds); ++j) {
Frank Galligand80d9442014-12-19 11:21:52 -0800129 for (size_t k = 0; k < NELEMENTS(kEncodePerfTestThreads); ++k) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700130 if (kAV1EncodePerfTestVectors[i].width < 512 &&
Frank Galligand80d9442014-12-19 11:21:52 -0800131 kEncodePerfTestThreads[k] > 1)
132 continue;
Yaowu Xuf883b422016-08-30 14:01:10 -0700133 else if (kAV1EncodePerfTestVectors[i].width < 1024 &&
Frank Galligand80d9442014-12-19 11:21:52 -0800134 kEncodePerfTestThreads[k] > 2)
135 continue;
Joshua Litt83b843f2014-07-21 10:57:16 -0700136
Frank Galligand80d9442014-12-19 11:21:52 -0800137 set_threads(kEncodePerfTestThreads[k]);
138 SetUp();
Joshua Litt83b843f2014-07-21 10:57:16 -0700139
Yaowu Xuf883b422016-08-30 14:01:10 -0700140 const aom_rational timebase = { 33333333, 1000000000 };
Frank Galligand80d9442014-12-19 11:21:52 -0800141 cfg_.g_timebase = timebase;
Yaowu Xuf883b422016-08-30 14:01:10 -0700142 cfg_.rc_target_bitrate = kAV1EncodePerfTestVectors[i].bitrate;
Joshua Litt83b843f2014-07-21 10:57:16 -0700143
Yaowu Xuf883b422016-08-30 14:01:10 -0700144 init_flags_ = AOM_CODEC_USE_PSNR;
Joshua Litt83b843f2014-07-21 10:57:16 -0700145
Yaowu Xuf883b422016-08-30 14:01:10 -0700146 const unsigned frames = kAV1EncodePerfTestVectors[i].frames;
147 const char *video_name = kAV1EncodePerfTestVectors[i].name;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700148 libaom_test::I420VideoSource video(
Yaowu Xuf883b422016-08-30 14:01:10 -0700149 video_name, kAV1EncodePerfTestVectors[i].width,
150 kAV1EncodePerfTestVectors[i].height, timebase.den, timebase.num, 0,
151 kAV1EncodePerfTestVectors[i].frames);
Frank Galligand80d9442014-12-19 11:21:52 -0800152 set_speed(kEncodePerfTestSpeeds[j]);
Joshua Litt83b843f2014-07-21 10:57:16 -0700153
Yaowu Xuf883b422016-08-30 14:01:10 -0700154 aom_usec_timer t;
155 aom_usec_timer_start(&t);
Joshua Litt83b843f2014-07-21 10:57:16 -0700156
Frank Galligand80d9442014-12-19 11:21:52 -0800157 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
Joshua Litt83b843f2014-07-21 10:57:16 -0700158
Yaowu Xuf883b422016-08-30 14:01:10 -0700159 aom_usec_timer_mark(&t);
160 const double elapsed_secs = aom_usec_timer_elapsed(&t) / kUsecsInSec;
Frank Galligand80d9442014-12-19 11:21:52 -0800161 const double fps = frames / elapsed_secs;
162 const double minimum_psnr = min_psnr();
163 std::string display_name(video_name);
164 if (kEncodePerfTestThreads[k] > 1) {
165 char thread_count[32];
166 snprintf(thread_count, sizeof(thread_count), "_t-%d",
167 kEncodePerfTestThreads[k]);
168 display_name += thread_count;
169 }
170
171 printf("{\n");
172 printf("\t\"type\" : \"encode_perf_test\",\n");
173 printf("\t\"version\" : \"%s\",\n", VERSION_STRING_NOSP);
174 printf("\t\"videoName\" : \"%s\",\n", display_name.c_str());
175 printf("\t\"encodeTimeSecs\" : %f,\n", elapsed_secs);
176 printf("\t\"totalFrames\" : %u,\n", frames);
177 printf("\t\"framesPerSecond\" : %f,\n", fps);
178 printf("\t\"minPsnr\" : %f,\n", minimum_psnr);
Frank Galligan238c4fa2015-01-06 11:06:33 -0800179 printf("\t\"speed\" : %d,\n", kEncodePerfTestSpeeds[j]);
Frank Galligand80d9442014-12-19 11:21:52 -0800180 printf("\t\"threads\" : %d\n", kEncodePerfTestThreads[k]);
181 printf("}\n");
182 }
Joshua Litt83b843f2014-07-21 10:57:16 -0700183 }
184 }
185}
186
Yaowu Xuf883b422016-08-30 14:01:10 -0700187AV1_INSTANTIATE_TEST_CASE(AV1EncodePerfTest,
188 ::testing::Values(::libaom_test::kRealTime));
Joshua Litt83b843f2014-07-21 10:57:16 -0700189} // namespace