mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-19 08:37:54 +01:00
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:
parent
006815eed0
commit
cf497890f3
1 changed files with 50 additions and 116 deletions
|
@ -80,7 +80,7 @@ using ::testing::AllOf;
|
|||
using ::testing::AtLeast;
|
||||
using ::testing::Contains;
|
||||
using ::testing::Each;
|
||||
using ::testing::ElementsAreArray;
|
||||
using ::testing::ElementsAre;
|
||||
using ::testing::Eq;
|
||||
using ::testing::Field;
|
||||
using ::testing::Gt;
|
||||
|
@ -1784,126 +1784,65 @@ TEST_P(RtpSenderTest, SupportsPadding) {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_P(RtpSenderTest, SetsCaptureTimeAndPopulatesTransmissionOffset) {
|
||||
rtp_sender()->RegisterRtpHeaderExtension(TransmissionOffset::kUri,
|
||||
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]);
|
||||
});
|
||||
TEST_P(RtpSenderTest, SetsCaptureTimeOnRtxRetransmissions) {
|
||||
EnableRtx();
|
||||
|
||||
// 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);
|
||||
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));
|
||||
|
||||
rtp_sender_context_->InjectPacket(std::move(packet_to_pace),
|
||||
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]);
|
||||
});
|
||||
// Advance time, request an RTX retransmission. Capture timestamp should be
|
||||
// preserved.
|
||||
time_controller_.AdvanceTime(TimeDelta::Millis(10));
|
||||
|
||||
EXPECT_CALL(mock_paced_sender_,
|
||||
EnqueuePackets(ElementsAre(Pointee(Property(
|
||||
&RtpPacketToSend::capture_time_ms, start_time_ms)))));
|
||||
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) {
|
||||
const int64_t kRtt = 10;
|
||||
EnableRtx();
|
||||
|
||||
rtp_sender()->SetSendingMediaStatus(true);
|
||||
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);
|
||||
// Put a packet in the packet history.
|
||||
const int64_t now_ms = clock_->TimeInMilliseconds();
|
||||
std::unique_ptr<RtpPacketToSend> packet =
|
||||
BuildRtpPacket(kPayload, kMarkerBit, now_ms, now_ms);
|
||||
packet->set_allow_retransmission(true);
|
||||
rtp_sender_context_->packet_history_.PutRtpPacket(std::move(packet), now_ms);
|
||||
|
||||
// Send a packet and record its sequence numbers.
|
||||
SendGenericPacket();
|
||||
ASSERT_EQ(1u, transport_.sent_packets_.size());
|
||||
const uint16_t packet_seqence_number =
|
||||
transport_.sent_packets_.back().SequenceNumber();
|
||||
EXPECT_TRUE(rtp_sender_context_->packet_history_.GetPacketState(kSeqNum));
|
||||
|
||||
// Advance time and make sure it can be retransmitted, even if we try to set
|
||||
// the ssrc the what it already is.
|
||||
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.
|
||||
// Update the sequence number of the RTP module, verify packet has been
|
||||
// removed.
|
||||
rtp_sender()->SetSequenceNumber(rtp_sender()->SequenceNumber() - 1);
|
||||
time_controller_.AdvanceTime(TimeDelta::Millis(kRtt));
|
||||
EXPECT_EQ(rtp_sender()->ReSendPacket(packet_seqence_number), 0);
|
||||
EXPECT_FALSE(rtp_sender_context_->packet_history_.GetPacketState(kSeqNum));
|
||||
}
|
||||
|
||||
TEST_P(RtpSenderTest, IgnoresNackAfterDisablingMedia) {
|
||||
const int64_t kRtt = 10;
|
||||
|
||||
rtp_sender()->SetSendingMediaStatus(true);
|
||||
rtp_sender()->SetRtxStatus(kRtxRetransmitted | kRtxRedundantPayloads);
|
||||
rtp_sender()->SetRtxPayloadType(kRtxPayload, kPayload);
|
||||
rtp_sender_context_->packet_history_.SetStorePacketsStatus(
|
||||
RtpPacketHistory::StorageMode::kStoreAndCull, 10);
|
||||
EnableRtx();
|
||||
rtp_sender_context_->packet_history_.SetRtt(kRtt);
|
||||
|
||||
// Send a packet so it is in the packet history.
|
||||
std::unique_ptr<RtpPacketToSend> packet_to_pace;
|
||||
EXPECT_CALL(mock_paced_sender_, EnqueuePackets)
|
||||
.WillOnce([&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
|
||||
packet_to_pace = std::move(packets[0]);
|
||||
});
|
||||
// Put a packet in the history.
|
||||
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);
|
||||
rtp_sender_context_->packet_history_.PutRtpPacket(std::move(packet),
|
||||
start_time_ms);
|
||||
|
||||
SendGenericPacket();
|
||||
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.
|
||||
rtp_sender()->SetSendingMediaStatus(false);
|
||||
time_controller_.AdvanceTime(TimeDelta::Millis(kRtt));
|
||||
EXPECT_LT(rtp_sender()->ReSendPacket(kSeqNum), 0);
|
||||
// Disable media sending and try to retransmit the packet, it should fail.
|
||||
rtp_sender()->SetSendingMediaStatus(false);
|
||||
time_controller_.AdvanceTime(TimeDelta::Millis(kRtt));
|
||||
EXPECT_LT(rtp_sender()->ReSendPacket(kSeqNum), 0);
|
||||
}
|
||||
|
||||
TEST_P(RtpSenderTest, DoesntFecProtectRetransmissions) {
|
||||
|
@ -1916,25 +1855,20 @@ TEST_P(RtpSenderTest, DoesntFecProtectRetransmissions) {
|
|||
RtpPacketHistory::StorageMode::kStoreAndCull, 10);
|
||||
rtp_sender_context_->packet_history_.SetRtt(kRtt);
|
||||
|
||||
// Send a packet so it is in the packet history, make sure to mark it for
|
||||
// FEC protection.
|
||||
std::unique_ptr<RtpPacketToSend> packet_to_pace;
|
||||
EXPECT_CALL(mock_paced_sender_, EnqueuePackets)
|
||||
.WillOnce([&](std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
|
||||
packet_to_pace = std::move(packets[0]);
|
||||
});
|
||||
|
||||
SendGenericPacket();
|
||||
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());
|
||||
// Put a fec protected packet in the history.
|
||||
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_fec_protect_packet(true);
|
||||
rtp_sender_context_->packet_history_.PutRtpPacket(std::move(packet),
|
||||
start_time_ms);
|
||||
|
||||
// Re-send packet, the retransmitted packet should not have the FEC protection
|
||||
// flag set.
|
||||
EXPECT_CALL(mock_paced_sender_,
|
||||
EnqueuePackets(Each(Pointee(
|
||||
EnqueuePackets(ElementsAre(Pointee(
|
||||
Property(&RtpPacketToSend::fec_protect_packet, false)))));
|
||||
|
||||
time_controller_.AdvanceTime(TimeDelta::Millis(kRtt));
|
||||
|
|
Loading…
Reference in a new issue