diff --git a/modules/audio_coding/BUILD.gn b/modules/audio_coding/BUILD.gn index 38bff0228f..4f04b35d70 100644 --- a/modules/audio_coding/BUILD.gn +++ b/modules/audio_coding/BUILD.gn @@ -734,6 +734,7 @@ rtc_library("neteq") { "../../rtc_base:gtest_prod", "../../rtc_base:logging", "../../rtc_base:macromagic", + "../../rtc_base:rtc_numerics", "../../rtc_base:safe_conversions", "../../rtc_base:safe_minmax", "../../rtc_base:sanitizer", diff --git a/modules/audio_coding/neteq/packet_arrival_history.cc b/modules/audio_coding/neteq/packet_arrival_history.cc index 7196a6e393..2077383f76 100644 --- a/modules/audio_coding/neteq/packet_arrival_history.cc +++ b/modules/audio_coding/neteq/packet_arrival_history.cc @@ -13,7 +13,6 @@ #include #include "api/neteq/tick_timer.h" -#include "modules/include/module_common_types_public.h" namespace webrtc { @@ -62,7 +61,7 @@ void PacketArrivalHistory::Reset() { history_.clear(); min_packet_arrival_ = nullptr; max_packet_arrival_ = nullptr; - timestamp_unwrapper_ = TimestampUnwrapper(); + timestamp_unwrapper_.Reset(); newest_rtp_timestamp_ = absl::nullopt; } @@ -70,8 +69,7 @@ int PacketArrivalHistory::GetDelayMs(uint32_t rtp_timestamp, int64_t time_ms) const { RTC_DCHECK(sample_rate_khz_ > 0); int64_t unwrapped_rtp_timestamp_ms = - timestamp_unwrapper_.UnwrapWithoutUpdate(rtp_timestamp) / - sample_rate_khz_; + timestamp_unwrapper_.PeekUnwrap(rtp_timestamp) / sample_rate_khz_; PacketArrival packet(unwrapped_rtp_timestamp_ms, time_ms); return GetPacketArrivalDelayMs(packet); } @@ -88,7 +86,7 @@ bool PacketArrivalHistory::IsNewestRtpTimestamp(uint32_t rtp_timestamp) const { return false; } int64_t unwrapped_rtp_timestamp = - timestamp_unwrapper_.UnwrapWithoutUpdate(rtp_timestamp); + timestamp_unwrapper_.PeekUnwrap(rtp_timestamp); return unwrapped_rtp_timestamp == *newest_rtp_timestamp_; } diff --git a/modules/audio_coding/neteq/packet_arrival_history.h b/modules/audio_coding/neteq/packet_arrival_history.h index 79fc9176bc..cad362b469 100644 --- a/modules/audio_coding/neteq/packet_arrival_history.h +++ b/modules/audio_coding/neteq/packet_arrival_history.h @@ -16,7 +16,7 @@ #include "absl/types/optional.h" #include "api/neteq/tick_timer.h" -#include "modules/include/module_common_types_public.h" +#include "rtc_base/numerics/sequence_number_unwrapper.h" namespace webrtc { @@ -72,7 +72,7 @@ class PacketArrivalHistory { const PacketArrival* min_packet_arrival_ = nullptr; const PacketArrival* max_packet_arrival_ = nullptr; const int window_size_ms_; - TimestampUnwrapper timestamp_unwrapper_; + RtpTimestampUnwrapper timestamp_unwrapper_; absl::optional newest_rtp_timestamp_; int sample_rate_khz_ = 0; }; diff --git a/modules/audio_coding/neteq/packet_arrival_history_unittest.cc b/modules/audio_coding/neteq/packet_arrival_history_unittest.cc index 286a7acb2c..539a318fe1 100644 --- a/modules/audio_coding/neteq/packet_arrival_history_unittest.cc +++ b/modules/audio_coding/neteq/packet_arrival_history_unittest.cc @@ -120,5 +120,22 @@ TEST_F(PacketArrivalHistoryTest, TimestampWraparound) { EXPECT_EQ(history_.GetMaxDelayMs(), 3 * kFrameSizeMs); } +TEST_F(PacketArrivalHistoryTest, TimestampWraparoundBackwards) { + timestamp_ = 0; + EXPECT_EQ(InsertPacketAndGetDelay(0), 0); + + IncrementTime(2 * kFrameSizeMs); + // Insert timestamp that will wrap around. + EXPECT_EQ(InsertPacketAndGetDelay(kFrameSizeMs), kFrameSizeMs); + + // Insert reordered packet before the wraparound. + EXPECT_EQ(InsertPacketAndGetDelay(-2 * kFrameSizeMs), 3 * kFrameSizeMs); + + // Insert another in-order packet after the wraparound. + EXPECT_EQ(InsertPacketAndGetDelay(kFrameSizeMs), 0); + + EXPECT_EQ(history_.GetMaxDelayMs(), 3 * kFrameSizeMs); +} + } // namespace } // namespace webrtc