webrtc_m130/modules/pacing/round_robin_packet_queue_unittest.cc
Henrik Boström ef241167a5 [SlackedPacer] Don't slack while retransmissions or audio is in queue.
This CL introduces PacketQueue::SizeInPacketsPerRtpPacketMediaType
keeping track of the number of packets in the queue per
RtpPacketMediaType.

The TaskQueuePacedSender is updated not to apply slack if the queue
contains any kRetransmission or kAudio packets. The hope is that not
slacking retransmissions will make the NACK/retransmission regression
of the SlackedPacer experiment go away. Wanting to not slack audio
packets is unrelated to the regression but a sensible thing to due
since audio is highest priority.

This CL does not change anything when the SlackedPacer experiment is
not running, since if its not running then none of the packets are
slacked.

Bug: webrtc:14161
Change-Id: I1e588599b6b64ebfd7d890706b6afd0b84fd746d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/265160
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37139}
2022-06-07 12:16:37 +00:00

99 lines
3.3 KiB
C++

/*
* Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/pacing/round_robin_packet_queue.h"
#include <utility>
#include "api/units/timestamp.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
#include "rtc_base/checks.h"
#include "test/gmock.h"
#include "test/gtest.h"
namespace webrtc {
namespace {
constexpr uint32_t kDefaultSsrc = 123;
constexpr int kDefaultPayloadSize = 321;
std::unique_ptr<RtpPacketToSend> CreatePacket(RtpPacketMediaType type,
uint16_t sequence_number) {
auto packet = std::make_unique<RtpPacketToSend>(/*extensions=*/nullptr);
packet->set_packet_type(type);
packet->SetSsrc(kDefaultSsrc);
packet->SetSequenceNumber(sequence_number);
packet->SetPayloadSize(kDefaultPayloadSize);
return packet;
}
} // namespace
TEST(RoundRobinPacketQueueTest,
PushAndPopUpdatesSizeInPacketsPerRtpPacketMediaType) {
Timestamp now = Timestamp::Zero();
RoundRobinPacketQueue queue(now);
// Initially all sizes are zero.
for (size_t i = 0; i < kNumMediaTypes; ++i) {
EXPECT_EQ(queue.SizeInPacketsPerRtpPacketMediaType()[i], 0);
}
// Push packets.
queue.Push(now, CreatePacket(RtpPacketMediaType::kAudio, 1));
EXPECT_EQ(queue.SizeInPacketsPerRtpPacketMediaType()[static_cast<size_t>(
RtpPacketMediaType::kAudio)],
1);
queue.Push(now, CreatePacket(RtpPacketMediaType::kVideo, 2));
EXPECT_EQ(queue.SizeInPacketsPerRtpPacketMediaType()[static_cast<size_t>(
RtpPacketMediaType::kVideo)],
1);
queue.Push(now, CreatePacket(RtpPacketMediaType::kRetransmission, 3));
EXPECT_EQ(queue.SizeInPacketsPerRtpPacketMediaType()[static_cast<size_t>(
RtpPacketMediaType::kRetransmission)],
1);
queue.Push(now, CreatePacket(RtpPacketMediaType::kForwardErrorCorrection, 4));
EXPECT_EQ(queue.SizeInPacketsPerRtpPacketMediaType()[static_cast<size_t>(
RtpPacketMediaType::kForwardErrorCorrection)],
1);
queue.Push(now, CreatePacket(RtpPacketMediaType::kPadding, 5));
EXPECT_EQ(queue.SizeInPacketsPerRtpPacketMediaType()[static_cast<size_t>(
RtpPacketMediaType::kPadding)],
1);
// Now all sizes are 1.
for (size_t i = 0; i < kNumMediaTypes; ++i) {
EXPECT_EQ(queue.SizeInPacketsPerRtpPacketMediaType()[i], 1);
}
// Popping happens in a priority order based on media type. This test does not
// assert what this order is, only that the counter for the popped packet's
// media type is decremented.
for (size_t i = 0; i < kNumMediaTypes; ++i) {
auto popped_packet = queue.Pop();
EXPECT_EQ(queue.SizeInPacketsPerRtpPacketMediaType()[static_cast<size_t>(
popped_packet->packet_type().value())],
0);
}
// We've popped all packets, so all sizes are zero.
for (size_t i = 0; i < kNumMediaTypes; ++i) {
EXPECT_EQ(queue.SizeInPacketsPerRtpPacketMediaType()[i], 0);
}
}
} // namespace webrtc