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 20 matching lines...) Expand all Loading... | |
31 // #define VERBOSE_OUTPUT | 31 // #define VERBOSE_OUTPUT |
32 | 32 |
33 namespace webrtc { | 33 namespace webrtc { |
34 namespace fec_private_tables { | 34 namespace fec_private_tables { |
35 extern const uint8_t** kPacketMaskBurstyTbl[12]; | 35 extern const uint8_t** kPacketMaskBurstyTbl[12]; |
36 } | 36 } |
37 namespace test { | 37 namespace test { |
38 using fec_private_tables::kPacketMaskBurstyTbl; | 38 using fec_private_tables::kPacketMaskBurstyTbl; |
39 | 39 |
40 void ReceivePackets( | 40 void ReceivePackets( |
41 ForwardErrorCorrection::ReceivedPacketList* toDecodeList, | 41 ForwardErrorCorrection::ReceivedPacketList* to_decode_list, |
42 ForwardErrorCorrection::ReceivedPacketList* receivedPacketList, | 42 ForwardErrorCorrection::ReceivedPacketList* received_packet_list, |
43 size_t numPacketsToDecode, | 43 size_t num_packets_to_decode, |
44 float reorderRate, | 44 float reorder_rate, |
45 float duplicateRate, | 45 float duplicate_rate, |
46 Random* random) { | 46 Random* random) { |
47 assert(toDecodeList->empty()); | 47 assert(to_decode_list->empty()); |
48 assert(numPacketsToDecode <= receivedPacketList->size()); | 48 assert(num_packets_to_decode <= received_packet_list->size()); |
49 | 49 |
50 ForwardErrorCorrection::ReceivedPacketList::iterator it; | 50 for (size_t i = 0; i < num_packets_to_decode; i++) { |
51 for (size_t i = 0; i < numPacketsToDecode; i++) { | 51 auto it = received_packet_list->begin(); |
52 it = receivedPacketList->begin(); | |
53 // Reorder packets. | 52 // Reorder packets. |
54 float randomVariable = random->Rand<float>(); | 53 float random_variable = random->Rand<float>(); |
55 while (randomVariable < reorderRate) { | 54 while (random_variable < reorder_rate) { |
56 ++it; | 55 ++it; |
57 if (it == receivedPacketList->end()) { | 56 if (it == received_packet_list->end()) { |
58 --it; | 57 --it; |
59 break; | 58 break; |
60 } | 59 } |
61 randomVariable = random->Rand<float>(); | 60 random_variable = random->Rand<float>(); |
62 } | 61 } |
63 ForwardErrorCorrection::ReceivedPacket* receivedPacket = *it; | 62 ForwardErrorCorrection::ReceivedPacket* received_packet = *it; |
64 toDecodeList->push_back(receivedPacket); | 63 to_decode_list->push_back(received_packet); |
65 | 64 |
66 // Duplicate packets. | 65 // Duplicate packets. |
67 randomVariable = random->Rand<float>(); | 66 random_variable = random->Rand<float>(); |
68 while (randomVariable < duplicateRate) { | 67 while (random_variable < duplicate_rate) { |
69 ForwardErrorCorrection::ReceivedPacket* duplicatePacket = | 68 ForwardErrorCorrection::ReceivedPacket* duplicate_packet = |
70 new ForwardErrorCorrection::ReceivedPacket; | 69 new ForwardErrorCorrection::ReceivedPacket; |
71 *duplicatePacket = *receivedPacket; | 70 *duplicate_packet = *received_packet; |
72 duplicatePacket->pkt = new ForwardErrorCorrection::Packet; | 71 duplicate_packet->pkt = new ForwardErrorCorrection::Packet; |
73 memcpy(duplicatePacket->pkt->data, receivedPacket->pkt->data, | 72 memcpy(duplicate_packet->pkt->data, received_packet->pkt->data, |
74 receivedPacket->pkt->length); | 73 received_packet->pkt->length); |
75 duplicatePacket->pkt->length = receivedPacket->pkt->length; | 74 duplicate_packet->pkt->length = received_packet->pkt->length; |
76 | 75 |
77 toDecodeList->push_back(duplicatePacket); | 76 to_decode_list->push_back(duplicate_packet); |
78 randomVariable = random->Rand<float>(); | 77 random_variable = random->Rand<float>(); |
79 } | 78 } |
80 receivedPacketList->erase(it); | 79 received_packet_list->erase(it); |
81 } | 80 } |
82 } | 81 } |
83 | 82 |
84 // Too slow to finish before timeout on iOS. See webrtc:4755. | 83 // Too slow to finish before timeout on iOS. See webrtc:4755. |
85 #if defined(WEBRTC_IOS) | 84 #if defined(WEBRTC_IOS) |
86 #define MAYBE_FecTest DISABLED_FecTest | 85 #define MAYBE_FecTest DISABLED_FecTest |
87 #else | 86 #else |
88 #define MAYBE_FecTest FecTest | 87 #define MAYBE_FecTest FecTest |
89 #endif | 88 #endif |
90 TEST(FecTest, MAYBE_FecTest) { | 89 TEST(FecTest, MAYBE_FecTest) { |
(...skipping 13 matching lines...) Expand all Loading... | |
104 | 103 |
105 // Maximum number of media packets allowed for the mask type. | 104 // Maximum number of media packets allowed for the mask type. |
106 const uint16_t kMaxMediaPackets[] = { | 105 const uint16_t kMaxMediaPackets[] = { |
107 kMaxNumberMediaPackets, | 106 kMaxNumberMediaPackets, |
108 sizeof(kPacketMaskBurstyTbl) / sizeof(*kPacketMaskBurstyTbl)}; | 107 sizeof(kPacketMaskBurstyTbl) / sizeof(*kPacketMaskBurstyTbl)}; |
109 | 108 |
110 ASSERT_EQ(12, kMaxMediaPackets[1]) << "Max media packets for bursty mode not " | 109 ASSERT_EQ(12, kMaxMediaPackets[1]) << "Max media packets for bursty mode not " |
111 << "equal to 12."; | 110 << "equal to 12."; |
112 | 111 |
113 ForwardErrorCorrection fec; | 112 ForwardErrorCorrection fec; |
114 ForwardErrorCorrection::PacketList mediaPacketList; | 113 ForwardErrorCorrection::PacketList media_packet_list; |
115 ForwardErrorCorrection::PacketList fecPacketList; | 114 ForwardErrorCorrection::PacketList fec_packet_list; |
116 ForwardErrorCorrection::ReceivedPacketList toDecodeList; | 115 ForwardErrorCorrection::ReceivedPacketList to_decode_list; |
117 ForwardErrorCorrection::ReceivedPacketList receivedPacketList; | 116 ForwardErrorCorrection::ReceivedPacketList received_packet_list; |
118 ForwardErrorCorrection::RecoveredPacketList recoveredPacketList; | 117 ForwardErrorCorrection::RecoveredPacketList recovered_packet_list; |
119 std::list<uint8_t*> fecMaskList; | 118 std::list<uint8_t*> fec_mask_list; |
120 | 119 |
121 ForwardErrorCorrection::Packet* mediaPacket = NULL; | 120 ForwardErrorCorrection::Packet* media_packet = NULL; |
danilchap
2016/06/29 10:31:53
= nullptr;
brandtr
2016/06/29 14:24:11
Done.
| |
122 // Running over only one loss rate to limit execution time. | 121 // Running over only one loss rate to limit execution time. |
123 const float lossRate[] = {0.5f}; | 122 const float loss_rate[] = {0.5f}; |
124 const uint32_t lossRateSize = sizeof(lossRate) / sizeof(*lossRate); | 123 const uint32_t loss_rate_size = sizeof(loss_rate) / sizeof(*loss_rate); |
125 const float reorderRate = 0.1f; | 124 const float reorder_rate = 0.1f; |
126 const float duplicateRate = 0.1f; | 125 const float duplicate_rate = 0.1f; |
127 | 126 |
128 uint8_t mediaLossMask[kMaxNumberMediaPackets]; | 127 uint8_t media_loss_mask[kMaxNumberMediaPackets]; |
129 uint8_t fecLossMask[kMaxNumberFecPackets]; | 128 uint8_t fec_loss_mask[kMaxNumberFecPackets]; |
130 uint8_t fecPacketMasks[kMaxNumberFecPackets][kMaxNumberMediaPackets]; | 129 uint8_t fec_packet_masks[kMaxNumberFecPackets][kMaxNumberMediaPackets]; |
131 | 130 |
132 // Seed the random number generator, storing the seed to file in order to | 131 // Seed the random number generator, storing the seed to file in order to |
133 // reproduce past results. | 132 // reproduce past results. |
134 const unsigned int randomSeed = static_cast<unsigned int>(time(NULL)); | 133 const unsigned int random_seed = static_cast<unsigned int>(time(NULL)); |
135 Random random(randomSeed); | 134 Random random(random_seed); |
136 std::string filename = webrtc::test::OutputPath() + "randomSeedLog.txt"; | 135 std::string filename = webrtc::test::OutputPath() + "randomSeedLog.txt"; |
137 FILE* randomSeedFile = fopen(filename.c_str(), "a"); | 136 FILE* random_seed_file = fopen(filename.c_str(), "a"); |
138 fprintf(randomSeedFile, "%u\n", randomSeed); | 137 fprintf(random_seed_file, "%u\n", random_seed); |
139 fclose(randomSeedFile); | 138 fclose(random_seed_file); |
140 randomSeedFile = NULL; | 139 random_seed_file = NULL; |
danilchap
2016/06/29 10:31:53
ditto
brandtr
2016/06/29 14:24:11
Done.
| |
141 | 140 |
142 uint16_t seqNum = 0; | 141 uint16_t seq_num = 0; |
143 uint32_t timeStamp = random.Rand<uint32_t>(); | 142 uint32_t timestamp = random.Rand<uint32_t>(); |
144 const uint32_t ssrc = random.Rand(1u, 0xfffffffe); | 143 const uint32_t ssrc = random.Rand(1u, 0xfffffffe); |
145 | 144 |
146 // Loop over the mask types: random and bursty. | 145 // Loop over the mask types: random and bursty. |
147 for (int mask_type_idx = 0; mask_type_idx < kNumFecMaskTypes; | 146 for (int mask_type_idx = 0; mask_type_idx < kNumFecMaskTypes; |
148 ++mask_type_idx) { | 147 ++mask_type_idx) { |
149 for (uint32_t lossRateIdx = 0; lossRateIdx < lossRateSize; ++lossRateIdx) { | 148 for (uint32_t loss_rate_idx = 0; loss_rate_idx < loss_rate_size; |
150 printf("Loss rate: %.2f, Mask type %d \n", lossRate[lossRateIdx], | 149 ++loss_rate_idx) { |
150 printf("Loss rate: %.2f, Mask type %d \n", loss_rate[loss_rate_idx], | |
151 mask_type_idx); | 151 mask_type_idx); |
152 | 152 |
153 const uint32_t packetMaskMax = kMaxMediaPackets[mask_type_idx]; | 153 const uint32_t packet_mask_max = kMaxMediaPackets[mask_type_idx]; |
154 uint8_t* packetMask = new uint8_t[packetMaskMax * kNumMaskBytesL1]; | 154 uint8_t* packet_mask = new uint8_t[packet_mask_max * kNumMaskBytesL1]; |
155 | 155 |
156 FecMaskType fec_mask_type = kMaskTypes[mask_type_idx]; | 156 FecMaskType fec_mask_type = kMaskTypes[mask_type_idx]; |
157 | 157 |
158 for (uint32_t numMediaPackets = 1; numMediaPackets <= packetMaskMax; | 158 for (uint32_t num_media_packets = 1; num_media_packets <= packet_mask_max; |
159 numMediaPackets++) { | 159 num_media_packets++) { |
160 internal::PacketMaskTable mask_table(fec_mask_type, numMediaPackets); | 160 internal::PacketMaskTable mask_table(fec_mask_type, num_media_packets); |
161 | 161 |
162 for (uint32_t numFecPackets = 1; | 162 for (uint32_t num_fec_packets = 1; |
163 numFecPackets <= numMediaPackets && numFecPackets <= packetMaskMax; | 163 num_fec_packets <= num_media_packets && |
164 numFecPackets++) { | 164 num_fec_packets <= packet_mask_max; |
165 // Loop over numImpPackets: usually <= (0.3*numMediaPackets). | 165 num_fec_packets++) { |
166 // For this test we check up to ~ (numMediaPackets / 4). | 166 // Loop over num_imp_packets: usually <= (0.3*num_media_packets). |
167 uint32_t maxNumImpPackets = numMediaPackets / 4 + 1; | 167 // For this test we check up to ~ (num_media_packets / 4). |
168 for (uint32_t numImpPackets = 0; numImpPackets <= maxNumImpPackets && | 168 uint32_t max_num_imp_packets = num_media_packets / 4 + 1; |
169 numImpPackets <= packetMaskMax; | 169 for (uint32_t num_imp_packets = 0; |
170 numImpPackets++) { | 170 num_imp_packets <= max_num_imp_packets && |
171 uint8_t protectionFactor = | 171 num_imp_packets <= packet_mask_max; |
172 static_cast<uint8_t>(numFecPackets * 255 / numMediaPackets); | 172 num_imp_packets++) { |
173 uint8_t protection_factor = | |
174 static_cast<uint8_t>(num_fec_packets * 255 / num_media_packets); | |
173 | 175 |
174 const uint32_t maskBytesPerFecPacket = | 176 const uint32_t mask_bytes_per_fec_packet = |
175 (numMediaPackets > 16) ? kNumMaskBytesL1 : kNumMaskBytesL0; | 177 (num_media_packets > 16) ? kNumMaskBytesL1 : kNumMaskBytesL0; |
176 | 178 |
177 memset(packetMask, 0, numMediaPackets * maskBytesPerFecPacket); | 179 memset(packet_mask, 0, |
180 num_media_packets * mask_bytes_per_fec_packet); | |
178 | 181 |
179 // Transfer packet masks from bit-mask to byte-mask. | 182 // Transfer packet masks from bit-mask to byte-mask. |
180 internal::GeneratePacketMasks(numMediaPackets, numFecPackets, | 183 internal::GeneratePacketMasks(num_media_packets, num_fec_packets, |
181 numImpPackets, kUseUnequalProtection, | 184 num_imp_packets, |
182 mask_table, packetMask); | 185 kUseUnequalProtection, |
186 mask_table, packet_mask); | |
183 | 187 |
184 #ifdef VERBOSE_OUTPUT | 188 #ifdef VERBOSE_OUTPUT |
185 printf( | 189 printf( |
186 "%u media packets, %u FEC packets, %u numImpPackets, " | 190 "%u media packets, %u FEC packets, %u num_imp_packets, " |
187 "loss rate = %.2f \n", | 191 "loss rate = %.2f \n", |
188 numMediaPackets, numFecPackets, numImpPackets, | 192 num_media_packets, num_fec_packets, num_imp_packets, |
189 lossRate[lossRateIdx]); | 193 loss_rate[loss_rate_idx]); |
190 printf("Packet mask matrix \n"); | 194 printf("Packet mask matrix \n"); |
191 #endif | 195 #endif |
192 | 196 |
193 for (uint32_t i = 0; i < numFecPackets; i++) { | 197 for (uint32_t i = 0; i < num_fec_packets; i++) { |
194 for (uint32_t j = 0; j < numMediaPackets; j++) { | 198 for (uint32_t j = 0; j < num_media_packets; j++) { |
195 const uint8_t byteMask = | 199 const uint8_t byte_mask = |
196 packetMask[i * maskBytesPerFecPacket + j / 8]; | 200 packet_mask[i * mask_bytes_per_fec_packet + j / 8]; |
197 const uint32_t bitPosition = (7 - j % 8); | 201 const uint32_t bit_position = (7 - j % 8); |
198 fecPacketMasks[i][j] = | 202 fec_packet_masks[i][j] = |
199 (byteMask & (1 << bitPosition)) >> bitPosition; | 203 (byte_mask & (1 << bit_position)) >> bit_position; |
200 #ifdef VERBOSE_OUTPUT | 204 #ifdef VERBOSE_OUTPUT |
201 printf("%u ", fecPacketMasks[i][j]); | 205 printf("%u ", fec_packet_masks[i][j]); |
202 #endif | 206 #endif |
203 } | 207 } |
204 #ifdef VERBOSE_OUTPUT | 208 #ifdef VERBOSE_OUTPUT |
205 printf("\n"); | 209 printf("\n"); |
206 #endif | 210 #endif |
207 } | 211 } |
208 #ifdef VERBOSE_OUTPUT | 212 #ifdef VERBOSE_OUTPUT |
209 printf("\n"); | 213 printf("\n"); |
210 #endif | 214 #endif |
211 // Check for all zero rows or columns: indicates incorrect mask. | 215 // Check for all zero rows or columns: indicates incorrect mask. |
212 uint32_t rowLimit = numMediaPackets; | 216 uint32_t row_limit = num_media_packets; |
213 for (uint32_t i = 0; i < numFecPackets; ++i) { | 217 for (uint32_t i = 0; i < num_fec_packets; ++i) { |
214 uint32_t rowSum = 0; | 218 uint32_t row_sum = 0; |
215 for (uint32_t j = 0; j < rowLimit; ++j) { | 219 for (uint32_t j = 0; j < row_limit; ++j) { |
216 rowSum += fecPacketMasks[i][j]; | 220 row_sum += fec_packet_masks[i][j]; |
217 } | 221 } |
218 ASSERT_NE(0u, rowSum) << "Row is all zero " << i; | 222 ASSERT_NE(0u, row_sum) << "Row is all zero " << i; |
219 } | 223 } |
220 for (uint32_t j = 0; j < rowLimit; ++j) { | 224 for (uint32_t j = 0; j < row_limit; ++j) { |
221 uint32_t columnSum = 0; | 225 uint32_t column_sum = 0; |
222 for (uint32_t i = 0; i < numFecPackets; ++i) { | 226 for (uint32_t i = 0; i < num_fec_packets; ++i) { |
223 columnSum += fecPacketMasks[i][j]; | 227 column_sum += fec_packet_masks[i][j]; |
224 } | 228 } |
225 ASSERT_NE(0u, columnSum) << "Column is all zero " << j; | 229 ASSERT_NE(0u, column_sum) << "Column is all zero " << j; |
226 } | 230 } |
227 | 231 |
228 // Construct media packets. | 232 // Construct media packets. |
229 // Reset the sequence number here for each FEC code/mask tested | 233 // Reset the sequence number here for each FEC code/mask tested |
230 // below, to avoid sequence number wrap-around. In actual decoding, | 234 // below, to avoid sequence number wrap-around. In actual decoding, |
231 // old FEC packets in list are dropped if sequence number wrap | 235 // old FEC packets in list are dropped if sequence number wrap |
232 // around is detected. This case is currently not handled below. | 236 // around is detected. This case is currently not handled below. |
233 seqNum = 0; | 237 seq_num = 0; |
234 for (uint32_t i = 0; i < numMediaPackets; ++i) { | 238 for (uint32_t i = 0; i < num_media_packets; ++i) { |
235 mediaPacket = new ForwardErrorCorrection::Packet; | 239 media_packet = new ForwardErrorCorrection::Packet; |
236 mediaPacketList.push_back(mediaPacket); | 240 media_packet_list.push_back(media_packet); |
237 const uint32_t kMinPacketSize = 12; | 241 const uint32_t kMinPacketSize = 12; |
238 const uint32_t kMaxPacketSize = static_cast<uint32_t>( | 242 const uint32_t kMaxPacketSize = static_cast<uint32_t>( |
239 IP_PACKET_SIZE - 12 - 28 - | 243 IP_PACKET_SIZE - 12 - 28 - |
240 ForwardErrorCorrection::PacketOverhead()); | 244 ForwardErrorCorrection::PacketOverhead()); |
241 mediaPacket->length = random.Rand(kMinPacketSize, kMaxPacketSize); | 245 media_packet->length = random.Rand(kMinPacketSize, |
246 kMaxPacketSize); | |
242 | 247 |
243 // Generate random values for the first 2 bytes. | 248 // Generate random values for the first 2 bytes. |
244 mediaPacket->data[0] = random.Rand<uint8_t>(); | 249 media_packet->data[0] = random.Rand<uint8_t>(); |
245 mediaPacket->data[1] = random.Rand<uint8_t>(); | 250 media_packet->data[1] = random.Rand<uint8_t>(); |
246 | 251 |
247 // The first two bits are assumed to be 10 by the | 252 // The first two bits are assumed to be 10 by the |
248 // FEC encoder. In fact the FEC decoder will set the | 253 // FEC encoder. In fact the FEC decoder will set the |
249 // two first bits to 10 regardless of what they | 254 // two first bits to 10 regardless of what they |
250 // actually were. Set the first two bits to 10 | 255 // actually were. Set the first two bits to 10 |
251 // so that a memcmp can be performed for the | 256 // so that a memcmp can be performed for the |
252 // whole restored packet. | 257 // whole restored packet. |
253 mediaPacket->data[0] |= 0x80; | 258 media_packet->data[0] |= 0x80; |
254 mediaPacket->data[0] &= 0xbf; | 259 media_packet->data[0] &= 0xbf; |
255 | 260 |
256 // FEC is applied to a whole frame. | 261 // FEC is applied to a whole frame. |
257 // A frame is signaled by multiple packets without | 262 // A frame is signaled by multiple packets without |
258 // the marker bit set followed by the last packet of | 263 // the marker bit set followed by the last packet of |
259 // the frame for which the marker bit is set. | 264 // the frame for which the marker bit is set. |
260 // Only push one (fake) frame to the FEC. | 265 // Only push one (fake) frame to the FEC. |
261 mediaPacket->data[1] &= 0x7f; | 266 media_packet->data[1] &= 0x7f; |
262 | 267 |
263 ByteWriter<uint16_t>::WriteBigEndian(&mediaPacket->data[2], | 268 ByteWriter<uint16_t>::WriteBigEndian(&media_packet->data[2], |
264 seqNum); | 269 seq_num); |
265 ByteWriter<uint32_t>::WriteBigEndian(&mediaPacket->data[4], | 270 ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[4], |
266 timeStamp); | 271 timestamp); |
267 ByteWriter<uint32_t>::WriteBigEndian(&mediaPacket->data[8], ssrc); | 272 ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[8], |
273 ssrc); | |
268 // Generate random values for payload | 274 // Generate random values for payload |
269 for (size_t j = 12; j < mediaPacket->length; ++j) { | 275 for (size_t j = 12; j < media_packet->length; ++j) { |
270 mediaPacket->data[j] = random.Rand<uint8_t>(); | 276 media_packet->data[j] = random.Rand<uint8_t>(); |
271 } | 277 } |
272 seqNum++; | 278 seq_num++; |
273 } | 279 } |
274 mediaPacket->data[1] |= 0x80; | 280 media_packet->data[1] |= 0x80; |
275 | 281 |
276 ASSERT_EQ(0, fec.GenerateFEC(mediaPacketList, protectionFactor, | 282 ASSERT_EQ(0, fec.GenerateFEC(media_packet_list, protection_factor, |
277 numImpPackets, kUseUnequalProtection, | 283 num_imp_packets, kUseUnequalProtection, |
278 fec_mask_type, &fecPacketList)) | 284 fec_mask_type, &fec_packet_list)) |
279 << "GenerateFEC() failed"; | 285 << "GenerateFEC() failed"; |
280 | 286 |
281 ASSERT_EQ(numFecPackets, fecPacketList.size()) | 287 ASSERT_EQ(num_fec_packets, fec_packet_list.size()) |
282 << "We requested " << numFecPackets << " FEC packets, but " | 288 << "We requested " << num_fec_packets << " FEC packets, but " |
283 << "GenerateFEC() produced " << fecPacketList.size(); | 289 << "GenerateFEC() produced " << fec_packet_list.size(); |
284 memset(mediaLossMask, 0, sizeof(mediaLossMask)); | 290 memset(media_loss_mask, 0, sizeof(media_loss_mask)); |
285 ForwardErrorCorrection::PacketList::iterator mediaPacketListItem = | 291 auto media_packet_list_it = media_packet_list.cbegin(); |
286 mediaPacketList.begin(); | 292 ForwardErrorCorrection::ReceivedPacket* received_packet; |
danilchap
2016/06/29 10:31:53
do not leave uninitialized: either initialized wit
brandtr
2016/06/29 14:24:11
Acknowledged.
| |
287 ForwardErrorCorrection::ReceivedPacket* receivedPacket; | 293 uint32_t media_packet_idx = 0; |
288 uint32_t mediaPacketIdx = 0; | 294 |
289 | 295 while (media_packet_list_it != media_packet_list.end()) { |
290 while (mediaPacketListItem != mediaPacketList.end()) { | 296 media_packet = *media_packet_list_it; |
291 mediaPacket = *mediaPacketListItem; | |
292 // We want a value between 0 and 1. | 297 // We want a value between 0 and 1. |
293 const float lossRandomVariable = random.Rand<float>(); | 298 const float loss_random_variable = random.Rand<float>(); |
294 | 299 |
295 if (lossRandomVariable >= lossRate[lossRateIdx]) { | 300 if (loss_random_variable >= loss_rate[loss_rate_idx]) { |
296 mediaLossMask[mediaPacketIdx] = 1; | 301 media_loss_mask[media_packet_idx] = 1; |
297 receivedPacket = new ForwardErrorCorrection::ReceivedPacket; | 302 received_packet = new ForwardErrorCorrection::ReceivedPacket; |
298 receivedPacket->pkt = new ForwardErrorCorrection::Packet; | 303 received_packet->pkt = new ForwardErrorCorrection::Packet; |
299 receivedPacketList.push_back(receivedPacket); | 304 received_packet_list.push_back(received_packet); |
300 | 305 |
301 receivedPacket->pkt->length = mediaPacket->length; | 306 received_packet->pkt->length = media_packet->length; |
302 memcpy(receivedPacket->pkt->data, mediaPacket->data, | 307 memcpy(received_packet->pkt->data, media_packet->data, |
303 mediaPacket->length); | 308 media_packet->length); |
304 receivedPacket->seq_num = | 309 received_packet->seq_num = |
305 ByteReader<uint16_t>::ReadBigEndian(&mediaPacket->data[2]); | 310 ByteReader<uint16_t>::ReadBigEndian(&media_packet->data[2]); |
306 receivedPacket->is_fec = false; | 311 received_packet->is_fec = false; |
307 } | 312 } |
308 mediaPacketIdx++; | 313 media_packet_idx++; |
309 ++mediaPacketListItem; | 314 ++media_packet_list_it; |
310 } | 315 } |
311 memset(fecLossMask, 0, sizeof(fecLossMask)); | 316 memset(fec_loss_mask, 0, sizeof(fec_loss_mask)); |
312 ForwardErrorCorrection::PacketList::iterator fecPacketListItem = | 317 auto fec_packet_list_it = fec_packet_list.cbegin(); |
313 fecPacketList.begin(); | 318 ForwardErrorCorrection::Packet* fec_packet; |
danilchap
2016/06/29 10:31:53
ditto
brandtr
2016/06/29 14:24:11
Acknowledged.
| |
314 ForwardErrorCorrection::Packet* fecPacket; | 319 uint32_t fec_packet_idx = 0; |
315 uint32_t fecPacketIdx = 0; | 320 while (fec_packet_list_it != fec_packet_list.end()) { |
316 while (fecPacketListItem != fecPacketList.end()) { | 321 fec_packet = *fec_packet_list_it; |
317 fecPacket = *fecPacketListItem; | 322 const float loss_random_variable = random.Rand<float>(); |
318 const float lossRandomVariable = random.Rand<float>(); | 323 if (loss_random_variable >= loss_rate[loss_rate_idx]) { |
319 if (lossRandomVariable >= lossRate[lossRateIdx]) { | 324 fec_loss_mask[fec_packet_idx] = 1; |
320 fecLossMask[fecPacketIdx] = 1; | 325 received_packet = new ForwardErrorCorrection::ReceivedPacket; |
321 receivedPacket = new ForwardErrorCorrection::ReceivedPacket; | 326 received_packet->pkt = new ForwardErrorCorrection::Packet; |
322 receivedPacket->pkt = new ForwardErrorCorrection::Packet; | 327 |
323 | 328 received_packet_list.push_back(received_packet); |
324 receivedPacketList.push_back(receivedPacket); | 329 |
325 | 330 received_packet->pkt->length = fec_packet->length; |
326 receivedPacket->pkt->length = fecPacket->length; | 331 memcpy(received_packet->pkt->data, fec_packet->data, |
327 memcpy(receivedPacket->pkt->data, fecPacket->data, | 332 fec_packet->length); |
328 fecPacket->length); | 333 |
329 | 334 received_packet->seq_num = seq_num; |
330 receivedPacket->seq_num = seqNum; | 335 received_packet->is_fec = true; |
331 receivedPacket->is_fec = true; | 336 received_packet->ssrc = ssrc; |
332 receivedPacket->ssrc = ssrc; | 337 |
333 | 338 fec_mask_list.push_back(fec_packet_masks[fec_packet_idx]); |
334 fecMaskList.push_back(fecPacketMasks[fecPacketIdx]); | 339 } |
335 } | 340 ++fec_packet_idx; |
336 ++fecPacketIdx; | 341 ++seq_num; |
337 ++seqNum; | 342 ++fec_packet_list_it; |
338 ++fecPacketListItem; | |
339 } | 343 } |
340 | 344 |
341 #ifdef VERBOSE_OUTPUT | 345 #ifdef VERBOSE_OUTPUT |
342 printf("Media loss mask:\n"); | 346 printf("Media loss mask:\n"); |
343 for (uint32_t i = 0; i < numMediaPackets; i++) { | 347 for (uint32_t i = 0; i < num_media_packets; i++) { |
344 printf("%u ", mediaLossMask[i]); | 348 printf("%u ", media_loss_mask[i]); |
345 } | 349 } |
346 printf("\n\n"); | 350 printf("\n\n"); |
347 | 351 |
348 printf("FEC loss mask:\n"); | 352 printf("FEC loss mask:\n"); |
349 for (uint32_t i = 0; i < numFecPackets; i++) { | 353 for (uint32_t i = 0; i < num_fec_packets; i++) { |
350 printf("%u ", fecLossMask[i]); | 354 printf("%u ", fec_loss_mask[i]); |
351 } | 355 } |
352 printf("\n\n"); | 356 printf("\n\n"); |
353 #endif | 357 #endif |
354 | 358 |
355 std::list<uint8_t*>::iterator fecMaskIt = fecMaskList.begin(); | 359 auto fec_mask_it = fec_mask_list.begin(); |
356 uint8_t* fecMask; | 360 uint8_t* fec_mask; |
danilchap
2016/06/29 10:31:53
ditto
brandtr
2016/06/29 14:24:11
Acknowledged.
| |
357 while (fecMaskIt != fecMaskList.end()) { | 361 while (fec_mask_it != fec_mask_list.end()) { |
358 fecMask = *fecMaskIt; | 362 fec_mask = *fec_mask_it; |
359 uint32_t hammingDist = 0; | 363 uint32_t hamming_dist = 0; |
360 uint32_t recoveryPosition = 0; | 364 uint32_t recovery_position = 0; |
361 for (uint32_t i = 0; i < numMediaPackets; i++) { | 365 for (uint32_t i = 0; i < num_media_packets; i++) { |
362 if (mediaLossMask[i] == 0 && fecMask[i] == 1) { | 366 if (media_loss_mask[i] == 0 && fec_mask[i] == 1) { |
363 recoveryPosition = i; | 367 recovery_position = i; |
364 ++hammingDist; | 368 ++hamming_dist; |
365 } | 369 } |
366 } | 370 } |
367 std::list<uint8_t*>::iterator itemToDelete = fecMaskIt; | 371 std::list<uint8_t*>::iterator item_to_delete = fec_mask_it; |
368 ++fecMaskIt; | 372 ++fec_mask_it; |
369 | 373 |
370 if (hammingDist == 1) { | 374 if (hamming_dist == 1) { |
371 // Recovery possible. Restart search. | 375 // Recovery possible. Restart search. |
372 mediaLossMask[recoveryPosition] = 1; | 376 media_loss_mask[recovery_position] = 1; |
373 fecMaskIt = fecMaskList.begin(); | 377 fec_mask_it = fec_mask_list.begin(); |
374 } else if (hammingDist == 0) { | 378 } else if (hamming_dist == 0) { |
375 // FEC packet cannot provide further recovery. | 379 // FEC packet cannot provide further recovery. |
376 fecMaskList.erase(itemToDelete); | 380 fec_mask_list.erase(item_to_delete); |
377 } | 381 } |
378 } | 382 } |
379 #ifdef VERBOSE_OUTPUT | 383 #ifdef VERBOSE_OUTPUT |
380 printf("Recovery mask:\n"); | 384 printf("Recovery mask:\n"); |
381 for (uint32_t i = 0; i < numMediaPackets; ++i) { | 385 for (uint32_t i = 0; i < num_media_packets; ++i) { |
382 printf("%u ", mediaLossMask[i]); | 386 printf("%u ", media_loss_mask[i]); |
383 } | 387 } |
384 printf("\n\n"); | 388 printf("\n\n"); |
385 #endif | 389 #endif |
386 // For error-checking frame completion. | 390 // For error-checking frame completion. |
387 bool fecPacketReceived = false; | 391 bool fec_packet_received = false; |
388 while (!receivedPacketList.empty()) { | 392 while (!received_packet_list.empty()) { |
389 size_t numPacketsToDecode = random.Rand( | 393 size_t num_packets_to_decode = random.Rand( |
390 1u, static_cast<uint32_t>(receivedPacketList.size())); | 394 1u, static_cast<uint32_t>(received_packet_list.size())); |
391 ReceivePackets(&toDecodeList, &receivedPacketList, | 395 ReceivePackets(&to_decode_list, &received_packet_list, |
392 numPacketsToDecode, reorderRate, duplicateRate, | 396 num_packets_to_decode, reorder_rate, |
393 &random); | 397 duplicate_rate, &random); |
394 | 398 |
395 if (fecPacketReceived == false) { | 399 if (fec_packet_received == false) { |
396 ForwardErrorCorrection::ReceivedPacketList::iterator | 400 auto to_decode_it = to_decode_list.cbegin(); |
397 toDecodeIt = toDecodeList.begin(); | 401 while (to_decode_it != to_decode_list.end()) { |
398 while (toDecodeIt != toDecodeList.end()) { | 402 received_packet = *to_decode_it; |
399 receivedPacket = *toDecodeIt; | 403 if (received_packet->is_fec) { |
400 if (receivedPacket->is_fec) { | 404 fec_packet_received = true; |
401 fecPacketReceived = true; | |
402 } | 405 } |
403 ++toDecodeIt; | 406 ++to_decode_it; |
404 } | 407 } |
405 } | 408 } |
406 ASSERT_EQ(0, fec.DecodeFEC(&toDecodeList, &recoveredPacketList)) | 409 ASSERT_EQ(0, fec.DecodeFEC(&to_decode_list, |
410 &recovered_packet_list)) | |
407 << "DecodeFEC() failed"; | 411 << "DecodeFEC() failed"; |
408 ASSERT_TRUE(toDecodeList.empty()) | 412 ASSERT_TRUE(to_decode_list.empty()) |
409 << "Received packet list is not empty."; | 413 << "Received packet list is not empty."; |
410 } | 414 } |
411 mediaPacketListItem = mediaPacketList.begin(); | 415 media_packet_list_it = media_packet_list.begin(); |
412 mediaPacketIdx = 0; | 416 media_packet_idx = 0; |
413 while (mediaPacketListItem != mediaPacketList.end()) { | 417 while (media_packet_list_it != media_packet_list.end()) { |
414 if (mediaLossMask[mediaPacketIdx] == 1) { | 418 if (media_loss_mask[media_packet_idx] == 1) { |
415 // Should have recovered this packet. | 419 // Should have recovered this packet. |
416 ForwardErrorCorrection::RecoveredPacketList::iterator | 420 auto recovered_packet_list_it = recovered_packet_list.cbegin(); |
417 recoveredPacketListItem = recoveredPacketList.begin(); | 421 |
418 | 422 ASSERT_FALSE(recovered_packet_list_it == |
419 ASSERT_FALSE(recoveredPacketListItem == | 423 recovered_packet_list.end()) |
420 recoveredPacketList.end()) | |
421 << "Insufficient number of recovered packets."; | 424 << "Insufficient number of recovered packets."; |
422 mediaPacket = *mediaPacketListItem; | 425 media_packet = *media_packet_list_it; |
423 ForwardErrorCorrection::RecoveredPacket* recoveredPacket = | 426 ForwardErrorCorrection::RecoveredPacket* recovered_packet = |
424 *recoveredPacketListItem; | 427 *recovered_packet_list_it; |
425 | 428 |
426 ASSERT_EQ(recoveredPacket->pkt->length, mediaPacket->length) | 429 ASSERT_EQ(recovered_packet->pkt->length, media_packet->length) |
427 << "Recovered packet length not identical to original " | 430 << "Recovered packet length not identical to original " |
428 << "media packet"; | 431 << "media packet"; |
429 ASSERT_EQ(0, memcmp(recoveredPacket->pkt->data, | 432 ASSERT_EQ(0, memcmp(recovered_packet->pkt->data, |
430 mediaPacket->data, mediaPacket->length)) | 433 media_packet->data, media_packet->length)) |
431 << "Recovered packet payload not identical to original " | 434 << "Recovered packet payload not identical to original " |
432 << "media packet"; | 435 << "media packet"; |
433 delete recoveredPacket; | 436 delete recovered_packet; |
434 recoveredPacketList.pop_front(); | 437 recovered_packet_list.pop_front(); |
435 } | 438 } |
436 ++mediaPacketIdx; | 439 ++media_packet_idx; |
437 ++mediaPacketListItem; | 440 ++media_packet_list_it; |
438 } | 441 } |
439 fec.ResetState(&recoveredPacketList); | 442 fec.ResetState(&recovered_packet_list); |
440 ASSERT_TRUE(recoveredPacketList.empty()) | 443 ASSERT_TRUE(recovered_packet_list.empty()) |
441 << "Excessive number of recovered packets.\t size is: " | 444 << "Excessive number of recovered packets.\t size is: " |
442 << recoveredPacketList.size(); | 445 << recovered_packet_list.size(); |
443 // -- Teardown -- | 446 // -- Teardown -- |
444 mediaPacketListItem = mediaPacketList.begin(); | 447 media_packet_list_it = media_packet_list.begin(); |
445 while (mediaPacketListItem != mediaPacketList.end()) { | 448 while (media_packet_list_it != media_packet_list.end()) { |
446 delete *mediaPacketListItem; | 449 delete *media_packet_list_it; |
447 ++mediaPacketListItem; | 450 ++media_packet_list_it; |
448 mediaPacketList.pop_front(); | 451 media_packet_list.pop_front(); |
449 } | 452 } |
450 assert(mediaPacketList.empty()); | 453 assert(media_packet_list.empty()); |
451 | 454 |
452 fecPacketListItem = fecPacketList.begin(); | 455 fec_packet_list_it = fec_packet_list.begin(); |
453 while (fecPacketListItem != fecPacketList.end()) { | 456 while (fec_packet_list_it != fec_packet_list.end()) { |
454 ++fecPacketListItem; | 457 ++fec_packet_list_it; |
455 fecPacketList.pop_front(); | 458 fec_packet_list.pop_front(); |
456 } | 459 } |
457 | 460 |
458 // Delete received packets we didn't pass to DecodeFEC(), due to | 461 // Delete received packets we didn't pass to DecodeFEC(), due to |
459 // early frame completion. | 462 // early frame completion. |
460 ForwardErrorCorrection::ReceivedPacketList::iterator | 463 auto received_packet_it = received_packet_list.cbegin(); |
461 receivedPacketIt = receivedPacketList.begin(); | 464 while (received_packet_it != received_packet_list.end()) { |
462 while (receivedPacketIt != receivedPacketList.end()) { | 465 received_packet = *received_packet_it; |
463 receivedPacket = *receivedPacketIt; | 466 delete received_packet; |
464 delete receivedPacket; | 467 ++received_packet_it; |
465 ++receivedPacketIt; | 468 received_packet_list.pop_front(); |
466 receivedPacketList.pop_front(); | 469 } |
467 } | 470 assert(received_packet_list.empty()); |
468 assert(receivedPacketList.empty()); | 471 |
469 | 472 while (!fec_mask_list.empty()) { |
470 while (!fecMaskList.empty()) { | 473 fec_mask_list.pop_front(); |
471 fecMaskList.pop_front(); | 474 } |
472 } | 475 timestamp += 90000 / 30; |
473 timeStamp += 90000 / 30; | 476 } // loop over num_imp_packets |
474 } // loop over numImpPackets | |
475 } // loop over FecPackets | 477 } // loop over FecPackets |
476 } // loop over numMediaPackets | 478 } // loop over num_media_packets |
477 delete[] packetMask; | 479 delete[] packet_mask; |
478 } // loop over loss rates | 480 } // loop over loss rates |
479 } // loop over mask types | 481 } // loop over mask types |
480 | 482 |
481 // Have DecodeFEC free allocated memory. | 483 // Have DecodeFEC free allocated memory. |
482 fec.ResetState(&recoveredPacketList); | 484 fec.ResetState(&recovered_packet_list); |
483 ASSERT_TRUE(recoveredPacketList.empty()) | 485 ASSERT_TRUE(recovered_packet_list.empty()) |
484 << "Recovered packet list is not empty"; | 486 << "Recovered packet list is not empty"; |
485 } | 487 } |
486 | 488 |
487 } // namespace test | 489 } // namespace test |
488 } // namespace webrtc | 490 } // namespace webrtc |
OLD | NEW |