Refactor some retransmission tests.

This simplifies some tests and removes dependency on RtpSenderEgress
for those tests in rtp_sender_unittest.

Bug: webrtc:11340
Change-Id: I37489875947b0ac48a1742d2e9945510ee002f99
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/219624
Commit-Queue: Erik Språng <sprang@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34099}
This commit is contained in:
Erik Språng 2021-05-24 14:26:59 +02:00 committed by WebRTC LUCI CQ
parent 006815eed0
commit cf497890f3

View file

@ -80,7 +80,7 @@ using ::testing::AllOf;
using ::testing::AtLeast; using ::testing::AtLeast;
using ::testing::Contains; using ::testing::Contains;
using ::testing::Each; using ::testing::Each;
using ::testing::ElementsAreArray; using ::testing::ElementsAre;
using ::testing::Eq; using ::testing::Eq;
using ::testing::Field; using ::testing::Field;
using ::testing::Gt; using ::testing::Gt;
@ -1784,121 +1784,60 @@ TEST_P(RtpSenderTest, SupportsPadding) {
} }
} }
TEST_P(RtpSenderTest, SetsCaptureTimeAndPopulatesTransmissionOffset) { TEST_P(RtpSenderTest, SetsCaptureTimeOnRtxRetransmissions) {
rtp_sender()->RegisterRtpHeaderExtension(TransmissionOffset::kUri, EnableRtx();
kTransmissionTimeOffsetExtensionId);
rtp_sender()->SetSendingMediaStatus(true);
rtp_sender()->SetRtxStatus(kRtxRetransmitted | kRtxRedundantPayloads);
rtp_sender()->SetRtxPayloadType(kRtxPayload, kPayload);
rtp_sender_context_->packet_history_.SetStorePacketsStatus(
RtpPacketHistory::StorageMode::kStoreAndCull, 10);
const int64_t kMissingCaptureTimeMs = 0;
const int64_t kOffsetMs = 10;
auto packet =
BuildRtpPacket(kPayload, kMarkerBit, clock_->TimeInMilliseconds(),
kMissingCaptureTimeMs);
packet->set_packet_type(RtpPacketMediaType::kVideo);
packet->ReserveExtension<TransmissionOffset>();
packet->AllocatePayload(sizeof(kPayloadData));
std::unique_ptr<RtpPacketToSend> packet_to_pace;
EXPECT_CALL(mock_paced_sender_, EnqueuePackets)
.WillOnce([&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
EXPECT_EQ(packets.size(), 1u);
EXPECT_GT(packets[0]->capture_time_ms(), 0);
packet_to_pace = std::move(packets[0]);
});
// Put a packet in the packet history, with current time as capture time.
const int64_t start_time_ms = clock_->TimeInMilliseconds();
std::unique_ptr<RtpPacketToSend> packet =
BuildRtpPacket(kPayload, kMarkerBit, start_time_ms,
/*capture_time_ms=*/start_time_ms);
packet->set_allow_retransmission(true); packet->set_allow_retransmission(true);
EXPECT_TRUE(rtp_sender()->SendToNetwork(std::move(packet))); rtp_sender_context_->packet_history_.PutRtpPacket(std::move(packet),
start_time_ms);
time_controller_.AdvanceTime(TimeDelta::Millis(kOffsetMs)); // Advance time, request an RTX retransmission. Capture timestamp should be
// preserved.
rtp_sender_context_->InjectPacket(std::move(packet_to_pace), time_controller_.AdvanceTime(TimeDelta::Millis(10));
PacedPacketInfo());
EXPECT_EQ(1, transport_.packets_sent());
absl::optional<int32_t> transmission_time_extension =
transport_.sent_packets_.back().GetExtension<TransmissionOffset>();
ASSERT_TRUE(transmission_time_extension.has_value());
EXPECT_EQ(*transmission_time_extension, kOffsetMs * kTimestampTicksPerMs);
// Retransmit packet. The RTX packet should get the same capture time as the
// original packet, so offset is delta from original packet to now.
time_controller_.AdvanceTime(TimeDelta::Millis(kOffsetMs));
std::unique_ptr<RtpPacketToSend> rtx_packet_to_pace;
EXPECT_CALL(mock_paced_sender_, EnqueuePackets)
.WillOnce([&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
EXPECT_GT(packets[0]->capture_time_ms(), 0);
rtx_packet_to_pace = std::move(packets[0]);
});
EXPECT_CALL(mock_paced_sender_,
EnqueuePackets(ElementsAre(Pointee(Property(
&RtpPacketToSend::capture_time_ms, start_time_ms)))));
EXPECT_GT(rtp_sender()->ReSendPacket(kSeqNum), 0); EXPECT_GT(rtp_sender()->ReSendPacket(kSeqNum), 0);
rtp_sender_context_->InjectPacket(std::move(rtx_packet_to_pace),
PacedPacketInfo());
EXPECT_EQ(2, transport_.packets_sent());
transmission_time_extension =
transport_.sent_packets_.back().GetExtension<TransmissionOffset>();
ASSERT_TRUE(transmission_time_extension.has_value());
EXPECT_EQ(*transmission_time_extension, 2 * kOffsetMs * kTimestampTicksPerMs);
} }
TEST_P(RtpSenderTestWithoutPacer, ClearHistoryOnSequenceNumberCange) { TEST_P(RtpSenderTestWithoutPacer, ClearHistoryOnSequenceNumberCange) {
const int64_t kRtt = 10; EnableRtx();
rtp_sender()->SetSendingMediaStatus(true); // Put a packet in the packet history.
rtp_sender()->SetRtxStatus(kRtxRetransmitted | kRtxRedundantPayloads); const int64_t now_ms = clock_->TimeInMilliseconds();
rtp_sender()->SetRtxPayloadType(kRtxPayload, kPayload); std::unique_ptr<RtpPacketToSend> packet =
rtp_sender_context_->packet_history_.SetStorePacketsStatus( BuildRtpPacket(kPayload, kMarkerBit, now_ms, now_ms);
RtpPacketHistory::StorageMode::kStoreAndCull, 10); packet->set_allow_retransmission(true);
rtp_sender_context_->packet_history_.SetRtt(kRtt); rtp_sender_context_->packet_history_.PutRtpPacket(std::move(packet), now_ms);
// Send a packet and record its sequence numbers. EXPECT_TRUE(rtp_sender_context_->packet_history_.GetPacketState(kSeqNum));
SendGenericPacket();
ASSERT_EQ(1u, transport_.sent_packets_.size());
const uint16_t packet_seqence_number =
transport_.sent_packets_.back().SequenceNumber();
// Advance time and make sure it can be retransmitted, even if we try to set // Update the sequence number of the RTP module, verify packet has been
// the ssrc the what it already is. // removed.
rtp_sender()->SetSequenceNumber(rtp_sender()->SequenceNumber());
time_controller_.AdvanceTime(TimeDelta::Millis(kRtt));
EXPECT_GT(rtp_sender()->ReSendPacket(packet_seqence_number), 0);
// Change the sequence number, then move the time and try to retransmit again.
// The old packet should now be gone.
rtp_sender()->SetSequenceNumber(rtp_sender()->SequenceNumber() - 1); rtp_sender()->SetSequenceNumber(rtp_sender()->SequenceNumber() - 1);
time_controller_.AdvanceTime(TimeDelta::Millis(kRtt)); EXPECT_FALSE(rtp_sender_context_->packet_history_.GetPacketState(kSeqNum));
EXPECT_EQ(rtp_sender()->ReSendPacket(packet_seqence_number), 0);
} }
TEST_P(RtpSenderTest, IgnoresNackAfterDisablingMedia) { TEST_P(RtpSenderTest, IgnoresNackAfterDisablingMedia) {
const int64_t kRtt = 10; const int64_t kRtt = 10;
rtp_sender()->SetSendingMediaStatus(true); EnableRtx();
rtp_sender()->SetRtxStatus(kRtxRetransmitted | kRtxRedundantPayloads);
rtp_sender()->SetRtxPayloadType(kRtxPayload, kPayload);
rtp_sender_context_->packet_history_.SetStorePacketsStatus(
RtpPacketHistory::StorageMode::kStoreAndCull, 10);
rtp_sender_context_->packet_history_.SetRtt(kRtt); rtp_sender_context_->packet_history_.SetRtt(kRtt);
// Send a packet so it is in the packet history. // Put a packet in the history.
std::unique_ptr<RtpPacketToSend> packet_to_pace; const int64_t start_time_ms = clock_->TimeInMilliseconds();
EXPECT_CALL(mock_paced_sender_, EnqueuePackets) std::unique_ptr<RtpPacketToSend> packet =
.WillOnce([&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) { BuildRtpPacket(kPayload, kMarkerBit, start_time_ms,
packet_to_pace = std::move(packets[0]); /*capture_time_ms=*/start_time_ms);
}); packet->set_allow_retransmission(true);
rtp_sender_context_->packet_history_.PutRtpPacket(std::move(packet),
SendGenericPacket(); start_time_ms);
rtp_sender_context_->InjectPacket(std::move(packet_to_pace),
PacedPacketInfo());
ASSERT_EQ(1u, transport_.sent_packets_.size());
// 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);
@ -1916,25 +1855,20 @@ TEST_P(RtpSenderTest, DoesntFecProtectRetransmissions) {
RtpPacketHistory::StorageMode::kStoreAndCull, 10); RtpPacketHistory::StorageMode::kStoreAndCull, 10);
rtp_sender_context_->packet_history_.SetRtt(kRtt); rtp_sender_context_->packet_history_.SetRtt(kRtt);
// Send a packet so it is in the packet history, make sure to mark it for // Put a fec protected packet in the history.
// FEC protection. const int64_t start_time_ms = clock_->TimeInMilliseconds();
std::unique_ptr<RtpPacketToSend> packet_to_pace; std::unique_ptr<RtpPacketToSend> packet =
EXPECT_CALL(mock_paced_sender_, EnqueuePackets) BuildRtpPacket(kPayload, kMarkerBit, start_time_ms,
.WillOnce([&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) { /*capture_time_ms=*/start_time_ms);
packet_to_pace = std::move(packets[0]); packet->set_allow_retransmission(true);
}); packet->set_fec_protect_packet(true);
rtp_sender_context_->packet_history_.PutRtpPacket(std::move(packet),
SendGenericPacket(); start_time_ms);
packet_to_pace->set_fec_protect_packet(true);
rtp_sender_context_->InjectPacket(std::move(packet_to_pace),
PacedPacketInfo());
ASSERT_EQ(1u, transport_.sent_packets_.size());
// 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.
EXPECT_CALL(mock_paced_sender_, EXPECT_CALL(mock_paced_sender_,
EnqueuePackets(Each(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(TimeDelta::Millis(kRtt));