| 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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 "dummy name", kPayloadType, kSampleRateHz)); | 459 "dummy name", kPayloadType, kSampleRateHz)); |
| 460 | 460 |
| 461 // Insert one packet. | 461 // Insert one packet. |
| 462 EXPECT_EQ(NetEq::kOK, | 462 EXPECT_EQ(NetEq::kOK, |
| 463 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 463 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 464 | 464 |
| 465 // Pull audio once. | 465 // Pull audio once. |
| 466 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); | 466 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); |
| 467 int16_t output[kMaxOutputSize]; | 467 int16_t output[kMaxOutputSize]; |
| 468 size_t samples_per_channel; | 468 size_t samples_per_channel; |
| 469 int num_channels; | 469 size_t num_channels; |
| 470 NetEqOutputType type; | 470 NetEqOutputType type; |
| 471 EXPECT_EQ( | 471 EXPECT_EQ( |
| 472 NetEq::kOK, | 472 NetEq::kOK, |
| 473 neteq_->GetAudio( | 473 neteq_->GetAudio( |
| 474 kMaxOutputSize, output, &samples_per_channel, &num_channels, &type)); | 474 kMaxOutputSize, output, &samples_per_channel, &num_channels, &type)); |
| 475 ASSERT_EQ(kMaxOutputSize, samples_per_channel); | 475 ASSERT_EQ(kMaxOutputSize, samples_per_channel); |
| 476 EXPECT_EQ(1, num_channels); | 476 EXPECT_EQ(1u, num_channels); |
| 477 EXPECT_EQ(kOutputNormal, type); | 477 EXPECT_EQ(kOutputNormal, type); |
| 478 | 478 |
| 479 // Start with a simple check that the fake decoder is behaving as expected. | 479 // Start with a simple check that the fake decoder is behaving as expected. |
| 480 EXPECT_EQ(kPayloadLengthSamples, | 480 EXPECT_EQ(kPayloadLengthSamples, |
| 481 static_cast<size_t>(decoder_.next_value() - 1)); | 481 static_cast<size_t>(decoder_.next_value() - 1)); |
| 482 | 482 |
| 483 // The value of the last of the output samples is the same as the number of | 483 // The value of the last of the output samples is the same as the number of |
| 484 // samples played from the decoded packet. Thus, this number + the RTP | 484 // samples played from the decoded packet. Thus, this number + the RTP |
| 485 // timestamp should match the playout timestamp. | 485 // timestamp should match the playout timestamp. |
| 486 uint32_t timestamp = 0; | 486 uint32_t timestamp = 0; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 "dummy name", kPayloadType, kSampleRateHz)); | 538 "dummy name", kPayloadType, kSampleRateHz)); |
| 539 | 539 |
| 540 // Insert one packet. | 540 // Insert one packet. |
| 541 EXPECT_EQ(NetEq::kOK, | 541 EXPECT_EQ(NetEq::kOK, |
| 542 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 542 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 543 | 543 |
| 544 // Pull audio once. | 544 // Pull audio once. |
| 545 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); | 545 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); |
| 546 int16_t output[kMaxOutputSize]; | 546 int16_t output[kMaxOutputSize]; |
| 547 size_t samples_per_channel; | 547 size_t samples_per_channel; |
| 548 int num_channels; | 548 size_t num_channels; |
| 549 NetEqOutputType type; | 549 NetEqOutputType type; |
| 550 EXPECT_EQ( | 550 EXPECT_EQ( |
| 551 NetEq::kOK, | 551 NetEq::kOK, |
| 552 neteq_->GetAudio( | 552 neteq_->GetAudio( |
| 553 kMaxOutputSize, output, &samples_per_channel, &num_channels, &type)); | 553 kMaxOutputSize, output, &samples_per_channel, &num_channels, &type)); |
| 554 ASSERT_EQ(kMaxOutputSize, samples_per_channel); | 554 ASSERT_EQ(kMaxOutputSize, samples_per_channel); |
| 555 EXPECT_EQ(1, num_channels); | 555 EXPECT_EQ(1u, num_channels); |
| 556 EXPECT_EQ(kOutputNormal, type); | 556 EXPECT_EQ(kOutputNormal, type); |
| 557 | 557 |
| 558 // Insert two more packets. The first one is out of order, and is already too | 558 // Insert two more packets. The first one is out of order, and is already too |
| 559 // old, the second one is the expected next packet. | 559 // old, the second one is the expected next packet. |
| 560 rtp_header.header.sequenceNumber -= 1; | 560 rtp_header.header.sequenceNumber -= 1; |
| 561 rtp_header.header.timestamp -= kPayloadLengthSamples; | 561 rtp_header.header.timestamp -= kPayloadLengthSamples; |
| 562 payload[0] = 1; | 562 payload[0] = 1; |
| 563 EXPECT_EQ(NetEq::kOK, | 563 EXPECT_EQ(NetEq::kOK, |
| 564 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 564 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 565 rtp_header.header.sequenceNumber += 2; | 565 rtp_header.header.sequenceNumber += 2; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 576 dummy_output + kPayloadLengthSamples), | 576 dummy_output + kPayloadLengthSamples), |
| 577 SetArgPointee<4>(AudioDecoder::kSpeech), | 577 SetArgPointee<4>(AudioDecoder::kSpeech), |
| 578 Return(kPayloadLengthSamples))); | 578 Return(kPayloadLengthSamples))); |
| 579 | 579 |
| 580 // Pull audio once. | 580 // Pull audio once. |
| 581 EXPECT_EQ( | 581 EXPECT_EQ( |
| 582 NetEq::kOK, | 582 NetEq::kOK, |
| 583 neteq_->GetAudio( | 583 neteq_->GetAudio( |
| 584 kMaxOutputSize, output, &samples_per_channel, &num_channels, &type)); | 584 kMaxOutputSize, output, &samples_per_channel, &num_channels, &type)); |
| 585 ASSERT_EQ(kMaxOutputSize, samples_per_channel); | 585 ASSERT_EQ(kMaxOutputSize, samples_per_channel); |
| 586 EXPECT_EQ(1, num_channels); | 586 EXPECT_EQ(1u, num_channels); |
| 587 EXPECT_EQ(kOutputNormal, type); | 587 EXPECT_EQ(kOutputNormal, type); |
| 588 | 588 |
| 589 // Now check the packet buffer, and make sure it is empty, since the | 589 // Now check the packet buffer, and make sure it is empty, since the |
| 590 // out-of-order packet should have been discarded. | 590 // out-of-order packet should have been discarded. |
| 591 EXPECT_TRUE(packet_buffer_->Empty()); | 591 EXPECT_TRUE(packet_buffer_->Empty()); |
| 592 | 592 |
| 593 EXPECT_CALL(mock_decoder, Die()); | 593 EXPECT_CALL(mock_decoder, Die()); |
| 594 } | 594 } |
| 595 | 595 |
| 596 // This test verifies that NetEq can handle the situation where the first | 596 // This test verifies that NetEq can handle the situation where the first |
| (...skipping 18 matching lines...) Expand all Loading... |
| 615 // Insert one packet. Note that we have not registered any payload type, so | 615 // Insert one packet. Note that we have not registered any payload type, so |
| 616 // this packet will be rejected. | 616 // this packet will be rejected. |
| 617 EXPECT_EQ(NetEq::kFail, | 617 EXPECT_EQ(NetEq::kFail, |
| 618 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 618 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 619 EXPECT_EQ(NetEq::kUnknownRtpPayloadType, neteq_->LastError()); | 619 EXPECT_EQ(NetEq::kUnknownRtpPayloadType, neteq_->LastError()); |
| 620 | 620 |
| 621 // Pull audio once. | 621 // Pull audio once. |
| 622 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); | 622 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); |
| 623 int16_t output[kMaxOutputSize]; | 623 int16_t output[kMaxOutputSize]; |
| 624 size_t samples_per_channel; | 624 size_t samples_per_channel; |
| 625 int num_channels; | 625 size_t num_channels; |
| 626 NetEqOutputType type; | 626 NetEqOutputType type; |
| 627 EXPECT_EQ(NetEq::kOK, | 627 EXPECT_EQ(NetEq::kOK, |
| 628 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 628 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 629 &num_channels, &type)); | 629 &num_channels, &type)); |
| 630 ASSERT_LE(samples_per_channel, kMaxOutputSize); | 630 ASSERT_LE(samples_per_channel, kMaxOutputSize); |
| 631 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | 631 EXPECT_EQ(kMaxOutputSize, samples_per_channel); |
| 632 EXPECT_EQ(1, num_channels); | 632 EXPECT_EQ(1u, num_channels); |
| 633 EXPECT_EQ(kOutputPLC, type); | 633 EXPECT_EQ(kOutputPLC, type); |
| 634 | 634 |
| 635 // Register the payload type. | 635 // Register the payload type. |
| 636 EXPECT_EQ(NetEq::kOK, neteq_->RegisterPayloadType( | 636 EXPECT_EQ(NetEq::kOK, neteq_->RegisterPayloadType( |
| 637 NetEqDecoder::kDecoderPCM16B, "", kPayloadType)); | 637 NetEqDecoder::kDecoderPCM16B, "", kPayloadType)); |
| 638 | 638 |
| 639 // Insert 10 packets. | 639 // Insert 10 packets. |
| 640 for (size_t i = 0; i < 10; ++i) { | 640 for (size_t i = 0; i < 10; ++i) { |
| 641 rtp_header.header.sequenceNumber++; | 641 rtp_header.header.sequenceNumber++; |
| 642 rtp_header.header.timestamp += kPayloadLengthSamples; | 642 rtp_header.header.timestamp += kPayloadLengthSamples; |
| 643 EXPECT_EQ(NetEq::kOK, | 643 EXPECT_EQ(NetEq::kOK, |
| 644 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 644 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 645 EXPECT_EQ(i + 1, packet_buffer_->NumPacketsInBuffer()); | 645 EXPECT_EQ(i + 1, packet_buffer_->NumPacketsInBuffer()); |
| 646 } | 646 } |
| 647 | 647 |
| 648 // Pull audio repeatedly and make sure we get normal output, that is not PLC. | 648 // Pull audio repeatedly and make sure we get normal output, that is not PLC. |
| 649 for (size_t i = 0; i < 3; ++i) { | 649 for (size_t i = 0; i < 3; ++i) { |
| 650 EXPECT_EQ(NetEq::kOK, | 650 EXPECT_EQ(NetEq::kOK, |
| 651 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 651 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 652 &num_channels, &type)); | 652 &num_channels, &type)); |
| 653 ASSERT_LE(samples_per_channel, kMaxOutputSize); | 653 ASSERT_LE(samples_per_channel, kMaxOutputSize); |
| 654 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | 654 EXPECT_EQ(kMaxOutputSize, samples_per_channel); |
| 655 EXPECT_EQ(1, num_channels); | 655 EXPECT_EQ(1u, num_channels); |
| 656 EXPECT_EQ(kOutputNormal, type) | 656 EXPECT_EQ(kOutputNormal, type) |
| 657 << "NetEq did not decode the packets as expected."; | 657 << "NetEq did not decode the packets as expected."; |
| 658 } | 658 } |
| 659 } | 659 } |
| 660 | 660 |
| 661 // This test verifies that NetEq can handle comfort noise and enters/quits codec | 661 // This test verifies that NetEq can handle comfort noise and enters/quits codec |
| 662 // internal CNG mode properly. | 662 // internal CNG mode properly. |
| 663 TEST_F(NetEqImplTest, CodecInternalCng) { | 663 TEST_F(NetEqImplTest, CodecInternalCng) { |
| 664 UseNoMocks(); | 664 UseNoMocks(); |
| 665 CreateInstance(); | 665 CreateInstance(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 // Insert second packet (decoder will return CNG). | 727 // Insert second packet (decoder will return CNG). |
| 728 payload[0] = 1; | 728 payload[0] = 1; |
| 729 rtp_header.header.sequenceNumber++; | 729 rtp_header.header.sequenceNumber++; |
| 730 rtp_header.header.timestamp += kPayloadLengthSamples; | 730 rtp_header.header.timestamp += kPayloadLengthSamples; |
| 731 EXPECT_EQ(NetEq::kOK, | 731 EXPECT_EQ(NetEq::kOK, |
| 732 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 732 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 733 | 733 |
| 734 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateKhz); | 734 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateKhz); |
| 735 int16_t output[kMaxOutputSize]; | 735 int16_t output[kMaxOutputSize]; |
| 736 size_t samples_per_channel; | 736 size_t samples_per_channel; |
| 737 int num_channels; | 737 size_t num_channels; |
| 738 uint32_t timestamp; | 738 uint32_t timestamp; |
| 739 uint32_t last_timestamp; | 739 uint32_t last_timestamp; |
| 740 NetEqOutputType type; | 740 NetEqOutputType type; |
| 741 NetEqOutputType expected_type[8] = { | 741 NetEqOutputType expected_type[8] = { |
| 742 kOutputNormal, kOutputNormal, | 742 kOutputNormal, kOutputNormal, |
| 743 kOutputCNG, kOutputCNG, | 743 kOutputCNG, kOutputCNG, |
| 744 kOutputCNG, kOutputCNG, | 744 kOutputCNG, kOutputCNG, |
| 745 kOutputNormal, kOutputNormal | 745 kOutputNormal, kOutputNormal |
| 746 }; | 746 }; |
| 747 int expected_timestamp_increment[8] = { | 747 int expected_timestamp_increment[8] = { |
| 748 -1, // will not be used. | 748 -1, // will not be used. |
| 749 10 * kSampleRateKhz, | 749 10 * kSampleRateKhz, |
| 750 0, 0, // timestamp does not increase during CNG mode. | 750 0, 0, // timestamp does not increase during CNG mode. |
| 751 0, 0, | 751 0, 0, |
| 752 50 * kSampleRateKhz, 10 * kSampleRateKhz | 752 50 * kSampleRateKhz, 10 * kSampleRateKhz |
| 753 }; | 753 }; |
| 754 | 754 |
| 755 EXPECT_EQ(NetEq::kOK, | 755 EXPECT_EQ(NetEq::kOK, |
| 756 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 756 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 757 &num_channels, &type)); | 757 &num_channels, &type)); |
| 758 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&last_timestamp)); | 758 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&last_timestamp)); |
| 759 | 759 |
| 760 for (size_t i = 1; i < 6; ++i) { | 760 for (size_t i = 1; i < 6; ++i) { |
| 761 ASSERT_EQ(kMaxOutputSize, samples_per_channel); | 761 ASSERT_EQ(kMaxOutputSize, samples_per_channel); |
| 762 EXPECT_EQ(1, num_channels); | 762 EXPECT_EQ(1u, num_channels); |
| 763 EXPECT_EQ(expected_type[i - 1], type); | 763 EXPECT_EQ(expected_type[i - 1], type); |
| 764 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(×tamp)); | 764 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(×tamp)); |
| 765 EXPECT_EQ(NetEq::kOK, | 765 EXPECT_EQ(NetEq::kOK, |
| 766 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 766 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 767 &num_channels, &type)); | 767 &num_channels, &type)); |
| 768 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(×tamp)); | 768 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(×tamp)); |
| 769 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]); | 769 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]); |
| 770 last_timestamp = timestamp; | 770 last_timestamp = timestamp; |
| 771 } | 771 } |
| 772 | 772 |
| 773 // Insert third packet, which leaves a gap from last packet. | 773 // Insert third packet, which leaves a gap from last packet. |
| 774 payload[0] = 2; | 774 payload[0] = 2; |
| 775 rtp_header.header.sequenceNumber += 2; | 775 rtp_header.header.sequenceNumber += 2; |
| 776 rtp_header.header.timestamp += 2 * kPayloadLengthSamples; | 776 rtp_header.header.timestamp += 2 * kPayloadLengthSamples; |
| 777 EXPECT_EQ(NetEq::kOK, | 777 EXPECT_EQ(NetEq::kOK, |
| 778 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 778 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 779 | 779 |
| 780 for (size_t i = 6; i < 8; ++i) { | 780 for (size_t i = 6; i < 8; ++i) { |
| 781 ASSERT_EQ(kMaxOutputSize, samples_per_channel); | 781 ASSERT_EQ(kMaxOutputSize, samples_per_channel); |
| 782 EXPECT_EQ(1, num_channels); | 782 EXPECT_EQ(1u, num_channels); |
| 783 EXPECT_EQ(expected_type[i - 1], type); | 783 EXPECT_EQ(expected_type[i - 1], type); |
| 784 EXPECT_EQ(NetEq::kOK, | 784 EXPECT_EQ(NetEq::kOK, |
| 785 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 785 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 786 &num_channels, &type)); | 786 &num_channels, &type)); |
| 787 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(×tamp)); | 787 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(×tamp)); |
| 788 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]); | 788 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]); |
| 789 last_timestamp = timestamp; | 789 last_timestamp = timestamp; |
| 790 } | 790 } |
| 791 | 791 |
| 792 // Now check the packet buffer, and make sure it is empty. | 792 // Now check the packet buffer, and make sure it is empty. |
| 793 EXPECT_TRUE(packet_buffer_->Empty()); | 793 EXPECT_TRUE(packet_buffer_->Empty()); |
| 794 | 794 |
| 795 EXPECT_CALL(mock_decoder, Die()); | 795 EXPECT_CALL(mock_decoder, Die()); |
| 796 } | 796 } |
| 797 | 797 |
| 798 TEST_F(NetEqImplTest, UnsupportedDecoder) { | 798 TEST_F(NetEqImplTest, UnsupportedDecoder) { |
| 799 UseNoMocks(); | 799 UseNoMocks(); |
| 800 CreateInstance(); | 800 CreateInstance(); |
| 801 static const size_t kNetEqMaxFrameSize = 2880; // 60 ms @ 48 kHz. | 801 static const size_t kNetEqMaxFrameSize = 2880; // 60 ms @ 48 kHz. |
| 802 static const int kChannels = 2; | 802 static const size_t kChannels = 2; |
| 803 | 803 |
| 804 const uint8_t kPayloadType = 17; // Just an arbitrary number. | 804 const uint8_t kPayloadType = 17; // Just an arbitrary number. |
| 805 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test. | 805 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test. |
| 806 const int kSampleRateHz = 8000; | 806 const int kSampleRateHz = 8000; |
| 807 | 807 |
| 808 const size_t kPayloadLengthSamples = | 808 const size_t kPayloadLengthSamples = |
| 809 static_cast<size_t>(10 * kSampleRateHz / 1000); // 10 ms. | 809 static_cast<size_t>(10 * kSampleRateHz / 1000); // 10 ms. |
| 810 const size_t kPayloadLengthBytes = 1; | 810 const size_t kPayloadLengthBytes = 1; |
| 811 uint8_t payload[kPayloadLengthBytes]= {0}; | 811 uint8_t payload[kPayloadLengthBytes]= {0}; |
| 812 int16_t dummy_output[kPayloadLengthSamples * kChannels] = {0}; | 812 int16_t dummy_output[kPayloadLengthSamples * kChannels] = {0}; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 | 864 |
| 865 // Insert another packet. | 865 // Insert another packet. |
| 866 payload[0] = kSecondPayloadValue; // This will make Decode() successful. | 866 payload[0] = kSecondPayloadValue; // This will make Decode() successful. |
| 867 rtp_header.header.sequenceNumber++; | 867 rtp_header.header.sequenceNumber++; |
| 868 // The second timestamp needs to be at least 30 ms after the first to make | 868 // The second timestamp needs to be at least 30 ms after the first to make |
| 869 // the second packet get decoded. | 869 // the second packet get decoded. |
| 870 rtp_header.header.timestamp += 3 * kPayloadLengthSamples; | 870 rtp_header.header.timestamp += 3 * kPayloadLengthSamples; |
| 871 EXPECT_EQ(NetEq::kOK, | 871 EXPECT_EQ(NetEq::kOK, |
| 872 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 872 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 873 | 873 |
| 874 const size_t kMaxOutputSize = | 874 const size_t kMaxOutputSize = 10 * kSampleRateHz / 1000 * kChannels; |
| 875 static_cast<size_t>(10 * kSampleRateHz / 1000 * kChannels); | |
| 876 int16_t output[kMaxOutputSize]; | 875 int16_t output[kMaxOutputSize]; |
| 877 size_t samples_per_channel; | 876 size_t samples_per_channel; |
| 878 int num_channels; | 877 size_t num_channels; |
| 879 NetEqOutputType type; | 878 NetEqOutputType type; |
| 880 | 879 |
| 881 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(kMaxOutputSize, output, | 880 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(kMaxOutputSize, output, |
| 882 &samples_per_channel, &num_channels, | 881 &samples_per_channel, &num_channels, |
| 883 &type)); | 882 &type)); |
| 884 EXPECT_EQ(NetEq::kOtherDecoderError, neteq_->LastError()); | 883 EXPECT_EQ(NetEq::kOtherDecoderError, neteq_->LastError()); |
| 885 EXPECT_EQ(kMaxOutputSize, samples_per_channel * kChannels); | 884 EXPECT_EQ(kMaxOutputSize, samples_per_channel * kChannels); |
| 886 EXPECT_EQ(kChannels, num_channels); | 885 EXPECT_EQ(kChannels, num_channels); |
| 887 | 886 |
| 888 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(kMaxOutputSize, output, | 887 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(kMaxOutputSize, output, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 // Insert one packet. | 973 // Insert one packet. |
| 975 EXPECT_EQ(NetEq::kOK, | 974 EXPECT_EQ(NetEq::kOK, |
| 976 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 975 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 977 | 976 |
| 978 EXPECT_EQ(5u, neteq_->sync_buffer_for_test()->FutureLength()); | 977 EXPECT_EQ(5u, neteq_->sync_buffer_for_test()->FutureLength()); |
| 979 | 978 |
| 980 // Pull audio once. | 979 // Pull audio once. |
| 981 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); | 980 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); |
| 982 int16_t output[kMaxOutputSize]; | 981 int16_t output[kMaxOutputSize]; |
| 983 size_t samples_per_channel; | 982 size_t samples_per_channel; |
| 984 int num_channels; | 983 size_t num_channels; |
| 985 NetEqOutputType type; | 984 NetEqOutputType type; |
| 986 EXPECT_EQ(NetEq::kOK, | 985 EXPECT_EQ(NetEq::kOK, |
| 987 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 986 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 988 &num_channels, &type)); | 987 &num_channels, &type)); |
| 989 ASSERT_EQ(kMaxOutputSize, samples_per_channel); | 988 ASSERT_EQ(kMaxOutputSize, samples_per_channel); |
| 990 EXPECT_EQ(1, num_channels); | 989 EXPECT_EQ(1u, num_channels); |
| 991 EXPECT_EQ(kOutputNormal, type); | 990 EXPECT_EQ(kOutputNormal, type); |
| 992 | 991 |
| 993 EXPECT_CALL(mock_decoder, Die()); | 992 EXPECT_CALL(mock_decoder, Die()); |
| 994 } | 993 } |
| 995 | 994 |
| 996 // This test checks the behavior of NetEq when audio decoder fails. | 995 // This test checks the behavior of NetEq when audio decoder fails. |
| 997 TEST_F(NetEqImplTest, DecodingError) { | 996 TEST_F(NetEqImplTest, DecodingError) { |
| 998 UseNoMocks(); | 997 UseNoMocks(); |
| 999 CreateInstance(); | 998 CreateInstance(); |
| 1000 | 999 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 rtp_header.header.sequenceNumber += 1; | 1070 rtp_header.header.sequenceNumber += 1; |
| 1072 rtp_header.header.timestamp += kFrameLengthSamples; | 1071 rtp_header.header.timestamp += kFrameLengthSamples; |
| 1073 EXPECT_EQ(NetEq::kOK, | 1072 EXPECT_EQ(NetEq::kOK, |
| 1074 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 1073 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 1075 } | 1074 } |
| 1076 | 1075 |
| 1077 // Pull audio. | 1076 // Pull audio. |
| 1078 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); | 1077 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); |
| 1079 int16_t output[kMaxOutputSize]; | 1078 int16_t output[kMaxOutputSize]; |
| 1080 size_t samples_per_channel; | 1079 size_t samples_per_channel; |
| 1081 int num_channels; | 1080 size_t num_channels; |
| 1082 NetEqOutputType type; | 1081 NetEqOutputType type; |
| 1083 EXPECT_EQ(NetEq::kOK, | 1082 EXPECT_EQ(NetEq::kOK, |
| 1084 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 1083 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 1085 &num_channels, &type)); | 1084 &num_channels, &type)); |
| 1086 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | 1085 EXPECT_EQ(kMaxOutputSize, samples_per_channel); |
| 1087 EXPECT_EQ(1, num_channels); | 1086 EXPECT_EQ(1u, num_channels); |
| 1088 EXPECT_EQ(kOutputNormal, type); | 1087 EXPECT_EQ(kOutputNormal, type); |
| 1089 | 1088 |
| 1090 // Pull audio again. Decoder fails. | 1089 // Pull audio again. Decoder fails. |
| 1091 EXPECT_EQ(NetEq::kFail, | 1090 EXPECT_EQ(NetEq::kFail, |
| 1092 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 1091 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 1093 &num_channels, &type)); | 1092 &num_channels, &type)); |
| 1094 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); | 1093 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); |
| 1095 EXPECT_EQ(kDecoderErrorCode, neteq_->LastDecoderError()); | 1094 EXPECT_EQ(kDecoderErrorCode, neteq_->LastDecoderError()); |
| 1096 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | 1095 EXPECT_EQ(kMaxOutputSize, samples_per_channel); |
| 1097 EXPECT_EQ(1, num_channels); | 1096 EXPECT_EQ(1u, num_channels); |
| 1098 // TODO(minyue): should NetEq better give kOutputPLC, since it is actually an | 1097 // TODO(minyue): should NetEq better give kOutputPLC, since it is actually an |
| 1099 // expansion. | 1098 // expansion. |
| 1100 EXPECT_EQ(kOutputNormal, type); | 1099 EXPECT_EQ(kOutputNormal, type); |
| 1101 | 1100 |
| 1102 // Pull audio again, should continue an expansion. | 1101 // Pull audio again, should continue an expansion. |
| 1103 EXPECT_EQ(NetEq::kOK, | 1102 EXPECT_EQ(NetEq::kOK, |
| 1104 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 1103 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 1105 &num_channels, &type)); | 1104 &num_channels, &type)); |
| 1106 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | 1105 EXPECT_EQ(kMaxOutputSize, samples_per_channel); |
| 1107 EXPECT_EQ(1, num_channels); | 1106 EXPECT_EQ(1u, num_channels); |
| 1108 EXPECT_EQ(kOutputPLC, type); | 1107 EXPECT_EQ(kOutputPLC, type); |
| 1109 | 1108 |
| 1110 // Pull audio again, should behave normal. | 1109 // Pull audio again, should behave normal. |
| 1111 EXPECT_EQ(NetEq::kOK, | 1110 EXPECT_EQ(NetEq::kOK, |
| 1112 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 1111 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 1113 &num_channels, &type)); | 1112 &num_channels, &type)); |
| 1114 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | 1113 EXPECT_EQ(kMaxOutputSize, samples_per_channel); |
| 1115 EXPECT_EQ(1, num_channels); | 1114 EXPECT_EQ(1u, num_channels); |
| 1116 EXPECT_EQ(kOutputNormal, type); | 1115 EXPECT_EQ(kOutputNormal, type); |
| 1117 | 1116 |
| 1118 EXPECT_CALL(mock_decoder, Die()); | 1117 EXPECT_CALL(mock_decoder, Die()); |
| 1119 } | 1118 } |
| 1120 | 1119 |
| 1121 // This test checks the behavior of NetEq when audio decoder fails during CNG. | 1120 // This test checks the behavior of NetEq when audio decoder fails during CNG. |
| 1122 TEST_F(NetEqImplTest, DecodingErrorDuringInternalCng) { | 1121 TEST_F(NetEqImplTest, DecodingErrorDuringInternalCng) { |
| 1123 UseNoMocks(); | 1122 UseNoMocks(); |
| 1124 CreateInstance(); | 1123 CreateInstance(); |
| 1125 | 1124 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 rtp_header.header.sequenceNumber += 1; | 1191 rtp_header.header.sequenceNumber += 1; |
| 1193 rtp_header.header.timestamp += kFrameLengthSamples; | 1192 rtp_header.header.timestamp += kFrameLengthSamples; |
| 1194 EXPECT_EQ(NetEq::kOK, | 1193 EXPECT_EQ(NetEq::kOK, |
| 1195 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 1194 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 1196 } | 1195 } |
| 1197 | 1196 |
| 1198 // Pull audio. | 1197 // Pull audio. |
| 1199 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); | 1198 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); |
| 1200 int16_t output[kMaxOutputSize]; | 1199 int16_t output[kMaxOutputSize]; |
| 1201 size_t samples_per_channel; | 1200 size_t samples_per_channel; |
| 1202 int num_channels; | 1201 size_t num_channels; |
| 1203 NetEqOutputType type; | 1202 NetEqOutputType type; |
| 1204 EXPECT_EQ(NetEq::kOK, | 1203 EXPECT_EQ(NetEq::kOK, |
| 1205 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 1204 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 1206 &num_channels, &type)); | 1205 &num_channels, &type)); |
| 1207 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | 1206 EXPECT_EQ(kMaxOutputSize, samples_per_channel); |
| 1208 EXPECT_EQ(1, num_channels); | 1207 EXPECT_EQ(1u, num_channels); |
| 1209 EXPECT_EQ(kOutputCNG, type); | 1208 EXPECT_EQ(kOutputCNG, type); |
| 1210 | 1209 |
| 1211 // Pull audio again. Decoder fails. | 1210 // Pull audio again. Decoder fails. |
| 1212 EXPECT_EQ(NetEq::kFail, | 1211 EXPECT_EQ(NetEq::kFail, |
| 1213 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 1212 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 1214 &num_channels, &type)); | 1213 &num_channels, &type)); |
| 1215 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); | 1214 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); |
| 1216 EXPECT_EQ(kDecoderErrorCode, neteq_->LastDecoderError()); | 1215 EXPECT_EQ(kDecoderErrorCode, neteq_->LastDecoderError()); |
| 1217 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | 1216 EXPECT_EQ(kMaxOutputSize, samples_per_channel); |
| 1218 EXPECT_EQ(1, num_channels); | 1217 EXPECT_EQ(1u, num_channels); |
| 1219 // TODO(minyue): should NetEq better give kOutputPLC, since it is actually an | 1218 // TODO(minyue): should NetEq better give kOutputPLC, since it is actually an |
| 1220 // expansion. | 1219 // expansion. |
| 1221 EXPECT_EQ(kOutputCNG, type); | 1220 EXPECT_EQ(kOutputCNG, type); |
| 1222 | 1221 |
| 1223 // Pull audio again, should resume codec CNG. | 1222 // Pull audio again, should resume codec CNG. |
| 1224 EXPECT_EQ(NetEq::kOK, | 1223 EXPECT_EQ(NetEq::kOK, |
| 1225 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 1224 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 1226 &num_channels, &type)); | 1225 &num_channels, &type)); |
| 1227 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | 1226 EXPECT_EQ(kMaxOutputSize, samples_per_channel); |
| 1228 EXPECT_EQ(1, num_channels); | 1227 EXPECT_EQ(1u, num_channels); |
| 1229 EXPECT_EQ(kOutputCNG, type); | 1228 EXPECT_EQ(kOutputCNG, type); |
| 1230 | 1229 |
| 1231 EXPECT_CALL(mock_decoder, Die()); | 1230 EXPECT_CALL(mock_decoder, Die()); |
| 1232 } | 1231 } |
| 1233 | 1232 |
| 1234 // Tests that the return value from last_output_sample_rate_hz() is equal to the | 1233 // Tests that the return value from last_output_sample_rate_hz() is equal to the |
| 1235 // configured inital sample rate. | 1234 // configured inital sample rate. |
| 1236 TEST_F(NetEqImplTest, InitialLastOutputSampleRate) { | 1235 TEST_F(NetEqImplTest, InitialLastOutputSampleRate) { |
| 1237 UseNoMocks(); | 1236 UseNoMocks(); |
| 1238 config_.sample_rate_hz = 48000; | 1237 config_.sample_rate_hz = 48000; |
| 1239 CreateInstance(); | 1238 CreateInstance(); |
| 1240 EXPECT_EQ(48000, neteq_->last_output_sample_rate_hz()); | 1239 EXPECT_EQ(48000, neteq_->last_output_sample_rate_hz()); |
| 1241 } | 1240 } |
| 1242 | 1241 |
| 1243 }// namespace webrtc | 1242 }// namespace webrtc |
| OLD | NEW |