[Unwrap] Migrate PacketArrivalHistory to RtpTimestampUnwrapper

Bug: webrtc:13982
Change-Id: Idd4905c1930d51efd0b9a5a1df1ad6001f9bc37c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/288941
Commit-Queue: Jakob Ivarsson‎ <jakobi@webrtc.org>
Auto-Submit: Evan Shrubsole <eshr@webrtc.org>
Reviewed-by: Jakob Ivarsson‎ <jakobi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39037}
This commit is contained in:
Evan Shrubsole 2023-01-09 10:22:22 +00:00 committed by WebRTC LUCI CQ
parent a1bb81e5c2
commit 224e390988
4 changed files with 23 additions and 7 deletions

View File

@ -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",

View File

@ -13,7 +13,6 @@
#include <algorithm>
#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_;
}

View File

@ -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<int64_t> newest_rtp_timestamp_;
int sample_rate_khz_ = 0;
};

View File

@ -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