Chromium Code Reviews| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 | 52 | 
| 53 Packet* PacketGenerator::NextPacket(int payload_size_bytes) { | 53 Packet* PacketGenerator::NextPacket(int payload_size_bytes) { | 
| 54 Packet* packet = new Packet; | 54 Packet* packet = new Packet; | 
| 55 packet->header.sequenceNumber = seq_no_; | 55 packet->header.sequenceNumber = seq_no_; | 
| 56 packet->header.timestamp = ts_; | 56 packet->header.timestamp = ts_; | 
| 57 packet->header.payloadType = pt_; | 57 packet->header.payloadType = pt_; | 
| 58 packet->header.markerBit = false; | 58 packet->header.markerBit = false; | 
| 59 packet->header.ssrc = 0x12345678; | 59 packet->header.ssrc = 0x12345678; | 
| 60 packet->header.numCSRCs = 0; | 60 packet->header.numCSRCs = 0; | 
| 61 packet->header.paddingLength = 0; | 61 packet->header.paddingLength = 0; | 
| 62 packet->payload_length = payload_size_bytes; | |
| 63 packet->primary = true; | 62 packet->primary = true; | 
| 64 packet->payload = new uint8_t[payload_size_bytes]; | 63 packet->payload = rtc::Buffer(payload_size_bytes); | 
| 
 
kwiberg-webrtc
2016/08/30 16:04:36
packet->payload.SetSize(payload_size_bytes);
Also
 
ossu
2016/08/30 16:27:14
Acknowledged.
 
 | |
| 65 ++seq_no_; | 64 ++seq_no_; | 
| 66 ts_ += frame_size_; | 65 ts_ += frame_size_; | 
| 67 return packet; | 66 return packet; | 
| 68 } | 67 } | 
| 69 | 68 | 
| 70 struct PacketsToInsert { | 69 struct PacketsToInsert { | 
| 71 uint16_t sequence_number; | 70 uint16_t sequence_number; | 
| 72 uint32_t timestamp; | 71 uint32_t timestamp; | 
| 73 uint8_t payload_type; | 72 uint8_t payload_type; | 
| 74 bool primary; | 73 bool primary; | 
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 } | 274 } | 
| 276 } | 275 } | 
| 277 | 276 | 
| 278 EXPECT_EQ(kExpectPacketsInBuffer, buffer.NumPacketsInBuffer()); | 277 EXPECT_EQ(kExpectPacketsInBuffer, buffer.NumPacketsInBuffer()); | 
| 279 | 278 | 
| 280 size_t drop_count; | 279 size_t drop_count; | 
| 281 for (size_t i = 0; i < kExpectPacketsInBuffer; ++i) { | 280 for (size_t i = 0; i < kExpectPacketsInBuffer; ++i) { | 
| 282 Packet* packet = buffer.GetNextPacket(&drop_count); | 281 Packet* packet = buffer.GetNextPacket(&drop_count); | 
| 283 EXPECT_EQ(0u, drop_count); | 282 EXPECT_EQ(0u, drop_count); | 
| 284 EXPECT_EQ(packet, expect_order[i]); // Compare pointer addresses. | 283 EXPECT_EQ(packet, expect_order[i]); // Compare pointer addresses. | 
| 285 delete[] packet->payload; | |
| 286 delete packet; | 284 delete packet; | 
| 287 } | 285 } | 
| 288 EXPECT_TRUE(buffer.Empty()); | 286 EXPECT_TRUE(buffer.Empty()); | 
| 289 } | 287 } | 
| 290 | 288 | 
| 291 TEST(PacketBuffer, DiscardPackets) { | 289 TEST(PacketBuffer, DiscardPackets) { | 
| 292 TickTimer tick_timer; | 290 TickTimer tick_timer; | 
| 293 PacketBuffer buffer(100, &tick_timer); // 100 packets. | 291 PacketBuffer buffer(100, &tick_timer); // 100 packets. | 
| 294 const uint16_t start_seq_no = 17; | 292 const uint16_t start_seq_no = 17; | 
| 295 const uint32_t start_ts = 4711; | 293 const uint32_t start_ts = 4711; | 
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 ¤t_cng_pt)); | 348 ¤t_cng_pt)); | 
| 351 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); | 349 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); | 
| 352 | 350 | 
| 353 // Extract them and make sure that come out in the right order. | 351 // Extract them and make sure that come out in the right order. | 
| 354 uint32_t current_ts = start_ts; | 352 uint32_t current_ts = start_ts; | 
| 355 for (int i = 0; i < 10; ++i) { | 353 for (int i = 0; i < 10; ++i) { | 
| 356 Packet* packet = buffer.GetNextPacket(NULL); | 354 Packet* packet = buffer.GetNextPacket(NULL); | 
| 357 ASSERT_FALSE(packet == NULL); | 355 ASSERT_FALSE(packet == NULL); | 
| 358 EXPECT_EQ(current_ts, packet->header.timestamp); | 356 EXPECT_EQ(current_ts, packet->header.timestamp); | 
| 359 current_ts += ts_increment; | 357 current_ts += ts_increment; | 
| 360 delete [] packet->payload; | |
| 361 delete packet; | 358 delete packet; | 
| 362 } | 359 } | 
| 363 EXPECT_TRUE(buffer.Empty()); | 360 EXPECT_TRUE(buffer.Empty()); | 
| 364 | 361 | 
| 365 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. | 362 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. | 
| 366 } | 363 } | 
| 367 | 364 | 
| 368 TEST(PacketBuffer, Failures) { | 365 TEST(PacketBuffer, Failures) { | 
| 369 const uint16_t start_seq_no = 17; | 366 const uint16_t start_seq_no = 17; | 
| 370 const uint32_t start_ts = 4711; | 367 const uint32_t start_ts = 4711; | 
| 371 const uint32_t ts_increment = 10; | 368 const uint32_t ts_increment = 10; | 
| 372 int payload_len = 100; | 369 int payload_len = 100; | 
| 373 PacketGenerator gen(start_seq_no, start_ts, 0, ts_increment); | 370 PacketGenerator gen(start_seq_no, start_ts, 0, ts_increment); | 
| 374 TickTimer tick_timer; | 371 TickTimer tick_timer; | 
| 375 | 372 | 
| 376 PacketBuffer* buffer = new PacketBuffer(100, &tick_timer); // 100 packets. | 373 PacketBuffer* buffer = new PacketBuffer(100, &tick_timer); // 100 packets. | 
| 377 Packet* packet = NULL; | 374 Packet* packet = NULL; | 
| 378 EXPECT_EQ(PacketBuffer::kInvalidPacket, buffer->InsertPacket(packet)); | 375 EXPECT_EQ(PacketBuffer::kInvalidPacket, buffer->InsertPacket(packet)); | 
| 379 packet = gen.NextPacket(payload_len); | 376 packet = gen.NextPacket(payload_len); | 
| 380 delete [] packet->payload; | 377 packet->payload.Clear(); | 
| 381 packet->payload = NULL; | |
| 382 EXPECT_EQ(PacketBuffer::kInvalidPacket, buffer->InsertPacket(packet)); | 378 EXPECT_EQ(PacketBuffer::kInvalidPacket, buffer->InsertPacket(packet)); | 
| 383 // Packet is deleted by the PacketBuffer. | 379 // Packet is deleted by the PacketBuffer. | 
| 384 | 380 | 
| 385 // Buffer should still be empty. Test all empty-checks. | 381 // Buffer should still be empty. Test all empty-checks. | 
| 386 uint32_t temp_ts; | 382 uint32_t temp_ts; | 
| 387 EXPECT_EQ(PacketBuffer::kBufferEmpty, buffer->NextTimestamp(&temp_ts)); | 383 EXPECT_EQ(PacketBuffer::kBufferEmpty, buffer->NextTimestamp(&temp_ts)); | 
| 388 EXPECT_EQ(PacketBuffer::kBufferEmpty, | 384 EXPECT_EQ(PacketBuffer::kBufferEmpty, | 
| 389 buffer->NextHigherTimestamp(0, &temp_ts)); | 385 buffer->NextHigherTimestamp(0, &temp_ts)); | 
| 390 EXPECT_EQ(NULL, buffer->NextRtpHeader()); | 386 EXPECT_EQ(NULL, buffer->NextRtpHeader()); | 
| 391 EXPECT_EQ(NULL, buffer->GetNextPacket(NULL)); | 387 EXPECT_EQ(NULL, buffer->GetNextPacket(NULL)); | 
| 392 EXPECT_EQ(PacketBuffer::kBufferEmpty, buffer->DiscardNextPacket()); | 388 EXPECT_EQ(PacketBuffer::kBufferEmpty, buffer->DiscardNextPacket()); | 
| 393 EXPECT_EQ(0, buffer->DiscardAllOldPackets(0)); // 0 packets discarded. | 389 EXPECT_EQ(0, buffer->DiscardAllOldPackets(0)); // 0 packets discarded. | 
| 394 | 390 | 
| 395 // Insert one packet to make the buffer non-empty. | 391 // Insert one packet to make the buffer non-empty. | 
| 396 packet = gen.NextPacket(payload_len); | 392 packet = gen.NextPacket(payload_len); | 
| 397 EXPECT_EQ(PacketBuffer::kOK, buffer->InsertPacket(packet)); | 393 EXPECT_EQ(PacketBuffer::kOK, buffer->InsertPacket(packet)); | 
| 398 EXPECT_EQ(PacketBuffer::kInvalidPointer, buffer->NextTimestamp(NULL)); | 394 EXPECT_EQ(PacketBuffer::kInvalidPointer, buffer->NextTimestamp(NULL)); | 
| 399 EXPECT_EQ(PacketBuffer::kInvalidPointer, | 395 EXPECT_EQ(PacketBuffer::kInvalidPointer, | 
| 400 buffer->NextHigherTimestamp(0, NULL)); | 396 buffer->NextHigherTimestamp(0, NULL)); | 
| 401 delete buffer; | 397 delete buffer; | 
| 402 | 398 | 
| 403 // Insert packet list of three packets, where the second packet has an invalid | 399 // Insert packet list of three packets, where the second packet has an invalid | 
| 404 // payload. Expect first packet to be inserted, and the remaining two to be | 400 // payload. Expect first packet to be inserted, and the remaining two to be | 
| 405 // discarded. | 401 // discarded. | 
| 406 buffer = new PacketBuffer(100, &tick_timer); // 100 packets. | 402 buffer = new PacketBuffer(100, &tick_timer); // 100 packets. | 
| 407 PacketList list; | 403 PacketList list; | 
| 408 list.push_back(gen.NextPacket(payload_len)); // Valid packet. | 404 list.push_back(gen.NextPacket(payload_len)); // Valid packet. | 
| 409 packet = gen.NextPacket(payload_len); | 405 packet = gen.NextPacket(payload_len); | 
| 410 delete [] packet->payload; | 406 packet->payload.Clear(); // Invalid. | 
| 411 packet->payload = NULL; // Invalid. | |
| 412 list.push_back(packet); | 407 list.push_back(packet); | 
| 413 list.push_back(gen.NextPacket(payload_len)); // Valid packet. | 408 list.push_back(gen.NextPacket(payload_len)); // Valid packet. | 
| 414 MockDecoderDatabase decoder_database; | 409 MockDecoderDatabase decoder_database; | 
| 415 uint8_t current_pt = 0xFF; | 410 uint8_t current_pt = 0xFF; | 
| 416 uint8_t current_cng_pt = 0xFF; | 411 uint8_t current_cng_pt = 0xFF; | 
| 417 EXPECT_EQ(PacketBuffer::kInvalidPacket, | 412 EXPECT_EQ(PacketBuffer::kInvalidPacket, | 
| 418 buffer->InsertPacketList(&list, | 413 buffer->InsertPacketList(&list, | 
| 419 decoder_database, | 414 decoder_database, | 
| 420 ¤t_pt, | 415 ¤t_pt, | 
| 421 ¤t_cng_pt)); | 416 ¤t_cng_pt)); | 
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 477 a->header.sequenceNumber = b->header.sequenceNumber; | 472 a->header.sequenceNumber = b->header.sequenceNumber; | 
| 478 a->primary = false; | 473 a->primary = false; | 
| 479 b->primary = true; | 474 b->primary = true; | 
| 480 EXPECT_FALSE(*a == *b); | 475 EXPECT_FALSE(*a == *b); | 
| 481 EXPECT_TRUE(*a != *b); | 476 EXPECT_TRUE(*a != *b); | 
| 482 EXPECT_FALSE(*a < *b); | 477 EXPECT_FALSE(*a < *b); | 
| 483 EXPECT_TRUE(*a > *b); | 478 EXPECT_TRUE(*a > *b); | 
| 484 EXPECT_FALSE(*a <= *b); | 479 EXPECT_FALSE(*a <= *b); | 
| 485 EXPECT_TRUE(*a >= *b); | 480 EXPECT_TRUE(*a >= *b); | 
| 486 | 481 | 
| 487 delete [] a->payload; | |
| 488 delete a; | 482 delete a; | 
| 489 delete [] b->payload; | |
| 490 delete b; | 483 delete b; | 
| 491 } | 484 } | 
| 492 | 485 | 
| 493 // Test the DeleteFirstPacket DeleteAllPackets methods. | 486 // Test the DeleteFirstPacket DeleteAllPackets methods. | 
| 494 TEST(PacketBuffer, DeleteAllPackets) { | 487 TEST(PacketBuffer, DeleteAllPackets) { | 
| 495 PacketGenerator gen(0, 0, 0, 10); | 488 PacketGenerator gen(0, 0, 0, 10); | 
| 496 PacketList list; | 489 PacketList list; | 
| 497 const int payload_len = 10; | 490 const int payload_len = 10; | 
| 498 | 491 | 
| 499 // Insert 10 small packets. | 492 // Insert 10 small packets. | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 // Test the IsObsoleteTimestamp method with different limit timestamps. | 557 // Test the IsObsoleteTimestamp method with different limit timestamps. | 
| 565 TEST(PacketBuffer, IsObsoleteTimestamp) { | 558 TEST(PacketBuffer, IsObsoleteTimestamp) { | 
| 566 TestIsObsoleteTimestamp(0); | 559 TestIsObsoleteTimestamp(0); | 
| 567 TestIsObsoleteTimestamp(1); | 560 TestIsObsoleteTimestamp(1); | 
| 568 TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t. | 561 TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t. | 
| 569 TestIsObsoleteTimestamp(0x80000000); // 2^31. | 562 TestIsObsoleteTimestamp(0x80000000); // 2^31. | 
| 570 TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1. | 563 TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1. | 
| 571 TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1. | 564 TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1. | 
| 572 } | 565 } | 
| 573 } // namespace webrtc | 566 } // namespace webrtc | 
| OLD | NEW |