Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 4 | * 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 Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 11 | |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 12 | #include <string> |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 13 | #include "test/codec_factory.h" |
| 14 | #include "test/decode_test_driver.h" |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 15 | #include "test/encode_test_driver.h" |
| 16 | #include "test/i420_video_source.h" |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 17 | #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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 21 | #include "aom_ports/aom_timer.h" |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 22 | #include "./ivfenc.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 23 | #include "./aom_version.h" |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 24 | |
| 25 | using std::tr1::make_tuple; |
| 26 | |
| 27 | namespace { |
| 28 | |
| 29 | #define VIDEO_NAME 0 |
| 30 | #define THREADS 1 |
| 31 | |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 32 | const int kMaxPsnr = 100; |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 33 | const double kUsecsInSec = 1000000.0; |
Jim Bankoski | 4276eac | 2014-12-19 15:53:59 -0800 | [diff] [blame] | 34 | const char kNewEncodeOutputFile[] = "new_encode.ivf"; |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | DecodePerfTest takes a tuple of filename + number of threads to decode with |
| 38 | */ |
James Zern | c3314b7 | 2014-07-16 18:55:08 -0700 | [diff] [blame] | 39 | typedef std::tr1::tuple<const char *, unsigned> DecodePerfParam; |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 40 | |
Jim Bankoski | 4362b3e | 2016-11-22 07:50:05 -0800 | [diff] [blame] | 41 | // TODO(jimbankoski): Add actual test vectors here when available. |
| 42 | // const DecodePerfParam kAV1DecodePerfVectors[] = {}; |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 43 | |
| 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-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 55 | class DecodePerfTest : public ::testing::TestWithParam<DecodePerfParam> {}; |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 56 | |
| 57 | TEST_P(DecodePerfTest, PerfTest) { |
| 58 | const char *const video_name = GET_PARAM(VIDEO_NAME); |
| 59 | const unsigned threads = GET_PARAM(THREADS); |
| 60 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 61 | libaom_test::WebMVideoSource video(video_name); |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 62 | video.Init(); |
| 63 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 64 | aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t(); |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 65 | cfg.threads = threads; |
Sebastien Alaiwan | 8a65f9f | 2017-06-23 07:28:44 +0200 | [diff] [blame] | 66 | cfg.allow_lowbitdepth = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 67 | libaom_test::AV1Decoder decoder(cfg, 0); |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 68 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 69 | aom_usec_timer t; |
| 70 | aom_usec_timer_start(&t); |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 71 | |
| 72 | for (video.Begin(); video.cxdata() != NULL; video.Next()) { |
| 73 | decoder.DecodeFrame(video.cxdata(), video.frame_size()); |
| 74 | } |
| 75 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 76 | aom_usec_timer_mark(&t); |
| 77 | const double elapsed_secs = double(aom_usec_timer_elapsed(&t)) / kUsecsInSec; |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 78 | const unsigned frames = video.frame_number(); |
| 79 | const double fps = double(frames) / elapsed_secs; |
| 80 | |
| 81 | printf("{\n"); |
Joshua Litt | 83b843f | 2014-07-21 10:57:16 -0700 | [diff] [blame] | 82 | printf("\t\"type\" : \"decode_perf_test\",\n"); |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 83 | 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 Bankoski | 4362b3e | 2016-11-22 07:50:05 -0800 | [diff] [blame] | 92 | // TODO(jimbankoski): Enabled when we have actual AV1 Decode vectors. |
| 93 | // INSTANTIATE_TEST_CASE_P(AV1, DecodePerfTest, |
| 94 | // ::testing::ValuesIn(kAV1DecodePerfVectors)); |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 95 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 96 | class AV1NewEncodeDecodePerfTest |
Sebastien Alaiwan | 4322bc1 | 2017-06-05 10:18:28 +0200 | [diff] [blame] | 97 | : public ::libaom_test::CodecTestWithParam<libaom_test::TestMode>, |
| 98 | public ::libaom_test::EncoderTest { |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 99 | protected: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 100 | AV1NewEncodeDecodePerfTest() |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 101 | : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)), speed_(0), |
| 102 | outfile_(0), out_frames_(0) {} |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 103 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 104 | virtual ~AV1NewEncodeDecodePerfTest() {} |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 105 | |
| 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 119 | cfg_.rc_end_usage = AOM_VBR; |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 120 | } |
| 121 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 122 | virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video, |
| 123 | ::libaom_test::Encoder *encoder) { |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 124 | if (video->frame() == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 125 | encoder->Control(AOME_SET_CPUUSED, speed_); |
| 126 | encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1); |
| 127 | encoder->Control(AV1E_SET_TILE_COLUMNS, 2); |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | |
| 131 | virtual void BeginPassHook(unsigned int /*pass*/) { |
Yaowu Xu | 97aa09f | 2016-10-12 08:25:39 -0700 | [diff] [blame] | 132 | const std::string data_path = getenv("LIBAOM_TEST_DATA_PATH"); |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 133 | const std::string path_to_source = data_path + "/" + kNewEncodeOutputFile; |
| 134 | outfile_ = fopen(path_to_source.c_str(), "wb"); |
Jim Bankoski | 4276eac | 2014-12-19 15:53:59 -0800 | [diff] [blame] | 135 | ASSERT_TRUE(outfile_ != NULL); |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | virtual void EndPassHook() { |
Jim Bankoski | 4276eac | 2014-12-19 15:53:59 -0800 | [diff] [blame] | 139 | if (outfile_ != NULL) { |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 140 | if (!fseek(outfile_, 0, SEEK_SET)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 141 | ivf_write_file_header(outfile_, &cfg_, AV1_FOURCC, out_frames_); |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 142 | fclose(outfile_); |
| 143 | outfile_ = NULL; |
| 144 | } |
| 145 | } |
| 146 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 147 | virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) { |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 148 | ++out_frames_; |
| 149 | |
| 150 | // Write initial file header if first frame. |
| 151 | if (pkt->data.frame.pts == 0) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 152 | ivf_write_file_header(outfile_, &cfg_, AV1_FOURCC, out_frames_); |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 153 | |
| 154 | // Write frame header and data. |
| 155 | ivf_write_frame_header(outfile_, out_frames_, pkt->data.frame.sz); |
Jim Bankoski | 8619274 | 2014-12-23 08:35:26 -0800 | [diff] [blame] | 156 | ASSERT_EQ(fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, outfile_), |
| 157 | pkt->data.frame.sz); |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Jim Bankoski | 4276eac | 2014-12-19 15:53:59 -0800 | [diff] [blame] | 160 | virtual bool DoDecode() { return false; } |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 161 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 162 | void set_speed(unsigned int speed) { speed_ = speed; } |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 163 | |
| 164 | private: |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 165 | libaom_test::TestMode encoding_mode_; |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 166 | uint32_t speed_; |
| 167 | FILE *outfile_; |
| 168 | uint32_t out_frames_; |
| 169 | }; |
| 170 | |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 171 | struct EncodePerfTestVideo { |
| 172 | EncodePerfTestVideo(const char *name_, uint32_t width_, uint32_t height_, |
| 173 | uint32_t bitrate_, int frames_) |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 174 | : name(name_), width(width_), height(height_), bitrate(bitrate_), |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 175 | frames(frames_) {} |
| 176 | const char *name; |
| 177 | uint32_t width; |
| 178 | uint32_t height; |
| 179 | uint32_t bitrate; |
| 180 | int frames; |
| 181 | }; |
| 182 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 183 | const EncodePerfTestVideo kAV1EncodePerfTestVectors[] = { |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 184 | EncodePerfTestVideo("niklas_1280_720_30.yuv", 1280, 720, 600, 470), |
| 185 | }; |
| 186 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 187 | TEST_P(AV1NewEncodeDecodePerfTest, PerfTest) { |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 188 | SetUp(); |
| 189 | |
| 190 | // TODO(JBB): Make this work by going through the set of given files. |
| 191 | const int i = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 192 | const aom_rational timebase = { 33333333, 1000000000 }; |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 193 | cfg_.g_timebase = timebase; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 194 | cfg_.rc_target_bitrate = kAV1EncodePerfTestVectors[i].bitrate; |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 195 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 196 | init_flags_ = AOM_CODEC_USE_PSNR; |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 197 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 198 | const char *video_name = kAV1EncodePerfTestVectors[i].name; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 199 | libaom_test::I420VideoSource video( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 200 | video_name, kAV1EncodePerfTestVectors[i].width, |
| 201 | kAV1EncodePerfTestVectors[i].height, timebase.den, timebase.num, 0, |
| 202 | kAV1EncodePerfTestVectors[i].frames); |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 203 | set_speed(2); |
| 204 | |
| 205 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 206 | |
| 207 | const uint32_t threads = 4; |
| 208 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 209 | libaom_test::IVFVideoSource decode_video(kNewEncodeOutputFile); |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 210 | decode_video.Init(); |
| 211 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 212 | aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t(); |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 213 | cfg.threads = threads; |
Sebastien Alaiwan | 8a65f9f | 2017-06-23 07:28:44 +0200 | [diff] [blame] | 214 | cfg.allow_lowbitdepth = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 215 | libaom_test::AV1Decoder decoder(cfg, 0); |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 216 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 217 | aom_usec_timer t; |
| 218 | aom_usec_timer_start(&t); |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 219 | |
| 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 225 | aom_usec_timer_mark(&t); |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 226 | const double elapsed_secs = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 227 | static_cast<double>(aom_usec_timer_elapsed(&t)) / kUsecsInSec; |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 228 | const unsigned decode_frames = decode_video.frame_number(); |
Jim Bankoski | 4276eac | 2014-12-19 15:53:59 -0800 | [diff] [blame] | 229 | const double fps = static_cast<double>(decode_frames) / elapsed_secs; |
Jim Bankoski | c2638bd | 2014-12-09 12:44:45 -0800 | [diff] [blame] | 230 | |
| 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 242 | AV1_INSTANTIATE_TEST_CASE(AV1NewEncodeDecodePerfTest, |
| 243 | ::testing::Values(::libaom_test::kTwoPassGood)); |
Joshua Litt | a782d63 | 2013-11-15 12:29:26 -0800 | [diff] [blame] | 244 | } // namespace |