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

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

Issue 2101253002: Unit test for media packet reordering in ForwardErrorCorrection. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@flexfec-pt1c_renames-and-fixes
Patch Set: Response to feedback. Created 4 years, 5 months 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/rtp_fec_unittest.cc
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_fec_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_fec_unittest.cc
index f830354342b8eaaffcc47a03409ad40801ce87f4..c8b66d646d2affc4a075130e804eff4c100c9e92 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_fec_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_fec_unittest.cc
@@ -19,13 +19,14 @@
using webrtc::ForwardErrorCorrection;
// Minimum RTP header size in bytes.
-const uint8_t kRtpHeaderSize = 12;
+constexpr uint8_t kRtpHeaderSize = 12;
// Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum.
-const uint8_t kTransportOverhead = 28;
+constexpr uint8_t kTransportOverhead = 28;
// Maximum number of media packets used in the FEC (RFC 5109).
-const uint8_t kMaxNumberMediaPackets = ForwardErrorCorrection::kMaxMediaPackets;
+constexpr uint8_t kMaxNumberMediaPackets =
+ ForwardErrorCorrection::kMaxMediaPackets;
using PacketList = ForwardErrorCorrection::PacketList;
using ReceivedPacketList = ForwardErrorCorrection::ReceivedPacketList;
@@ -84,10 +85,10 @@ class RtpFecTest : public ::testing::Test {
};
TEST_F(RtpFecTest, FecRecoveryNoLoss) {
- const int kNumImportantPackets = 0;
- const bool kUseUnequalProtection = false;
- const int kNumMediaPackets = 4;
- uint8_t kProtectionFactor = 60;
+ constexpr int kNumImportantPackets = 0;
+ constexpr bool kUseUnequalProtection = false;
+ constexpr int kNumMediaPackets = 4;
+ constexpr uint8_t kProtectionFactor = 60;
fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets);
@@ -96,7 +97,7 @@ TEST_F(RtpFecTest, FecRecoveryNoLoss) {
webrtc::kFecMaskBursty, &fec_packet_list_));
// Expect 1 FEC packet.
- EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size()));
+ EXPECT_EQ(1u, fec_packet_list_.size());
// No packets lost.
memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
@@ -111,10 +112,10 @@ TEST_F(RtpFecTest, FecRecoveryNoLoss) {
}
TEST_F(RtpFecTest, FecRecoveryWithLoss) {
- const int kNumImportantPackets = 0;
- const bool kUseUnequalProtection = false;
- const int kNumMediaPackets = 4;
- uint8_t kProtectionFactor = 60;
+ constexpr int kNumImportantPackets = 0;
+ constexpr bool kUseUnequalProtection = false;
+ constexpr int kNumMediaPackets = 4;
+ constexpr uint8_t kProtectionFactor = 60;
fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets);
@@ -123,7 +124,7 @@ TEST_F(RtpFecTest, FecRecoveryWithLoss) {
webrtc::kFecMaskBursty, &fec_packet_list_));
// Expect 1 FEC packet.
- EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size()));
+ EXPECT_EQ(1u, fec_packet_list_.size());
// 1 media packet lost
memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
@@ -154,9 +155,9 @@ TEST_F(RtpFecTest, FecRecoveryWithLoss) {
// Verify that we don't use an old FEC packet for FEC decoding.
TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapTwoFrames) {
- const int kNumImportantPackets = 0;
- const bool kUseUnequalProtection = false;
- uint8_t kProtectionFactor = 20;
+ constexpr int kNumImportantPackets = 0;
+ constexpr bool kUseUnequalProtection = false;
+ constexpr uint8_t kProtectionFactor = 20;
// Two frames: first frame (old) with two media packets and 1 FEC packet.
// Second frame (new) with 3 media packets, and no FEC packets.
@@ -172,7 +173,7 @@ TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapTwoFrames) {
kNumImportantPackets, kUseUnequalProtection,
webrtc::kFecMaskBursty, &fec_packet_list_));
// Expect 1 FEC packet.
- EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size()));
+ EXPECT_EQ(1u, fec_packet_list_.size());
// Add FEC packet (seq#2) of this first frame to received list (i.e., assume
// the two media packet were lost).
memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
@@ -183,7 +184,7 @@ TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapTwoFrames) {
fec_seq_num_ = ConstructMediaPacketsSeqNum(3, 65535);
// Expect 3 media packets for this frame.
- EXPECT_EQ(3, static_cast<int>(media_packet_list_.size()));
+ EXPECT_EQ(3u, media_packet_list_.size());
// Second media packet lost (seq#0).
memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
@@ -197,16 +198,16 @@ TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapTwoFrames) {
// Expect that no decoding is done to get missing packet (seq#0) of second
// frame, using old FEC packet (seq#2) from first (old) frame. So number of
// recovered packets is 2, and not equal to number of media packets (=3).
- EXPECT_EQ(2, static_cast<int>(recovered_packet_list_.size()));
+ EXPECT_EQ(2u, recovered_packet_list_.size());
EXPECT_TRUE(recovered_packet_list_.size() != media_packet_list_.size());
}
-// Verify we can still recovery frame if sequence number wrap occurs within
+// Verify we can still recover frame if sequence number wrap occurs within
// the frame and FEC packet following wrap is received after media packets.
TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameRecovery) {
- const int kNumImportantPackets = 0;
- const bool kUseUnequalProtection = false;
- uint8_t kProtectionFactor = 20;
+ constexpr int kNumImportantPackets = 0;
+ constexpr bool kUseUnequalProtection = false;
+ constexpr uint8_t kProtectionFactor = 20;
// One frame, with sequence number wrap in media packets.
// -----Frame 1----
@@ -218,7 +219,7 @@ TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameRecovery) {
webrtc::kFecMaskBursty, &fec_packet_list_));
// Expect 1 FEC packet.
- EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size()));
+ EXPECT_EQ(1u, fec_packet_list_.size());
// Lose one media packet (seq# 65535).
memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
@@ -233,7 +234,7 @@ TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameRecovery) {
// Expect 3 media packets in recovered list, and complete recovery.
// Wrap-around won't remove FEC packet, as it follows the wrap.
- EXPECT_EQ(3, static_cast<int>(recovered_packet_list_.size()));
+ EXPECT_EQ(3u, recovered_packet_list_.size());
EXPECT_TRUE(IsRecoveryComplete());
}
@@ -244,9 +245,9 @@ TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameRecovery) {
// is used to detect old FEC packets.
// TODO(marpan): Update test if wrap-around handling changes in FEC decoding.
TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameNoRecovery) {
- const int kNumImportantPackets = 0;
- const bool kUseUnequalProtection = false;
- uint8_t kProtectionFactor = 200;
+ constexpr int kNumImportantPackets = 0;
+ constexpr bool kUseUnequalProtection = false;
+ constexpr uint8_t kProtectionFactor = 200;
// 1 frame: 3 media packets and 2 FEC packets.
// Sequence number wrap in FEC packets.
@@ -259,7 +260,7 @@ TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameNoRecovery) {
webrtc::kFecMaskBursty, &fec_packet_list_));
// Expect 2 FEC packets.
- EXPECT_EQ(2, static_cast<int>(fec_packet_list_.size()));
+ EXPECT_EQ(2u, fec_packet_list_.size());
// Lose the last two media packets (seq# 65533, 65534).
memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
@@ -276,16 +277,54 @@ TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameNoRecovery) {
// but because of the wrap the second FEC packet will be discarded, and only
// one media packet is recoverable. So exepct 2 media packets on recovered
// list and no complete recovery.
- EXPECT_EQ(2, static_cast<int>(recovered_packet_list_.size()));
+ EXPECT_EQ(2u, recovered_packet_list_.size());
EXPECT_TRUE(recovered_packet_list_.size() != media_packet_list_.size());
EXPECT_FALSE(IsRecoveryComplete());
}
-// Verify we can still recovery frame if FEC is received before media packets.
+// Verify we can still recover frame if media packets are reordered.
+TEST_F(RtpFecTest, FecRecoveryWithMediaReordering) {
+ constexpr int kNumImportantPackets = 0;
+ constexpr bool kUseUnequalProtection = false;
+ constexpr uint8_t kProtectionFactor = 20;
+
+ // One frame: 3 media packets, 1 FEC packet.
+ // -----Frame 1----
+ // #0(media) #1(media) #2(media) #3(FEC).
+ fec_seq_num_ = ConstructMediaPacketsSeqNum(3, 0);
+
+ EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor,
+ kNumImportantPackets, kUseUnequalProtection,
+ webrtc::kFecMaskBursty, &fec_packet_list_));
+
+ // Expect 1 FEC packet.
+ EXPECT_EQ(1u, fec_packet_list_.size());
+
+ // Lose one media packet (seq# 1).
+ memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
+ memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
+ media_loss_mask_[1] = 1;
+ NetworkReceivedPackets();
stefan-webrtc 2016/07/05 17:26:49 I think it would have been nicer to pass media_los
brandtr 2016/07/07 14:59:12 Done.
+
+ // Reorder received media packets.
+ auto it0 = received_packet_list_.begin();
+ auto it2 = received_packet_list_.begin();
+ it2++;
+ std::swap(*it0, *it2);
+
+ EXPECT_EQ(0,
+ fec_->DecodeFec(&received_packet_list_, &recovered_packet_list_));
+
+ // Expect 3 media packets in recovered list, and complete recovery.
+ EXPECT_EQ(3u, recovered_packet_list_.size());
+ EXPECT_TRUE(IsRecoveryComplete());
+}
+
+// Verify we can still recover frame if FEC is received before media packets.
TEST_F(RtpFecTest, FecRecoveryWithFecOutOfOrder) {
- const int kNumImportantPackets = 0;
- const bool kUseUnequalProtection = false;
- uint8_t kProtectionFactor = 20;
+ constexpr int kNumImportantPackets = 0;
+ constexpr bool kUseUnequalProtection = false;
+ constexpr uint8_t kProtectionFactor = 20;
// One frame: 3 media packets, 1 FEC packet.
// -----Frame 1----
@@ -297,7 +336,7 @@ TEST_F(RtpFecTest, FecRecoveryWithFecOutOfOrder) {
webrtc::kFecMaskBursty, &fec_packet_list_));
// Expect 1 FEC packet.
- EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size()));
+ EXPECT_EQ(1u, fec_packet_list_.size());
// Lose one media packet (seq# 1).
memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
@@ -312,7 +351,7 @@ TEST_F(RtpFecTest, FecRecoveryWithFecOutOfOrder) {
fec_->DecodeFec(&received_packet_list_, &recovered_packet_list_));
// Expect 3 media packets in recovered list, and complete recovery.
- EXPECT_EQ(3, static_cast<int>(recovered_packet_list_.size()));
+ EXPECT_EQ(3u, recovered_packet_list_.size());
EXPECT_TRUE(IsRecoveryComplete());
}
@@ -320,10 +359,10 @@ TEST_F(RtpFecTest, FecRecoveryWithFecOutOfOrder) {
// a 50% non-consecutive loss which can be fully recovered, and a 50%
// consecutive loss which cannot be fully recovered.
TEST_F(RtpFecTest, FecRecoveryWithLoss50percRandomMask) {
- const int kNumImportantPackets = 0;
- const bool kUseUnequalProtection = false;
- const int kNumMediaPackets = 4;
- const uint8_t kProtectionFactor = 255;
+ constexpr int kNumImportantPackets = 0;
+ constexpr bool kUseUnequalProtection = false;
+ constexpr int kNumMediaPackets = 4;
+ constexpr uint8_t kProtectionFactor = 255;
// Packet Mask for (4,4,0) code, from random mask table.
// (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 0)
@@ -342,7 +381,7 @@ TEST_F(RtpFecTest, FecRecoveryWithLoss50percRandomMask) {
webrtc::kFecMaskRandom, &fec_packet_list_));
// Expect 4 FEC packets.
- EXPECT_EQ(4, static_cast<int>(fec_packet_list_.size()));
+ EXPECT_EQ(4u, fec_packet_list_.size());
// 4 packets lost: 3 media packets (0, 2, 3), and one FEC packet (0) lost.
memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
@@ -380,10 +419,10 @@ TEST_F(RtpFecTest, FecRecoveryWithLoss50percRandomMask) {
// two 50% consecutive losses which can be fully recovered, and one
// non-consecutive which cannot be fully recovered.
TEST_F(RtpFecTest, FecRecoveryWithLoss50percBurstyMask) {
- const int kNumImportantPackets = 0;
- const bool kUseUnequalProtection = false;
- const int kNumMediaPackets = 4;
- const uint8_t kProtectionFactor = 255;
+ constexpr int kNumImportantPackets = 0;
+ constexpr bool kUseUnequalProtection = false;
+ constexpr int kNumMediaPackets = 4;
+ constexpr uint8_t kProtectionFactor = 255;
// Packet Mask for (4,4,0) code, from bursty mask table.
// (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 0)
@@ -402,7 +441,7 @@ TEST_F(RtpFecTest, FecRecoveryWithLoss50percBurstyMask) {
webrtc::kFecMaskBursty, &fec_packet_list_));
// Expect 4 FEC packets.
- EXPECT_EQ(4, static_cast<int>(fec_packet_list_.size()));
+ EXPECT_EQ(4u, fec_packet_list_.size());
// 4 consecutive packets lost: media packets 0,1,2,3.
memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
@@ -453,10 +492,10 @@ TEST_F(RtpFecTest, FecRecoveryWithLoss50percBurstyMask) {
}
TEST_F(RtpFecTest, FecRecoveryNoLossUep) {
- const int kNumImportantPackets = 2;
- const bool kUseUnequalProtection = true;
- const int kNumMediaPackets = 4;
- const uint8_t kProtectionFactor = 60;
+ constexpr int kNumImportantPackets = 2;
+ constexpr bool kUseUnequalProtection = true;
+ constexpr int kNumMediaPackets = 4;
+ constexpr uint8_t kProtectionFactor = 60;
fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets);
@@ -465,7 +504,7 @@ TEST_F(RtpFecTest, FecRecoveryNoLossUep) {
webrtc::kFecMaskBursty, &fec_packet_list_));
// Expect 1 FEC packet.
- EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size()));
+ EXPECT_EQ(1u, fec_packet_list_.size());
// No packets lost.
memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
@@ -480,10 +519,10 @@ TEST_F(RtpFecTest, FecRecoveryNoLossUep) {
}
TEST_F(RtpFecTest, FecRecoveryWithLossUep) {
- const int kNumImportantPackets = 2;
- const bool kUseUnequalProtection = true;
- const int kNumMediaPackets = 4;
- const uint8_t kProtectionFactor = 60;
+ constexpr int kNumImportantPackets = 2;
+ constexpr bool kUseUnequalProtection = true;
+ constexpr int kNumMediaPackets = 4;
+ constexpr uint8_t kProtectionFactor = 60;
fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets);
@@ -492,7 +531,7 @@ TEST_F(RtpFecTest, FecRecoveryWithLossUep) {
webrtc::kFecMaskBursty, &fec_packet_list_));
// Expect 1 FEC packet.
- EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size()));
+ EXPECT_EQ(1u, fec_packet_list_.size());
// 1 media packet lost.
memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
@@ -523,10 +562,10 @@ TEST_F(RtpFecTest, FecRecoveryWithLossUep) {
// Test 50% protection with random mask type for UEP on.
TEST_F(RtpFecTest, FecRecoveryWithLoss50percUepRandomMask) {
- const int kNumImportantPackets = 1;
- const bool kUseUnequalProtection = true;
- const int kNumMediaPackets = 4;
- const uint8_t kProtectionFactor = 255;
+ constexpr int kNumImportantPackets = 1;
+ constexpr bool kUseUnequalProtection = true;
+ constexpr int kNumMediaPackets = 4;
+ constexpr uint8_t kProtectionFactor = 255;
// Packet Mask for (4,4,1) code, from random mask table.
// (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 1)
@@ -545,7 +584,7 @@ TEST_F(RtpFecTest, FecRecoveryWithLoss50percUepRandomMask) {
webrtc::kFecMaskRandom, &fec_packet_list_));
// Expect 4 FEC packets.
- EXPECT_EQ(4, static_cast<int>(fec_packet_list_.size()));
+ EXPECT_EQ(4u, fec_packet_list_.size());
// 4 packets lost: 3 media packets and FEC packet#1 lost.
memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
@@ -581,10 +620,10 @@ TEST_F(RtpFecTest, FecRecoveryWithLoss50percUepRandomMask) {
}
TEST_F(RtpFecTest, FecRecoveryNonConsecutivePackets) {
- const int kNumImportantPackets = 0;
- const bool kUseUnequalProtection = false;
- const int kNumMediaPackets = 5;
- uint8_t kProtectionFactor = 60;
+ constexpr int kNumImportantPackets = 0;
+ constexpr bool kUseUnequalProtection = false;
+ constexpr int kNumMediaPackets = 5;
+ constexpr uint8_t kProtectionFactor = 60;
fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets);
@@ -598,7 +637,7 @@ TEST_F(RtpFecTest, FecRecoveryNonConsecutivePackets) {
webrtc::kFecMaskBursty, &fec_packet_list_));
// Expect 1 FEC packet.
- EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size()));
+ EXPECT_EQ(1u, fec_packet_list_.size());
// 1 protected media packet lost
memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
@@ -641,9 +680,9 @@ TEST_F(RtpFecTest, FecRecoveryNonConsecutivePackets) {
}
TEST_F(RtpFecTest, FecRecoveryNonConsecutivePacketsExtension) {
- const int kNumImportantPackets = 0;
- const bool kUseUnequalProtection = false;
- const int kNumMediaPackets = 21;
+ constexpr int kNumImportantPackets = 0;
+ constexpr bool kUseUnequalProtection = false;
+ constexpr int kNumMediaPackets = 21;
uint8_t kProtectionFactor = 127;
fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets);
@@ -661,7 +700,7 @@ TEST_F(RtpFecTest, FecRecoveryNonConsecutivePacketsExtension) {
webrtc::kFecMaskBursty, &fec_packet_list_));
// Expect 5 FEC packet.
- EXPECT_EQ(5, static_cast<int>(fec_packet_list_.size()));
+ EXPECT_EQ(5u, fec_packet_list_.size());
// Last protected media packet lost
memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
@@ -708,9 +747,9 @@ TEST_F(RtpFecTest, FecRecoveryNonConsecutivePacketsExtension) {
}
TEST_F(RtpFecTest, FecRecoveryNonConsecutivePacketsWrap) {
- const int kNumImportantPackets = 0;
- const bool kUseUnequalProtection = false;
- const int kNumMediaPackets = 21;
+ constexpr int kNumImportantPackets = 0;
+ constexpr bool kUseUnequalProtection = false;
+ constexpr int kNumMediaPackets = 21;
uint8_t kProtectionFactor = 127;
fec_seq_num_ = ConstructMediaPacketsSeqNum(kNumMediaPackets, 0xFFFF - 5);
@@ -728,7 +767,7 @@ TEST_F(RtpFecTest, FecRecoveryNonConsecutivePacketsWrap) {
webrtc::kFecMaskBursty, &fec_packet_list_));
// Expect 5 FEC packet.
- EXPECT_EQ(5, static_cast<int>(fec_packet_list_.size()));
+ EXPECT_EQ(5u, fec_packet_list_.size());
// Last protected media packet lost
memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
@@ -810,7 +849,7 @@ bool RtpFecTest::IsRecoveryComplete() {
}
void RtpFecTest::NetworkReceivedPackets() {
- const bool kFecPacket = true;
+ constexpr bool kFecPacket = true;
ReceivedPackets(media_packet_list_, media_loss_mask_, !kFecPacket);
ReceivedPackets(fec_packet_list_, fec_loss_mask_, kFecPacket);
}
@@ -862,7 +901,7 @@ int RtpFecTest::ConstructMediaPacketsSeqNum(int num_media_packets,
for (int i = 0; i < num_media_packets; ++i) {
std::unique_ptr<ForwardErrorCorrection::Packet> media_packet(
new ForwardErrorCorrection::Packet());
- const uint32_t kMinPacketSize = kRtpHeaderSize;
+ constexpr uint32_t kMinPacketSize = kRtpHeaderSize;
const uint32_t kMaxPacketSize = IP_PACKET_SIZE - kRtpHeaderSize -
kTransportOverhead -
ForwardErrorCorrection::PacketOverhead();

Powered by Google App Engine
This is Rietveld 408576698