Index: webrtc/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc |
diff --git a/webrtc/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc b/webrtc/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc |
index 8bf0f3701fa2b3ba38d1eb84f82299cf075e6f54..8b46878e2d9d9b6fa4211691356d168060a49dc4 100644 |
--- a/webrtc/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc |
+++ b/webrtc/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc |
@@ -16,7 +16,6 @@ |
#include "webrtc/modules/rtp_rtcp/mocks/mock_recovered_packet_receiver.h" |
#include "webrtc/modules/rtp_rtcp/source/fec_test_helper.h" |
#include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" |
-#include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" |
#include "webrtc/test/gmock.h" |
#include "webrtc/test/gtest.h" |
@@ -36,12 +35,6 @@ |
constexpr size_t kPayloadLength = 500; |
constexpr uint32_t kFlexfecSsrc = 42984; |
constexpr uint32_t kMediaSsrc = 8353; |
- |
-RtpPacketReceived ParsePacket(const Packet& packet) { |
- RtpPacketReceived parsed_packet; |
- EXPECT_TRUE(parsed_packet.Parse(packet.data, packet.length)); |
- return parsed_packet; |
-} |
} // namespace |
@@ -100,8 +93,21 @@ |
std::unique_ptr<Packet> media_packet( |
packet_generator_.NextPacket(0, kPayloadLength)); |
- EXPECT_TRUE( |
- receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_packet))); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
+ media_packet->length)); |
+} |
+ |
+TEST_F(FlexfecReceiverTest, FailsOnTruncatedMediaPacket) { |
+ const size_t kNoPayload = 0; |
+ |
+ packet_generator_.NewFrame(1); |
+ std::unique_ptr<Packet> media_packet( |
+ packet_generator_.NextPacket(0, kNoPayload)); |
+ // Simulate truncated media packet. |
+ media_packet->length = kRtpHeaderSize - 1; |
+ |
+ EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
+ media_packet->length)); |
} |
TEST_F(FlexfecReceiverTest, ReceivesMediaAndFecPackets) { |
@@ -111,12 +117,13 @@ |
PacketList media_packets; |
PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
- const auto& media_packet = media_packets.front(); |
+ auto media_packet = media_packets.front().get(); |
auto fec_packet = packet_generator_.BuildFlexfecPacket(*fec_packets.front()); |
- EXPECT_TRUE( |
- receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_packet))); |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(*fec_packet))); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
+ media_packet->length)); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(fec_packet->data, |
+ fec_packet->length)); |
} |
TEST_F(FlexfecReceiverTest, FailsOnTruncatedFecPacket) { |
@@ -126,14 +133,15 @@ |
PacketList media_packets; |
PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
- const auto& media_packet = media_packets.front(); |
+ auto media_packet = media_packets.front().get(); |
// Simulate truncated FlexFEC payload. |
fec_packets.front()->length = 1; |
auto fec_packet = packet_generator_.BuildFlexfecPacket(*fec_packets.front()); |
- EXPECT_TRUE( |
- receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_packet))); |
- EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(ParsePacket(*fec_packet))); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
+ media_packet->length)); |
+ EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(fec_packet->data, |
+ fec_packet->length)); |
} |
TEST_F(FlexfecReceiverTest, FailsOnUnknownMediaSsrc) { |
@@ -141,15 +149,15 @@ |
PacketList media_packets; |
PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
- auto& media_packet = media_packets.front(); |
+ auto media_packet = media_packets.front().get(); |
// Corrupt the SSRC. |
media_packet->data[8] = 0; |
media_packet->data[9] = 1; |
media_packet->data[10] = 2; |
media_packet->data[11] = 3; |
- EXPECT_FALSE( |
- receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_packet))); |
+ EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
+ media_packet->length)); |
} |
TEST_F(FlexfecReceiverTest, FailsOnUnknownFecSsrc) { |
@@ -159,7 +167,7 @@ |
PacketList media_packets; |
PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
- const auto& media_packet = media_packets.front(); |
+ auto media_packet = media_packets.front().get(); |
auto fec_packet = packet_generator_.BuildFlexfecPacket(*fec_packets.front()); |
// Corrupt the SSRC. |
fec_packet->data[8] = 4; |
@@ -167,9 +175,10 @@ |
fec_packet->data[10] = 6; |
fec_packet->data[11] = 7; |
- EXPECT_TRUE( |
- receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_packet))); |
- EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(ParsePacket(*fec_packet))); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
+ media_packet->length)); |
+ EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(fec_packet->data, |
+ fec_packet->length)); |
} |
TEST_F(FlexfecReceiverTest, ReceivesMultiplePackets) { |
@@ -182,8 +191,8 @@ |
// Receive all media packets. |
for (const auto& media_packet : media_packets) { |
- EXPECT_TRUE( |
- receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_packet))); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
+ media_packet->length)); |
} |
// Receive FEC packet. |
@@ -191,7 +200,7 @@ |
std::unique_ptr<Packet> packet_with_rtp_header = |
packet_generator_.BuildFlexfecPacket(*fec_packet); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- ParsePacket(*packet_with_rtp_header))); |
+ packet_with_rtp_header->data, packet_with_rtp_header->length)); |
} |
TEST_F(FlexfecReceiverTest, RecoversFromSingleMediaLoss) { |
@@ -204,7 +213,8 @@ |
// Receive first media packet but drop second. |
auto media_it = media_packets.begin(); |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_it))); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
+ (*media_it)->length)); |
// Receive FEC packet and ensure recovery of lost media packet. |
auto fec_it = fec_packets.begin(); |
@@ -217,7 +227,7 @@ |
Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
.WillOnce(Return(true)); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- ParsePacket(*packet_with_rtp_header))); |
+ packet_with_rtp_header->data, packet_with_rtp_header->length)); |
} |
TEST_F(FlexfecReceiverTest, RecoversFromDoubleMediaLoss) { |
@@ -241,7 +251,7 @@ |
Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
.WillOnce(Return(true)); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- ParsePacket(*packet_with_rtp_header))); |
+ packet_with_rtp_header->data, packet_with_rtp_header->length)); |
// Receive second FEC packet and recover second lost media packet. |
fec_it++; |
@@ -253,7 +263,7 @@ |
Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
.WillOnce(Return(true)); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- ParsePacket(*packet_with_rtp_header))); |
+ packet_with_rtp_header->data, packet_with_rtp_header->length)); |
} |
TEST_F(FlexfecReceiverTest, DoesNotRecoverFromMediaAndFecLoss) { |
@@ -266,7 +276,8 @@ |
// Receive first media packet. |
auto media_it = media_packets.begin(); |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_it))); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
+ (*media_it)->length)); |
// Drop second media packet and FEC packet. Do not expect call back. |
} |
@@ -281,7 +292,8 @@ |
// Receive first media packet but drop second. |
auto media_it = media_packets.begin(); |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_it))); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
+ (*media_it)->length)); |
// Receive FEC packet and ensure recovery of lost media packet. |
auto fec_it = fec_packets.begin(); |
@@ -294,11 +306,11 @@ |
Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
.WillOnce(Return(true)); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- ParsePacket(*packet_with_rtp_header))); |
+ packet_with_rtp_header->data, packet_with_rtp_header->length)); |
// Receive FEC packet again. |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- ParsePacket(*packet_with_rtp_header))); |
+ packet_with_rtp_header->data, packet_with_rtp_header->length)); |
// Do not call back again. |
} |
@@ -320,7 +332,8 @@ |
// Drop every second media packet. |
auto media_it = media_packets.begin(); |
while (media_it != media_packets.end()) { |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_it))); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
+ (*media_it)->length)); |
++media_it; |
if (media_it == media_packets.end()) { |
break; |
@@ -343,7 +356,7 @@ |
ElementsAreArray((*media_it)->data, (*media_it)->length))) |
.WillOnce(Return(true)); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- ParsePacket(*fec_packet_with_rtp_header))); |
+ fec_packet_with_rtp_header->data, fec_packet_with_rtp_header->length)); |
++media_it; |
} |
} |
@@ -370,7 +383,8 @@ |
// Receive all other media packets. |
while (media_it != media_packets.end()) { |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_it))); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
+ (*media_it)->length)); |
++media_it; |
} |
@@ -385,7 +399,7 @@ |
Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
.WillOnce(Return(true)); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- ParsePacket(*packet_with_rtp_header))); |
+ packet_with_rtp_header->data, packet_with_rtp_header->length)); |
} |
TEST_F(FlexfecReceiverTest, TooDelayedFecPacketDoesNotHelp) { |
@@ -410,7 +424,8 @@ |
// Receive all other media packets. |
while (media_it != media_packets.end()) { |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_it))); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
+ (*media_it)->length)); |
++media_it; |
} |
@@ -419,7 +434,7 @@ |
std::unique_ptr<Packet> packet_with_rtp_header = |
packet_generator_.BuildFlexfecPacket(**fec_it); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- ParsePacket(*packet_with_rtp_header))); |
+ packet_with_rtp_header->data, packet_with_rtp_header->length)); |
// Do not expect a call back. |
} |
@@ -440,14 +455,14 @@ |
auto media_packet3 = media_it++; |
auto media_packet4 = media_it++; |
auto media_packet5 = media_it++; |
- EXPECT_TRUE( |
- receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_packet5))); |
- EXPECT_TRUE( |
- receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_packet2))); |
- EXPECT_TRUE( |
- receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_packet3))); |
- EXPECT_TRUE( |
- receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_packet0))); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_packet5)->data, |
+ (*media_packet5)->length)); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_packet2)->data, |
+ (*media_packet2)->length)); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_packet3)->data, |
+ (*media_packet3)->length)); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_packet0)->data, |
+ (*media_packet0)->length)); |
// Expect to recover lost media packets. |
EXPECT_CALL(recovered_packet_receiver_, |
@@ -467,7 +482,7 @@ |
while (fec_it != fec_packets.end()) { |
packet_with_rtp_header = packet_generator_.BuildFlexfecPacket(**fec_it); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- ParsePacket(*packet_with_rtp_header))); |
+ packet_with_rtp_header->data, packet_with_rtp_header->length)); |
++fec_it; |
} |
} |
@@ -482,7 +497,8 @@ |
// Receive first media packet but drop second. |
auto media_it = media_packets.begin(); |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_it))); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
+ (*media_it)->length)); |
// Receive FEC packet and ensure recovery of lost media packet. |
auto fec_it = fec_packets.begin(); |
@@ -495,7 +511,7 @@ |
Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
.WillOnce(Return(true)); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- ParsePacket(*packet_with_rtp_header))); |
+ packet_with_rtp_header->data, packet_with_rtp_header->length)); |
// Check stats calculations. |
FecPacketCounter packet_counter = receiver_.GetPacketCounter(); |