summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Galligan <fgalligan@google.com>2019-03-25 23:48:04 -0700
committerJames Zern <jzern@google.com>2019-04-04 17:53:42 +0000
commit65e5ba89b3c15c2fdbad35808bc91c1838754270 (patch)
tree59cd72af24fa1ff7106450fcc1d9d9331c6a0bb9
parent4117995a8ecef413849bdc51ddaa82c77f5967bd (diff)
downloadlibvpx-65e5ba89b3c15c2fdbad35808bc91c1838754270.tar
libvpx-65e5ba89b3c15c2fdbad35808bc91c1838754270.tar.gz
libvpx-65e5ba89b3c15c2fdbad35808bc91c1838754270.tar.bz2
libvpx-65e5ba89b3c15c2fdbad35808bc91c1838754270.zip
Add a test to test rollover of int64 in encoder interface.
The current libvpx encoder interface can potentially rollover an int64_t value used to calculate the current timestamp. If the timebase was set to microseconds and first timestamp was 0, then the rollover would occur in about 10.675 days. BUG=webm:701 Change-Id: I8d5aab46f8dcf250c1d4d43d5f3d27363c19cd54
-rw-r--r--test/test.mk1
-rw-r--r--test/timestamp_test.cc110
2 files changed, 111 insertions, 0 deletions
diff --git a/test/test.mk b/test/test.mk
index 61eb6060f..8ab4932ce 100644
--- a/test/test.mk
+++ b/test/test.mk
@@ -57,6 +57,7 @@ LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += svc_datarate_test.cc
LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += svc_test.cc
LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += svc_test.h
LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += svc_end_to_end_test.cc
+LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += timestamp_test.cc
LIBVPX_TEST_SRCS-yes += decode_test_driver.cc
LIBVPX_TEST_SRCS-yes += decode_test_driver.h
diff --git a/test/timestamp_test.cc b/test/timestamp_test.cc
new file mode 100644
index 000000000..987c8f04e
--- /dev/null
+++ b/test/timestamp_test.cc
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2019 The WebM project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "test/codec_factory.h"
+#include "test/encode_test_driver.h"
+#include "test/util.h"
+#include "test/video_source.h"
+#include "third_party/googletest/src/include/gtest/gtest.h"
+
+namespace {
+
+const int kVideoSourceWidth = 320;
+const int kVideoSourceHeight = 240;
+const int kFramesToEncode = 3;
+
+// A video source that exposes functions to set the timebase, framerate and
+// starting pts.
+class DummyTimebaseVideoSource : public ::libvpx_test::DummyVideoSource {
+ public:
+ // Parameters num and den set the timebase for the video source.
+ DummyTimebaseVideoSource(int num, int den)
+ : timebase_({ num, den }), framerate_numerator_(30),
+ framerate_denominator_(1), starting_pts_(0) {
+ SetSize(kVideoSourceWidth, kVideoSourceHeight);
+ set_limit(kFramesToEncode);
+ }
+
+ void SetFramerate(int numerator, int denominator) {
+ framerate_numerator_ = numerator;
+ framerate_denominator_ = denominator;
+ }
+
+ // Returns one frames duration in timebase units as a double.
+ double FrameDuration() const {
+ return (static_cast<double>(timebase_.den) / timebase_.num) /
+ (static_cast<double>(framerate_numerator_) / framerate_denominator_);
+ }
+
+ virtual vpx_codec_pts_t pts() const {
+ return static_cast<vpx_codec_pts_t>(frame_ * FrameDuration() +
+ starting_pts_ + 0.5);
+ }
+
+ virtual unsigned long duration() const {
+ return static_cast<unsigned long>(FrameDuration() + 0.5);
+ }
+
+ virtual vpx_rational_t timebase() const { return timebase_; }
+
+ void set_starting_pts(int64_t starting_pts) { starting_pts_ = starting_pts; }
+
+ private:
+ vpx_rational_t timebase_;
+ int framerate_numerator_;
+ int framerate_denominator_;
+ int64_t starting_pts_;
+};
+
+class TimestampTest
+ : public ::libvpx_test::EncoderTest,
+ public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
+ protected:
+ TimestampTest() : EncoderTest(GET_PARAM(0)) {}
+ virtual ~TimestampTest() {}
+
+ virtual void SetUp() {
+ InitializeConfig();
+ SetMode(GET_PARAM(1));
+ }
+};
+
+// Tests encoding in millisecond timebase.
+TEST_P(TimestampTest, EncodeFrames) {
+ DummyTimebaseVideoSource video(1, 1000);
+ ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
+}
+
+// TODO(fgalligan): Enable test when
+// https://bugs.chromium.org/p/webm/issues/detail?id=1614 is fixed.
+TEST_P(TimestampTest, DISABLED_TestMicrosecondTimebase) {
+ // Set the timebase to microseconds.
+ DummyTimebaseVideoSource video(1, 1000000);
+ video.set_limit(1);
+ ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
+}
+
+// TODO(fgalligan): Enable test when
+// https://bugs.chromium.org/p/webm/issues/detail?id=701 is fixed. Tests
+// rollover of int64_t value in libvpx encoder interface. The rollover happens
+// in the algorithm "(pts + duration) * 10000000 * ctx->cfg.g_timebase.num". In
+// this test the second frame will rollover an int64_t and the resulting
+// timestamp will become negative.
+TEST_P(TimestampTest, DISABLED_TestVpxRollover) {
+ DummyTimebaseVideoSource video(1, 1000);
+ video.set_starting_pts(922337170351ll);
+ ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
+}
+
+VP8_INSTANTIATE_TEST_CASE(TimestampTest,
+ ::testing::Values(::libvpx_test::kTwoPassGood));
+VP9_INSTANTIATE_TEST_CASE(TimestampTest,
+ ::testing::Values(::libvpx_test::kTwoPassGood));
+
+} // namespace