OLD | NEW |
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 memcpy(duplicate_packet->pkt->data, received_packet->pkt->data, | 71 memcpy(duplicate_packet->pkt->data, received_packet->pkt->data, |
72 received_packet->pkt->length); | 72 received_packet->pkt->length); |
73 duplicate_packet->pkt->length = received_packet->pkt->length; | 73 duplicate_packet->pkt->length = received_packet->pkt->length; |
74 | 74 |
75 to_decode_list->push_back(std::move(duplicate_packet)); | 75 to_decode_list->push_back(std::move(duplicate_packet)); |
76 random_variable = random->Rand<float>(); | 76 random_variable = random->Rand<float>(); |
77 } | 77 } |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 // Too slow to finish before timeout on iOS. See webrtc:4755. | 81 void RunTest(bool use_flexfec) { |
82 #if defined(WEBRTC_IOS) | |
83 #define MAYBE_FecTest DISABLED_FecTest | |
84 #else | |
85 #define MAYBE_FecTest FecTest | |
86 #endif | |
87 TEST(FecTest, MAYBE_FecTest) { | |
88 // TODO(marpan): Split this function into subroutines/helper functions. | 82 // TODO(marpan): Split this function into subroutines/helper functions. |
89 enum { kMaxNumberMediaPackets = 48 }; | 83 enum { kMaxNumberMediaPackets = 48 }; |
90 enum { kMaxNumberFecPackets = 48 }; | 84 enum { kMaxNumberFecPackets = 48 }; |
91 | 85 |
92 const uint32_t kNumMaskBytesL0 = 2; | 86 const uint32_t kNumMaskBytesL0 = 2; |
93 const uint32_t kNumMaskBytesL1 = 6; | 87 const uint32_t kNumMaskBytesL1 = 6; |
94 | 88 |
95 // FOR UEP | 89 // FOR UEP |
96 const bool kUseUnequalProtection = true; | 90 const bool kUseUnequalProtection = true; |
97 | 91 |
98 // FEC mask types. | 92 // FEC mask types. |
99 const FecMaskType kMaskTypes[] = {kFecMaskRandom, kFecMaskBursty}; | 93 const FecMaskType kMaskTypes[] = {kFecMaskRandom, kFecMaskBursty}; |
100 const int kNumFecMaskTypes = sizeof(kMaskTypes) / sizeof(*kMaskTypes); | 94 const int kNumFecMaskTypes = sizeof(kMaskTypes) / sizeof(*kMaskTypes); |
101 | 95 |
102 // Maximum number of media packets allowed for the mask type. | 96 // Maximum number of media packets allowed for the mask type. |
103 const uint16_t kMaxMediaPackets[] = { | 97 const uint16_t kMaxMediaPackets[] = { |
104 kMaxNumberMediaPackets, | 98 kMaxNumberMediaPackets, |
105 sizeof(kPacketMaskBurstyTbl) / sizeof(*kPacketMaskBurstyTbl)}; | 99 sizeof(kPacketMaskBurstyTbl) / sizeof(*kPacketMaskBurstyTbl)}; |
106 | 100 |
107 ASSERT_EQ(12, kMaxMediaPackets[1]) << "Max media packets for bursty mode not " | 101 ASSERT_EQ(12, kMaxMediaPackets[1]) << "Max media packets for bursty mode not " |
108 << "equal to 12."; | 102 << "equal to 12."; |
109 | 103 |
110 std::unique_ptr<ForwardErrorCorrection> fec = | 104 std::unique_ptr<ForwardErrorCorrection> fec; |
111 ForwardErrorCorrection::CreateUlpfec(); | 105 if (use_flexfec) { |
| 106 fec = ForwardErrorCorrection::CreateFlexfec(); |
| 107 } else { |
| 108 fec = ForwardErrorCorrection::CreateUlpfec(); |
| 109 } |
| 110 |
112 ForwardErrorCorrection::PacketList media_packet_list; | 111 ForwardErrorCorrection::PacketList media_packet_list; |
113 std::list<ForwardErrorCorrection::Packet*> fec_packet_list; | 112 std::list<ForwardErrorCorrection::Packet*> fec_packet_list; |
114 ForwardErrorCorrection::ReceivedPacketList to_decode_list; | 113 ForwardErrorCorrection::ReceivedPacketList to_decode_list; |
115 ForwardErrorCorrection::ReceivedPacketList received_packet_list; | 114 ForwardErrorCorrection::ReceivedPacketList received_packet_list; |
116 ForwardErrorCorrection::RecoveredPacketList recovered_packet_list; | 115 ForwardErrorCorrection::RecoveredPacketList recovered_packet_list; |
117 std::list<uint8_t*> fec_mask_list; | 116 std::list<uint8_t*> fec_mask_list; |
118 | 117 |
119 // Running over only one loss rate to limit execution time. | 118 // Running over only one loss rate to limit execution time. |
120 const float loss_rate[] = {0.5f}; | 119 const float loss_rate[] = {0.5f}; |
121 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); |
122 const float reorder_rate = 0.1f; | 121 const float reorder_rate = 0.1f; |
123 const float duplicate_rate = 0.1f; | 122 const float duplicate_rate = 0.1f; |
124 | 123 |
125 uint8_t media_loss_mask[kMaxNumberMediaPackets]; | 124 uint8_t media_loss_mask[kMaxNumberMediaPackets]; |
126 uint8_t fec_loss_mask[kMaxNumberFecPackets]; | 125 uint8_t fec_loss_mask[kMaxNumberFecPackets]; |
127 uint8_t fec_packet_masks[kMaxNumberFecPackets][kMaxNumberMediaPackets]; | 126 uint8_t fec_packet_masks[kMaxNumberFecPackets][kMaxNumberMediaPackets]; |
128 | 127 |
129 // Seed the random number generator, storing the seed to file in order to | 128 // Seed the random number generator, storing the seed to file in order to |
130 // reproduce past results. | 129 // reproduce past results. |
131 const unsigned int random_seed = static_cast<unsigned int>(time(nullptr)); | 130 const unsigned int random_seed = static_cast<unsigned int>(time(nullptr)); |
132 Random random(random_seed); | 131 Random random(random_seed); |
133 std::string filename = webrtc::test::OutputPath() + "randomSeedLog.txt"; | 132 std::string filename = webrtc::test::OutputPath() + "randomSeedLog.txt"; |
134 FILE* random_seed_file = fopen(filename.c_str(), "a"); | 133 FILE* random_seed_file = fopen(filename.c_str(), "a"); |
135 fprintf(random_seed_file, "%u\n", random_seed); | 134 fprintf(random_seed_file, "%u\n", random_seed); |
136 fclose(random_seed_file); | 135 fclose(random_seed_file); |
137 random_seed_file = nullptr; | 136 random_seed_file = nullptr; |
138 | 137 |
139 uint16_t seq_num = 0; | 138 uint16_t seq_num = 0; |
140 uint32_t timestamp = random.Rand<uint32_t>(); | 139 uint32_t timestamp = random.Rand<uint32_t>(); |
141 const uint32_t ssrc = random.Rand(1u, 0xfffffffe); | 140 const uint32_t media_ssrc = random.Rand(1u, 0xfffffffe); |
| 141 uint32_t fec_ssrc; |
| 142 uint16_t fec_seq_num_offset; |
| 143 if (use_flexfec) { |
| 144 fec_ssrc = random.Rand(1u, 0xfffffffe); |
| 145 fec_seq_num_offset = random.Rand<uint16_t>(); |
| 146 } else { |
| 147 fec_ssrc = media_ssrc; |
| 148 fec_seq_num_offset = 0; |
| 149 } |
142 | 150 |
143 // Loop over the mask types: random and bursty. | 151 // Loop over the mask types: random and bursty. |
144 for (int mask_type_idx = 0; mask_type_idx < kNumFecMaskTypes; | 152 for (int mask_type_idx = 0; mask_type_idx < kNumFecMaskTypes; |
145 ++mask_type_idx) { | 153 ++mask_type_idx) { |
146 for (uint32_t loss_rate_idx = 0; loss_rate_idx < loss_rate_size; | 154 for (uint32_t loss_rate_idx = 0; loss_rate_idx < loss_rate_size; |
147 ++loss_rate_idx) { | 155 ++loss_rate_idx) { |
148 printf("Loss rate: %.2f, Mask type %d \n", loss_rate[loss_rate_idx], | 156 printf("Loss rate: %.2f, Mask type %d \n", loss_rate[loss_rate_idx], |
149 mask_type_idx); | 157 mask_type_idx); |
150 | 158 |
151 const uint32_t packet_mask_max = kMaxMediaPackets[mask_type_idx]; | 159 const uint32_t packet_mask_max = kMaxMediaPackets[mask_type_idx]; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 // the marker bit set followed by the last packet of | 269 // the marker bit set followed by the last packet of |
262 // the frame for which the marker bit is set. | 270 // the frame for which the marker bit is set. |
263 // Only push one (fake) frame to the FEC. | 271 // Only push one (fake) frame to the FEC. |
264 media_packet->data[1] &= 0x7f; | 272 media_packet->data[1] &= 0x7f; |
265 | 273 |
266 ByteWriter<uint16_t>::WriteBigEndian(&media_packet->data[2], | 274 ByteWriter<uint16_t>::WriteBigEndian(&media_packet->data[2], |
267 seq_num); | 275 seq_num); |
268 ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[4], | 276 ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[4], |
269 timestamp); | 277 timestamp); |
270 ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[8], | 278 ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[8], |
271 ssrc); | 279 media_ssrc); |
272 // Generate random values for payload | 280 // Generate random values for payload |
273 for (size_t j = 12; j < media_packet->length; ++j) { | 281 for (size_t j = 12; j < media_packet->length; ++j) { |
274 media_packet->data[j] = random.Rand<uint8_t>(); | 282 media_packet->data[j] = random.Rand<uint8_t>(); |
275 } | 283 } |
276 media_packet_list.push_back(std::move(media_packet)); | 284 media_packet_list.push_back(std::move(media_packet)); |
277 seq_num++; | 285 seq_num++; |
278 } | 286 } |
279 media_packet_list.back()->data[1] |= 0x80; | 287 media_packet_list.back()->data[1] |= 0x80; |
280 | 288 |
281 ASSERT_EQ(0, fec->EncodeFec(media_packet_list, protection_factor, | 289 ASSERT_EQ(0, fec->EncodeFec(media_packet_list, protection_factor, |
(...skipping 13 matching lines...) Expand all Loading... |
295 | 303 |
296 if (loss_random_variable >= loss_rate[loss_rate_idx]) { | 304 if (loss_random_variable >= loss_rate[loss_rate_idx]) { |
297 media_loss_mask[media_packet_idx] = 1; | 305 media_loss_mask[media_packet_idx] = 1; |
298 std::unique_ptr<ForwardErrorCorrection::ReceivedPacket> | 306 std::unique_ptr<ForwardErrorCorrection::ReceivedPacket> |
299 received_packet( | 307 received_packet( |
300 new ForwardErrorCorrection::ReceivedPacket()); | 308 new ForwardErrorCorrection::ReceivedPacket()); |
301 received_packet->pkt = new ForwardErrorCorrection::Packet(); | 309 received_packet->pkt = new ForwardErrorCorrection::Packet(); |
302 received_packet->pkt->length = media_packet->length; | 310 received_packet->pkt->length = media_packet->length; |
303 memcpy(received_packet->pkt->data, media_packet->data, | 311 memcpy(received_packet->pkt->data, media_packet->data, |
304 media_packet->length); | 312 media_packet->length); |
| 313 received_packet->ssrc = media_ssrc; |
305 received_packet->seq_num = | 314 received_packet->seq_num = |
306 ByteReader<uint16_t>::ReadBigEndian(&media_packet->data[2]); | 315 ByteReader<uint16_t>::ReadBigEndian(&media_packet->data[2]); |
307 received_packet->is_fec = false; | 316 received_packet->is_fec = false; |
308 received_packet_list.push_back(std::move(received_packet)); | 317 received_packet_list.push_back(std::move(received_packet)); |
309 } | 318 } |
310 media_packet_idx++; | 319 media_packet_idx++; |
311 } | 320 } |
312 | 321 |
313 memset(fec_loss_mask, 0, sizeof(fec_loss_mask)); | 322 memset(fec_loss_mask, 0, sizeof(fec_loss_mask)); |
314 uint32_t fec_packet_idx = 0; | 323 uint32_t fec_packet_idx = 0; |
315 for (auto* fec_packet : fec_packet_list) { | 324 for (auto* fec_packet : fec_packet_list) { |
316 const float loss_random_variable = random.Rand<float>(); | 325 const float loss_random_variable = random.Rand<float>(); |
317 if (loss_random_variable >= loss_rate[loss_rate_idx]) { | 326 if (loss_random_variable >= loss_rate[loss_rate_idx]) { |
318 fec_loss_mask[fec_packet_idx] = 1; | 327 fec_loss_mask[fec_packet_idx] = 1; |
319 std::unique_ptr<ForwardErrorCorrection::ReceivedPacket> | 328 std::unique_ptr<ForwardErrorCorrection::ReceivedPacket> |
320 received_packet( | 329 received_packet( |
321 new ForwardErrorCorrection::ReceivedPacket()); | 330 new ForwardErrorCorrection::ReceivedPacket()); |
322 received_packet->pkt = new ForwardErrorCorrection::Packet(); | 331 received_packet->pkt = new ForwardErrorCorrection::Packet(); |
323 received_packet->pkt->length = fec_packet->length; | 332 received_packet->pkt->length = fec_packet->length; |
324 memcpy(received_packet->pkt->data, fec_packet->data, | 333 memcpy(received_packet->pkt->data, fec_packet->data, |
325 fec_packet->length); | 334 fec_packet->length); |
326 received_packet->seq_num = seq_num; | 335 received_packet->seq_num = fec_seq_num_offset + seq_num; |
327 received_packet->is_fec = true; | 336 received_packet->is_fec = true; |
328 received_packet->ssrc = ssrc; | 337 received_packet->ssrc = fec_ssrc; |
329 received_packet_list.push_back(std::move(received_packet)); | 338 received_packet_list.push_back(std::move(received_packet)); |
330 | 339 |
331 fec_mask_list.push_back(fec_packet_masks[fec_packet_idx]); | 340 fec_mask_list.push_back(fec_packet_masks[fec_packet_idx]); |
332 } | 341 } |
333 ++fec_packet_idx; | 342 ++fec_packet_idx; |
334 ++seq_num; | 343 ++seq_num; |
335 } | 344 } |
336 | 345 |
337 #ifdef VERBOSE_OUTPUT | 346 #ifdef VERBOSE_OUTPUT |
338 printf("Media loss mask:\n"); | 347 printf("Media loss mask:\n"); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 } // loop over num_media_packets | 455 } // loop over num_media_packets |
447 } // loop over loss rates | 456 } // loop over loss rates |
448 } // loop over mask types | 457 } // loop over mask types |
449 | 458 |
450 // Have DecodeFec clear the recovered packet list. | 459 // Have DecodeFec clear the recovered packet list. |
451 fec->ResetState(&recovered_packet_list); | 460 fec->ResetState(&recovered_packet_list); |
452 ASSERT_TRUE(recovered_packet_list.empty()) | 461 ASSERT_TRUE(recovered_packet_list.empty()) |
453 << "Recovered packet list is not empty"; | 462 << "Recovered packet list is not empty"; |
454 } | 463 } |
455 | 464 |
| 465 // Too slow to finish before timeout on iOS. See webrtc:4755. |
| 466 #if defined(WEBRTC_IOS) |
| 467 #define MAYBE_UlpecTest DISABLED_UlpecTest |
| 468 #define MAYBE_FlexfecTest DISABLED_FlexfecTest |
| 469 #else |
| 470 #define MAYBE_UlpecTest UlpecTest |
| 471 #define MAYBE_FlexfecTest FlexfecTest |
| 472 #endif |
| 473 TEST(FecTest, MAYBE_UlpecTest) { |
| 474 RunTest(false); |
| 475 } |
| 476 |
| 477 TEST(FecTest, MAYBE_FlexfecTest) { |
| 478 RunTest(true); |
| 479 } |
| 480 |
456 } // namespace test | 481 } // namespace test |
457 } // namespace webrtc | 482 } // namespace webrtc |
OLD | NEW |