Avoid negative timestamp in SourceTracker.

Bug: b/364184684
Change-Id: If03cd697fed05c24549b9ef80bbaf9f11b47d8bc
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/361640
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Commit-Queue: Jakob Ivarsson‎ <jakobi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42959}
This commit is contained in:
Jakob Ivarsson 2024-09-04 12:45:50 +00:00 committed by WebRTC LUCI CQ
parent 3047e6449a
commit 6255a7f3a0
2 changed files with 11 additions and 0 deletions

View File

@ -94,6 +94,9 @@ SourceTracker::SourceEntry& SourceTracker::UpdateEntry(const SourceKey& key) {
}
void SourceTracker::PruneEntries(Timestamp now) const {
if (now < Timestamp::Zero() + kTimeout) {
return;
}
Timestamp prune = now - kTimeout;
while (!list_.empty() && list_.back().second.timestamp < prune) {
map_.erase(list_.back().first);

View File

@ -535,4 +535,12 @@ TEST(SourceTrackerTest, TimedOutSourcesAreRemoved) {
kRtpTimestamp1, extensions1)));
}
TEST(SourceTrackerTest, AvoidNegativeTimestamp) {
SimulatedClock clock(Timestamp::Zero());
SourceTracker tracker(&clock);
tracker.OnFrameDelivered(RtpPacketInfos(
{RtpPacketInfo(/*ssrc=*/111, /*csrcs=*/{}, /*rtp_timestamp=*/0,
/*receive_time=*/Timestamp::Zero())}));
}
} // namespace webrtc