vp9_end_to_end_test.cc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright (c) 2014 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/util.h"
  14. #include "test/y4m_video_source.h"
  15. #include "test/yuv_video_source.h"
  16. namespace {
  17. const unsigned int kWidth = 160;
  18. const unsigned int kHeight = 90;
  19. const unsigned int kFramerate = 50;
  20. const unsigned int kFrames = 10;
  21. const int kBitrate = 500;
  22. // List of psnr thresholds for speed settings 0-7 and 5 encoding modes
  23. const double kPsnrThreshold[][5] = {
  24. { 36.0, 37.0, 37.0, 37.0, 37.0 }, { 35.0, 36.0, 36.0, 36.0, 36.0 },
  25. { 34.0, 35.0, 35.0, 35.0, 35.0 }, { 33.0, 34.0, 34.0, 34.0, 34.0 },
  26. { 32.0, 33.0, 33.0, 33.0, 33.0 }, { 31.0, 32.0, 32.0, 32.0, 32.0 },
  27. { 30.0, 31.0, 31.0, 31.0, 31.0 }, { 29.0, 30.0, 30.0, 30.0, 30.0 },
  28. };
  29. typedef struct {
  30. const char *filename;
  31. unsigned int input_bit_depth;
  32. vpx_img_fmt fmt;
  33. vpx_bit_depth_t bit_depth;
  34. unsigned int profile;
  35. } TestVideoParam;
  36. const TestVideoParam kTestVectors[] = {
  37. { "park_joy_90p_8_420.y4m", 8, VPX_IMG_FMT_I420, VPX_BITS_8, 0 },
  38. { "park_joy_90p_8_422.y4m", 8, VPX_IMG_FMT_I422, VPX_BITS_8, 1 },
  39. { "park_joy_90p_8_444.y4m", 8, VPX_IMG_FMT_I444, VPX_BITS_8, 1 },
  40. { "park_joy_90p_8_440.yuv", 8, VPX_IMG_FMT_I440, VPX_BITS_8, 1 },
  41. #if CONFIG_VP9_HIGHBITDEPTH
  42. { "park_joy_90p_10_420.y4m", 10, VPX_IMG_FMT_I42016, VPX_BITS_10, 2 },
  43. { "park_joy_90p_10_422.y4m", 10, VPX_IMG_FMT_I42216, VPX_BITS_10, 3 },
  44. { "park_joy_90p_10_444.y4m", 10, VPX_IMG_FMT_I44416, VPX_BITS_10, 3 },
  45. { "park_joy_90p_10_440.yuv", 10, VPX_IMG_FMT_I44016, VPX_BITS_10, 3 },
  46. { "park_joy_90p_12_420.y4m", 12, VPX_IMG_FMT_I42016, VPX_BITS_12, 2 },
  47. { "park_joy_90p_12_422.y4m", 12, VPX_IMG_FMT_I42216, VPX_BITS_12, 3 },
  48. { "park_joy_90p_12_444.y4m", 12, VPX_IMG_FMT_I44416, VPX_BITS_12, 3 },
  49. { "park_joy_90p_12_440.yuv", 12, VPX_IMG_FMT_I44016, VPX_BITS_12, 3 },
  50. #endif // CONFIG_VP9_HIGHBITDEPTH
  51. };
  52. // Encoding modes tested
  53. const libvpx_test::TestMode kEncodingModeVectors[] = {
  54. ::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood,
  55. ::libvpx_test::kRealTime,
  56. };
  57. // Speed settings tested
  58. const int kCpuUsedVectors[] = { 1, 2, 3, 5, 6 };
  59. int is_extension_y4m(const char *filename) {
  60. const char *dot = strrchr(filename, '.');
  61. if (!dot || dot == filename) {
  62. return 0;
  63. } else {
  64. return !strcmp(dot, ".y4m");
  65. }
  66. }
  67. class EndToEndTestLarge
  68. : public ::libvpx_test::EncoderTest,
  69. public ::libvpx_test::CodecTestWith3Params<libvpx_test::TestMode,
  70. TestVideoParam, int> {
  71. protected:
  72. EndToEndTestLarge()
  73. : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(2)),
  74. cpu_used_(GET_PARAM(3)), psnr_(0.0), nframes_(0),
  75. encoding_mode_(GET_PARAM(1)) {}
  76. virtual ~EndToEndTestLarge() {}
  77. virtual void SetUp() {
  78. InitializeConfig();
  79. SetMode(encoding_mode_);
  80. if (encoding_mode_ != ::libvpx_test::kRealTime) {
  81. cfg_.g_lag_in_frames = 5;
  82. cfg_.rc_end_usage = VPX_VBR;
  83. } else {
  84. cfg_.g_lag_in_frames = 0;
  85. cfg_.rc_end_usage = VPX_CBR;
  86. cfg_.rc_buf_sz = 1000;
  87. cfg_.rc_buf_initial_sz = 500;
  88. cfg_.rc_buf_optimal_sz = 600;
  89. }
  90. dec_cfg_.threads = 4;
  91. }
  92. virtual void BeginPassHook(unsigned int) {
  93. psnr_ = 0.0;
  94. nframes_ = 0;
  95. }
  96. virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
  97. psnr_ += pkt->data.psnr.psnr[0];
  98. nframes_++;
  99. }
  100. virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
  101. ::libvpx_test::Encoder *encoder) {
  102. if (video->frame() == 1) {
  103. encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING, 1);
  104. encoder->Control(VP9E_SET_TILE_COLUMNS, 4);
  105. encoder->Control(VP8E_SET_CPUUSED, cpu_used_);
  106. if (encoding_mode_ != ::libvpx_test::kRealTime) {
  107. encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
  108. encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
  109. encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
  110. encoder->Control(VP8E_SET_ARNR_TYPE, 3);
  111. }
  112. }
  113. }
  114. double GetAveragePsnr() const {
  115. if (nframes_) return psnr_ / nframes_;
  116. return 0.0;
  117. }
  118. double GetPsnrThreshold() {
  119. return kPsnrThreshold[cpu_used_][encoding_mode_];
  120. }
  121. TestVideoParam test_video_param_;
  122. int cpu_used_;
  123. private:
  124. double psnr_;
  125. unsigned int nframes_;
  126. libvpx_test::TestMode encoding_mode_;
  127. };
  128. TEST_P(EndToEndTestLarge, EndtoEndPSNRTest) {
  129. cfg_.rc_target_bitrate = kBitrate;
  130. cfg_.g_error_resilient = 0;
  131. cfg_.g_profile = test_video_param_.profile;
  132. cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
  133. cfg_.g_bit_depth = test_video_param_.bit_depth;
  134. init_flags_ = VPX_CODEC_USE_PSNR;
  135. if (cfg_.g_bit_depth > 8) init_flags_ |= VPX_CODEC_USE_HIGHBITDEPTH;
  136. testing::internal::scoped_ptr<libvpx_test::VideoSource> video;
  137. if (is_extension_y4m(test_video_param_.filename)) {
  138. video.reset(new libvpx_test::Y4mVideoSource(test_video_param_.filename, 0,
  139. kFrames));
  140. } else {
  141. video.reset(new libvpx_test::YUVVideoSource(
  142. test_video_param_.filename, test_video_param_.fmt, kWidth, kHeight,
  143. kFramerate, 1, 0, kFrames));
  144. }
  145. ASSERT_TRUE(video.get() != NULL);
  146. ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
  147. const double psnr = GetAveragePsnr();
  148. EXPECT_GT(psnr, GetPsnrThreshold());
  149. }
  150. VP9_INSTANTIATE_TEST_CASE(EndToEndTestLarge,
  151. ::testing::ValuesIn(kEncodingModeVectors),
  152. ::testing::ValuesIn(kTestVectors),
  153. ::testing::ValuesIn(kCpuUsedVectors));
  154. } // namespace