blob: a24d02a6c3509b4bbd6bc86d84c319bc8f5abeee [file] [log] [blame]
Joshua Litta782d632013-11-15 12:29:26 -08001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Joshua Litta782d632013-11-15 12:29:26 -08003 *
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*/
Joshua Litta782d632013-11-15 12:29:26 -080011
Jim Bankoskic2638bd2014-12-09 12:44:45 -080012#include <string>
Joshua Litta782d632013-11-15 12:29:26 -080013#include "test/codec_factory.h"
14#include "test/decode_test_driver.h"
Jim Bankoskic2638bd2014-12-09 12:44:45 -080015#include "test/encode_test_driver.h"
16#include "test/i420_video_source.h"
Joshua Litta782d632013-11-15 12:29:26 -080017#include "test/ivf_video_source.h"
18#include "test/md5_helper.h"
19#include "test/util.h"
20#include "test/webm_video_source.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070021#include "aom_ports/aom_timer.h"
Jim Bankoskic2638bd2014-12-09 12:44:45 -080022#include "./ivfenc.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070023#include "./aom_version.h"
Joshua Litta782d632013-11-15 12:29:26 -080024
25using std::tr1::make_tuple;
26
27namespace {
28
29#define VIDEO_NAME 0
30#define THREADS 1
31
Jim Bankoskic2638bd2014-12-09 12:44:45 -080032const int kMaxPsnr = 100;
Joshua Litta782d632013-11-15 12:29:26 -080033const double kUsecsInSec = 1000000.0;
Jim Bankoski4276eac2014-12-19 15:53:59 -080034const char kNewEncodeOutputFile[] = "new_encode.ivf";
Joshua Litta782d632013-11-15 12:29:26 -080035
36/*
37 DecodePerfTest takes a tuple of filename + number of threads to decode with
38 */
James Zernc3314b72014-07-16 18:55:08 -070039typedef std::tr1::tuple<const char *, unsigned> DecodePerfParam;
Joshua Litta782d632013-11-15 12:29:26 -080040
Jim Bankoski4362b3e2016-11-22 07:50:05 -080041// TODO(jimbankoski): Add actual test vectors here when available.
42// const DecodePerfParam kAV1DecodePerfVectors[] = {};
Joshua Litta782d632013-11-15 12:29:26 -080043
44/*
45 In order to reflect real world performance as much as possible, Perf tests
46 *DO NOT* do any correctness checks. Please run them alongside correctness
47 tests to ensure proper codec integrity. Furthermore, in this test we
48 deliberately limit the amount of system calls we make to avoid OS
49 preemption.
50
51 TODO(joshualitt) create a more detailed perf measurement test to collect
52 power/temp/min max frame decode times/etc
53 */
54
clang-format3a826f12016-08-11 17:46:05 -070055class DecodePerfTest : public ::testing::TestWithParam<DecodePerfParam> {};
Joshua Litta782d632013-11-15 12:29:26 -080056
57TEST_P(DecodePerfTest, PerfTest) {
58 const char *const video_name = GET_PARAM(VIDEO_NAME);
59 const unsigned threads = GET_PARAM(THREADS);
60
Yaowu Xuc27fc142016-08-22 16:08:15 -070061 libaom_test::WebMVideoSource video(video_name);
Joshua Litta782d632013-11-15 12:29:26 -080062 video.Init();
63
Yaowu Xuf883b422016-08-30 14:01:10 -070064 aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
Joshua Litta782d632013-11-15 12:29:26 -080065 cfg.threads = threads;
Sebastien Alaiwan8a65f9f2017-06-23 07:28:44 +020066 cfg.allow_lowbitdepth = 1;
Yaowu Xuf883b422016-08-30 14:01:10 -070067 libaom_test::AV1Decoder decoder(cfg, 0);
Joshua Litta782d632013-11-15 12:29:26 -080068
Yaowu Xuf883b422016-08-30 14:01:10 -070069 aom_usec_timer t;
70 aom_usec_timer_start(&t);
Joshua Litta782d632013-11-15 12:29:26 -080071
72 for (video.Begin(); video.cxdata() != NULL; video.Next()) {
73 decoder.DecodeFrame(video.cxdata(), video.frame_size());
74 }
75
Yaowu Xuf883b422016-08-30 14:01:10 -070076 aom_usec_timer_mark(&t);
77 const double elapsed_secs = double(aom_usec_timer_elapsed(&t)) / kUsecsInSec;
Joshua Litta782d632013-11-15 12:29:26 -080078 const unsigned frames = video.frame_number();
79 const double fps = double(frames) / elapsed_secs;
80
81 printf("{\n");
Joshua Litt83b843f2014-07-21 10:57:16 -070082 printf("\t\"type\" : \"decode_perf_test\",\n");
Joshua Litta782d632013-11-15 12:29:26 -080083 printf("\t\"version\" : \"%s\",\n", VERSION_STRING_NOSP);
84 printf("\t\"videoName\" : \"%s\",\n", video_name);
85 printf("\t\"threadCount\" : %u,\n", threads);
86 printf("\t\"decodeTimeSecs\" : %f,\n", elapsed_secs);
87 printf("\t\"totalFrames\" : %u,\n", frames);
88 printf("\t\"framesPerSecond\" : %f\n", fps);
89 printf("}\n");
90}
91
Jim Bankoski4362b3e2016-11-22 07:50:05 -080092// TODO(jimbankoski): Enabled when we have actual AV1 Decode vectors.
93// INSTANTIATE_TEST_CASE_P(AV1, DecodePerfTest,
94// ::testing::ValuesIn(kAV1DecodePerfVectors));
Joshua Litta782d632013-11-15 12:29:26 -080095
Yaowu Xuf883b422016-08-30 14:01:10 -070096class AV1NewEncodeDecodePerfTest
Sebastien Alaiwan4322bc12017-06-05 10:18:28 +020097 : public ::libaom_test::CodecTestWithParam<libaom_test::TestMode>,
98 public ::libaom_test::EncoderTest {
Jim Bankoskic2638bd2014-12-09 12:44:45 -080099 protected:
Yaowu Xuf883b422016-08-30 14:01:10 -0700100 AV1NewEncodeDecodePerfTest()
clang-format3a826f12016-08-11 17:46:05 -0700101 : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)), speed_(0),
102 outfile_(0), out_frames_(0) {}
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800103
Yaowu Xuf883b422016-08-30 14:01:10 -0700104 virtual ~AV1NewEncodeDecodePerfTest() {}
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800105
106 virtual void SetUp() {
107 InitializeConfig();
108 SetMode(encoding_mode_);
109
110 cfg_.g_lag_in_frames = 25;
111 cfg_.rc_min_quantizer = 2;
112 cfg_.rc_max_quantizer = 56;
113 cfg_.rc_dropframe_thresh = 0;
114 cfg_.rc_undershoot_pct = 50;
115 cfg_.rc_overshoot_pct = 50;
116 cfg_.rc_buf_sz = 1000;
117 cfg_.rc_buf_initial_sz = 500;
118 cfg_.rc_buf_optimal_sz = 600;
Yaowu Xuf883b422016-08-30 14:01:10 -0700119 cfg_.rc_end_usage = AOM_VBR;
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800120 }
121
Yaowu Xuc27fc142016-08-22 16:08:15 -0700122 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
123 ::libaom_test::Encoder *encoder) {
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800124 if (video->frame() == 1) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700125 encoder->Control(AOME_SET_CPUUSED, speed_);
126 encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
127 encoder->Control(AV1E_SET_TILE_COLUMNS, 2);
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800128 }
129 }
130
131 virtual void BeginPassHook(unsigned int /*pass*/) {
Yaowu Xu97aa09f2016-10-12 08:25:39 -0700132 const std::string data_path = getenv("LIBAOM_TEST_DATA_PATH");
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800133 const std::string path_to_source = data_path + "/" + kNewEncodeOutputFile;
134 outfile_ = fopen(path_to_source.c_str(), "wb");
Jim Bankoski4276eac2014-12-19 15:53:59 -0800135 ASSERT_TRUE(outfile_ != NULL);
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800136 }
137
138 virtual void EndPassHook() {
Jim Bankoski4276eac2014-12-19 15:53:59 -0800139 if (outfile_ != NULL) {
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800140 if (!fseek(outfile_, 0, SEEK_SET))
Yaowu Xuf883b422016-08-30 14:01:10 -0700141 ivf_write_file_header(outfile_, &cfg_, AV1_FOURCC, out_frames_);
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800142 fclose(outfile_);
143 outfile_ = NULL;
144 }
145 }
146
Yaowu Xuf883b422016-08-30 14:01:10 -0700147 virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800148 ++out_frames_;
149
150 // Write initial file header if first frame.
151 if (pkt->data.frame.pts == 0)
Yaowu Xuf883b422016-08-30 14:01:10 -0700152 ivf_write_file_header(outfile_, &cfg_, AV1_FOURCC, out_frames_);
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800153
154 // Write frame header and data.
155 ivf_write_frame_header(outfile_, out_frames_, pkt->data.frame.sz);
Jim Bankoski86192742014-12-23 08:35:26 -0800156 ASSERT_EQ(fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, outfile_),
157 pkt->data.frame.sz);
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800158 }
159
Jim Bankoski4276eac2014-12-19 15:53:59 -0800160 virtual bool DoDecode() { return false; }
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800161
clang-format3a826f12016-08-11 17:46:05 -0700162 void set_speed(unsigned int speed) { speed_ = speed; }
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800163
164 private:
Yaowu Xuc27fc142016-08-22 16:08:15 -0700165 libaom_test::TestMode encoding_mode_;
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800166 uint32_t speed_;
167 FILE *outfile_;
168 uint32_t out_frames_;
169};
170
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800171struct EncodePerfTestVideo {
172 EncodePerfTestVideo(const char *name_, uint32_t width_, uint32_t height_,
173 uint32_t bitrate_, int frames_)
clang-format3a826f12016-08-11 17:46:05 -0700174 : name(name_), width(width_), height(height_), bitrate(bitrate_),
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800175 frames(frames_) {}
176 const char *name;
177 uint32_t width;
178 uint32_t height;
179 uint32_t bitrate;
180 int frames;
181};
182
Yaowu Xuf883b422016-08-30 14:01:10 -0700183const EncodePerfTestVideo kAV1EncodePerfTestVectors[] = {
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800184 EncodePerfTestVideo("niklas_1280_720_30.yuv", 1280, 720, 600, 470),
185};
186
Yaowu Xuf883b422016-08-30 14:01:10 -0700187TEST_P(AV1NewEncodeDecodePerfTest, PerfTest) {
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800188 SetUp();
189
190 // TODO(JBB): Make this work by going through the set of given files.
191 const int i = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -0700192 const aom_rational timebase = { 33333333, 1000000000 };
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800193 cfg_.g_timebase = timebase;
Yaowu Xuf883b422016-08-30 14:01:10 -0700194 cfg_.rc_target_bitrate = kAV1EncodePerfTestVectors[i].bitrate;
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800195
Yaowu Xuf883b422016-08-30 14:01:10 -0700196 init_flags_ = AOM_CODEC_USE_PSNR;
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800197
Yaowu Xuf883b422016-08-30 14:01:10 -0700198 const char *video_name = kAV1EncodePerfTestVectors[i].name;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700199 libaom_test::I420VideoSource video(
Yaowu Xuf883b422016-08-30 14:01:10 -0700200 video_name, kAV1EncodePerfTestVectors[i].width,
201 kAV1EncodePerfTestVectors[i].height, timebase.den, timebase.num, 0,
202 kAV1EncodePerfTestVectors[i].frames);
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800203 set_speed(2);
204
205 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
206
207 const uint32_t threads = 4;
208
Yaowu Xuc27fc142016-08-22 16:08:15 -0700209 libaom_test::IVFVideoSource decode_video(kNewEncodeOutputFile);
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800210 decode_video.Init();
211
Yaowu Xuf883b422016-08-30 14:01:10 -0700212 aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800213 cfg.threads = threads;
Sebastien Alaiwan8a65f9f2017-06-23 07:28:44 +0200214 cfg.allow_lowbitdepth = 1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700215 libaom_test::AV1Decoder decoder(cfg, 0);
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800216
Yaowu Xuf883b422016-08-30 14:01:10 -0700217 aom_usec_timer t;
218 aom_usec_timer_start(&t);
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800219
220 for (decode_video.Begin(); decode_video.cxdata() != NULL;
221 decode_video.Next()) {
222 decoder.DecodeFrame(decode_video.cxdata(), decode_video.frame_size());
223 }
224
Yaowu Xuf883b422016-08-30 14:01:10 -0700225 aom_usec_timer_mark(&t);
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800226 const double elapsed_secs =
Yaowu Xuf883b422016-08-30 14:01:10 -0700227 static_cast<double>(aom_usec_timer_elapsed(&t)) / kUsecsInSec;
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800228 const unsigned decode_frames = decode_video.frame_number();
Jim Bankoski4276eac2014-12-19 15:53:59 -0800229 const double fps = static_cast<double>(decode_frames) / elapsed_secs;
Jim Bankoskic2638bd2014-12-09 12:44:45 -0800230
231 printf("{\n");
232 printf("\t\"type\" : \"decode_perf_test\",\n");
233 printf("\t\"version\" : \"%s\",\n", VERSION_STRING_NOSP);
234 printf("\t\"videoName\" : \"%s\",\n", kNewEncodeOutputFile);
235 printf("\t\"threadCount\" : %u,\n", threads);
236 printf("\t\"decodeTimeSecs\" : %f,\n", elapsed_secs);
237 printf("\t\"totalFrames\" : %u,\n", decode_frames);
238 printf("\t\"framesPerSecond\" : %f\n", fps);
239 printf("}\n");
240}
241
Yaowu Xuf883b422016-08-30 14:01:10 -0700242AV1_INSTANTIATE_TEST_CASE(AV1NewEncodeDecodePerfTest,
243 ::testing::Values(::libaom_test::kTwoPassGood));
Joshua Litta782d632013-11-15 12:29:26 -0800244} // namespace