1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #include <string>
13*77c1e3ccSAndroid Build Coastguard Worker #include <tuple>
14*77c1e3ccSAndroid Build Coastguard Worker
15*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aom_codec.h"
16*77c1e3ccSAndroid Build Coastguard Worker #include "aom_ports/aom_timer.h"
17*77c1e3ccSAndroid Build Coastguard Worker #include "common/ivfenc.h"
18*77c1e3ccSAndroid Build Coastguard Worker #include "test/codec_factory.h"
19*77c1e3ccSAndroid Build Coastguard Worker #include "test/decode_test_driver.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "test/encode_test_driver.h"
21*77c1e3ccSAndroid Build Coastguard Worker #include "test/i420_video_source.h"
22*77c1e3ccSAndroid Build Coastguard Worker #include "test/ivf_video_source.h"
23*77c1e3ccSAndroid Build Coastguard Worker #include "test/md5_helper.h"
24*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
25*77c1e3ccSAndroid Build Coastguard Worker #include "test/webm_video_source.h"
26*77c1e3ccSAndroid Build Coastguard Worker
27*77c1e3ccSAndroid Build Coastguard Worker using std::make_tuple;
28*77c1e3ccSAndroid Build Coastguard Worker
29*77c1e3ccSAndroid Build Coastguard Worker namespace {
30*77c1e3ccSAndroid Build Coastguard Worker
31*77c1e3ccSAndroid Build Coastguard Worker #define VIDEO_NAME 0
32*77c1e3ccSAndroid Build Coastguard Worker #define THREADS 1
33*77c1e3ccSAndroid Build Coastguard Worker
34*77c1e3ccSAndroid Build Coastguard Worker const double kUsecsInSec = 1000000.0;
35*77c1e3ccSAndroid Build Coastguard Worker const char kNewEncodeOutputFile[] = "new_encode.ivf";
36*77c1e3ccSAndroid Build Coastguard Worker
37*77c1e3ccSAndroid Build Coastguard Worker /*
38*77c1e3ccSAndroid Build Coastguard Worker DecodePerfTest takes a tuple of filename + number of threads to decode with
39*77c1e3ccSAndroid Build Coastguard Worker */
40*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<const char *, unsigned> DecodePerfParam;
41*77c1e3ccSAndroid Build Coastguard Worker
42*77c1e3ccSAndroid Build Coastguard Worker // TODO(jimbankoski): Add actual test vectors here when available.
43*77c1e3ccSAndroid Build Coastguard Worker // const DecodePerfParam kAV1DecodePerfVectors[] = {};
44*77c1e3ccSAndroid Build Coastguard Worker
45*77c1e3ccSAndroid Build Coastguard Worker /*
46*77c1e3ccSAndroid Build Coastguard Worker In order to reflect real world performance as much as possible, Perf tests
47*77c1e3ccSAndroid Build Coastguard Worker *DO NOT* do any correctness checks. Please run them alongside correctness
48*77c1e3ccSAndroid Build Coastguard Worker tests to ensure proper codec integrity. Furthermore, in this test we
49*77c1e3ccSAndroid Build Coastguard Worker deliberately limit the amount of system calls we make to avoid OS
50*77c1e3ccSAndroid Build Coastguard Worker preemption.
51*77c1e3ccSAndroid Build Coastguard Worker
52*77c1e3ccSAndroid Build Coastguard Worker TODO(joshualitt) create a more detailed perf measurement test to collect
53*77c1e3ccSAndroid Build Coastguard Worker power/temp/min max frame decode times/etc
54*77c1e3ccSAndroid Build Coastguard Worker */
55*77c1e3ccSAndroid Build Coastguard Worker
56*77c1e3ccSAndroid Build Coastguard Worker class DecodePerfTest : public ::testing::TestWithParam<DecodePerfParam> {};
57*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(DecodePerfTest,PerfTest)58*77c1e3ccSAndroid Build Coastguard Worker TEST_P(DecodePerfTest, PerfTest) {
59*77c1e3ccSAndroid Build Coastguard Worker const char *const video_name = GET_PARAM(VIDEO_NAME);
60*77c1e3ccSAndroid Build Coastguard Worker const unsigned threads = GET_PARAM(THREADS);
61*77c1e3ccSAndroid Build Coastguard Worker
62*77c1e3ccSAndroid Build Coastguard Worker libaom_test::WebMVideoSource video(video_name);
63*77c1e3ccSAndroid Build Coastguard Worker video.Init();
64*77c1e3ccSAndroid Build Coastguard Worker
65*77c1e3ccSAndroid Build Coastguard Worker aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
66*77c1e3ccSAndroid Build Coastguard Worker cfg.threads = threads;
67*77c1e3ccSAndroid Build Coastguard Worker cfg.allow_lowbitdepth = 1;
68*77c1e3ccSAndroid Build Coastguard Worker libaom_test::AV1Decoder decoder(cfg, 0);
69*77c1e3ccSAndroid Build Coastguard Worker
70*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer t;
71*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer_start(&t);
72*77c1e3ccSAndroid Build Coastguard Worker
73*77c1e3ccSAndroid Build Coastguard Worker for (video.Begin(); video.cxdata() != nullptr; video.Next()) {
74*77c1e3ccSAndroid Build Coastguard Worker decoder.DecodeFrame(video.cxdata(), video.frame_size());
75*77c1e3ccSAndroid Build Coastguard Worker }
76*77c1e3ccSAndroid Build Coastguard Worker
77*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer_mark(&t);
78*77c1e3ccSAndroid Build Coastguard Worker const double elapsed_secs = double(aom_usec_timer_elapsed(&t)) / kUsecsInSec;
79*77c1e3ccSAndroid Build Coastguard Worker const unsigned frames = video.frame_number();
80*77c1e3ccSAndroid Build Coastguard Worker const double fps = double(frames) / elapsed_secs;
81*77c1e3ccSAndroid Build Coastguard Worker
82*77c1e3ccSAndroid Build Coastguard Worker printf("{\n");
83*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"type\" : \"decode_perf_test\",\n");
84*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"version\" : \"%s\",\n", aom_codec_version_str());
85*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"videoName\" : \"%s\",\n", video_name);
86*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"threadCount\" : %u,\n", threads);
87*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"decodeTimeSecs\" : %f,\n", elapsed_secs);
88*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"totalFrames\" : %u,\n", frames);
89*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"framesPerSecond\" : %f\n", fps);
90*77c1e3ccSAndroid Build Coastguard Worker printf("}\n");
91*77c1e3ccSAndroid Build Coastguard Worker }
92*77c1e3ccSAndroid Build Coastguard Worker
93*77c1e3ccSAndroid Build Coastguard Worker // TODO(jimbankoski): Enabled when we have actual AV1 Decode vectors.
94*77c1e3ccSAndroid Build Coastguard Worker // INSTANTIATE_TEST_SUITE_P(AV1, DecodePerfTest,
95*77c1e3ccSAndroid Build Coastguard Worker // ::testing::ValuesIn(kAV1DecodePerfVectors));
96*77c1e3ccSAndroid Build Coastguard Worker
97*77c1e3ccSAndroid Build Coastguard Worker class AV1NewEncodeDecodePerfTest
98*77c1e3ccSAndroid Build Coastguard Worker : public ::libaom_test::CodecTestWithParam<libaom_test::TestMode>,
99*77c1e3ccSAndroid Build Coastguard Worker public ::libaom_test::EncoderTest {
100*77c1e3ccSAndroid Build Coastguard Worker protected:
AV1NewEncodeDecodePerfTest()101*77c1e3ccSAndroid Build Coastguard Worker AV1NewEncodeDecodePerfTest()
102*77c1e3ccSAndroid Build Coastguard Worker : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)), speed_(0),
103*77c1e3ccSAndroid Build Coastguard Worker outfile_(nullptr), out_frames_(0) {}
104*77c1e3ccSAndroid Build Coastguard Worker
105*77c1e3ccSAndroid Build Coastguard Worker ~AV1NewEncodeDecodePerfTest() override = default;
106*77c1e3ccSAndroid Build Coastguard Worker
SetUp()107*77c1e3ccSAndroid Build Coastguard Worker void SetUp() override {
108*77c1e3ccSAndroid Build Coastguard Worker InitializeConfig(encoding_mode_);
109*77c1e3ccSAndroid Build Coastguard Worker
110*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_lag_in_frames = 25;
111*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_min_quantizer = 2;
112*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_max_quantizer = 56;
113*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_dropframe_thresh = 0;
114*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_undershoot_pct = 50;
115*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_overshoot_pct = 50;
116*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_sz = 1000;
117*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_initial_sz = 500;
118*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_optimal_sz = 600;
119*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_end_usage = AOM_VBR;
120*77c1e3ccSAndroid Build Coastguard Worker }
121*77c1e3ccSAndroid Build Coastguard Worker
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)122*77c1e3ccSAndroid Build Coastguard Worker void PreEncodeFrameHook(::libaom_test::VideoSource *video,
123*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Encoder *encoder) override {
124*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() == 0) {
125*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_CPUUSED, speed_);
126*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
127*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_TILE_COLUMNS, 2);
128*77c1e3ccSAndroid Build Coastguard Worker }
129*77c1e3ccSAndroid Build Coastguard Worker }
130*77c1e3ccSAndroid Build Coastguard Worker
BeginPassHook(unsigned int)131*77c1e3ccSAndroid Build Coastguard Worker void BeginPassHook(unsigned int /*pass*/) override {
132*77c1e3ccSAndroid Build Coastguard Worker const char *const env = getenv("LIBAOM_TEST_DATA_PATH");
133*77c1e3ccSAndroid Build Coastguard Worker const std::string data_path(env ? env : ".");
134*77c1e3ccSAndroid Build Coastguard Worker const std::string path_to_source = data_path + "/" + kNewEncodeOutputFile;
135*77c1e3ccSAndroid Build Coastguard Worker outfile_ = fopen(path_to_source.c_str(), "wb");
136*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NE(outfile_, nullptr);
137*77c1e3ccSAndroid Build Coastguard Worker }
138*77c1e3ccSAndroid Build Coastguard Worker
EndPassHook()139*77c1e3ccSAndroid Build Coastguard Worker void EndPassHook() override {
140*77c1e3ccSAndroid Build Coastguard Worker if (outfile_ != nullptr) {
141*77c1e3ccSAndroid Build Coastguard Worker if (!fseek(outfile_, 0, SEEK_SET))
142*77c1e3ccSAndroid Build Coastguard Worker ivf_write_file_header(outfile_, &cfg_, AV1_FOURCC, out_frames_);
143*77c1e3ccSAndroid Build Coastguard Worker fclose(outfile_);
144*77c1e3ccSAndroid Build Coastguard Worker outfile_ = nullptr;
145*77c1e3ccSAndroid Build Coastguard Worker }
146*77c1e3ccSAndroid Build Coastguard Worker }
147*77c1e3ccSAndroid Build Coastguard Worker
FramePktHook(const aom_codec_cx_pkt_t * pkt)148*77c1e3ccSAndroid Build Coastguard Worker void FramePktHook(const aom_codec_cx_pkt_t *pkt) override {
149*77c1e3ccSAndroid Build Coastguard Worker ++out_frames_;
150*77c1e3ccSAndroid Build Coastguard Worker
151*77c1e3ccSAndroid Build Coastguard Worker // Write initial file header if first frame.
152*77c1e3ccSAndroid Build Coastguard Worker if (pkt->data.frame.pts == 0)
153*77c1e3ccSAndroid Build Coastguard Worker ivf_write_file_header(outfile_, &cfg_, AV1_FOURCC, out_frames_);
154*77c1e3ccSAndroid Build Coastguard Worker
155*77c1e3ccSAndroid Build Coastguard Worker // Write frame header and data.
156*77c1e3ccSAndroid Build Coastguard Worker ivf_write_frame_header(outfile_, out_frames_, pkt->data.frame.sz);
157*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, outfile_),
158*77c1e3ccSAndroid Build Coastguard Worker pkt->data.frame.sz);
159*77c1e3ccSAndroid Build Coastguard Worker }
160*77c1e3ccSAndroid Build Coastguard Worker
DoDecode() const161*77c1e3ccSAndroid Build Coastguard Worker bool DoDecode() const override { return false; }
162*77c1e3ccSAndroid Build Coastguard Worker
set_speed(unsigned int speed)163*77c1e3ccSAndroid Build Coastguard Worker void set_speed(unsigned int speed) { speed_ = speed; }
164*77c1e3ccSAndroid Build Coastguard Worker
165*77c1e3ccSAndroid Build Coastguard Worker private:
166*77c1e3ccSAndroid Build Coastguard Worker libaom_test::TestMode encoding_mode_;
167*77c1e3ccSAndroid Build Coastguard Worker uint32_t speed_;
168*77c1e3ccSAndroid Build Coastguard Worker FILE *outfile_;
169*77c1e3ccSAndroid Build Coastguard Worker uint32_t out_frames_;
170*77c1e3ccSAndroid Build Coastguard Worker };
171*77c1e3ccSAndroid Build Coastguard Worker
172*77c1e3ccSAndroid Build Coastguard Worker struct EncodePerfTestVideo {
EncodePerfTestVideo__anonad5f291c0111::EncodePerfTestVideo173*77c1e3ccSAndroid Build Coastguard Worker EncodePerfTestVideo(const char *name_, uint32_t width_, uint32_t height_,
174*77c1e3ccSAndroid Build Coastguard Worker uint32_t bitrate_, int frames_)
175*77c1e3ccSAndroid Build Coastguard Worker : name(name_), width(width_), height(height_), bitrate(bitrate_),
176*77c1e3ccSAndroid Build Coastguard Worker frames(frames_) {}
177*77c1e3ccSAndroid Build Coastguard Worker const char *name;
178*77c1e3ccSAndroid Build Coastguard Worker uint32_t width;
179*77c1e3ccSAndroid Build Coastguard Worker uint32_t height;
180*77c1e3ccSAndroid Build Coastguard Worker uint32_t bitrate;
181*77c1e3ccSAndroid Build Coastguard Worker int frames;
182*77c1e3ccSAndroid Build Coastguard Worker };
183*77c1e3ccSAndroid Build Coastguard Worker
184*77c1e3ccSAndroid Build Coastguard Worker const EncodePerfTestVideo kAV1EncodePerfTestVectors[] = {
185*77c1e3ccSAndroid Build Coastguard Worker EncodePerfTestVideo("niklas_1280_720_30.yuv", 1280, 720, 600, 470),
186*77c1e3ccSAndroid Build Coastguard Worker };
187*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(AV1NewEncodeDecodePerfTest,PerfTest)188*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1NewEncodeDecodePerfTest, PerfTest) {
189*77c1e3ccSAndroid Build Coastguard Worker SetUp();
190*77c1e3ccSAndroid Build Coastguard Worker
191*77c1e3ccSAndroid Build Coastguard Worker // TODO(JBB): Make this work by going through the set of given files.
192*77c1e3ccSAndroid Build Coastguard Worker const int i = 0;
193*77c1e3ccSAndroid Build Coastguard Worker const aom_rational timebase = { 33333333, 1000000000 };
194*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_timebase = timebase;
195*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = kAV1EncodePerfTestVectors[i].bitrate;
196*77c1e3ccSAndroid Build Coastguard Worker
197*77c1e3ccSAndroid Build Coastguard Worker init_flags_ = AOM_CODEC_USE_PSNR;
198*77c1e3ccSAndroid Build Coastguard Worker
199*77c1e3ccSAndroid Build Coastguard Worker const char *video_name = kAV1EncodePerfTestVectors[i].name;
200*77c1e3ccSAndroid Build Coastguard Worker libaom_test::I420VideoSource video(
201*77c1e3ccSAndroid Build Coastguard Worker video_name, kAV1EncodePerfTestVectors[i].width,
202*77c1e3ccSAndroid Build Coastguard Worker kAV1EncodePerfTestVectors[i].height, timebase.den, timebase.num, 0,
203*77c1e3ccSAndroid Build Coastguard Worker kAV1EncodePerfTestVectors[i].frames);
204*77c1e3ccSAndroid Build Coastguard Worker set_speed(2);
205*77c1e3ccSAndroid Build Coastguard Worker
206*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
207*77c1e3ccSAndroid Build Coastguard Worker
208*77c1e3ccSAndroid Build Coastguard Worker const uint32_t threads = 4;
209*77c1e3ccSAndroid Build Coastguard Worker
210*77c1e3ccSAndroid Build Coastguard Worker libaom_test::IVFVideoSource decode_video(kNewEncodeOutputFile);
211*77c1e3ccSAndroid Build Coastguard Worker decode_video.Init();
212*77c1e3ccSAndroid Build Coastguard Worker
213*77c1e3ccSAndroid Build Coastguard Worker aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
214*77c1e3ccSAndroid Build Coastguard Worker cfg.threads = threads;
215*77c1e3ccSAndroid Build Coastguard Worker cfg.allow_lowbitdepth = 1;
216*77c1e3ccSAndroid Build Coastguard Worker libaom_test::AV1Decoder decoder(cfg, 0);
217*77c1e3ccSAndroid Build Coastguard Worker
218*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer t;
219*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer_start(&t);
220*77c1e3ccSAndroid Build Coastguard Worker
221*77c1e3ccSAndroid Build Coastguard Worker for (decode_video.Begin(); decode_video.cxdata() != nullptr;
222*77c1e3ccSAndroid Build Coastguard Worker decode_video.Next()) {
223*77c1e3ccSAndroid Build Coastguard Worker decoder.DecodeFrame(decode_video.cxdata(), decode_video.frame_size());
224*77c1e3ccSAndroid Build Coastguard Worker }
225*77c1e3ccSAndroid Build Coastguard Worker
226*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer_mark(&t);
227*77c1e3ccSAndroid Build Coastguard Worker const double elapsed_secs =
228*77c1e3ccSAndroid Build Coastguard Worker static_cast<double>(aom_usec_timer_elapsed(&t)) / kUsecsInSec;
229*77c1e3ccSAndroid Build Coastguard Worker const unsigned decode_frames = decode_video.frame_number();
230*77c1e3ccSAndroid Build Coastguard Worker const double fps = static_cast<double>(decode_frames) / elapsed_secs;
231*77c1e3ccSAndroid Build Coastguard Worker
232*77c1e3ccSAndroid Build Coastguard Worker printf("{\n");
233*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"type\" : \"decode_perf_test\",\n");
234*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"version\" : \"%s\",\n", aom_codec_version_str());
235*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"videoName\" : \"%s\",\n", kNewEncodeOutputFile);
236*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"threadCount\" : %u,\n", threads);
237*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"decodeTimeSecs\" : %f,\n", elapsed_secs);
238*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"totalFrames\" : %u,\n", decode_frames);
239*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"framesPerSecond\" : %f\n", fps);
240*77c1e3ccSAndroid Build Coastguard Worker printf("}\n");
241*77c1e3ccSAndroid Build Coastguard Worker }
242*77c1e3ccSAndroid Build Coastguard Worker
243*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(AV1NewEncodeDecodePerfTest,
244*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(::libaom_test::kTwoPassGood));
245*77c1e3ccSAndroid Build Coastguard Worker } // namespace
246