Migrate to Timestamp and TimeDelta types in RtpPacketHistory

Bug: webrtc:13757
Change-Id: Ie542fca50b97fe9dc450e45da40f05e2b66c7da5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/252981
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36132}
This commit is contained in:
Danil Chapovalov
2022-03-04 15:03:02 +01:00
committed by WebRTC LUCI CQ
parent fabc3a5aa7
commit a2ee9234b4
9 changed files with 173 additions and 167 deletions

View File

@ -201,7 +201,7 @@ void DEPRECATED_RtpSenderEgress::SendPacket(
// actual sending fails.
if (is_media && packet->allow_retransmission()) {
packet_history_->PutRtpPacket(std::make_unique<RtpPacketToSend>(*packet),
now_ms);
Timestamp::Millis(now_ms));
} else if (packet->retransmitted_sequence_number()) {
packet_history_->MarkPacketAsSent(*packet->retransmitted_sequence_number());
}

View File

@ -23,19 +23,13 @@
namespace webrtc {
constexpr size_t RtpPacketHistory::kMaxCapacity;
constexpr size_t RtpPacketHistory::kMaxPaddingHistory;
constexpr int64_t RtpPacketHistory::kMinPacketDurationMs;
constexpr int RtpPacketHistory::kMinPacketDurationRtt;
constexpr int RtpPacketHistory::kPacketCullingDelayFactor;
RtpPacketHistory::StoredPacket::StoredPacket(
std::unique_ptr<RtpPacketToSend> packet,
int64_t send_time_ms,
Timestamp send_time,
uint64_t insert_order)
: send_time_ms_(send_time_ms),
packet_(std::move(packet)),
: packet_(std::move(packet)),
pending_transmission_(false),
send_time_(send_time),
insert_order_(insert_order),
times_retransmitted_(0) {}
@ -78,7 +72,7 @@ RtpPacketHistory::RtpPacketHistory(Clock* clock, bool enable_padding_prio)
enable_padding_prio_(enable_padding_prio),
number_to_store_(0),
mode_(StorageMode::kDisabled),
rtt_ms_(-1),
rtt_(TimeDelta::MinusInfinity()),
packets_inserted_(0) {}
RtpPacketHistory::~RtpPacketHistory() {}
@ -100,29 +94,28 @@ RtpPacketHistory::StorageMode RtpPacketHistory::GetStorageMode() const {
return mode_;
}
void RtpPacketHistory::SetRtt(int64_t rtt_ms) {
void RtpPacketHistory::SetRtt(TimeDelta rtt) {
MutexLock lock(&lock_);
RTC_DCHECK_GE(rtt_ms, 0);
rtt_ms_ = rtt_ms;
RTC_DCHECK_GE(rtt, TimeDelta::Zero());
rtt_ = rtt;
// If storage is not disabled, packets will be removed after a timeout
// that depends on the RTT. Changing the RTT may thus cause some packets
// become "old" and subject to removal.
if (mode_ != StorageMode::kDisabled) {
CullOldPackets(clock_->TimeInMilliseconds());
CullOldPackets();
}
}
void RtpPacketHistory::PutRtpPacket(std::unique_ptr<RtpPacketToSend> packet,
int64_t send_time_ms) {
Timestamp send_time) {
RTC_DCHECK(packet);
MutexLock lock(&lock_);
int64_t now_ms = clock_->TimeInMilliseconds();
if (mode_ == StorageMode::kDisabled) {
return;
}
RTC_DCHECK(packet->allow_retransmission());
CullOldPackets(now_ms);
CullOldPackets();
// Store packet.
const uint16_t rtp_seq_no = packet->SequenceNumber();
@ -150,7 +143,7 @@ void RtpPacketHistory::PutRtpPacket(std::unique_ptr<RtpPacketToSend> packet,
RTC_DCHECK(packet_history_[packet_index].packet_ == nullptr);
packet_history_[packet_index] =
StoredPacket(std::move(packet), send_time_ms, packets_inserted_++);
StoredPacket(std::move(packet), send_time, packets_inserted_++);
if (enable_padding_prio_) {
if (padding_priority_.size() >= kMaxPaddingHistory - 1) {
@ -188,7 +181,7 @@ std::unique_ptr<RtpPacketToSend> RtpPacketHistory::GetPacketAndMarkAsPending(
return nullptr;
}
if (!VerifyRtt(*packet, clock_->TimeInMilliseconds())) {
if (!VerifyRtt(*packet)) {
// Packet already resent within too short a time window, ignore.
return nullptr;
}
@ -216,7 +209,7 @@ void RtpPacketHistory::MarkPacketAsSent(uint16_t sequence_number) {
// Update send-time, mark as no longer in pacer queue, and increment
// transmission count.
packet->send_time_ms_ = clock_->TimeInMilliseconds();
packet->set_send_time(clock_->CurrentTime());
packet->pending_transmission_ = false;
packet->IncrementTimesRetransmitted(enable_padding_prio_ ? &padding_priority_
: nullptr);
@ -238,17 +231,17 @@ bool RtpPacketHistory::GetPacketState(uint16_t sequence_number) const {
return false;
}
if (!VerifyRtt(packet, clock_->TimeInMilliseconds())) {
if (!VerifyRtt(packet)) {
return false;
}
return true;
}
bool RtpPacketHistory::VerifyRtt(const RtpPacketHistory::StoredPacket& packet,
int64_t now_ms) const {
bool RtpPacketHistory::VerifyRtt(
const RtpPacketHistory::StoredPacket& packet) const {
if (packet.times_retransmitted() > 0 &&
now_ms < packet.send_time_ms_ + rtt_ms_) {
clock_->CurrentTime() - packet.send_time() < rtt_) {
// This packet has already been retransmitted once, and the time since
// that even is lower than on RTT. Ignore request as this packet is
// likely already in the network pipe.
@ -305,7 +298,7 @@ std::unique_ptr<RtpPacketToSend> RtpPacketHistory::GetPayloadPaddingPacket(
return nullptr;
}
best_packet->send_time_ms_ = clock_->TimeInMilliseconds();
best_packet->set_send_time(clock_->CurrentTime());
best_packet->IncrementTimesRetransmitted(
enable_padding_prio_ ? &padding_priority_ : nullptr);
@ -335,9 +328,12 @@ void RtpPacketHistory::Reset() {
padding_priority_.clear();
}
void RtpPacketHistory::CullOldPackets(int64_t now_ms) {
int64_t packet_duration_ms =
std::max(kMinPacketDurationRtt * rtt_ms_, kMinPacketDurationMs);
void RtpPacketHistory::CullOldPackets() {
Timestamp now = clock_->CurrentTime();
TimeDelta packet_duration =
rtt_.IsFinite()
? std::max(kMinPacketDurationRtt * rtt_, kMinPacketDuration)
: kMinPacketDuration;
while (!packet_history_.empty()) {
if (packet_history_.size() >= kMaxCapacity) {
// We have reached the absolute max capacity, remove one packet
@ -352,15 +348,15 @@ void RtpPacketHistory::CullOldPackets(int64_t now_ms) {
return;
}
if (stored_packet.send_time_ms_ + packet_duration_ms > now_ms) {
if (stored_packet.send_time() + packet_duration > now) {
// Don't cull packets too early to avoid failed retransmission requests.
return;
}
if (packet_history_.size() >= number_to_store_ ||
stored_packet.send_time_ms_ +
(packet_duration_ms * kPacketCullingDelayFactor) <=
now_ms) {
stored_packet.send_time() +
(packet_duration * kPacketCullingDelayFactor) <=
now) {
// Too many packets in history, or this packet has timed out. Remove it
// and continue.
RemovePacket(0);

View File

@ -15,9 +15,13 @@
#include <map>
#include <memory>
#include <set>
#include <utility>
#include <vector>
#include "absl/base/attributes.h"
#include "api/function_view.h"
#include "api/units/time_delta.h"
#include "api/units/timestamp.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
@ -39,8 +43,8 @@ class RtpPacketHistory {
static constexpr size_t kMaxCapacity = 9600;
// Maximum number of entries in prioritized queue of padding packets.
static constexpr size_t kMaxPaddingHistory = 63;
// Don't remove packets within max(1000ms, 3x RTT).
static constexpr int64_t kMinPacketDurationMs = 1000;
// Don't remove packets within max(1 second, 3x RTT).
static constexpr TimeDelta kMinPacketDuration = TimeDelta::Seconds(1);
static constexpr int kMinPacketDurationRtt = 3;
// With kStoreAndCull, always remove packets after 3x max(1000ms, 3x rtt).
static constexpr int kPacketCullingDelayFactor = 3;
@ -60,10 +64,19 @@ class RtpPacketHistory {
// Set RTT, used to avoid premature retransmission and to prevent over-writing
// a packet in the history before we are reasonably sure it has been received.
void SetRtt(int64_t rtt_ms);
ABSL_DEPRECATED("Use SetRtt below that takes TimeDelta")
void SetRtt(int64_t rtt_ms) { SetRtt(TimeDelta::Millis(rtt_ms)); }
void SetRtt(TimeDelta rtt);
ABSL_DEPRECATED("Use PutRtpPacket below that take Timestamp")
void PutRtpPacket(std::unique_ptr<RtpPacketToSend> packet,
int64_t send_time_ms) {
PutRtpPacket(std::move(packet), Timestamp::Millis(send_time_ms));
}
void PutRtpPacket(std::unique_ptr<RtpPacketToSend> packet,
int64_t send_time_ms);
Timestamp send_time);
// Gets stored RTP packet corresponding to the input |sequence number|.
// Returns nullptr if packet is not found or was (re)sent too recently.
@ -120,7 +133,7 @@ class RtpPacketHistory {
public:
StoredPacket() = default;
StoredPacket(std::unique_ptr<RtpPacketToSend> packet,
int64_t send_time_ms,
Timestamp send_time,
uint64_t insert_order);
StoredPacket(StoredPacket&&);
StoredPacket& operator=(StoredPacket&&);
@ -131,7 +144,8 @@ class RtpPacketHistory {
void IncrementTimesRetransmitted(PacketPrioritySet* priority_set);
// The time of last transmission, including retransmissions.
int64_t send_time_ms_;
Timestamp send_time() const { return send_time_; }
void set_send_time(Timestamp value) { send_time_ = value; }
// The actual packet.
std::unique_ptr<RtpPacketToSend> packet_;
@ -140,6 +154,8 @@ class RtpPacketHistory {
bool pending_transmission_;
private:
Timestamp send_time_ = Timestamp::Zero();
// Unique number per StoredPacket, incremented by one for each added
// packet. Used to sort on insert order.
uint64_t insert_order_;
@ -152,10 +168,10 @@ class RtpPacketHistory {
};
// Helper method to check if packet has too recently been sent.
bool VerifyRtt(const StoredPacket& packet, int64_t now_ms) const
bool VerifyRtt(const StoredPacket& packet) const
RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_);
void Reset() RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_);
void CullOldPackets(int64_t now_ms) RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_);
void CullOldPackets() RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_);
// Removes the packet from the history, and context/mapping that has been
// stored. Returns the RTP packet instance contained within the StoredPacket.
std::unique_ptr<RtpPacketToSend> RemovePacket(int packet_index)
@ -170,7 +186,7 @@ class RtpPacketHistory {
mutable Mutex lock_;
size_t number_to_store_ RTC_GUARDED_BY(lock_);
StorageMode mode_ RTC_GUARDED_BY(lock_);
int64_t rtt_ms_ RTC_GUARDED_BY(lock_);
TimeDelta rtt_ RTC_GUARDED_BY(lock_);
// Queue of stored packets, ordered by sequence number, with older packets in
// the front and new packets being added to the back. Note that there may be

View File

@ -64,7 +64,7 @@ TEST_P(RtpPacketHistoryTest, SetStoreStatus) {
TEST_P(RtpPacketHistoryTest, ClearsHistoryAfterSetStoreStatus) {
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 10);
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
fake_clock_.TimeInMilliseconds());
/*send_time=*/fake_clock_.CurrentTime());
EXPECT_TRUE(hist_.GetPacketState(kStartSeqNum));
// Changing store status, even to the current one, will clear the history.
@ -75,7 +75,7 @@ TEST_P(RtpPacketHistoryTest, ClearsHistoryAfterSetStoreStatus) {
TEST_P(RtpPacketHistoryTest, StartSeqResetAfterReset) {
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 10);
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
fake_clock_.TimeInMilliseconds());
/*send_time=*/fake_clock_.CurrentTime());
// Mark packet as pending so it won't be removed.
EXPECT_TRUE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
@ -85,17 +85,16 @@ TEST_P(RtpPacketHistoryTest, StartSeqResetAfterReset) {
// Add a new packet.
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 1)),
fake_clock_.TimeInMilliseconds());
/*send_time=*/fake_clock_.CurrentTime());
EXPECT_TRUE(hist_.GetPacketAndMarkAsPending(To16u(kStartSeqNum + 1)));
// Advance time past where packet expires.
fake_clock_.AdvanceTimeMilliseconds(
RtpPacketHistory::kPacketCullingDelayFactor *
RtpPacketHistory::kMinPacketDurationMs);
fake_clock_.AdvanceTime(RtpPacketHistory::kPacketCullingDelayFactor *
RtpPacketHistory::kMinPacketDuration);
// Add one more packet and verify no state left from packet before reset.
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 2)),
fake_clock_.TimeInMilliseconds());
/*send_time=*/fake_clock_.CurrentTime());
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
EXPECT_TRUE(hist_.GetPacketState(To16u(kStartSeqNum + 1)));
EXPECT_TRUE(hist_.GetPacketState(To16u(kStartSeqNum + 2)));
@ -104,7 +103,8 @@ TEST_P(RtpPacketHistoryTest, StartSeqResetAfterReset) {
TEST_P(RtpPacketHistoryTest, NoStoreStatus) {
EXPECT_EQ(StorageMode::kDisabled, hist_.GetStorageMode());
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(std::move(packet),
/*send_time=*/fake_clock_.CurrentTime());
// Packet should not be stored.
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
}
@ -119,7 +119,8 @@ TEST_P(RtpPacketHistoryTest, PutRtpPacket) {
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(std::move(packet),
/*send_time=*/fake_clock_.CurrentTime());
EXPECT_TRUE(hist_.GetPacketState(kStartSeqNum));
}
@ -129,7 +130,8 @@ TEST_P(RtpPacketHistoryTest, GetRtpPacket) {
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
packet->set_capture_time(capture_time);
rtc::CopyOnWriteBuffer buffer = packet->Buffer();
hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(std::move(packet),
/*send_time=*/fake_clock_.CurrentTime());
std::unique_ptr<RtpPacketToSend> packet_out =
hist_.GetPacketAndMarkAsPending(kStartSeqNum);
@ -139,14 +141,14 @@ TEST_P(RtpPacketHistoryTest, GetRtpPacket) {
}
TEST_P(RtpPacketHistoryTest, MinResendTime) {
static const int64_t kMinRetransmitIntervalMs = 100;
static const TimeDelta kMinRetransmitInterval = TimeDelta::Millis(100);
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 10);
hist_.SetRtt(kMinRetransmitIntervalMs);
hist_.SetRtt(kMinRetransmitInterval);
Timestamp capture_time = fake_clock_.CurrentTime();
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
size_t len = packet->size();
hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(std::move(packet), fake_clock_.CurrentTime());
// First retransmission - allow early retransmission.
fake_clock_.AdvanceTimeMilliseconds(1);
@ -157,7 +159,7 @@ TEST_P(RtpPacketHistoryTest, MinResendTime) {
hist_.MarkPacketAsSent(kStartSeqNum);
// Second retransmission - advance time to just before retransmission OK.
fake_clock_.AdvanceTimeMilliseconds(kMinRetransmitIntervalMs - 1);
fake_clock_.AdvanceTime(kMinRetransmitInterval - TimeDelta::Millis(1));
EXPECT_FALSE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
// Advance time to just after retransmission OK.
@ -169,18 +171,18 @@ TEST_P(RtpPacketHistoryTest, RemovesOldestSentPacketWhenAtMaxSize) {
const size_t kMaxNumPackets = 10;
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, kMaxNumPackets);
// History does not allow removing packets within kMinPacketDurationMs,
// History does not allow removing packets within kMinPacketDuration,
// so in order to test capacity, make sure insertion spans this time.
const int64_t kPacketIntervalMs =
RtpPacketHistory::kMinPacketDurationMs / kMaxNumPackets;
const TimeDelta kPacketInterval =
RtpPacketHistory::kMinPacketDuration / kMaxNumPackets;
// Add packets until the buffer is full.
for (size_t i = 0; i < kMaxNumPackets; ++i) {
std::unique_ptr<RtpPacketToSend> packet =
CreateRtpPacket(To16u(kStartSeqNum + i));
// Immediate mark packet as sent.
hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMilliseconds());
fake_clock_.AdvanceTimeMilliseconds(kPacketIntervalMs);
hist_.PutRtpPacket(std::move(packet), fake_clock_.CurrentTime());
fake_clock_.AdvanceTime(kPacketInterval);
}
// First packet should still be there.
@ -189,7 +191,7 @@ TEST_P(RtpPacketHistoryTest, RemovesOldestSentPacketWhenAtMaxSize) {
// History is full, oldest one should be overwritten.
std::unique_ptr<RtpPacketToSend> packet =
CreateRtpPacket(To16u(kStartSeqNum + kMaxNumPackets));
hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(std::move(packet), fake_clock_.CurrentTime());
// Oldest packet should be gone, but packet after than one still present.
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
@ -207,7 +209,8 @@ TEST_P(RtpPacketHistoryTest, RemovesOldestPacketWhenAtMaxCapacity) {
for (size_t i = 0; i < kMaxNumPackets; ++i) {
std::unique_ptr<RtpPacketToSend> packet =
CreateRtpPacket(To16u(kStartSeqNum + i));
hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(std::move(packet),
/*send_time=*/fake_clock_.CurrentTime());
// Mark packets as pending, preventing it from being removed.
hist_.GetPacketAndMarkAsPending(To16u(kStartSeqNum + i));
}
@ -218,7 +221,7 @@ TEST_P(RtpPacketHistoryTest, RemovesOldestPacketWhenAtMaxCapacity) {
// History is full, oldest one should be overwritten.
std::unique_ptr<RtpPacketToSend> packet =
CreateRtpPacket(To16u(kStartSeqNum + kMaxNumPackets));
hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(std::move(packet), fake_clock_.CurrentTime());
// Oldest packet should be gone, but packet after than one still present.
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
@ -235,14 +238,14 @@ TEST_P(RtpPacketHistoryTest, RemovesLowestPrioPaddingWhenAtMaxCapacity) {
// set of potential padding packets.
const size_t kMaxNumPackets = RtpPacketHistory::kMaxPaddingHistory;
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, kMaxNumPackets * 2);
hist_.SetRtt(1);
hist_.SetRtt(TimeDelta::Millis(1));
// Add packets until the max is reached, and then yet another one.
for (size_t i = 0; i < kMaxNumPackets + 1; ++i) {
std::unique_ptr<RtpPacketToSend> packet =
CreateRtpPacket(To16u(kStartSeqNum + i));
// Don't mark packets as sent, preventing them from being removed.
hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(std::move(packet), fake_clock_.CurrentTime());
}
// Advance time to allow retransmission/padding.
@ -267,50 +270,48 @@ TEST_P(RtpPacketHistoryTest, DontRemoveTooRecentlyTransmittedPackets) {
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
// Add a packet, marked as send, and advance time to just before removal time.
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
fake_clock_.TimeInMilliseconds());
fake_clock_.AdvanceTimeMilliseconds(RtpPacketHistory::kMinPacketDurationMs -
1);
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
fake_clock_.AdvanceTime(RtpPacketHistory::kMinPacketDuration -
TimeDelta::Millis(1));
// Add a new packet to trigger culling.
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 1)),
fake_clock_.TimeInMilliseconds());
fake_clock_.CurrentTime());
// First packet should still be there.
EXPECT_TRUE(hist_.GetPacketState(kStartSeqNum));
// Advance time to where packet will be eligible for removal and try again.
fake_clock_.AdvanceTimeMilliseconds(1);
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 2)),
fake_clock_.TimeInMilliseconds());
fake_clock_.CurrentTime());
// First packet should no be gone, but next one still there.
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
EXPECT_TRUE(hist_.GetPacketState(To16u(kStartSeqNum + 1)));
}
TEST_P(RtpPacketHistoryTest, DontRemoveTooRecentlyTransmittedPacketsHighRtt) {
const int64_t kRttMs = RtpPacketHistory::kMinPacketDurationMs * 2;
const int64_t kPacketTimeoutMs =
kRttMs * RtpPacketHistory::kMinPacketDurationRtt;
const TimeDelta kRtt = RtpPacketHistory::kMinPacketDuration * 2;
const TimeDelta kPacketTimeout =
kRtt * RtpPacketHistory::kMinPacketDurationRtt;
// Set size to remove old packets as soon as possible.
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
hist_.SetRtt(kRttMs);
hist_.SetRtt(kRtt);
// Add a packet, marked as send, and advance time to just before removal time.
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
fake_clock_.TimeInMilliseconds());
fake_clock_.AdvanceTimeMilliseconds(kPacketTimeoutMs - 1);
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
fake_clock_.AdvanceTime(kPacketTimeout - TimeDelta::Millis(1));
// Add a new packet to trigger culling.
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 1)),
fake_clock_.TimeInMilliseconds());
fake_clock_.CurrentTime());
// First packet should still be there.
EXPECT_TRUE(hist_.GetPacketState(kStartSeqNum));
// Advance time to where packet will be eligible for removal and try again.
fake_clock_.AdvanceTimeMilliseconds(1);
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 2)),
fake_clock_.TimeInMilliseconds());
fake_clock_.CurrentTime());
// First packet should no be gone, but next one still there.
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
EXPECT_TRUE(hist_.GetPacketState(To16u(kStartSeqNum + 1)));
@ -321,12 +322,11 @@ TEST_P(RtpPacketHistoryTest, RemovesOldWithCulling) {
// Enable culling. Even without feedback, this can trigger early removal.
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, kMaxNumPackets);
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
int64_t kMaxPacketDurationMs = RtpPacketHistory::kMinPacketDurationMs *
TimeDelta kMaxPacketDuration = RtpPacketHistory::kMinPacketDuration *
RtpPacketHistory::kPacketCullingDelayFactor;
fake_clock_.AdvanceTimeMilliseconds(kMaxPacketDurationMs - 1);
fake_clock_.AdvanceTime(kMaxPacketDuration - TimeDelta::Millis(1));
// First packet should still be there.
EXPECT_TRUE(hist_.GetPacketState(kStartSeqNum));
@ -334,25 +334,24 @@ TEST_P(RtpPacketHistoryTest, RemovesOldWithCulling) {
// Advance to where packet can be culled, even if buffer is not full.
fake_clock_.AdvanceTimeMilliseconds(1);
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 1)),
fake_clock_.TimeInMilliseconds());
fake_clock_.CurrentTime());
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
}
TEST_P(RtpPacketHistoryTest, RemovesOldWithCullingHighRtt) {
const size_t kMaxNumPackets = 10;
const int64_t kRttMs = RtpPacketHistory::kMinPacketDurationMs * 2;
const TimeDelta kRtt = RtpPacketHistory::kMinPacketDuration * 2;
// Enable culling. Even without feedback, this can trigger early removal.
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, kMaxNumPackets);
hist_.SetRtt(kRttMs);
hist_.SetRtt(kRtt);
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
int64_t kMaxPacketDurationMs = kRttMs *
TimeDelta kMaxPacketDuration = kRtt *
RtpPacketHistory::kMinPacketDurationRtt *
RtpPacketHistory::kPacketCullingDelayFactor;
fake_clock_.AdvanceTimeMilliseconds(kMaxPacketDurationMs - 1);
fake_clock_.AdvanceTime(kMaxPacketDuration - TimeDelta::Millis(1));
// First packet should still be there.
EXPECT_TRUE(hist_.GetPacketState(kStartSeqNum));
@ -360,30 +359,33 @@ TEST_P(RtpPacketHistoryTest, RemovesOldWithCullingHighRtt) {
// Advance to where packet can be culled, even if buffer is not full.
fake_clock_.AdvanceTimeMilliseconds(1);
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 1)),
fake_clock_.TimeInMilliseconds());
fake_clock_.CurrentTime());
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
}
TEST_P(RtpPacketHistoryTest, CullWithAcks) {
const int64_t kPacketLifetime = RtpPacketHistory::kMinPacketDurationMs *
RtpPacketHistory::kPacketCullingDelayFactor;
const TimeDelta kPacketLifetime = RtpPacketHistory::kMinPacketDuration *
RtpPacketHistory::kPacketCullingDelayFactor;
const int64_t start_time = fake_clock_.TimeInMilliseconds();
const Timestamp start_time = fake_clock_.CurrentTime();
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 10);
// Insert three packets 33ms apart, immediately mark them as sent.
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
packet->SetPayloadSize(50);
hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(std::move(packet),
/*send_time=*/fake_clock_.CurrentTime());
fake_clock_.AdvanceTimeMilliseconds(33);
packet = CreateRtpPacket(To16u(kStartSeqNum + 1));
packet->SetPayloadSize(50);
hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(std::move(packet),
/*send_time=*/fake_clock_.CurrentTime());
fake_clock_.AdvanceTimeMilliseconds(33);
packet = CreateRtpPacket(To16u(kStartSeqNum + 2));
packet->SetPayloadSize(50);
hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(std::move(packet),
/*send_time=*/fake_clock_.CurrentTime());
EXPECT_TRUE(hist_.GetPacketState(kStartSeqNum));
EXPECT_TRUE(hist_.GetPacketState(To16u(kStartSeqNum + 1)));
@ -399,38 +401,38 @@ TEST_P(RtpPacketHistoryTest, CullWithAcks) {
// Advance time to where second packet would have expired, verify first packet
// is removed.
int64_t second_packet_expiry_time = start_time + kPacketLifetime + 33 + 1;
fake_clock_.AdvanceTimeMilliseconds(second_packet_expiry_time -
fake_clock_.TimeInMilliseconds());
hist_.SetRtt(1); // Trigger culling of old packets.
Timestamp second_packet_expiry_time =
start_time + kPacketLifetime + TimeDelta::Millis(33 + 1);
fake_clock_.AdvanceTime(second_packet_expiry_time -
fake_clock_.CurrentTime());
hist_.SetRtt(TimeDelta::Millis(1)); // Trigger culling of old packets.
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
EXPECT_FALSE(hist_.GetPacketState(To16u(kStartSeqNum + 1)));
EXPECT_TRUE(hist_.GetPacketState(To16u(kStartSeqNum + 2)));
// Advance to where last packet expires, verify all gone.
fake_clock_.AdvanceTimeMilliseconds(33);
hist_.SetRtt(1); // Trigger culling of old packets.
hist_.SetRtt(TimeDelta::Millis(1)); // Trigger culling of old packets.
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
EXPECT_FALSE(hist_.GetPacketState(To16u(kStartSeqNum + 1)));
EXPECT_FALSE(hist_.GetPacketState(To16u(kStartSeqNum + 2)));
}
TEST_P(RtpPacketHistoryTest, GetPacketAndSetSent) {
const int64_t kRttMs = RtpPacketHistory::kMinPacketDurationMs * 2;
hist_.SetRtt(kRttMs);
const TimeDelta kRtt = RtpPacketHistory::kMinPacketDuration * 2;
hist_.SetRtt(kRtt);
// Set size to remove old packets as soon as possible.
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
// Add a sent packet to the history.
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
fake_clock_.TimeInMicroseconds());
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
// Retransmission request, first retransmission is allowed immediately.
EXPECT_TRUE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
// Packet not yet sent, new retransmission not allowed.
fake_clock_.AdvanceTimeMilliseconds(kRttMs);
fake_clock_.AdvanceTime(kRtt);
EXPECT_FALSE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
// Mark as sent, but too early for retransmission.
@ -438,14 +440,14 @@ TEST_P(RtpPacketHistoryTest, GetPacketAndSetSent) {
EXPECT_FALSE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
// Enough time has passed, retransmission is allowed again.
fake_clock_.AdvanceTimeMilliseconds(kRttMs);
fake_clock_.AdvanceTime(kRtt);
EXPECT_TRUE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
}
TEST_P(RtpPacketHistoryTest, GetPacketWithEncapsulation) {
const uint32_t kSsrc = 92384762;
const int64_t kRttMs = RtpPacketHistory::kMinPacketDurationMs * 2;
hist_.SetRtt(kRttMs);
const TimeDelta kRtt = RtpPacketHistory::kMinPacketDuration * 2;
hist_.SetRtt(kRtt);
// Set size to remove old packets as soon as possible.
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
@ -453,7 +455,7 @@ TEST_P(RtpPacketHistoryTest, GetPacketWithEncapsulation) {
// Add a sent packet to the history, with a set SSRC.
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
packet->SetSsrc(kSsrc);
hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMicroseconds());
hist_.PutRtpPacket(std::move(packet), fake_clock_.CurrentTime());
// Retransmission request, simulate an RTX-like encapsulation, were the packet
// is sent on a different SSRC.
@ -472,8 +474,7 @@ TEST_P(RtpPacketHistoryTest, GetPacketWithEncapsulation) {
TEST_P(RtpPacketHistoryTest, GetPacketWithEncapsulationAbortOnNullptr) {
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
fake_clock_.TimeInMicroseconds());
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
// Retransmission request, but the encapsulator determines that this packet is
// not suitable for retransmission (bandwidth exhausted?) so the retransmit is
@ -487,20 +488,19 @@ TEST_P(RtpPacketHistoryTest, GetPacketWithEncapsulationAbortOnNullptr) {
}
TEST_P(RtpPacketHistoryTest, DontRemovePendingTransmissions) {
const int64_t kRttMs = RtpPacketHistory::kMinPacketDurationMs * 2;
const int64_t kPacketTimeoutMs =
kRttMs * RtpPacketHistory::kMinPacketDurationRtt;
const TimeDelta kRtt = RtpPacketHistory::kMinPacketDuration * 2;
const TimeDelta kPacketTimeout =
kRtt * RtpPacketHistory::kMinPacketDurationRtt;
// Set size to remove old packets as soon as possible.
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
hist_.SetRtt(kRttMs);
hist_.SetRtt(kRtt);
// Add a sent packet.
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
// Advance clock to just before packet timeout.
fake_clock_.AdvanceTimeMilliseconds(kPacketTimeoutMs - 1);
fake_clock_.AdvanceTime(kPacketTimeout - TimeDelta::Millis(1));
// Mark as enqueued in pacer.
EXPECT_TRUE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
@ -511,7 +511,7 @@ TEST_P(RtpPacketHistoryTest, DontRemovePendingTransmissions) {
// Packet sent. Now it can be removed.
hist_.MarkPacketAsSent(kStartSeqNum);
hist_.SetRtt(kRttMs); // Force culling of old packets.
hist_.SetRtt(kRtt); // Force culling of old packets.
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
}
@ -524,12 +524,11 @@ TEST_P(RtpPacketHistoryTest, PrioritizedPayloadPadding) {
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
// Add two sent packets, one millisecond apart.
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
fake_clock_.AdvanceTimeMilliseconds(1);
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum + 1),
fake_clock_.TimeInMilliseconds());
fake_clock_.CurrentTime());
fake_clock_.AdvanceTimeMilliseconds(1);
// Latest packet given equal retransmission count.
@ -560,8 +559,7 @@ TEST_P(RtpPacketHistoryTest, PrioritizedPayloadPadding) {
TEST_P(RtpPacketHistoryTest, NoPendingPacketAsPadding) {
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
fake_clock_.AdvanceTimeMilliseconds(1);
EXPECT_EQ(hist_.GetPayloadPaddingPacket()->SequenceNumber(), kStartSeqNum);
@ -578,8 +576,7 @@ TEST_P(RtpPacketHistoryTest, NoPendingPacketAsPadding) {
TEST_P(RtpPacketHistoryTest, PayloadPaddingWithEncapsulation) {
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
fake_clock_.AdvanceTimeMilliseconds(1);
// Aborted padding.
@ -600,10 +597,9 @@ TEST_P(RtpPacketHistoryTest, PayloadPaddingWithEncapsulation) {
TEST_P(RtpPacketHistoryTest, NackAfterAckIsNoop) {
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 2);
// Add two sent packets.
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum + 1),
fake_clock_.TimeInMilliseconds());
fake_clock_.CurrentTime());
// Remove newest one.
hist_.CullAcknowledgedPackets(std::vector<uint16_t>{kStartSeqNum + 1});
// Retransmission request for already acked packet, should be noop.
@ -622,7 +618,7 @@ TEST_P(RtpPacketHistoryTest, OutOfOrderInsertRemoval) {
uint16_t seq_no = To16u(kStartSeqNum + offset);
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(seq_no);
packet->SetPayloadSize(50);
hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMilliseconds());
hist_.PutRtpPacket(std::move(packet), fake_clock_.CurrentTime());
fake_clock_.AdvanceTimeMilliseconds(33);
}
@ -649,7 +645,7 @@ TEST_P(RtpPacketHistoryTest, UsesLastPacketAsPaddingWithPrioOff) {
for (size_t i = 0; i < kHistorySize; ++i) {
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + i)),
fake_clock_.TimeInMilliseconds());
fake_clock_.CurrentTime());
hist_.MarkPacketAsSent(To16u(kStartSeqNum + i));
fake_clock_.AdvanceTimeMilliseconds(1);

View File

@ -787,7 +787,7 @@ void ModuleRtpRtcpImpl::set_rtt_ms(int64_t rtt_ms) {
rtt_ms_ = rtt_ms;
}
if (rtp_sender_) {
rtp_sender_->packet_history.SetRtt(rtt_ms);
rtp_sender_->packet_history.SetRtt(TimeDelta::Millis(rtt_ms));
}
}

View File

@ -745,7 +745,7 @@ void ModuleRtpRtcpImpl2::set_rtt_ms(int64_t rtt_ms) {
rtt_ms_ = rtt_ms;
}
if (rtp_sender_) {
rtp_sender_->packet_history.SetRtt(rtt_ms);
rtp_sender_->packet_history.SetRtt(TimeDelta::Millis(rtt_ms));
}
}

View File

@ -354,7 +354,7 @@ void RTPSender::OnReceivedAckOnRtxSsrc(
void RTPSender::OnReceivedNack(
const std::vector<uint16_t>& nack_sequence_numbers,
int64_t avg_rtt) {
packet_history_->SetRtt(5 + avg_rtt);
packet_history_->SetRtt(TimeDelta::Millis(5 + avg_rtt));
for (uint16_t seq_no : nack_sequence_numbers) {
const int32_t bytes_sent = ReSendPacket(seq_no);
if (bytes_sent < 0) {

View File

@ -276,7 +276,7 @@ void RtpSenderEgress::SendPacket(RtpPacketToSend* packet,
// actual sending fails.
if (is_media && packet->allow_retransmission()) {
packet_history_->PutRtpPacket(std::make_unique<RtpPacketToSend>(*packet),
now_ms);
Timestamp::Millis(now_ms));
} else if (packet->retransmitted_sequence_number()) {
packet_history_->MarkPacketAsSent(*packet->retransmitted_sequence_number());
}

View File

@ -371,7 +371,7 @@ TEST_F(RtpSenderTest, ReSendPacketForwardsPacketsToPacer) {
auto packet = BuildRtpPacket(kPayload, kMarkerBit, kTimestamp, now_ms);
packet->SetSequenceNumber(kSeqNum);
packet->set_allow_retransmission(true);
packet_history_->PutRtpPacket(std::move(packet), now_ms);
packet_history_->PutRtpPacket(std::move(packet), Timestamp::Millis(now_ms));
EXPECT_CALL(mock_paced_sender_,
EnqueuePackets(ElementsAre(AllOf(
@ -571,7 +571,8 @@ TEST_F(RtpSenderTest, KeepsTimestampsOnPayloadPadding) {
Timestamp::Millis(start_time)))))));
std::unique_ptr<RtpPacketToSend> media_packet =
SendPacket(start_time, kPayloadSize);
packet_history_->PutRtpPacket(std::move(media_packet), start_time);
packet_history_->PutRtpPacket(std::move(media_packet),
Timestamp::Millis(start_time));
// Advance time before sending padding.
const TimeDelta kTimeDiff = TimeDelta::Millis(17);
@ -626,7 +627,7 @@ TEST_F(RtpSenderTest, RidIncludedOnRtxSentPackets) {
.WillOnce([&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
sequencer_->Sequence(*packets[0]);
packet_history_->PutRtpPacket(std::move(packets[0]),
clock_->TimeInMilliseconds());
clock_->CurrentTime());
});
SendGenericPacket();
@ -705,7 +706,7 @@ TEST_F(RtpSenderTest, MidAndRidIncludedOnFirstRtxPacket) {
EXPECT_CALL(mock_paced_sender_, EnqueuePackets(SizeIs(1)))
.WillOnce([&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
packet_history_->PutRtpPacket(std::move(packets[0]),
clock_->TimeInMilliseconds());
clock_->CurrentTime());
});
auto second_built_packet = SendGenericPacket();
@ -734,7 +735,7 @@ TEST_F(RtpSenderTest, MidAndRidNotIncludedOnRtxPacketsAfterAck) {
sequencer_->Sequence(*first_built_packet);
packet_history_->PutRtpPacket(
std::make_unique<RtpPacketToSend>(*first_built_packet),
/*send_time=*/clock_->TimeInMilliseconds());
/*send_time=*/clock_->CurrentTime());
rtp_sender_->OnReceivedAckOnSsrc(first_built_packet->SequenceNumber());
// The second packet will include neither since an ack was received.
@ -742,7 +743,7 @@ TEST_F(RtpSenderTest, MidAndRidNotIncludedOnRtxPacketsAfterAck) {
sequencer_->Sequence(*second_built_packet);
packet_history_->PutRtpPacket(
std::make_unique<RtpPacketToSend>(*second_built_packet),
/*send_time=*/clock_->TimeInMilliseconds());
/*send_time=*/clock_->CurrentTime());
// The first RTX packet will include MID and RRID.
EXPECT_CALL(mock_paced_sender_, EnqueuePackets(SizeIs(1)))
@ -782,7 +783,7 @@ TEST_F(RtpSenderTest, MidAndRidAlwaysIncludedOnRtxPacketsWhenConfigured) {
.WillRepeatedly(
[&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
packet_history_->PutRtpPacket(std::move(packets[0]),
clock_->TimeInMilliseconds());
clock_->CurrentTime());
});
auto media_packet1 = SendGenericPacket();
rtp_sender_->OnReceivedAckOnSsrc(media_packet1->SequenceNumber());
@ -850,7 +851,7 @@ TEST_F(RtpSenderTest, MidAndRridNotIncludedOnRtxPacketsAfterRtpStateRestored) {
EXPECT_CALL(mock_paced_sender_, EnqueuePackets(SizeIs(1)))
.WillOnce([&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
packet_history_->PutRtpPacket(std::move(packets[0]),
clock_->TimeInMilliseconds());
clock_->CurrentTime());
});
auto built_packet = SendGenericPacket();
@ -877,7 +878,7 @@ TEST_F(RtpSenderTest, RespectsNackBitrateLimit) {
sequencer_->Sequence(*packet);
sequence_numbers.push_back(packet->SequenceNumber());
packet_history_->PutRtpPacket(std::move(packet),
/*send_time=*/clock_->TimeInMilliseconds());
/*send_time=*/clock_->CurrentTime());
time_controller_.AdvanceTime(TimeDelta::Millis(1));
}
@ -994,8 +995,7 @@ TEST_F(RtpSenderTest, SendPacketHandlesRetransmissionHistory) {
BuildRtpPacket(kPayload, true, 0, clock_->TimeInMilliseconds());
const uint16_t media_sequence_number = packet->SequenceNumber();
packet->set_allow_retransmission(true);
packet_history_->PutRtpPacket(std::move(packet),
clock_->TimeInMilliseconds());
packet_history_->PutRtpPacket(std::move(packet), clock_->CurrentTime());
// Simulate successful retransmission request.
time_controller_.AdvanceTime(TimeDelta::Millis(30));
@ -1022,8 +1022,7 @@ TEST_F(RtpSenderTest, MarksRetransmittedPackets) {
BuildRtpPacket(kPayload, true, 0, clock_->TimeInMilliseconds());
const uint16_t media_sequence_number = packet->SequenceNumber();
packet->set_allow_retransmission(true);
packet_history_->PutRtpPacket(std::move(packet),
clock_->TimeInMilliseconds());
packet_history_->PutRtpPacket(std::move(packet), clock_->CurrentTime());
// Expect a retransmission packet marked with which packet it is a
// retransmit of.
@ -1055,8 +1054,7 @@ TEST_F(RtpSenderTest, GeneratedPaddingHasBweExtensions) {
packet->set_allow_retransmission(true);
packet->SetPayloadSize(kMinPaddingSize);
packet->set_packet_type(RtpPacketMediaType::kVideo);
packet_history_->PutRtpPacket(std::move(packet),
clock_->TimeInMilliseconds());
packet_history_->PutRtpPacket(std::move(packet), clock_->CurrentTime());
// Generate a plain padding packet, check that extensions are registered.
std::vector<std::unique_ptr<RtpPacketToSend>> generated_packets =
@ -1098,8 +1096,7 @@ TEST_F(RtpSenderTest, GeneratePaddingResendsOldPacketsWithRtx) {
packet->set_allow_retransmission(true);
packet->SetPayloadSize(kPayloadPacketSize);
packet->set_packet_type(RtpPacketMediaType::kVideo);
packet_history_->PutRtpPacket(std::move(packet),
clock_->TimeInMilliseconds());
packet_history_->PutRtpPacket(std::move(packet), clock_->CurrentTime());
// Generated padding has large enough budget that the video packet should be
// retransmitted as padding.
@ -1149,8 +1146,7 @@ TEST_F(RtpSenderTest, LimitsPayloadPaddingSize) {
packet->set_allow_retransmission(true);
packet->SetPayloadSize(kPayloadPacketSize);
packet->set_packet_type(RtpPacketMediaType::kVideo);
packet_history_->PutRtpPacket(std::move(packet),
clock_->TimeInMilliseconds());
packet_history_->PutRtpPacket(std::move(packet), clock_->CurrentTime());
// Smallest target size that will result in the sent packet being returned as
// padding.
@ -1191,8 +1187,7 @@ TEST_F(RtpSenderTest, GeneratePaddingCreatesPurePaddingWithoutRtx) {
packet->SetPayloadSize(kPayloadPacketSize);
packet->set_packet_type(RtpPacketMediaType::kVideo);
sequencer_->Sequence(*packet);
packet_history_->PutRtpPacket(std::move(packet),
clock_->TimeInMilliseconds());
packet_history_->PutRtpPacket(std::move(packet), clock_->CurrentTime());
// Payload padding not available without RTX, only generate plain padding on
// the media SSRC.
@ -1269,7 +1264,8 @@ TEST_F(RtpSenderTest, SetsCaptureTimeOnRtxRetransmissions) {
/*capture_time_ms=*/start_time_ms);
packet->set_allow_retransmission(true);
sequencer_->Sequence(*packet);
packet_history_->PutRtpPacket(std::move(packet), start_time_ms);
packet_history_->PutRtpPacket(std::move(packet),
Timestamp::Millis(start_time_ms));
// Advance time, request an RTX retransmission. Capture timestamp should be
// preserved.
@ -1283,7 +1279,7 @@ TEST_F(RtpSenderTest, SetsCaptureTimeOnRtxRetransmissions) {
}
TEST_F(RtpSenderTest, IgnoresNackAfterDisablingMedia) {
const int64_t kRtt = 10;
const TimeDelta kRtt = TimeDelta::Millis(10);
EnableRtx();
packet_history_->SetRtt(kRtt);
@ -1295,18 +1291,19 @@ TEST_F(RtpSenderTest, IgnoresNackAfterDisablingMedia) {
/*capture_time_ms=*/start_time_ms);
packet->set_allow_retransmission(true);
sequencer_->Sequence(*packet);
packet_history_->PutRtpPacket(std::move(packet), start_time_ms);
packet_history_->PutRtpPacket(std::move(packet),
Timestamp::Millis(start_time_ms));
// Disable media sending and try to retransmit the packet, it should fail.
rtp_sender_->SetSendingMediaStatus(false);
time_controller_.AdvanceTime(TimeDelta::Millis(kRtt));
time_controller_.AdvanceTime(kRtt);
EXPECT_LT(rtp_sender_->ReSendPacket(kSeqNum), 0);
}
TEST_F(RtpSenderTest, DoesntFecProtectRetransmissions) {
// Set up retranmission without RTX, so that a plain copy of the old packet is
// re-sent instead.
const int64_t kRtt = 10;
const TimeDelta kRtt = TimeDelta::Millis(10);
rtp_sender_->SetSendingMediaStatus(true);
rtp_sender_->SetRtxStatus(kRtxOff);
packet_history_->SetStorePacketsStatus(
@ -1321,7 +1318,8 @@ TEST_F(RtpSenderTest, DoesntFecProtectRetransmissions) {
packet->set_allow_retransmission(true);
packet->set_fec_protect_packet(true);
sequencer_->Sequence(*packet);
packet_history_->PutRtpPacket(std::move(packet), start_time_ms);
packet_history_->PutRtpPacket(std::move(packet),
Timestamp::Millis(start_time_ms));
// Re-send packet, the retransmitted packet should not have the FEC protection
// flag set.
@ -1329,7 +1327,7 @@ TEST_F(RtpSenderTest, DoesntFecProtectRetransmissions) {
EnqueuePackets(ElementsAre(Pointee(
Property(&RtpPacketToSend::fec_protect_packet, false)))));
time_controller_.AdvanceTime(TimeDelta::Millis(kRtt));
time_controller_.AdvanceTime(kRtt);
EXPECT_GT(rtp_sender_->ReSendPacket(kSeqNum), 0);
}