[Unwrap] Migrate RtpToNtpEstimator to use RtpTimestampUnwrapper

Bug: webrtc:13982
Change-Id: Ib32b374237e19d10b3d36fe981939289c34dd6e8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/288965
Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
Auto-Submit: Evan Shrubsole <eshr@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39075}
diff --git a/system_wrappers/include/rtp_to_ntp_estimator.h b/system_wrappers/include/rtp_to_ntp_estimator.h
index 3b62b78..a5c7a15 100644
--- a/system_wrappers/include/rtp_to_ntp_estimator.h
+++ b/system_wrappers/include/rtp_to_ntp_estimator.h
@@ -16,8 +16,8 @@
 #include <list>
 
 #include "absl/types/optional.h"
-#include "modules/include/module_common_types_public.h"
 #include "rtc_base/checks.h"
+#include "rtc_base/numerics/sequence_number_unwrapper.h"
 #include "system_wrappers/include/ntp_time.h"
 
 namespace webrtc {
@@ -65,7 +65,7 @@
   int consecutive_invalid_samples_ = 0;
   std::list<RtcpMeasurement> measurements_;
   absl::optional<Parameters> params_;
-  mutable TimestampUnwrapper unwrapper_;
+  mutable RtpTimestampUnwrapper unwrapper_;
 };
 }  // namespace webrtc
 
diff --git a/system_wrappers/source/rtp_to_ntp_estimator_unittest.cc b/system_wrappers/source/rtp_to_ntp_estimator_unittest.cc
index 29de761..81effd9 100644
--- a/system_wrappers/source/rtp_to_ntp_estimator_unittest.cc
+++ b/system_wrappers/source/rtp_to_ntp_estimator_unittest.cc
@@ -48,6 +48,17 @@
             RtpToNtpEstimator::kInvalidMeasurement);
 }
 
+TEST(WrapAroundTests, OldRtcpWrapped_OldRtpTimestamp_NegativeWraparound) {
+  RtpToNtpEstimator estimator;
+  EXPECT_EQ(estimator.UpdateMeasurements(NtpTime(1), 0),
+            RtpToNtpEstimator::kNewMeasurement);
+  // Expected to fail since the older RTCP has a smaller RTP timestamp than the
+  // newer (old:0, new:-180).
+  EXPECT_EQ(estimator.UpdateMeasurements(NtpTime(1 + 2 * kOneMsInNtp),
+                                         0xFFFFFFFF - 2 * kTimestampTicksPerMs),
+            RtpToNtpEstimator::kInvalidMeasurement);
+}
+
 TEST(WrapAroundTests, NewRtcpWrapped) {
   RtpToNtpEstimator estimator;
   EXPECT_EQ(estimator.UpdateMeasurements(NtpTime(1), 0xFFFFFFFF),