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