Reland "Reland "Refactors UlpFec and FlexFec to use a common interface.""

This is a reland of 49734dc0faa69616a58a1a95c7fc61a4610793cf

Patchset 2 contains a fix for the fuzzer set up. Since we now parse
an RtpPacket out of the fuzzer data, the header needs to be correct,
otherwise we fail before even reaching the FEC code that we actually
want to test.

Bug: webrtc:11340, chromium:1052323, chromium:1055974
TBR=stefan@webrtc.org

Original change's description:
> Reland "Refactors UlpFec and FlexFec to use a common interface."
>
> This is a reland of 11af1d7444fd7438766b7bc52cbd64752d72e32e
>
> Original change's description:
> > Refactors UlpFec and FlexFec to use a common interface.
> >
> > The new VideoFecGenerator is now injected into RtpSenderVideo,
> > and generalizes the usage.
> > This also prepares for being able to genera FEC in the RTP egress
> > module.
> >
> > Bug: webrtc:11340
> > Change-Id: I8aa873129b2fb4131eb3399ee88f6ea2747155a3
> > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168347
> > Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> > Reviewed-by: Sebastian Jansson <srte@webrtc.org>
> > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
> > Commit-Queue: Erik Språng <sprang@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#30515}
>
> Bug: webrtc:11340, chromium:1052323
> Change-Id: Id646047365f1c46cca9e6f3e8eefa5151207b4a0
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168608
> Commit-Queue: Erik Språng <sprang@webrtc.org>
> Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#30593}

Bug: webrtc:11340, chromium:1052323
Change-Id: Ib8925f44e2edfcfeadc95c845c3bfc23822604ed
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/169222
Commit-Queue: Erik Språng <sprang@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30724}
This commit is contained in:
Erik Språng
2020-03-05 10:14:04 +01:00
committed by Commit Bot
parent 269d68f521
commit f87536c9de
23 changed files with 578 additions and 563 deletions

View File

@ -35,11 +35,8 @@ void VerifyHeader(uint16_t seq_num,
uint32_t timestamp,
int red_payload_type,
int fec_payload_type,
RedPacket* packet,
bool marker_bit) {
EXPECT_GT(packet->length(), kRtpHeaderSize);
EXPECT_TRUE(packet->data() != NULL);
uint8_t* data = packet->data();
bool marker_bit,
const rtc::CopyOnWriteBuffer& data) {
// Marker bit not set.
EXPECT_EQ(marker_bit ? 0x80 : 0, data[1] & 0x80);
EXPECT_EQ(red_payload_type, data[1] & 0x7F);
@ -52,8 +49,12 @@ void VerifyHeader(uint16_t seq_num,
class UlpfecGeneratorTest : public ::testing::Test {
protected:
UlpfecGeneratorTest() : packet_generator_(kMediaSsrc) {}
UlpfecGeneratorTest()
: fake_clock_(1),
ulpfec_generator_(kRedPayloadType, kFecPayloadType, &fake_clock_),
packet_generator_(kMediaSsrc) {}
SimulatedClock fake_clock_;
UlpfecGenerator ulpfec_generator_;
AugmentedPacketGenerator packet_generator_;
};
@ -81,24 +82,22 @@ TEST_F(UlpfecGeneratorTest, NoEmptyFecWithSeqNumGaps) {
protected_packets.push_back({21, 0, 55, 0});
protected_packets.push_back({13, 3, 57, 1});
FecProtectionParams params = {117, 3, kFecMaskBursty};
ulpfec_generator_.SetFecParameters(params);
uint8_t packet[28] = {0};
ulpfec_generator_.SetProtectionParameters(params, params);
for (Packet p : protected_packets) {
if (p.marker_bit) {
packet[1] |= 0x80;
RtpPacketToSend packet(nullptr);
packet.SetMarker(p.marker_bit);
packet.AllocateExtension(RTPExtensionType::kRtpExtensionMid,
p.header_size - packet.headers_size());
packet.SetSequenceNumber(p.seq_num);
packet.AllocatePayload(p.payload_size);
ulpfec_generator_.AddPacketAndGenerateFec(packet);
std::vector<std::unique_ptr<RtpPacketToSend>> fec_packets =
ulpfec_generator_.GetFecPackets();
if (!p.marker_bit) {
EXPECT_TRUE(fec_packets.empty());
} else {
packet[1] &= ~0x80;
}
ByteWriter<uint16_t>::WriteBigEndian(&packet[2], p.seq_num);
ulpfec_generator_.AddRtpPacketAndGenerateFec(
rtc::CopyOnWriteBuffer(packet, p.payload_size + p.header_size),
p.header_size);
size_t num_fec_packets = ulpfec_generator_.NumAvailableFecPackets();
if (num_fec_packets > 0) {
std::vector<std::unique_ptr<RedPacket>> fec_packets =
ulpfec_generator_.GetUlpfecPacketsAsRed(kRedPayloadType,
kFecPayloadType, 100);
EXPECT_EQ(num_fec_packets, fec_packets.size());
EXPECT_FALSE(fec_packets.empty());
}
}
}
@ -113,24 +112,28 @@ TEST_F(UlpfecGeneratorTest, OneFrameFec) {
constexpr size_t kNumPackets = 4;
FecProtectionParams params = {15, 3, kFecMaskRandom};
packet_generator_.NewFrame(kNumPackets);
ulpfec_generator_.SetFecParameters(params); // Expecting one FEC packet.
// Expecting one FEC packet.
ulpfec_generator_.SetProtectionParameters(params, params);
uint32_t last_timestamp = 0;
for (size_t i = 0; i < kNumPackets; ++i) {
std::unique_ptr<AugmentedPacket> packet =
packet_generator_.NextPacket(i, 10);
EXPECT_EQ(0, ulpfec_generator_.AddRtpPacketAndGenerateFec(packet->data,
kRtpHeaderSize));
RtpPacketToSend rtp_packet(nullptr);
EXPECT_TRUE(rtp_packet.Parse(packet->data.data(), packet->data.size()));
ulpfec_generator_.AddPacketAndGenerateFec(rtp_packet);
last_timestamp = packet->header.timestamp;
}
EXPECT_TRUE(ulpfec_generator_.FecAvailable());
const uint16_t seq_num = packet_generator_.NextPacketSeqNum();
std::vector<std::unique_ptr<RedPacket>> red_packets =
ulpfec_generator_.GetUlpfecPacketsAsRed(kRedPayloadType, kFecPayloadType,
seq_num);
EXPECT_FALSE(ulpfec_generator_.FecAvailable());
ASSERT_EQ(1u, red_packets.size());
VerifyHeader(seq_num, last_timestamp, kRedPayloadType, kFecPayloadType,
red_packets.front().get(), false);
std::vector<std::unique_ptr<RtpPacketToSend>> fec_packets =
ulpfec_generator_.GetFecPackets();
EXPECT_EQ(fec_packets.size(), 1u);
uint16_t seq_num = packet_generator_.NextPacketSeqNum();
fec_packets[0]->SetSequenceNumber(seq_num);
EXPECT_TRUE(ulpfec_generator_.GetFecPackets().empty());
EXPECT_EQ(fec_packets[0]->headers_size(), kRtpHeaderSize);
VerifyHeader(seq_num, last_timestamp, kRedPayloadType, kFecPayloadType, false,
fec_packets[0]->Buffer());
}
TEST_F(UlpfecGeneratorTest, TwoFrameFec) {
@ -145,27 +148,27 @@ TEST_F(UlpfecGeneratorTest, TwoFrameFec) {
constexpr size_t kNumFrames = 2;
FecProtectionParams params = {15, 3, kFecMaskRandom};
ulpfec_generator_.SetFecParameters(params); // Expecting one FEC packet.
// Expecting one FEC packet.
ulpfec_generator_.SetProtectionParameters(params, params);
uint32_t last_timestamp = 0;
for (size_t i = 0; i < kNumFrames; ++i) {
packet_generator_.NewFrame(kNumPackets);
for (size_t j = 0; j < kNumPackets; ++j) {
std::unique_ptr<AugmentedPacket> packet =
packet_generator_.NextPacket(i * kNumPackets + j, 10);
EXPECT_EQ(0, ulpfec_generator_.AddRtpPacketAndGenerateFec(
packet->data, kRtpHeaderSize));
RtpPacketToSend rtp_packet(nullptr);
EXPECT_TRUE(rtp_packet.Parse(packet->data.data(), packet->data.size()));
ulpfec_generator_.AddPacketAndGenerateFec(rtp_packet);
last_timestamp = packet->header.timestamp;
}
}
EXPECT_TRUE(ulpfec_generator_.FecAvailable());
std::vector<std::unique_ptr<RtpPacketToSend>> fec_packets =
ulpfec_generator_.GetFecPackets();
EXPECT_EQ(fec_packets.size(), 1u);
const uint16_t seq_num = packet_generator_.NextPacketSeqNum();
std::vector<std::unique_ptr<RedPacket>> red_packets =
ulpfec_generator_.GetUlpfecPacketsAsRed(kRedPayloadType, kFecPayloadType,
seq_num);
EXPECT_FALSE(ulpfec_generator_.FecAvailable());
ASSERT_EQ(1u, red_packets.size());
VerifyHeader(seq_num, last_timestamp, kRedPayloadType, kFecPayloadType,
red_packets.front().get(), false);
fec_packets[0]->SetSequenceNumber(seq_num);
VerifyHeader(seq_num, last_timestamp, kRedPayloadType, kFecPayloadType, false,
fec_packets[0]->Buffer());
}
TEST_F(UlpfecGeneratorTest, MixedMediaRtpHeaderLengths) {
@ -174,34 +177,43 @@ TEST_F(UlpfecGeneratorTest, MixedMediaRtpHeaderLengths) {
// Only one frame required to generate FEC.
FecProtectionParams params = {127, 1, kFecMaskRandom};
ulpfec_generator_.SetFecParameters(params);
ulpfec_generator_.SetProtectionParameters(params, params);
// Fill up internal buffer with media packets with short RTP header length.
packet_generator_.NewFrame(kUlpfecMaxMediaPackets + 1);
for (size_t i = 0; i < kUlpfecMaxMediaPackets; ++i) {
std::unique_ptr<AugmentedPacket> packet =
packet_generator_.NextPacket(i, 10);
EXPECT_EQ(0, ulpfec_generator_.AddRtpPacketAndGenerateFec(
packet->data, kShortRtpHeaderLength));
EXPECT_FALSE(ulpfec_generator_.FecAvailable());
RtpPacketToSend rtp_packet(nullptr);
EXPECT_TRUE(rtp_packet.Parse(packet->data.data(), packet->data.size()));
EXPECT_EQ(rtp_packet.headers_size(), kShortRtpHeaderLength);
ulpfec_generator_.AddPacketAndGenerateFec(rtp_packet);
EXPECT_TRUE(ulpfec_generator_.GetFecPackets().empty());
}
// Kick off FEC generation with media packet with long RTP header length.
// Since the internal buffer is full, this packet will not be protected.
std::unique_ptr<AugmentedPacket> packet =
packet_generator_.NextPacket(kUlpfecMaxMediaPackets, 10);
EXPECT_EQ(0, ulpfec_generator_.AddRtpPacketAndGenerateFec(
packet->data, kLongRtpHeaderLength));
EXPECT_TRUE(ulpfec_generator_.FecAvailable());
RtpPacketToSend rtp_packet(nullptr);
EXPECT_TRUE(rtp_packet.Parse(packet->data.data(), packet->data.size()));
EXPECT_TRUE(rtp_packet.SetPayloadSize(0) != nullptr);
const uint32_t csrcs[]{1};
rtp_packet.SetCsrcs(csrcs);
EXPECT_EQ(rtp_packet.headers_size(), kLongRtpHeaderLength);
ulpfec_generator_.AddPacketAndGenerateFec(rtp_packet);
std::vector<std::unique_ptr<RtpPacketToSend>> fec_packets =
ulpfec_generator_.GetFecPackets();
EXPECT_FALSE(fec_packets.empty());
// Ensure that the RED header is placed correctly, i.e. the correct
// RTP header length was used in the RED packet creation.
const uint16_t seq_num = packet_generator_.NextPacketSeqNum();
std::vector<std::unique_ptr<RedPacket>> red_packets =
ulpfec_generator_.GetUlpfecPacketsAsRed(kRedPayloadType, kFecPayloadType,
seq_num);
for (const auto& red_packet : red_packets) {
EXPECT_EQ(kFecPayloadType, red_packet->data()[kShortRtpHeaderLength]);
uint16_t seq_num = packet_generator_.NextPacketSeqNum();
for (const auto& fec_packet : fec_packets) {
fec_packet->SetSequenceNumber(seq_num++);
EXPECT_EQ(kFecPayloadType, fec_packet->data()[kShortRtpHeaderLength]);
}
}