| 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 10 matching lines...) Expand all Loading... |
| 21 #include "webrtc/modules/audio_coding/neteq/mock/mock_decoder_database.h" | 21 #include "webrtc/modules/audio_coding/neteq/mock/mock_decoder_database.h" |
| 22 #include "webrtc/modules/audio_coding/neteq/mock/mock_delay_manager.h" | 22 #include "webrtc/modules/audio_coding/neteq/mock/mock_delay_manager.h" |
| 23 #include "webrtc/modules/audio_coding/neteq/mock/mock_delay_peak_detector.h" | 23 #include "webrtc/modules/audio_coding/neteq/mock/mock_delay_peak_detector.h" |
| 24 #include "webrtc/modules/audio_coding/neteq/mock/mock_dtmf_buffer.h" | 24 #include "webrtc/modules/audio_coding/neteq/mock/mock_dtmf_buffer.h" |
| 25 #include "webrtc/modules/audio_coding/neteq/mock/mock_dtmf_tone_generator.h" | 25 #include "webrtc/modules/audio_coding/neteq/mock/mock_dtmf_tone_generator.h" |
| 26 #include "webrtc/modules/audio_coding/neteq/mock/mock_packet_buffer.h" | 26 #include "webrtc/modules/audio_coding/neteq/mock/mock_packet_buffer.h" |
| 27 #include "webrtc/modules/audio_coding/neteq/mock/mock_payload_splitter.h" | 27 #include "webrtc/modules/audio_coding/neteq/mock/mock_payload_splitter.h" |
| 28 #include "webrtc/modules/audio_coding/neteq/preemptive_expand.h" | 28 #include "webrtc/modules/audio_coding/neteq/preemptive_expand.h" |
| 29 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" | 29 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" |
| 30 #include "webrtc/modules/audio_coding/neteq/timestamp_scaler.h" | 30 #include "webrtc/modules/audio_coding/neteq/timestamp_scaler.h" |
| 31 #include "webrtc/modules/include/module_common_types.h" |
| 31 | 32 |
| 32 using ::testing::AtLeast; | 33 using ::testing::AtLeast; |
| 33 using ::testing::Return; | 34 using ::testing::Return; |
| 34 using ::testing::ReturnNull; | 35 using ::testing::ReturnNull; |
| 35 using ::testing::_; | 36 using ::testing::_; |
| 36 using ::testing::SetArgPointee; | 37 using ::testing::SetArgPointee; |
| 37 using ::testing::SetArrayArgument; | 38 using ::testing::SetArrayArgument; |
| 38 using ::testing::InSequence; | 39 using ::testing::InSequence; |
| 39 using ::testing::Invoke; | 40 using ::testing::Invoke; |
| 40 using ::testing::WithArg; | 41 using ::testing::WithArg; |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 EXPECT_EQ(NetEq::kOK, neteq_->RegisterExternalDecoder( | 458 EXPECT_EQ(NetEq::kOK, neteq_->RegisterExternalDecoder( |
| 458 &decoder_, NetEqDecoder::kDecoderPCM16B, | 459 &decoder_, NetEqDecoder::kDecoderPCM16B, |
| 459 "dummy name", kPayloadType, kSampleRateHz)); | 460 "dummy name", kPayloadType, kSampleRateHz)); |
| 460 | 461 |
| 461 // Insert one packet. | 462 // Insert one packet. |
| 462 EXPECT_EQ(NetEq::kOK, | 463 EXPECT_EQ(NetEq::kOK, |
| 463 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 464 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 464 | 465 |
| 465 // Pull audio once. | 466 // Pull audio once. |
| 466 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); | 467 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); |
| 467 int16_t output[kMaxOutputSize]; | 468 AudioFrame output; |
| 468 size_t samples_per_channel; | |
| 469 size_t num_channels; | |
| 470 NetEqOutputType type; | 469 NetEqOutputType type; |
| 471 EXPECT_EQ( | 470 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); |
| 472 NetEq::kOK, | 471 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 473 neteq_->GetAudio( | 472 EXPECT_EQ(1u, output.num_channels_); |
| 474 kMaxOutputSize, output, &samples_per_channel, &num_channels, &type)); | |
| 475 ASSERT_EQ(kMaxOutputSize, samples_per_channel); | |
| 476 EXPECT_EQ(1u, num_channels); | |
| 477 EXPECT_EQ(kOutputNormal, type); | 473 EXPECT_EQ(kOutputNormal, type); |
| 478 | 474 |
| 479 // Start with a simple check that the fake decoder is behaving as expected. | 475 // Start with a simple check that the fake decoder is behaving as expected. |
| 480 EXPECT_EQ(kPayloadLengthSamples, | 476 EXPECT_EQ(kPayloadLengthSamples, |
| 481 static_cast<size_t>(decoder_.next_value() - 1)); | 477 static_cast<size_t>(decoder_.next_value() - 1)); |
| 482 | 478 |
| 483 // The value of the last of the output samples is the same as the number of | 479 // 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 | 480 // samples played from the decoded packet. Thus, this number + the RTP |
| 485 // timestamp should match the playout timestamp. | 481 // timestamp should match the playout timestamp. |
| 486 uint32_t timestamp = 0; | 482 uint32_t timestamp = 0; |
| 487 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(×tamp)); | 483 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(×tamp)); |
| 488 EXPECT_EQ(rtp_header.header.timestamp + output[samples_per_channel - 1], | 484 EXPECT_EQ(rtp_header.header.timestamp + |
| 485 output.data_[output.samples_per_channel_ - 1], |
| 489 timestamp); | 486 timestamp); |
| 490 | 487 |
| 491 // Check the timestamp for the last value in the sync buffer. This should | 488 // Check the timestamp for the last value in the sync buffer. This should |
| 492 // be one full frame length ahead of the RTP timestamp. | 489 // be one full frame length ahead of the RTP timestamp. |
| 493 const SyncBuffer* sync_buffer = neteq_->sync_buffer_for_test(); | 490 const SyncBuffer* sync_buffer = neteq_->sync_buffer_for_test(); |
| 494 ASSERT_TRUE(sync_buffer != NULL); | 491 ASSERT_TRUE(sync_buffer != NULL); |
| 495 EXPECT_EQ(rtp_header.header.timestamp + kPayloadLengthSamples, | 492 EXPECT_EQ(rtp_header.header.timestamp + kPayloadLengthSamples, |
| 496 sync_buffer->end_timestamp()); | 493 sync_buffer->end_timestamp()); |
| 497 | 494 |
| 498 // Check that the number of samples still to play from the sync buffer add | 495 // Check that the number of samples still to play from the sync buffer add |
| 499 // up with what was already played out. | 496 // up with what was already played out. |
| 500 EXPECT_EQ(kPayloadLengthSamples - output[samples_per_channel - 1], | 497 EXPECT_EQ( |
| 501 sync_buffer->FutureLength()); | 498 kPayloadLengthSamples - output.data_[output.samples_per_channel_ - 1], |
| 499 sync_buffer->FutureLength()); |
| 502 } | 500 } |
| 503 | 501 |
| 504 TEST_F(NetEqImplTest, ReorderedPacket) { | 502 TEST_F(NetEqImplTest, ReorderedPacket) { |
| 505 UseNoMocks(); | 503 UseNoMocks(); |
| 506 CreateInstance(); | 504 CreateInstance(); |
| 507 | 505 |
| 508 const uint8_t kPayloadType = 17; // Just an arbitrary number. | 506 const uint8_t kPayloadType = 17; // Just an arbitrary number. |
| 509 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test. | 507 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test. |
| 510 const int kSampleRateHz = 8000; | 508 const int kSampleRateHz = 8000; |
| 511 const size_t kPayloadLengthSamples = | 509 const size_t kPayloadLengthSamples = |
| (...skipping 24 matching lines...) Expand all Loading... |
| 536 EXPECT_EQ(NetEq::kOK, neteq_->RegisterExternalDecoder( | 534 EXPECT_EQ(NetEq::kOK, neteq_->RegisterExternalDecoder( |
| 537 &mock_decoder, NetEqDecoder::kDecoderPCM16B, | 535 &mock_decoder, NetEqDecoder::kDecoderPCM16B, |
| 538 "dummy name", kPayloadType, kSampleRateHz)); | 536 "dummy name", kPayloadType, kSampleRateHz)); |
| 539 | 537 |
| 540 // Insert one packet. | 538 // Insert one packet. |
| 541 EXPECT_EQ(NetEq::kOK, | 539 EXPECT_EQ(NetEq::kOK, |
| 542 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 540 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 543 | 541 |
| 544 // Pull audio once. | 542 // Pull audio once. |
| 545 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); | 543 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); |
| 546 int16_t output[kMaxOutputSize]; | 544 AudioFrame output; |
| 547 size_t samples_per_channel; | |
| 548 size_t num_channels; | |
| 549 NetEqOutputType type; | 545 NetEqOutputType type; |
| 550 EXPECT_EQ( | 546 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); |
| 551 NetEq::kOK, | 547 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 552 neteq_->GetAudio( | 548 EXPECT_EQ(1u, output.num_channels_); |
| 553 kMaxOutputSize, output, &samples_per_channel, &num_channels, &type)); | |
| 554 ASSERT_EQ(kMaxOutputSize, samples_per_channel); | |
| 555 EXPECT_EQ(1u, num_channels); | |
| 556 EXPECT_EQ(kOutputNormal, type); | 549 EXPECT_EQ(kOutputNormal, type); |
| 557 | 550 |
| 558 // Insert two more packets. The first one is out of order, and is already too | 551 // 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. | 552 // old, the second one is the expected next packet. |
| 560 rtp_header.header.sequenceNumber -= 1; | 553 rtp_header.header.sequenceNumber -= 1; |
| 561 rtp_header.header.timestamp -= kPayloadLengthSamples; | 554 rtp_header.header.timestamp -= kPayloadLengthSamples; |
| 562 payload[0] = 1; | 555 payload[0] = 1; |
| 563 EXPECT_EQ(NetEq::kOK, | 556 EXPECT_EQ(NetEq::kOK, |
| 564 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 557 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 565 rtp_header.header.sequenceNumber += 2; | 558 rtp_header.header.sequenceNumber += 2; |
| 566 rtp_header.header.timestamp += 2 * kPayloadLengthSamples; | 559 rtp_header.header.timestamp += 2 * kPayloadLengthSamples; |
| 567 payload[0] = 2; | 560 payload[0] = 2; |
| 568 EXPECT_EQ(NetEq::kOK, | 561 EXPECT_EQ(NetEq::kOK, |
| 569 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 562 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 570 | 563 |
| 571 // Expect only the second packet to be decoded (the one with "2" as the first | 564 // Expect only the second packet to be decoded (the one with "2" as the first |
| 572 // payload byte). | 565 // payload byte). |
| 573 EXPECT_CALL(mock_decoder, DecodeInternal(Pointee(2), kPayloadLengthBytes, | 566 EXPECT_CALL(mock_decoder, DecodeInternal(Pointee(2), kPayloadLengthBytes, |
| 574 kSampleRateHz, _, _)) | 567 kSampleRateHz, _, _)) |
| 575 .WillOnce(DoAll(SetArrayArgument<3>(dummy_output, | 568 .WillOnce(DoAll(SetArrayArgument<3>(dummy_output, |
| 576 dummy_output + kPayloadLengthSamples), | 569 dummy_output + kPayloadLengthSamples), |
| 577 SetArgPointee<4>(AudioDecoder::kSpeech), | 570 SetArgPointee<4>(AudioDecoder::kSpeech), |
| 578 Return(kPayloadLengthSamples))); | 571 Return(kPayloadLengthSamples))); |
| 579 | 572 |
| 580 // Pull audio once. | 573 // Pull audio once. |
| 581 EXPECT_EQ( | 574 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); |
| 582 NetEq::kOK, | 575 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 583 neteq_->GetAudio( | 576 EXPECT_EQ(1u, output.num_channels_); |
| 584 kMaxOutputSize, output, &samples_per_channel, &num_channels, &type)); | |
| 585 ASSERT_EQ(kMaxOutputSize, samples_per_channel); | |
| 586 EXPECT_EQ(1u, num_channels); | |
| 587 EXPECT_EQ(kOutputNormal, type); | 577 EXPECT_EQ(kOutputNormal, type); |
| 588 | 578 |
| 589 // Now check the packet buffer, and make sure it is empty, since the | 579 // Now check the packet buffer, and make sure it is empty, since the |
| 590 // out-of-order packet should have been discarded. | 580 // out-of-order packet should have been discarded. |
| 591 EXPECT_TRUE(packet_buffer_->Empty()); | 581 EXPECT_TRUE(packet_buffer_->Empty()); |
| 592 | 582 |
| 593 EXPECT_CALL(mock_decoder, Die()); | 583 EXPECT_CALL(mock_decoder, Die()); |
| 594 } | 584 } |
| 595 | 585 |
| 596 // This test verifies that NetEq can handle the situation where the first | 586 // This test verifies that NetEq can handle the situation where the first |
| (...skipping 16 matching lines...) Expand all Loading... |
| 613 rtp_header.header.ssrc = 0x87654321; | 603 rtp_header.header.ssrc = 0x87654321; |
| 614 | 604 |
| 615 // Insert one packet. Note that we have not registered any payload type, so | 605 // Insert one packet. Note that we have not registered any payload type, so |
| 616 // this packet will be rejected. | 606 // this packet will be rejected. |
| 617 EXPECT_EQ(NetEq::kFail, | 607 EXPECT_EQ(NetEq::kFail, |
| 618 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 608 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 619 EXPECT_EQ(NetEq::kUnknownRtpPayloadType, neteq_->LastError()); | 609 EXPECT_EQ(NetEq::kUnknownRtpPayloadType, neteq_->LastError()); |
| 620 | 610 |
| 621 // Pull audio once. | 611 // Pull audio once. |
| 622 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); | 612 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); |
| 623 int16_t output[kMaxOutputSize]; | 613 AudioFrame output; |
| 624 size_t samples_per_channel; | |
| 625 size_t num_channels; | |
| 626 NetEqOutputType type; | 614 NetEqOutputType type; |
| 627 EXPECT_EQ(NetEq::kOK, | 615 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); |
| 628 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 616 ASSERT_LE(output.samples_per_channel_, kMaxOutputSize); |
| 629 &num_channels, &type)); | 617 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 630 ASSERT_LE(samples_per_channel, kMaxOutputSize); | 618 EXPECT_EQ(1u, output.num_channels_); |
| 631 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | |
| 632 EXPECT_EQ(1u, num_channels); | |
| 633 EXPECT_EQ(kOutputPLC, type); | 619 EXPECT_EQ(kOutputPLC, type); |
| 634 | 620 |
| 635 // Register the payload type. | 621 // Register the payload type. |
| 636 EXPECT_EQ(NetEq::kOK, neteq_->RegisterPayloadType( | 622 EXPECT_EQ(NetEq::kOK, neteq_->RegisterPayloadType( |
| 637 NetEqDecoder::kDecoderPCM16B, "", kPayloadType)); | 623 NetEqDecoder::kDecoderPCM16B, "", kPayloadType)); |
| 638 | 624 |
| 639 // Insert 10 packets. | 625 // Insert 10 packets. |
| 640 for (size_t i = 0; i < 10; ++i) { | 626 for (size_t i = 0; i < 10; ++i) { |
| 641 rtp_header.header.sequenceNumber++; | 627 rtp_header.header.sequenceNumber++; |
| 642 rtp_header.header.timestamp += kPayloadLengthSamples; | 628 rtp_header.header.timestamp += kPayloadLengthSamples; |
| 643 EXPECT_EQ(NetEq::kOK, | 629 EXPECT_EQ(NetEq::kOK, |
| 644 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 630 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 645 EXPECT_EQ(i + 1, packet_buffer_->NumPacketsInBuffer()); | 631 EXPECT_EQ(i + 1, packet_buffer_->NumPacketsInBuffer()); |
| 646 } | 632 } |
| 647 | 633 |
| 648 // Pull audio repeatedly and make sure we get normal output, that is not PLC. | 634 // Pull audio repeatedly and make sure we get normal output, that is not PLC. |
| 649 for (size_t i = 0; i < 3; ++i) { | 635 for (size_t i = 0; i < 3; ++i) { |
| 650 EXPECT_EQ(NetEq::kOK, | 636 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); |
| 651 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 637 ASSERT_LE(output.samples_per_channel_, kMaxOutputSize); |
| 652 &num_channels, &type)); | 638 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 653 ASSERT_LE(samples_per_channel, kMaxOutputSize); | 639 EXPECT_EQ(1u, output.num_channels_); |
| 654 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | |
| 655 EXPECT_EQ(1u, num_channels); | |
| 656 EXPECT_EQ(kOutputNormal, type) | 640 EXPECT_EQ(kOutputNormal, type) |
| 657 << "NetEq did not decode the packets as expected."; | 641 << "NetEq did not decode the packets as expected."; |
| 658 } | 642 } |
| 659 } | 643 } |
| 660 | 644 |
| 661 // This test verifies that NetEq can handle comfort noise and enters/quits codec | 645 // This test verifies that NetEq can handle comfort noise and enters/quits codec |
| 662 // internal CNG mode properly. | 646 // internal CNG mode properly. |
| 663 TEST_F(NetEqImplTest, CodecInternalCng) { | 647 TEST_F(NetEqImplTest, CodecInternalCng) { |
| 664 UseNoMocks(); | 648 UseNoMocks(); |
| 665 CreateInstance(); | 649 CreateInstance(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 709 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 726 | 710 |
| 727 // Insert second packet (decoder will return CNG). | 711 // Insert second packet (decoder will return CNG). |
| 728 payload[0] = 1; | 712 payload[0] = 1; |
| 729 rtp_header.header.sequenceNumber++; | 713 rtp_header.header.sequenceNumber++; |
| 730 rtp_header.header.timestamp += kPayloadLengthSamples; | 714 rtp_header.header.timestamp += kPayloadLengthSamples; |
| 731 EXPECT_EQ(NetEq::kOK, | 715 EXPECT_EQ(NetEq::kOK, |
| 732 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 716 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 733 | 717 |
| 734 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateKhz); | 718 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateKhz); |
| 735 int16_t output[kMaxOutputSize]; | 719 AudioFrame output; |
| 736 size_t samples_per_channel; | |
| 737 size_t num_channels; | |
| 738 uint32_t timestamp; | 720 uint32_t timestamp; |
| 739 uint32_t last_timestamp; | 721 uint32_t last_timestamp; |
| 740 NetEqOutputType type; | 722 NetEqOutputType type; |
| 741 NetEqOutputType expected_type[8] = { | 723 NetEqOutputType expected_type[8] = { |
| 742 kOutputNormal, kOutputNormal, | 724 kOutputNormal, kOutputNormal, |
| 743 kOutputCNG, kOutputCNG, | 725 kOutputCNG, kOutputCNG, |
| 744 kOutputCNG, kOutputCNG, | 726 kOutputCNG, kOutputCNG, |
| 745 kOutputNormal, kOutputNormal | 727 kOutputNormal, kOutputNormal |
| 746 }; | 728 }; |
| 747 int expected_timestamp_increment[8] = { | 729 int expected_timestamp_increment[8] = { |
| 748 -1, // will not be used. | 730 -1, // will not be used. |
| 749 10 * kSampleRateKhz, | 731 10 * kSampleRateKhz, |
| 750 0, 0, // timestamp does not increase during CNG mode. | 732 0, 0, // timestamp does not increase during CNG mode. |
| 751 0, 0, | 733 0, 0, |
| 752 50 * kSampleRateKhz, 10 * kSampleRateKhz | 734 50 * kSampleRateKhz, 10 * kSampleRateKhz |
| 753 }; | 735 }; |
| 754 | 736 |
| 755 EXPECT_EQ(NetEq::kOK, | 737 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); |
| 756 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | |
| 757 &num_channels, &type)); | |
| 758 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&last_timestamp)); | 738 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&last_timestamp)); |
| 759 | 739 |
| 760 for (size_t i = 1; i < 6; ++i) { | 740 for (size_t i = 1; i < 6; ++i) { |
| 761 ASSERT_EQ(kMaxOutputSize, samples_per_channel); | 741 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 762 EXPECT_EQ(1u, num_channels); | 742 EXPECT_EQ(1u, output.num_channels_); |
| 763 EXPECT_EQ(expected_type[i - 1], type); | 743 EXPECT_EQ(expected_type[i - 1], type); |
| 764 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(×tamp)); | 744 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(×tamp)); |
| 765 EXPECT_EQ(NetEq::kOK, | 745 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); |
| 766 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | |
| 767 &num_channels, &type)); | |
| 768 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(×tamp)); | 746 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(×tamp)); |
| 769 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]); | 747 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]); |
| 770 last_timestamp = timestamp; | 748 last_timestamp = timestamp; |
| 771 } | 749 } |
| 772 | 750 |
| 773 // Insert third packet, which leaves a gap from last packet. | 751 // Insert third packet, which leaves a gap from last packet. |
| 774 payload[0] = 2; | 752 payload[0] = 2; |
| 775 rtp_header.header.sequenceNumber += 2; | 753 rtp_header.header.sequenceNumber += 2; |
| 776 rtp_header.header.timestamp += 2 * kPayloadLengthSamples; | 754 rtp_header.header.timestamp += 2 * kPayloadLengthSamples; |
| 777 EXPECT_EQ(NetEq::kOK, | 755 EXPECT_EQ(NetEq::kOK, |
| 778 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 756 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 779 | 757 |
| 780 for (size_t i = 6; i < 8; ++i) { | 758 for (size_t i = 6; i < 8; ++i) { |
| 781 ASSERT_EQ(kMaxOutputSize, samples_per_channel); | 759 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 782 EXPECT_EQ(1u, num_channels); | 760 EXPECT_EQ(1u, output.num_channels_); |
| 783 EXPECT_EQ(expected_type[i - 1], type); | 761 EXPECT_EQ(expected_type[i - 1], type); |
| 784 EXPECT_EQ(NetEq::kOK, | 762 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); |
| 785 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | |
| 786 &num_channels, &type)); | |
| 787 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(×tamp)); | 763 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(×tamp)); |
| 788 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]); | 764 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]); |
| 789 last_timestamp = timestamp; | 765 last_timestamp = timestamp; |
| 790 } | 766 } |
| 791 | 767 |
| 792 // Now check the packet buffer, and make sure it is empty. | 768 // Now check the packet buffer, and make sure it is empty. |
| 793 EXPECT_TRUE(packet_buffer_->Empty()); | 769 EXPECT_TRUE(packet_buffer_->Empty()); |
| 794 | 770 |
| 795 EXPECT_CALL(mock_decoder, Die()); | 771 EXPECT_CALL(mock_decoder, Die()); |
| 796 } | 772 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 | 840 |
| 865 // Insert another packet. | 841 // Insert another packet. |
| 866 payload[0] = kSecondPayloadValue; // This will make Decode() successful. | 842 payload[0] = kSecondPayloadValue; // This will make Decode() successful. |
| 867 rtp_header.header.sequenceNumber++; | 843 rtp_header.header.sequenceNumber++; |
| 868 // The second timestamp needs to be at least 30 ms after the first to make | 844 // The second timestamp needs to be at least 30 ms after the first to make |
| 869 // the second packet get decoded. | 845 // the second packet get decoded. |
| 870 rtp_header.header.timestamp += 3 * kPayloadLengthSamples; | 846 rtp_header.header.timestamp += 3 * kPayloadLengthSamples; |
| 871 EXPECT_EQ(NetEq::kOK, | 847 EXPECT_EQ(NetEq::kOK, |
| 872 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 848 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 873 | 849 |
| 874 const size_t kMaxOutputSize = 10 * kSampleRateHz / 1000 * kChannels; | 850 AudioFrame output; |
| 875 int16_t output[kMaxOutputSize]; | |
| 876 size_t samples_per_channel; | |
| 877 size_t num_channels; | |
| 878 NetEqOutputType type; | 851 NetEqOutputType type; |
| 852 // First call to GetAudio will try to decode the "faulty" packet. |
| 853 // Expect kFail return value... |
| 854 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&output, &type)); |
| 855 // ... and kOtherDecoderError error code. |
| 856 EXPECT_EQ(NetEq::kOtherDecoderError, neteq_->LastError()); |
| 857 // Output size and number of channels should be correct. |
| 858 const size_t kExpectedOutputSize = 10 * (kSampleRateHz / 1000) * kChannels; |
| 859 EXPECT_EQ(kExpectedOutputSize, output.samples_per_channel_ * kChannels); |
| 860 EXPECT_EQ(kChannels, output.num_channels_); |
| 879 | 861 |
| 880 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(kMaxOutputSize, output, | 862 // Second call to GetAudio will decode the packet that is ok. No errors are |
| 881 &samples_per_channel, &num_channels, | 863 // expected. |
| 882 &type)); | 864 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); |
| 883 EXPECT_EQ(NetEq::kOtherDecoderError, neteq_->LastError()); | 865 EXPECT_EQ(kExpectedOutputSize, output.samples_per_channel_ * kChannels); |
| 884 EXPECT_EQ(kMaxOutputSize, samples_per_channel * kChannels); | 866 EXPECT_EQ(kChannels, output.num_channels_); |
| 885 EXPECT_EQ(kChannels, num_channels); | |
| 886 | |
| 887 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(kMaxOutputSize, output, | |
| 888 &samples_per_channel, &num_channels, | |
| 889 &type)); | |
| 890 EXPECT_EQ(kMaxOutputSize, samples_per_channel * kChannels); | |
| 891 EXPECT_EQ(kChannels, num_channels); | |
| 892 } | 867 } |
| 893 | 868 |
| 894 // This test inserts packets until the buffer is flushed. After that, it asks | 869 // This test inserts packets until the buffer is flushed. After that, it asks |
| 895 // NetEq for the network statistics. The purpose of the test is to make sure | 870 // NetEq for the network statistics. The purpose of the test is to make sure |
| 896 // that even though the buffer size increment is negative (which it becomes when | 871 // that even though the buffer size increment is negative (which it becomes when |
| 897 // the packet causing a flush is inserted), the packet length stored in the | 872 // the packet causing a flush is inserted), the packet length stored in the |
| 898 // decision logic remains valid. | 873 // decision logic remains valid. |
| 899 TEST_F(NetEqImplTest, FloodBufferAndGetNetworkStats) { | 874 TEST_F(NetEqImplTest, FloodBufferAndGetNetworkStats) { |
| 900 UseNoMocks(); | 875 UseNoMocks(); |
| 901 CreateInstance(); | 876 CreateInstance(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 "dummy name", kPayloadType, kSampleRateHz)); | 946 "dummy name", kPayloadType, kSampleRateHz)); |
| 972 | 947 |
| 973 // Insert one packet. | 948 // Insert one packet. |
| 974 EXPECT_EQ(NetEq::kOK, | 949 EXPECT_EQ(NetEq::kOK, |
| 975 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 950 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 976 | 951 |
| 977 EXPECT_EQ(5u, neteq_->sync_buffer_for_test()->FutureLength()); | 952 EXPECT_EQ(5u, neteq_->sync_buffer_for_test()->FutureLength()); |
| 978 | 953 |
| 979 // Pull audio once. | 954 // Pull audio once. |
| 980 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); | 955 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); |
| 981 int16_t output[kMaxOutputSize]; | 956 AudioFrame output; |
| 982 size_t samples_per_channel; | |
| 983 size_t num_channels; | |
| 984 NetEqOutputType type; | 957 NetEqOutputType type; |
| 985 EXPECT_EQ(NetEq::kOK, | 958 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); |
| 986 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 959 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 987 &num_channels, &type)); | 960 EXPECT_EQ(1u, output.num_channels_); |
| 988 ASSERT_EQ(kMaxOutputSize, samples_per_channel); | |
| 989 EXPECT_EQ(1u, num_channels); | |
| 990 EXPECT_EQ(kOutputNormal, type); | 961 EXPECT_EQ(kOutputNormal, type); |
| 991 | 962 |
| 992 EXPECT_CALL(mock_decoder, Die()); | 963 EXPECT_CALL(mock_decoder, Die()); |
| 993 } | 964 } |
| 994 | 965 |
| 995 // This test checks the behavior of NetEq when audio decoder fails. | 966 // This test checks the behavior of NetEq when audio decoder fails. |
| 996 TEST_F(NetEqImplTest, DecodingError) { | 967 TEST_F(NetEqImplTest, DecodingError) { |
| 997 UseNoMocks(); | 968 UseNoMocks(); |
| 998 CreateInstance(); | 969 CreateInstance(); |
| 999 | 970 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 // Insert packets. | 1039 // Insert packets. |
| 1069 for (int i = 0; i < 6; ++i) { | 1040 for (int i = 0; i < 6; ++i) { |
| 1070 rtp_header.header.sequenceNumber += 1; | 1041 rtp_header.header.sequenceNumber += 1; |
| 1071 rtp_header.header.timestamp += kFrameLengthSamples; | 1042 rtp_header.header.timestamp += kFrameLengthSamples; |
| 1072 EXPECT_EQ(NetEq::kOK, | 1043 EXPECT_EQ(NetEq::kOK, |
| 1073 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 1044 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 1074 } | 1045 } |
| 1075 | 1046 |
| 1076 // Pull audio. | 1047 // Pull audio. |
| 1077 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); | 1048 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); |
| 1078 int16_t output[kMaxOutputSize]; | 1049 AudioFrame output; |
| 1079 size_t samples_per_channel; | |
| 1080 size_t num_channels; | |
| 1081 NetEqOutputType type; | 1050 NetEqOutputType type; |
| 1082 EXPECT_EQ(NetEq::kOK, | 1051 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); |
| 1083 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 1052 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 1084 &num_channels, &type)); | 1053 EXPECT_EQ(1u, output.num_channels_); |
| 1085 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | |
| 1086 EXPECT_EQ(1u, num_channels); | |
| 1087 EXPECT_EQ(kOutputNormal, type); | 1054 EXPECT_EQ(kOutputNormal, type); |
| 1088 | 1055 |
| 1089 // Pull audio again. Decoder fails. | 1056 // Pull audio again. Decoder fails. |
| 1090 EXPECT_EQ(NetEq::kFail, | 1057 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&output, &type)); |
| 1091 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | |
| 1092 &num_channels, &type)); | |
| 1093 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); | 1058 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); |
| 1094 EXPECT_EQ(kDecoderErrorCode, neteq_->LastDecoderError()); | 1059 EXPECT_EQ(kDecoderErrorCode, neteq_->LastDecoderError()); |
| 1095 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | 1060 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 1096 EXPECT_EQ(1u, num_channels); | 1061 EXPECT_EQ(1u, output.num_channels_); |
| 1097 // TODO(minyue): should NetEq better give kOutputPLC, since it is actually an | 1062 // TODO(minyue): should NetEq better give kOutputPLC, since it is actually an |
| 1098 // expansion. | 1063 // expansion. |
| 1099 EXPECT_EQ(kOutputNormal, type); | 1064 EXPECT_EQ(kOutputNormal, type); |
| 1100 | 1065 |
| 1101 // Pull audio again, should continue an expansion. | 1066 // Pull audio again, should continue an expansion. |
| 1102 EXPECT_EQ(NetEq::kOK, | 1067 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); |
| 1103 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 1068 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 1104 &num_channels, &type)); | 1069 EXPECT_EQ(1u, output.num_channels_); |
| 1105 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | |
| 1106 EXPECT_EQ(1u, num_channels); | |
| 1107 EXPECT_EQ(kOutputPLC, type); | 1070 EXPECT_EQ(kOutputPLC, type); |
| 1108 | 1071 |
| 1109 // Pull audio again, should behave normal. | 1072 // Pull audio again, should behave normal. |
| 1110 EXPECT_EQ(NetEq::kOK, | 1073 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); |
| 1111 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 1074 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 1112 &num_channels, &type)); | 1075 EXPECT_EQ(1u, output.num_channels_); |
| 1113 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | |
| 1114 EXPECT_EQ(1u, num_channels); | |
| 1115 EXPECT_EQ(kOutputNormal, type); | 1076 EXPECT_EQ(kOutputNormal, type); |
| 1116 | 1077 |
| 1117 EXPECT_CALL(mock_decoder, Die()); | 1078 EXPECT_CALL(mock_decoder, Die()); |
| 1118 } | 1079 } |
| 1119 | 1080 |
| 1120 // This test checks the behavior of NetEq when audio decoder fails during CNG. | 1081 // This test checks the behavior of NetEq when audio decoder fails during CNG. |
| 1121 TEST_F(NetEqImplTest, DecodingErrorDuringInternalCng) { | 1082 TEST_F(NetEqImplTest, DecodingErrorDuringInternalCng) { |
| 1122 UseNoMocks(); | 1083 UseNoMocks(); |
| 1123 CreateInstance(); | 1084 CreateInstance(); |
| 1124 | 1085 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 // Insert 2 packets. This will make netEq into codec internal CNG mode. | 1150 // Insert 2 packets. This will make netEq into codec internal CNG mode. |
| 1190 for (int i = 0; i < 2; ++i) { | 1151 for (int i = 0; i < 2; ++i) { |
| 1191 rtp_header.header.sequenceNumber += 1; | 1152 rtp_header.header.sequenceNumber += 1; |
| 1192 rtp_header.header.timestamp += kFrameLengthSamples; | 1153 rtp_header.header.timestamp += kFrameLengthSamples; |
| 1193 EXPECT_EQ(NetEq::kOK, | 1154 EXPECT_EQ(NetEq::kOK, |
| 1194 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 1155 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 1195 } | 1156 } |
| 1196 | 1157 |
| 1197 // Pull audio. | 1158 // Pull audio. |
| 1198 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); | 1159 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); |
| 1199 int16_t output[kMaxOutputSize]; | 1160 AudioFrame output; |
| 1200 size_t samples_per_channel; | |
| 1201 size_t num_channels; | |
| 1202 NetEqOutputType type; | 1161 NetEqOutputType type; |
| 1203 EXPECT_EQ(NetEq::kOK, | 1162 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); |
| 1204 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 1163 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 1205 &num_channels, &type)); | 1164 EXPECT_EQ(1u, output.num_channels_); |
| 1206 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | |
| 1207 EXPECT_EQ(1u, num_channels); | |
| 1208 EXPECT_EQ(kOutputCNG, type); | 1165 EXPECT_EQ(kOutputCNG, type); |
| 1209 | 1166 |
| 1210 // Pull audio again. Decoder fails. | 1167 // Pull audio again. Decoder fails. |
| 1211 EXPECT_EQ(NetEq::kFail, | 1168 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&output, &type)); |
| 1212 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | |
| 1213 &num_channels, &type)); | |
| 1214 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); | 1169 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); |
| 1215 EXPECT_EQ(kDecoderErrorCode, neteq_->LastDecoderError()); | 1170 EXPECT_EQ(kDecoderErrorCode, neteq_->LastDecoderError()); |
| 1216 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | 1171 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 1217 EXPECT_EQ(1u, num_channels); | 1172 EXPECT_EQ(1u, output.num_channels_); |
| 1218 // TODO(minyue): should NetEq better give kOutputPLC, since it is actually an | 1173 // TODO(minyue): should NetEq better give kOutputPLC, since it is actually an |
| 1219 // expansion. | 1174 // expansion. |
| 1220 EXPECT_EQ(kOutputCNG, type); | 1175 EXPECT_EQ(kOutputCNG, type); |
| 1221 | 1176 |
| 1222 // Pull audio again, should resume codec CNG. | 1177 // Pull audio again, should resume codec CNG. |
| 1223 EXPECT_EQ(NetEq::kOK, | 1178 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); |
| 1224 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 1179 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 1225 &num_channels, &type)); | 1180 EXPECT_EQ(1u, output.num_channels_); |
| 1226 EXPECT_EQ(kMaxOutputSize, samples_per_channel); | |
| 1227 EXPECT_EQ(1u, num_channels); | |
| 1228 EXPECT_EQ(kOutputCNG, type); | 1181 EXPECT_EQ(kOutputCNG, type); |
| 1229 | 1182 |
| 1230 EXPECT_CALL(mock_decoder, Die()); | 1183 EXPECT_CALL(mock_decoder, Die()); |
| 1231 } | 1184 } |
| 1232 | 1185 |
| 1233 // Tests that the return value from last_output_sample_rate_hz() is equal to the | 1186 // Tests that the return value from last_output_sample_rate_hz() is equal to the |
| 1234 // configured inital sample rate. | 1187 // configured inital sample rate. |
| 1235 TEST_F(NetEqImplTest, InitialLastOutputSampleRate) { | 1188 TEST_F(NetEqImplTest, InitialLastOutputSampleRate) { |
| 1236 UseNoMocks(); | 1189 UseNoMocks(); |
| 1237 config_.sample_rate_hz = 48000; | 1190 config_.sample_rate_hz = 48000; |
| 1238 CreateInstance(); | 1191 CreateInstance(); |
| 1239 EXPECT_EQ(48000, neteq_->last_output_sample_rate_hz()); | 1192 EXPECT_EQ(48000, neteq_->last_output_sample_rate_hz()); |
| 1240 } | 1193 } |
| 1241 | 1194 |
| 1242 }// namespace webrtc | 1195 }// namespace webrtc |
| OLD | NEW |