level_test.cc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (c) 2016 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. namespace {
  16. class LevelTest
  17. : public ::libvpx_test::EncoderTest,
  18. public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> {
  19. protected:
  20. LevelTest()
  21. : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
  22. cpu_used_(GET_PARAM(2)), min_gf_internal_(24), target_level_(0),
  23. level_(0) {}
  24. virtual ~LevelTest() {}
  25. virtual void SetUp() {
  26. InitializeConfig();
  27. SetMode(encoding_mode_);
  28. if (encoding_mode_ != ::libvpx_test::kRealTime) {
  29. cfg_.g_lag_in_frames = 25;
  30. cfg_.rc_end_usage = VPX_VBR;
  31. } else {
  32. cfg_.g_lag_in_frames = 0;
  33. cfg_.rc_end_usage = VPX_CBR;
  34. }
  35. cfg_.rc_2pass_vbr_minsection_pct = 5;
  36. cfg_.rc_2pass_vbr_maxsection_pct = 2000;
  37. cfg_.rc_target_bitrate = 400;
  38. cfg_.rc_max_quantizer = 63;
  39. cfg_.rc_min_quantizer = 0;
  40. }
  41. virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
  42. ::libvpx_test::Encoder *encoder) {
  43. if (video->frame() == 0) {
  44. encoder->Control(VP8E_SET_CPUUSED, cpu_used_);
  45. encoder->Control(VP9E_SET_TARGET_LEVEL, target_level_);
  46. encoder->Control(VP9E_SET_MIN_GF_INTERVAL, min_gf_internal_);
  47. if (encoding_mode_ != ::libvpx_test::kRealTime) {
  48. encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
  49. encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
  50. encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
  51. encoder->Control(VP8E_SET_ARNR_TYPE, 3);
  52. }
  53. }
  54. encoder->Control(VP9E_GET_LEVEL, &level_);
  55. ASSERT_LE(level_, 51);
  56. ASSERT_GE(level_, 0);
  57. }
  58. ::libvpx_test::TestMode encoding_mode_;
  59. int cpu_used_;
  60. int min_gf_internal_;
  61. int target_level_;
  62. int level_;
  63. };
  64. TEST_P(LevelTest, TestTargetLevel11Large) {
  65. ASSERT_NE(encoding_mode_, ::libvpx_test::kRealTime);
  66. ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
  67. 60);
  68. target_level_ = 11;
  69. cfg_.rc_target_bitrate = 150;
  70. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  71. ASSERT_GE(target_level_, level_);
  72. }
  73. TEST_P(LevelTest, TestTargetLevel20Large) {
  74. ASSERT_NE(encoding_mode_, ::libvpx_test::kRealTime);
  75. ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
  76. 30, 1, 0, 60);
  77. target_level_ = 20;
  78. cfg_.rc_target_bitrate = 1200;
  79. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  80. ASSERT_GE(target_level_, level_);
  81. }
  82. TEST_P(LevelTest, TestTargetLevel31Large) {
  83. ASSERT_NE(encoding_mode_, ::libvpx_test::kRealTime);
  84. ::libvpx_test::I420VideoSource video("niklas_1280_720_30.y4m", 1280, 720, 30,
  85. 1, 0, 60);
  86. target_level_ = 31;
  87. cfg_.rc_target_bitrate = 8000;
  88. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  89. ASSERT_GE(target_level_, level_);
  90. }
  91. // Test for keeping level stats only
  92. TEST_P(LevelTest, TestTargetLevel0) {
  93. ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
  94. 40);
  95. target_level_ = 0;
  96. min_gf_internal_ = 4;
  97. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  98. ASSERT_GE(11, level_);
  99. cfg_.rc_target_bitrate = 1600;
  100. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  101. ASSERT_GE(20, level_);
  102. }
  103. // Test for level control being turned off
  104. TEST_P(LevelTest, TestTargetLevel255) {
  105. ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
  106. 30);
  107. target_level_ = 255;
  108. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  109. }
  110. TEST_P(LevelTest, TestTargetLevelApi) {
  111. ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0, 1);
  112. static const vpx_codec_iface_t *codec = &vpx_codec_vp9_cx_algo;
  113. vpx_codec_ctx_t enc;
  114. vpx_codec_enc_cfg_t cfg;
  115. EXPECT_EQ(VPX_CODEC_OK, vpx_codec_enc_config_default(codec, &cfg, 0));
  116. cfg.rc_target_bitrate = 100;
  117. EXPECT_EQ(VPX_CODEC_OK, vpx_codec_enc_init(&enc, codec, &cfg, 0));
  118. for (int level = 0; level <= 256; ++level) {
  119. if (level == 10 || level == 11 || level == 20 || level == 21 ||
  120. level == 30 || level == 31 || level == 40 || level == 41 ||
  121. level == 50 || level == 51 || level == 52 || level == 60 ||
  122. level == 61 || level == 62 || level == 0 || level == 1 || level == 255)
  123. EXPECT_EQ(VPX_CODEC_OK,
  124. vpx_codec_control(&enc, VP9E_SET_TARGET_LEVEL, level));
  125. else
  126. EXPECT_EQ(VPX_CODEC_INVALID_PARAM,
  127. vpx_codec_control(&enc, VP9E_SET_TARGET_LEVEL, level));
  128. }
  129. EXPECT_EQ(VPX_CODEC_OK, vpx_codec_destroy(&enc));
  130. }
  131. VP9_INSTANTIATE_TEST_CASE(LevelTest,
  132. ::testing::Values(::libvpx_test::kTwoPassGood,
  133. ::libvpx_test::kOnePassGood),
  134. ::testing::Range(0, 9));
  135. } // namespace