diff --git a/modules/video_coding/timing/BUILD.gn b/modules/video_coding/timing/BUILD.gn index fc2ea9fdd6..17dd42bbc9 100644 --- a/modules/video_coding/timing/BUILD.gn +++ b/modules/video_coding/timing/BUILD.gn @@ -94,6 +94,7 @@ rtc_library("timestamp_extrapolator") { deps = [ "../../../api/units:timestamp", "../../../modules:module_api_public", + "../../../rtc_base:rtc_numerics", ] absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } diff --git a/modules/video_coding/timing/timestamp_extrapolator.cc b/modules/video_coding/timing/timestamp_extrapolator.cc index d13fa7dd8c..c91aa1a362 100644 --- a/modules/video_coding/timing/timestamp_extrapolator.cc +++ b/modules/video_coding/timing/timestamp_extrapolator.cc @@ -13,7 +13,7 @@ #include #include "absl/types/optional.h" -#include "modules/include/module_common_types_public.h" +#include "rtc_base/numerics/sequence_number_unwrapper.h" namespace webrtc { @@ -47,7 +47,7 @@ void TimestampExtrapolator::Reset(Timestamp start) { p_[0][0] = 1; p_[1][1] = kP11; p_[0][1] = p_[1][0] = 0; - unwrapper_ = TimestampUnwrapper(); + unwrapper_ = RtpTimestampUnwrapper(); packet_count_ = 0; detector_accumulator_pos_ = 0; detector_accumulator_neg_ = 0; @@ -124,7 +124,7 @@ void TimestampExtrapolator::Update(Timestamp now, uint32_t ts90khz) { absl::optional TimestampExtrapolator::ExtrapolateLocalTime( uint32_t timestamp90khz) const { - int64_t unwrapped_ts90khz = unwrapper_.UnwrapWithoutUpdate(timestamp90khz); + int64_t unwrapped_ts90khz = unwrapper_.PeekUnwrap(timestamp90khz); if (!first_unwrapped_timestamp_) { return absl::nullopt; diff --git a/modules/video_coding/timing/timestamp_extrapolator.h b/modules/video_coding/timing/timestamp_extrapolator.h index b7162ed281..6a9763943e 100644 --- a/modules/video_coding/timing/timestamp_extrapolator.h +++ b/modules/video_coding/timing/timestamp_extrapolator.h @@ -15,7 +15,7 @@ #include "absl/types/optional.h" #include "api/units/timestamp.h" -#include "modules/include/module_common_types_public.h" +#include "rtc_base/numerics/sequence_number_unwrapper.h" namespace webrtc { @@ -36,7 +36,7 @@ class TimestampExtrapolator { Timestamp start_; Timestamp prev_; absl::optional first_unwrapped_timestamp_; - TimestampUnwrapper unwrapper_; + RtpTimestampUnwrapper unwrapper_; absl::optional prev_unwrapped_timestamp_; uint32_t packet_count_; double detector_accumulator_pos_; diff --git a/modules/video_coding/timing/timestamp_extrapolator_unittest.cc b/modules/video_coding/timing/timestamp_extrapolator_unittest.cc index bb24f92abd..0b5fd74a8e 100644 --- a/modules/video_coding/timing/timestamp_extrapolator_unittest.cc +++ b/modules/video_coding/timing/timestamp_extrapolator_unittest.cc @@ -120,6 +120,19 @@ TEST(TimestampExtrapolatorTest, TimestampExtrapolatesMultipleRtpWrapArounds) { } } +TEST(TimestampExtrapolatorTest, NegativeRtpTimestampWrapAround) { + SimulatedClock clock(Timestamp::Millis(1337)); + TimestampExtrapolator ts_extrapolator(clock.CurrentTime()); + uint32_t rtp = 0; + ts_extrapolator.Update(clock.CurrentTime(), rtp); + EXPECT_THAT(ts_extrapolator.ExtrapolateLocalTime(rtp), + Optional(clock.CurrentTime())); + // Go backwards! + rtp -= kRtpHz.hertz(); + EXPECT_THAT(ts_extrapolator.ExtrapolateLocalTime(rtp), + Optional(clock.CurrentTime() - TimeDelta::Seconds(1))); +} + TEST(TimestampExtrapolatorTest, Slow90KHzClock) { // This simulates a slow camera, which produces frames at 24Hz instead of // 25Hz. The extrapolator should be able to resolve this with enough data.