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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 // |num_payloads|). Each redundant payload is |timestamp_offset| samples | 75 // |num_payloads|). Each redundant payload is |timestamp_offset| samples |
76 // "behind" the the previous payload. | 76 // "behind" the the previous payload. |
77 Packet* CreateRedPayload(size_t num_payloads, | 77 Packet* CreateRedPayload(size_t num_payloads, |
78 uint8_t* payload_types, | 78 uint8_t* payload_types, |
79 int timestamp_offset, | 79 int timestamp_offset, |
80 bool embed_opus_fec = false) { | 80 bool embed_opus_fec = false) { |
81 Packet* packet = new Packet; | 81 Packet* packet = new Packet; |
82 packet->header.payloadType = kRedPayloadType; | 82 packet->header.payloadType = kRedPayloadType; |
83 packet->header.timestamp = kBaseTimestamp; | 83 packet->header.timestamp = kBaseTimestamp; |
84 packet->header.sequenceNumber = kSequenceNumber; | 84 packet->header.sequenceNumber = kSequenceNumber; |
85 packet->payload_length = (kPayloadLength + 1) + | 85 packet->payload.SetSize((kPayloadLength + 1) + |
86 (num_payloads - 1) * (kPayloadLength + kRedHeaderLength); | 86 (num_payloads - 1) * |
87 uint8_t* payload = new uint8_t[packet->payload_length]; | 87 (kPayloadLength + kRedHeaderLength)); |
88 uint8_t* payload_ptr = payload; | 88 uint8_t* payload_ptr = packet->payload.data(); |
89 for (size_t i = 0; i < num_payloads; ++i) { | 89 for (size_t i = 0; i < num_payloads; ++i) { |
90 // Write the RED headers. | 90 // Write the RED headers. |
91 if (i == num_payloads - 1) { | 91 if (i == num_payloads - 1) { |
92 // Special case for last payload. | 92 // Special case for last payload. |
93 *payload_ptr = payload_types[i] & 0x7F; // F = 0; | 93 *payload_ptr = payload_types[i] & 0x7F; // F = 0; |
94 ++payload_ptr; | 94 ++payload_ptr; |
95 break; | 95 break; |
96 } | 96 } |
97 *payload_ptr = payload_types[i] & 0x7F; | 97 *payload_ptr = payload_types[i] & 0x7F; |
98 // Not the last block; set F = 1. | 98 // Not the last block; set F = 1. |
(...skipping 11 matching lines...) Expand all Loading... | |
110 for (size_t i = 0; i < num_payloads; ++i) { | 110 for (size_t i = 0; i < num_payloads; ++i) { |
111 // Write |i| to all bytes in each payload. | 111 // Write |i| to all bytes in each payload. |
112 if (embed_opus_fec) { | 112 if (embed_opus_fec) { |
113 CreateOpusFecPayload(payload_ptr, kPayloadLength, | 113 CreateOpusFecPayload(payload_ptr, kPayloadLength, |
114 static_cast<uint8_t>(i)); | 114 static_cast<uint8_t>(i)); |
115 } else { | 115 } else { |
116 memset(payload_ptr, static_cast<int>(i), kPayloadLength); | 116 memset(payload_ptr, static_cast<int>(i), kPayloadLength); |
117 } | 117 } |
118 payload_ptr += kPayloadLength; | 118 payload_ptr += kPayloadLength; |
119 } | 119 } |
120 packet->payload = payload; | |
121 return packet; | 120 return packet; |
122 } | 121 } |
123 | 122 |
124 // Create a packet with all payload bytes set to |payload_value|. | 123 // Create a packet with all payload bytes set to |payload_value|. |
125 Packet* CreatePacket(uint8_t payload_type, size_t payload_length, | 124 Packet* CreatePacket(uint8_t payload_type, size_t payload_length, |
126 uint8_t payload_value, bool opus_fec = false) { | 125 uint8_t payload_value, bool opus_fec = false) { |
127 Packet* packet = new Packet; | 126 Packet* packet = new Packet; |
128 packet->header.payloadType = payload_type; | 127 packet->header.payloadType = payload_type; |
129 packet->header.timestamp = kBaseTimestamp; | 128 packet->header.timestamp = kBaseTimestamp; |
130 packet->header.sequenceNumber = kSequenceNumber; | 129 packet->header.sequenceNumber = kSequenceNumber; |
131 packet->payload_length = payload_length; | 130 packet->payload.SetSize(payload_length); |
132 uint8_t* payload = new uint8_t[packet->payload_length]; | |
133 packet->payload = payload; | |
134 if (opus_fec) { | 131 if (opus_fec) { |
135 CreateOpusFecPayload(packet->payload, packet->payload_length, | 132 CreateOpusFecPayload(packet->payload.data(), packet->payload.size(), |
136 payload_value); | 133 payload_value); |
137 } else { | 134 } else { |
138 memset(payload, payload_value, payload_length); | 135 memset(packet->payload.data(), payload_value, packet->payload.size()); |
hlundin-webrtc
2016/09/01 14:08:04
I was thinking you could use std::fill, to avoid t
| |
139 } | 136 } |
140 return packet; | 137 return packet; |
141 } | 138 } |
142 | 139 |
143 // Checks that |packet| has the attributes given in the remaining parameters. | 140 // Checks that |packet| has the attributes given in the remaining parameters. |
144 void VerifyPacket(const Packet* packet, | 141 void VerifyPacket(const Packet* packet, |
145 size_t payload_length, | 142 size_t payload_length, |
146 uint8_t payload_type, | 143 uint8_t payload_type, |
147 uint16_t sequence_number, | 144 uint16_t sequence_number, |
148 uint32_t timestamp, | 145 uint32_t timestamp, |
149 uint8_t payload_value, | 146 uint8_t payload_value, |
150 bool primary = true) { | 147 bool primary = true) { |
151 EXPECT_EQ(payload_length, packet->payload_length); | 148 EXPECT_EQ(payload_length, packet->payload.size()); |
152 EXPECT_EQ(payload_type, packet->header.payloadType); | 149 EXPECT_EQ(payload_type, packet->header.payloadType); |
153 EXPECT_EQ(sequence_number, packet->header.sequenceNumber); | 150 EXPECT_EQ(sequence_number, packet->header.sequenceNumber); |
154 EXPECT_EQ(timestamp, packet->header.timestamp); | 151 EXPECT_EQ(timestamp, packet->header.timestamp); |
155 EXPECT_EQ(primary, packet->primary); | 152 EXPECT_EQ(primary, packet->primary); |
156 ASSERT_FALSE(packet->payload == NULL); | 153 ASSERT_FALSE(packet->payload.empty()); |
157 for (size_t i = 0; i < packet->payload_length; ++i) { | 154 for (size_t i = 0; i < packet->payload.size(); ++i) { |
158 EXPECT_EQ(payload_value, packet->payload[i]); | 155 EXPECT_EQ(payload_value, packet->payload[i]); |
159 } | 156 } |
160 } | 157 } |
161 | 158 |
162 // Start of test definitions. | 159 // Start of test definitions. |
163 | 160 |
164 TEST(PayloadSplitter, CreateAndDestroy) { | 161 TEST(PayloadSplitter, CreateAndDestroy) { |
165 PayloadSplitter* splitter = new PayloadSplitter; | 162 PayloadSplitter* splitter = new PayloadSplitter; |
166 delete splitter; | 163 delete splitter; |
167 } | 164 } |
168 | 165 |
169 // Packet A is split into A1 and A2. | 166 // Packet A is split into A1 and A2. |
170 TEST(RedPayloadSplitter, OnePacketTwoPayloads) { | 167 TEST(RedPayloadSplitter, OnePacketTwoPayloads) { |
171 uint8_t payload_types[] = {0, 0}; | 168 uint8_t payload_types[] = {0, 0}; |
172 const int kTimestampOffset = 160; | 169 const int kTimestampOffset = 160; |
173 Packet* packet = CreateRedPayload(2, payload_types, kTimestampOffset); | 170 Packet* packet = CreateRedPayload(2, payload_types, kTimestampOffset); |
174 PacketList packet_list; | 171 PacketList packet_list; |
175 packet_list.push_back(packet); | 172 packet_list.push_back(packet); |
176 PayloadSplitter splitter; | 173 PayloadSplitter splitter; |
177 EXPECT_EQ(PayloadSplitter::kOK, splitter.SplitRed(&packet_list)); | 174 EXPECT_EQ(PayloadSplitter::kOK, splitter.SplitRed(&packet_list)); |
178 ASSERT_EQ(2u, packet_list.size()); | 175 ASSERT_EQ(2u, packet_list.size()); |
179 // Check first packet. The first in list should always be the primary payload. | 176 // Check first packet. The first in list should always be the primary payload. |
180 packet = packet_list.front(); | 177 packet = packet_list.front(); |
181 VerifyPacket(packet, kPayloadLength, payload_types[1], kSequenceNumber, | 178 VerifyPacket(packet, kPayloadLength, payload_types[1], kSequenceNumber, |
182 kBaseTimestamp, 1, true); | 179 kBaseTimestamp, 1, true); |
183 delete [] packet->payload; | |
184 delete packet; | 180 delete packet; |
185 packet_list.pop_front(); | 181 packet_list.pop_front(); |
186 // Check second packet. | 182 // Check second packet. |
187 packet = packet_list.front(); | 183 packet = packet_list.front(); |
188 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber, | 184 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber, |
189 kBaseTimestamp - kTimestampOffset, 0, false); | 185 kBaseTimestamp - kTimestampOffset, 0, false); |
190 delete [] packet->payload; | |
191 delete packet; | 186 delete packet; |
192 } | 187 } |
193 | 188 |
194 // Packets A and B are not split at all. Only the RED header in each packet is | 189 // Packets A and B are not split at all. Only the RED header in each packet is |
195 // removed. | 190 // removed. |
196 TEST(RedPayloadSplitter, TwoPacketsOnePayload) { | 191 TEST(RedPayloadSplitter, TwoPacketsOnePayload) { |
197 uint8_t payload_types[] = {0}; | 192 uint8_t payload_types[] = {0}; |
198 const int kTimestampOffset = 160; | 193 const int kTimestampOffset = 160; |
199 // Create first packet, with a single RED payload. | 194 // Create first packet, with a single RED payload. |
200 Packet* packet = CreateRedPayload(1, payload_types, kTimestampOffset); | 195 Packet* packet = CreateRedPayload(1, payload_types, kTimestampOffset); |
201 PacketList packet_list; | 196 PacketList packet_list; |
202 packet_list.push_back(packet); | 197 packet_list.push_back(packet); |
203 // Create second packet, with a single RED payload. | 198 // Create second packet, with a single RED payload. |
204 packet = CreateRedPayload(1, payload_types, kTimestampOffset); | 199 packet = CreateRedPayload(1, payload_types, kTimestampOffset); |
205 // Manually change timestamp and sequence number of second packet. | 200 // Manually change timestamp and sequence number of second packet. |
206 packet->header.timestamp += kTimestampOffset; | 201 packet->header.timestamp += kTimestampOffset; |
207 packet->header.sequenceNumber++; | 202 packet->header.sequenceNumber++; |
208 packet_list.push_back(packet); | 203 packet_list.push_back(packet); |
209 PayloadSplitter splitter; | 204 PayloadSplitter splitter; |
210 EXPECT_EQ(PayloadSplitter::kOK, splitter.SplitRed(&packet_list)); | 205 EXPECT_EQ(PayloadSplitter::kOK, splitter.SplitRed(&packet_list)); |
211 ASSERT_EQ(2u, packet_list.size()); | 206 ASSERT_EQ(2u, packet_list.size()); |
212 // Check first packet. | 207 // Check first packet. |
213 packet = packet_list.front(); | 208 packet = packet_list.front(); |
214 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber, | 209 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber, |
215 kBaseTimestamp, 0, true); | 210 kBaseTimestamp, 0, true); |
216 delete [] packet->payload; | |
217 delete packet; | 211 delete packet; |
218 packet_list.pop_front(); | 212 packet_list.pop_front(); |
219 // Check second packet. | 213 // Check second packet. |
220 packet = packet_list.front(); | 214 packet = packet_list.front(); |
221 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber + 1, | 215 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber + 1, |
222 kBaseTimestamp + kTimestampOffset, 0, true); | 216 kBaseTimestamp + kTimestampOffset, 0, true); |
223 delete [] packet->payload; | |
224 delete packet; | 217 delete packet; |
225 } | 218 } |
226 | 219 |
227 // Packets A and B are split into packets A1, A2, A3, B1, B2, B3, with | 220 // Packets A and B are split into packets A1, A2, A3, B1, B2, B3, with |
228 // attributes as follows: | 221 // attributes as follows: |
229 // | 222 // |
230 // A1* A2 A3 B1* B2 B3 | 223 // A1* A2 A3 B1* B2 B3 |
231 // Payload type 0 1 2 0 1 2 | 224 // Payload type 0 1 2 0 1 2 |
232 // Timestamp b b-o b-2o b+o b b-o | 225 // Timestamp b b-o b-2o b+o b b-o |
233 // Sequence number 0 0 0 1 1 1 | 226 // Sequence number 0 0 0 1 1 1 |
(...skipping 12 matching lines...) Expand all Loading... | |
246 packet->header.timestamp += kTimestampOffset; | 239 packet->header.timestamp += kTimestampOffset; |
247 packet->header.sequenceNumber++; | 240 packet->header.sequenceNumber++; |
248 packet_list.push_back(packet); | 241 packet_list.push_back(packet); |
249 PayloadSplitter splitter; | 242 PayloadSplitter splitter; |
250 EXPECT_EQ(PayloadSplitter::kOK, splitter.SplitRed(&packet_list)); | 243 EXPECT_EQ(PayloadSplitter::kOK, splitter.SplitRed(&packet_list)); |
251 ASSERT_EQ(6u, packet_list.size()); | 244 ASSERT_EQ(6u, packet_list.size()); |
252 // Check first packet, A1. | 245 // Check first packet, A1. |
253 packet = packet_list.front(); | 246 packet = packet_list.front(); |
254 VerifyPacket(packet, kPayloadLength, payload_types[2], kSequenceNumber, | 247 VerifyPacket(packet, kPayloadLength, payload_types[2], kSequenceNumber, |
255 kBaseTimestamp, 2, true); | 248 kBaseTimestamp, 2, true); |
256 delete [] packet->payload; | |
257 delete packet; | 249 delete packet; |
258 packet_list.pop_front(); | 250 packet_list.pop_front(); |
259 // Check second packet, A2. | 251 // Check second packet, A2. |
260 packet = packet_list.front(); | 252 packet = packet_list.front(); |
261 VerifyPacket(packet, kPayloadLength, payload_types[1], kSequenceNumber, | 253 VerifyPacket(packet, kPayloadLength, payload_types[1], kSequenceNumber, |
262 kBaseTimestamp - kTimestampOffset, 1, false); | 254 kBaseTimestamp - kTimestampOffset, 1, false); |
263 delete [] packet->payload; | |
264 delete packet; | 255 delete packet; |
265 packet_list.pop_front(); | 256 packet_list.pop_front(); |
266 // Check third packet, A3. | 257 // Check third packet, A3. |
267 packet = packet_list.front(); | 258 packet = packet_list.front(); |
268 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber, | 259 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber, |
269 kBaseTimestamp - 2 * kTimestampOffset, 0, false); | 260 kBaseTimestamp - 2 * kTimestampOffset, 0, false); |
270 delete [] packet->payload; | |
271 delete packet; | 261 delete packet; |
272 packet_list.pop_front(); | 262 packet_list.pop_front(); |
273 // Check fourth packet, B1. | 263 // Check fourth packet, B1. |
274 packet = packet_list.front(); | 264 packet = packet_list.front(); |
275 VerifyPacket(packet, kPayloadLength, payload_types[2], kSequenceNumber + 1, | 265 VerifyPacket(packet, kPayloadLength, payload_types[2], kSequenceNumber + 1, |
276 kBaseTimestamp + kTimestampOffset, 2, true); | 266 kBaseTimestamp + kTimestampOffset, 2, true); |
277 delete [] packet->payload; | |
278 delete packet; | 267 delete packet; |
279 packet_list.pop_front(); | 268 packet_list.pop_front(); |
280 // Check fifth packet, B2. | 269 // Check fifth packet, B2. |
281 packet = packet_list.front(); | 270 packet = packet_list.front(); |
282 VerifyPacket(packet, kPayloadLength, payload_types[1], kSequenceNumber + 1, | 271 VerifyPacket(packet, kPayloadLength, payload_types[1], kSequenceNumber + 1, |
283 kBaseTimestamp, 1, false); | 272 kBaseTimestamp, 1, false); |
284 delete [] packet->payload; | |
285 delete packet; | 273 delete packet; |
286 packet_list.pop_front(); | 274 packet_list.pop_front(); |
287 // Check sixth packet, B3. | 275 // Check sixth packet, B3. |
288 packet = packet_list.front(); | 276 packet = packet_list.front(); |
289 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber + 1, | 277 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber + 1, |
290 kBaseTimestamp - kTimestampOffset, 0, false); | 278 kBaseTimestamp - kTimestampOffset, 0, false); |
291 delete [] packet->payload; | |
292 delete packet; | 279 delete packet; |
293 } | 280 } |
294 | 281 |
295 // Creates a list with 4 packets with these payload types: | 282 // Creates a list with 4 packets with these payload types: |
296 // 0 = CNGnb | 283 // 0 = CNGnb |
297 // 1 = PCMu | 284 // 1 = PCMu |
298 // 2 = DTMF (AVT) | 285 // 2 = DTMF (AVT) |
299 // 3 = iLBC | 286 // 3 = iLBC |
300 // We expect the method CheckRedPayloads to discard the iLBC packet, since it | 287 // We expect the method CheckRedPayloads to discard the iLBC packet, since it |
301 // is a non-CNG, non-DTMF payload of another type than the first speech payload | 288 // is a non-CNG, non-DTMF payload of another type than the first speech payload |
(...skipping 18 matching lines...) Expand all Loading... | |
320 | 307 |
321 PayloadSplitter splitter; | 308 PayloadSplitter splitter; |
322 splitter.CheckRedPayloads(&packet_list, decoder_database); | 309 splitter.CheckRedPayloads(&packet_list, decoder_database); |
323 | 310 |
324 ASSERT_EQ(3u, packet_list.size()); // Should have dropped the last packet. | 311 ASSERT_EQ(3u, packet_list.size()); // Should have dropped the last packet. |
325 // Verify packets. The loop verifies that payload types 0, 1, and 2 are in the | 312 // Verify packets. The loop verifies that payload types 0, 1, and 2 are in the |
326 // list. | 313 // list. |
327 for (int i = 0; i <= 2; ++i) { | 314 for (int i = 0; i <= 2; ++i) { |
328 Packet* packet = packet_list.front(); | 315 Packet* packet = packet_list.front(); |
329 VerifyPacket(packet, 10, i, kSequenceNumber, kBaseTimestamp, 0, true); | 316 VerifyPacket(packet, 10, i, kSequenceNumber, kBaseTimestamp, 0, true); |
330 delete [] packet->payload; | |
331 delete packet; | 317 delete packet; |
332 packet_list.pop_front(); | 318 packet_list.pop_front(); |
333 } | 319 } |
334 EXPECT_TRUE(packet_list.empty()); | 320 EXPECT_TRUE(packet_list.empty()); |
335 } | 321 } |
336 | 322 |
337 // Packet A is split into A1, A2 and A3. But the length parameter is off, so | 323 // Packet A is split into A1, A2 and A3. But the length parameter is off, so |
338 // the last payloads should be discarded. | 324 // the last payloads should be discarded. |
339 TEST(RedPayloadSplitter, WrongPayloadLength) { | 325 TEST(RedPayloadSplitter, WrongPayloadLength) { |
340 uint8_t payload_types[] = {0, 0, 0}; | 326 uint8_t payload_types[] = {0, 0, 0}; |
341 const int kTimestampOffset = 160; | 327 const int kTimestampOffset = 160; |
342 Packet* packet = CreateRedPayload(3, payload_types, kTimestampOffset); | 328 Packet* packet = CreateRedPayload(3, payload_types, kTimestampOffset); |
343 // Manually tamper with the payload length of the packet. | 329 // Manually tamper with the payload length of the packet. |
344 // This is one byte too short for the second payload (out of three). | 330 // This is one byte too short for the second payload (out of three). |
345 // We expect only the first payload to be returned. | 331 // We expect only the first payload to be returned. |
346 packet->payload_length -= kPayloadLength + 1; | 332 packet->payload.SetSize(packet->payload.size() - (kPayloadLength + 1)); |
347 PacketList packet_list; | 333 PacketList packet_list; |
348 packet_list.push_back(packet); | 334 packet_list.push_back(packet); |
349 PayloadSplitter splitter; | 335 PayloadSplitter splitter; |
350 EXPECT_EQ(PayloadSplitter::kRedLengthMismatch, | 336 EXPECT_EQ(PayloadSplitter::kRedLengthMismatch, |
351 splitter.SplitRed(&packet_list)); | 337 splitter.SplitRed(&packet_list)); |
352 ASSERT_EQ(1u, packet_list.size()); | 338 ASSERT_EQ(1u, packet_list.size()); |
353 // Check first packet. | 339 // Check first packet. |
354 packet = packet_list.front(); | 340 packet = packet_list.front(); |
355 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber, | 341 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber, |
356 kBaseTimestamp - 2 * kTimestampOffset, 0, false); | 342 kBaseTimestamp - 2 * kTimestampOffset, 0, false); |
357 delete [] packet->payload; | |
358 delete packet; | 343 delete packet; |
359 packet_list.pop_front(); | 344 packet_list.pop_front(); |
360 } | 345 } |
361 | 346 |
362 // Test that iSAC, iSAC-swb, RED, DTMF, CNG, and "Arbitrary" payloads do not | 347 // Test that iSAC, iSAC-swb, RED, DTMF, CNG, and "Arbitrary" payloads do not |
363 // get split. | 348 // get split. |
364 TEST(AudioPayloadSplitter, NonSplittable) { | 349 TEST(AudioPayloadSplitter, NonSplittable) { |
365 // Set up packets with different RTP payload types. The actual values do not | 350 // Set up packets with different RTP payload types. The actual values do not |
366 // matter, since we are mocking the decoder database anyway. | 351 // matter, since we are mocking the decoder database anyway. |
367 PacketList packet_list; | 352 PacketList packet_list; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 EXPECT_EQ(0, splitter.SplitAudio(&packet_list, decoder_database)); | 388 EXPECT_EQ(0, splitter.SplitAudio(&packet_list, decoder_database)); |
404 EXPECT_EQ(6u, packet_list.size()); | 389 EXPECT_EQ(6u, packet_list.size()); |
405 | 390 |
406 // Check that all payloads are intact. | 391 // Check that all payloads are intact. |
407 uint8_t payload_type = 0; | 392 uint8_t payload_type = 0; |
408 PacketList::iterator it = packet_list.begin(); | 393 PacketList::iterator it = packet_list.begin(); |
409 while (it != packet_list.end()) { | 394 while (it != packet_list.end()) { |
410 VerifyPacket((*it), kPayloadLength, payload_type, kSequenceNumber, | 395 VerifyPacket((*it), kPayloadLength, payload_type, kSequenceNumber, |
411 kBaseTimestamp, 10 * payload_type); | 396 kBaseTimestamp, 10 * payload_type); |
412 ++payload_type; | 397 ++payload_type; |
413 delete [] (*it)->payload; | |
414 delete (*it); | 398 delete (*it); |
415 it = packet_list.erase(it); | 399 it = packet_list.erase(it); |
416 } | 400 } |
417 | 401 |
418 // The destructor is called when decoder_database goes out of scope. | 402 // The destructor is called when decoder_database goes out of scope. |
419 EXPECT_CALL(decoder_database, Die()); | 403 EXPECT_CALL(decoder_database, Die()); |
420 } | 404 } |
421 | 405 |
422 // Test unknown payload type. | 406 // Test unknown payload type. |
423 TEST(AudioPayloadSplitter, UnknownPayloadType) { | 407 TEST(AudioPayloadSplitter, UnknownPayloadType) { |
(...skipping 10 matching lines...) Expand all Loading... | |
434 | 418 |
435 PayloadSplitter splitter; | 419 PayloadSplitter splitter; |
436 EXPECT_EQ(PayloadSplitter::kUnknownPayloadType, | 420 EXPECT_EQ(PayloadSplitter::kUnknownPayloadType, |
437 splitter.SplitAudio(&packet_list, decoder_database)); | 421 splitter.SplitAudio(&packet_list, decoder_database)); |
438 EXPECT_EQ(1u, packet_list.size()); | 422 EXPECT_EQ(1u, packet_list.size()); |
439 | 423 |
440 | 424 |
441 // Delete the packets and payloads to avoid having the test leak memory. | 425 // Delete the packets and payloads to avoid having the test leak memory. |
442 PacketList::iterator it = packet_list.begin(); | 426 PacketList::iterator it = packet_list.begin(); |
443 while (it != packet_list.end()) { | 427 while (it != packet_list.end()) { |
444 delete [] (*it)->payload; | |
445 delete (*it); | 428 delete (*it); |
446 it = packet_list.erase(it); | 429 it = packet_list.erase(it); |
447 } | 430 } |
448 | 431 |
449 // The destructor is called when decoder_database goes out of scope. | 432 // The destructor is called when decoder_database goes out of scope. |
450 EXPECT_CALL(decoder_database, Die()); | 433 EXPECT_CALL(decoder_database, Die()); |
451 } | 434 } |
452 | 435 |
453 class SplitBySamplesTest : public ::testing::TestWithParam<NetEqDecoder> { | 436 class SplitBySamplesTest : public ::testing::TestWithParam<NetEqDecoder> { |
454 protected: | 437 protected: |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 EXPECT_EQ(expected_num_packets, packet_list.size()); | 537 EXPECT_EQ(expected_num_packets, packet_list.size()); |
555 | 538 |
556 PacketList::iterator it = packet_list.begin(); | 539 PacketList::iterator it = packet_list.begin(); |
557 int i = 0; | 540 int i = 0; |
558 while (it != packet_list.end()) { | 541 while (it != packet_list.end()) { |
559 size_t length_bytes = expected_size_ms[i] * bytes_per_ms_; | 542 size_t length_bytes = expected_size_ms[i] * bytes_per_ms_; |
560 uint32_t expected_timestamp = kBaseTimestamp + | 543 uint32_t expected_timestamp = kBaseTimestamp + |
561 expected_timestamp_offset_ms[i] * samples_per_ms_; | 544 expected_timestamp_offset_ms[i] * samples_per_ms_; |
562 VerifyPacket((*it), length_bytes, kPayloadType, kSequenceNumber, | 545 VerifyPacket((*it), length_bytes, kPayloadType, kSequenceNumber, |
563 expected_timestamp, expected_payload_value[i]); | 546 expected_timestamp, expected_payload_value[i]); |
564 delete [] (*it)->payload; | |
565 delete (*it); | 547 delete (*it); |
566 it = packet_list.erase(it); | 548 it = packet_list.erase(it); |
567 ++i; | 549 ++i; |
568 } | 550 } |
569 | 551 |
570 // The destructor is called when decoder_database goes out of scope. | 552 // The destructor is called when decoder_database goes out of scope. |
571 EXPECT_CALL(decoder_database, Die()); | 553 EXPECT_CALL(decoder_database, Die()); |
572 } | 554 } |
573 | 555 |
574 INSTANTIATE_TEST_CASE_P( | 556 INSTANTIATE_TEST_CASE_P( |
(...skipping 28 matching lines...) Expand all Loading... | |
603 }; | 585 }; |
604 | 586 |
605 // Test splitting sample-based payloads. | 587 // Test splitting sample-based payloads. |
606 TEST_P(SplitIlbcTest, NumFrames) { | 588 TEST_P(SplitIlbcTest, NumFrames) { |
607 PacketList packet_list; | 589 PacketList packet_list; |
608 static const uint8_t kPayloadType = 17; // Just a random number. | 590 static const uint8_t kPayloadType = 17; // Just a random number. |
609 const int frame_length_samples = frame_length_ms_ * 8; | 591 const int frame_length_samples = frame_length_ms_ * 8; |
610 size_t payload_length_bytes = frame_length_bytes_ * num_frames_; | 592 size_t payload_length_bytes = frame_length_bytes_ * num_frames_; |
611 Packet* packet = CreatePacket(kPayloadType, payload_length_bytes, 0); | 593 Packet* packet = CreatePacket(kPayloadType, payload_length_bytes, 0); |
612 // Fill payload with increasing integers {0, 1, 2, ...}. | 594 // Fill payload with increasing integers {0, 1, 2, ...}. |
613 for (size_t i = 0; i < packet->payload_length; ++i) { | 595 for (size_t i = 0; i < packet->payload.size(); ++i) { |
614 packet->payload[i] = static_cast<uint8_t>(i); | 596 packet->payload[i] = static_cast<uint8_t>(i); |
615 } | 597 } |
616 packet_list.push_back(packet); | 598 packet_list.push_back(packet); |
617 | 599 |
618 MockDecoderDatabase decoder_database; | 600 MockDecoderDatabase decoder_database; |
619 // Tell the mock decoder database to return DecoderInfo structs with different | 601 // Tell the mock decoder database to return DecoderInfo structs with different |
620 // codec types. | 602 // codec types. |
621 // Use scoped pointers to avoid having to delete them later. | 603 // Use scoped pointers to avoid having to delete them later. |
622 std::unique_ptr<DecoderDatabase::DecoderInfo> info( | 604 std::unique_ptr<DecoderDatabase::DecoderInfo> info( |
623 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderILBC, "")); | 605 new DecoderDatabase::DecoderInfo(NetEqDecoder::kDecoderILBC, "")); |
624 EXPECT_CALL(decoder_database, GetDecoderInfo(kPayloadType)) | 606 EXPECT_CALL(decoder_database, GetDecoderInfo(kPayloadType)) |
625 .WillRepeatedly(Return(info.get())); | 607 .WillRepeatedly(Return(info.get())); |
626 | 608 |
627 PayloadSplitter splitter; | 609 PayloadSplitter splitter; |
628 EXPECT_EQ(0, splitter.SplitAudio(&packet_list, decoder_database)); | 610 EXPECT_EQ(0, splitter.SplitAudio(&packet_list, decoder_database)); |
629 EXPECT_EQ(num_frames_, packet_list.size()); | 611 EXPECT_EQ(num_frames_, packet_list.size()); |
630 | 612 |
631 PacketList::iterator it = packet_list.begin(); | 613 PacketList::iterator it = packet_list.begin(); |
632 int frame_num = 0; | 614 int frame_num = 0; |
633 uint8_t payload_value = 0; | 615 uint8_t payload_value = 0; |
634 while (it != packet_list.end()) { | 616 while (it != packet_list.end()) { |
635 Packet* packet = (*it); | 617 Packet* packet = (*it); |
636 EXPECT_EQ(kBaseTimestamp + frame_length_samples * frame_num, | 618 EXPECT_EQ(kBaseTimestamp + frame_length_samples * frame_num, |
637 packet->header.timestamp); | 619 packet->header.timestamp); |
638 EXPECT_EQ(frame_length_bytes_, packet->payload_length); | 620 EXPECT_EQ(frame_length_bytes_, packet->payload.size()); |
639 EXPECT_EQ(kPayloadType, packet->header.payloadType); | 621 EXPECT_EQ(kPayloadType, packet->header.payloadType); |
640 EXPECT_EQ(kSequenceNumber, packet->header.sequenceNumber); | 622 EXPECT_EQ(kSequenceNumber, packet->header.sequenceNumber); |
641 EXPECT_EQ(true, packet->primary); | 623 EXPECT_EQ(true, packet->primary); |
642 ASSERT_FALSE(packet->payload == NULL); | 624 ASSERT_FALSE(packet->payload.empty()); |
643 for (size_t i = 0; i < packet->payload_length; ++i) { | 625 for (size_t i = 0; i < packet->payload.size(); ++i) { |
644 EXPECT_EQ(payload_value, packet->payload[i]); | 626 EXPECT_EQ(payload_value, packet->payload[i]); |
645 ++payload_value; | 627 ++payload_value; |
646 } | 628 } |
647 delete [] (*it)->payload; | |
648 delete (*it); | 629 delete (*it); |
649 it = packet_list.erase(it); | 630 it = packet_list.erase(it); |
650 ++frame_num; | 631 ++frame_num; |
651 } | 632 } |
652 | 633 |
653 // The destructor is called when decoder_database goes out of scope. | 634 // The destructor is called when decoder_database goes out of scope. |
654 EXPECT_CALL(decoder_database, Die()); | 635 EXPECT_CALL(decoder_database, Die()); |
655 } | 636 } |
656 | 637 |
657 // Test 1 through 5 frames of 20 and 30 ms size. | 638 // Test 1 through 5 frames of 20 and 30 ms size. |
(...skipping 30 matching lines...) Expand all Loading... | |
688 .WillRepeatedly(Return(info.get())); | 669 .WillRepeatedly(Return(info.get())); |
689 | 670 |
690 PayloadSplitter splitter; | 671 PayloadSplitter splitter; |
691 EXPECT_EQ(PayloadSplitter::kTooLargePayload, | 672 EXPECT_EQ(PayloadSplitter::kTooLargePayload, |
692 splitter.SplitAudio(&packet_list, decoder_database)); | 673 splitter.SplitAudio(&packet_list, decoder_database)); |
693 EXPECT_EQ(1u, packet_list.size()); | 674 EXPECT_EQ(1u, packet_list.size()); |
694 | 675 |
695 // Delete the packets and payloads to avoid having the test leak memory. | 676 // Delete the packets and payloads to avoid having the test leak memory. |
696 PacketList::iterator it = packet_list.begin(); | 677 PacketList::iterator it = packet_list.begin(); |
697 while (it != packet_list.end()) { | 678 while (it != packet_list.end()) { |
698 delete [] (*it)->payload; | |
699 delete (*it); | 679 delete (*it); |
700 it = packet_list.erase(it); | 680 it = packet_list.erase(it); |
701 } | 681 } |
702 | 682 |
703 // The destructor is called when decoder_database goes out of scope. | 683 // The destructor is called when decoder_database goes out of scope. |
704 EXPECT_CALL(decoder_database, Die()); | 684 EXPECT_CALL(decoder_database, Die()); |
705 } | 685 } |
706 | 686 |
707 // Payload not an integer number of frames. | 687 // Payload not an integer number of frames. |
708 TEST(IlbcPayloadSplitter, UnevenPayload) { | 688 TEST(IlbcPayloadSplitter, UnevenPayload) { |
(...skipping 10 matching lines...) Expand all Loading... | |
719 .WillRepeatedly(Return(info.get())); | 699 .WillRepeatedly(Return(info.get())); |
720 | 700 |
721 PayloadSplitter splitter; | 701 PayloadSplitter splitter; |
722 EXPECT_EQ(PayloadSplitter::kFrameSplitError, | 702 EXPECT_EQ(PayloadSplitter::kFrameSplitError, |
723 splitter.SplitAudio(&packet_list, decoder_database)); | 703 splitter.SplitAudio(&packet_list, decoder_database)); |
724 EXPECT_EQ(1u, packet_list.size()); | 704 EXPECT_EQ(1u, packet_list.size()); |
725 | 705 |
726 // Delete the packets and payloads to avoid having the test leak memory. | 706 // Delete the packets and payloads to avoid having the test leak memory. |
727 PacketList::iterator it = packet_list.begin(); | 707 PacketList::iterator it = packet_list.begin(); |
728 while (it != packet_list.end()) { | 708 while (it != packet_list.end()) { |
729 delete [] (*it)->payload; | |
730 delete (*it); | 709 delete (*it); |
731 it = packet_list.erase(it); | 710 it = packet_list.erase(it); |
732 } | 711 } |
733 | 712 |
734 // The destructor is called when decoder_database goes out of scope. | 713 // The destructor is called when decoder_database goes out of scope. |
735 EXPECT_CALL(decoder_database, Die()); | 714 EXPECT_CALL(decoder_database, Die()); |
736 } | 715 } |
737 | 716 |
738 TEST(FecPayloadSplitter, MixedPayload) { | 717 TEST(FecPayloadSplitter, MixedPayload) { |
739 PacketList packet_list; | 718 PacketList packet_list; |
(...skipping 13 matching lines...) Expand all Loading... | |
753 | 732 |
754 PayloadSplitter splitter; | 733 PayloadSplitter splitter; |
755 EXPECT_EQ(PayloadSplitter::kOK, | 734 EXPECT_EQ(PayloadSplitter::kOK, |
756 splitter.SplitFec(&packet_list, &decoder_database)); | 735 splitter.SplitFec(&packet_list, &decoder_database)); |
757 EXPECT_EQ(4u, packet_list.size()); | 736 EXPECT_EQ(4u, packet_list.size()); |
758 | 737 |
759 // Check first packet. | 738 // Check first packet. |
760 packet = packet_list.front(); | 739 packet = packet_list.front(); |
761 EXPECT_EQ(0, packet->header.payloadType); | 740 EXPECT_EQ(0, packet->header.payloadType); |
762 EXPECT_EQ(kBaseTimestamp - 20 * 48, packet->header.timestamp); | 741 EXPECT_EQ(kBaseTimestamp - 20 * 48, packet->header.timestamp); |
763 EXPECT_EQ(10U, packet->payload_length); | 742 EXPECT_EQ(10U, packet->payload.size()); |
764 EXPECT_FALSE(packet->primary); | 743 EXPECT_FALSE(packet->primary); |
765 delete [] packet->payload; | |
766 delete packet; | 744 delete packet; |
767 packet_list.pop_front(); | 745 packet_list.pop_front(); |
768 | 746 |
769 // Check second packet. | 747 // Check second packet. |
770 packet = packet_list.front(); | 748 packet = packet_list.front(); |
771 EXPECT_EQ(0, packet->header.payloadType); | 749 EXPECT_EQ(0, packet->header.payloadType); |
772 EXPECT_EQ(kBaseTimestamp, packet->header.timestamp); | 750 EXPECT_EQ(kBaseTimestamp, packet->header.timestamp); |
773 EXPECT_EQ(10U, packet->payload_length); | 751 EXPECT_EQ(10U, packet->payload.size()); |
774 EXPECT_TRUE(packet->primary); | 752 EXPECT_TRUE(packet->primary); |
775 delete [] packet->payload; | |
776 delete packet; | 753 delete packet; |
777 packet_list.pop_front(); | 754 packet_list.pop_front(); |
778 | 755 |
779 // Check third packet. | 756 // Check third packet. |
780 packet = packet_list.front(); | 757 packet = packet_list.front(); |
781 VerifyPacket(packet, 10, 0, kSequenceNumber, kBaseTimestamp, 0, true); | 758 VerifyPacket(packet, 10, 0, kSequenceNumber, kBaseTimestamp, 0, true); |
782 delete [] packet->payload; | |
783 delete packet; | 759 delete packet; |
784 packet_list.pop_front(); | 760 packet_list.pop_front(); |
785 | 761 |
786 // Check fourth packet. | 762 // Check fourth packet. |
787 packet = packet_list.front(); | 763 packet = packet_list.front(); |
788 VerifyPacket(packet, 10, 1, kSequenceNumber, kBaseTimestamp, 0, true); | 764 VerifyPacket(packet, 10, 1, kSequenceNumber, kBaseTimestamp, 0, true); |
789 delete [] packet->payload; | |
790 delete packet; | 765 delete packet; |
791 } | 766 } |
792 | 767 |
793 TEST(FecPayloadSplitter, EmbedFecInRed) { | 768 TEST(FecPayloadSplitter, EmbedFecInRed) { |
794 PacketList packet_list; | 769 PacketList packet_list; |
795 DecoderDatabase decoder_database(CreateBuiltinAudioDecoderFactory()); | 770 DecoderDatabase decoder_database(CreateBuiltinAudioDecoderFactory()); |
796 | 771 |
797 const int kTimestampOffset = 20 * 48; // 20 ms * 48 kHz. | 772 const int kTimestampOffset = 20 * 48; // 20 ms * 48 kHz. |
798 uint8_t payload_types[] = {0, 0}; | 773 uint8_t payload_types[] = {0, 0}; |
799 decoder_database.RegisterPayload(0, NetEqDecoder::kDecoderOpus, "opus"); | 774 decoder_database.RegisterPayload(0, NetEqDecoder::kDecoderOpus, "opus"); |
800 Packet* packet = CreateRedPayload(2, payload_types, kTimestampOffset, true); | 775 Packet* packet = CreateRedPayload(2, payload_types, kTimestampOffset, true); |
801 packet_list.push_back(packet); | 776 packet_list.push_back(packet); |
802 | 777 |
803 PayloadSplitter splitter; | 778 PayloadSplitter splitter; |
804 EXPECT_EQ(PayloadSplitter::kOK, | 779 EXPECT_EQ(PayloadSplitter::kOK, |
805 splitter.SplitRed(&packet_list)); | 780 splitter.SplitRed(&packet_list)); |
806 EXPECT_EQ(PayloadSplitter::kOK, | 781 EXPECT_EQ(PayloadSplitter::kOK, |
807 splitter.SplitFec(&packet_list, &decoder_database)); | 782 splitter.SplitFec(&packet_list, &decoder_database)); |
808 | 783 |
809 EXPECT_EQ(4u, packet_list.size()); | 784 EXPECT_EQ(4u, packet_list.size()); |
810 | 785 |
811 // Check first packet. FEC packet copied from primary payload in RED. | 786 // Check first packet. FEC packet copied from primary payload in RED. |
812 packet = packet_list.front(); | 787 packet = packet_list.front(); |
813 EXPECT_EQ(0, packet->header.payloadType); | 788 EXPECT_EQ(0, packet->header.payloadType); |
814 EXPECT_EQ(kBaseTimestamp - kTimestampOffset, packet->header.timestamp); | 789 EXPECT_EQ(kBaseTimestamp - kTimestampOffset, packet->header.timestamp); |
815 EXPECT_EQ(kPayloadLength, packet->payload_length); | 790 EXPECT_EQ(kPayloadLength, packet->payload.size()); |
816 EXPECT_FALSE(packet->primary); | 791 EXPECT_FALSE(packet->primary); |
817 EXPECT_EQ(packet->payload[3], 1); | 792 EXPECT_EQ(packet->payload[3], 1); |
818 delete [] packet->payload; | |
819 delete packet; | 793 delete packet; |
820 packet_list.pop_front(); | 794 packet_list.pop_front(); |
821 | 795 |
822 // Check second packet. Normal packet copied from primary payload in RED. | 796 // Check second packet. Normal packet copied from primary payload in RED. |
823 packet = packet_list.front(); | 797 packet = packet_list.front(); |
824 EXPECT_EQ(0, packet->header.payloadType); | 798 EXPECT_EQ(0, packet->header.payloadType); |
825 EXPECT_EQ(kBaseTimestamp, packet->header.timestamp); | 799 EXPECT_EQ(kBaseTimestamp, packet->header.timestamp); |
826 EXPECT_EQ(kPayloadLength, packet->payload_length); | 800 EXPECT_EQ(kPayloadLength, packet->payload.size()); |
827 EXPECT_TRUE(packet->primary); | 801 EXPECT_TRUE(packet->primary); |
828 EXPECT_EQ(packet->payload[3], 1); | 802 EXPECT_EQ(packet->payload[3], 1); |
829 delete [] packet->payload; | |
830 delete packet; | 803 delete packet; |
831 packet_list.pop_front(); | 804 packet_list.pop_front(); |
832 | 805 |
833 // Check third packet. FEC packet copied from secondary payload in RED. | 806 // Check third packet. FEC packet copied from secondary payload in RED. |
834 packet = packet_list.front(); | 807 packet = packet_list.front(); |
835 EXPECT_EQ(0, packet->header.payloadType); | 808 EXPECT_EQ(0, packet->header.payloadType); |
836 EXPECT_EQ(kBaseTimestamp - 2 * kTimestampOffset, packet->header.timestamp); | 809 EXPECT_EQ(kBaseTimestamp - 2 * kTimestampOffset, packet->header.timestamp); |
837 EXPECT_EQ(kPayloadLength, packet->payload_length); | 810 EXPECT_EQ(kPayloadLength, packet->payload.size()); |
838 EXPECT_FALSE(packet->primary); | 811 EXPECT_FALSE(packet->primary); |
839 EXPECT_EQ(packet->payload[3], 0); | 812 EXPECT_EQ(packet->payload[3], 0); |
840 delete [] packet->payload; | |
841 delete packet; | 813 delete packet; |
842 packet_list.pop_front(); | 814 packet_list.pop_front(); |
843 | 815 |
844 // Check fourth packet. Normal packet copied from primary payload in RED. | 816 // Check fourth packet. Normal packet copied from primary payload in RED. |
845 packet = packet_list.front(); | 817 packet = packet_list.front(); |
846 EXPECT_EQ(0, packet->header.payloadType); | 818 EXPECT_EQ(0, packet->header.payloadType); |
847 EXPECT_EQ(kBaseTimestamp - kTimestampOffset, packet->header.timestamp); | 819 EXPECT_EQ(kBaseTimestamp - kTimestampOffset, packet->header.timestamp); |
848 EXPECT_EQ(kPayloadLength, packet->payload_length); | 820 EXPECT_EQ(kPayloadLength, packet->payload.size()); |
849 EXPECT_TRUE(packet->primary); | 821 EXPECT_TRUE(packet->primary); |
850 EXPECT_EQ(packet->payload[3], 0); | 822 EXPECT_EQ(packet->payload[3], 0); |
851 delete [] packet->payload; | |
852 delete packet; | 823 delete packet; |
853 packet_list.pop_front(); | 824 packet_list.pop_front(); |
854 } | 825 } |
855 | 826 |
856 } // namespace webrtc | 827 } // namespace webrtc |
OLD | NEW |