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

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

Issue 1228843002: Update audio code to use size_t more correctly, (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Review comments Created 5 years, 4 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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 WebRtcRTPHeader rtp_header; 377 WebRtcRTPHeader rtp_header;
378 rtp_header.header.payloadType = kPayloadType; 378 rtp_header.header.payloadType = kPayloadType;
379 rtp_header.header.sequenceNumber = 0x1234; 379 rtp_header.header.sequenceNumber = 0x1234;
380 rtp_header.header.timestamp = 0x12345678; 380 rtp_header.header.timestamp = 0x12345678;
381 rtp_header.header.ssrc = 0x87654321; 381 rtp_header.header.ssrc = 0x87654321;
382 382
383 EXPECT_EQ(NetEq::kOK, 383 EXPECT_EQ(NetEq::kOK,
384 neteq_->RegisterPayloadType(kDecoderPCM16B, kPayloadType)); 384 neteq_->RegisterPayloadType(kDecoderPCM16B, kPayloadType));
385 385
386 // Insert packets. The buffer should not flush. 386 // Insert packets. The buffer should not flush.
387 for (int i = 1; i <= config_.max_packets_in_buffer; ++i) { 387 for (size_t i = 1; i <= config_.max_packets_in_buffer; ++i) {
388 EXPECT_EQ(NetEq::kOK, 388 EXPECT_EQ(NetEq::kOK,
389 neteq_->InsertPacket( 389 neteq_->InsertPacket(
390 rtp_header, payload, kPayloadLengthBytes, kReceiveTime)); 390 rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
391 rtp_header.header.timestamp += kPayloadLengthSamples; 391 rtp_header.header.timestamp += kPayloadLengthSamples;
392 rtp_header.header.sequenceNumber += 1; 392 rtp_header.header.sequenceNumber += 1;
393 EXPECT_EQ(i, packet_buffer_->NumPacketsInBuffer()); 393 EXPECT_EQ(i, packet_buffer_->NumPacketsInBuffer());
394 } 394 }
395 395
396 // Insert one more packet and make sure the buffer got flushed. That is, it 396 // Insert one more packet and make sure the buffer got flushed. That is, it
397 // should only hold one single packet. 397 // should only hold one single packet.
398 EXPECT_EQ(NetEq::kOK, 398 EXPECT_EQ(NetEq::kOK,
399 neteq_->InsertPacket( 399 neteq_->InsertPacket(
400 rtp_header, payload, kPayloadLengthBytes, kReceiveTime)); 400 rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
401 EXPECT_EQ(1, packet_buffer_->NumPacketsInBuffer()); 401 EXPECT_EQ(1u, packet_buffer_->NumPacketsInBuffer());
402 const RTPHeader* test_header = packet_buffer_->NextRtpHeader(); 402 const RTPHeader* test_header = packet_buffer_->NextRtpHeader();
403 EXPECT_EQ(rtp_header.header.timestamp, test_header->timestamp); 403 EXPECT_EQ(rtp_header.header.timestamp, test_header->timestamp);
404 EXPECT_EQ(rtp_header.header.sequenceNumber, test_header->sequenceNumber); 404 EXPECT_EQ(rtp_header.header.sequenceNumber, test_header->sequenceNumber);
405 } 405 }
406 406
407 // This test verifies that timestamps propagate from the incoming packets 407 // This test verifies that timestamps propagate from the incoming packets
408 // through to the sync buffer and to the playout timestamp. 408 // through to the sync buffer and to the playout timestamp.
409 TEST_F(NetEqImplTest, VerifyTimestampPropagation) { 409 TEST_F(NetEqImplTest, VerifyTimestampPropagation) {
410 UseNoMocks(); 410 UseNoMocks();
411 CreateInstance(); 411 CreateInstance();
412 412
413 const uint8_t kPayloadType = 17; // Just an arbitrary number. 413 const uint8_t kPayloadType = 17; // Just an arbitrary number.
414 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test. 414 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test.
415 const int kSampleRateHz = 8000; 415 const int kSampleRateHz = 8000;
416 const int kPayloadLengthSamples = 10 * kSampleRateHz / 1000; // 10 ms. 416 const size_t kPayloadLengthSamples =
417 static_cast<size_t>(10 * kSampleRateHz / 1000); // 10 ms.
417 const size_t kPayloadLengthBytes = kPayloadLengthSamples; 418 const size_t kPayloadLengthBytes = kPayloadLengthSamples;
418 uint8_t payload[kPayloadLengthBytes] = {0}; 419 uint8_t payload[kPayloadLengthBytes] = {0};
419 WebRtcRTPHeader rtp_header; 420 WebRtcRTPHeader rtp_header;
420 rtp_header.header.payloadType = kPayloadType; 421 rtp_header.header.payloadType = kPayloadType;
421 rtp_header.header.sequenceNumber = 0x1234; 422 rtp_header.header.sequenceNumber = 0x1234;
422 rtp_header.header.timestamp = 0x12345678; 423 rtp_header.header.timestamp = 0x12345678;
423 rtp_header.header.ssrc = 0x87654321; 424 rtp_header.header.ssrc = 0x87654321;
424 425
425 // This is a dummy decoder that produces as many output samples as the input 426 // This is a dummy decoder that produces as many output samples as the input
426 // has bytes. The output is an increasing series, starting at 1 for the first 427 // has bytes. The output is an increasing series, starting at 1 for the first
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 EXPECT_EQ(NetEq::kOK, 460 EXPECT_EQ(NetEq::kOK,
460 neteq_->RegisterExternalDecoder(&decoder_, kDecoderPCM16B, 461 neteq_->RegisterExternalDecoder(&decoder_, kDecoderPCM16B,
461 kPayloadType, kSampleRateHz)); 462 kPayloadType, kSampleRateHz));
462 463
463 // Insert one packet. 464 // Insert one packet.
464 EXPECT_EQ(NetEq::kOK, 465 EXPECT_EQ(NetEq::kOK,
465 neteq_->InsertPacket( 466 neteq_->InsertPacket(
466 rtp_header, payload, kPayloadLengthBytes, kReceiveTime)); 467 rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
467 468
468 // Pull audio once. 469 // Pull audio once.
469 const int kMaxOutputSize = 10 * kSampleRateHz / 1000; 470 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000);
470 int16_t output[kMaxOutputSize]; 471 int16_t output[kMaxOutputSize];
471 int samples_per_channel; 472 size_t samples_per_channel;
472 int num_channels; 473 int num_channels;
473 NetEqOutputType type; 474 NetEqOutputType type;
474 EXPECT_EQ( 475 EXPECT_EQ(
475 NetEq::kOK, 476 NetEq::kOK,
476 neteq_->GetAudio( 477 neteq_->GetAudio(
477 kMaxOutputSize, output, &samples_per_channel, &num_channels, &type)); 478 kMaxOutputSize, output, &samples_per_channel, &num_channels, &type));
478 ASSERT_EQ(kMaxOutputSize, samples_per_channel); 479 ASSERT_EQ(kMaxOutputSize, samples_per_channel);
479 EXPECT_EQ(1, num_channels); 480 EXPECT_EQ(1, num_channels);
480 EXPECT_EQ(kOutputNormal, type); 481 EXPECT_EQ(kOutputNormal, type);
481 482
482 // Start with a simple check that the fake decoder is behaving as expected. 483 // Start with a simple check that the fake decoder is behaving as expected.
483 EXPECT_EQ(kPayloadLengthSamples, decoder_.next_value() - 1); 484 EXPECT_EQ(kPayloadLengthSamples,
485 static_cast<size_t>(decoder_.next_value() - 1));
484 486
485 // The value of the last of the output samples is the same as the number of 487 // The value of the last of the output samples is the same as the number of
486 // samples played from the decoded packet. Thus, this number + the RTP 488 // samples played from the decoded packet. Thus, this number + the RTP
487 // timestamp should match the playout timestamp. 489 // timestamp should match the playout timestamp.
488 uint32_t timestamp = 0; 490 uint32_t timestamp = 0;
489 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp)); 491 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp));
490 EXPECT_EQ(rtp_header.header.timestamp + output[samples_per_channel - 1], 492 EXPECT_EQ(rtp_header.header.timestamp + output[samples_per_channel - 1],
491 timestamp); 493 timestamp);
492 494
493 // Check the timestamp for the last value in the sync buffer. This should 495 // Check the timestamp for the last value in the sync buffer. This should
494 // be one full frame length ahead of the RTP timestamp. 496 // be one full frame length ahead of the RTP timestamp.
495 const SyncBuffer* sync_buffer = neteq_->sync_buffer_for_test(); 497 const SyncBuffer* sync_buffer = neteq_->sync_buffer_for_test();
496 ASSERT_TRUE(sync_buffer != NULL); 498 ASSERT_TRUE(sync_buffer != NULL);
497 EXPECT_EQ(rtp_header.header.timestamp + kPayloadLengthSamples, 499 EXPECT_EQ(rtp_header.header.timestamp + kPayloadLengthSamples,
498 sync_buffer->end_timestamp()); 500 sync_buffer->end_timestamp());
499 501
500 // Check that the number of samples still to play from the sync buffer add 502 // Check that the number of samples still to play from the sync buffer add
501 // up with what was already played out. 503 // up with what was already played out.
502 EXPECT_EQ(kPayloadLengthSamples - output[samples_per_channel - 1], 504 EXPECT_EQ(kPayloadLengthSamples - output[samples_per_channel - 1],
503 static_cast<int>(sync_buffer->FutureLength())); 505 sync_buffer->FutureLength());
504 } 506 }
505 507
506 TEST_F(NetEqImplTest, ReorderedPacket) { 508 TEST_F(NetEqImplTest, ReorderedPacket) {
507 UseNoMocks(); 509 UseNoMocks();
508 CreateInstance(); 510 CreateInstance();
509 511
510 const uint8_t kPayloadType = 17; // Just an arbitrary number. 512 const uint8_t kPayloadType = 17; // Just an arbitrary number.
511 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test. 513 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test.
512 const int kSampleRateHz = 8000; 514 const int kSampleRateHz = 8000;
513 const int kPayloadLengthSamples = 10 * kSampleRateHz / 1000; // 10 ms. 515 const size_t kPayloadLengthSamples =
516 static_cast<size_t>(10 * kSampleRateHz / 1000); // 10 ms.
514 const size_t kPayloadLengthBytes = kPayloadLengthSamples; 517 const size_t kPayloadLengthBytes = kPayloadLengthSamples;
515 uint8_t payload[kPayloadLengthBytes] = {0}; 518 uint8_t payload[kPayloadLengthBytes] = {0};
516 WebRtcRTPHeader rtp_header; 519 WebRtcRTPHeader rtp_header;
517 rtp_header.header.payloadType = kPayloadType; 520 rtp_header.header.payloadType = kPayloadType;
518 rtp_header.header.sequenceNumber = 0x1234; 521 rtp_header.header.sequenceNumber = 0x1234;
519 rtp_header.header.timestamp = 0x12345678; 522 rtp_header.header.timestamp = 0x12345678;
520 rtp_header.header.ssrc = 0x87654321; 523 rtp_header.header.ssrc = 0x87654321;
521 524
522 // Create a mock decoder object. 525 // Create a mock decoder object.
523 MockAudioDecoder mock_decoder; 526 MockAudioDecoder mock_decoder;
(...skipping 13 matching lines...) Expand all
537 EXPECT_EQ(NetEq::kOK, 540 EXPECT_EQ(NetEq::kOK,
538 neteq_->RegisterExternalDecoder(&mock_decoder, kDecoderPCM16B, 541 neteq_->RegisterExternalDecoder(&mock_decoder, kDecoderPCM16B,
539 kPayloadType, kSampleRateHz)); 542 kPayloadType, kSampleRateHz));
540 543
541 // Insert one packet. 544 // Insert one packet.
542 EXPECT_EQ(NetEq::kOK, 545 EXPECT_EQ(NetEq::kOK,
543 neteq_->InsertPacket( 546 neteq_->InsertPacket(
544 rtp_header, payload, kPayloadLengthBytes, kReceiveTime)); 547 rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
545 548
546 // Pull audio once. 549 // Pull audio once.
547 const int kMaxOutputSize = 10 * kSampleRateHz / 1000; 550 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000);
548 int16_t output[kMaxOutputSize]; 551 int16_t output[kMaxOutputSize];
549 int samples_per_channel; 552 size_t samples_per_channel;
550 int num_channels; 553 int num_channels;
551 NetEqOutputType type; 554 NetEqOutputType type;
552 EXPECT_EQ( 555 EXPECT_EQ(
553 NetEq::kOK, 556 NetEq::kOK,
554 neteq_->GetAudio( 557 neteq_->GetAudio(
555 kMaxOutputSize, output, &samples_per_channel, &num_channels, &type)); 558 kMaxOutputSize, output, &samples_per_channel, &num_channels, &type));
556 ASSERT_EQ(kMaxOutputSize, samples_per_channel); 559 ASSERT_EQ(kMaxOutputSize, samples_per_channel);
557 EXPECT_EQ(1, num_channels); 560 EXPECT_EQ(1, num_channels);
558 EXPECT_EQ(kOutputNormal, type); 561 EXPECT_EQ(kOutputNormal, type);
559 562
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 602
600 // This test verifies that NetEq can handle the situation where the first 603 // This test verifies that NetEq can handle the situation where the first
601 // incoming packet is rejected. 604 // incoming packet is rejected.
602 TEST_F(NetEqImplTest, FirstPacketUnknown) { 605 TEST_F(NetEqImplTest, FirstPacketUnknown) {
603 UseNoMocks(); 606 UseNoMocks();
604 CreateInstance(); 607 CreateInstance();
605 608
606 const uint8_t kPayloadType = 17; // Just an arbitrary number. 609 const uint8_t kPayloadType = 17; // Just an arbitrary number.
607 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test. 610 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test.
608 const int kSampleRateHz = 8000; 611 const int kSampleRateHz = 8000;
609 const int kPayloadLengthSamples = 10 * kSampleRateHz / 1000; // 10 ms. 612 const size_t kPayloadLengthSamples =
613 static_cast<size_t>(10 * kSampleRateHz / 1000); // 10 ms.
610 const size_t kPayloadLengthBytes = kPayloadLengthSamples; 614 const size_t kPayloadLengthBytes = kPayloadLengthSamples;
611 uint8_t payload[kPayloadLengthBytes] = {0}; 615 uint8_t payload[kPayloadLengthBytes] = {0};
612 WebRtcRTPHeader rtp_header; 616 WebRtcRTPHeader rtp_header;
613 rtp_header.header.payloadType = kPayloadType; 617 rtp_header.header.payloadType = kPayloadType;
614 rtp_header.header.sequenceNumber = 0x1234; 618 rtp_header.header.sequenceNumber = 0x1234;
615 rtp_header.header.timestamp = 0x12345678; 619 rtp_header.header.timestamp = 0x12345678;
616 rtp_header.header.ssrc = 0x87654321; 620 rtp_header.header.ssrc = 0x87654321;
617 621
618 // Insert one packet. Note that we have not registered any payload type, so 622 // Insert one packet. Note that we have not registered any payload type, so
619 // this packet will be rejected. 623 // this packet will be rejected.
620 EXPECT_EQ(NetEq::kFail, 624 EXPECT_EQ(NetEq::kFail,
621 neteq_->InsertPacket(rtp_header, payload, kPayloadLengthBytes, 625 neteq_->InsertPacket(rtp_header, payload, kPayloadLengthBytes,
622 kReceiveTime)); 626 kReceiveTime));
623 EXPECT_EQ(NetEq::kUnknownRtpPayloadType, neteq_->LastError()); 627 EXPECT_EQ(NetEq::kUnknownRtpPayloadType, neteq_->LastError());
624 628
625 // Pull audio once. 629 // Pull audio once.
626 const int kMaxOutputSize = 10 * kSampleRateHz / 1000; 630 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000);
627 int16_t output[kMaxOutputSize]; 631 int16_t output[kMaxOutputSize];
628 int samples_per_channel; 632 size_t samples_per_channel;
629 int num_channels; 633 int num_channels;
630 NetEqOutputType type; 634 NetEqOutputType type;
631 EXPECT_EQ(NetEq::kOK, 635 EXPECT_EQ(NetEq::kOK,
632 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, 636 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel,
633 &num_channels, &type)); 637 &num_channels, &type));
634 ASSERT_LE(samples_per_channel, kMaxOutputSize); 638 ASSERT_LE(samples_per_channel, kMaxOutputSize);
635 EXPECT_EQ(kMaxOutputSize, samples_per_channel); 639 EXPECT_EQ(kMaxOutputSize, samples_per_channel);
636 EXPECT_EQ(1, num_channels); 640 EXPECT_EQ(1, num_channels);
637 EXPECT_EQ(kOutputPLC, type); 641 EXPECT_EQ(kOutputPLC, type);
638 642
639 // Register the payload type. 643 // Register the payload type.
640 EXPECT_EQ(NetEq::kOK, 644 EXPECT_EQ(NetEq::kOK,
641 neteq_->RegisterPayloadType(kDecoderPCM16B, kPayloadType)); 645 neteq_->RegisterPayloadType(kDecoderPCM16B, kPayloadType));
642 646
643 // Insert 10 packets. 647 // Insert 10 packets.
644 for (int i = 0; i < 10; ++i) { 648 for (size_t i = 0; i < 10; ++i) {
645 rtp_header.header.sequenceNumber++; 649 rtp_header.header.sequenceNumber++;
646 rtp_header.header.timestamp += kPayloadLengthSamples; 650 rtp_header.header.timestamp += kPayloadLengthSamples;
647 EXPECT_EQ(NetEq::kOK, 651 EXPECT_EQ(NetEq::kOK,
648 neteq_->InsertPacket(rtp_header, payload, kPayloadLengthBytes, 652 neteq_->InsertPacket(rtp_header, payload, kPayloadLengthBytes,
649 kReceiveTime)); 653 kReceiveTime));
650 EXPECT_EQ(i + 1, packet_buffer_->NumPacketsInBuffer()); 654 EXPECT_EQ(i + 1, packet_buffer_->NumPacketsInBuffer());
651 } 655 }
652 656
653 // Pull audio repeatedly and make sure we get normal output, that is not PLC. 657 // Pull audio repeatedly and make sure we get normal output, that is not PLC.
654 for (int i = 0; i < 3; ++i) { 658 for (size_t i = 0; i < 3; ++i) {
655 EXPECT_EQ(NetEq::kOK, 659 EXPECT_EQ(NetEq::kOK,
656 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, 660 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel,
657 &num_channels, &type)); 661 &num_channels, &type));
658 ASSERT_LE(samples_per_channel, kMaxOutputSize); 662 ASSERT_LE(samples_per_channel, kMaxOutputSize);
659 EXPECT_EQ(kMaxOutputSize, samples_per_channel); 663 EXPECT_EQ(kMaxOutputSize, samples_per_channel);
660 EXPECT_EQ(1, num_channels); 664 EXPECT_EQ(1, num_channels);
661 EXPECT_EQ(kOutputNormal, type) 665 EXPECT_EQ(kOutputNormal, type)
662 << "NetEq did not decode the packets as expected."; 666 << "NetEq did not decode the packets as expected.";
663 } 667 }
664 } 668 }
665 669
666 // This test verifies that NetEq can handle comfort noise and enters/quits codec 670 // This test verifies that NetEq can handle comfort noise and enters/quits codec
667 // internal CNG mode properly. 671 // internal CNG mode properly.
668 TEST_F(NetEqImplTest, CodecInternalCng) { 672 TEST_F(NetEqImplTest, CodecInternalCng) {
669 UseNoMocks(); 673 UseNoMocks();
670 CreateInstance(); 674 CreateInstance();
671 675
672 const uint8_t kPayloadType = 17; // Just an arbitrary number. 676 const uint8_t kPayloadType = 17; // Just an arbitrary number.
673 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test. 677 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test.
674 const int kSampleRateKhz = 48; 678 const int kSampleRateKhz = 48;
675 const int kPayloadLengthSamples = 20 * kSampleRateKhz; // 20 ms. 679 const size_t kPayloadLengthSamples =
676 const int kPayloadLengthBytes = 10; 680 static_cast<size_t>(20 * kSampleRateKhz); // 20 ms.
681 const size_t kPayloadLengthBytes = 10;
677 uint8_t payload[kPayloadLengthBytes] = {0}; 682 uint8_t payload[kPayloadLengthBytes] = {0};
678 int16_t dummy_output[kPayloadLengthSamples] = {0}; 683 int16_t dummy_output[kPayloadLengthSamples] = {0};
679 684
680 WebRtcRTPHeader rtp_header; 685 WebRtcRTPHeader rtp_header;
681 rtp_header.header.payloadType = kPayloadType; 686 rtp_header.header.payloadType = kPayloadType;
682 rtp_header.header.sequenceNumber = 0x1234; 687 rtp_header.header.sequenceNumber = 0x1234;
683 rtp_header.header.timestamp = 0x12345678; 688 rtp_header.header.timestamp = 0x12345678;
684 rtp_header.header.ssrc = 0x87654321; 689 rtp_header.header.ssrc = 0x87654321;
685 690
686 // Create a mock decoder object. 691 // Create a mock decoder object.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 rtp_header, payload, kPayloadLengthBytes, kReceiveTime)); 734 rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
730 735
731 // Insert second packet (decoder will return CNG). 736 // Insert second packet (decoder will return CNG).
732 payload[0] = 1; 737 payload[0] = 1;
733 rtp_header.header.sequenceNumber++; 738 rtp_header.header.sequenceNumber++;
734 rtp_header.header.timestamp += kPayloadLengthSamples; 739 rtp_header.header.timestamp += kPayloadLengthSamples;
735 EXPECT_EQ(NetEq::kOK, 740 EXPECT_EQ(NetEq::kOK,
736 neteq_->InsertPacket( 741 neteq_->InsertPacket(
737 rtp_header, payload, kPayloadLengthBytes, kReceiveTime)); 742 rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
738 743
739 const int kMaxOutputSize = 10 * kSampleRateKhz; 744 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateKhz);
740 int16_t output[kMaxOutputSize]; 745 int16_t output[kMaxOutputSize];
741 int samples_per_channel; 746 size_t samples_per_channel;
742 int num_channels; 747 int num_channels;
743 uint32_t timestamp; 748 uint32_t timestamp;
744 uint32_t last_timestamp; 749 uint32_t last_timestamp;
745 NetEqOutputType type; 750 NetEqOutputType type;
746 NetEqOutputType expected_type[8] = { 751 NetEqOutputType expected_type[8] = {
747 kOutputNormal, kOutputNormal, 752 kOutputNormal, kOutputNormal,
748 kOutputCNG, kOutputCNG, 753 kOutputCNG, kOutputCNG,
749 kOutputCNG, kOutputCNG, 754 kOutputCNG, kOutputCNG,
750 kOutputNormal, kOutputNormal 755 kOutputNormal, kOutputNormal
751 }; 756 };
752 int expected_timestamp_increment[8] = { 757 int expected_timestamp_increment[8] = {
753 -1, // will not be used. 758 -1, // will not be used.
754 10 * kSampleRateKhz, 759 10 * kSampleRateKhz,
755 0, 0, // timestamp does not increase during CNG mode. 760 0, 0, // timestamp does not increase during CNG mode.
756 0, 0, 761 0, 0,
757 50 * kSampleRateKhz, 10 * kSampleRateKhz 762 50 * kSampleRateKhz, 10 * kSampleRateKhz
758 }; 763 };
759 764
760 EXPECT_EQ(NetEq::kOK, 765 EXPECT_EQ(NetEq::kOK,
761 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, 766 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel,
762 &num_channels, &type)); 767 &num_channels, &type));
763 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&last_timestamp)); 768 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&last_timestamp));
764 769
765 for (int i = 1; i < 6; ++i) { 770 for (size_t i = 1; i < 6; ++i) {
766 ASSERT_EQ(kMaxOutputSize, samples_per_channel); 771 ASSERT_EQ(kMaxOutputSize, samples_per_channel);
767 EXPECT_EQ(1, num_channels); 772 EXPECT_EQ(1, num_channels);
768 EXPECT_EQ(expected_type[i - 1], type); 773 EXPECT_EQ(expected_type[i - 1], type);
769 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp)); 774 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp));
770 EXPECT_EQ(NetEq::kOK, 775 EXPECT_EQ(NetEq::kOK,
771 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, 776 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel,
772 &num_channels, &type)); 777 &num_channels, &type));
773 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp)); 778 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp));
774 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]); 779 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]);
775 last_timestamp = timestamp; 780 last_timestamp = timestamp;
776 } 781 }
777 782
778 // Insert third packet, which leaves a gap from last packet. 783 // Insert third packet, which leaves a gap from last packet.
779 payload[0] = 2; 784 payload[0] = 2;
780 rtp_header.header.sequenceNumber += 2; 785 rtp_header.header.sequenceNumber += 2;
781 rtp_header.header.timestamp += 2 * kPayloadLengthSamples; 786 rtp_header.header.timestamp += 2 * kPayloadLengthSamples;
782 EXPECT_EQ(NetEq::kOK, 787 EXPECT_EQ(NetEq::kOK,
783 neteq_->InsertPacket( 788 neteq_->InsertPacket(
784 rtp_header, payload, kPayloadLengthBytes, kReceiveTime)); 789 rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
785 790
786 for (int i = 6; i < 8; ++i) { 791 for (size_t i = 6; i < 8; ++i) {
787 ASSERT_EQ(kMaxOutputSize, samples_per_channel); 792 ASSERT_EQ(kMaxOutputSize, samples_per_channel);
788 EXPECT_EQ(1, num_channels); 793 EXPECT_EQ(1, num_channels);
789 EXPECT_EQ(expected_type[i - 1], type); 794 EXPECT_EQ(expected_type[i - 1], type);
790 EXPECT_EQ(NetEq::kOK, 795 EXPECT_EQ(NetEq::kOK,
791 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, 796 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel,
792 &num_channels, &type)); 797 &num_channels, &type));
793 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp)); 798 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp));
794 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]); 799 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]);
795 last_timestamp = timestamp; 800 last_timestamp = timestamp;
796 } 801 }
797 802
798 // Now check the packet buffer, and make sure it is empty. 803 // Now check the packet buffer, and make sure it is empty.
799 EXPECT_TRUE(packet_buffer_->Empty()); 804 EXPECT_TRUE(packet_buffer_->Empty());
800 805
801 EXPECT_CALL(mock_decoder, Die()); 806 EXPECT_CALL(mock_decoder, Die());
802 } 807 }
803 808
804 TEST_F(NetEqImplTest, UnsupportedDecoder) { 809 TEST_F(NetEqImplTest, UnsupportedDecoder) {
805 UseNoMocks(); 810 UseNoMocks();
806 CreateInstance(); 811 CreateInstance();
807 static const size_t kNetEqMaxFrameSize = 2880; // 60 ms @ 48 kHz. 812 static const size_t kNetEqMaxFrameSize = 2880; // 60 ms @ 48 kHz.
808 static const int kChannels = 2; 813 static const int kChannels = 2;
809 814
810 const uint8_t kPayloadType = 17; // Just an arbitrary number. 815 const uint8_t kPayloadType = 17; // Just an arbitrary number.
811 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test. 816 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test.
812 const int kSampleRateHz = 8000; 817 const int kSampleRateHz = 8000;
813 818
814 const int kPayloadLengthSamples = 10 * kSampleRateHz / 1000; // 10 ms. 819 const size_t kPayloadLengthSamples =
820 static_cast<size_t>(10 * kSampleRateHz / 1000); // 10 ms.
815 const size_t kPayloadLengthBytes = 1; 821 const size_t kPayloadLengthBytes = 1;
816 uint8_t payload[kPayloadLengthBytes]= {0}; 822 uint8_t payload[kPayloadLengthBytes]= {0};
817 int16_t dummy_output[kPayloadLengthSamples * kChannels] = {0}; 823 int16_t dummy_output[kPayloadLengthSamples * kChannels] = {0};
818 WebRtcRTPHeader rtp_header; 824 WebRtcRTPHeader rtp_header;
819 rtp_header.header.payloadType = kPayloadType; 825 rtp_header.header.payloadType = kPayloadType;
820 rtp_header.header.sequenceNumber = 0x1234; 826 rtp_header.header.sequenceNumber = 0x1234;
821 rtp_header.header.timestamp = 0x12345678; 827 rtp_header.header.timestamp = 0x12345678;
822 rtp_header.header.ssrc = 0x87654321; 828 rtp_header.header.ssrc = 0x87654321;
823 829
824 class MockAudioDecoder : public AudioDecoder { 830 class MockAudioDecoder : public AudioDecoder {
(...skipping 20 matching lines...) Expand all
845 .Times(0); 851 .Times(0);
846 852
847 EXPECT_CALL(decoder_, DecodeInternal(Pointee(kSecondPayloadValue), 853 EXPECT_CALL(decoder_, DecodeInternal(Pointee(kSecondPayloadValue),
848 kPayloadLengthBytes, 854 kPayloadLengthBytes,
849 kSampleRateHz, _, _)) 855 kSampleRateHz, _, _))
850 .Times(1) 856 .Times(1)
851 .WillOnce(DoAll(SetArrayArgument<3>(dummy_output, 857 .WillOnce(DoAll(SetArrayArgument<3>(dummy_output,
852 dummy_output + 858 dummy_output +
853 kPayloadLengthSamples * kChannels), 859 kPayloadLengthSamples * kChannels),
854 SetArgPointee<4>(AudioDecoder::kSpeech), 860 SetArgPointee<4>(AudioDecoder::kSpeech),
855 Return(kPayloadLengthSamples * kChannels))); 861 Return(static_cast<int>(
862 kPayloadLengthSamples * kChannels))));
856 863
857 EXPECT_CALL(decoder_, PacketDuration(Pointee(kSecondPayloadValue), 864 EXPECT_CALL(decoder_, PacketDuration(Pointee(kSecondPayloadValue),
858 kPayloadLengthBytes)) 865 kPayloadLengthBytes))
859 .Times(AtLeast(1)) 866 .Times(AtLeast(1))
860 .WillRepeatedly(Return(kNetEqMaxFrameSize)); 867 .WillRepeatedly(Return(kNetEqMaxFrameSize));
861 868
862 EXPECT_EQ(NetEq::kOK, 869 EXPECT_EQ(NetEq::kOK,
863 neteq_->RegisterExternalDecoder(&decoder_, kDecoderPCM16B, 870 neteq_->RegisterExternalDecoder(&decoder_, kDecoderPCM16B,
864 kPayloadType, kSampleRateHz)); 871 kPayloadType, kSampleRateHz));
865 872
866 // Insert one packet. 873 // Insert one packet.
867 payload[0] = kFirstPayloadValue; // This will make Decode() fail. 874 payload[0] = kFirstPayloadValue; // This will make Decode() fail.
868 EXPECT_EQ(NetEq::kOK, 875 EXPECT_EQ(NetEq::kOK,
869 neteq_->InsertPacket( 876 neteq_->InsertPacket(
870 rtp_header, payload, kPayloadLengthBytes, kReceiveTime)); 877 rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
871 878
872 // Insert another packet. 879 // Insert another packet.
873 payload[0] = kSecondPayloadValue; // This will make Decode() successful. 880 payload[0] = kSecondPayloadValue; // This will make Decode() successful.
874 rtp_header.header.sequenceNumber++; 881 rtp_header.header.sequenceNumber++;
875 // The second timestamp needs to be at least 30 ms after the first to make 882 // The second timestamp needs to be at least 30 ms after the first to make
876 // the second packet get decoded. 883 // the second packet get decoded.
877 rtp_header.header.timestamp += 3 * kPayloadLengthSamples; 884 rtp_header.header.timestamp += 3 * kPayloadLengthSamples;
878 EXPECT_EQ(NetEq::kOK, 885 EXPECT_EQ(NetEq::kOK,
879 neteq_->InsertPacket( 886 neteq_->InsertPacket(
880 rtp_header, payload, kPayloadLengthBytes, kReceiveTime)); 887 rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
881 888
882 const int kMaxOutputSize = 10 * kSampleRateHz / 1000 * kChannels; 889 const size_t kMaxOutputSize =
890 static_cast<size_t>(10 * kSampleRateHz / 1000 * kChannels);
883 int16_t output[kMaxOutputSize]; 891 int16_t output[kMaxOutputSize];
884 int samples_per_channel; 892 size_t samples_per_channel;
885 int num_channels; 893 int num_channels;
886 NetEqOutputType type; 894 NetEqOutputType type;
887 895
888 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(kMaxOutputSize, output, 896 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(kMaxOutputSize, output,
889 &samples_per_channel, &num_channels, 897 &samples_per_channel, &num_channels,
890 &type)); 898 &type));
891 EXPECT_EQ(NetEq::kOtherDecoderError, neteq_->LastError()); 899 EXPECT_EQ(NetEq::kOtherDecoderError, neteq_->LastError());
892 EXPECT_EQ(kMaxOutputSize, samples_per_channel * kChannels); 900 EXPECT_EQ(kMaxOutputSize, samples_per_channel * kChannels);
893 EXPECT_EQ(kChannels, num_channels); 901 EXPECT_EQ(kChannels, num_channels);
894 902
895 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(kMaxOutputSize, output, 903 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(kMaxOutputSize, output,
896 &samples_per_channel, &num_channels, 904 &samples_per_channel, &num_channels,
897 &type)); 905 &type));
898 EXPECT_EQ(kMaxOutputSize, samples_per_channel * kChannels); 906 EXPECT_EQ(kMaxOutputSize, samples_per_channel * kChannels);
899 EXPECT_EQ(kChannels, num_channels); 907 EXPECT_EQ(kChannels, num_channels);
900 } 908 }
901 909
902 } // namespace webrtc 910 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/neteq_impl.cc ('k') | webrtc/modules/audio_coding/neteq/neteq_stereo_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698