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 // This test sends 1 regular video packet, then 4 padding packets, and then
// 1 more regular packet. // 1 more regular packet.
TEST_P(RtpSenderTest, SendPadding) { TEST_P(RtpSenderTest, SendPadding) {
// Make all (non-padding) packets go to send queue. constexpr int kNumPaddingPackets = 4;
EXPECT_CALL(mock_rtc_event_log_, EXPECT_CALL(mock_paced_sender_, EnqueuePackets);
LogProxy(SameRtcEventTypeAs(RtcEvent::Type::RtpPacketOutgoing))) std::unique_ptr<RtpPacketToSend> media_packet =
.Times(1 + 4 + 1); SendPacket(/*capture_time_ms=*/clock_->TimeInMilliseconds(),
/*payload_size=*/100);
uint16_t seq_num = kSeqNum; // Wait 50 ms before generating each padding packet.
uint32_t timestamp = kTimestamp; for (int i = 0; i < kNumPaddingPackets; ++i) {
rtp_sender_context_->packet_history_.SetStorePacketsStatus( time_controller_.AdvanceTime(TimeDelta::Millis(50));
RtpPacketHistory::StorageMode::kStoreAndCull, 10); const size_t kPaddingTargetBytes = 100; // Request 100 bytes of padding.
size_t rtp_header_len = kRtpHeaderSize; const size_t kMaxPaddingLength = 224; // Value taken from rtp_sender.cc.
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.
webrtc::RTPHeader rtp_header; // 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
int64_t capture_time_ms = clock_->TimeInMilliseconds(); // shall be that of the last media packet.
auto packet = EXPECT_CALL(mock_paced_sender_,
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( EnqueuePackets(Contains(AllOf(
Pointee(Property(&RtpPacketToSend::Ssrc, kSsrc)), Pointee(Property(&RtpPacketToSend::Ssrc, kSsrc)),
Pointee(Property(&RtpPacketToSend::SequenceNumber, kSeqNum)))))); Pointee(Property(&RtpPacketToSend::SequenceNumber,
packet->set_packet_type(RtpPacketMediaType::kVideo); media_packet->SequenceNumber() + i + 1)),
packet->set_allow_retransmission(true); Pointee(Property(&RtpPacketToSend::padding_size,
EXPECT_TRUE( kMaxPaddingLength)),
rtp_sender()->SendToNetwork(std::make_unique<RtpPacketToSend>(*packet))); Pointee(Property(&RtpPacketToSend::Timestamp,
EXPECT_EQ(total_packets_sent, transport_.packets_sent()); media_packet->Timestamp()))))));
time_controller_.AdvanceTime(TimeDelta::Millis(kStoredTimeInMs)); std::vector<std::unique_ptr<RtpPacketToSend>> padding_packets =
rtp_sender_context_->InjectPacket(std::move(packet), PacedPacketInfo()); rtp_sender()->GeneratePadding(kPaddingTargetBytes,
++seq_num; /*media_has_been_sent=*/true);
ASSERT_THAT(padding_packets, SizeIs(1));
// Packet should now be sent. This test doesn't verify the regular video rtp_sender()->SendToNetwork(std::move(padding_packets[0]));
// 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;
} }
// Send a regular video packet again. // Send a regular video packet again.
capture_time_ms = clock_->TimeInMilliseconds(); EXPECT_CALL(mock_paced_sender_,
packet = BuildRtpPacket(kPayload, kMarkerBit, timestamp, capture_time_ms);
packet_size = packet->size();
packet->set_packet_type(RtpPacketMediaType::kVideo);
packet->set_allow_retransmission(true);
EXPECT_CALL(
mock_paced_sender_,
EnqueuePackets(Contains(AllOf( EnqueuePackets(Contains(AllOf(
Pointee(Property(&RtpPacketToSend::Ssrc, kSsrc)), Pointee(Property(
Pointee(Property(&RtpPacketToSend::SequenceNumber, seq_num)))))); &RtpPacketToSend::SequenceNumber,
EXPECT_TRUE( media_packet->SequenceNumber() + kNumPaddingPackets + 1)),
rtp_sender()->SendToNetwork(std::make_unique<RtpPacketToSend>(*packet))); Pointee(Property(&RtpPacketToSend::Timestamp,
rtp_sender_context_->InjectPacket(std::move(packet), PacedPacketInfo()); Gt(media_packet->Timestamp())))))));
// Process send bucket. std::unique_ptr<RtpPacketToSend> next_media_packet =
EXPECT_EQ(++total_packets_sent, transport_.packets_sent()); SendPacket(/*capture_time_ms=*/clock_->TimeInMilliseconds(),
EXPECT_EQ(packet_size, transport_.last_sent_packet().size()); /*payload_size=*/100);
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);
} }
TEST_P(RtpSenderTest, OnSendPacketUpdated) { TEST_P(RtpSenderTest, OnSendPacketUpdated) {