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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 PacketGenerator gen(17u, 4711u, 0, 10); | 90 PacketGenerator gen(17u, 4711u, 0, 10); |
91 | 91 |
92 const int payload_len = 100; | 92 const int payload_len = 100; |
93 Packet* packet = gen.NextPacket(payload_len); | 93 Packet* packet = gen.NextPacket(payload_len); |
94 | 94 |
95 EXPECT_EQ(0, buffer.InsertPacket(packet)); | 95 EXPECT_EQ(0, buffer.InsertPacket(packet)); |
96 uint32_t next_ts; | 96 uint32_t next_ts; |
97 EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&next_ts)); | 97 EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&next_ts)); |
98 EXPECT_EQ(4711u, next_ts); | 98 EXPECT_EQ(4711u, next_ts); |
99 EXPECT_FALSE(buffer.Empty()); | 99 EXPECT_FALSE(buffer.Empty()); |
100 EXPECT_EQ(1, buffer.NumPacketsInBuffer()); | 100 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); |
101 const RTPHeader* hdr = buffer.NextRtpHeader(); | 101 const RTPHeader* hdr = buffer.NextRtpHeader(); |
102 EXPECT_EQ(&(packet->header), hdr); // Compare pointer addresses. | 102 EXPECT_EQ(&(packet->header), hdr); // Compare pointer addresses. |
103 | 103 |
104 // Do not explicitly flush buffer or delete packet to test that it is deleted | 104 // Do not explicitly flush buffer or delete packet to test that it is deleted |
105 // with the buffer. (Tested with Valgrind or similar tool.) | 105 // with the buffer. (Tested with Valgrind or similar tool.) |
106 } | 106 } |
107 | 107 |
108 // Test to flush buffer. | 108 // Test to flush buffer. |
109 TEST(PacketBuffer, FlushBuffer) { | 109 TEST(PacketBuffer, FlushBuffer) { |
110 PacketBuffer buffer(10); // 10 packets. | 110 PacketBuffer buffer(10); // 10 packets. |
111 PacketGenerator gen(0, 0, 0, 10); | 111 PacketGenerator gen(0, 0, 0, 10); |
112 const int payload_len = 10; | 112 const int payload_len = 10; |
113 | 113 |
114 // Insert 10 small packets; should be ok. | 114 // Insert 10 small packets; should be ok. |
115 for (int i = 0; i < 10; ++i) { | 115 for (int i = 0; i < 10; ++i) { |
116 Packet* packet = gen.NextPacket(payload_len); | 116 Packet* packet = gen.NextPacket(payload_len); |
117 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacket(packet)); | 117 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacket(packet)); |
118 } | 118 } |
119 EXPECT_EQ(10, buffer.NumPacketsInBuffer()); | 119 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); |
120 EXPECT_FALSE(buffer.Empty()); | 120 EXPECT_FALSE(buffer.Empty()); |
121 | 121 |
122 buffer.Flush(); | 122 buffer.Flush(); |
123 // Buffer should delete the payloads itself. | 123 // Buffer should delete the payloads itself. |
124 EXPECT_EQ(0, buffer.NumPacketsInBuffer()); | 124 EXPECT_EQ(0u, buffer.NumPacketsInBuffer()); |
125 EXPECT_TRUE(buffer.Empty()); | 125 EXPECT_TRUE(buffer.Empty()); |
126 } | 126 } |
127 | 127 |
128 // Test to fill the buffer over the limits, and verify that it flushes. | 128 // Test to fill the buffer over the limits, and verify that it flushes. |
129 TEST(PacketBuffer, OverfillBuffer) { | 129 TEST(PacketBuffer, OverfillBuffer) { |
130 PacketBuffer buffer(10); // 10 packets. | 130 PacketBuffer buffer(10); // 10 packets. |
131 PacketGenerator gen(0, 0, 0, 10); | 131 PacketGenerator gen(0, 0, 0, 10); |
132 | 132 |
133 // Insert 10 small packets; should be ok. | 133 // Insert 10 small packets; should be ok. |
134 const int payload_len = 10; | 134 const int payload_len = 10; |
135 int i; | 135 int i; |
136 for (i = 0; i < 10; ++i) { | 136 for (i = 0; i < 10; ++i) { |
137 Packet* packet = gen.NextPacket(payload_len); | 137 Packet* packet = gen.NextPacket(payload_len); |
138 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacket(packet)); | 138 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacket(packet)); |
139 } | 139 } |
140 EXPECT_EQ(10, buffer.NumPacketsInBuffer()); | 140 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); |
141 uint32_t next_ts; | 141 uint32_t next_ts; |
142 EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&next_ts)); | 142 EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&next_ts)); |
143 EXPECT_EQ(0u, next_ts); // Expect first inserted packet to be first in line. | 143 EXPECT_EQ(0u, next_ts); // Expect first inserted packet to be first in line. |
144 | 144 |
145 // Insert 11th packet; should flush the buffer and insert it after flushing. | 145 // Insert 11th packet; should flush the buffer and insert it after flushing. |
146 Packet* packet = gen.NextPacket(payload_len); | 146 Packet* packet = gen.NextPacket(payload_len); |
147 EXPECT_EQ(PacketBuffer::kFlushed, buffer.InsertPacket(packet)); | 147 EXPECT_EQ(PacketBuffer::kFlushed, buffer.InsertPacket(packet)); |
148 EXPECT_EQ(1, buffer.NumPacketsInBuffer()); | 148 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); |
149 EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&next_ts)); | 149 EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&next_ts)); |
150 // Expect last inserted packet to be first in line. | 150 // Expect last inserted packet to be first in line. |
151 EXPECT_EQ(packet->header.timestamp, next_ts); | 151 EXPECT_EQ(packet->header.timestamp, next_ts); |
152 | 152 |
153 // Flush buffer to delete all packets. | 153 // Flush buffer to delete all packets. |
154 buffer.Flush(); | 154 buffer.Flush(); |
155 } | 155 } |
156 | 156 |
157 // Test inserting a list of packets. | 157 // Test inserting a list of packets. |
158 TEST(PacketBuffer, InsertPacketList) { | 158 TEST(PacketBuffer, InsertPacketList) { |
(...skipping 13 matching lines...) Expand all Loading... |
172 .WillRepeatedly(Return(false)); | 172 .WillRepeatedly(Return(false)); |
173 EXPECT_CALL(decoder_database, IsDtmf(0)) | 173 EXPECT_CALL(decoder_database, IsDtmf(0)) |
174 .WillRepeatedly(Return(false)); | 174 .WillRepeatedly(Return(false)); |
175 uint8_t current_pt = 0xFF; | 175 uint8_t current_pt = 0xFF; |
176 uint8_t current_cng_pt = 0xFF; | 176 uint8_t current_cng_pt = 0xFF; |
177 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list, | 177 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list, |
178 decoder_database, | 178 decoder_database, |
179 ¤t_pt, | 179 ¤t_pt, |
180 ¤t_cng_pt)); | 180 ¤t_cng_pt)); |
181 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. | 181 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. |
182 EXPECT_EQ(10, buffer.NumPacketsInBuffer()); | 182 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); |
183 EXPECT_EQ(0, current_pt); // Current payload type changed to 0. | 183 EXPECT_EQ(0, current_pt); // Current payload type changed to 0. |
184 EXPECT_EQ(0xFF, current_cng_pt); // CNG payload type not changed. | 184 EXPECT_EQ(0xFF, current_cng_pt); // CNG payload type not changed. |
185 | 185 |
186 buffer.Flush(); // Clean up. | 186 buffer.Flush(); // Clean up. |
187 | 187 |
188 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. | 188 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. |
189 } | 189 } |
190 | 190 |
191 // Test inserting a list of packets. Last packet is of a different payload type. | 191 // Test inserting a list of packets. Last packet is of a different payload type. |
192 // Expecting the buffer to flush. | 192 // Expecting the buffer to flush. |
(...skipping 20 matching lines...) Expand all Loading... |
213 .WillRepeatedly(Return(false)); | 213 .WillRepeatedly(Return(false)); |
214 EXPECT_CALL(decoder_database, IsDtmf(_)) | 214 EXPECT_CALL(decoder_database, IsDtmf(_)) |
215 .WillRepeatedly(Return(false)); | 215 .WillRepeatedly(Return(false)); |
216 uint8_t current_pt = 0xFF; | 216 uint8_t current_pt = 0xFF; |
217 uint8_t current_cng_pt = 0xFF; | 217 uint8_t current_cng_pt = 0xFF; |
218 EXPECT_EQ(PacketBuffer::kFlushed, buffer.InsertPacketList(&list, | 218 EXPECT_EQ(PacketBuffer::kFlushed, buffer.InsertPacketList(&list, |
219 decoder_database, | 219 decoder_database, |
220 ¤t_pt, | 220 ¤t_pt, |
221 ¤t_cng_pt)); | 221 ¤t_cng_pt)); |
222 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. | 222 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. |
223 EXPECT_EQ(1, buffer.NumPacketsInBuffer()); // Only the last packet. | 223 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); // Only the last packet. |
224 EXPECT_EQ(1, current_pt); // Current payload type changed to 0. | 224 EXPECT_EQ(1, current_pt); // Current payload type changed to 0. |
225 EXPECT_EQ(0xFF, current_cng_pt); // CNG payload type not changed. | 225 EXPECT_EQ(0xFF, current_cng_pt); // CNG payload type not changed. |
226 | 226 |
227 buffer.Flush(); // Clean up. | 227 buffer.Flush(); // Clean up. |
228 | 228 |
229 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. | 229 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. |
230 } | 230 } |
231 | 231 |
232 TEST(PacketBuffer, ExtractOrderRedundancy) { | 232 TEST(PacketBuffer, ExtractOrderRedundancy) { |
233 PacketBuffer buffer(100); // 100 packets. | 233 PacketBuffer buffer(100); // 100 packets. |
(...skipping 15 matching lines...) Expand all Loading... |
249 {0x0002, 0xFFFFFFFF, 1, false, -1}, | 249 {0x0002, 0xFFFFFFFF, 1, false, -1}, |
250 {0x0003, 0x0000000A, 1, false, -1}, | 250 {0x0003, 0x0000000A, 1, false, -1}, |
251 {0x0004, 0x0000001E, 0, true, 7}, | 251 {0x0004, 0x0000001E, 0, true, 7}, |
252 {0x0004, 0x00000014, 1, false, 6}, | 252 {0x0004, 0x00000014, 1, false, 6}, |
253 {0x0005, 0x0000001E, 0, true, -1}, | 253 {0x0005, 0x0000001E, 0, true, -1}, |
254 {0x0005, 0x00000014, 1, false, -1}, | 254 {0x0005, 0x00000014, 1, false, -1}, |
255 {0x0006, 0x00000028, 0, true, 8}, | 255 {0x0006, 0x00000028, 0, true, 8}, |
256 {0x0006, 0x0000001E, 1, false, -1}, | 256 {0x0006, 0x0000001E, 1, false, -1}, |
257 }; | 257 }; |
258 | 258 |
259 const int kExpectPacketsInBuffer = 9; | 259 const size_t kExpectPacketsInBuffer = 9; |
260 | 260 |
261 std::vector<Packet*> expect_order(kExpectPacketsInBuffer); | 261 std::vector<Packet*> expect_order(kExpectPacketsInBuffer); |
262 | 262 |
263 PacketGenerator gen(0, 0, 0, kFrameSize); | 263 PacketGenerator gen(0, 0, 0, kFrameSize); |
264 | 264 |
265 for (int i = 0; i < kPackets; ++i) { | 265 for (int i = 0; i < kPackets; ++i) { |
266 gen.Reset(packet_facts[i].sequence_number, | 266 gen.Reset(packet_facts[i].sequence_number, |
267 packet_facts[i].timestamp, | 267 packet_facts[i].timestamp, |
268 packet_facts[i].payload_type, | 268 packet_facts[i].payload_type, |
269 kFrameSize); | 269 kFrameSize); |
270 Packet* packet = gen.NextPacket(kPayloadLength); | 270 Packet* packet = gen.NextPacket(kPayloadLength); |
271 packet->primary = packet_facts[i].primary; | 271 packet->primary = packet_facts[i].primary; |
272 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacket(packet)); | 272 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacket(packet)); |
273 if (packet_facts[i].extract_order >= 0) { | 273 if (packet_facts[i].extract_order >= 0) { |
274 expect_order[packet_facts[i].extract_order] = packet; | 274 expect_order[packet_facts[i].extract_order] = packet; |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
278 EXPECT_EQ(kExpectPacketsInBuffer, buffer.NumPacketsInBuffer()); | 278 EXPECT_EQ(kExpectPacketsInBuffer, buffer.NumPacketsInBuffer()); |
279 | 279 |
280 int drop_count; | 280 size_t drop_count; |
281 for (int i = 0; i < kExpectPacketsInBuffer; ++i) { | 281 for (size_t i = 0; i < kExpectPacketsInBuffer; ++i) { |
282 Packet* packet = buffer.GetNextPacket(&drop_count); | 282 Packet* packet = buffer.GetNextPacket(&drop_count); |
283 EXPECT_EQ(0, drop_count); | 283 EXPECT_EQ(0u, drop_count); |
284 EXPECT_EQ(packet, expect_order[i]); // Compare pointer addresses. | 284 EXPECT_EQ(packet, expect_order[i]); // Compare pointer addresses. |
285 delete[] packet->payload; | 285 delete[] packet->payload; |
286 delete packet; | 286 delete packet; |
287 } | 287 } |
288 EXPECT_TRUE(buffer.Empty()); | 288 EXPECT_TRUE(buffer.Empty()); |
289 } | 289 } |
290 | 290 |
291 TEST(PacketBuffer, DiscardPackets) { | 291 TEST(PacketBuffer, DiscardPackets) { |
292 PacketBuffer buffer(100); // 100 packets. | 292 PacketBuffer buffer(100); // 100 packets. |
293 const uint16_t start_seq_no = 17; | 293 const uint16_t start_seq_no = 17; |
294 const uint32_t start_ts = 4711; | 294 const uint32_t start_ts = 4711; |
295 const uint32_t ts_increment = 10; | 295 const uint32_t ts_increment = 10; |
296 PacketGenerator gen(start_seq_no, start_ts, 0, ts_increment); | 296 PacketGenerator gen(start_seq_no, start_ts, 0, ts_increment); |
297 PacketList list; | 297 PacketList list; |
298 const int payload_len = 10; | 298 const int payload_len = 10; |
299 | 299 |
300 // Insert 10 small packets. | 300 // Insert 10 small packets. |
301 for (int i = 0; i < 10; ++i) { | 301 for (int i = 0; i < 10; ++i) { |
302 Packet* packet = gen.NextPacket(payload_len); | 302 Packet* packet = gen.NextPacket(payload_len); |
303 buffer.InsertPacket(packet); | 303 buffer.InsertPacket(packet); |
304 } | 304 } |
305 EXPECT_EQ(10, buffer.NumPacketsInBuffer()); | 305 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); |
306 | 306 |
307 // Discard them one by one and make sure that the right packets are at the | 307 // Discard them one by one and make sure that the right packets are at the |
308 // front of the buffer. | 308 // front of the buffer. |
309 uint32_t current_ts = start_ts; | 309 uint32_t current_ts = start_ts; |
310 for (int i = 0; i < 10; ++i) { | 310 for (int i = 0; i < 10; ++i) { |
311 uint32_t ts; | 311 uint32_t ts; |
312 EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&ts)); | 312 EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&ts)); |
313 EXPECT_EQ(current_ts, ts); | 313 EXPECT_EQ(current_ts, ts); |
314 EXPECT_EQ(PacketBuffer::kOK, buffer.DiscardNextPacket()); | 314 EXPECT_EQ(PacketBuffer::kOK, buffer.DiscardNextPacket()); |
315 current_ts += ts_increment; | 315 current_ts += ts_increment; |
(...skipping 27 matching lines...) Expand all Loading... |
343 .WillRepeatedly(Return(false)); | 343 .WillRepeatedly(Return(false)); |
344 EXPECT_CALL(decoder_database, IsDtmf(0)) | 344 EXPECT_CALL(decoder_database, IsDtmf(0)) |
345 .WillRepeatedly(Return(false)); | 345 .WillRepeatedly(Return(false)); |
346 uint8_t current_pt = 0xFF; | 346 uint8_t current_pt = 0xFF; |
347 uint8_t current_cng_pt = 0xFF; | 347 uint8_t current_cng_pt = 0xFF; |
348 | 348 |
349 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list, | 349 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list, |
350 decoder_database, | 350 decoder_database, |
351 ¤t_pt, | 351 ¤t_pt, |
352 ¤t_cng_pt)); | 352 ¤t_cng_pt)); |
353 EXPECT_EQ(10, buffer.NumPacketsInBuffer()); | 353 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); |
354 | 354 |
355 // Extract them and make sure that come out in the right order. | 355 // Extract them and make sure that come out in the right order. |
356 uint32_t current_ts = start_ts; | 356 uint32_t current_ts = start_ts; |
357 for (int i = 0; i < 10; ++i) { | 357 for (int i = 0; i < 10; ++i) { |
358 Packet* packet = buffer.GetNextPacket(NULL); | 358 Packet* packet = buffer.GetNextPacket(NULL); |
359 ASSERT_FALSE(packet == NULL); | 359 ASSERT_FALSE(packet == NULL); |
360 EXPECT_EQ(current_ts, packet->header.timestamp); | 360 EXPECT_EQ(current_ts, packet->header.timestamp); |
361 current_ts += ts_increment; | 361 current_ts += ts_increment; |
362 delete [] packet->payload; | 362 delete [] packet->payload; |
363 delete packet; | 363 delete packet; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 EXPECT_CALL(decoder_database, IsDtmf(0)) | 418 EXPECT_CALL(decoder_database, IsDtmf(0)) |
419 .WillRepeatedly(Return(false)); | 419 .WillRepeatedly(Return(false)); |
420 uint8_t current_pt = 0xFF; | 420 uint8_t current_pt = 0xFF; |
421 uint8_t current_cng_pt = 0xFF; | 421 uint8_t current_cng_pt = 0xFF; |
422 EXPECT_EQ(PacketBuffer::kInvalidPacket, | 422 EXPECT_EQ(PacketBuffer::kInvalidPacket, |
423 buffer->InsertPacketList(&list, | 423 buffer->InsertPacketList(&list, |
424 decoder_database, | 424 decoder_database, |
425 ¤t_pt, | 425 ¤t_pt, |
426 ¤t_cng_pt)); | 426 ¤t_cng_pt)); |
427 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. | 427 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. |
428 EXPECT_EQ(1, buffer->NumPacketsInBuffer()); | 428 EXPECT_EQ(1u, buffer->NumPacketsInBuffer()); |
429 delete buffer; | 429 delete buffer; |
430 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. | 430 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. |
431 } | 431 } |
432 | 432 |
433 // Test packet comparison function. | 433 // Test packet comparison function. |
434 // The function should return true if the first packet "goes before" the second. | 434 // The function should return true if the first packet "goes before" the second. |
435 TEST(PacketBuffer, ComparePackets) { | 435 TEST(PacketBuffer, ComparePackets) { |
436 PacketGenerator gen(0, 0, 0, 10); | 436 PacketGenerator gen(0, 0, 0, 10); |
437 Packet* a = gen.NextPacket(10); // SN = 0, TS = 0. | 437 Packet* a = gen.NextPacket(10); // SN = 0, TS = 0. |
438 Packet* b = gen.NextPacket(10); // SN = 1, TS = 10. | 438 Packet* b = gen.NextPacket(10); // SN = 1, TS = 10. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 // Test the IsObsoleteTimestamp method with different limit timestamps. | 569 // Test the IsObsoleteTimestamp method with different limit timestamps. |
570 TEST(PacketBuffer, IsObsoleteTimestamp) { | 570 TEST(PacketBuffer, IsObsoleteTimestamp) { |
571 TestIsObsoleteTimestamp(0); | 571 TestIsObsoleteTimestamp(0); |
572 TestIsObsoleteTimestamp(1); | 572 TestIsObsoleteTimestamp(1); |
573 TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t. | 573 TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t. |
574 TestIsObsoleteTimestamp(0x80000000); // 2^31. | 574 TestIsObsoleteTimestamp(0x80000000); // 2^31. |
575 TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1. | 575 TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1. |
576 TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1. | 576 TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1. |
577 } | 577 } |
578 } // namespace webrtc | 578 } // namespace webrtc |
OLD | NEW |