blob: 5f84af501fd1bad20895e7ff84630f17de41501b [file] [log] [blame]
marpan@webrtc.orgb783a552012-02-04 02:46:35 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Rasmus Brandtae4f7672016-07-07 09:40:51 +020011#include <algorithm>
marpan@webrtc.orgb783a552012-02-04 02:46:35 +000012#include <list>
brandtrece4aba2016-09-20 23:16:28 -070013#include <memory>
marpan@webrtc.orgb783a552012-02-04 02:46:35 +000014
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "modules/rtp_rtcp/source/byte_io.h"
16#include "modules/rtp_rtcp/source/fec_test_helper.h"
17#include "modules/rtp_rtcp/source/flexfec_header_reader_writer.h"
18#include "modules/rtp_rtcp/source/forward_error_correction.h"
19#include "modules/rtp_rtcp/source/ulpfec_header_reader_writer.h"
20#include "rtc_base/basictypes.h"
21#include "rtc_base/random.h"
22#include "test/gtest.h"
marpan@webrtc.orgb783a552012-02-04 02:46:35 +000023
brandtrece4aba2016-09-20 23:16:28 -070024namespace webrtc {
marpan@webrtc.orgb783a552012-02-04 02:46:35 +000025
brandtrece4aba2016-09-20 23:16:28 -070026namespace {
marpan@webrtc.orgb783a552012-02-04 02:46:35 +000027
28// Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum.
brandtrece4aba2016-09-20 23:16:28 -070029constexpr size_t kTransportOverhead = 28;
marpan@webrtc.orgb783a552012-02-04 02:46:35 +000030
brandtrece4aba2016-09-20 23:16:28 -070031constexpr uint32_t kMediaSsrc = 83542;
brandtr0496de22016-10-03 00:43:25 -070032constexpr uint32_t kFlexfecSsrc = 43245;
marpan@webrtc.orgb783a552012-02-04 02:46:35 +000033
brandtrece4aba2016-09-20 23:16:28 -070034// Deep copies |src| to |dst|, but only keeps every Nth packet.
35void DeepCopyEveryNthPacket(const ForwardErrorCorrection::PacketList& src,
36 int n,
37 ForwardErrorCorrection::PacketList* dst) {
38 RTC_DCHECK_GT(n, 0);
39 int i = 0;
40 for (const auto& packet : src) {
41 if (i % n == 0) {
42 dst->emplace_back(new ForwardErrorCorrection::Packet(*packet));
43 }
44 ++i;
45 }
46}
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +000047
brandtrece4aba2016-09-20 23:16:28 -070048} // namespace
49
50using ::testing::Types;
51
52template <typename ForwardErrorCorrectionType>
marpan@webrtc.orgb783a552012-02-04 02:46:35 +000053class RtpFecTest : public ::testing::Test {
54 protected:
55 RtpFecTest()
brandtrece4aba2016-09-20 23:16:28 -070056 : random_(0xabcdef123456),
57 media_packet_generator_(
58 kRtpHeaderSize, // Minimum packet size.
59 IP_PACKET_SIZE - kRtpHeaderSize - kTransportOverhead -
60 fec_.MaxPacketOverhead(), // Maximum packet size.
61 kMediaSsrc,
62 &random_) {}
marpan@webrtc.orgb783a552012-02-04 02:46:35 +000063
brandtrece4aba2016-09-20 23:16:28 -070064 // Construct |received_packets_|: a subset of the media and FEC packets.
brandtrd90fa0b2016-08-09 06:57:14 -070065 //
66 // Media packet "i" is lost if media_loss_mask_[i] = 1, received if
67 // media_loss_mask_[i] = 0.
68 // FEC packet "i" is lost if fec_loss_mask_[i] = 1, received if
69 // fec_loss_mask_[i] = 0.
70 void NetworkReceivedPackets(int* media_loss_mask, int* fec_loss_mask);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +000071
72 // Add packet from |packet_list| to list of received packets, using the
73 // |loss_mask|.
74 // The |packet_list| may be a media packet list (is_fec = false), or a
75 // FEC packet list (is_fec = true).
brandtr35c480c2016-08-09 01:23:23 -070076 template <typename T>
77 void ReceivedPackets(const T& packet_list, int* loss_mask, bool is_fec);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +000078
79 // Check for complete recovery after FEC decoding.
80 bool IsRecoveryComplete();
81
brandtrece4aba2016-09-20 23:16:28 -070082 ForwardErrorCorrectionType fec_;
brandtrd90fa0b2016-08-09 06:57:14 -070083
brandtrece4aba2016-09-20 23:16:28 -070084 Random random_;
85 test::fec::MediaPacketGenerator media_packet_generator_;
brandtrd90fa0b2016-08-09 06:57:14 -070086
brandtrece4aba2016-09-20 23:16:28 -070087 ForwardErrorCorrection::PacketList media_packets_;
88 std::list<ForwardErrorCorrection::Packet*> generated_fec_packets_;
89 ForwardErrorCorrection::ReceivedPacketList received_packets_;
90 ForwardErrorCorrection::RecoveredPacketList recovered_packets_;
brandtrd90fa0b2016-08-09 06:57:14 -070091
Rasmus Brandt78db1582016-09-21 09:19:34 +020092 int media_loss_mask_[kUlpfecMaxMediaPackets];
93 int fec_loss_mask_[kUlpfecMaxMediaPackets];
marpan@webrtc.orgb783a552012-02-04 02:46:35 +000094};
95
Rasmus Brandtea7beb92016-09-21 12:01:19 +020096template <typename ForwardErrorCorrectionType>
97void RtpFecTest<ForwardErrorCorrectionType>::NetworkReceivedPackets(
98 int* media_loss_mask,
99 int* fec_loss_mask) {
100 constexpr bool kFecPacket = true;
101 ReceivedPackets(media_packets_, media_loss_mask, !kFecPacket);
102 ReceivedPackets(generated_fec_packets_, fec_loss_mask, kFecPacket);
103}
104
105template <typename ForwardErrorCorrectionType>
106template <typename PacketListType>
107void RtpFecTest<ForwardErrorCorrectionType>::ReceivedPackets(
108 const PacketListType& packet_list,
109 int* loss_mask,
110 bool is_fec) {
brandtrd726a3f2017-06-29 02:45:35 -0700111 uint16_t fec_seq_num = ForwardErrorCorrectionType::GetFirstFecSeqNum(
112 media_packet_generator_.GetNextSeqNum());
Rasmus Brandtea7beb92016-09-21 12:01:19 +0200113 int packet_idx = 0;
114
115 for (const auto& packet : packet_list) {
116 if (loss_mask[packet_idx] == 0) {
117 std::unique_ptr<ForwardErrorCorrection::ReceivedPacket> received_packet(
118 new ForwardErrorCorrection::ReceivedPacket());
119 received_packet->pkt = new ForwardErrorCorrection::Packet();
120 received_packet->pkt->length = packet->length;
121 memcpy(received_packet->pkt->data, packet->data, packet->length);
122 received_packet->is_fec = is_fec;
123 if (!is_fec) {
brandtrd726a3f2017-06-29 02:45:35 -0700124 received_packet->ssrc = kMediaSsrc;
125 // For media packets, the sequence number is obtained from the
126 // RTP header as written by MediaPacketGenerator::ConstructMediaPackets.
Rasmus Brandtea7beb92016-09-21 12:01:19 +0200127 received_packet->seq_num =
128 ByteReader<uint16_t>::ReadBigEndian(&packet->data[2]);
129 } else {
brandtrd726a3f2017-06-29 02:45:35 -0700130 received_packet->ssrc = ForwardErrorCorrectionType::kFecSsrc;
131 // For FEC packets, we simulate the sequence numbers differently
132 // depending on if ULPFEC or FlexFEC is used. See the definition of
133 // ForwardErrorCorrectionType::GetFirstFecSeqNum.
Rasmus Brandtea7beb92016-09-21 12:01:19 +0200134 received_packet->seq_num = fec_seq_num;
Rasmus Brandtea7beb92016-09-21 12:01:19 +0200135 }
136 received_packets_.push_back(std::move(received_packet));
137 }
138 packet_idx++;
139 // Sequence number of FEC packets are defined as increment by 1 from
140 // last media packet in frame.
141 if (is_fec)
142 fec_seq_num++;
143 }
144}
145
146template <typename ForwardErrorCorrectionType>
147bool RtpFecTest<ForwardErrorCorrectionType>::IsRecoveryComplete() {
148 // We must have equally many recovered packets as original packets.
149 if (recovered_packets_.size() != media_packets_.size()) {
150 return false;
151 }
152
153 // All recovered packets must be identical to the corresponding
154 // original packets.
brandtr0496de22016-10-03 00:43:25 -0700155 auto cmp = [](
156 const std::unique_ptr<ForwardErrorCorrection::Packet>& media_packet,
157 const std::unique_ptr<ForwardErrorCorrection::RecoveredPacket>&
158 recovered_packet) {
Rasmus Brandtea7beb92016-09-21 12:01:19 +0200159 if (media_packet->length != recovered_packet->pkt->length) {
160 return false;
161 }
brandtr0496de22016-10-03 00:43:25 -0700162 if (memcmp(media_packet->data, recovered_packet->pkt->data,
Rasmus Brandtea7beb92016-09-21 12:01:19 +0200163 media_packet->length) != 0) {
164 return false;
165 }
166 return true;
167 };
168 return std::equal(media_packets_.cbegin(), media_packets_.cend(),
169 recovered_packets_.cbegin(), cmp);
170}
171
brandtrece4aba2016-09-20 23:16:28 -0700172// Define gTest typed test to loop over both ULPFEC and FlexFEC.
173// Since the tests now are parameterized, we need to access
174// member variables using |this|, thereby enforcing runtime
175// resolution.
Rasmus Brandtea7beb92016-09-21 12:01:19 +0200176
brandtr0496de22016-10-03 00:43:25 -0700177class FlexfecForwardErrorCorrection : public ForwardErrorCorrection {
178 public:
brandtrd726a3f2017-06-29 02:45:35 -0700179 static const uint32_t kFecSsrc = kFlexfecSsrc;
180
brandtr0496de22016-10-03 00:43:25 -0700181 FlexfecForwardErrorCorrection()
182 : ForwardErrorCorrection(
183 std::unique_ptr<FecHeaderReader>(new FlexfecHeaderReader()),
brandtrd726a3f2017-06-29 02:45:35 -0700184 std::unique_ptr<FecHeaderWriter>(new FlexfecHeaderWriter()),
185 kFecSsrc,
186 kMediaSsrc) {}
187
188 // For FlexFEC we let the FEC packet sequence numbers be independent of
189 // the media packet sequence numbers.
190 static uint16_t GetFirstFecSeqNum(uint16_t next_media_seq_num) {
191 Random random(0xbe110);
192 return random.Rand<uint16_t>();
193 }
brandtr0496de22016-10-03 00:43:25 -0700194};
195
Rasmus Brandtea7beb92016-09-21 12:01:19 +0200196class UlpfecForwardErrorCorrection : public ForwardErrorCorrection {
197 public:
brandtrd726a3f2017-06-29 02:45:35 -0700198 static const uint32_t kFecSsrc = kMediaSsrc;
199
Rasmus Brandtea7beb92016-09-21 12:01:19 +0200200 UlpfecForwardErrorCorrection()
201 : ForwardErrorCorrection(
202 std::unique_ptr<FecHeaderReader>(new UlpfecHeaderReader()),
brandtrd726a3f2017-06-29 02:45:35 -0700203 std::unique_ptr<FecHeaderWriter>(new UlpfecHeaderWriter()),
204 kFecSsrc,
205 kMediaSsrc) {}
206
207 // For ULPFEC we assume that the FEC packets are subsequent to the media
208 // packets in terms of sequence number.
209 static uint16_t GetFirstFecSeqNum(uint16_t next_media_seq_num) {
210 return next_media_seq_num;
211 }
Rasmus Brandtea7beb92016-09-21 12:01:19 +0200212};
213
brandtr0496de22016-10-03 00:43:25 -0700214using FecTypes =
215 Types<FlexfecForwardErrorCorrection, UlpfecForwardErrorCorrection>;
brandtrece4aba2016-09-20 23:16:28 -0700216TYPED_TEST_CASE(RtpFecTest, FecTypes);
217
218TYPED_TEST(RtpFecTest, FecRecoveryNoLoss) {
brandtrd90fa0b2016-08-09 06:57:14 -0700219 constexpr int kNumImportantPackets = 0;
220 constexpr bool kUseUnequalProtection = false;
221 constexpr int kNumMediaPackets = 4;
222 constexpr uint8_t kProtectionFactor = 60;
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000223
brandtrece4aba2016-09-20 23:16:28 -0700224 this->media_packets_ =
225 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000226
brandtrece4aba2016-09-20 23:16:28 -0700227 EXPECT_EQ(
228 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor,
229 kNumImportantPackets, kUseUnequalProtection,
230 kFecMaskBursty, &this->generated_fec_packets_));
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000231
232 // Expect 1 FEC packet.
brandtrece4aba2016-09-20 23:16:28 -0700233 EXPECT_EQ(1u, this->generated_fec_packets_.size());
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000234
235 // No packets lost.
brandtrece4aba2016-09-20 23:16:28 -0700236 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
237 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
238 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000239
brandtrece4aba2016-09-20 23:16:28 -0700240 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
241 &this->recovered_packets_));
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000242
243 // No packets lost, expect complete recovery.
brandtrece4aba2016-09-20 23:16:28 -0700244 EXPECT_TRUE(this->IsRecoveryComplete());
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000245}
246
brandtrece4aba2016-09-20 23:16:28 -0700247TYPED_TEST(RtpFecTest, FecRecoveryWithLoss) {
brandtrd90fa0b2016-08-09 06:57:14 -0700248 constexpr int kNumImportantPackets = 0;
249 constexpr bool kUseUnequalProtection = false;
250 constexpr int kNumMediaPackets = 4;
251 constexpr uint8_t kProtectionFactor = 60;
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000252
brandtrece4aba2016-09-20 23:16:28 -0700253 this->media_packets_ =
254 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000255
brandtrece4aba2016-09-20 23:16:28 -0700256 EXPECT_EQ(
257 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor,
258 kNumImportantPackets, kUseUnequalProtection,
259 kFecMaskBursty, &this->generated_fec_packets_));
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000260
261 // Expect 1 FEC packet.
brandtrece4aba2016-09-20 23:16:28 -0700262 EXPECT_EQ(1u, this->generated_fec_packets_.size());
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000263
264 // 1 media packet lost
brandtrece4aba2016-09-20 23:16:28 -0700265 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
266 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
267 this->media_loss_mask_[3] = 1;
268 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000269
brandtrece4aba2016-09-20 23:16:28 -0700270 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
271 &this->recovered_packets_));
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000272
273 // One packet lost, one FEC packet, expect complete recovery.
brandtrece4aba2016-09-20 23:16:28 -0700274 EXPECT_TRUE(this->IsRecoveryComplete());
275 this->recovered_packets_.clear();
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000276
277 // 2 media packets lost.
brandtrece4aba2016-09-20 23:16:28 -0700278 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
279 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
280 this->media_loss_mask_[1] = 1;
281 this->media_loss_mask_[3] = 1;
282 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000283
brandtrece4aba2016-09-20 23:16:28 -0700284 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
285 &this->recovered_packets_));
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000286
287 // 2 packets lost, one FEC packet, cannot get complete recovery.
brandtrece4aba2016-09-20 23:16:28 -0700288 EXPECT_FALSE(this->IsRecoveryComplete());
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000289}
290
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000291// Verify that we don't use an old FEC packet for FEC decoding.
brandtrece4aba2016-09-20 23:16:28 -0700292TYPED_TEST(RtpFecTest, FecRecoveryWithSeqNumGapTwoFrames) {
brandtrd90fa0b2016-08-09 06:57:14 -0700293 constexpr int kNumImportantPackets = 0;
294 constexpr bool kUseUnequalProtection = false;
295 constexpr uint8_t kProtectionFactor = 20;
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000296
297 // Two frames: first frame (old) with two media packets and 1 FEC packet.
298 // Second frame (new) with 3 media packets, and no FEC packets.
299 // ---Frame 1---- ----Frame 2------
300 // #0(media) #1(media) #2(FEC) #65535(media) #0(media) #1(media).
301 // If we lose either packet 0 or 1 of second frame, FEC decoding should not
302 // try to decode using "old" FEC packet #2.
303
304 // Construct media packets for first frame, starting at sequence number 0.
brandtrece4aba2016-09-20 23:16:28 -0700305 this->media_packets_ =
306 this->media_packet_generator_.ConstructMediaPackets(2, 0);
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000307
brandtrece4aba2016-09-20 23:16:28 -0700308 EXPECT_EQ(
309 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor,
310 kNumImportantPackets, kUseUnequalProtection,
311 kFecMaskBursty, &this->generated_fec_packets_));
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000312 // Expect 1 FEC packet.
brandtrece4aba2016-09-20 23:16:28 -0700313 EXPECT_EQ(1u, this->generated_fec_packets_.size());
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000314 // Add FEC packet (seq#2) of this first frame to received list (i.e., assume
315 // the two media packet were lost).
brandtrece4aba2016-09-20 23:16:28 -0700316 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
317 this->ReceivedPackets(this->generated_fec_packets_, this->fec_loss_mask_,
318 true);
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000319
320 // Construct media packets for second frame, with sequence number wrap.
brandtrece4aba2016-09-20 23:16:28 -0700321 this->media_packets_ =
322 this->media_packet_generator_.ConstructMediaPackets(3, 65535);
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000323
324 // Expect 3 media packets for this frame.
brandtrece4aba2016-09-20 23:16:28 -0700325 EXPECT_EQ(3u, this->media_packets_.size());
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000326
327 // Second media packet lost (seq#0).
brandtrece4aba2016-09-20 23:16:28 -0700328 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
329 this->media_loss_mask_[1] = 1;
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000330 // Add packets #65535, and #1 to received list.
brandtrece4aba2016-09-20 23:16:28 -0700331 this->ReceivedPackets(this->media_packets_, this->media_loss_mask_, false);
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000332
brandtrece4aba2016-09-20 23:16:28 -0700333 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
334 &this->recovered_packets_));
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000335
336 // Expect that no decoding is done to get missing packet (seq#0) of second
337 // frame, using old FEC packet (seq#2) from first (old) frame. So number of
338 // recovered packets is 2, and not equal to number of media packets (=3).
brandtrece4aba2016-09-20 23:16:28 -0700339 EXPECT_EQ(2u, this->recovered_packets_.size());
340 EXPECT_TRUE(this->recovered_packets_.size() != this->media_packets_.size());
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000341}
342
brandtrd90fa0b2016-08-09 06:57:14 -0700343// Verify we can still recover frame if sequence number wrap occurs within
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000344// the frame and FEC packet following wrap is received after media packets.
brandtrece4aba2016-09-20 23:16:28 -0700345TYPED_TEST(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameRecovery) {
brandtrd90fa0b2016-08-09 06:57:14 -0700346 constexpr int kNumImportantPackets = 0;
347 constexpr bool kUseUnequalProtection = false;
348 constexpr uint8_t kProtectionFactor = 20;
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000349
350 // One frame, with sequence number wrap in media packets.
351 // -----Frame 1----
352 // #65534(media) #65535(media) #0(media) #1(FEC).
brandtrece4aba2016-09-20 23:16:28 -0700353 this->media_packets_ =
354 this->media_packet_generator_.ConstructMediaPackets(3, 65534);
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000355
brandtrece4aba2016-09-20 23:16:28 -0700356 EXPECT_EQ(
357 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor,
358 kNumImportantPackets, kUseUnequalProtection,
359 kFecMaskBursty, &this->generated_fec_packets_));
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000360
361 // Expect 1 FEC packet.
brandtrece4aba2016-09-20 23:16:28 -0700362 EXPECT_EQ(1u, this->generated_fec_packets_.size());
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000363
364 // Lose one media packet (seq# 65535).
brandtrece4aba2016-09-20 23:16:28 -0700365 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
366 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
367 this->media_loss_mask_[1] = 1;
368 this->ReceivedPackets(this->media_packets_, this->media_loss_mask_, false);
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000369 // Add FEC packet to received list following the media packets.
brandtrece4aba2016-09-20 23:16:28 -0700370 this->ReceivedPackets(this->generated_fec_packets_, this->fec_loss_mask_,
371 true);
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000372
brandtrece4aba2016-09-20 23:16:28 -0700373 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
374 &this->recovered_packets_));
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000375
376 // Expect 3 media packets in recovered list, and complete recovery.
377 // Wrap-around won't remove FEC packet, as it follows the wrap.
brandtrece4aba2016-09-20 23:16:28 -0700378 EXPECT_EQ(3u, this->recovered_packets_.size());
379 EXPECT_TRUE(this->IsRecoveryComplete());
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000380}
381
brandtrd726a3f2017-06-29 02:45:35 -0700382// Sequence number wrap occurs within the ULPFEC packets for the frame.
383// In this case we will discard ULPFEC packet and full recovery is not expected.
384// Same problem will occur if wrap is within media packets but ULPFEC packet is
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000385// received before the media packets. This may be improved if timing information
brandtrd726a3f2017-06-29 02:45:35 -0700386// is used to detect old ULPFEC packets.
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000387// TODO(marpan): Update test if wrap-around handling changes in FEC decoding.
brandtrd726a3f2017-06-29 02:45:35 -0700388using RtpFecTestUlpfecOnly = RtpFecTest<UlpfecForwardErrorCorrection>;
389TEST_F(RtpFecTestUlpfecOnly, FecRecoveryWithSeqNumGapOneFrameNoRecovery) {
brandtrd90fa0b2016-08-09 06:57:14 -0700390 constexpr int kNumImportantPackets = 0;
391 constexpr bool kUseUnequalProtection = false;
392 constexpr uint8_t kProtectionFactor = 200;
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000393
394 // 1 frame: 3 media packets and 2 FEC packets.
395 // Sequence number wrap in FEC packets.
396 // -----Frame 1----
397 // #65532(media) #65533(media) #65534(media) #65535(FEC) #0(FEC).
brandtrece4aba2016-09-20 23:16:28 -0700398 this->media_packets_ =
399 this->media_packet_generator_.ConstructMediaPackets(3, 65532);
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000400
brandtrece4aba2016-09-20 23:16:28 -0700401 EXPECT_EQ(
402 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor,
403 kNumImportantPackets, kUseUnequalProtection,
404 kFecMaskBursty, &this->generated_fec_packets_));
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000405
406 // Expect 2 FEC packets.
brandtrece4aba2016-09-20 23:16:28 -0700407 EXPECT_EQ(2u, this->generated_fec_packets_.size());
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000408
409 // Lose the last two media packets (seq# 65533, 65534).
brandtrece4aba2016-09-20 23:16:28 -0700410 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
411 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
412 this->media_loss_mask_[1] = 1;
413 this->media_loss_mask_[2] = 1;
414 this->ReceivedPackets(this->media_packets_, this->media_loss_mask_, false);
415 this->ReceivedPackets(this->generated_fec_packets_, this->fec_loss_mask_,
416 true);
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000417
brandtrece4aba2016-09-20 23:16:28 -0700418 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
419 &this->recovered_packets_));
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000420
421 // The two FEC packets are received and should allow for complete recovery,
brandtrd726a3f2017-06-29 02:45:35 -0700422 // but because of the wrap the first FEC packet will be discarded, and only
423 // one media packet is recoverable. So expect 2 media packets on recovered
424 // list and no complete recovery.
425 EXPECT_EQ(2u, this->recovered_packets_.size());
426 EXPECT_TRUE(this->recovered_packets_.size() != this->media_packets_.size());
427 EXPECT_FALSE(this->IsRecoveryComplete());
428}
429
430// TODO(brandtr): This test mimics the one above, ensuring that the recovery
431// strategy of FlexFEC matches the recovery strategy of ULPFEC. Since FlexFEC
432// does not share the sequence number space with the media, however, having a
433// matching recovery strategy may be suboptimal. Study this further.
434using RtpFecTestFlexfecOnly = RtpFecTest<FlexfecForwardErrorCorrection>;
435TEST_F(RtpFecTestFlexfecOnly, FecRecoveryWithSeqNumGapOneFrameNoRecovery) {
436 constexpr int kNumImportantPackets = 0;
437 constexpr bool kUseUnequalProtection = false;
438 constexpr uint8_t kProtectionFactor = 200;
439
440 // 1 frame: 3 media packets and 2 FEC packets.
441 // Sequence number wrap in FEC packets.
442 // -----Frame 1----
443 // #65532(media) #65533(media) #65534(media) #65535(FEC) #0(FEC).
444 this->media_packets_ =
445 this->media_packet_generator_.ConstructMediaPackets(3, 65532);
446
447 EXPECT_EQ(
448 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor,
449 kNumImportantPackets, kUseUnequalProtection,
450 kFecMaskBursty, &this->generated_fec_packets_));
451
452 // Expect 2 FEC packets.
453 EXPECT_EQ(2u, this->generated_fec_packets_.size());
454
455 // Overwrite the sequence numbers generated by ConstructMediaPackets,
456 // to make sure that we do have a wrap.
457 auto it = this->generated_fec_packets_.begin();
458 ByteWriter<uint16_t>::WriteBigEndian(&(*it)->data[2], 65535);
459 ++it;
460 ByteWriter<uint16_t>::WriteBigEndian(&(*it)->data[2], 0);
461
462 // Lose the last two media packets (seq# 65533, 65534).
463 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
464 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
465 this->media_loss_mask_[1] = 1;
466 this->media_loss_mask_[2] = 1;
467 this->ReceivedPackets(this->media_packets_, this->media_loss_mask_, false);
468 this->ReceivedPackets(this->generated_fec_packets_, this->fec_loss_mask_,
469 true);
470
471 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
472 &this->recovered_packets_));
473
474 // The two FEC packets are received and should allow for complete recovery,
475 // but because of the wrap the first FEC packet will be discarded, and only
476 // one media packet is recoverable. So expect 2 media packets on recovered
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000477 // list and no complete recovery.
brandtrece4aba2016-09-20 23:16:28 -0700478 EXPECT_EQ(2u, this->recovered_packets_.size());
479 EXPECT_TRUE(this->recovered_packets_.size() != this->media_packets_.size());
480 EXPECT_FALSE(this->IsRecoveryComplete());
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000481}
482
brandtrd90fa0b2016-08-09 06:57:14 -0700483// Verify we can still recover frame if media packets are reordered.
brandtrece4aba2016-09-20 23:16:28 -0700484TYPED_TEST(RtpFecTest, FecRecoveryWithMediaOutOfOrder) {
brandtrd90fa0b2016-08-09 06:57:14 -0700485 constexpr int kNumImportantPackets = 0;
486 constexpr bool kUseUnequalProtection = false;
487 constexpr uint8_t kProtectionFactor = 20;
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000488
489 // One frame: 3 media packets, 1 FEC packet.
490 // -----Frame 1----
491 // #0(media) #1(media) #2(media) #3(FEC).
brandtrece4aba2016-09-20 23:16:28 -0700492 this->media_packets_ =
493 this->media_packet_generator_.ConstructMediaPackets(3, 0);
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000494
brandtrece4aba2016-09-20 23:16:28 -0700495 EXPECT_EQ(
496 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor,
497 kNumImportantPackets, kUseUnequalProtection,
498 kFecMaskBursty, &this->generated_fec_packets_));
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000499
500 // Expect 1 FEC packet.
brandtrece4aba2016-09-20 23:16:28 -0700501 EXPECT_EQ(1u, this->generated_fec_packets_.size());
brandtrd90fa0b2016-08-09 06:57:14 -0700502
503 // Lose one media packet (seq# 1).
brandtrece4aba2016-09-20 23:16:28 -0700504 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
505 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
506 this->media_loss_mask_[1] = 1;
507 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
brandtrd90fa0b2016-08-09 06:57:14 -0700508
509 // Reorder received media packets.
brandtrece4aba2016-09-20 23:16:28 -0700510 auto it0 = this->received_packets_.begin();
brandtrd726a3f2017-06-29 02:45:35 -0700511 auto it1 = this->received_packets_.begin();
512 it1++;
513 std::swap(*it0, *it1);
brandtrd90fa0b2016-08-09 06:57:14 -0700514
brandtrece4aba2016-09-20 23:16:28 -0700515 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
516 &this->recovered_packets_));
brandtrd90fa0b2016-08-09 06:57:14 -0700517
518 // Expect 3 media packets in recovered list, and complete recovery.
brandtrece4aba2016-09-20 23:16:28 -0700519 EXPECT_EQ(3u, this->recovered_packets_.size());
520 EXPECT_TRUE(this->IsRecoveryComplete());
brandtrd90fa0b2016-08-09 06:57:14 -0700521}
522
523// Verify we can still recover frame if FEC is received before media packets.
brandtrece4aba2016-09-20 23:16:28 -0700524TYPED_TEST(RtpFecTest, FecRecoveryWithFecOutOfOrder) {
brandtrd90fa0b2016-08-09 06:57:14 -0700525 constexpr int kNumImportantPackets = 0;
526 constexpr bool kUseUnequalProtection = false;
527 constexpr uint8_t kProtectionFactor = 20;
528
529 // One frame: 3 media packets, 1 FEC packet.
530 // -----Frame 1----
531 // #0(media) #1(media) #2(media) #3(FEC).
brandtrece4aba2016-09-20 23:16:28 -0700532 this->media_packets_ =
533 this->media_packet_generator_.ConstructMediaPackets(3, 0);
brandtrd90fa0b2016-08-09 06:57:14 -0700534
brandtrece4aba2016-09-20 23:16:28 -0700535 EXPECT_EQ(
536 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor,
537 kNumImportantPackets, kUseUnequalProtection,
538 kFecMaskBursty, &this->generated_fec_packets_));
brandtrd90fa0b2016-08-09 06:57:14 -0700539
540 // Expect 1 FEC packet.
brandtrece4aba2016-09-20 23:16:28 -0700541 EXPECT_EQ(1u, this->generated_fec_packets_.size());
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000542
543 // Lose one media packet (seq# 1).
brandtrece4aba2016-09-20 23:16:28 -0700544 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
545 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
546 this->media_loss_mask_[1] = 1;
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000547 // Add FEC packet to received list before the media packets.
brandtrece4aba2016-09-20 23:16:28 -0700548 this->ReceivedPackets(this->generated_fec_packets_, this->fec_loss_mask_,
549 true);
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000550 // Add media packets to received list.
brandtrece4aba2016-09-20 23:16:28 -0700551 this->ReceivedPackets(this->media_packets_, this->media_loss_mask_, false);
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000552
brandtrece4aba2016-09-20 23:16:28 -0700553 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
554 &this->recovered_packets_));
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000555
556 // Expect 3 media packets in recovered list, and complete recovery.
brandtrece4aba2016-09-20 23:16:28 -0700557 EXPECT_EQ(3u, this->recovered_packets_.size());
558 EXPECT_TRUE(this->IsRecoveryComplete());
marpan@webrtc.orgc8364532014-07-03 16:49:30 +0000559}
560
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000561// Test 50% protection with random mask type: Two cases are considered:
562// a 50% non-consecutive loss which can be fully recovered, and a 50%
563// consecutive loss which cannot be fully recovered.
brandtrece4aba2016-09-20 23:16:28 -0700564TYPED_TEST(RtpFecTest, FecRecoveryWithLoss50percRandomMask) {
brandtrd90fa0b2016-08-09 06:57:14 -0700565 constexpr int kNumImportantPackets = 0;
566 constexpr bool kUseUnequalProtection = false;
567 constexpr int kNumMediaPackets = 4;
568 constexpr uint8_t kProtectionFactor = 255;
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000569
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000570 // Packet Mask for (4,4,0) code, from random mask table.
571 // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 0)
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000572
573 // media#0 media#1 media#2 media#3
574 // fec#0: 1 1 0 0
575 // fec#1: 1 0 1 0
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000576 // fec#2: 0 0 1 1
577 // fec#3: 0 1 0 1
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000578 //
579
brandtrece4aba2016-09-20 23:16:28 -0700580 this->media_packets_ =
581 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000582
brandtrece4aba2016-09-20 23:16:28 -0700583 EXPECT_EQ(
584 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor,
585 kNumImportantPackets, kUseUnequalProtection,
586 kFecMaskRandom, &this->generated_fec_packets_));
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000587
588 // Expect 4 FEC packets.
brandtrece4aba2016-09-20 23:16:28 -0700589 EXPECT_EQ(4u, this->generated_fec_packets_.size());
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000590
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000591 // 4 packets lost: 3 media packets (0, 2, 3), and one FEC packet (0) lost.
brandtrece4aba2016-09-20 23:16:28 -0700592 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
593 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
594 this->fec_loss_mask_[0] = 1;
595 this->media_loss_mask_[0] = 1;
596 this->media_loss_mask_[2] = 1;
597 this->media_loss_mask_[3] = 1;
598 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000599
brandtrece4aba2016-09-20 23:16:28 -0700600 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
601 &this->recovered_packets_));
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000602
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000603 // With media packet#1 and FEC packets #1, #2, #3, expect complete recovery.
brandtrece4aba2016-09-20 23:16:28 -0700604 EXPECT_TRUE(this->IsRecoveryComplete());
605 this->recovered_packets_.clear();
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000606
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000607 // 4 consecutive packets lost: media packets 0, 1, 2, 3.
brandtrece4aba2016-09-20 23:16:28 -0700608 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
609 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
610 this->media_loss_mask_[0] = 1;
611 this->media_loss_mask_[1] = 1;
612 this->media_loss_mask_[2] = 1;
613 this->media_loss_mask_[3] = 1;
614 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000615
brandtrece4aba2016-09-20 23:16:28 -0700616 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
617 &this->recovered_packets_));
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000618
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000619 // Cannot get complete recovery for this loss configuration with random mask.
brandtrece4aba2016-09-20 23:16:28 -0700620 EXPECT_FALSE(this->IsRecoveryComplete());
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000621}
622
623// Test 50% protection with bursty type: Three cases are considered:
624// two 50% consecutive losses which can be fully recovered, and one
625// non-consecutive which cannot be fully recovered.
brandtrece4aba2016-09-20 23:16:28 -0700626TYPED_TEST(RtpFecTest, FecRecoveryWithLoss50percBurstyMask) {
brandtrd90fa0b2016-08-09 06:57:14 -0700627 constexpr int kNumImportantPackets = 0;
628 constexpr bool kUseUnequalProtection = false;
629 constexpr int kNumMediaPackets = 4;
630 constexpr uint8_t kProtectionFactor = 255;
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000631
632 // Packet Mask for (4,4,0) code, from bursty mask table.
633 // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 0)
634
635 // media#0 media#1 media#2 media#3
636 // fec#0: 1 0 0 0
637 // fec#1: 1 1 0 0
638 // fec#2: 0 1 1 0
639 // fec#3: 0 0 1 1
640 //
641
brandtrece4aba2016-09-20 23:16:28 -0700642 this->media_packets_ =
643 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets);
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000644
brandtrece4aba2016-09-20 23:16:28 -0700645 EXPECT_EQ(
646 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor,
647 kNumImportantPackets, kUseUnequalProtection,
648 kFecMaskBursty, &this->generated_fec_packets_));
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000649
650 // Expect 4 FEC packets.
brandtrece4aba2016-09-20 23:16:28 -0700651 EXPECT_EQ(4u, this->generated_fec_packets_.size());
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000652
653 // 4 consecutive packets lost: media packets 0,1,2,3.
brandtrece4aba2016-09-20 23:16:28 -0700654 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
655 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
656 this->media_loss_mask_[0] = 1;
657 this->media_loss_mask_[1] = 1;
658 this->media_loss_mask_[2] = 1;
659 this->media_loss_mask_[3] = 1;
660 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000661
brandtrece4aba2016-09-20 23:16:28 -0700662 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
663 &this->recovered_packets_));
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000664
665 // Expect complete recovery for consecutive packet loss <= 50%.
brandtrece4aba2016-09-20 23:16:28 -0700666 EXPECT_TRUE(this->IsRecoveryComplete());
667 this->recovered_packets_.clear();
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000668
669 // 4 consecutive packets lost: media packets 1,2, 3, and FEC packet 0.
brandtrece4aba2016-09-20 23:16:28 -0700670 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
671 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
672 this->fec_loss_mask_[0] = 1;
673 this->media_loss_mask_[1] = 1;
674 this->media_loss_mask_[2] = 1;
675 this->media_loss_mask_[3] = 1;
676 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000677
brandtrece4aba2016-09-20 23:16:28 -0700678 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
679 &this->recovered_packets_));
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000680
681 // Expect complete recovery for consecutive packet loss <= 50%.
brandtrece4aba2016-09-20 23:16:28 -0700682 EXPECT_TRUE(this->IsRecoveryComplete());
683 this->recovered_packets_.clear();
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000684
685 // 4 packets lost (non-consecutive loss): media packets 0, 3, and FEC# 0, 3.
brandtrece4aba2016-09-20 23:16:28 -0700686 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
687 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
688 this->fec_loss_mask_[0] = 1;
689 this->fec_loss_mask_[3] = 1;
690 this->media_loss_mask_[0] = 1;
691 this->media_loss_mask_[3] = 1;
692 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000693
brandtrece4aba2016-09-20 23:16:28 -0700694 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
695 &this->recovered_packets_));
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000696
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000697 // Cannot get complete recovery for this loss configuration.
brandtrece4aba2016-09-20 23:16:28 -0700698 EXPECT_FALSE(this->IsRecoveryComplete());
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000699}
700
brandtrece4aba2016-09-20 23:16:28 -0700701TYPED_TEST(RtpFecTest, FecRecoveryNoLossUep) {
brandtrd90fa0b2016-08-09 06:57:14 -0700702 constexpr int kNumImportantPackets = 2;
703 constexpr bool kUseUnequalProtection = true;
704 constexpr int kNumMediaPackets = 4;
705 constexpr uint8_t kProtectionFactor = 60;
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000706
brandtrece4aba2016-09-20 23:16:28 -0700707 this->media_packets_ =
708 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000709
brandtrece4aba2016-09-20 23:16:28 -0700710 EXPECT_EQ(
711 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor,
712 kNumImportantPackets, kUseUnequalProtection,
713 kFecMaskBursty, &this->generated_fec_packets_));
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000714
715 // Expect 1 FEC packet.
brandtrece4aba2016-09-20 23:16:28 -0700716 EXPECT_EQ(1u, this->generated_fec_packets_.size());
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000717
718 // No packets lost.
brandtrece4aba2016-09-20 23:16:28 -0700719 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
720 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
721 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000722
brandtrece4aba2016-09-20 23:16:28 -0700723 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
724 &this->recovered_packets_));
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000725
726 // No packets lost, expect complete recovery.
brandtrece4aba2016-09-20 23:16:28 -0700727 EXPECT_TRUE(this->IsRecoveryComplete());
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000728}
729
brandtrece4aba2016-09-20 23:16:28 -0700730TYPED_TEST(RtpFecTest, FecRecoveryWithLossUep) {
brandtrd90fa0b2016-08-09 06:57:14 -0700731 constexpr int kNumImportantPackets = 2;
732 constexpr bool kUseUnequalProtection = true;
733 constexpr int kNumMediaPackets = 4;
734 constexpr uint8_t kProtectionFactor = 60;
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000735
brandtrece4aba2016-09-20 23:16:28 -0700736 this->media_packets_ =
737 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000738
brandtrece4aba2016-09-20 23:16:28 -0700739 EXPECT_EQ(
740 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor,
741 kNumImportantPackets, kUseUnequalProtection,
742 kFecMaskBursty, &this->generated_fec_packets_));
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000743
744 // Expect 1 FEC packet.
brandtrece4aba2016-09-20 23:16:28 -0700745 EXPECT_EQ(1u, this->generated_fec_packets_.size());
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000746
747 // 1 media packet lost.
brandtrece4aba2016-09-20 23:16:28 -0700748 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
749 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
750 this->media_loss_mask_[3] = 1;
751 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000752
brandtrece4aba2016-09-20 23:16:28 -0700753 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
754 &this->recovered_packets_));
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000755
756 // One packet lost, one FEC packet, expect complete recovery.
brandtrece4aba2016-09-20 23:16:28 -0700757 EXPECT_TRUE(this->IsRecoveryComplete());
758 this->recovered_packets_.clear();
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000759
760 // 2 media packets lost.
brandtrece4aba2016-09-20 23:16:28 -0700761 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
762 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
763 this->media_loss_mask_[1] = 1;
764 this->media_loss_mask_[3] = 1;
765 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000766
brandtrece4aba2016-09-20 23:16:28 -0700767 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
768 &this->recovered_packets_));
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000769
770 // 2 packets lost, one FEC packet, cannot get complete recovery.
brandtrece4aba2016-09-20 23:16:28 -0700771 EXPECT_FALSE(this->IsRecoveryComplete());
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000772}
773
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000774// Test 50% protection with random mask type for UEP on.
brandtrece4aba2016-09-20 23:16:28 -0700775TYPED_TEST(RtpFecTest, FecRecoveryWithLoss50percUepRandomMask) {
brandtrd90fa0b2016-08-09 06:57:14 -0700776 constexpr int kNumImportantPackets = 1;
777 constexpr bool kUseUnequalProtection = true;
778 constexpr int kNumMediaPackets = 4;
779 constexpr uint8_t kProtectionFactor = 255;
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000780
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000781 // Packet Mask for (4,4,1) code, from random mask table.
782 // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 1)
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000783
784 // media#0 media#1 media#2 media#3
785 // fec#0: 1 0 0 0
786 // fec#1: 1 1 0 0
787 // fec#2: 1 0 1 1
788 // fec#3: 0 1 1 0
789 //
790
brandtrece4aba2016-09-20 23:16:28 -0700791 this->media_packets_ =
792 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000793
brandtrece4aba2016-09-20 23:16:28 -0700794 EXPECT_EQ(
795 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor,
796 kNumImportantPackets, kUseUnequalProtection,
797 kFecMaskRandom, &this->generated_fec_packets_));
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000798
799 // Expect 4 FEC packets.
brandtrece4aba2016-09-20 23:16:28 -0700800 EXPECT_EQ(4u, this->generated_fec_packets_.size());
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000801
802 // 4 packets lost: 3 media packets and FEC packet#1 lost.
brandtrece4aba2016-09-20 23:16:28 -0700803 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
804 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
805 this->fec_loss_mask_[1] = 1;
806 this->media_loss_mask_[0] = 1;
807 this->media_loss_mask_[2] = 1;
808 this->media_loss_mask_[3] = 1;
809 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000810
brandtrece4aba2016-09-20 23:16:28 -0700811 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
812 &this->recovered_packets_));
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000813
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000814 // With media packet#3 and FEC packets #0, #1, #3, expect complete recovery.
brandtrece4aba2016-09-20 23:16:28 -0700815 EXPECT_TRUE(this->IsRecoveryComplete());
816 this->recovered_packets_.clear();
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000817
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000818 // 5 packets lost: 4 media packets and one FEC packet#2 lost.
brandtrece4aba2016-09-20 23:16:28 -0700819 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
820 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
821 this->fec_loss_mask_[2] = 1;
822 this->media_loss_mask_[0] = 1;
823 this->media_loss_mask_[1] = 1;
824 this->media_loss_mask_[2] = 1;
825 this->media_loss_mask_[3] = 1;
826 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000827
brandtrece4aba2016-09-20 23:16:28 -0700828 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
829 &this->recovered_packets_));
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000830
831 // Cannot get complete recovery for this loss configuration.
brandtrece4aba2016-09-20 23:16:28 -0700832 EXPECT_FALSE(this->IsRecoveryComplete());
marpan@webrtc.orgb783a552012-02-04 02:46:35 +0000833}
834
brandtrece4aba2016-09-20 23:16:28 -0700835TYPED_TEST(RtpFecTest, FecRecoveryNonConsecutivePackets) {
brandtrd90fa0b2016-08-09 06:57:14 -0700836 constexpr int kNumImportantPackets = 0;
837 constexpr bool kUseUnequalProtection = false;
838 constexpr int kNumMediaPackets = 5;
839 constexpr uint8_t kProtectionFactor = 60;
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000840
brandtrece4aba2016-09-20 23:16:28 -0700841 this->media_packets_ =
842 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets);
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000843
844 // Create a new temporary packet list for generating FEC packets.
845 // This list should have every other packet removed.
brandtrece4aba2016-09-20 23:16:28 -0700846 ForwardErrorCorrection::PacketList protected_media_packets;
847 DeepCopyEveryNthPacket(this->media_packets_, 2, &protected_media_packets);
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000848
brandtrece4aba2016-09-20 23:16:28 -0700849 EXPECT_EQ(
850 0, this->fec_.EncodeFec(protected_media_packets, kProtectionFactor,
851 kNumImportantPackets, kUseUnequalProtection,
852 kFecMaskBursty, &this->generated_fec_packets_));
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000853
854 // Expect 1 FEC packet.
brandtrece4aba2016-09-20 23:16:28 -0700855 EXPECT_EQ(1u, this->generated_fec_packets_.size());
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000856
857 // 1 protected media packet lost
brandtrece4aba2016-09-20 23:16:28 -0700858 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
859 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
860 this->media_loss_mask_[2] = 1;
861 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000862
brandtrece4aba2016-09-20 23:16:28 -0700863 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
864 &this->recovered_packets_));
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000865
866 // One packet lost, one FEC packet, expect complete recovery.
brandtrece4aba2016-09-20 23:16:28 -0700867 EXPECT_TRUE(this->IsRecoveryComplete());
868 this->recovered_packets_.clear();
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000869
870 // Unprotected packet lost.
brandtrece4aba2016-09-20 23:16:28 -0700871 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
872 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
873 this->media_loss_mask_[1] = 1;
874 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000875
brandtrece4aba2016-09-20 23:16:28 -0700876 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
877 &this->recovered_packets_));
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000878
879 // Unprotected packet lost. Recovery not possible.
brandtrece4aba2016-09-20 23:16:28 -0700880 EXPECT_FALSE(this->IsRecoveryComplete());
881 this->recovered_packets_.clear();
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000882
883 // 2 media packets lost.
brandtrece4aba2016-09-20 23:16:28 -0700884 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
885 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
886 this->media_loss_mask_[0] = 1;
887 this->media_loss_mask_[2] = 1;
888 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000889
brandtrece4aba2016-09-20 23:16:28 -0700890 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
891 &this->recovered_packets_));
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000892
893 // 2 protected packets lost, one FEC packet, cannot get complete recovery.
brandtrece4aba2016-09-20 23:16:28 -0700894 EXPECT_FALSE(this->IsRecoveryComplete());
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000895}
896
brandtrece4aba2016-09-20 23:16:28 -0700897TYPED_TEST(RtpFecTest, FecRecoveryNonConsecutivePacketsExtension) {
brandtrd90fa0b2016-08-09 06:57:14 -0700898 constexpr int kNumImportantPackets = 0;
899 constexpr bool kUseUnequalProtection = false;
900 constexpr int kNumMediaPackets = 21;
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000901 uint8_t kProtectionFactor = 127;
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000902
brandtrece4aba2016-09-20 23:16:28 -0700903 this->media_packets_ =
904 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets);
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000905
906 // Create a new temporary packet list for generating FEC packets.
907 // This list should have every other packet removed.
brandtrece4aba2016-09-20 23:16:28 -0700908 ForwardErrorCorrection::PacketList protected_media_packets;
909 DeepCopyEveryNthPacket(this->media_packets_, 2, &protected_media_packets);
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000910
911 // Zero column insertion will have to extend the size of the packet
912 // mask since the number of actual packets are 21, while the number
913 // of protected packets are 11.
brandtrece4aba2016-09-20 23:16:28 -0700914 EXPECT_EQ(
915 0, this->fec_.EncodeFec(protected_media_packets, kProtectionFactor,
916 kNumImportantPackets, kUseUnequalProtection,
917 kFecMaskBursty, &this->generated_fec_packets_));
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000918
919 // Expect 5 FEC packet.
brandtrece4aba2016-09-20 23:16:28 -0700920 EXPECT_EQ(5u, this->generated_fec_packets_.size());
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000921
922 // Last protected media packet lost
brandtrece4aba2016-09-20 23:16:28 -0700923 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
924 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
925 this->media_loss_mask_[kNumMediaPackets - 1] = 1;
926 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000927
brandtrece4aba2016-09-20 23:16:28 -0700928 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
929 &this->recovered_packets_));
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000930
931 // One packet lost, one FEC packet, expect complete recovery.
brandtrece4aba2016-09-20 23:16:28 -0700932 EXPECT_TRUE(this->IsRecoveryComplete());
933 this->recovered_packets_.clear();
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000934
935 // Last unprotected packet lost.
brandtrece4aba2016-09-20 23:16:28 -0700936 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
937 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
938 this->media_loss_mask_[kNumMediaPackets - 2] = 1;
939 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000940
brandtrece4aba2016-09-20 23:16:28 -0700941 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
942 &this->recovered_packets_));
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000943
944 // Unprotected packet lost. Recovery not possible.
brandtrece4aba2016-09-20 23:16:28 -0700945 EXPECT_FALSE(this->IsRecoveryComplete());
946 this->recovered_packets_.clear();
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000947
948 // 6 media packets lost.
brandtrece4aba2016-09-20 23:16:28 -0700949 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
950 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
951 this->media_loss_mask_[kNumMediaPackets - 11] = 1;
952 this->media_loss_mask_[kNumMediaPackets - 9] = 1;
953 this->media_loss_mask_[kNumMediaPackets - 7] = 1;
954 this->media_loss_mask_[kNumMediaPackets - 5] = 1;
955 this->media_loss_mask_[kNumMediaPackets - 3] = 1;
956 this->media_loss_mask_[kNumMediaPackets - 1] = 1;
957 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000958
brandtrece4aba2016-09-20 23:16:28 -0700959 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
960 &this->recovered_packets_));
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000961
962 // 5 protected packets lost, one FEC packet, cannot get complete recovery.
brandtrece4aba2016-09-20 23:16:28 -0700963 EXPECT_FALSE(this->IsRecoveryComplete());
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000964}
965
brandtrece4aba2016-09-20 23:16:28 -0700966TYPED_TEST(RtpFecTest, FecRecoveryNonConsecutivePacketsWrap) {
brandtrd90fa0b2016-08-09 06:57:14 -0700967 constexpr int kNumImportantPackets = 0;
968 constexpr bool kUseUnequalProtection = false;
969 constexpr int kNumMediaPackets = 21;
marpan@webrtc.org8866bb12012-06-05 16:42:20 +0000970 uint8_t kProtectionFactor = 127;
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000971
brandtrece4aba2016-09-20 23:16:28 -0700972 this->media_packets_ = this->media_packet_generator_.ConstructMediaPackets(
973 kNumMediaPackets, 0xFFFF - 5);
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000974
975 // Create a new temporary packet list for generating FEC packets.
976 // This list should have every other packet removed.
brandtrece4aba2016-09-20 23:16:28 -0700977 ForwardErrorCorrection::PacketList protected_media_packets;
978 DeepCopyEveryNthPacket(this->media_packets_, 2, &protected_media_packets);
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000979
980 // Zero column insertion will have to extend the size of the packet
981 // mask since the number of actual packets are 21, while the number
982 // of protected packets are 11.
brandtrece4aba2016-09-20 23:16:28 -0700983 EXPECT_EQ(
984 0, this->fec_.EncodeFec(protected_media_packets, kProtectionFactor,
985 kNumImportantPackets, kUseUnequalProtection,
986 kFecMaskBursty, &this->generated_fec_packets_));
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000987
988 // Expect 5 FEC packet.
brandtrece4aba2016-09-20 23:16:28 -0700989 EXPECT_EQ(5u, this->generated_fec_packets_.size());
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000990
991 // Last protected media packet lost
brandtrece4aba2016-09-20 23:16:28 -0700992 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
993 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
994 this->media_loss_mask_[kNumMediaPackets - 1] = 1;
995 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000996
brandtrece4aba2016-09-20 23:16:28 -0700997 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
998 &this->recovered_packets_));
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +0000999
1000 // One packet lost, one FEC packet, expect complete recovery.
brandtrece4aba2016-09-20 23:16:28 -07001001 EXPECT_TRUE(this->IsRecoveryComplete());
1002 this->recovered_packets_.clear();
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +00001003
1004 // Last unprotected packet lost.
brandtrece4aba2016-09-20 23:16:28 -07001005 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
1006 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
1007 this->media_loss_mask_[kNumMediaPackets - 2] = 1;
1008 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +00001009
brandtrece4aba2016-09-20 23:16:28 -07001010 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
1011 &this->recovered_packets_));
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +00001012
1013 // Unprotected packet lost. Recovery not possible.
brandtrece4aba2016-09-20 23:16:28 -07001014 EXPECT_FALSE(this->IsRecoveryComplete());
1015 this->recovered_packets_.clear();
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +00001016
1017 // 6 media packets lost.
brandtrece4aba2016-09-20 23:16:28 -07001018 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
1019 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_));
1020 this->media_loss_mask_[kNumMediaPackets - 11] = 1;
1021 this->media_loss_mask_[kNumMediaPackets - 9] = 1;
1022 this->media_loss_mask_[kNumMediaPackets - 7] = 1;
1023 this->media_loss_mask_[kNumMediaPackets - 5] = 1;
1024 this->media_loss_mask_[kNumMediaPackets - 3] = 1;
1025 this->media_loss_mask_[kNumMediaPackets - 1] = 1;
1026 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_);
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +00001027
brandtrece4aba2016-09-20 23:16:28 -07001028 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_,
1029 &this->recovered_packets_));
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +00001030
1031 // 5 protected packets lost, one FEC packet, cannot get complete recovery.
brandtrece4aba2016-09-20 23:16:28 -07001032 EXPECT_FALSE(this->IsRecoveryComplete());
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +00001033}
1034
brandtrece4aba2016-09-20 23:16:28 -07001035} // namespace webrtc