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 "gtest/gtest.h"
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 "test/codec_factory.h"
18*77c1e3ccSAndroid Build Coastguard Worker #include "test/encode_test_driver.h"
19*77c1e3ccSAndroid Build Coastguard Worker #include "test/i420_video_source.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
21*77c1e3ccSAndroid Build Coastguard Worker #include "test/y4m_video_source.h"
22*77c1e3ccSAndroid Build Coastguard Worker
23*77c1e3ccSAndroid Build Coastguard Worker namespace {
24*77c1e3ccSAndroid Build Coastguard Worker
25*77c1e3ccSAndroid Build Coastguard Worker const int kMaxPsnr = 100;
26*77c1e3ccSAndroid Build Coastguard Worker const double kUsecsInSec = 1000000.0;
27*77c1e3ccSAndroid Build Coastguard Worker
28*77c1e3ccSAndroid Build Coastguard Worker struct EncodePerfTestVideo {
EncodePerfTestVideo__anonbd00c2860111::EncodePerfTestVideo29*77c1e3ccSAndroid Build Coastguard Worker EncodePerfTestVideo(const char *name_, uint32_t width_, uint32_t height_,
30*77c1e3ccSAndroid Build Coastguard Worker uint32_t bitrate_, int frames_)
31*77c1e3ccSAndroid Build Coastguard Worker : name(name_), width(width_), height(height_), bitrate(bitrate_),
32*77c1e3ccSAndroid Build Coastguard Worker frames(frames_) {}
33*77c1e3ccSAndroid Build Coastguard Worker const char *name;
34*77c1e3ccSAndroid Build Coastguard Worker uint32_t width;
35*77c1e3ccSAndroid Build Coastguard Worker uint32_t height;
36*77c1e3ccSAndroid Build Coastguard Worker uint32_t bitrate;
37*77c1e3ccSAndroid Build Coastguard Worker int frames;
38*77c1e3ccSAndroid Build Coastguard Worker };
39*77c1e3ccSAndroid Build Coastguard Worker
40*77c1e3ccSAndroid Build Coastguard Worker const EncodePerfTestVideo kAV1EncodePerfTestVectors[] = {
41*77c1e3ccSAndroid Build Coastguard Worker EncodePerfTestVideo("desktop_640_360_30.yuv", 640, 360, 200, 2484),
42*77c1e3ccSAndroid Build Coastguard Worker EncodePerfTestVideo("kirland_640_480_30.yuv", 640, 480, 200, 300),
43*77c1e3ccSAndroid Build Coastguard Worker EncodePerfTestVideo("macmarcomoving_640_480_30.yuv", 640, 480, 200, 987),
44*77c1e3ccSAndroid Build Coastguard Worker EncodePerfTestVideo("macmarcostationary_640_480_30.yuv", 640, 480, 200, 718),
45*77c1e3ccSAndroid Build Coastguard Worker EncodePerfTestVideo("niklas_640_480_30.yuv", 640, 480, 200, 471),
46*77c1e3ccSAndroid Build Coastguard Worker EncodePerfTestVideo("tacomanarrows_640_480_30.yuv", 640, 480, 200, 300),
47*77c1e3ccSAndroid Build Coastguard Worker EncodePerfTestVideo("tacomasmallcameramovement_640_480_30.yuv", 640, 480, 200,
48*77c1e3ccSAndroid Build Coastguard Worker 300),
49*77c1e3ccSAndroid Build Coastguard Worker EncodePerfTestVideo("thaloundeskmtg_640_480_30.yuv", 640, 480, 200, 300),
50*77c1e3ccSAndroid Build Coastguard Worker EncodePerfTestVideo("niklas_1280_720_30.yuv", 1280, 720, 600, 470),
51*77c1e3ccSAndroid Build Coastguard Worker };
52*77c1e3ccSAndroid Build Coastguard Worker
53*77c1e3ccSAndroid Build Coastguard Worker const int kEncodePerfTestSpeeds[] = { 5, 6, 7, 8 };
54*77c1e3ccSAndroid Build Coastguard Worker const int kEncodePerfTestThreads[] = { 1, 2, 4 };
55*77c1e3ccSAndroid Build Coastguard Worker
56*77c1e3ccSAndroid Build Coastguard Worker class AV1EncodePerfTest
57*77c1e3ccSAndroid Build Coastguard Worker : public ::libaom_test::CodecTestWithParam<libaom_test::TestMode>,
58*77c1e3ccSAndroid Build Coastguard Worker public ::libaom_test::EncoderTest {
59*77c1e3ccSAndroid Build Coastguard Worker protected:
AV1EncodePerfTest()60*77c1e3ccSAndroid Build Coastguard Worker AV1EncodePerfTest()
61*77c1e3ccSAndroid Build Coastguard Worker : EncoderTest(GET_PARAM(0)), min_psnr_(kMaxPsnr), nframes_(0),
62*77c1e3ccSAndroid Build Coastguard Worker encoding_mode_(GET_PARAM(1)), speed_(0), threads_(1) {}
63*77c1e3ccSAndroid Build Coastguard Worker
64*77c1e3ccSAndroid Build Coastguard Worker ~AV1EncodePerfTest() override = default;
65*77c1e3ccSAndroid Build Coastguard Worker
SetUp()66*77c1e3ccSAndroid Build Coastguard Worker void SetUp() override {
67*77c1e3ccSAndroid Build Coastguard Worker InitializeConfig(encoding_mode_);
68*77c1e3ccSAndroid Build Coastguard Worker
69*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_lag_in_frames = 0;
70*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_min_quantizer = 2;
71*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_max_quantizer = 56;
72*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_dropframe_thresh = 0;
73*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_undershoot_pct = 50;
74*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_overshoot_pct = 50;
75*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_sz = 1000;
76*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_initial_sz = 500;
77*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_optimal_sz = 600;
78*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_end_usage = AOM_CBR;
79*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_error_resilient = 1;
80*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_threads = threads_;
81*77c1e3ccSAndroid Build Coastguard Worker }
82*77c1e3ccSAndroid Build Coastguard Worker
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)83*77c1e3ccSAndroid Build Coastguard Worker void PreEncodeFrameHook(::libaom_test::VideoSource *video,
84*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Encoder *encoder) override {
85*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() == 0) {
86*77c1e3ccSAndroid Build Coastguard Worker const int log2_tile_columns = 3;
87*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_CPUUSED, speed_);
88*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_TILE_COLUMNS, log2_tile_columns);
89*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
90*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0);
91*77c1e3ccSAndroid Build Coastguard Worker }
92*77c1e3ccSAndroid Build Coastguard Worker }
93*77c1e3ccSAndroid Build Coastguard Worker
BeginPassHook(unsigned int)94*77c1e3ccSAndroid Build Coastguard Worker void BeginPassHook(unsigned int /*pass*/) override {
95*77c1e3ccSAndroid Build Coastguard Worker min_psnr_ = kMaxPsnr;
96*77c1e3ccSAndroid Build Coastguard Worker nframes_ = 0;
97*77c1e3ccSAndroid Build Coastguard Worker }
98*77c1e3ccSAndroid Build Coastguard Worker
PSNRPktHook(const aom_codec_cx_pkt_t * pkt)99*77c1e3ccSAndroid Build Coastguard Worker void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) override {
100*77c1e3ccSAndroid Build Coastguard Worker if (pkt->data.psnr.psnr[0] < min_psnr_) {
101*77c1e3ccSAndroid Build Coastguard Worker min_psnr_ = pkt->data.psnr.psnr[0];
102*77c1e3ccSAndroid Build Coastguard Worker }
103*77c1e3ccSAndroid Build Coastguard Worker }
104*77c1e3ccSAndroid Build Coastguard Worker
105*77c1e3ccSAndroid Build Coastguard Worker // for performance reasons don't decode
DoDecode() const106*77c1e3ccSAndroid Build Coastguard Worker bool DoDecode() const override { return false; }
107*77c1e3ccSAndroid Build Coastguard Worker
min_psnr() const108*77c1e3ccSAndroid Build Coastguard Worker double min_psnr() const { return min_psnr_; }
109*77c1e3ccSAndroid Build Coastguard Worker
set_speed(unsigned int speed)110*77c1e3ccSAndroid Build Coastguard Worker void set_speed(unsigned int speed) { speed_ = speed; }
111*77c1e3ccSAndroid Build Coastguard Worker
set_threads(unsigned int threads)112*77c1e3ccSAndroid Build Coastguard Worker void set_threads(unsigned int threads) { threads_ = threads; }
113*77c1e3ccSAndroid Build Coastguard Worker
114*77c1e3ccSAndroid Build Coastguard Worker private:
115*77c1e3ccSAndroid Build Coastguard Worker double min_psnr_;
116*77c1e3ccSAndroid Build Coastguard Worker unsigned int nframes_;
117*77c1e3ccSAndroid Build Coastguard Worker libaom_test::TestMode encoding_mode_;
118*77c1e3ccSAndroid Build Coastguard Worker unsigned speed_;
119*77c1e3ccSAndroid Build Coastguard Worker unsigned int threads_;
120*77c1e3ccSAndroid Build Coastguard Worker };
121*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(AV1EncodePerfTest,PerfTest)122*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1EncodePerfTest, PerfTest) {
123*77c1e3ccSAndroid Build Coastguard Worker for (const EncodePerfTestVideo &test_video : kAV1EncodePerfTestVectors) {
124*77c1e3ccSAndroid Build Coastguard Worker for (int speed : kEncodePerfTestSpeeds) {
125*77c1e3ccSAndroid Build Coastguard Worker for (int threads : kEncodePerfTestThreads) {
126*77c1e3ccSAndroid Build Coastguard Worker if (test_video.width < 512 && threads > 1)
127*77c1e3ccSAndroid Build Coastguard Worker continue;
128*77c1e3ccSAndroid Build Coastguard Worker else if (test_video.width < 1024 && threads > 2)
129*77c1e3ccSAndroid Build Coastguard Worker continue;
130*77c1e3ccSAndroid Build Coastguard Worker
131*77c1e3ccSAndroid Build Coastguard Worker set_threads(threads);
132*77c1e3ccSAndroid Build Coastguard Worker SetUp();
133*77c1e3ccSAndroid Build Coastguard Worker
134*77c1e3ccSAndroid Build Coastguard Worker const aom_rational timebase = { 33333333, 1000000000 };
135*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_timebase = timebase;
136*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = test_video.bitrate;
137*77c1e3ccSAndroid Build Coastguard Worker
138*77c1e3ccSAndroid Build Coastguard Worker init_flags_ = AOM_CODEC_USE_PSNR;
139*77c1e3ccSAndroid Build Coastguard Worker
140*77c1e3ccSAndroid Build Coastguard Worker const unsigned frames = test_video.frames;
141*77c1e3ccSAndroid Build Coastguard Worker const char *video_name = test_video.name;
142*77c1e3ccSAndroid Build Coastguard Worker libaom_test::I420VideoSource video(video_name, test_video.width,
143*77c1e3ccSAndroid Build Coastguard Worker test_video.height, timebase.den,
144*77c1e3ccSAndroid Build Coastguard Worker timebase.num, 0, test_video.frames);
145*77c1e3ccSAndroid Build Coastguard Worker set_speed(speed);
146*77c1e3ccSAndroid Build Coastguard Worker
147*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer t;
148*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer_start(&t);
149*77c1e3ccSAndroid Build Coastguard Worker
150*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
151*77c1e3ccSAndroid Build Coastguard Worker
152*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer_mark(&t);
153*77c1e3ccSAndroid Build Coastguard Worker const double elapsed_secs = aom_usec_timer_elapsed(&t) / kUsecsInSec;
154*77c1e3ccSAndroid Build Coastguard Worker const double fps = frames / elapsed_secs;
155*77c1e3ccSAndroid Build Coastguard Worker const double minimum_psnr = min_psnr();
156*77c1e3ccSAndroid Build Coastguard Worker std::string display_name(video_name);
157*77c1e3ccSAndroid Build Coastguard Worker if (threads > 1) {
158*77c1e3ccSAndroid Build Coastguard Worker char thread_count[32];
159*77c1e3ccSAndroid Build Coastguard Worker snprintf(thread_count, sizeof(thread_count), "_t-%d", threads);
160*77c1e3ccSAndroid Build Coastguard Worker display_name += thread_count;
161*77c1e3ccSAndroid Build Coastguard Worker }
162*77c1e3ccSAndroid Build Coastguard Worker
163*77c1e3ccSAndroid Build Coastguard Worker printf("{\n");
164*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"type\" : \"encode_perf_test\",\n");
165*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"version\" : \"%s\",\n", aom_codec_version_str());
166*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"videoName\" : \"%s\",\n", display_name.c_str());
167*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"encodeTimeSecs\" : %f,\n", elapsed_secs);
168*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"totalFrames\" : %u,\n", frames);
169*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"framesPerSecond\" : %f,\n", fps);
170*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"minPsnr\" : %f,\n", minimum_psnr);
171*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"speed\" : %d,\n", speed);
172*77c1e3ccSAndroid Build Coastguard Worker printf("\t\"threads\" : %d\n", threads);
173*77c1e3ccSAndroid Build Coastguard Worker printf("}\n");
174*77c1e3ccSAndroid Build Coastguard Worker }
175*77c1e3ccSAndroid Build Coastguard Worker }
176*77c1e3ccSAndroid Build Coastguard Worker }
177*77c1e3ccSAndroid Build Coastguard Worker }
178*77c1e3ccSAndroid Build Coastguard Worker
179*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(AV1EncodePerfTest,
180*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(::libaom_test::kRealTime));
181*77c1e3ccSAndroid Build Coastguard Worker } // namespace
182