Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: webrtc/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc

Issue 2553863003: Parse FlexFEC RTP headers in Call and add integration with BWE. (Closed)
Patch Set: Work in progress. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..1fc5b3cf49ef714f473a9cae0d5b4573943188c2 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) {
+ RtpPacketReceived parsed_packet(nullptr);
+ 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,8 +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));
+ EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(media_packet)));
}
TEST_F(FlexfecReceiverTest, FailsOnTruncatedMediaPacket) {
@@ -106,8 +121,8 @@ TEST_F(FlexfecReceiverTest, FailsOnTruncatedMediaPacket) {
// Simulate truncated media packet.
media_packet->length = kRtpHeaderSize - 1;
- EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(media_packet->data,
- media_packet->length));
+ EXPECT_FALSE(
+ receiver_.AddAndProcessReceivedPacket(ParsePacket(media_packet)));
}
TEST_F(FlexfecReceiverTest, ReceivesMediaAndFecPackets) {
@@ -117,13 +132,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 +146,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 +160,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 +178,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 +186,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 +200,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 +209,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 +222,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 +235,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 +259,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 +271,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 +284,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 +299,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 +312,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 +338,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 +361,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 +388,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 +403,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 +428,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 +437,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 +458,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 +485,71 @@ 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 RTP header extensions.
+ testing::StrictMock<MockRecoveredPacketReceiver> recovered_packet_receiver;
+ testing::StrictMock<MockRemoteBitrateEstimator> remote_bitrate_estimator;
+ FlexfecReceiver receiver(kFlexfecSsrc, kMediaSsrc, &recovered_packet_receiver,
+ &remote_bitrate_estimator);
+ RtpHeaderExtensionMap rtp_header_extension_map;
+ rtp_header_extension_map.Register<TransportSequenceNumber>(
+ TransportSequenceNumber::kId);
danilchap 2016/12/06 15:04:30 sorry for confusing, but it is better not to use T
brandtr 2016/12/12 13:51:08 Done.
+
+ // 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 = media_packets.front().get();
+ RtpPacketReceived media_packet_without_extension;
+ media_packet_without_extension.Parse(media_packet->data,
+ media_packet->length);
+ RtpPacketReceived media_packet_with_extension(&rtp_header_extension_map);
+ media_packet_with_extension.CopyHeaderFrom(media_packet_without_extension);
+ media_packet_with_extension.SetExtension<TransportSequenceNumber>(1);
+ uint8_t* media_payload = media_packet_with_extension.AllocatePayload(
+ media_packet_without_extension.payload_size());
+ memcpy(media_payload, media_packet_with_extension.payload().data(),
+ media_packet_without_extension.payload_size());
+
+ ASSERT_EQ(1u, fec_packets.size());
+ auto fec_packet = packet_generator_.BuildFlexfecPacket(*fec_packets.front());
+ RtpPacketReceived fec_packet_without_extension;
+ fec_packet_without_extension.Parse(fec_packet->data, fec_packet->length);
+ RtpPacketReceived fec_packet_with_extension(&rtp_header_extension_map);
+ fec_packet_with_extension.CopyHeaderFrom(fec_packet_without_extension);
+ fec_packet_with_extension.SetExtension<TransportSequenceNumber>(2);
+ uint8_t* fec_payload = fec_packet_with_extension.AllocatePayload(
+ fec_packet_without_extension.payload_size());
+ memcpy(fec_payload, fec_packet_with_extension.payload().data(),
+ fec_packet_without_extension.payload_size());
+
+ // Expect BWE notification for FEC packet, but not media packet.
+ RTPHeader reported_header;
+ EXPECT_CALL(remote_bitrate_estimator,
+ IncomingPacket(_, fec_packet_with_extension.payload_size(), _))
+ .WillOnce(SaveArg<2>(&reported_header));
+
+ // Add packets to receiver.
+ EXPECT_TRUE(
+ receiver.AddAndProcessReceivedPacket(media_packet_with_extension));
+ EXPECT_TRUE(receiver.AddAndProcessReceivedPacket(fec_packet_with_extension));
+
+ // 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 +560,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 +573,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();

Powered by Google App Engine
This is Rietveld 408576698