vp9_lossless_test.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (c) 2013 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 "./vpx_config.h"
  12. #include "test/codec_factory.h"
  13. #include "test/encode_test_driver.h"
  14. #include "test/i420_video_source.h"
  15. #include "test/util.h"
  16. #include "test/y4m_video_source.h"
  17. namespace {
  18. const int kMaxPsnr = 100;
  19. class LosslessTest
  20. : public ::libvpx_test::EncoderTest,
  21. public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
  22. protected:
  23. LosslessTest()
  24. : EncoderTest(GET_PARAM(0)), psnr_(kMaxPsnr), nframes_(0),
  25. encoding_mode_(GET_PARAM(1)) {}
  26. virtual ~LosslessTest() {}
  27. virtual void SetUp() {
  28. InitializeConfig();
  29. SetMode(encoding_mode_);
  30. }
  31. virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
  32. ::libvpx_test::Encoder *encoder) {
  33. if (video->frame() == 0) {
  34. // Only call Control if quantizer > 0 to verify that using quantizer
  35. // alone will activate lossless
  36. if (cfg_.rc_max_quantizer > 0 || cfg_.rc_min_quantizer > 0) {
  37. encoder->Control(VP9E_SET_LOSSLESS, 1);
  38. }
  39. }
  40. }
  41. virtual void BeginPassHook(unsigned int /*pass*/) {
  42. psnr_ = kMaxPsnr;
  43. nframes_ = 0;
  44. }
  45. virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
  46. if (pkt->data.psnr.psnr[0] < psnr_) psnr_ = pkt->data.psnr.psnr[0];
  47. }
  48. double GetMinPsnr() const { return psnr_; }
  49. private:
  50. double psnr_;
  51. unsigned int nframes_;
  52. libvpx_test::TestMode encoding_mode_;
  53. };
  54. TEST_P(LosslessTest, TestLossLessEncoding) {
  55. const vpx_rational timebase = { 33333333, 1000000000 };
  56. cfg_.g_timebase = timebase;
  57. cfg_.rc_target_bitrate = 2000;
  58. cfg_.g_lag_in_frames = 25;
  59. cfg_.rc_min_quantizer = 0;
  60. cfg_.rc_max_quantizer = 0;
  61. init_flags_ = VPX_CODEC_USE_PSNR;
  62. // intentionally changed the dimension for better testing coverage
  63. libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
  64. timebase.den, timebase.num, 0, 10);
  65. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  66. const double psnr_lossless = GetMinPsnr();
  67. EXPECT_GE(psnr_lossless, kMaxPsnr);
  68. }
  69. TEST_P(LosslessTest, TestLossLessEncoding444) {
  70. libvpx_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 10);
  71. cfg_.g_profile = 1;
  72. cfg_.g_timebase = video.timebase();
  73. cfg_.rc_target_bitrate = 2000;
  74. cfg_.g_lag_in_frames = 25;
  75. cfg_.rc_min_quantizer = 0;
  76. cfg_.rc_max_quantizer = 0;
  77. init_flags_ = VPX_CODEC_USE_PSNR;
  78. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  79. const double psnr_lossless = GetMinPsnr();
  80. EXPECT_GE(psnr_lossless, kMaxPsnr);
  81. }
  82. TEST_P(LosslessTest, TestLossLessEncodingCtrl) {
  83. const vpx_rational timebase = { 33333333, 1000000000 };
  84. cfg_.g_timebase = timebase;
  85. cfg_.rc_target_bitrate = 2000;
  86. cfg_.g_lag_in_frames = 25;
  87. // Intentionally set Q > 0, to make sure control can be used to activate
  88. // lossless
  89. cfg_.rc_min_quantizer = 10;
  90. cfg_.rc_max_quantizer = 20;
  91. init_flags_ = VPX_CODEC_USE_PSNR;
  92. libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
  93. timebase.den, timebase.num, 0, 10);
  94. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  95. const double psnr_lossless = GetMinPsnr();
  96. EXPECT_GE(psnr_lossless, kMaxPsnr);
  97. }
  98. VP9_INSTANTIATE_TEST_CASE(LosslessTest,
  99. ::testing::Values(::libvpx_test::kRealTime,
  100. ::libvpx_test::kOnePassGood,
  101. ::libvpx_test::kTwoPassGood));
  102. } // namespace