Refactor RtpSenderTest.SendPadding.

Simplifies the test so that it only tests the padding-related parts.
Header extensions for padding already has a dedicated test, as does
packet stats from RtpSenderEgress.

Bug: webrtc:11340
Change-Id: I88829409aac15f0aad0d4d634114731e819574bd
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/218844
Commit-Queue: Erik Språng <sprang@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34019}
This commit is contained in:
Erik Språng
2021-05-17 14:54:02 +02:00
committed by WebRTC LUCI CQ
parent 36b7d10a1f
commit 7a86aadf3d

View File

@ -653,113 +653,49 @@ TEST_P(RtpSenderTest, TrafficSmoothingRetransmits) {
// This test sends 1 regular video packet, then 4 padding packets, and then
// 1 more regular packet.
TEST_P(RtpSenderTest, SendPadding) {
// Make all (non-padding) packets go to send queue.
EXPECT_CALL(mock_rtc_event_log_,
LogProxy(SameRtcEventTypeAs(RtcEvent::Type::RtpPacketOutgoing)))
.Times(1 + 4 + 1);
constexpr int kNumPaddingPackets = 4;
EXPECT_CALL(mock_paced_sender_, EnqueuePackets);
std::unique_ptr<RtpPacketToSend> media_packet =
SendPacket(/*capture_time_ms=*/clock_->TimeInMilliseconds(),
/*payload_size=*/100);
uint16_t seq_num = kSeqNum;
uint32_t timestamp = kTimestamp;
rtp_sender_context_->packet_history_.SetStorePacketsStatus(
RtpPacketHistory::StorageMode::kStoreAndCull, 10);
size_t rtp_header_len = kRtpHeaderSize;
EXPECT_TRUE(rtp_sender()->RegisterRtpHeaderExtension(
TransmissionOffset::kUri, kTransmissionTimeOffsetExtensionId));
rtp_header_len += 4; // 4 bytes extension.
EXPECT_TRUE(rtp_sender()->RegisterRtpHeaderExtension(
AbsoluteSendTime::kUri, kAbsoluteSendTimeExtensionId));
rtp_header_len += 4; // 4 bytes extension.
rtp_header_len += 4; // 4 extra bytes common to all extension headers.
// Wait 50 ms before generating each padding packet.
for (int i = 0; i < kNumPaddingPackets; ++i) {
time_controller_.AdvanceTime(TimeDelta::Millis(50));
const size_t kPaddingTargetBytes = 100; // Request 100 bytes of padding.
const size_t kMaxPaddingLength = 224; // Value taken from rtp_sender.cc.
webrtc::RTPHeader rtp_header;
int64_t capture_time_ms = clock_->TimeInMilliseconds();
auto packet =
BuildRtpPacket(kPayload, kMarkerBit, timestamp, capture_time_ms);
const uint32_t media_packet_timestamp = timestamp;
size_t packet_size = packet->size();
int total_packets_sent = 0;
const int kStoredTimeInMs = 100;
// Packet should be stored in a send bucket.
EXPECT_CALL(
mock_paced_sender_,
EnqueuePackets(Contains(AllOf(
Pointee(Property(&RtpPacketToSend::Ssrc, kSsrc)),
Pointee(Property(&RtpPacketToSend::SequenceNumber, kSeqNum))))));
packet->set_packet_type(RtpPacketMediaType::kVideo);
packet->set_allow_retransmission(true);
EXPECT_TRUE(
rtp_sender()->SendToNetwork(std::make_unique<RtpPacketToSend>(*packet)));
EXPECT_EQ(total_packets_sent, transport_.packets_sent());
time_controller_.AdvanceTime(TimeDelta::Millis(kStoredTimeInMs));
rtp_sender_context_->InjectPacket(std::move(packet), PacedPacketInfo());
++seq_num;
// Packet should now be sent. This test doesn't verify the regular video
// packet, since it is tested in another test.
EXPECT_EQ(++total_packets_sent, transport_.packets_sent());
timestamp += 90 * kStoredTimeInMs;
// Send padding 4 times, waiting 50 ms between each.
for (int i = 0; i < 4; ++i) {
const int kPaddingPeriodMs = 50;
const size_t kPaddingBytes = 100;
const size_t kMaxPaddingLength = 224; // Value taken from rtp_sender.cc.
// Padding will be forced to full packets.
EXPECT_EQ(kMaxPaddingLength, GenerateAndSendPadding(kPaddingBytes));
// Process send bucket. Padding should now be sent.
EXPECT_EQ(++total_packets_sent, transport_.packets_sent());
EXPECT_EQ(kMaxPaddingLength + rtp_header_len,
transport_.last_sent_packet().size());
transport_.last_sent_packet().GetHeader(&rtp_header);
EXPECT_EQ(kMaxPaddingLength, rtp_header.paddingLength);
// Verify sequence number and timestamp. The timestamp should be the same
// as the last media packet.
EXPECT_EQ(seq_num++, rtp_header.sequenceNumber);
EXPECT_EQ(media_packet_timestamp, rtp_header.timestamp);
// Verify transmission time offset.
int offset = timestamp - media_packet_timestamp;
EXPECT_EQ(offset, rtp_header.extension.transmissionTimeOffset);
uint64_t expected_send_time =
ConvertMsToAbsSendTime(clock_->TimeInMilliseconds());
EXPECT_EQ(expected_send_time, rtp_header.extension.absoluteSendTime);
time_controller_.AdvanceTime(TimeDelta::Millis(kPaddingPeriodMs));
timestamp += 90 * kPaddingPeriodMs;
// Padding should be sent on the media ssrc, with a continous sequence
// number range. Size will be forced to full pack size and the timestamp
// shall be that of the last media packet.
EXPECT_CALL(mock_paced_sender_,
EnqueuePackets(Contains(AllOf(
Pointee(Property(&RtpPacketToSend::Ssrc, kSsrc)),
Pointee(Property(&RtpPacketToSend::SequenceNumber,
media_packet->SequenceNumber() + i + 1)),
Pointee(Property(&RtpPacketToSend::padding_size,
kMaxPaddingLength)),
Pointee(Property(&RtpPacketToSend::Timestamp,
media_packet->Timestamp()))))));
std::vector<std::unique_ptr<RtpPacketToSend>> padding_packets =
rtp_sender()->GeneratePadding(kPaddingTargetBytes,
/*media_has_been_sent=*/true);
ASSERT_THAT(padding_packets, SizeIs(1));
rtp_sender()->SendToNetwork(std::move(padding_packets[0]));
}
// Send a regular video packet again.
capture_time_ms = clock_->TimeInMilliseconds();
packet = BuildRtpPacket(kPayload, kMarkerBit, timestamp, capture_time_ms);
packet_size = packet->size();
EXPECT_CALL(mock_paced_sender_,
EnqueuePackets(Contains(AllOf(
Pointee(Property(
&RtpPacketToSend::SequenceNumber,
media_packet->SequenceNumber() + kNumPaddingPackets + 1)),
Pointee(Property(&RtpPacketToSend::Timestamp,
Gt(media_packet->Timestamp())))))));
packet->set_packet_type(RtpPacketMediaType::kVideo);
packet->set_allow_retransmission(true);
EXPECT_CALL(
mock_paced_sender_,
EnqueuePackets(Contains(AllOf(
Pointee(Property(&RtpPacketToSend::Ssrc, kSsrc)),
Pointee(Property(&RtpPacketToSend::SequenceNumber, seq_num))))));
EXPECT_TRUE(
rtp_sender()->SendToNetwork(std::make_unique<RtpPacketToSend>(*packet)));
rtp_sender_context_->InjectPacket(std::move(packet), PacedPacketInfo());
// Process send bucket.
EXPECT_EQ(++total_packets_sent, transport_.packets_sent());
EXPECT_EQ(packet_size, transport_.last_sent_packet().size());
transport_.last_sent_packet().GetHeader(&rtp_header);
// Verify sequence number and timestamp.
EXPECT_EQ(seq_num, rtp_header.sequenceNumber);
EXPECT_EQ(timestamp, rtp_header.timestamp);
// Verify transmission time offset. This packet is sent without delay.
EXPECT_EQ(0, rtp_header.extension.transmissionTimeOffset);
uint64_t expected_send_time =
ConvertMsToAbsSendTime(clock_->TimeInMilliseconds());
EXPECT_EQ(expected_send_time, rtp_header.extension.absoluteSendTime);
std::unique_ptr<RtpPacketToSend> next_media_packet =
SendPacket(/*capture_time_ms=*/clock_->TimeInMilliseconds(),
/*payload_size=*/100);
}
TEST_P(RtpSenderTest, OnSendPacketUpdated) {