altref_test.cc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. namespace {
  16. #if CONFIG_VP8_ENCODER
  17. // lookahead range: [kLookAheadMin, kLookAheadMax).
  18. const int kLookAheadMin = 5;
  19. const int kLookAheadMax = 26;
  20. class AltRefTest : public ::libvpx_test::EncoderTest,
  21. public ::libvpx_test::CodecTestWithParam<int> {
  22. protected:
  23. AltRefTest() : EncoderTest(GET_PARAM(0)), altref_count_(0) {}
  24. virtual ~AltRefTest() {}
  25. virtual void SetUp() {
  26. InitializeConfig();
  27. SetMode(libvpx_test::kTwoPassGood);
  28. }
  29. virtual void BeginPassHook(unsigned int /*pass*/) { altref_count_ = 0; }
  30. virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video,
  31. libvpx_test::Encoder *encoder) {
  32. if (video->frame() == 0) {
  33. encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
  34. encoder->Control(VP8E_SET_CPUUSED, 3);
  35. }
  36. }
  37. virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
  38. if (pkt->data.frame.flags & VPX_FRAME_IS_INVISIBLE) ++altref_count_;
  39. }
  40. int altref_count() const { return altref_count_; }
  41. private:
  42. int altref_count_;
  43. };
  44. TEST_P(AltRefTest, MonotonicTimestamps) {
  45. const vpx_rational timebase = { 33333333, 1000000000 };
  46. cfg_.g_timebase = timebase;
  47. cfg_.rc_target_bitrate = 1000;
  48. cfg_.g_lag_in_frames = GET_PARAM(1);
  49. libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
  50. timebase.den, timebase.num, 0, 30);
  51. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  52. EXPECT_GE(altref_count(), 1);
  53. }
  54. VP8_INSTANTIATE_TEST_CASE(AltRefTest,
  55. ::testing::Range(kLookAheadMin, kLookAheadMax));
  56. #endif // CONFIG_VP8_ENCODER
  57. class AltRefForcedKeyTestLarge
  58. : public ::libvpx_test::EncoderTest,
  59. public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> {
  60. protected:
  61. AltRefForcedKeyTestLarge()
  62. : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
  63. cpu_used_(GET_PARAM(2)), forced_kf_frame_num_(1), frame_num_(0) {}
  64. virtual ~AltRefForcedKeyTestLarge() {}
  65. virtual void SetUp() {
  66. InitializeConfig();
  67. SetMode(encoding_mode_);
  68. cfg_.rc_end_usage = VPX_VBR;
  69. cfg_.g_threads = 0;
  70. }
  71. virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
  72. ::libvpx_test::Encoder *encoder) {
  73. if (video->frame() == 0) {
  74. encoder->Control(VP8E_SET_CPUUSED, cpu_used_);
  75. encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
  76. #if CONFIG_VP9_ENCODER
  77. // override test default for tile columns if necessary.
  78. if (GET_PARAM(0) == &libvpx_test::kVP9) {
  79. encoder->Control(VP9E_SET_TILE_COLUMNS, 6);
  80. }
  81. #endif
  82. }
  83. frame_flags_ =
  84. (video->frame() == forced_kf_frame_num_) ? VPX_EFLAG_FORCE_KF : 0;
  85. }
  86. virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
  87. if (frame_num_ == forced_kf_frame_num_) {
  88. ASSERT_TRUE(!!(pkt->data.frame.flags & VPX_FRAME_IS_KEY))
  89. << "Frame #" << frame_num_ << " isn't a keyframe!";
  90. }
  91. ++frame_num_;
  92. }
  93. ::libvpx_test::TestMode encoding_mode_;
  94. int cpu_used_;
  95. unsigned int forced_kf_frame_num_;
  96. unsigned int frame_num_;
  97. };
  98. TEST_P(AltRefForcedKeyTestLarge, Frame1IsKey) {
  99. const vpx_rational timebase = { 1, 30 };
  100. const int lag_values[] = { 3, 15, 25, -1 };
  101. forced_kf_frame_num_ = 1;
  102. for (int i = 0; lag_values[i] != -1; ++i) {
  103. frame_num_ = 0;
  104. cfg_.g_lag_in_frames = lag_values[i];
  105. libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
  106. timebase.den, timebase.num, 0, 30);
  107. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  108. }
  109. }
  110. TEST_P(AltRefForcedKeyTestLarge, ForcedFrameIsKey) {
  111. const vpx_rational timebase = { 1, 30 };
  112. const int lag_values[] = { 3, 15, 25, -1 };
  113. for (int i = 0; lag_values[i] != -1; ++i) {
  114. frame_num_ = 0;
  115. forced_kf_frame_num_ = lag_values[i] - 1;
  116. cfg_.g_lag_in_frames = lag_values[i];
  117. libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
  118. timebase.den, timebase.num, 0, 30);
  119. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  120. }
  121. }
  122. VP8_INSTANTIATE_TEST_CASE(AltRefForcedKeyTestLarge,
  123. ::testing::Values(::libvpx_test::kOnePassGood),
  124. ::testing::Range(0, 9));
  125. VP9_INSTANTIATE_TEST_CASE(AltRefForcedKeyTestLarge,
  126. ::testing::Values(::libvpx_test::kOnePassGood),
  127. ::testing::Range(0, 9));
  128. } // namespace