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

Side by Side Diff: webrtc/modules/rtp_rtcp/test/testFec/test_fec.cc

Issue 2260803002: Generalize FEC header formatting. (pt. 4) (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Lint fix. Created 4 years, 3 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
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 const int kNumFecMaskTypes = sizeof(kMaskTypes) / sizeof(*kMaskTypes); 100 const int kNumFecMaskTypes = sizeof(kMaskTypes) / sizeof(*kMaskTypes);
101 101
102 // Maximum number of media packets allowed for the mask type. 102 // Maximum number of media packets allowed for the mask type.
103 const uint16_t kMaxMediaPackets[] = { 103 const uint16_t kMaxMediaPackets[] = {
104 kMaxNumberMediaPackets, 104 kMaxNumberMediaPackets,
105 sizeof(kPacketMaskBurstyTbl) / sizeof(*kPacketMaskBurstyTbl)}; 105 sizeof(kPacketMaskBurstyTbl) / sizeof(*kPacketMaskBurstyTbl)};
106 106
107 ASSERT_EQ(12, kMaxMediaPackets[1]) << "Max media packets for bursty mode not " 107 ASSERT_EQ(12, kMaxMediaPackets[1]) << "Max media packets for bursty mode not "
108 << "equal to 12."; 108 << "equal to 12.";
109 109
110 ForwardErrorCorrection fec; 110 std::unique_ptr<ForwardErrorCorrection> fec =
111 ForwardErrorCorrection::CreateUlpfec();
111 ForwardErrorCorrection::PacketList media_packet_list; 112 ForwardErrorCorrection::PacketList media_packet_list;
112 std::list<ForwardErrorCorrection::Packet*> fec_packet_list; 113 std::list<ForwardErrorCorrection::Packet*> fec_packet_list;
113 ForwardErrorCorrection::ReceivedPacketList to_decode_list; 114 ForwardErrorCorrection::ReceivedPacketList to_decode_list;
114 ForwardErrorCorrection::ReceivedPacketList received_packet_list; 115 ForwardErrorCorrection::ReceivedPacketList received_packet_list;
115 ForwardErrorCorrection::RecoveredPacketList recovered_packet_list; 116 ForwardErrorCorrection::RecoveredPacketList recovered_packet_list;
116 std::list<uint8_t*> fec_mask_list; 117 std::list<uint8_t*> fec_mask_list;
117 118
118 // Running over only one loss rate to limit execution time. 119 // Running over only one loss rate to limit execution time.
119 const float loss_rate[] = {0.5f}; 120 const float loss_rate[] = {0.5f};
120 const uint32_t loss_rate_size = sizeof(loss_rate) / sizeof(*loss_rate); 121 const uint32_t loss_rate_size = sizeof(loss_rate) / sizeof(*loss_rate);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // Reset the sequence number here for each FEC code/mask tested 232 // Reset the sequence number here for each FEC code/mask tested
232 // below, to avoid sequence number wrap-around. In actual decoding, 233 // below, to avoid sequence number wrap-around. In actual decoding,
233 // old FEC packets in list are dropped if sequence number wrap 234 // old FEC packets in list are dropped if sequence number wrap
234 // around is detected. This case is currently not handled below. 235 // around is detected. This case is currently not handled below.
235 seq_num = 0; 236 seq_num = 0;
236 for (uint32_t i = 0; i < num_media_packets; ++i) { 237 for (uint32_t i = 0; i < num_media_packets; ++i) {
237 std::unique_ptr<ForwardErrorCorrection::Packet> media_packet( 238 std::unique_ptr<ForwardErrorCorrection::Packet> media_packet(
238 new ForwardErrorCorrection::Packet()); 239 new ForwardErrorCorrection::Packet());
239 const uint32_t kMinPacketSize = 12; 240 const uint32_t kMinPacketSize = 12;
240 const uint32_t kMaxPacketSize = static_cast<uint32_t>( 241 const uint32_t kMaxPacketSize = static_cast<uint32_t>(
241 IP_PACKET_SIZE - 12 - 28 - fec.MaxPacketOverhead()); 242 IP_PACKET_SIZE - 12 - 28 - fec->MaxPacketOverhead());
242 media_packet->length = random.Rand(kMinPacketSize, 243 media_packet->length = random.Rand(kMinPacketSize,
243 kMaxPacketSize); 244 kMaxPacketSize);
244 245
245 // Generate random values for the first 2 bytes. 246 // Generate random values for the first 2 bytes.
246 media_packet->data[0] = random.Rand<uint8_t>(); 247 media_packet->data[0] = random.Rand<uint8_t>();
247 media_packet->data[1] = random.Rand<uint8_t>(); 248 media_packet->data[1] = random.Rand<uint8_t>();
248 249
249 // The first two bits are assumed to be 10 by the 250 // The first two bits are assumed to be 10 by the
250 // FEC encoder. In fact the FEC decoder will set the 251 // FEC encoder. In fact the FEC decoder will set the
251 // two first bits to 10 regardless of what they 252 // two first bits to 10 regardless of what they
(...skipping 18 matching lines...) Expand all
270 ssrc); 271 ssrc);
271 // Generate random values for payload 272 // Generate random values for payload
272 for (size_t j = 12; j < media_packet->length; ++j) { 273 for (size_t j = 12; j < media_packet->length; ++j) {
273 media_packet->data[j] = random.Rand<uint8_t>(); 274 media_packet->data[j] = random.Rand<uint8_t>();
274 } 275 }
275 media_packet_list.push_back(std::move(media_packet)); 276 media_packet_list.push_back(std::move(media_packet));
276 seq_num++; 277 seq_num++;
277 } 278 }
278 media_packet_list.back()->data[1] |= 0x80; 279 media_packet_list.back()->data[1] |= 0x80;
279 280
280 ASSERT_EQ(0, fec.EncodeFec(media_packet_list, protection_factor, 281 ASSERT_EQ(0, fec->EncodeFec(media_packet_list, protection_factor,
281 num_imp_packets, kUseUnequalProtection, 282 num_imp_packets, kUseUnequalProtection,
282 fec_mask_type, &fec_packet_list)) 283 fec_mask_type, &fec_packet_list))
283 << "EncodeFec() failed"; 284 << "EncodeFec() failed";
284 285
285 ASSERT_EQ(num_fec_packets, fec_packet_list.size()) 286 ASSERT_EQ(num_fec_packets, fec_packet_list.size())
286 << "We requested " << num_fec_packets << " FEC packets, but " 287 << "We requested " << num_fec_packets << " FEC packets, but "
287 << "EncodeFec() produced " << fec_packet_list.size(); 288 << "EncodeFec() produced " << fec_packet_list.size();
288 289
289 memset(media_loss_mask, 0, sizeof(media_loss_mask)); 290 memset(media_loss_mask, 0, sizeof(media_loss_mask));
290 uint32_t media_packet_idx = 0; 291 uint32_t media_packet_idx = 0;
291 for (const auto& media_packet : media_packet_list) { 292 for (const auto& media_packet : media_packet_list) {
292 // We want a value between 0 and 1. 293 // We want a value between 0 and 1.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 duplicate_rate, &random); 387 duplicate_rate, &random);
387 388
388 if (fec_packet_received == false) { 389 if (fec_packet_received == false) {
389 for (const auto& received_packet : to_decode_list) { 390 for (const auto& received_packet : to_decode_list) {
390 if (received_packet->is_fec) { 391 if (received_packet->is_fec) {
391 fec_packet_received = true; 392 fec_packet_received = true;
392 } 393 }
393 } 394 }
394 } 395 }
395 ASSERT_EQ(0, 396 ASSERT_EQ(0,
396 fec.DecodeFec(&to_decode_list, &recovered_packet_list)) 397 fec->DecodeFec(&to_decode_list, &recovered_packet_list))
397 << "DecodeFec() failed"; 398 << "DecodeFec() failed";
398 ASSERT_TRUE(to_decode_list.empty()) 399 ASSERT_TRUE(to_decode_list.empty())
399 << "Received packet list is not empty."; 400 << "Received packet list is not empty.";
400 } 401 }
401 media_packet_idx = 0; 402 media_packet_idx = 0;
402 for (const auto& media_packet : media_packet_list) { 403 for (const auto& media_packet : media_packet_list) {
403 if (media_loss_mask[media_packet_idx] == 1) { 404 if (media_loss_mask[media_packet_idx] == 1) {
404 // Should have recovered this packet. 405 // Should have recovered this packet.
405 auto recovered_packet_list_it = recovered_packet_list.cbegin(); 406 auto recovered_packet_list_it = recovered_packet_list.cbegin();
406 407
407 ASSERT_FALSE(recovered_packet_list_it == 408 ASSERT_FALSE(recovered_packet_list_it ==
408 recovered_packet_list.end()) 409 recovered_packet_list.end())
409 << "Insufficient number of recovered packets."; 410 << "Insufficient number of recovered packets.";
410 ForwardErrorCorrection::RecoveredPacket* recovered_packet = 411 ForwardErrorCorrection::RecoveredPacket* recovered_packet =
411 recovered_packet_list_it->get(); 412 recovered_packet_list_it->get();
412 413
413 ASSERT_EQ(recovered_packet->pkt->length, media_packet->length) 414 ASSERT_EQ(recovered_packet->pkt->length, media_packet->length)
414 << "Recovered packet length not identical to original " 415 << "Recovered packet length not identical to original "
415 << "media packet"; 416 << "media packet";
416 ASSERT_EQ(0, memcmp(recovered_packet->pkt->data, 417 ASSERT_EQ(0, memcmp(recovered_packet->pkt->data,
417 media_packet->data, media_packet->length)) 418 media_packet->data, media_packet->length))
418 << "Recovered packet payload not identical to original " 419 << "Recovered packet payload not identical to original "
419 << "media packet"; 420 << "media packet";
420 recovered_packet_list.pop_front(); 421 recovered_packet_list.pop_front();
421 } 422 }
422 ++media_packet_idx; 423 ++media_packet_idx;
423 } 424 }
424 fec.ResetState(&recovered_packet_list); 425 fec->ResetState(&recovered_packet_list);
425 ASSERT_TRUE(recovered_packet_list.empty()) 426 ASSERT_TRUE(recovered_packet_list.empty())
426 << "Excessive number of recovered packets.\t size is: " 427 << "Excessive number of recovered packets.\t size is: "
427 << recovered_packet_list.size(); 428 << recovered_packet_list.size();
428 // -- Teardown -- 429 // -- Teardown --
429 media_packet_list.clear(); 430 media_packet_list.clear();
430 431
431 // Clear FEC packet list, so we don't pass in a non-empty 432 // Clear FEC packet list, so we don't pass in a non-empty
432 // list in the next call to DecodeFec(). 433 // list in the next call to DecodeFec().
433 fec_packet_list.clear(); 434 fec_packet_list.clear();
434 435
435 // Delete received packets we didn't pass to DecodeFec(), due to 436 // Delete received packets we didn't pass to DecodeFec(), due to
436 // early frame completion. 437 // early frame completion.
437 received_packet_list.clear(); 438 received_packet_list.clear();
438 439
439 while (!fec_mask_list.empty()) { 440 while (!fec_mask_list.empty()) {
440 fec_mask_list.pop_front(); 441 fec_mask_list.pop_front();
441 } 442 }
442 timestamp += 90000 / 30; 443 timestamp += 90000 / 30;
443 } // loop over num_imp_packets 444 } // loop over num_imp_packets
444 } // loop over FecPackets 445 } // loop over FecPackets
445 } // loop over num_media_packets 446 } // loop over num_media_packets
446 } // loop over loss rates 447 } // loop over loss rates
447 } // loop over mask types 448 } // loop over mask types
448 449
449 // Have DecodeFec clear the recovered packet list. 450 // Have DecodeFec clear the recovered packet list.
450 fec.ResetState(&recovered_packet_list); 451 fec->ResetState(&recovered_packet_list);
451 ASSERT_TRUE(recovered_packet_list.empty()) 452 ASSERT_TRUE(recovered_packet_list.empty())
452 << "Recovered packet list is not empty"; 453 << "Recovered packet list is not empty";
453 } 454 }
454 455
455 } // namespace test 456 } // namespace test
456 } // namespace webrtc 457 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698