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 8b46878e2d9d9b6fa4211691356d168060a49dc4..459c616d6f4bbe309f7b40520a6e2e8b7afd1c7f 100644 |
--- a/webrtc/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc |
+++ b/webrtc/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc |
@@ -12,10 +12,14 @@ |
#include <memory> |
#include "webrtc/base/basictypes.h" |
+#include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitrate_estimator.h" |
#include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" |
#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_header_extension.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" |
#include "webrtc/test/gmock.h" |
#include "webrtc/test/gtest.h" |
@@ -27,6 +31,7 @@ using ::testing::_; |
using ::testing::Args; |
using ::testing::ElementsAreArray; |
using ::testing::Return; |
+using ::testing::SaveArg; |
using test::fec::FlexfecPacketGenerator; |
using Packet = ForwardErrorCorrection::Packet; |
@@ -36,12 +41,22 @@ constexpr size_t kPayloadLength = 500; |
constexpr uint32_t kFlexfecSsrc = 42984; |
constexpr uint32_t kMediaSsrc = 8353; |
+template <typename T> |
+RtpPacketReceived ParsePacket(const std::unique_ptr<T>& packet) { |
danilchap
2016/12/13 14:11:24
probably better to use const reference to object t
brandtr
2016/12/14 12:55:49
Done. Could remove the templatization then too :)
|
+ RtpPacketReceived parsed_packet(nullptr); |
+ RTC_DCHECK(parsed_packet.Parse(packet->data, packet->length)); |
+ return parsed_packet; |
+} |
+ |
} // namespace |
class FlexfecReceiverTest : public ::testing::Test { |
protected: |
FlexfecReceiverTest() |
- : receiver_(kFlexfecSsrc, kMediaSsrc, &recovered_packet_receiver_), |
+ : receiver_(kFlexfecSsrc, |
+ kMediaSsrc, |
+ &recovered_packet_receiver_, |
+ &remote_bitrate_estimator_), |
erasure_code_(ForwardErrorCorrection::CreateFlexfec()), |
packet_generator_(kMediaSsrc, kFlexfecSsrc) {} |
@@ -59,6 +74,7 @@ class FlexfecReceiverTest : public ::testing::Test { |
FlexfecPacketGenerator packet_generator_; |
testing::StrictMock<MockRecoveredPacketReceiver> recovered_packet_receiver_; |
+ MockRemoteBitrateEstimator remote_bitrate_estimator_; |
}; |
void FlexfecReceiverTest::PacketizeFrame(size_t num_media_packets, |
@@ -93,21 +109,7 @@ TEST_F(FlexfecReceiverTest, ReceivesMediaPacket) { |
std::unique_ptr<Packet> media_packet( |
packet_generator_.NextPacket(0, kPayloadLength)); |
- 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)); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(media_packet))); |
} |
TEST_F(FlexfecReceiverTest, ReceivesMediaAndFecPackets) { |
@@ -117,13 +119,11 @@ TEST_F(FlexfecReceiverTest, ReceivesMediaAndFecPackets) { |
PacketList media_packets; |
PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
- auto media_packet = media_packets.front().get(); |
+ const auto& media_packet = media_packets.front(); |
auto fec_packet = packet_generator_.BuildFlexfecPacket(*fec_packets.front()); |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
- media_packet->length)); |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(fec_packet->data, |
- fec_packet->length)); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(media_packet))); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(fec_packet))); |
} |
TEST_F(FlexfecReceiverTest, FailsOnTruncatedFecPacket) { |
@@ -133,15 +133,13 @@ TEST_F(FlexfecReceiverTest, FailsOnTruncatedFecPacket) { |
PacketList media_packets; |
PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
- auto media_packet = media_packets.front().get(); |
+ const auto& media_packet = media_packets.front(); |
// Simulate truncated FlexFEC payload. |
fec_packets.front()->length = 1; |
auto fec_packet = packet_generator_.BuildFlexfecPacket(*fec_packets.front()); |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
- media_packet->length)); |
- EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(fec_packet->data, |
- fec_packet->length)); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(media_packet))); |
+ EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(ParsePacket(fec_packet))); |
} |
TEST_F(FlexfecReceiverTest, FailsOnUnknownMediaSsrc) { |
@@ -149,15 +147,15 @@ TEST_F(FlexfecReceiverTest, FailsOnUnknownMediaSsrc) { |
PacketList media_packets; |
PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
- auto media_packet = media_packets.front().get(); |
+ auto& media_packet = media_packets.front(); |
// 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(media_packet->data, |
- media_packet->length)); |
+ EXPECT_FALSE( |
+ receiver_.AddAndProcessReceivedPacket(ParsePacket(media_packet))); |
} |
TEST_F(FlexfecReceiverTest, FailsOnUnknownFecSsrc) { |
@@ -167,7 +165,7 @@ TEST_F(FlexfecReceiverTest, FailsOnUnknownFecSsrc) { |
PacketList media_packets; |
PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
- auto media_packet = media_packets.front().get(); |
+ const auto& media_packet = media_packets.front(); |
auto fec_packet = packet_generator_.BuildFlexfecPacket(*fec_packets.front()); |
// Corrupt the SSRC. |
fec_packet->data[8] = 4; |
@@ -175,10 +173,8 @@ TEST_F(FlexfecReceiverTest, FailsOnUnknownFecSsrc) { |
fec_packet->data[10] = 6; |
fec_packet->data[11] = 7; |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
- media_packet->length)); |
- EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(fec_packet->data, |
- fec_packet->length)); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(media_packet))); |
+ EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(ParsePacket(fec_packet))); |
} |
TEST_F(FlexfecReceiverTest, ReceivesMultiplePackets) { |
@@ -191,8 +187,8 @@ TEST_F(FlexfecReceiverTest, ReceivesMultiplePackets) { |
// Receive all media packets. |
for (const auto& media_packet : media_packets) { |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
- media_packet->length)); |
+ EXPECT_TRUE( |
+ receiver_.AddAndProcessReceivedPacket(ParsePacket(media_packet))); |
} |
// Receive FEC packet. |
@@ -200,7 +196,7 @@ TEST_F(FlexfecReceiverTest, ReceivesMultiplePackets) { |
std::unique_ptr<Packet> packet_with_rtp_header = |
packet_generator_.BuildFlexfecPacket(*fec_packet); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- packet_with_rtp_header->data, packet_with_rtp_header->length)); |
+ ParsePacket(packet_with_rtp_header))); |
} |
TEST_F(FlexfecReceiverTest, RecoversFromSingleMediaLoss) { |
@@ -213,8 +209,7 @@ TEST_F(FlexfecReceiverTest, RecoversFromSingleMediaLoss) { |
// Receive first media packet but drop second. |
auto media_it = media_packets.begin(); |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
- (*media_it)->length)); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_it))); |
// Receive FEC packet and ensure recovery of lost media packet. |
auto fec_it = fec_packets.begin(); |
@@ -227,7 +222,7 @@ TEST_F(FlexfecReceiverTest, RecoversFromSingleMediaLoss) { |
Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
.WillOnce(Return(true)); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- packet_with_rtp_header->data, packet_with_rtp_header->length)); |
+ ParsePacket(packet_with_rtp_header))); |
} |
TEST_F(FlexfecReceiverTest, RecoversFromDoubleMediaLoss) { |
@@ -251,7 +246,7 @@ TEST_F(FlexfecReceiverTest, RecoversFromDoubleMediaLoss) { |
Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
.WillOnce(Return(true)); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- packet_with_rtp_header->data, packet_with_rtp_header->length)); |
+ ParsePacket(packet_with_rtp_header))); |
// Receive second FEC packet and recover second lost media packet. |
fec_it++; |
@@ -263,7 +258,7 @@ TEST_F(FlexfecReceiverTest, RecoversFromDoubleMediaLoss) { |
Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
.WillOnce(Return(true)); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- packet_with_rtp_header->data, packet_with_rtp_header->length)); |
+ ParsePacket(packet_with_rtp_header))); |
} |
TEST_F(FlexfecReceiverTest, DoesNotRecoverFromMediaAndFecLoss) { |
@@ -276,8 +271,7 @@ TEST_F(FlexfecReceiverTest, DoesNotRecoverFromMediaAndFecLoss) { |
// Receive first media packet. |
auto media_it = media_packets.begin(); |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
- (*media_it)->length)); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_it))); |
// Drop second media packet and FEC packet. Do not expect call back. |
} |
@@ -292,8 +286,7 @@ TEST_F(FlexfecReceiverTest, DoesNotCallbackTwice) { |
// Receive first media packet but drop second. |
auto media_it = media_packets.begin(); |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
- (*media_it)->length)); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_it))); |
// Receive FEC packet and ensure recovery of lost media packet. |
auto fec_it = fec_packets.begin(); |
@@ -306,11 +299,11 @@ TEST_F(FlexfecReceiverTest, DoesNotCallbackTwice) { |
Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
.WillOnce(Return(true)); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- packet_with_rtp_header->data, packet_with_rtp_header->length)); |
+ ParsePacket(packet_with_rtp_header))); |
// Receive FEC packet again. |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- packet_with_rtp_header->data, packet_with_rtp_header->length)); |
+ ParsePacket(packet_with_rtp_header))); |
// Do not call back again. |
} |
@@ -332,8 +325,7 @@ TEST_F(FlexfecReceiverTest, RecoversFrom50PercentLoss) { |
// Drop every second media packet. |
auto media_it = media_packets.begin(); |
while (media_it != media_packets.end()) { |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
- (*media_it)->length)); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_it))); |
++media_it; |
if (media_it == media_packets.end()) { |
break; |
@@ -356,7 +348,7 @@ TEST_F(FlexfecReceiverTest, RecoversFrom50PercentLoss) { |
ElementsAreArray((*media_it)->data, (*media_it)->length))) |
.WillOnce(Return(true)); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- fec_packet_with_rtp_header->data, fec_packet_with_rtp_header->length)); |
+ ParsePacket(fec_packet_with_rtp_header))); |
++media_it; |
} |
} |
@@ -383,8 +375,7 @@ TEST_F(FlexfecReceiverTest, DelayedFecPacketDoesHelp) { |
// Receive all other media packets. |
while (media_it != media_packets.end()) { |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
- (*media_it)->length)); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_it))); |
++media_it; |
} |
@@ -399,7 +390,7 @@ TEST_F(FlexfecReceiverTest, DelayedFecPacketDoesHelp) { |
Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
.WillOnce(Return(true)); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- packet_with_rtp_header->data, packet_with_rtp_header->length)); |
+ ParsePacket(packet_with_rtp_header))); |
} |
TEST_F(FlexfecReceiverTest, TooDelayedFecPacketDoesNotHelp) { |
@@ -424,8 +415,7 @@ TEST_F(FlexfecReceiverTest, TooDelayedFecPacketDoesNotHelp) { |
// Receive all other media packets. |
while (media_it != media_packets.end()) { |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
- (*media_it)->length)); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_it))); |
++media_it; |
} |
@@ -434,7 +424,7 @@ TEST_F(FlexfecReceiverTest, TooDelayedFecPacketDoesNotHelp) { |
std::unique_ptr<Packet> packet_with_rtp_header = |
packet_generator_.BuildFlexfecPacket(**fec_it); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- packet_with_rtp_header->data, packet_with_rtp_header->length)); |
+ ParsePacket(packet_with_rtp_header))); |
// Do not expect a call back. |
} |
@@ -455,14 +445,14 @@ TEST_F(FlexfecReceiverTest, RecoversWithMediaPacketsOutOfOrder) { |
auto media_packet3 = media_it++; |
auto media_packet4 = media_it++; |
auto media_packet5 = media_it++; |
- 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_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 to recover lost media packets. |
EXPECT_CALL(recovered_packet_receiver_, |
@@ -482,11 +472,69 @@ TEST_F(FlexfecReceiverTest, RecoversWithMediaPacketsOutOfOrder) { |
while (fec_it != fec_packets.end()) { |
packet_with_rtp_header = packet_generator_.BuildFlexfecPacket(**fec_it); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- packet_with_rtp_header->data, packet_with_rtp_header->length)); |
+ ParsePacket(packet_with_rtp_header))); |
++fec_it; |
} |
} |
+TEST_F(FlexfecReceiverTest, |
+ NotifiesBweOfReceivedFecPacketWithTransportSequenceNumberExtension) { |
+ // Set up receiver. |
+ testing::StrictMock<MockRecoveredPacketReceiver> recovered_packet_receiver; |
+ testing::StrictMock<MockRemoteBitrateEstimator> remote_bitrate_estimator; |
+ FlexfecReceiver receiver(kFlexfecSsrc, kMediaSsrc, &recovered_packet_receiver, |
+ &remote_bitrate_estimator); |
+ |
+ // Set up RTP header extensions. |
+ RtpHeaderExtensionMap rtp_header_extension_map; |
+ rtp_header_extension_map.Register<TransportSequenceNumber>(7); |
+ |
+ // Generate media and FEC payloads. |
+ const size_t kNumMediaPackets = 1; |
+ const size_t kNumFecPackets = 1; |
+ PacketList media_packets; |
+ PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
+ std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
+ |
+ // Add transport-wide sequence numbers to packets. |
+ ASSERT_EQ(1u, media_packets.size()); |
+ auto media_packet_raw = media_packets.front().get(); |
danilchap
2016/12/13 14:11:24
may be use "auto*" to stress it is a raw pointer
|
+ RtpPacketReceived media_packet; |
+ media_packet.Parse(media_packet_raw->data, media_packet_raw->length); |
danilchap
2016/12/13 14:11:24
may be
RtpPacketReceived media_packet = ParsePacke
|
+ RtpPacketReceived media_packet_ext(&rtp_header_extension_map); |
+ media_packet_ext.CopyHeaderFrom(media_packet); |
+ media_packet_ext.SetExtension<TransportSequenceNumber>(1); |
+ auto payload = media_packet.payload(); |
+ uint8_t* ext_payload = media_packet_ext.AllocatePayload(payload.size()); |
+ memcpy(ext_payload, payload.data(), payload.size()); |
+ |
+ ASSERT_EQ(1u, fec_packets.size()); |
+ auto fec_packet_raw = |
+ packet_generator_.BuildFlexfecPacket(*fec_packets.front()); |
+ RtpPacketReceived fec_packet; |
danilchap
2016/12/13 14:11:24
ditto
|
+ fec_packet.Parse(fec_packet_raw->data, fec_packet_raw->length); |
+ RtpPacketReceived fec_packet_ext(&rtp_header_extension_map); |
+ fec_packet_ext.CopyHeaderFrom(fec_packet); |
+ fec_packet_ext.SetExtension<TransportSequenceNumber>(2); |
+ payload = fec_packet.payload(); |
+ ext_payload = fec_packet_ext.AllocatePayload(payload.size()); |
+ memcpy(ext_payload, payload.data(), payload.size()); |
+ |
+ // Expect BWE notification for FEC packet, but not media packet. |
+ RTPHeader reported_header; |
+ EXPECT_CALL(remote_bitrate_estimator, |
+ IncomingPacket(_, fec_packet_ext.payload_size(), _)) |
+ .WillOnce(SaveArg<2>(&reported_header)); |
+ |
+ // Add packets to receiver. |
+ EXPECT_TRUE(receiver.AddAndProcessReceivedPacket(media_packet_ext)); |
+ EXPECT_TRUE(receiver.AddAndProcessReceivedPacket(fec_packet_ext)); |
+ |
+ // Ensure that the BWE was notified of the FlexFEC packet. |
+ EXPECT_EQ(kFlexfecSsrc, reported_header.ssrc); |
+ EXPECT_EQ(2, reported_header.extension.transportSequenceNumber); |
+} |
+ |
TEST_F(FlexfecReceiverTest, CalculatesNumberOfPackets) { |
const size_t kNumMediaPackets = 2; |
const size_t kNumFecPackets = 1; |
@@ -497,8 +545,7 @@ TEST_F(FlexfecReceiverTest, CalculatesNumberOfPackets) { |
// Receive first media packet but drop second. |
auto media_it = media_packets.begin(); |
- EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
- (*media_it)->length)); |
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_it))); |
// Receive FEC packet and ensure recovery of lost media packet. |
auto fec_it = fec_packets.begin(); |
@@ -511,7 +558,7 @@ TEST_F(FlexfecReceiverTest, CalculatesNumberOfPackets) { |
Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
.WillOnce(Return(true)); |
EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
- packet_with_rtp_header->data, packet_with_rtp_header->length)); |
+ ParsePacket(packet_with_rtp_header))); |
// Check stats calculations. |
FecPacketCounter packet_counter = receiver_.GetPacketCounter(); |