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:

committed by
WebRTC LUCI CQ

parent
fabc3a5aa7
commit
a2ee9234b4
@ -201,7 +201,7 @@ void DEPRECATED_RtpSenderEgress::SendPacket(
|
|||||||
// actual sending fails.
|
// actual sending fails.
|
||||||
if (is_media && packet->allow_retransmission()) {
|
if (is_media && packet->allow_retransmission()) {
|
||||||
packet_history_->PutRtpPacket(std::make_unique<RtpPacketToSend>(*packet),
|
packet_history_->PutRtpPacket(std::make_unique<RtpPacketToSend>(*packet),
|
||||||
now_ms);
|
Timestamp::Millis(now_ms));
|
||||||
} else if (packet->retransmitted_sequence_number()) {
|
} else if (packet->retransmitted_sequence_number()) {
|
||||||
packet_history_->MarkPacketAsSent(*packet->retransmitted_sequence_number());
|
packet_history_->MarkPacketAsSent(*packet->retransmitted_sequence_number());
|
||||||
}
|
}
|
||||||
|
@ -23,19 +23,13 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
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(
|
RtpPacketHistory::StoredPacket::StoredPacket(
|
||||||
std::unique_ptr<RtpPacketToSend> packet,
|
std::unique_ptr<RtpPacketToSend> packet,
|
||||||
int64_t send_time_ms,
|
Timestamp send_time,
|
||||||
uint64_t insert_order)
|
uint64_t insert_order)
|
||||||
: send_time_ms_(send_time_ms),
|
: packet_(std::move(packet)),
|
||||||
packet_(std::move(packet)),
|
|
||||||
pending_transmission_(false),
|
pending_transmission_(false),
|
||||||
|
send_time_(send_time),
|
||||||
insert_order_(insert_order),
|
insert_order_(insert_order),
|
||||||
times_retransmitted_(0) {}
|
times_retransmitted_(0) {}
|
||||||
|
|
||||||
@ -78,7 +72,7 @@ RtpPacketHistory::RtpPacketHistory(Clock* clock, bool enable_padding_prio)
|
|||||||
enable_padding_prio_(enable_padding_prio),
|
enable_padding_prio_(enable_padding_prio),
|
||||||
number_to_store_(0),
|
number_to_store_(0),
|
||||||
mode_(StorageMode::kDisabled),
|
mode_(StorageMode::kDisabled),
|
||||||
rtt_ms_(-1),
|
rtt_(TimeDelta::MinusInfinity()),
|
||||||
packets_inserted_(0) {}
|
packets_inserted_(0) {}
|
||||||
|
|
||||||
RtpPacketHistory::~RtpPacketHistory() {}
|
RtpPacketHistory::~RtpPacketHistory() {}
|
||||||
@ -100,29 +94,28 @@ RtpPacketHistory::StorageMode RtpPacketHistory::GetStorageMode() const {
|
|||||||
return mode_;
|
return mode_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtpPacketHistory::SetRtt(int64_t rtt_ms) {
|
void RtpPacketHistory::SetRtt(TimeDelta rtt) {
|
||||||
MutexLock lock(&lock_);
|
MutexLock lock(&lock_);
|
||||||
RTC_DCHECK_GE(rtt_ms, 0);
|
RTC_DCHECK_GE(rtt, TimeDelta::Zero());
|
||||||
rtt_ms_ = rtt_ms;
|
rtt_ = rtt;
|
||||||
// If storage is not disabled, packets will be removed after a timeout
|
// 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
|
// that depends on the RTT. Changing the RTT may thus cause some packets
|
||||||
// become "old" and subject to removal.
|
// become "old" and subject to removal.
|
||||||
if (mode_ != StorageMode::kDisabled) {
|
if (mode_ != StorageMode::kDisabled) {
|
||||||
CullOldPackets(clock_->TimeInMilliseconds());
|
CullOldPackets();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtpPacketHistory::PutRtpPacket(std::unique_ptr<RtpPacketToSend> packet,
|
void RtpPacketHistory::PutRtpPacket(std::unique_ptr<RtpPacketToSend> packet,
|
||||||
int64_t send_time_ms) {
|
Timestamp send_time) {
|
||||||
RTC_DCHECK(packet);
|
RTC_DCHECK(packet);
|
||||||
MutexLock lock(&lock_);
|
MutexLock lock(&lock_);
|
||||||
int64_t now_ms = clock_->TimeInMilliseconds();
|
|
||||||
if (mode_ == StorageMode::kDisabled) {
|
if (mode_ == StorageMode::kDisabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RTC_DCHECK(packet->allow_retransmission());
|
RTC_DCHECK(packet->allow_retransmission());
|
||||||
CullOldPackets(now_ms);
|
CullOldPackets();
|
||||||
|
|
||||||
// Store packet.
|
// Store packet.
|
||||||
const uint16_t rtp_seq_no = packet->SequenceNumber();
|
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);
|
RTC_DCHECK(packet_history_[packet_index].packet_ == nullptr);
|
||||||
|
|
||||||
packet_history_[packet_index] =
|
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 (enable_padding_prio_) {
|
||||||
if (padding_priority_.size() >= kMaxPaddingHistory - 1) {
|
if (padding_priority_.size() >= kMaxPaddingHistory - 1) {
|
||||||
@ -188,7 +181,7 @@ std::unique_ptr<RtpPacketToSend> RtpPacketHistory::GetPacketAndMarkAsPending(
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!VerifyRtt(*packet, clock_->TimeInMilliseconds())) {
|
if (!VerifyRtt(*packet)) {
|
||||||
// Packet already resent within too short a time window, ignore.
|
// Packet already resent within too short a time window, ignore.
|
||||||
return nullptr;
|
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
|
// Update send-time, mark as no longer in pacer queue, and increment
|
||||||
// transmission count.
|
// transmission count.
|
||||||
packet->send_time_ms_ = clock_->TimeInMilliseconds();
|
packet->set_send_time(clock_->CurrentTime());
|
||||||
packet->pending_transmission_ = false;
|
packet->pending_transmission_ = false;
|
||||||
packet->IncrementTimesRetransmitted(enable_padding_prio_ ? &padding_priority_
|
packet->IncrementTimesRetransmitted(enable_padding_prio_ ? &padding_priority_
|
||||||
: nullptr);
|
: nullptr);
|
||||||
@ -238,17 +231,17 @@ bool RtpPacketHistory::GetPacketState(uint16_t sequence_number) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!VerifyRtt(packet, clock_->TimeInMilliseconds())) {
|
if (!VerifyRtt(packet)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RtpPacketHistory::VerifyRtt(const RtpPacketHistory::StoredPacket& packet,
|
bool RtpPacketHistory::VerifyRtt(
|
||||||
int64_t now_ms) const {
|
const RtpPacketHistory::StoredPacket& packet) const {
|
||||||
if (packet.times_retransmitted() > 0 &&
|
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
|
// This packet has already been retransmitted once, and the time since
|
||||||
// that even is lower than on RTT. Ignore request as this packet is
|
// that even is lower than on RTT. Ignore request as this packet is
|
||||||
// likely already in the network pipe.
|
// likely already in the network pipe.
|
||||||
@ -305,7 +298,7 @@ std::unique_ptr<RtpPacketToSend> RtpPacketHistory::GetPayloadPaddingPacket(
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
best_packet->send_time_ms_ = clock_->TimeInMilliseconds();
|
best_packet->set_send_time(clock_->CurrentTime());
|
||||||
best_packet->IncrementTimesRetransmitted(
|
best_packet->IncrementTimesRetransmitted(
|
||||||
enable_padding_prio_ ? &padding_priority_ : nullptr);
|
enable_padding_prio_ ? &padding_priority_ : nullptr);
|
||||||
|
|
||||||
@ -335,9 +328,12 @@ void RtpPacketHistory::Reset() {
|
|||||||
padding_priority_.clear();
|
padding_priority_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtpPacketHistory::CullOldPackets(int64_t now_ms) {
|
void RtpPacketHistory::CullOldPackets() {
|
||||||
int64_t packet_duration_ms =
|
Timestamp now = clock_->CurrentTime();
|
||||||
std::max(kMinPacketDurationRtt * rtt_ms_, kMinPacketDurationMs);
|
TimeDelta packet_duration =
|
||||||
|
rtt_.IsFinite()
|
||||||
|
? std::max(kMinPacketDurationRtt * rtt_, kMinPacketDuration)
|
||||||
|
: kMinPacketDuration;
|
||||||
while (!packet_history_.empty()) {
|
while (!packet_history_.empty()) {
|
||||||
if (packet_history_.size() >= kMaxCapacity) {
|
if (packet_history_.size() >= kMaxCapacity) {
|
||||||
// We have reached the absolute max capacity, remove one packet
|
// We have reached the absolute max capacity, remove one packet
|
||||||
@ -352,15 +348,15 @@ void RtpPacketHistory::CullOldPackets(int64_t now_ms) {
|
|||||||
return;
|
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.
|
// Don't cull packets too early to avoid failed retransmission requests.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet_history_.size() >= number_to_store_ ||
|
if (packet_history_.size() >= number_to_store_ ||
|
||||||
stored_packet.send_time_ms_ +
|
stored_packet.send_time() +
|
||||||
(packet_duration_ms * kPacketCullingDelayFactor) <=
|
(packet_duration * kPacketCullingDelayFactor) <=
|
||||||
now_ms) {
|
now) {
|
||||||
// Too many packets in history, or this packet has timed out. Remove it
|
// Too many packets in history, or this packet has timed out. Remove it
|
||||||
// and continue.
|
// and continue.
|
||||||
RemovePacket(0);
|
RemovePacket(0);
|
||||||
|
@ -15,9 +15,13 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/base/attributes.h"
|
||||||
#include "api/function_view.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 "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
||||||
#include "rtc_base/synchronization/mutex.h"
|
#include "rtc_base/synchronization/mutex.h"
|
||||||
#include "rtc_base/thread_annotations.h"
|
#include "rtc_base/thread_annotations.h"
|
||||||
@ -39,8 +43,8 @@ class RtpPacketHistory {
|
|||||||
static constexpr size_t kMaxCapacity = 9600;
|
static constexpr size_t kMaxCapacity = 9600;
|
||||||
// Maximum number of entries in prioritized queue of padding packets.
|
// Maximum number of entries in prioritized queue of padding packets.
|
||||||
static constexpr size_t kMaxPaddingHistory = 63;
|
static constexpr size_t kMaxPaddingHistory = 63;
|
||||||
// Don't remove packets within max(1000ms, 3x RTT).
|
// Don't remove packets within max(1 second, 3x RTT).
|
||||||
static constexpr int64_t kMinPacketDurationMs = 1000;
|
static constexpr TimeDelta kMinPacketDuration = TimeDelta::Seconds(1);
|
||||||
static constexpr int kMinPacketDurationRtt = 3;
|
static constexpr int kMinPacketDurationRtt = 3;
|
||||||
// With kStoreAndCull, always remove packets after 3x max(1000ms, 3x rtt).
|
// With kStoreAndCull, always remove packets after 3x max(1000ms, 3x rtt).
|
||||||
static constexpr int kPacketCullingDelayFactor = 3;
|
static constexpr int kPacketCullingDelayFactor = 3;
|
||||||
@ -60,10 +64,19 @@ class RtpPacketHistory {
|
|||||||
|
|
||||||
// Set RTT, used to avoid premature retransmission and to prevent over-writing
|
// 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.
|
// 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,
|
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|.
|
// Gets stored RTP packet corresponding to the input |sequence number|.
|
||||||
// Returns nullptr if packet is not found or was (re)sent too recently.
|
// Returns nullptr if packet is not found or was (re)sent too recently.
|
||||||
@ -120,7 +133,7 @@ class RtpPacketHistory {
|
|||||||
public:
|
public:
|
||||||
StoredPacket() = default;
|
StoredPacket() = default;
|
||||||
StoredPacket(std::unique_ptr<RtpPacketToSend> packet,
|
StoredPacket(std::unique_ptr<RtpPacketToSend> packet,
|
||||||
int64_t send_time_ms,
|
Timestamp send_time,
|
||||||
uint64_t insert_order);
|
uint64_t insert_order);
|
||||||
StoredPacket(StoredPacket&&);
|
StoredPacket(StoredPacket&&);
|
||||||
StoredPacket& operator=(StoredPacket&&);
|
StoredPacket& operator=(StoredPacket&&);
|
||||||
@ -131,7 +144,8 @@ class RtpPacketHistory {
|
|||||||
void IncrementTimesRetransmitted(PacketPrioritySet* priority_set);
|
void IncrementTimesRetransmitted(PacketPrioritySet* priority_set);
|
||||||
|
|
||||||
// The time of last transmission, including retransmissions.
|
// 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.
|
// The actual packet.
|
||||||
std::unique_ptr<RtpPacketToSend> packet_;
|
std::unique_ptr<RtpPacketToSend> packet_;
|
||||||
@ -140,6 +154,8 @@ class RtpPacketHistory {
|
|||||||
bool pending_transmission_;
|
bool pending_transmission_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Timestamp send_time_ = Timestamp::Zero();
|
||||||
|
|
||||||
// Unique number per StoredPacket, incremented by one for each added
|
// Unique number per StoredPacket, incremented by one for each added
|
||||||
// packet. Used to sort on insert order.
|
// packet. Used to sort on insert order.
|
||||||
uint64_t insert_order_;
|
uint64_t insert_order_;
|
||||||
@ -152,10 +168,10 @@ class RtpPacketHistory {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Helper method to check if packet has too recently been sent.
|
// 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_);
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_);
|
||||||
void Reset() 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
|
// Removes the packet from the history, and context/mapping that has been
|
||||||
// stored. Returns the RTP packet instance contained within the StoredPacket.
|
// stored. Returns the RTP packet instance contained within the StoredPacket.
|
||||||
std::unique_ptr<RtpPacketToSend> RemovePacket(int packet_index)
|
std::unique_ptr<RtpPacketToSend> RemovePacket(int packet_index)
|
||||||
@ -170,7 +186,7 @@ class RtpPacketHistory {
|
|||||||
mutable Mutex lock_;
|
mutable Mutex lock_;
|
||||||
size_t number_to_store_ RTC_GUARDED_BY(lock_);
|
size_t number_to_store_ RTC_GUARDED_BY(lock_);
|
||||||
StorageMode mode_ 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
|
// 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
|
// the front and new packets being added to the back. Note that there may be
|
||||||
|
@ -64,7 +64,7 @@ TEST_P(RtpPacketHistoryTest, SetStoreStatus) {
|
|||||||
TEST_P(RtpPacketHistoryTest, ClearsHistoryAfterSetStoreStatus) {
|
TEST_P(RtpPacketHistoryTest, ClearsHistoryAfterSetStoreStatus) {
|
||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 10);
|
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 10);
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
|
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
|
||||||
fake_clock_.TimeInMilliseconds());
|
/*send_time=*/fake_clock_.CurrentTime());
|
||||||
EXPECT_TRUE(hist_.GetPacketState(kStartSeqNum));
|
EXPECT_TRUE(hist_.GetPacketState(kStartSeqNum));
|
||||||
|
|
||||||
// Changing store status, even to the current one, will clear the history.
|
// Changing store status, even to the current one, will clear the history.
|
||||||
@ -75,7 +75,7 @@ TEST_P(RtpPacketHistoryTest, ClearsHistoryAfterSetStoreStatus) {
|
|||||||
TEST_P(RtpPacketHistoryTest, StartSeqResetAfterReset) {
|
TEST_P(RtpPacketHistoryTest, StartSeqResetAfterReset) {
|
||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 10);
|
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 10);
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
|
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
|
||||||
fake_clock_.TimeInMilliseconds());
|
/*send_time=*/fake_clock_.CurrentTime());
|
||||||
// Mark packet as pending so it won't be removed.
|
// Mark packet as pending so it won't be removed.
|
||||||
EXPECT_TRUE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
|
EXPECT_TRUE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
|
||||||
|
|
||||||
@ -85,17 +85,16 @@ TEST_P(RtpPacketHistoryTest, StartSeqResetAfterReset) {
|
|||||||
|
|
||||||
// Add a new packet.
|
// Add a new packet.
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 1)),
|
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 1)),
|
||||||
fake_clock_.TimeInMilliseconds());
|
/*send_time=*/fake_clock_.CurrentTime());
|
||||||
EXPECT_TRUE(hist_.GetPacketAndMarkAsPending(To16u(kStartSeqNum + 1)));
|
EXPECT_TRUE(hist_.GetPacketAndMarkAsPending(To16u(kStartSeqNum + 1)));
|
||||||
|
|
||||||
// Advance time past where packet expires.
|
// Advance time past where packet expires.
|
||||||
fake_clock_.AdvanceTimeMilliseconds(
|
fake_clock_.AdvanceTime(RtpPacketHistory::kPacketCullingDelayFactor *
|
||||||
RtpPacketHistory::kPacketCullingDelayFactor *
|
RtpPacketHistory::kMinPacketDuration);
|
||||||
RtpPacketHistory::kMinPacketDurationMs);
|
|
||||||
|
|
||||||
// Add one more packet and verify no state left from packet before reset.
|
// Add one more packet and verify no state left from packet before reset.
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 2)),
|
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 2)),
|
||||||
fake_clock_.TimeInMilliseconds());
|
/*send_time=*/fake_clock_.CurrentTime());
|
||||||
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
||||||
EXPECT_TRUE(hist_.GetPacketState(To16u(kStartSeqNum + 1)));
|
EXPECT_TRUE(hist_.GetPacketState(To16u(kStartSeqNum + 1)));
|
||||||
EXPECT_TRUE(hist_.GetPacketState(To16u(kStartSeqNum + 2)));
|
EXPECT_TRUE(hist_.GetPacketState(To16u(kStartSeqNum + 2)));
|
||||||
@ -104,7 +103,8 @@ TEST_P(RtpPacketHistoryTest, StartSeqResetAfterReset) {
|
|||||||
TEST_P(RtpPacketHistoryTest, NoStoreStatus) {
|
TEST_P(RtpPacketHistoryTest, NoStoreStatus) {
|
||||||
EXPECT_EQ(StorageMode::kDisabled, hist_.GetStorageMode());
|
EXPECT_EQ(StorageMode::kDisabled, hist_.GetStorageMode());
|
||||||
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
|
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.
|
// Packet should not be stored.
|
||||||
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
||||||
}
|
}
|
||||||
@ -119,7 +119,8 @@ TEST_P(RtpPacketHistoryTest, PutRtpPacket) {
|
|||||||
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
|
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
|
||||||
|
|
||||||
EXPECT_FALSE(hist_.GetPacketState(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));
|
EXPECT_TRUE(hist_.GetPacketState(kStartSeqNum));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +130,8 @@ TEST_P(RtpPacketHistoryTest, GetRtpPacket) {
|
|||||||
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
|
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
|
||||||
packet->set_capture_time(capture_time);
|
packet->set_capture_time(capture_time);
|
||||||
rtc::CopyOnWriteBuffer buffer = packet->Buffer();
|
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 =
|
std::unique_ptr<RtpPacketToSend> packet_out =
|
||||||
hist_.GetPacketAndMarkAsPending(kStartSeqNum);
|
hist_.GetPacketAndMarkAsPending(kStartSeqNum);
|
||||||
@ -139,14 +141,14 @@ TEST_P(RtpPacketHistoryTest, GetRtpPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(RtpPacketHistoryTest, MinResendTime) {
|
TEST_P(RtpPacketHistoryTest, MinResendTime) {
|
||||||
static const int64_t kMinRetransmitIntervalMs = 100;
|
static const TimeDelta kMinRetransmitInterval = TimeDelta::Millis(100);
|
||||||
|
|
||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 10);
|
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 10);
|
||||||
hist_.SetRtt(kMinRetransmitIntervalMs);
|
hist_.SetRtt(kMinRetransmitInterval);
|
||||||
Timestamp capture_time = fake_clock_.CurrentTime();
|
Timestamp capture_time = fake_clock_.CurrentTime();
|
||||||
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
|
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
|
||||||
size_t len = packet->size();
|
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.
|
// First retransmission - allow early retransmission.
|
||||||
fake_clock_.AdvanceTimeMilliseconds(1);
|
fake_clock_.AdvanceTimeMilliseconds(1);
|
||||||
@ -157,7 +159,7 @@ TEST_P(RtpPacketHistoryTest, MinResendTime) {
|
|||||||
hist_.MarkPacketAsSent(kStartSeqNum);
|
hist_.MarkPacketAsSent(kStartSeqNum);
|
||||||
|
|
||||||
// Second retransmission - advance time to just before retransmission OK.
|
// 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));
|
EXPECT_FALSE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
|
||||||
|
|
||||||
// Advance time to just after retransmission OK.
|
// Advance time to just after retransmission OK.
|
||||||
@ -169,18 +171,18 @@ TEST_P(RtpPacketHistoryTest, RemovesOldestSentPacketWhenAtMaxSize) {
|
|||||||
const size_t kMaxNumPackets = 10;
|
const size_t kMaxNumPackets = 10;
|
||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, kMaxNumPackets);
|
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.
|
// so in order to test capacity, make sure insertion spans this time.
|
||||||
const int64_t kPacketIntervalMs =
|
const TimeDelta kPacketInterval =
|
||||||
RtpPacketHistory::kMinPacketDurationMs / kMaxNumPackets;
|
RtpPacketHistory::kMinPacketDuration / kMaxNumPackets;
|
||||||
|
|
||||||
// Add packets until the buffer is full.
|
// Add packets until the buffer is full.
|
||||||
for (size_t i = 0; i < kMaxNumPackets; ++i) {
|
for (size_t i = 0; i < kMaxNumPackets; ++i) {
|
||||||
std::unique_ptr<RtpPacketToSend> packet =
|
std::unique_ptr<RtpPacketToSend> packet =
|
||||||
CreateRtpPacket(To16u(kStartSeqNum + i));
|
CreateRtpPacket(To16u(kStartSeqNum + i));
|
||||||
// Immediate mark packet as sent.
|
// Immediate mark packet as sent.
|
||||||
hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMilliseconds());
|
hist_.PutRtpPacket(std::move(packet), fake_clock_.CurrentTime());
|
||||||
fake_clock_.AdvanceTimeMilliseconds(kPacketIntervalMs);
|
fake_clock_.AdvanceTime(kPacketInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
// First packet should still be there.
|
// First packet should still be there.
|
||||||
@ -189,7 +191,7 @@ TEST_P(RtpPacketHistoryTest, RemovesOldestSentPacketWhenAtMaxSize) {
|
|||||||
// History is full, oldest one should be overwritten.
|
// History is full, oldest one should be overwritten.
|
||||||
std::unique_ptr<RtpPacketToSend> packet =
|
std::unique_ptr<RtpPacketToSend> packet =
|
||||||
CreateRtpPacket(To16u(kStartSeqNum + kMaxNumPackets));
|
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.
|
// Oldest packet should be gone, but packet after than one still present.
|
||||||
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
||||||
@ -207,7 +209,8 @@ TEST_P(RtpPacketHistoryTest, RemovesOldestPacketWhenAtMaxCapacity) {
|
|||||||
for (size_t i = 0; i < kMaxNumPackets; ++i) {
|
for (size_t i = 0; i < kMaxNumPackets; ++i) {
|
||||||
std::unique_ptr<RtpPacketToSend> packet =
|
std::unique_ptr<RtpPacketToSend> packet =
|
||||||
CreateRtpPacket(To16u(kStartSeqNum + i));
|
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.
|
// Mark packets as pending, preventing it from being removed.
|
||||||
hist_.GetPacketAndMarkAsPending(To16u(kStartSeqNum + i));
|
hist_.GetPacketAndMarkAsPending(To16u(kStartSeqNum + i));
|
||||||
}
|
}
|
||||||
@ -218,7 +221,7 @@ TEST_P(RtpPacketHistoryTest, RemovesOldestPacketWhenAtMaxCapacity) {
|
|||||||
// History is full, oldest one should be overwritten.
|
// History is full, oldest one should be overwritten.
|
||||||
std::unique_ptr<RtpPacketToSend> packet =
|
std::unique_ptr<RtpPacketToSend> packet =
|
||||||
CreateRtpPacket(To16u(kStartSeqNum + kMaxNumPackets));
|
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.
|
// Oldest packet should be gone, but packet after than one still present.
|
||||||
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
||||||
@ -235,14 +238,14 @@ TEST_P(RtpPacketHistoryTest, RemovesLowestPrioPaddingWhenAtMaxCapacity) {
|
|||||||
// set of potential padding packets.
|
// set of potential padding packets.
|
||||||
const size_t kMaxNumPackets = RtpPacketHistory::kMaxPaddingHistory;
|
const size_t kMaxNumPackets = RtpPacketHistory::kMaxPaddingHistory;
|
||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, kMaxNumPackets * 2);
|
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.
|
// Add packets until the max is reached, and then yet another one.
|
||||||
for (size_t i = 0; i < kMaxNumPackets + 1; ++i) {
|
for (size_t i = 0; i < kMaxNumPackets + 1; ++i) {
|
||||||
std::unique_ptr<RtpPacketToSend> packet =
|
std::unique_ptr<RtpPacketToSend> packet =
|
||||||
CreateRtpPacket(To16u(kStartSeqNum + i));
|
CreateRtpPacket(To16u(kStartSeqNum + i));
|
||||||
// Don't mark packets as sent, preventing them from being removed.
|
// 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.
|
// Advance time to allow retransmission/padding.
|
||||||
@ -267,50 +270,48 @@ TEST_P(RtpPacketHistoryTest, DontRemoveTooRecentlyTransmittedPackets) {
|
|||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
||||||
|
|
||||||
// Add a packet, marked as send, and advance time to just before removal time.
|
// Add a packet, marked as send, and advance time to just before removal time.
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
|
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
|
||||||
fake_clock_.TimeInMilliseconds());
|
fake_clock_.AdvanceTime(RtpPacketHistory::kMinPacketDuration -
|
||||||
fake_clock_.AdvanceTimeMilliseconds(RtpPacketHistory::kMinPacketDurationMs -
|
TimeDelta::Millis(1));
|
||||||
1);
|
|
||||||
|
|
||||||
// Add a new packet to trigger culling.
|
// Add a new packet to trigger culling.
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 1)),
|
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 1)),
|
||||||
fake_clock_.TimeInMilliseconds());
|
fake_clock_.CurrentTime());
|
||||||
// First packet should still be there.
|
// First packet should still be there.
|
||||||
EXPECT_TRUE(hist_.GetPacketState(kStartSeqNum));
|
EXPECT_TRUE(hist_.GetPacketState(kStartSeqNum));
|
||||||
|
|
||||||
// Advance time to where packet will be eligible for removal and try again.
|
// Advance time to where packet will be eligible for removal and try again.
|
||||||
fake_clock_.AdvanceTimeMilliseconds(1);
|
fake_clock_.AdvanceTimeMilliseconds(1);
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 2)),
|
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 2)),
|
||||||
fake_clock_.TimeInMilliseconds());
|
fake_clock_.CurrentTime());
|
||||||
// First packet should no be gone, but next one still there.
|
// First packet should no be gone, but next one still there.
|
||||||
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
||||||
EXPECT_TRUE(hist_.GetPacketState(To16u(kStartSeqNum + 1)));
|
EXPECT_TRUE(hist_.GetPacketState(To16u(kStartSeqNum + 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(RtpPacketHistoryTest, DontRemoveTooRecentlyTransmittedPacketsHighRtt) {
|
TEST_P(RtpPacketHistoryTest, DontRemoveTooRecentlyTransmittedPacketsHighRtt) {
|
||||||
const int64_t kRttMs = RtpPacketHistory::kMinPacketDurationMs * 2;
|
const TimeDelta kRtt = RtpPacketHistory::kMinPacketDuration * 2;
|
||||||
const int64_t kPacketTimeoutMs =
|
const TimeDelta kPacketTimeout =
|
||||||
kRttMs * RtpPacketHistory::kMinPacketDurationRtt;
|
kRtt * RtpPacketHistory::kMinPacketDurationRtt;
|
||||||
|
|
||||||
// Set size to remove old packets as soon as possible.
|
// Set size to remove old packets as soon as possible.
|
||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
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.
|
// Add a packet, marked as send, and advance time to just before removal time.
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
|
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
|
||||||
fake_clock_.TimeInMilliseconds());
|
fake_clock_.AdvanceTime(kPacketTimeout - TimeDelta::Millis(1));
|
||||||
fake_clock_.AdvanceTimeMilliseconds(kPacketTimeoutMs - 1);
|
|
||||||
|
|
||||||
// Add a new packet to trigger culling.
|
// Add a new packet to trigger culling.
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 1)),
|
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 1)),
|
||||||
fake_clock_.TimeInMilliseconds());
|
fake_clock_.CurrentTime());
|
||||||
// First packet should still be there.
|
// First packet should still be there.
|
||||||
EXPECT_TRUE(hist_.GetPacketState(kStartSeqNum));
|
EXPECT_TRUE(hist_.GetPacketState(kStartSeqNum));
|
||||||
|
|
||||||
// Advance time to where packet will be eligible for removal and try again.
|
// Advance time to where packet will be eligible for removal and try again.
|
||||||
fake_clock_.AdvanceTimeMilliseconds(1);
|
fake_clock_.AdvanceTimeMilliseconds(1);
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 2)),
|
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 2)),
|
||||||
fake_clock_.TimeInMilliseconds());
|
fake_clock_.CurrentTime());
|
||||||
// First packet should no be gone, but next one still there.
|
// First packet should no be gone, but next one still there.
|
||||||
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
||||||
EXPECT_TRUE(hist_.GetPacketState(To16u(kStartSeqNum + 1)));
|
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.
|
// Enable culling. Even without feedback, this can trigger early removal.
|
||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, kMaxNumPackets);
|
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, kMaxNumPackets);
|
||||||
|
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
|
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
|
||||||
fake_clock_.TimeInMilliseconds());
|
|
||||||
|
|
||||||
int64_t kMaxPacketDurationMs = RtpPacketHistory::kMinPacketDurationMs *
|
TimeDelta kMaxPacketDuration = RtpPacketHistory::kMinPacketDuration *
|
||||||
RtpPacketHistory::kPacketCullingDelayFactor;
|
RtpPacketHistory::kPacketCullingDelayFactor;
|
||||||
fake_clock_.AdvanceTimeMilliseconds(kMaxPacketDurationMs - 1);
|
fake_clock_.AdvanceTime(kMaxPacketDuration - TimeDelta::Millis(1));
|
||||||
|
|
||||||
// First packet should still be there.
|
// First packet should still be there.
|
||||||
EXPECT_TRUE(hist_.GetPacketState(kStartSeqNum));
|
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.
|
// Advance to where packet can be culled, even if buffer is not full.
|
||||||
fake_clock_.AdvanceTimeMilliseconds(1);
|
fake_clock_.AdvanceTimeMilliseconds(1);
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 1)),
|
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 1)),
|
||||||
fake_clock_.TimeInMilliseconds());
|
fake_clock_.CurrentTime());
|
||||||
|
|
||||||
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(RtpPacketHistoryTest, RemovesOldWithCullingHighRtt) {
|
TEST_P(RtpPacketHistoryTest, RemovesOldWithCullingHighRtt) {
|
||||||
const size_t kMaxNumPackets = 10;
|
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.
|
// Enable culling. Even without feedback, this can trigger early removal.
|
||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, kMaxNumPackets);
|
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, kMaxNumPackets);
|
||||||
hist_.SetRtt(kRttMs);
|
hist_.SetRtt(kRtt);
|
||||||
|
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
|
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
|
||||||
fake_clock_.TimeInMilliseconds());
|
|
||||||
|
|
||||||
int64_t kMaxPacketDurationMs = kRttMs *
|
TimeDelta kMaxPacketDuration = kRtt *
|
||||||
RtpPacketHistory::kMinPacketDurationRtt *
|
RtpPacketHistory::kMinPacketDurationRtt *
|
||||||
RtpPacketHistory::kPacketCullingDelayFactor;
|
RtpPacketHistory::kPacketCullingDelayFactor;
|
||||||
fake_clock_.AdvanceTimeMilliseconds(kMaxPacketDurationMs - 1);
|
fake_clock_.AdvanceTime(kMaxPacketDuration - TimeDelta::Millis(1));
|
||||||
|
|
||||||
// First packet should still be there.
|
// First packet should still be there.
|
||||||
EXPECT_TRUE(hist_.GetPacketState(kStartSeqNum));
|
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.
|
// Advance to where packet can be culled, even if buffer is not full.
|
||||||
fake_clock_.AdvanceTimeMilliseconds(1);
|
fake_clock_.AdvanceTimeMilliseconds(1);
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 1)),
|
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + 1)),
|
||||||
fake_clock_.TimeInMilliseconds());
|
fake_clock_.CurrentTime());
|
||||||
|
|
||||||
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(RtpPacketHistoryTest, CullWithAcks) {
|
TEST_P(RtpPacketHistoryTest, CullWithAcks) {
|
||||||
const int64_t kPacketLifetime = RtpPacketHistory::kMinPacketDurationMs *
|
const TimeDelta kPacketLifetime = RtpPacketHistory::kMinPacketDuration *
|
||||||
RtpPacketHistory::kPacketCullingDelayFactor;
|
RtpPacketHistory::kPacketCullingDelayFactor;
|
||||||
|
|
||||||
const int64_t start_time = fake_clock_.TimeInMilliseconds();
|
const Timestamp start_time = fake_clock_.CurrentTime();
|
||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 10);
|
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 10);
|
||||||
|
|
||||||
// Insert three packets 33ms apart, immediately mark them as sent.
|
// Insert three packets 33ms apart, immediately mark them as sent.
|
||||||
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
|
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
|
||||||
packet->SetPayloadSize(50);
|
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);
|
fake_clock_.AdvanceTimeMilliseconds(33);
|
||||||
packet = CreateRtpPacket(To16u(kStartSeqNum + 1));
|
packet = CreateRtpPacket(To16u(kStartSeqNum + 1));
|
||||||
packet->SetPayloadSize(50);
|
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);
|
fake_clock_.AdvanceTimeMilliseconds(33);
|
||||||
packet = CreateRtpPacket(To16u(kStartSeqNum + 2));
|
packet = CreateRtpPacket(To16u(kStartSeqNum + 2));
|
||||||
packet->SetPayloadSize(50);
|
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(kStartSeqNum));
|
||||||
EXPECT_TRUE(hist_.GetPacketState(To16u(kStartSeqNum + 1)));
|
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
|
// Advance time to where second packet would have expired, verify first packet
|
||||||
// is removed.
|
// is removed.
|
||||||
int64_t second_packet_expiry_time = start_time + kPacketLifetime + 33 + 1;
|
Timestamp second_packet_expiry_time =
|
||||||
fake_clock_.AdvanceTimeMilliseconds(second_packet_expiry_time -
|
start_time + kPacketLifetime + TimeDelta::Millis(33 + 1);
|
||||||
fake_clock_.TimeInMilliseconds());
|
fake_clock_.AdvanceTime(second_packet_expiry_time -
|
||||||
hist_.SetRtt(1); // Trigger culling of old packets.
|
fake_clock_.CurrentTime());
|
||||||
|
hist_.SetRtt(TimeDelta::Millis(1)); // Trigger culling of old packets.
|
||||||
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
||||||
EXPECT_FALSE(hist_.GetPacketState(To16u(kStartSeqNum + 1)));
|
EXPECT_FALSE(hist_.GetPacketState(To16u(kStartSeqNum + 1)));
|
||||||
EXPECT_TRUE(hist_.GetPacketState(To16u(kStartSeqNum + 2)));
|
EXPECT_TRUE(hist_.GetPacketState(To16u(kStartSeqNum + 2)));
|
||||||
|
|
||||||
// Advance to where last packet expires, verify all gone.
|
// Advance to where last packet expires, verify all gone.
|
||||||
fake_clock_.AdvanceTimeMilliseconds(33);
|
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(kStartSeqNum));
|
||||||
EXPECT_FALSE(hist_.GetPacketState(To16u(kStartSeqNum + 1)));
|
EXPECT_FALSE(hist_.GetPacketState(To16u(kStartSeqNum + 1)));
|
||||||
EXPECT_FALSE(hist_.GetPacketState(To16u(kStartSeqNum + 2)));
|
EXPECT_FALSE(hist_.GetPacketState(To16u(kStartSeqNum + 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(RtpPacketHistoryTest, GetPacketAndSetSent) {
|
TEST_P(RtpPacketHistoryTest, GetPacketAndSetSent) {
|
||||||
const int64_t kRttMs = RtpPacketHistory::kMinPacketDurationMs * 2;
|
const TimeDelta kRtt = RtpPacketHistory::kMinPacketDuration * 2;
|
||||||
hist_.SetRtt(kRttMs);
|
hist_.SetRtt(kRtt);
|
||||||
|
|
||||||
// Set size to remove old packets as soon as possible.
|
// Set size to remove old packets as soon as possible.
|
||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
||||||
|
|
||||||
// Add a sent packet to the history.
|
// Add a sent packet to the history.
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
|
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
|
||||||
fake_clock_.TimeInMicroseconds());
|
|
||||||
|
|
||||||
// Retransmission request, first retransmission is allowed immediately.
|
// Retransmission request, first retransmission is allowed immediately.
|
||||||
EXPECT_TRUE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
|
EXPECT_TRUE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
|
||||||
|
|
||||||
// Packet not yet sent, new retransmission not allowed.
|
// Packet not yet sent, new retransmission not allowed.
|
||||||
fake_clock_.AdvanceTimeMilliseconds(kRttMs);
|
fake_clock_.AdvanceTime(kRtt);
|
||||||
EXPECT_FALSE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
|
EXPECT_FALSE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
|
||||||
|
|
||||||
// Mark as sent, but too early for retransmission.
|
// Mark as sent, but too early for retransmission.
|
||||||
@ -438,14 +440,14 @@ TEST_P(RtpPacketHistoryTest, GetPacketAndSetSent) {
|
|||||||
EXPECT_FALSE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
|
EXPECT_FALSE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
|
||||||
|
|
||||||
// Enough time has passed, retransmission is allowed again.
|
// Enough time has passed, retransmission is allowed again.
|
||||||
fake_clock_.AdvanceTimeMilliseconds(kRttMs);
|
fake_clock_.AdvanceTime(kRtt);
|
||||||
EXPECT_TRUE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
|
EXPECT_TRUE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(RtpPacketHistoryTest, GetPacketWithEncapsulation) {
|
TEST_P(RtpPacketHistoryTest, GetPacketWithEncapsulation) {
|
||||||
const uint32_t kSsrc = 92384762;
|
const uint32_t kSsrc = 92384762;
|
||||||
const int64_t kRttMs = RtpPacketHistory::kMinPacketDurationMs * 2;
|
const TimeDelta kRtt = RtpPacketHistory::kMinPacketDuration * 2;
|
||||||
hist_.SetRtt(kRttMs);
|
hist_.SetRtt(kRtt);
|
||||||
|
|
||||||
// Set size to remove old packets as soon as possible.
|
// Set size to remove old packets as soon as possible.
|
||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
||||||
@ -453,7 +455,7 @@ TEST_P(RtpPacketHistoryTest, GetPacketWithEncapsulation) {
|
|||||||
// Add a sent packet to the history, with a set SSRC.
|
// Add a sent packet to the history, with a set SSRC.
|
||||||
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
|
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kStartSeqNum);
|
||||||
packet->SetSsrc(kSsrc);
|
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
|
// Retransmission request, simulate an RTX-like encapsulation, were the packet
|
||||||
// is sent on a different SSRC.
|
// is sent on a different SSRC.
|
||||||
@ -472,8 +474,7 @@ TEST_P(RtpPacketHistoryTest, GetPacketWithEncapsulation) {
|
|||||||
TEST_P(RtpPacketHistoryTest, GetPacketWithEncapsulationAbortOnNullptr) {
|
TEST_P(RtpPacketHistoryTest, GetPacketWithEncapsulationAbortOnNullptr) {
|
||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
||||||
|
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
|
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
|
||||||
fake_clock_.TimeInMicroseconds());
|
|
||||||
|
|
||||||
// Retransmission request, but the encapsulator determines that this packet is
|
// Retransmission request, but the encapsulator determines that this packet is
|
||||||
// not suitable for retransmission (bandwidth exhausted?) so the retransmit is
|
// not suitable for retransmission (bandwidth exhausted?) so the retransmit is
|
||||||
@ -487,20 +488,19 @@ TEST_P(RtpPacketHistoryTest, GetPacketWithEncapsulationAbortOnNullptr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(RtpPacketHistoryTest, DontRemovePendingTransmissions) {
|
TEST_P(RtpPacketHistoryTest, DontRemovePendingTransmissions) {
|
||||||
const int64_t kRttMs = RtpPacketHistory::kMinPacketDurationMs * 2;
|
const TimeDelta kRtt = RtpPacketHistory::kMinPacketDuration * 2;
|
||||||
const int64_t kPacketTimeoutMs =
|
const TimeDelta kPacketTimeout =
|
||||||
kRttMs * RtpPacketHistory::kMinPacketDurationRtt;
|
kRtt * RtpPacketHistory::kMinPacketDurationRtt;
|
||||||
|
|
||||||
// Set size to remove old packets as soon as possible.
|
// Set size to remove old packets as soon as possible.
|
||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
||||||
hist_.SetRtt(kRttMs);
|
hist_.SetRtt(kRtt);
|
||||||
|
|
||||||
// Add a sent packet.
|
// Add a sent packet.
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
|
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
|
||||||
fake_clock_.TimeInMilliseconds());
|
|
||||||
|
|
||||||
// Advance clock to just before packet timeout.
|
// Advance clock to just before packet timeout.
|
||||||
fake_clock_.AdvanceTimeMilliseconds(kPacketTimeoutMs - 1);
|
fake_clock_.AdvanceTime(kPacketTimeout - TimeDelta::Millis(1));
|
||||||
// Mark as enqueued in pacer.
|
// Mark as enqueued in pacer.
|
||||||
EXPECT_TRUE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
|
EXPECT_TRUE(hist_.GetPacketAndMarkAsPending(kStartSeqNum));
|
||||||
|
|
||||||
@ -511,7 +511,7 @@ TEST_P(RtpPacketHistoryTest, DontRemovePendingTransmissions) {
|
|||||||
|
|
||||||
// Packet sent. Now it can be removed.
|
// Packet sent. Now it can be removed.
|
||||||
hist_.MarkPacketAsSent(kStartSeqNum);
|
hist_.MarkPacketAsSent(kStartSeqNum);
|
||||||
hist_.SetRtt(kRttMs); // Force culling of old packets.
|
hist_.SetRtt(kRtt); // Force culling of old packets.
|
||||||
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
EXPECT_FALSE(hist_.GetPacketState(kStartSeqNum));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,12 +524,11 @@ TEST_P(RtpPacketHistoryTest, PrioritizedPayloadPadding) {
|
|||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
||||||
|
|
||||||
// Add two sent packets, one millisecond apart.
|
// Add two sent packets, one millisecond apart.
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
|
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
|
||||||
fake_clock_.TimeInMilliseconds());
|
|
||||||
fake_clock_.AdvanceTimeMilliseconds(1);
|
fake_clock_.AdvanceTimeMilliseconds(1);
|
||||||
|
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum + 1),
|
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum + 1),
|
||||||
fake_clock_.TimeInMilliseconds());
|
fake_clock_.CurrentTime());
|
||||||
fake_clock_.AdvanceTimeMilliseconds(1);
|
fake_clock_.AdvanceTimeMilliseconds(1);
|
||||||
|
|
||||||
// Latest packet given equal retransmission count.
|
// Latest packet given equal retransmission count.
|
||||||
@ -560,8 +559,7 @@ TEST_P(RtpPacketHistoryTest, PrioritizedPayloadPadding) {
|
|||||||
TEST_P(RtpPacketHistoryTest, NoPendingPacketAsPadding) {
|
TEST_P(RtpPacketHistoryTest, NoPendingPacketAsPadding) {
|
||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
||||||
|
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
|
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
|
||||||
fake_clock_.TimeInMilliseconds());
|
|
||||||
fake_clock_.AdvanceTimeMilliseconds(1);
|
fake_clock_.AdvanceTimeMilliseconds(1);
|
||||||
|
|
||||||
EXPECT_EQ(hist_.GetPayloadPaddingPacket()->SequenceNumber(), kStartSeqNum);
|
EXPECT_EQ(hist_.GetPayloadPaddingPacket()->SequenceNumber(), kStartSeqNum);
|
||||||
@ -578,8 +576,7 @@ TEST_P(RtpPacketHistoryTest, NoPendingPacketAsPadding) {
|
|||||||
TEST_P(RtpPacketHistoryTest, PayloadPaddingWithEncapsulation) {
|
TEST_P(RtpPacketHistoryTest, PayloadPaddingWithEncapsulation) {
|
||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 1);
|
||||||
|
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
|
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
|
||||||
fake_clock_.TimeInMilliseconds());
|
|
||||||
fake_clock_.AdvanceTimeMilliseconds(1);
|
fake_clock_.AdvanceTimeMilliseconds(1);
|
||||||
|
|
||||||
// Aborted padding.
|
// Aborted padding.
|
||||||
@ -600,10 +597,9 @@ TEST_P(RtpPacketHistoryTest, PayloadPaddingWithEncapsulation) {
|
|||||||
TEST_P(RtpPacketHistoryTest, NackAfterAckIsNoop) {
|
TEST_P(RtpPacketHistoryTest, NackAfterAckIsNoop) {
|
||||||
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 2);
|
hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 2);
|
||||||
// Add two sent packets.
|
// Add two sent packets.
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum),
|
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum), fake_clock_.CurrentTime());
|
||||||
fake_clock_.TimeInMilliseconds());
|
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum + 1),
|
hist_.PutRtpPacket(CreateRtpPacket(kStartSeqNum + 1),
|
||||||
fake_clock_.TimeInMilliseconds());
|
fake_clock_.CurrentTime());
|
||||||
// Remove newest one.
|
// Remove newest one.
|
||||||
hist_.CullAcknowledgedPackets(std::vector<uint16_t>{kStartSeqNum + 1});
|
hist_.CullAcknowledgedPackets(std::vector<uint16_t>{kStartSeqNum + 1});
|
||||||
// Retransmission request for already acked packet, should be noop.
|
// Retransmission request for already acked packet, should be noop.
|
||||||
@ -622,7 +618,7 @@ TEST_P(RtpPacketHistoryTest, OutOfOrderInsertRemoval) {
|
|||||||
uint16_t seq_no = To16u(kStartSeqNum + offset);
|
uint16_t seq_no = To16u(kStartSeqNum + offset);
|
||||||
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(seq_no);
|
std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(seq_no);
|
||||||
packet->SetPayloadSize(50);
|
packet->SetPayloadSize(50);
|
||||||
hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMilliseconds());
|
hist_.PutRtpPacket(std::move(packet), fake_clock_.CurrentTime());
|
||||||
fake_clock_.AdvanceTimeMilliseconds(33);
|
fake_clock_.AdvanceTimeMilliseconds(33);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -649,7 +645,7 @@ TEST_P(RtpPacketHistoryTest, UsesLastPacketAsPaddingWithPrioOff) {
|
|||||||
|
|
||||||
for (size_t i = 0; i < kHistorySize; ++i) {
|
for (size_t i = 0; i < kHistorySize; ++i) {
|
||||||
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + i)),
|
hist_.PutRtpPacket(CreateRtpPacket(To16u(kStartSeqNum + i)),
|
||||||
fake_clock_.TimeInMilliseconds());
|
fake_clock_.CurrentTime());
|
||||||
hist_.MarkPacketAsSent(To16u(kStartSeqNum + i));
|
hist_.MarkPacketAsSent(To16u(kStartSeqNum + i));
|
||||||
fake_clock_.AdvanceTimeMilliseconds(1);
|
fake_clock_.AdvanceTimeMilliseconds(1);
|
||||||
|
|
||||||
|
@ -787,7 +787,7 @@ void ModuleRtpRtcpImpl::set_rtt_ms(int64_t rtt_ms) {
|
|||||||
rtt_ms_ = rtt_ms;
|
rtt_ms_ = rtt_ms;
|
||||||
}
|
}
|
||||||
if (rtp_sender_) {
|
if (rtp_sender_) {
|
||||||
rtp_sender_->packet_history.SetRtt(rtt_ms);
|
rtp_sender_->packet_history.SetRtt(TimeDelta::Millis(rtt_ms));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -745,7 +745,7 @@ void ModuleRtpRtcpImpl2::set_rtt_ms(int64_t rtt_ms) {
|
|||||||
rtt_ms_ = rtt_ms;
|
rtt_ms_ = rtt_ms;
|
||||||
}
|
}
|
||||||
if (rtp_sender_) {
|
if (rtp_sender_) {
|
||||||
rtp_sender_->packet_history.SetRtt(rtt_ms);
|
rtp_sender_->packet_history.SetRtt(TimeDelta::Millis(rtt_ms));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,7 +354,7 @@ void RTPSender::OnReceivedAckOnRtxSsrc(
|
|||||||
void RTPSender::OnReceivedNack(
|
void RTPSender::OnReceivedNack(
|
||||||
const std::vector<uint16_t>& nack_sequence_numbers,
|
const std::vector<uint16_t>& nack_sequence_numbers,
|
||||||
int64_t avg_rtt) {
|
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) {
|
for (uint16_t seq_no : nack_sequence_numbers) {
|
||||||
const int32_t bytes_sent = ReSendPacket(seq_no);
|
const int32_t bytes_sent = ReSendPacket(seq_no);
|
||||||
if (bytes_sent < 0) {
|
if (bytes_sent < 0) {
|
||||||
|
@ -276,7 +276,7 @@ void RtpSenderEgress::SendPacket(RtpPacketToSend* packet,
|
|||||||
// actual sending fails.
|
// actual sending fails.
|
||||||
if (is_media && packet->allow_retransmission()) {
|
if (is_media && packet->allow_retransmission()) {
|
||||||
packet_history_->PutRtpPacket(std::make_unique<RtpPacketToSend>(*packet),
|
packet_history_->PutRtpPacket(std::make_unique<RtpPacketToSend>(*packet),
|
||||||
now_ms);
|
Timestamp::Millis(now_ms));
|
||||||
} else if (packet->retransmitted_sequence_number()) {
|
} else if (packet->retransmitted_sequence_number()) {
|
||||||
packet_history_->MarkPacketAsSent(*packet->retransmitted_sequence_number());
|
packet_history_->MarkPacketAsSent(*packet->retransmitted_sequence_number());
|
||||||
}
|
}
|
||||||
|
@ -371,7 +371,7 @@ TEST_F(RtpSenderTest, ReSendPacketForwardsPacketsToPacer) {
|
|||||||
auto packet = BuildRtpPacket(kPayload, kMarkerBit, kTimestamp, now_ms);
|
auto packet = BuildRtpPacket(kPayload, kMarkerBit, kTimestamp, now_ms);
|
||||||
packet->SetSequenceNumber(kSeqNum);
|
packet->SetSequenceNumber(kSeqNum);
|
||||||
packet->set_allow_retransmission(true);
|
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_,
|
EXPECT_CALL(mock_paced_sender_,
|
||||||
EnqueuePackets(ElementsAre(AllOf(
|
EnqueuePackets(ElementsAre(AllOf(
|
||||||
@ -571,7 +571,8 @@ TEST_F(RtpSenderTest, KeepsTimestampsOnPayloadPadding) {
|
|||||||
Timestamp::Millis(start_time)))))));
|
Timestamp::Millis(start_time)))))));
|
||||||
std::unique_ptr<RtpPacketToSend> media_packet =
|
std::unique_ptr<RtpPacketToSend> media_packet =
|
||||||
SendPacket(start_time, kPayloadSize);
|
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.
|
// Advance time before sending padding.
|
||||||
const TimeDelta kTimeDiff = TimeDelta::Millis(17);
|
const TimeDelta kTimeDiff = TimeDelta::Millis(17);
|
||||||
@ -626,7 +627,7 @@ TEST_F(RtpSenderTest, RidIncludedOnRtxSentPackets) {
|
|||||||
.WillOnce([&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
|
.WillOnce([&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
|
||||||
sequencer_->Sequence(*packets[0]);
|
sequencer_->Sequence(*packets[0]);
|
||||||
packet_history_->PutRtpPacket(std::move(packets[0]),
|
packet_history_->PutRtpPacket(std::move(packets[0]),
|
||||||
clock_->TimeInMilliseconds());
|
clock_->CurrentTime());
|
||||||
});
|
});
|
||||||
SendGenericPacket();
|
SendGenericPacket();
|
||||||
|
|
||||||
@ -705,7 +706,7 @@ TEST_F(RtpSenderTest, MidAndRidIncludedOnFirstRtxPacket) {
|
|||||||
EXPECT_CALL(mock_paced_sender_, EnqueuePackets(SizeIs(1)))
|
EXPECT_CALL(mock_paced_sender_, EnqueuePackets(SizeIs(1)))
|
||||||
.WillOnce([&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
|
.WillOnce([&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
|
||||||
packet_history_->PutRtpPacket(std::move(packets[0]),
|
packet_history_->PutRtpPacket(std::move(packets[0]),
|
||||||
clock_->TimeInMilliseconds());
|
clock_->CurrentTime());
|
||||||
});
|
});
|
||||||
auto second_built_packet = SendGenericPacket();
|
auto second_built_packet = SendGenericPacket();
|
||||||
|
|
||||||
@ -734,7 +735,7 @@ TEST_F(RtpSenderTest, MidAndRidNotIncludedOnRtxPacketsAfterAck) {
|
|||||||
sequencer_->Sequence(*first_built_packet);
|
sequencer_->Sequence(*first_built_packet);
|
||||||
packet_history_->PutRtpPacket(
|
packet_history_->PutRtpPacket(
|
||||||
std::make_unique<RtpPacketToSend>(*first_built_packet),
|
std::make_unique<RtpPacketToSend>(*first_built_packet),
|
||||||
/*send_time=*/clock_->TimeInMilliseconds());
|
/*send_time=*/clock_->CurrentTime());
|
||||||
rtp_sender_->OnReceivedAckOnSsrc(first_built_packet->SequenceNumber());
|
rtp_sender_->OnReceivedAckOnSsrc(first_built_packet->SequenceNumber());
|
||||||
|
|
||||||
// The second packet will include neither since an ack was received.
|
// The second packet will include neither since an ack was received.
|
||||||
@ -742,7 +743,7 @@ TEST_F(RtpSenderTest, MidAndRidNotIncludedOnRtxPacketsAfterAck) {
|
|||||||
sequencer_->Sequence(*second_built_packet);
|
sequencer_->Sequence(*second_built_packet);
|
||||||
packet_history_->PutRtpPacket(
|
packet_history_->PutRtpPacket(
|
||||||
std::make_unique<RtpPacketToSend>(*second_built_packet),
|
std::make_unique<RtpPacketToSend>(*second_built_packet),
|
||||||
/*send_time=*/clock_->TimeInMilliseconds());
|
/*send_time=*/clock_->CurrentTime());
|
||||||
|
|
||||||
// The first RTX packet will include MID and RRID.
|
// The first RTX packet will include MID and RRID.
|
||||||
EXPECT_CALL(mock_paced_sender_, EnqueuePackets(SizeIs(1)))
|
EXPECT_CALL(mock_paced_sender_, EnqueuePackets(SizeIs(1)))
|
||||||
@ -782,7 +783,7 @@ TEST_F(RtpSenderTest, MidAndRidAlwaysIncludedOnRtxPacketsWhenConfigured) {
|
|||||||
.WillRepeatedly(
|
.WillRepeatedly(
|
||||||
[&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
|
[&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
|
||||||
packet_history_->PutRtpPacket(std::move(packets[0]),
|
packet_history_->PutRtpPacket(std::move(packets[0]),
|
||||||
clock_->TimeInMilliseconds());
|
clock_->CurrentTime());
|
||||||
});
|
});
|
||||||
auto media_packet1 = SendGenericPacket();
|
auto media_packet1 = SendGenericPacket();
|
||||||
rtp_sender_->OnReceivedAckOnSsrc(media_packet1->SequenceNumber());
|
rtp_sender_->OnReceivedAckOnSsrc(media_packet1->SequenceNumber());
|
||||||
@ -850,7 +851,7 @@ TEST_F(RtpSenderTest, MidAndRridNotIncludedOnRtxPacketsAfterRtpStateRestored) {
|
|||||||
EXPECT_CALL(mock_paced_sender_, EnqueuePackets(SizeIs(1)))
|
EXPECT_CALL(mock_paced_sender_, EnqueuePackets(SizeIs(1)))
|
||||||
.WillOnce([&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
|
.WillOnce([&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
|
||||||
packet_history_->PutRtpPacket(std::move(packets[0]),
|
packet_history_->PutRtpPacket(std::move(packets[0]),
|
||||||
clock_->TimeInMilliseconds());
|
clock_->CurrentTime());
|
||||||
});
|
});
|
||||||
auto built_packet = SendGenericPacket();
|
auto built_packet = SendGenericPacket();
|
||||||
|
|
||||||
@ -877,7 +878,7 @@ TEST_F(RtpSenderTest, RespectsNackBitrateLimit) {
|
|||||||
sequencer_->Sequence(*packet);
|
sequencer_->Sequence(*packet);
|
||||||
sequence_numbers.push_back(packet->SequenceNumber());
|
sequence_numbers.push_back(packet->SequenceNumber());
|
||||||
packet_history_->PutRtpPacket(std::move(packet),
|
packet_history_->PutRtpPacket(std::move(packet),
|
||||||
/*send_time=*/clock_->TimeInMilliseconds());
|
/*send_time=*/clock_->CurrentTime());
|
||||||
time_controller_.AdvanceTime(TimeDelta::Millis(1));
|
time_controller_.AdvanceTime(TimeDelta::Millis(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -994,8 +995,7 @@ TEST_F(RtpSenderTest, SendPacketHandlesRetransmissionHistory) {
|
|||||||
BuildRtpPacket(kPayload, true, 0, clock_->TimeInMilliseconds());
|
BuildRtpPacket(kPayload, true, 0, clock_->TimeInMilliseconds());
|
||||||
const uint16_t media_sequence_number = packet->SequenceNumber();
|
const uint16_t media_sequence_number = packet->SequenceNumber();
|
||||||
packet->set_allow_retransmission(true);
|
packet->set_allow_retransmission(true);
|
||||||
packet_history_->PutRtpPacket(std::move(packet),
|
packet_history_->PutRtpPacket(std::move(packet), clock_->CurrentTime());
|
||||||
clock_->TimeInMilliseconds());
|
|
||||||
|
|
||||||
// Simulate successful retransmission request.
|
// Simulate successful retransmission request.
|
||||||
time_controller_.AdvanceTime(TimeDelta::Millis(30));
|
time_controller_.AdvanceTime(TimeDelta::Millis(30));
|
||||||
@ -1022,8 +1022,7 @@ TEST_F(RtpSenderTest, MarksRetransmittedPackets) {
|
|||||||
BuildRtpPacket(kPayload, true, 0, clock_->TimeInMilliseconds());
|
BuildRtpPacket(kPayload, true, 0, clock_->TimeInMilliseconds());
|
||||||
const uint16_t media_sequence_number = packet->SequenceNumber();
|
const uint16_t media_sequence_number = packet->SequenceNumber();
|
||||||
packet->set_allow_retransmission(true);
|
packet->set_allow_retransmission(true);
|
||||||
packet_history_->PutRtpPacket(std::move(packet),
|
packet_history_->PutRtpPacket(std::move(packet), clock_->CurrentTime());
|
||||||
clock_->TimeInMilliseconds());
|
|
||||||
|
|
||||||
// Expect a retransmission packet marked with which packet it is a
|
// Expect a retransmission packet marked with which packet it is a
|
||||||
// retransmit of.
|
// retransmit of.
|
||||||
@ -1055,8 +1054,7 @@ TEST_F(RtpSenderTest, GeneratedPaddingHasBweExtensions) {
|
|||||||
packet->set_allow_retransmission(true);
|
packet->set_allow_retransmission(true);
|
||||||
packet->SetPayloadSize(kMinPaddingSize);
|
packet->SetPayloadSize(kMinPaddingSize);
|
||||||
packet->set_packet_type(RtpPacketMediaType::kVideo);
|
packet->set_packet_type(RtpPacketMediaType::kVideo);
|
||||||
packet_history_->PutRtpPacket(std::move(packet),
|
packet_history_->PutRtpPacket(std::move(packet), clock_->CurrentTime());
|
||||||
clock_->TimeInMilliseconds());
|
|
||||||
|
|
||||||
// Generate a plain padding packet, check that extensions are registered.
|
// Generate a plain padding packet, check that extensions are registered.
|
||||||
std::vector<std::unique_ptr<RtpPacketToSend>> generated_packets =
|
std::vector<std::unique_ptr<RtpPacketToSend>> generated_packets =
|
||||||
@ -1098,8 +1096,7 @@ TEST_F(RtpSenderTest, GeneratePaddingResendsOldPacketsWithRtx) {
|
|||||||
packet->set_allow_retransmission(true);
|
packet->set_allow_retransmission(true);
|
||||||
packet->SetPayloadSize(kPayloadPacketSize);
|
packet->SetPayloadSize(kPayloadPacketSize);
|
||||||
packet->set_packet_type(RtpPacketMediaType::kVideo);
|
packet->set_packet_type(RtpPacketMediaType::kVideo);
|
||||||
packet_history_->PutRtpPacket(std::move(packet),
|
packet_history_->PutRtpPacket(std::move(packet), clock_->CurrentTime());
|
||||||
clock_->TimeInMilliseconds());
|
|
||||||
|
|
||||||
// Generated padding has large enough budget that the video packet should be
|
// Generated padding has large enough budget that the video packet should be
|
||||||
// retransmitted as padding.
|
// retransmitted as padding.
|
||||||
@ -1149,8 +1146,7 @@ TEST_F(RtpSenderTest, LimitsPayloadPaddingSize) {
|
|||||||
packet->set_allow_retransmission(true);
|
packet->set_allow_retransmission(true);
|
||||||
packet->SetPayloadSize(kPayloadPacketSize);
|
packet->SetPayloadSize(kPayloadPacketSize);
|
||||||
packet->set_packet_type(RtpPacketMediaType::kVideo);
|
packet->set_packet_type(RtpPacketMediaType::kVideo);
|
||||||
packet_history_->PutRtpPacket(std::move(packet),
|
packet_history_->PutRtpPacket(std::move(packet), clock_->CurrentTime());
|
||||||
clock_->TimeInMilliseconds());
|
|
||||||
|
|
||||||
// Smallest target size that will result in the sent packet being returned as
|
// Smallest target size that will result in the sent packet being returned as
|
||||||
// padding.
|
// padding.
|
||||||
@ -1191,8 +1187,7 @@ TEST_F(RtpSenderTest, GeneratePaddingCreatesPurePaddingWithoutRtx) {
|
|||||||
packet->SetPayloadSize(kPayloadPacketSize);
|
packet->SetPayloadSize(kPayloadPacketSize);
|
||||||
packet->set_packet_type(RtpPacketMediaType::kVideo);
|
packet->set_packet_type(RtpPacketMediaType::kVideo);
|
||||||
sequencer_->Sequence(*packet);
|
sequencer_->Sequence(*packet);
|
||||||
packet_history_->PutRtpPacket(std::move(packet),
|
packet_history_->PutRtpPacket(std::move(packet), clock_->CurrentTime());
|
||||||
clock_->TimeInMilliseconds());
|
|
||||||
|
|
||||||
// Payload padding not available without RTX, only generate plain padding on
|
// Payload padding not available without RTX, only generate plain padding on
|
||||||
// the media SSRC.
|
// the media SSRC.
|
||||||
@ -1269,7 +1264,8 @@ TEST_F(RtpSenderTest, SetsCaptureTimeOnRtxRetransmissions) {
|
|||||||
/*capture_time_ms=*/start_time_ms);
|
/*capture_time_ms=*/start_time_ms);
|
||||||
packet->set_allow_retransmission(true);
|
packet->set_allow_retransmission(true);
|
||||||
sequencer_->Sequence(*packet);
|
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
|
// Advance time, request an RTX retransmission. Capture timestamp should be
|
||||||
// preserved.
|
// preserved.
|
||||||
@ -1283,7 +1279,7 @@ TEST_F(RtpSenderTest, SetsCaptureTimeOnRtxRetransmissions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RtpSenderTest, IgnoresNackAfterDisablingMedia) {
|
TEST_F(RtpSenderTest, IgnoresNackAfterDisablingMedia) {
|
||||||
const int64_t kRtt = 10;
|
const TimeDelta kRtt = TimeDelta::Millis(10);
|
||||||
|
|
||||||
EnableRtx();
|
EnableRtx();
|
||||||
packet_history_->SetRtt(kRtt);
|
packet_history_->SetRtt(kRtt);
|
||||||
@ -1295,18 +1291,19 @@ TEST_F(RtpSenderTest, IgnoresNackAfterDisablingMedia) {
|
|||||||
/*capture_time_ms=*/start_time_ms);
|
/*capture_time_ms=*/start_time_ms);
|
||||||
packet->set_allow_retransmission(true);
|
packet->set_allow_retransmission(true);
|
||||||
sequencer_->Sequence(*packet);
|
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.
|
// Disable media sending and try to retransmit the packet, it should fail.
|
||||||
rtp_sender_->SetSendingMediaStatus(false);
|
rtp_sender_->SetSendingMediaStatus(false);
|
||||||
time_controller_.AdvanceTime(TimeDelta::Millis(kRtt));
|
time_controller_.AdvanceTime(kRtt);
|
||||||
EXPECT_LT(rtp_sender_->ReSendPacket(kSeqNum), 0);
|
EXPECT_LT(rtp_sender_->ReSendPacket(kSeqNum), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RtpSenderTest, DoesntFecProtectRetransmissions) {
|
TEST_F(RtpSenderTest, DoesntFecProtectRetransmissions) {
|
||||||
// Set up retranmission without RTX, so that a plain copy of the old packet is
|
// Set up retranmission without RTX, so that a plain copy of the old packet is
|
||||||
// re-sent instead.
|
// re-sent instead.
|
||||||
const int64_t kRtt = 10;
|
const TimeDelta kRtt = TimeDelta::Millis(10);
|
||||||
rtp_sender_->SetSendingMediaStatus(true);
|
rtp_sender_->SetSendingMediaStatus(true);
|
||||||
rtp_sender_->SetRtxStatus(kRtxOff);
|
rtp_sender_->SetRtxStatus(kRtxOff);
|
||||||
packet_history_->SetStorePacketsStatus(
|
packet_history_->SetStorePacketsStatus(
|
||||||
@ -1321,7 +1318,8 @@ TEST_F(RtpSenderTest, DoesntFecProtectRetransmissions) {
|
|||||||
packet->set_allow_retransmission(true);
|
packet->set_allow_retransmission(true);
|
||||||
packet->set_fec_protect_packet(true);
|
packet->set_fec_protect_packet(true);
|
||||||
sequencer_->Sequence(*packet);
|
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
|
// Re-send packet, the retransmitted packet should not have the FEC protection
|
||||||
// flag set.
|
// flag set.
|
||||||
@ -1329,7 +1327,7 @@ TEST_F(RtpSenderTest, DoesntFecProtectRetransmissions) {
|
|||||||
EnqueuePackets(ElementsAre(Pointee(
|
EnqueuePackets(ElementsAre(Pointee(
|
||||||
Property(&RtpPacketToSend::fec_protect_packet, false)))));
|
Property(&RtpPacketToSend::fec_protect_packet, false)))));
|
||||||
|
|
||||||
time_controller_.AdvanceTime(TimeDelta::Millis(kRtt));
|
time_controller_.AdvanceTime(kRtt);
|
||||||
EXPECT_GT(rtp_sender_->ReSendPacket(kSeqNum), 0);
|
EXPECT_GT(rtp_sender_->ReSendPacket(kSeqNum), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user