cpu_speed_test.cc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "third_party/googletest/src/include/gtest/gtest.h"
  11. #include "test/codec_factory.h"
  12. #include "test/encode_test_driver.h"
  13. #include "test/i420_video_source.h"
  14. #include "test/util.h"
  15. #include "test/y4m_video_source.h"
  16. namespace {
  17. const int kMaxPSNR = 100;
  18. class CpuSpeedTest
  19. : public ::libvpx_test::EncoderTest,
  20. public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> {
  21. protected:
  22. CpuSpeedTest()
  23. : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
  24. set_cpu_used_(GET_PARAM(2)), min_psnr_(kMaxPSNR),
  25. tune_content_(VP9E_CONTENT_DEFAULT) {}
  26. virtual ~CpuSpeedTest() {}
  27. virtual void SetUp() {
  28. InitializeConfig();
  29. SetMode(encoding_mode_);
  30. if (encoding_mode_ != ::libvpx_test::kRealTime) {
  31. cfg_.g_lag_in_frames = 25;
  32. cfg_.rc_end_usage = VPX_VBR;
  33. } else {
  34. cfg_.g_lag_in_frames = 0;
  35. cfg_.rc_end_usage = VPX_CBR;
  36. }
  37. }
  38. virtual void BeginPassHook(unsigned int /*pass*/) { min_psnr_ = kMaxPSNR; }
  39. virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
  40. ::libvpx_test::Encoder *encoder) {
  41. if (video->frame() == 0) {
  42. encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_);
  43. encoder->Control(VP9E_SET_TUNE_CONTENT, tune_content_);
  44. if (encoding_mode_ != ::libvpx_test::kRealTime) {
  45. encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
  46. encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
  47. encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
  48. encoder->Control(VP8E_SET_ARNR_TYPE, 3);
  49. }
  50. }
  51. }
  52. virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
  53. if (pkt->data.psnr.psnr[0] < min_psnr_) min_psnr_ = pkt->data.psnr.psnr[0];
  54. }
  55. ::libvpx_test::TestMode encoding_mode_;
  56. int set_cpu_used_;
  57. double min_psnr_;
  58. int tune_content_;
  59. };
  60. TEST_P(CpuSpeedTest, TestQ0) {
  61. // Validate that this non multiple of 64 wide clip encodes and decodes
  62. // without a mismatch when passing in a very low max q. This pushes
  63. // the encoder to producing lots of big partitions which will likely
  64. // extend into the border and test the border condition.
  65. cfg_.rc_2pass_vbr_minsection_pct = 5;
  66. cfg_.rc_2pass_vbr_maxsection_pct = 2000;
  67. cfg_.rc_target_bitrate = 400;
  68. cfg_.rc_max_quantizer = 0;
  69. cfg_.rc_min_quantizer = 0;
  70. ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
  71. 20);
  72. init_flags_ = VPX_CODEC_USE_PSNR;
  73. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  74. EXPECT_GE(min_psnr_, kMaxPSNR);
  75. }
  76. TEST_P(CpuSpeedTest, TestScreencastQ0) {
  77. ::libvpx_test::Y4mVideoSource video("screendata.y4m", 0, 25);
  78. cfg_.g_timebase = video.timebase();
  79. cfg_.rc_2pass_vbr_minsection_pct = 5;
  80. cfg_.rc_2pass_vbr_maxsection_pct = 2000;
  81. cfg_.rc_target_bitrate = 400;
  82. cfg_.rc_max_quantizer = 0;
  83. cfg_.rc_min_quantizer = 0;
  84. init_flags_ = VPX_CODEC_USE_PSNR;
  85. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  86. EXPECT_GE(min_psnr_, kMaxPSNR);
  87. }
  88. TEST_P(CpuSpeedTest, TestTuneScreen) {
  89. ::libvpx_test::Y4mVideoSource video("screendata.y4m", 0, 25);
  90. cfg_.g_timebase = video.timebase();
  91. cfg_.rc_2pass_vbr_minsection_pct = 5;
  92. cfg_.rc_2pass_vbr_minsection_pct = 2000;
  93. cfg_.rc_target_bitrate = 2000;
  94. cfg_.rc_max_quantizer = 63;
  95. cfg_.rc_min_quantizer = 0;
  96. tune_content_ = VP9E_CONTENT_SCREEN;
  97. init_flags_ = VPX_CODEC_USE_PSNR;
  98. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  99. }
  100. TEST_P(CpuSpeedTest, TestEncodeHighBitrate) {
  101. // Validate that this non multiple of 64 wide clip encodes and decodes
  102. // without a mismatch when passing in a very low max q. This pushes
  103. // the encoder to producing lots of big partitions which will likely
  104. // extend into the border and test the border condition.
  105. cfg_.rc_2pass_vbr_minsection_pct = 5;
  106. cfg_.rc_2pass_vbr_maxsection_pct = 2000;
  107. cfg_.rc_target_bitrate = 12000;
  108. cfg_.rc_max_quantizer = 10;
  109. cfg_.rc_min_quantizer = 0;
  110. ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
  111. 20);
  112. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  113. }
  114. TEST_P(CpuSpeedTest, TestLowBitrate) {
  115. // Validate that this clip encodes and decodes without a mismatch
  116. // when passing in a very high min q. This pushes the encoder to producing
  117. // lots of small partitions which might will test the other condition.
  118. cfg_.rc_2pass_vbr_minsection_pct = 5;
  119. cfg_.rc_2pass_vbr_maxsection_pct = 2000;
  120. cfg_.rc_target_bitrate = 200;
  121. cfg_.rc_min_quantizer = 40;
  122. ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
  123. 20);
  124. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  125. }
  126. VP9_INSTANTIATE_TEST_CASE(CpuSpeedTest,
  127. ::testing::Values(::libvpx_test::kTwoPassGood,
  128. ::libvpx_test::kOnePassGood,
  129. ::libvpx_test::kRealTime),
  130. ::testing::Range(0, 10));
  131. } // namespace