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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <list> 12 #include <list>
13 13
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webrtc/base/random.h" 15 #include "webrtc/base/random.h"
16 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" 16 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
17 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" 17 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h"
18 18
19 using webrtc::ForwardErrorCorrection; 19 using webrtc::ForwardErrorCorrection;
20 20
21 // Minimum RTP header size in bytes. 21 // Minimum RTP header size in bytes.
22 const uint8_t kRtpHeaderSize = 12; 22 constexpr uint8_t kRtpHeaderSize = 12;
23 23
24 // Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum. 24 // Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum.
25 const uint8_t kTransportOverhead = 28; 25 constexpr uint8_t kTransportOverhead = 28;
26 26
27 // Maximum number of media packets used in the FEC (RFC 5109). 27 // Maximum number of media packets used in the FEC (RFC 5109).
28 const uint8_t kMaxNumberMediaPackets = ForwardErrorCorrection::kMaxMediaPackets; 28 constexpr uint8_t kMaxNumberMediaPackets =
29 ForwardErrorCorrection::kMaxMediaPackets;
29 30
30 using PacketList = ForwardErrorCorrection::PacketList; 31 using PacketList = ForwardErrorCorrection::PacketList;
31 using ReceivedPacketList = ForwardErrorCorrection::ReceivedPacketList; 32 using ReceivedPacketList = ForwardErrorCorrection::ReceivedPacketList;
32 using RecoveredPacketList = ForwardErrorCorrection::RecoveredPacketList; 33 using RecoveredPacketList = ForwardErrorCorrection::RecoveredPacketList;
33 34
34 class RtpFecTest : public ::testing::Test { 35 class RtpFecTest : public ::testing::Test {
35 protected: 36 protected:
36 RtpFecTest() 37 RtpFecTest()
37 : random_(0xfec133700742), 38 : random_(0xfec133700742),
38 fec_(new ForwardErrorCorrection()), 39 fec_(new ForwardErrorCorrection()),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 void ReceivedPackets(const T& packet_list, int* loss_mask, bool is_fec); 78 void ReceivedPackets(const T& packet_list, int* loss_mask, bool is_fec);
78 79
79 // Check for complete recovery after FEC decoding. 80 // Check for complete recovery after FEC decoding.
80 bool IsRecoveryComplete(); 81 bool IsRecoveryComplete();
81 82
82 // Delete the media and FEC packets. 83 // Delete the media and FEC packets.
83 void TearDown(); 84 void TearDown();
84 }; 85 };
85 86
86 TEST_F(RtpFecTest, FecRecoveryNoLoss) { 87 TEST_F(RtpFecTest, FecRecoveryNoLoss) {
87 const int kNumImportantPackets = 0; 88 constexpr int kNumImportantPackets = 0;
88 const bool kUseUnequalProtection = false; 89 constexpr bool kUseUnequalProtection = false;
89 const int kNumMediaPackets = 4; 90 constexpr int kNumMediaPackets = 4;
90 uint8_t kProtectionFactor = 60; 91 constexpr uint8_t kProtectionFactor = 60;
91 92
92 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); 93 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets);
93 94
94 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor, 95 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor,
95 kNumImportantPackets, kUseUnequalProtection, 96 kNumImportantPackets, kUseUnequalProtection,
96 webrtc::kFecMaskBursty, &fec_packet_list_)); 97 webrtc::kFecMaskBursty, &fec_packet_list_));
97 98
98 // Expect 1 FEC packet. 99 // Expect 1 FEC packet.
99 EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size())); 100 EXPECT_EQ(1u, fec_packet_list_.size());
100 101
101 // No packets lost. 102 // No packets lost.
102 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); 103 memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
103 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); 104 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
104 NetworkReceivedPackets(); 105 NetworkReceivedPackets();
105 106
106 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_, 107 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_,
107 &recovered_packet_list_)); 108 &recovered_packet_list_));
108 109
109 // No packets lost, expect complete recovery. 110 // No packets lost, expect complete recovery.
110 EXPECT_TRUE(IsRecoveryComplete()); 111 EXPECT_TRUE(IsRecoveryComplete());
111 } 112 }
112 113
113 TEST_F(RtpFecTest, FecRecoveryWithLoss) { 114 TEST_F(RtpFecTest, FecRecoveryWithLoss) {
114 const int kNumImportantPackets = 0; 115 constexpr int kNumImportantPackets = 0;
115 const bool kUseUnequalProtection = false; 116 constexpr bool kUseUnequalProtection = false;
116 const int kNumMediaPackets = 4; 117 constexpr int kNumMediaPackets = 4;
117 uint8_t kProtectionFactor = 60; 118 constexpr uint8_t kProtectionFactor = 60;
118 119
119 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); 120 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets);
120 121
121 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor, 122 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor,
122 kNumImportantPackets, kUseUnequalProtection, 123 kNumImportantPackets, kUseUnequalProtection,
123 webrtc::kFecMaskBursty, &fec_packet_list_)); 124 webrtc::kFecMaskBursty, &fec_packet_list_));
124 125
125 // Expect 1 FEC packet. 126 // Expect 1 FEC packet.
126 EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size())); 127 EXPECT_EQ(1u, fec_packet_list_.size());
127 128
128 // 1 media packet lost 129 // 1 media packet lost
129 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); 130 memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
130 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); 131 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
131 media_loss_mask_[3] = 1; 132 media_loss_mask_[3] = 1;
132 NetworkReceivedPackets(); 133 NetworkReceivedPackets();
133 134
134 EXPECT_EQ(0, 135 EXPECT_EQ(0,
135 fec_->DecodeFec(&received_packet_list_, &recovered_packet_list_)); 136 fec_->DecodeFec(&received_packet_list_, &recovered_packet_list_));
136 137
(...skipping 10 matching lines...) Expand all
147 148
148 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_, 149 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_,
149 &recovered_packet_list_)); 150 &recovered_packet_list_));
150 151
151 // 2 packets lost, one FEC packet, cannot get complete recovery. 152 // 2 packets lost, one FEC packet, cannot get complete recovery.
152 EXPECT_FALSE(IsRecoveryComplete()); 153 EXPECT_FALSE(IsRecoveryComplete());
153 } 154 }
154 155
155 // Verify that we don't use an old FEC packet for FEC decoding. 156 // Verify that we don't use an old FEC packet for FEC decoding.
156 TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapTwoFrames) { 157 TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapTwoFrames) {
157 const int kNumImportantPackets = 0; 158 constexpr int kNumImportantPackets = 0;
158 const bool kUseUnequalProtection = false; 159 constexpr bool kUseUnequalProtection = false;
159 uint8_t kProtectionFactor = 20; 160 constexpr uint8_t kProtectionFactor = 20;
160 161
161 // Two frames: first frame (old) with two media packets and 1 FEC packet. 162 // Two frames: first frame (old) with two media packets and 1 FEC packet.
162 // Second frame (new) with 3 media packets, and no FEC packets. 163 // Second frame (new) with 3 media packets, and no FEC packets.
163 // ---Frame 1---- ----Frame 2------ 164 // ---Frame 1---- ----Frame 2------
164 // #0(media) #1(media) #2(FEC) #65535(media) #0(media) #1(media). 165 // #0(media) #1(media) #2(FEC) #65535(media) #0(media) #1(media).
165 // If we lose either packet 0 or 1 of second frame, FEC decoding should not 166 // If we lose either packet 0 or 1 of second frame, FEC decoding should not
166 // try to decode using "old" FEC packet #2. 167 // try to decode using "old" FEC packet #2.
167 168
168 // Construct media packets for first frame, starting at sequence number 0. 169 // Construct media packets for first frame, starting at sequence number 0.
169 fec_seq_num_ = ConstructMediaPacketsSeqNum(2, 0); 170 fec_seq_num_ = ConstructMediaPacketsSeqNum(2, 0);
170 171
171 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor, 172 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor,
172 kNumImportantPackets, kUseUnequalProtection, 173 kNumImportantPackets, kUseUnequalProtection,
173 webrtc::kFecMaskBursty, &fec_packet_list_)); 174 webrtc::kFecMaskBursty, &fec_packet_list_));
174 // Expect 1 FEC packet. 175 // Expect 1 FEC packet.
175 EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size())); 176 EXPECT_EQ(1u, fec_packet_list_.size());
176 // Add FEC packet (seq#2) of this first frame to received list (i.e., assume 177 // Add FEC packet (seq#2) of this first frame to received list (i.e., assume
177 // the two media packet were lost). 178 // the two media packet were lost).
178 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); 179 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
179 ReceivedPackets(fec_packet_list_, fec_loss_mask_, true); 180 ReceivedPackets(fec_packet_list_, fec_loss_mask_, true);
180 181
181 // Construct media packets for second frame, with sequence number wrap. 182 // Construct media packets for second frame, with sequence number wrap.
182 media_packet_list_.clear(); 183 media_packet_list_.clear();
183 fec_seq_num_ = ConstructMediaPacketsSeqNum(3, 65535); 184 fec_seq_num_ = ConstructMediaPacketsSeqNum(3, 65535);
184 185
185 // Expect 3 media packets for this frame. 186 // Expect 3 media packets for this frame.
186 EXPECT_EQ(3, static_cast<int>(media_packet_list_.size())); 187 EXPECT_EQ(3u, media_packet_list_.size());
187 188
188 // Second media packet lost (seq#0). 189 // Second media packet lost (seq#0).
189 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); 190 memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
190 media_loss_mask_[1] = 1; 191 media_loss_mask_[1] = 1;
191 // Add packets #65535, and #1 to received list. 192 // Add packets #65535, and #1 to received list.
192 ReceivedPackets(media_packet_list_, media_loss_mask_, false); 193 ReceivedPackets(media_packet_list_, media_loss_mask_, false);
193 194
194 EXPECT_EQ(0, 195 EXPECT_EQ(0,
195 fec_->DecodeFec(&received_packet_list_, &recovered_packet_list_)); 196 fec_->DecodeFec(&received_packet_list_, &recovered_packet_list_));
196 197
197 // Expect that no decoding is done to get missing packet (seq#0) of second 198 // Expect that no decoding is done to get missing packet (seq#0) of second
198 // frame, using old FEC packet (seq#2) from first (old) frame. So number of 199 // frame, using old FEC packet (seq#2) from first (old) frame. So number of
199 // recovered packets is 2, and not equal to number of media packets (=3). 200 // recovered packets is 2, and not equal to number of media packets (=3).
200 EXPECT_EQ(2, static_cast<int>(recovered_packet_list_.size())); 201 EXPECT_EQ(2u, recovered_packet_list_.size());
201 EXPECT_TRUE(recovered_packet_list_.size() != media_packet_list_.size()); 202 EXPECT_TRUE(recovered_packet_list_.size() != media_packet_list_.size());
202 } 203 }
203 204
204 // Verify we can still recovery frame if sequence number wrap occurs within 205 // Verify we can still recover frame if sequence number wrap occurs within
205 // the frame and FEC packet following wrap is received after media packets. 206 // the frame and FEC packet following wrap is received after media packets.
206 TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameRecovery) { 207 TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameRecovery) {
207 const int kNumImportantPackets = 0; 208 constexpr int kNumImportantPackets = 0;
208 const bool kUseUnequalProtection = false; 209 constexpr bool kUseUnequalProtection = false;
209 uint8_t kProtectionFactor = 20; 210 constexpr uint8_t kProtectionFactor = 20;
210 211
211 // One frame, with sequence number wrap in media packets. 212 // One frame, with sequence number wrap in media packets.
212 // -----Frame 1---- 213 // -----Frame 1----
213 // #65534(media) #65535(media) #0(media) #1(FEC). 214 // #65534(media) #65535(media) #0(media) #1(FEC).
214 fec_seq_num_ = ConstructMediaPacketsSeqNum(3, 65534); 215 fec_seq_num_ = ConstructMediaPacketsSeqNum(3, 65534);
215 216
216 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor, 217 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor,
217 kNumImportantPackets, kUseUnequalProtection, 218 kNumImportantPackets, kUseUnequalProtection,
218 webrtc::kFecMaskBursty, &fec_packet_list_)); 219 webrtc::kFecMaskBursty, &fec_packet_list_));
219 220
220 // Expect 1 FEC packet. 221 // Expect 1 FEC packet.
221 EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size())); 222 EXPECT_EQ(1u, fec_packet_list_.size());
222 223
223 // Lose one media packet (seq# 65535). 224 // Lose one media packet (seq# 65535).
224 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); 225 memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
225 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); 226 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
226 media_loss_mask_[1] = 1; 227 media_loss_mask_[1] = 1;
227 ReceivedPackets(media_packet_list_, media_loss_mask_, false); 228 ReceivedPackets(media_packet_list_, media_loss_mask_, false);
228 // Add FEC packet to received list following the media packets. 229 // Add FEC packet to received list following the media packets.
229 ReceivedPackets(fec_packet_list_, fec_loss_mask_, true); 230 ReceivedPackets(fec_packet_list_, fec_loss_mask_, true);
230 231
231 EXPECT_EQ(0, 232 EXPECT_EQ(0,
232 fec_->DecodeFec(&received_packet_list_, &recovered_packet_list_)); 233 fec_->DecodeFec(&received_packet_list_, &recovered_packet_list_));
233 234
234 // Expect 3 media packets in recovered list, and complete recovery. 235 // Expect 3 media packets in recovered list, and complete recovery.
235 // Wrap-around won't remove FEC packet, as it follows the wrap. 236 // Wrap-around won't remove FEC packet, as it follows the wrap.
236 EXPECT_EQ(3, static_cast<int>(recovered_packet_list_.size())); 237 EXPECT_EQ(3u, recovered_packet_list_.size());
237 EXPECT_TRUE(IsRecoveryComplete()); 238 EXPECT_TRUE(IsRecoveryComplete());
238 } 239 }
239 240
240 // Sequence number wrap occurs within the FEC packets for the frame. 241 // Sequence number wrap occurs within the FEC packets for the frame.
241 // In this case we will discard FEC packet and full recovery is not expected. 242 // In this case we will discard FEC packet and full recovery is not expected.
242 // Same problem will occur if wrap is within media packets but FEC packet is 243 // Same problem will occur if wrap is within media packets but FEC packet is
243 // received before the media packets. This may be improved if timing information 244 // received before the media packets. This may be improved if timing information
244 // is used to detect old FEC packets. 245 // is used to detect old FEC packets.
245 // TODO(marpan): Update test if wrap-around handling changes in FEC decoding. 246 // TODO(marpan): Update test if wrap-around handling changes in FEC decoding.
246 TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameNoRecovery) { 247 TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameNoRecovery) {
247 const int kNumImportantPackets = 0; 248 constexpr int kNumImportantPackets = 0;
248 const bool kUseUnequalProtection = false; 249 constexpr bool kUseUnequalProtection = false;
249 uint8_t kProtectionFactor = 200; 250 constexpr uint8_t kProtectionFactor = 200;
250 251
251 // 1 frame: 3 media packets and 2 FEC packets. 252 // 1 frame: 3 media packets and 2 FEC packets.
252 // Sequence number wrap in FEC packets. 253 // Sequence number wrap in FEC packets.
253 // -----Frame 1---- 254 // -----Frame 1----
254 // #65532(media) #65533(media) #65534(media) #65535(FEC) #0(FEC). 255 // #65532(media) #65533(media) #65534(media) #65535(FEC) #0(FEC).
255 fec_seq_num_ = ConstructMediaPacketsSeqNum(3, 65532); 256 fec_seq_num_ = ConstructMediaPacketsSeqNum(3, 65532);
256 257
257 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor, 258 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor,
258 kNumImportantPackets, kUseUnequalProtection, 259 kNumImportantPackets, kUseUnequalProtection,
259 webrtc::kFecMaskBursty, &fec_packet_list_)); 260 webrtc::kFecMaskBursty, &fec_packet_list_));
260 261
261 // Expect 2 FEC packets. 262 // Expect 2 FEC packets.
262 EXPECT_EQ(2, static_cast<int>(fec_packet_list_.size())); 263 EXPECT_EQ(2u, fec_packet_list_.size());
263 264
264 // Lose the last two media packets (seq# 65533, 65534). 265 // Lose the last two media packets (seq# 65533, 65534).
265 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); 266 memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
266 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); 267 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
267 media_loss_mask_[1] = 1; 268 media_loss_mask_[1] = 1;
268 media_loss_mask_[2] = 1; 269 media_loss_mask_[2] = 1;
269 ReceivedPackets(media_packet_list_, media_loss_mask_, false); 270 ReceivedPackets(media_packet_list_, media_loss_mask_, false);
270 ReceivedPackets(fec_packet_list_, fec_loss_mask_, true); 271 ReceivedPackets(fec_packet_list_, fec_loss_mask_, true);
271 272
272 EXPECT_EQ(0, 273 EXPECT_EQ(0,
273 fec_->DecodeFec(&received_packet_list_, &recovered_packet_list_)); 274 fec_->DecodeFec(&received_packet_list_, &recovered_packet_list_));
274 275
275 // The two FEC packets are received and should allow for complete recovery, 276 // The two FEC packets are received and should allow for complete recovery,
276 // but because of the wrap the second FEC packet will be discarded, and only 277 // but because of the wrap the second FEC packet will be discarded, and only
277 // one media packet is recoverable. So exepct 2 media packets on recovered 278 // one media packet is recoverable. So exepct 2 media packets on recovered
278 // list and no complete recovery. 279 // list and no complete recovery.
279 EXPECT_EQ(2, static_cast<int>(recovered_packet_list_.size())); 280 EXPECT_EQ(2u, recovered_packet_list_.size());
280 EXPECT_TRUE(recovered_packet_list_.size() != media_packet_list_.size()); 281 EXPECT_TRUE(recovered_packet_list_.size() != media_packet_list_.size());
281 EXPECT_FALSE(IsRecoveryComplete()); 282 EXPECT_FALSE(IsRecoveryComplete());
282 } 283 }
283 284
284 // Verify we can still recovery frame if FEC is received before media packets. 285 // Verify we can still recover frame if media packets are reordered.
285 TEST_F(RtpFecTest, FecRecoveryWithFecOutOfOrder) { 286 TEST_F(RtpFecTest, FecRecoveryWithMediaReordering) {
286 const int kNumImportantPackets = 0; 287 constexpr int kNumImportantPackets = 0;
287 const bool kUseUnequalProtection = false; 288 constexpr bool kUseUnequalProtection = false;
288 uint8_t kProtectionFactor = 20; 289 constexpr uint8_t kProtectionFactor = 20;
289 290
290 // One frame: 3 media packets, 1 FEC packet. 291 // One frame: 3 media packets, 1 FEC packet.
291 // -----Frame 1---- 292 // -----Frame 1----
293 // #0(media) #1(media) #2(media) #3(FEC).
294 fec_seq_num_ = ConstructMediaPacketsSeqNum(3, 0);
295
296 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor,
297 kNumImportantPackets, kUseUnequalProtection,
298 webrtc::kFecMaskBursty, &fec_packet_list_));
299
300 // Expect 1 FEC packet.
301 EXPECT_EQ(1u, fec_packet_list_.size());
302
303 // Lose one media packet (seq# 1).
304 memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
305 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
306 media_loss_mask_[1] = 1;
307 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.
308
309 // Reorder received media packets.
310 auto it0 = received_packet_list_.begin();
311 auto it2 = received_packet_list_.begin();
312 it2++;
313 std::swap(*it0, *it2);
314
315 EXPECT_EQ(0,
316 fec_->DecodeFec(&received_packet_list_, &recovered_packet_list_));
317
318 // Expect 3 media packets in recovered list, and complete recovery.
319 EXPECT_EQ(3u, recovered_packet_list_.size());
320 EXPECT_TRUE(IsRecoveryComplete());
321 }
322
323 // Verify we can still recover frame if FEC is received before media packets.
324 TEST_F(RtpFecTest, FecRecoveryWithFecOutOfOrder) {
325 constexpr int kNumImportantPackets = 0;
326 constexpr bool kUseUnequalProtection = false;
327 constexpr uint8_t kProtectionFactor = 20;
328
329 // One frame: 3 media packets, 1 FEC packet.
330 // -----Frame 1----
292 // #0(media) #1(media) #2(media) #3(FEC). 331 // #0(media) #1(media) #2(media) #3(FEC).
293 fec_seq_num_ = ConstructMediaPacketsSeqNum(3, 0); 332 fec_seq_num_ = ConstructMediaPacketsSeqNum(3, 0);
294 333
295 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor, 334 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor,
296 kNumImportantPackets, kUseUnequalProtection, 335 kNumImportantPackets, kUseUnequalProtection,
297 webrtc::kFecMaskBursty, &fec_packet_list_)); 336 webrtc::kFecMaskBursty, &fec_packet_list_));
298 337
299 // Expect 1 FEC packet. 338 // Expect 1 FEC packet.
300 EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size())); 339 EXPECT_EQ(1u, fec_packet_list_.size());
301 340
302 // Lose one media packet (seq# 1). 341 // Lose one media packet (seq# 1).
303 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); 342 memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
304 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); 343 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
305 media_loss_mask_[1] = 1; 344 media_loss_mask_[1] = 1;
306 // Add FEC packet to received list before the media packets. 345 // Add FEC packet to received list before the media packets.
307 ReceivedPackets(fec_packet_list_, fec_loss_mask_, true); 346 ReceivedPackets(fec_packet_list_, fec_loss_mask_, true);
308 // Add media packets to received list. 347 // Add media packets to received list.
309 ReceivedPackets(media_packet_list_, media_loss_mask_, false); 348 ReceivedPackets(media_packet_list_, media_loss_mask_, false);
310 349
311 EXPECT_EQ(0, 350 EXPECT_EQ(0,
312 fec_->DecodeFec(&received_packet_list_, &recovered_packet_list_)); 351 fec_->DecodeFec(&received_packet_list_, &recovered_packet_list_));
313 352
314 // Expect 3 media packets in recovered list, and complete recovery. 353 // Expect 3 media packets in recovered list, and complete recovery.
315 EXPECT_EQ(3, static_cast<int>(recovered_packet_list_.size())); 354 EXPECT_EQ(3u, recovered_packet_list_.size());
316 EXPECT_TRUE(IsRecoveryComplete()); 355 EXPECT_TRUE(IsRecoveryComplete());
317 } 356 }
318 357
319 // Test 50% protection with random mask type: Two cases are considered: 358 // Test 50% protection with random mask type: Two cases are considered:
320 // a 50% non-consecutive loss which can be fully recovered, and a 50% 359 // a 50% non-consecutive loss which can be fully recovered, and a 50%
321 // consecutive loss which cannot be fully recovered. 360 // consecutive loss which cannot be fully recovered.
322 TEST_F(RtpFecTest, FecRecoveryWithLoss50percRandomMask) { 361 TEST_F(RtpFecTest, FecRecoveryWithLoss50percRandomMask) {
323 const int kNumImportantPackets = 0; 362 constexpr int kNumImportantPackets = 0;
324 const bool kUseUnequalProtection = false; 363 constexpr bool kUseUnequalProtection = false;
325 const int kNumMediaPackets = 4; 364 constexpr int kNumMediaPackets = 4;
326 const uint8_t kProtectionFactor = 255; 365 constexpr uint8_t kProtectionFactor = 255;
327 366
328 // Packet Mask for (4,4,0) code, from random mask table. 367 // Packet Mask for (4,4,0) code, from random mask table.
329 // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 0) 368 // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 0)
330 369
331 // media#0 media#1 media#2 media#3 370 // media#0 media#1 media#2 media#3
332 // fec#0: 1 1 0 0 371 // fec#0: 1 1 0 0
333 // fec#1: 1 0 1 0 372 // fec#1: 1 0 1 0
334 // fec#2: 0 0 1 1 373 // fec#2: 0 0 1 1
335 // fec#3: 0 1 0 1 374 // fec#3: 0 1 0 1
336 // 375 //
337 376
338 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); 377 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets);
339 378
340 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor, 379 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor,
341 kNumImportantPackets, kUseUnequalProtection, 380 kNumImportantPackets, kUseUnequalProtection,
342 webrtc::kFecMaskRandom, &fec_packet_list_)); 381 webrtc::kFecMaskRandom, &fec_packet_list_));
343 382
344 // Expect 4 FEC packets. 383 // Expect 4 FEC packets.
345 EXPECT_EQ(4, static_cast<int>(fec_packet_list_.size())); 384 EXPECT_EQ(4u, fec_packet_list_.size());
346 385
347 // 4 packets lost: 3 media packets (0, 2, 3), and one FEC packet (0) lost. 386 // 4 packets lost: 3 media packets (0, 2, 3), and one FEC packet (0) lost.
348 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); 387 memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
349 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); 388 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
350 fec_loss_mask_[0] = 1; 389 fec_loss_mask_[0] = 1;
351 media_loss_mask_[0] = 1; 390 media_loss_mask_[0] = 1;
352 media_loss_mask_[2] = 1; 391 media_loss_mask_[2] = 1;
353 media_loss_mask_[3] = 1; 392 media_loss_mask_[3] = 1;
354 NetworkReceivedPackets(); 393 NetworkReceivedPackets();
355 394
(...skipping 17 matching lines...) Expand all
373 &recovered_packet_list_)); 412 &recovered_packet_list_));
374 413
375 // Cannot get complete recovery for this loss configuration with random mask. 414 // Cannot get complete recovery for this loss configuration with random mask.
376 EXPECT_FALSE(IsRecoveryComplete()); 415 EXPECT_FALSE(IsRecoveryComplete());
377 } 416 }
378 417
379 // Test 50% protection with bursty type: Three cases are considered: 418 // Test 50% protection with bursty type: Three cases are considered:
380 // two 50% consecutive losses which can be fully recovered, and one 419 // two 50% consecutive losses which can be fully recovered, and one
381 // non-consecutive which cannot be fully recovered. 420 // non-consecutive which cannot be fully recovered.
382 TEST_F(RtpFecTest, FecRecoveryWithLoss50percBurstyMask) { 421 TEST_F(RtpFecTest, FecRecoveryWithLoss50percBurstyMask) {
383 const int kNumImportantPackets = 0; 422 constexpr int kNumImportantPackets = 0;
384 const bool kUseUnequalProtection = false; 423 constexpr bool kUseUnequalProtection = false;
385 const int kNumMediaPackets = 4; 424 constexpr int kNumMediaPackets = 4;
386 const uint8_t kProtectionFactor = 255; 425 constexpr uint8_t kProtectionFactor = 255;
387 426
388 // Packet Mask for (4,4,0) code, from bursty mask table. 427 // Packet Mask for (4,4,0) code, from bursty mask table.
389 // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 0) 428 // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 0)
390 429
391 // media#0 media#1 media#2 media#3 430 // media#0 media#1 media#2 media#3
392 // fec#0: 1 0 0 0 431 // fec#0: 1 0 0 0
393 // fec#1: 1 1 0 0 432 // fec#1: 1 1 0 0
394 // fec#2: 0 1 1 0 433 // fec#2: 0 1 1 0
395 // fec#3: 0 0 1 1 434 // fec#3: 0 0 1 1
396 // 435 //
397 436
398 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); 437 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets);
399 438
400 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor, 439 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor,
401 kNumImportantPackets, kUseUnequalProtection, 440 kNumImportantPackets, kUseUnequalProtection,
402 webrtc::kFecMaskBursty, &fec_packet_list_)); 441 webrtc::kFecMaskBursty, &fec_packet_list_));
403 442
404 // Expect 4 FEC packets. 443 // Expect 4 FEC packets.
405 EXPECT_EQ(4, static_cast<int>(fec_packet_list_.size())); 444 EXPECT_EQ(4u, fec_packet_list_.size());
406 445
407 // 4 consecutive packets lost: media packets 0,1,2,3. 446 // 4 consecutive packets lost: media packets 0,1,2,3.
408 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); 447 memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
409 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); 448 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
410 media_loss_mask_[0] = 1; 449 media_loss_mask_[0] = 1;
411 media_loss_mask_[1] = 1; 450 media_loss_mask_[1] = 1;
412 media_loss_mask_[2] = 1; 451 media_loss_mask_[2] = 1;
413 media_loss_mask_[3] = 1; 452 media_loss_mask_[3] = 1;
414 NetworkReceivedPackets(); 453 NetworkReceivedPackets();
415 454
(...skipping 30 matching lines...) Expand all
446 NetworkReceivedPackets(); 485 NetworkReceivedPackets();
447 486
448 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_, 487 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_,
449 &recovered_packet_list_)); 488 &recovered_packet_list_));
450 489
451 // Cannot get complete recovery for this loss configuration. 490 // Cannot get complete recovery for this loss configuration.
452 EXPECT_FALSE(IsRecoveryComplete()); 491 EXPECT_FALSE(IsRecoveryComplete());
453 } 492 }
454 493
455 TEST_F(RtpFecTest, FecRecoveryNoLossUep) { 494 TEST_F(RtpFecTest, FecRecoveryNoLossUep) {
456 const int kNumImportantPackets = 2; 495 constexpr int kNumImportantPackets = 2;
457 const bool kUseUnequalProtection = true; 496 constexpr bool kUseUnequalProtection = true;
458 const int kNumMediaPackets = 4; 497 constexpr int kNumMediaPackets = 4;
459 const uint8_t kProtectionFactor = 60; 498 constexpr uint8_t kProtectionFactor = 60;
460 499
461 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); 500 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets);
462 501
463 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor, 502 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor,
464 kNumImportantPackets, kUseUnequalProtection, 503 kNumImportantPackets, kUseUnequalProtection,
465 webrtc::kFecMaskBursty, &fec_packet_list_)); 504 webrtc::kFecMaskBursty, &fec_packet_list_));
466 505
467 // Expect 1 FEC packet. 506 // Expect 1 FEC packet.
468 EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size())); 507 EXPECT_EQ(1u, fec_packet_list_.size());
469 508
470 // No packets lost. 509 // No packets lost.
471 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); 510 memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
472 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); 511 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
473 NetworkReceivedPackets(); 512 NetworkReceivedPackets();
474 513
475 EXPECT_EQ(0, 514 EXPECT_EQ(0,
476 fec_->DecodeFec(&received_packet_list_, &recovered_packet_list_)); 515 fec_->DecodeFec(&received_packet_list_, &recovered_packet_list_));
477 516
478 // No packets lost, expect complete recovery. 517 // No packets lost, expect complete recovery.
479 EXPECT_TRUE(IsRecoveryComplete()); 518 EXPECT_TRUE(IsRecoveryComplete());
480 } 519 }
481 520
482 TEST_F(RtpFecTest, FecRecoveryWithLossUep) { 521 TEST_F(RtpFecTest, FecRecoveryWithLossUep) {
483 const int kNumImportantPackets = 2; 522 constexpr int kNumImportantPackets = 2;
484 const bool kUseUnequalProtection = true; 523 constexpr bool kUseUnequalProtection = true;
485 const int kNumMediaPackets = 4; 524 constexpr int kNumMediaPackets = 4;
486 const uint8_t kProtectionFactor = 60; 525 constexpr uint8_t kProtectionFactor = 60;
487 526
488 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); 527 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets);
489 528
490 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor, 529 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor,
491 kNumImportantPackets, kUseUnequalProtection, 530 kNumImportantPackets, kUseUnequalProtection,
492 webrtc::kFecMaskBursty, &fec_packet_list_)); 531 webrtc::kFecMaskBursty, &fec_packet_list_));
493 532
494 // Expect 1 FEC packet. 533 // Expect 1 FEC packet.
495 EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size())); 534 EXPECT_EQ(1u, fec_packet_list_.size());
496 535
497 // 1 media packet lost. 536 // 1 media packet lost.
498 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); 537 memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
499 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); 538 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
500 media_loss_mask_[3] = 1; 539 media_loss_mask_[3] = 1;
501 NetworkReceivedPackets(); 540 NetworkReceivedPackets();
502 541
503 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_, 542 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_,
504 &recovered_packet_list_)); 543 &recovered_packet_list_));
505 544
(...skipping 10 matching lines...) Expand all
516 555
517 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_, 556 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_,
518 &recovered_packet_list_)); 557 &recovered_packet_list_));
519 558
520 // 2 packets lost, one FEC packet, cannot get complete recovery. 559 // 2 packets lost, one FEC packet, cannot get complete recovery.
521 EXPECT_FALSE(IsRecoveryComplete()); 560 EXPECT_FALSE(IsRecoveryComplete());
522 } 561 }
523 562
524 // Test 50% protection with random mask type for UEP on. 563 // Test 50% protection with random mask type for UEP on.
525 TEST_F(RtpFecTest, FecRecoveryWithLoss50percUepRandomMask) { 564 TEST_F(RtpFecTest, FecRecoveryWithLoss50percUepRandomMask) {
526 const int kNumImportantPackets = 1; 565 constexpr int kNumImportantPackets = 1;
527 const bool kUseUnequalProtection = true; 566 constexpr bool kUseUnequalProtection = true;
528 const int kNumMediaPackets = 4; 567 constexpr int kNumMediaPackets = 4;
529 const uint8_t kProtectionFactor = 255; 568 constexpr uint8_t kProtectionFactor = 255;
530 569
531 // Packet Mask for (4,4,1) code, from random mask table. 570 // Packet Mask for (4,4,1) code, from random mask table.
532 // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 1) 571 // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 1)
533 572
534 // media#0 media#1 media#2 media#3 573 // media#0 media#1 media#2 media#3
535 // fec#0: 1 0 0 0 574 // fec#0: 1 0 0 0
536 // fec#1: 1 1 0 0 575 // fec#1: 1 1 0 0
537 // fec#2: 1 0 1 1 576 // fec#2: 1 0 1 1
538 // fec#3: 0 1 1 0 577 // fec#3: 0 1 1 0
539 // 578 //
540 579
541 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); 580 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets);
542 581
543 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor, 582 EXPECT_EQ(0, fec_->GenerateFec(media_packet_list_, kProtectionFactor,
544 kNumImportantPackets, kUseUnequalProtection, 583 kNumImportantPackets, kUseUnequalProtection,
545 webrtc::kFecMaskRandom, &fec_packet_list_)); 584 webrtc::kFecMaskRandom, &fec_packet_list_));
546 585
547 // Expect 4 FEC packets. 586 // Expect 4 FEC packets.
548 EXPECT_EQ(4, static_cast<int>(fec_packet_list_.size())); 587 EXPECT_EQ(4u, fec_packet_list_.size());
549 588
550 // 4 packets lost: 3 media packets and FEC packet#1 lost. 589 // 4 packets lost: 3 media packets and FEC packet#1 lost.
551 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); 590 memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
552 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); 591 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
553 fec_loss_mask_[1] = 1; 592 fec_loss_mask_[1] = 1;
554 media_loss_mask_[0] = 1; 593 media_loss_mask_[0] = 1;
555 media_loss_mask_[2] = 1; 594 media_loss_mask_[2] = 1;
556 media_loss_mask_[3] = 1; 595 media_loss_mask_[3] = 1;
557 NetworkReceivedPackets(); 596 NetworkReceivedPackets();
558 597
(...skipping 15 matching lines...) Expand all
574 NetworkReceivedPackets(); 613 NetworkReceivedPackets();
575 614
576 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_, 615 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_,
577 &recovered_packet_list_)); 616 &recovered_packet_list_));
578 617
579 // Cannot get complete recovery for this loss configuration. 618 // Cannot get complete recovery for this loss configuration.
580 EXPECT_FALSE(IsRecoveryComplete()); 619 EXPECT_FALSE(IsRecoveryComplete());
581 } 620 }
582 621
583 TEST_F(RtpFecTest, FecRecoveryNonConsecutivePackets) { 622 TEST_F(RtpFecTest, FecRecoveryNonConsecutivePackets) {
584 const int kNumImportantPackets = 0; 623 constexpr int kNumImportantPackets = 0;
585 const bool kUseUnequalProtection = false; 624 constexpr bool kUseUnequalProtection = false;
586 const int kNumMediaPackets = 5; 625 constexpr int kNumMediaPackets = 5;
587 uint8_t kProtectionFactor = 60; 626 constexpr uint8_t kProtectionFactor = 60;
588 627
589 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); 628 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets);
590 629
591 // Create a new temporary packet list for generating FEC packets. 630 // Create a new temporary packet list for generating FEC packets.
592 // This list should have every other packet removed. 631 // This list should have every other packet removed.
593 PacketList protected_media_packets; 632 PacketList protected_media_packets;
594 DeepCopyEveryNthPacket(media_packet_list_, &protected_media_packets, 2); 633 DeepCopyEveryNthPacket(media_packet_list_, &protected_media_packets, 2);
595 634
596 EXPECT_EQ(0, fec_->GenerateFec(protected_media_packets, kProtectionFactor, 635 EXPECT_EQ(0, fec_->GenerateFec(protected_media_packets, kProtectionFactor,
597 kNumImportantPackets, kUseUnequalProtection, 636 kNumImportantPackets, kUseUnequalProtection,
598 webrtc::kFecMaskBursty, &fec_packet_list_)); 637 webrtc::kFecMaskBursty, &fec_packet_list_));
599 638
600 // Expect 1 FEC packet. 639 // Expect 1 FEC packet.
601 EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size())); 640 EXPECT_EQ(1u, fec_packet_list_.size());
602 641
603 // 1 protected media packet lost 642 // 1 protected media packet lost
604 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); 643 memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
605 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); 644 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
606 media_loss_mask_[2] = 1; 645 media_loss_mask_[2] = 1;
607 NetworkReceivedPackets(); 646 NetworkReceivedPackets();
608 647
609 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_, 648 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_,
610 &recovered_packet_list_)); 649 &recovered_packet_list_));
611 650
(...skipping 22 matching lines...) Expand all
634 NetworkReceivedPackets(); 673 NetworkReceivedPackets();
635 674
636 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_, 675 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_,
637 &recovered_packet_list_)); 676 &recovered_packet_list_));
638 677
639 // 2 protected packets lost, one FEC packet, cannot get complete recovery. 678 // 2 protected packets lost, one FEC packet, cannot get complete recovery.
640 EXPECT_FALSE(IsRecoveryComplete()); 679 EXPECT_FALSE(IsRecoveryComplete());
641 } 680 }
642 681
643 TEST_F(RtpFecTest, FecRecoveryNonConsecutivePacketsExtension) { 682 TEST_F(RtpFecTest, FecRecoveryNonConsecutivePacketsExtension) {
644 const int kNumImportantPackets = 0; 683 constexpr int kNumImportantPackets = 0;
645 const bool kUseUnequalProtection = false; 684 constexpr bool kUseUnequalProtection = false;
646 const int kNumMediaPackets = 21; 685 constexpr int kNumMediaPackets = 21;
647 uint8_t kProtectionFactor = 127; 686 uint8_t kProtectionFactor = 127;
648 687
649 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); 688 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets);
650 689
651 // Create a new temporary packet list for generating FEC packets. 690 // Create a new temporary packet list for generating FEC packets.
652 // This list should have every other packet removed. 691 // This list should have every other packet removed.
653 PacketList protected_media_packets; 692 PacketList protected_media_packets;
654 DeepCopyEveryNthPacket(media_packet_list_, &protected_media_packets, 2); 693 DeepCopyEveryNthPacket(media_packet_list_, &protected_media_packets, 2);
655 694
656 // Zero column insertion will have to extend the size of the packet 695 // Zero column insertion will have to extend the size of the packet
657 // mask since the number of actual packets are 21, while the number 696 // mask since the number of actual packets are 21, while the number
658 // of protected packets are 11. 697 // of protected packets are 11.
659 EXPECT_EQ(0, fec_->GenerateFec(protected_media_packets, kProtectionFactor, 698 EXPECT_EQ(0, fec_->GenerateFec(protected_media_packets, kProtectionFactor,
660 kNumImportantPackets, kUseUnequalProtection, 699 kNumImportantPackets, kUseUnequalProtection,
661 webrtc::kFecMaskBursty, &fec_packet_list_)); 700 webrtc::kFecMaskBursty, &fec_packet_list_));
662 701
663 // Expect 5 FEC packet. 702 // Expect 5 FEC packet.
664 EXPECT_EQ(5, static_cast<int>(fec_packet_list_.size())); 703 EXPECT_EQ(5u, fec_packet_list_.size());
665 704
666 // Last protected media packet lost 705 // Last protected media packet lost
667 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); 706 memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
668 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); 707 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
669 media_loss_mask_[kNumMediaPackets - 1] = 1; 708 media_loss_mask_[kNumMediaPackets - 1] = 1;
670 NetworkReceivedPackets(); 709 NetworkReceivedPackets();
671 710
672 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_, 711 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_,
673 &recovered_packet_list_)); 712 &recovered_packet_list_));
674 713
(...skipping 26 matching lines...) Expand all
701 NetworkReceivedPackets(); 740 NetworkReceivedPackets();
702 741
703 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_, 742 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_,
704 &recovered_packet_list_)); 743 &recovered_packet_list_));
705 744
706 // 5 protected packets lost, one FEC packet, cannot get complete recovery. 745 // 5 protected packets lost, one FEC packet, cannot get complete recovery.
707 EXPECT_FALSE(IsRecoveryComplete()); 746 EXPECT_FALSE(IsRecoveryComplete());
708 } 747 }
709 748
710 TEST_F(RtpFecTest, FecRecoveryNonConsecutivePacketsWrap) { 749 TEST_F(RtpFecTest, FecRecoveryNonConsecutivePacketsWrap) {
711 const int kNumImportantPackets = 0; 750 constexpr int kNumImportantPackets = 0;
712 const bool kUseUnequalProtection = false; 751 constexpr bool kUseUnequalProtection = false;
713 const int kNumMediaPackets = 21; 752 constexpr int kNumMediaPackets = 21;
714 uint8_t kProtectionFactor = 127; 753 uint8_t kProtectionFactor = 127;
715 754
716 fec_seq_num_ = ConstructMediaPacketsSeqNum(kNumMediaPackets, 0xFFFF - 5); 755 fec_seq_num_ = ConstructMediaPacketsSeqNum(kNumMediaPackets, 0xFFFF - 5);
717 756
718 // Create a new temporary packet list for generating FEC packets. 757 // Create a new temporary packet list for generating FEC packets.
719 // This list should have every other packet removed. 758 // This list should have every other packet removed.
720 PacketList protected_media_packets; 759 PacketList protected_media_packets;
721 DeepCopyEveryNthPacket(media_packet_list_, &protected_media_packets, 2); 760 DeepCopyEveryNthPacket(media_packet_list_, &protected_media_packets, 2);
722 761
723 // Zero column insertion will have to extend the size of the packet 762 // Zero column insertion will have to extend the size of the packet
724 // mask since the number of actual packets are 21, while the number 763 // mask since the number of actual packets are 21, while the number
725 // of protected packets are 11. 764 // of protected packets are 11.
726 EXPECT_EQ(0, fec_->GenerateFec(protected_media_packets, kProtectionFactor, 765 EXPECT_EQ(0, fec_->GenerateFec(protected_media_packets, kProtectionFactor,
727 kNumImportantPackets, kUseUnequalProtection, 766 kNumImportantPackets, kUseUnequalProtection,
728 webrtc::kFecMaskBursty, &fec_packet_list_)); 767 webrtc::kFecMaskBursty, &fec_packet_list_));
729 768
730 // Expect 5 FEC packet. 769 // Expect 5 FEC packet.
731 EXPECT_EQ(5, static_cast<int>(fec_packet_list_.size())); 770 EXPECT_EQ(5u, fec_packet_list_.size());
732 771
733 // Last protected media packet lost 772 // Last protected media packet lost
734 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); 773 memset(media_loss_mask_, 0, sizeof(media_loss_mask_));
735 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); 774 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_));
736 media_loss_mask_[kNumMediaPackets - 1] = 1; 775 media_loss_mask_[kNumMediaPackets - 1] = 1;
737 NetworkReceivedPackets(); 776 NetworkReceivedPackets();
738 777
739 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_, 778 EXPECT_EQ(0, fec_->DecodeFec(&received_packet_list_,
740 &recovered_packet_list_)); 779 &recovered_packet_list_));
741 780
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 media_packet->length) != 0) { 842 media_packet->length) != 0) {
804 return false; 843 return false;
805 } 844 }
806 return true; 845 return true;
807 }; 846 };
808 return std::equal(media_packet_list_.cbegin(), media_packet_list_.cend(), 847 return std::equal(media_packet_list_.cbegin(), media_packet_list_.cend(),
809 recovered_packet_list_.cbegin(), cmp); 848 recovered_packet_list_.cbegin(), cmp);
810 } 849 }
811 850
812 void RtpFecTest::NetworkReceivedPackets() { 851 void RtpFecTest::NetworkReceivedPackets() {
813 const bool kFecPacket = true; 852 constexpr bool kFecPacket = true;
814 ReceivedPackets(media_packet_list_, media_loss_mask_, !kFecPacket); 853 ReceivedPackets(media_packet_list_, media_loss_mask_, !kFecPacket);
815 ReceivedPackets(fec_packet_list_, fec_loss_mask_, kFecPacket); 854 ReceivedPackets(fec_packet_list_, fec_loss_mask_, kFecPacket);
816 } 855 }
817 856
818 template <typename T> 857 template <typename T>
819 void RtpFecTest::ReceivedPackets(const T& packet_list, int* loss_mask, 858 void RtpFecTest::ReceivedPackets(const T& packet_list, int* loss_mask,
820 bool is_fec) { 859 bool is_fec) {
821 int seq_num = fec_seq_num_; 860 int seq_num = fec_seq_num_;
822 int packet_idx = 0; 861 int packet_idx = 0;
823 862
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 894
856 int RtpFecTest::ConstructMediaPacketsSeqNum(int num_media_packets, 895 int RtpFecTest::ConstructMediaPacketsSeqNum(int num_media_packets,
857 int start_seq_num) { 896 int start_seq_num) {
858 RTC_DCHECK_GT(num_media_packets, 0); 897 RTC_DCHECK_GT(num_media_packets, 0);
859 int sequence_number = start_seq_num; 898 int sequence_number = start_seq_num;
860 int time_stamp = random_.Rand<int>(); 899 int time_stamp = random_.Rand<int>();
861 900
862 for (int i = 0; i < num_media_packets; ++i) { 901 for (int i = 0; i < num_media_packets; ++i) {
863 std::unique_ptr<ForwardErrorCorrection::Packet> media_packet( 902 std::unique_ptr<ForwardErrorCorrection::Packet> media_packet(
864 new ForwardErrorCorrection::Packet()); 903 new ForwardErrorCorrection::Packet());
865 const uint32_t kMinPacketSize = kRtpHeaderSize; 904 constexpr uint32_t kMinPacketSize = kRtpHeaderSize;
866 const uint32_t kMaxPacketSize = IP_PACKET_SIZE - kRtpHeaderSize - 905 const uint32_t kMaxPacketSize = IP_PACKET_SIZE - kRtpHeaderSize -
867 kTransportOverhead - 906 kTransportOverhead -
868 ForwardErrorCorrection::PacketOverhead(); 907 ForwardErrorCorrection::PacketOverhead();
869 media_packet->length = random_.Rand(kMinPacketSize, kMaxPacketSize); 908 media_packet->length = random_.Rand(kMinPacketSize, kMaxPacketSize);
870 909
871 // Generate random values for the first 2 bytes 910 // Generate random values for the first 2 bytes
872 media_packet->data[0] = random_.Rand<uint8_t>(); 911 media_packet->data[0] = random_.Rand<uint8_t>();
873 media_packet->data[1] = random_.Rand<uint8_t>(); 912 media_packet->data[1] = random_.Rand<uint8_t>();
874 913
875 // The first two bits are assumed to be 10 by the FEC encoder. 914 // The first two bits are assumed to be 10 by the FEC encoder.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 PacketList* dst, int N) { 953 PacketList* dst, int N) {
915 RTC_DCHECK_GT(N, 0); 954 RTC_DCHECK_GT(N, 0);
916 int i = 0; 955 int i = 0;
917 for (auto& packet : src) { 956 for (auto& packet : src) {
918 if (i % N == 0) { 957 if (i % N == 0) {
919 dst->emplace_back(new ForwardErrorCorrection::Packet(*packet)); 958 dst->emplace_back(new ForwardErrorCorrection::Packet(*packet));
920 } 959 }
921 ++i; 960 ++i;
922 } 961 }
923 } 962 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698