timestamp_test.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (c) 2019 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 "test/codec_factory.h"
  11. #include "test/encode_test_driver.h"
  12. #include "test/util.h"
  13. #include "test/video_source.h"
  14. #include "third_party/googletest/src/include/gtest/gtest.h"
  15. namespace {
  16. const int kVideoSourceWidth = 320;
  17. const int kVideoSourceHeight = 240;
  18. const int kFramesToEncode = 3;
  19. // A video source that exposes functions to set the timebase, framerate and
  20. // starting pts.
  21. class DummyTimebaseVideoSource : public ::libvpx_test::DummyVideoSource {
  22. public:
  23. // Parameters num and den set the timebase for the video source.
  24. DummyTimebaseVideoSource(int num, int den)
  25. : timebase_({ num, den }), framerate_numerator_(30),
  26. framerate_denominator_(1), starting_pts_(0) {
  27. SetSize(kVideoSourceWidth, kVideoSourceHeight);
  28. set_limit(kFramesToEncode);
  29. }
  30. void SetFramerate(int numerator, int denominator) {
  31. framerate_numerator_ = numerator;
  32. framerate_denominator_ = denominator;
  33. }
  34. // Returns one frames duration in timebase units as a double.
  35. double FrameDuration() const {
  36. return (static_cast<double>(timebase_.den) / timebase_.num) /
  37. (static_cast<double>(framerate_numerator_) / framerate_denominator_);
  38. }
  39. virtual vpx_codec_pts_t pts() const {
  40. return static_cast<vpx_codec_pts_t>(frame_ * FrameDuration() +
  41. starting_pts_ + 0.5);
  42. }
  43. virtual unsigned long duration() const {
  44. return static_cast<unsigned long>(FrameDuration() + 0.5);
  45. }
  46. virtual vpx_rational_t timebase() const { return timebase_; }
  47. void set_starting_pts(int64_t starting_pts) { starting_pts_ = starting_pts; }
  48. private:
  49. vpx_rational_t timebase_;
  50. int framerate_numerator_;
  51. int framerate_denominator_;
  52. int64_t starting_pts_;
  53. };
  54. class TimestampTest
  55. : public ::libvpx_test::EncoderTest,
  56. public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
  57. protected:
  58. TimestampTest() : EncoderTest(GET_PARAM(0)) {}
  59. virtual ~TimestampTest() {}
  60. virtual void SetUp() {
  61. InitializeConfig();
  62. SetMode(GET_PARAM(1));
  63. }
  64. };
  65. class TimestampTestVp9Only : public TimestampTest {};
  66. // Tests encoding in millisecond timebase.
  67. TEST_P(TimestampTest, EncodeFrames) {
  68. DummyTimebaseVideoSource video(1, 1000);
  69. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  70. }
  71. // TODO(fgalligan): Enable test when
  72. // https://bugs.chromium.org/p/webm/issues/detail?id=1614 is fixed.
  73. TEST_P(TimestampTest, DISABLED_TestMicrosecondTimebase) {
  74. // Set the timebase to microseconds.
  75. DummyTimebaseVideoSource video(1, 1000000);
  76. video.set_limit(1);
  77. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  78. }
  79. // TODO(webm:701): Enable VP8 test when the overflow issue in
  80. // TestVpxRollover is fixed.
  81. TEST_P(TimestampTestVp9Only, TestVpxRollover) {
  82. DummyTimebaseVideoSource video(1, 1000);
  83. video.set_starting_pts(922337170351ll);
  84. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  85. }
  86. VP8_INSTANTIATE_TEST_CASE(TimestampTest,
  87. ::testing::Values(::libvpx_test::kTwoPassGood));
  88. VP9_INSTANTIATE_TEST_CASE(TimestampTest,
  89. ::testing::Values(::libvpx_test::kTwoPassGood));
  90. VP9_INSTANTIATE_TEST_CASE(TimestampTestVp9Only,
  91. ::testing::Values(::libvpx_test::kTwoPassGood));
  92. } // namespace