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

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

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

Powered by Google App Engine
This is Rietveld 408576698