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

Side by Side Diff: webrtc/modules/audio_coding/neteq/packet_buffer_unittest.cc

Issue 2342443005: Moved Opus-specific payload splitting into AudioDecoderOpus. (Closed)
Patch Set: Some small fixes. Created 4 years, 2 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
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 Packet* PacketGenerator::NextPacket(int payload_size_bytes) { 54 Packet* PacketGenerator::NextPacket(int payload_size_bytes) {
55 Packet* packet = new Packet; 55 Packet* packet = new Packet;
56 packet->header.sequenceNumber = seq_no_; 56 packet->header.sequenceNumber = seq_no_;
57 packet->header.timestamp = ts_; 57 packet->header.timestamp = ts_;
58 packet->header.payloadType = pt_; 58 packet->header.payloadType = pt_;
59 packet->header.markerBit = false; 59 packet->header.markerBit = false;
60 packet->header.ssrc = 0x12345678; 60 packet->header.ssrc = 0x12345678;
61 packet->header.numCSRCs = 0; 61 packet->header.numCSRCs = 0;
62 packet->header.paddingLength = 0; 62 packet->header.paddingLength = 0;
63 packet->primary = true;
64 packet->payload.SetSize(payload_size_bytes); 63 packet->payload.SetSize(payload_size_bytes);
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;
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 std::vector<Packet*> expect_order(kExpectPacketsInBuffer); 276 std::vector<Packet*> expect_order(kExpectPacketsInBuffer);
278 277
279 PacketGenerator gen(0, 0, 0, kFrameSize); 278 PacketGenerator gen(0, 0, 0, kFrameSize);
280 279
281 for (int i = 0; i < kPackets; ++i) { 280 for (int i = 0; i < kPackets; ++i) {
282 gen.Reset(packet_facts[i].sequence_number, 281 gen.Reset(packet_facts[i].sequence_number,
283 packet_facts[i].timestamp, 282 packet_facts[i].timestamp,
284 packet_facts[i].payload_type, 283 packet_facts[i].payload_type,
285 kFrameSize); 284 kFrameSize);
286 Packet* packet = gen.NextPacket(kPayloadLength); 285 Packet* packet = gen.NextPacket(kPayloadLength);
287 packet->primary = packet_facts[i].primary; 286 packet->priority.red_level = packet_facts[i].primary ? 0 : 1;
288 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacket(packet)); 287 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacket(packet));
289 if (packet_facts[i].extract_order >= 0) { 288 if (packet_facts[i].extract_order >= 0) {
290 expect_order[packet_facts[i].extract_order] = packet; 289 expect_order[packet_facts[i].extract_order] = packet;
291 } 290 }
292 } 291 }
293 292
294 EXPECT_EQ(kExpectPacketsInBuffer, buffer.NumPacketsInBuffer()); 293 EXPECT_EQ(kExpectPacketsInBuffer, buffer.NumPacketsInBuffer());
295 294
296 size_t drop_count; 295 size_t drop_count;
297 for (size_t i = 0; i < kExpectPacketsInBuffer; ++i) { 296 for (size_t i = 0; i < kExpectPacketsInBuffer; ++i) {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. 504 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list.
506 EXPECT_EQ(1u, buffer->NumPacketsInBuffer()); 505 EXPECT_EQ(1u, buffer->NumPacketsInBuffer());
507 delete buffer; 506 delete buffer;
508 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. 507 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted.
509 } 508 }
510 509
511 // Test packet comparison function. 510 // Test packet comparison function.
512 // The function should return true if the first packet "goes before" the second. 511 // The function should return true if the first packet "goes before" the second.
513 TEST(PacketBuffer, ComparePackets) { 512 TEST(PacketBuffer, ComparePackets) {
514 PacketGenerator gen(0, 0, 0, 10); 513 PacketGenerator gen(0, 0, 0, 10);
515 Packet* a = gen.NextPacket(10); // SN = 0, TS = 0. 514 std::unique_ptr<Packet> a(gen.NextPacket(10)); // SN = 0, TS = 0.
516 Packet* b = gen.NextPacket(10); // SN = 1, TS = 10. 515 std::unique_ptr<Packet> b(gen.NextPacket(10)); // SN = 1, TS = 10.
517 EXPECT_FALSE(*a == *b); 516 EXPECT_FALSE(*a == *b);
518 EXPECT_TRUE(*a != *b); 517 EXPECT_TRUE(*a != *b);
519 EXPECT_TRUE(*a < *b); 518 EXPECT_TRUE(*a < *b);
520 EXPECT_FALSE(*a > *b); 519 EXPECT_FALSE(*a > *b);
521 EXPECT_TRUE(*a <= *b); 520 EXPECT_TRUE(*a <= *b);
522 EXPECT_FALSE(*a >= *b); 521 EXPECT_FALSE(*a >= *b);
523 522
524 // Testing wrap-around case; 'a' is earlier but has a larger timestamp value. 523 // Testing wrap-around case; 'a' is earlier but has a larger timestamp value.
525 a->header.timestamp = 0xFFFFFFFF - 10; 524 a->header.timestamp = 0xFFFFFFFF - 10;
526 EXPECT_FALSE(*a == *b); 525 EXPECT_FALSE(*a == *b);
(...skipping 22 matching lines...) Expand all
549 548
550 // Test equal timestamps but different sequence numbers (32767 and 1). 549 // Test equal timestamps but different sequence numbers (32767 and 1).
551 a->header.sequenceNumber = 0xFFFF; 550 a->header.sequenceNumber = 0xFFFF;
552 EXPECT_FALSE(*a == *b); 551 EXPECT_FALSE(*a == *b);
553 EXPECT_TRUE(*a != *b); 552 EXPECT_TRUE(*a != *b);
554 EXPECT_TRUE(*a < *b); 553 EXPECT_TRUE(*a < *b);
555 EXPECT_FALSE(*a > *b); 554 EXPECT_FALSE(*a > *b);
556 EXPECT_TRUE(*a <= *b); 555 EXPECT_TRUE(*a <= *b);
557 EXPECT_FALSE(*a >= *b); 556 EXPECT_FALSE(*a >= *b);
558 557
559 // Test equal timestamps and sequence numbers, but only 'b' is primary. 558 // Test equal timestamps and sequence numbers, but differing priorities.
560 a->header.sequenceNumber = b->header.sequenceNumber; 559 a->header.sequenceNumber = b->header.sequenceNumber;
561 a->primary = false; 560 a->priority = {1, 0};
562 b->primary = true; 561 b->priority = {0, 0};
562 // a after b
563 EXPECT_FALSE(*a == *b); 563 EXPECT_FALSE(*a == *b);
564 EXPECT_TRUE(*a != *b); 564 EXPECT_TRUE(*a != *b);
565 EXPECT_FALSE(*a < *b); 565 EXPECT_FALSE(*a < *b);
566 EXPECT_TRUE(*a > *b); 566 EXPECT_TRUE(*a > *b);
567 EXPECT_FALSE(*a <= *b); 567 EXPECT_FALSE(*a <= *b);
568 EXPECT_TRUE(*a >= *b); 568 EXPECT_TRUE(*a >= *b);
569 569
570 delete a; 570 std::unique_ptr<Packet> c(gen.NextPacket(0)); // SN = 2, TS = 20.
571 delete b; 571 std::unique_ptr<Packet> d(gen.NextPacket(0)); // SN = 3, TS = 20.
572 c->header.timestamp = b->header.timestamp;
573 d->header.timestamp = b->header.timestamp;
574 c->header.sequenceNumber = b->header.sequenceNumber;
575 d->header.sequenceNumber = b->header.sequenceNumber;
576 c->priority = {1, 1};
577 d->priority = {0, 1};
578 // c after d
579 EXPECT_FALSE(*c == *d);
580 EXPECT_TRUE(*c != *d);
581 EXPECT_FALSE(*c < *d);
582 EXPECT_TRUE(*c > *d);
583 EXPECT_FALSE(*c <= *d);
584 EXPECT_TRUE(*c >= *d);
585
586 // c after a
587 EXPECT_FALSE(*c == *a);
588 EXPECT_TRUE(*c != *a);
589 EXPECT_FALSE(*c < *a);
590 EXPECT_TRUE(*c > *a);
591 EXPECT_FALSE(*c <= *a);
592 EXPECT_TRUE(*c >= *a);
593
594 // c after b
595 EXPECT_FALSE(*c == *b);
596 EXPECT_TRUE(*c != *b);
597 EXPECT_FALSE(*c < *b);
598 EXPECT_TRUE(*c > *b);
599 EXPECT_FALSE(*c <= *b);
600 EXPECT_TRUE(*c >= *b);
601
602 // a after d
603 EXPECT_FALSE(*a == *d);
604 EXPECT_TRUE(*a != *d);
605 EXPECT_FALSE(*a < *d);
606 EXPECT_TRUE(*a > *d);
607 EXPECT_FALSE(*a <= *d);
608 EXPECT_TRUE(*a >= *d);
609
610 // d after b
611 EXPECT_FALSE(*d == *b);
612 EXPECT_TRUE(*d != *b);
613 EXPECT_FALSE(*d < *b);
614 EXPECT_TRUE(*d > *b);
615 EXPECT_FALSE(*d <= *b);
616 EXPECT_TRUE(*d >= *b);
572 } 617 }
573 618
574 // Test the DeleteFirstPacket DeleteAllPackets methods. 619 // Test the DeleteFirstPacket DeleteAllPackets methods.
575 TEST(PacketBuffer, DeleteAllPackets) { 620 TEST(PacketBuffer, DeleteAllPackets) {
576 PacketGenerator gen(0, 0, 0, 10); 621 PacketGenerator gen(0, 0, 0, 10);
577 PacketList list; 622 PacketList list;
578 const int payload_len = 10; 623 const int payload_len = 10;
579 624
580 // Insert 10 small packets. 625 // Insert 10 small packets.
581 for (int i = 0; i < 10; ++i) { 626 for (int i = 0; i < 10; ++i) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 // Test the IsObsoleteTimestamp method with different limit timestamps. 690 // Test the IsObsoleteTimestamp method with different limit timestamps.
646 TEST(PacketBuffer, IsObsoleteTimestamp) { 691 TEST(PacketBuffer, IsObsoleteTimestamp) {
647 TestIsObsoleteTimestamp(0); 692 TestIsObsoleteTimestamp(0);
648 TestIsObsoleteTimestamp(1); 693 TestIsObsoleteTimestamp(1);
649 TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t. 694 TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t.
650 TestIsObsoleteTimestamp(0x80000000); // 2^31. 695 TestIsObsoleteTimestamp(0x80000000); // 2^31.
651 TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1. 696 TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1.
652 TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1. 697 TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1.
653 } 698 }
654 } // namespace webrtc 699 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698