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

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: Created 4 years, 4 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 ForwardErrorCorrection fec = ForwardErrorCorrection::CreateUlpfec();
111 ForwardErrorCorrection::PacketList media_packet_list; 111 ForwardErrorCorrection::PacketList media_packet_list;
112 std::list<ForwardErrorCorrection::Packet*> fec_packet_list; 112 std::list<ForwardErrorCorrection::Packet*> fec_packet_list;
113 ForwardErrorCorrection::ReceivedPacketList to_decode_list; 113 ForwardErrorCorrection::ReceivedPacketList to_decode_list;
114 ForwardErrorCorrection::ReceivedPacketList received_packet_list; 114 ForwardErrorCorrection::ReceivedPacketList received_packet_list;
115 ForwardErrorCorrection::RecoveredPacketList recovered_packet_list; 115 ForwardErrorCorrection::RecoveredPacketList recovered_packet_list;
116 std::list<uint8_t*> fec_mask_list; 116 std::list<uint8_t*> fec_mask_list;
117 117
118 // Running over only one loss rate to limit execution time. 118 // Running over only one loss rate to limit execution time.
119 const float loss_rate[] = {0.5f}; 119 const float loss_rate[] = {0.5f};
120 const uint32_t loss_rate_size = sizeof(loss_rate) / sizeof(*loss_rate); 120 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 231 // Reset the sequence number here for each FEC code/mask tested
232 // below, to avoid sequence number wrap-around. In actual decoding, 232 // below, to avoid sequence number wrap-around. In actual decoding,
233 // old FEC packets in list are dropped if sequence number wrap 233 // old FEC packets in list are dropped if sequence number wrap
234 // around is detected. This case is currently not handled below. 234 // around is detected. This case is currently not handled below.
235 seq_num = 0; 235 seq_num = 0;
236 for (uint32_t i = 0; i < num_media_packets; ++i) { 236 for (uint32_t i = 0; i < num_media_packets; ++i) {
237 std::unique_ptr<ForwardErrorCorrection::Packet> media_packet( 237 std::unique_ptr<ForwardErrorCorrection::Packet> media_packet(
238 new ForwardErrorCorrection::Packet()); 238 new ForwardErrorCorrection::Packet());
239 const uint32_t kMinPacketSize = 12; 239 const uint32_t kMinPacketSize = 12;
240 const uint32_t kMaxPacketSize = static_cast<uint32_t>( 240 const uint32_t kMaxPacketSize = static_cast<uint32_t>(
241 IP_PACKET_SIZE - 12 - 28 - 241 IP_PACKET_SIZE - 12 - 28 - fec.MaxPacketOverhead());
242 ForwardErrorCorrection::PacketOverhead());
243 media_packet->length = random.Rand(kMinPacketSize, 242 media_packet->length = random.Rand(kMinPacketSize,
244 kMaxPacketSize); 243 kMaxPacketSize);
245 244
246 // Generate random values for the first 2 bytes. 245 // Generate random values for the first 2 bytes.
247 media_packet->data[0] = random.Rand<uint8_t>(); 246 media_packet->data[0] = random.Rand<uint8_t>();
248 media_packet->data[1] = random.Rand<uint8_t>(); 247 media_packet->data[1] = random.Rand<uint8_t>();
249 248
250 // The first two bits are assumed to be 10 by the 249 // The first two bits are assumed to be 10 by the
251 // FEC encoder. In fact the FEC decoder will set the 250 // FEC encoder. In fact the FEC decoder will set the
252 // two first bits to 10 regardless of what they 251 // two first bits to 10 regardless of what they
(...skipping 18 matching lines...) Expand all
271 ssrc); 270 ssrc);
272 // Generate random values for payload 271 // Generate random values for payload
273 for (size_t j = 12; j < media_packet->length; ++j) { 272 for (size_t j = 12; j < media_packet->length; ++j) {
274 media_packet->data[j] = random.Rand<uint8_t>(); 273 media_packet->data[j] = random.Rand<uint8_t>();
275 } 274 }
276 media_packet_list.push_back(std::move(media_packet)); 275 media_packet_list.push_back(std::move(media_packet));
277 seq_num++; 276 seq_num++;
278 } 277 }
279 media_packet_list.back()->data[1] |= 0x80; 278 media_packet_list.back()->data[1] |= 0x80;
280 279
281 ASSERT_EQ(0, fec.GenerateFec(media_packet_list, protection_factor, 280 ASSERT_EQ(0, fec.EncodeFec(media_packet_list, protection_factor,
282 num_imp_packets, kUseUnequalProtection, 281 num_imp_packets, kUseUnequalProtection,
283 fec_mask_type, &fec_packet_list)) 282 fec_mask_type, &fec_packet_list))
284 << "GenerateFec() failed"; 283 << "EncodeFec() failed";
285 284
286 ASSERT_EQ(num_fec_packets, fec_packet_list.size()) 285 ASSERT_EQ(num_fec_packets, fec_packet_list.size())
287 << "We requested " << num_fec_packets << " FEC packets, but " 286 << "We requested " << num_fec_packets << " FEC packets, but "
288 << "GenerateFec() produced " << fec_packet_list.size(); 287 << "EncodeFec() produced " << fec_packet_list.size();
289 288
290 memset(media_loss_mask, 0, sizeof(media_loss_mask)); 289 memset(media_loss_mask, 0, sizeof(media_loss_mask));
291 uint32_t media_packet_idx = 0; 290 uint32_t media_packet_idx = 0;
292 for (const auto& media_packet : media_packet_list) { 291 for (const auto& media_packet : media_packet_list) {
293 // We want a value between 0 and 1. 292 // We want a value between 0 and 1.
294 const float loss_random_variable = random.Rand<float>(); 293 const float loss_random_variable = random.Rand<float>();
295 294
296 if (loss_random_variable >= loss_rate[loss_rate_idx]) { 295 if (loss_random_variable >= loss_rate[loss_rate_idx]) {
297 media_loss_mask[media_packet_idx] = 1; 296 media_loss_mask[media_packet_idx] = 1;
298 std::unique_ptr<ForwardErrorCorrection::ReceivedPacket> 297 std::unique_ptr<ForwardErrorCorrection::ReceivedPacket>
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 num_packets_to_decode, reorder_rate, 385 num_packets_to_decode, reorder_rate,
387 duplicate_rate, &random); 386 duplicate_rate, &random);
388 387
389 if (fec_packet_received == false) { 388 if (fec_packet_received == false) {
390 for (const auto& received_packet : to_decode_list) { 389 for (const auto& received_packet : to_decode_list) {
391 if (received_packet->is_fec) { 390 if (received_packet->is_fec) {
392 fec_packet_received = true; 391 fec_packet_received = true;
393 } 392 }
394 } 393 }
395 } 394 }
396 ASSERT_EQ(0, fec.DecodeFec(&to_decode_list, 395 ASSERT_EQ(0,
397 &recovered_packet_list)) 396 fec.DecodeFec(&to_decode_list, &recovered_packet_list))
398 << "DecodeFec() failed"; 397 << "DecodeFec() failed";
399 ASSERT_TRUE(to_decode_list.empty()) 398 ASSERT_TRUE(to_decode_list.empty())
400 << "Received packet list is not empty."; 399 << "Received packet list is not empty.";
401 } 400 }
402 media_packet_idx = 0; 401 media_packet_idx = 0;
403 for (const auto& media_packet : media_packet_list) { 402 for (const auto& media_packet : media_packet_list) {
404 if (media_loss_mask[media_packet_idx] == 1) { 403 if (media_loss_mask[media_packet_idx] == 1) {
405 // Should have recovered this packet. 404 // Should have recovered this packet.
406 auto recovered_packet_list_it = recovered_packet_list.cbegin(); 405 auto recovered_packet_list_it = recovered_packet_list.cbegin();
407 406
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 } // loop over mask types 447 } // loop over mask types
449 448
450 // Have DecodeFec clear the recovered packet list. 449 // Have DecodeFec clear the recovered packet list.
451 fec.ResetState(&recovered_packet_list); 450 fec.ResetState(&recovered_packet_list);
452 ASSERT_TRUE(recovered_packet_list.empty()) 451 ASSERT_TRUE(recovered_packet_list.empty())
453 << "Recovered packet list is not empty"; 452 << "Recovered packet list is not empty";
454 } 453 }
455 454
456 } // namespace test 455 } // namespace test
457 } // namespace webrtc 456 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698