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

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

Issue 1769883002: Remove the type parameter to NetEq::GetAudio (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@acm-rec-delete-vad
Patch Set: After review Created 4 years, 9 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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 &decoder_, NetEqDecoder::kDecoderPCM16B, 459 &decoder_, NetEqDecoder::kDecoderPCM16B,
460 "dummy name", kPayloadType, kSampleRateHz)); 460 "dummy name", kPayloadType, kSampleRateHz));
461 461
462 // Insert one packet. 462 // Insert one packet.
463 EXPECT_EQ(NetEq::kOK, 463 EXPECT_EQ(NetEq::kOK,
464 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); 464 neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
465 465
466 // Pull audio once. 466 // Pull audio once.
467 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); 467 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000);
468 AudioFrame output; 468 AudioFrame output;
469 NetEqOutputType type; 469 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
470 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type));
471 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); 470 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_);
472 EXPECT_EQ(1u, output.num_channels_); 471 EXPECT_EQ(1u, output.num_channels_);
473 EXPECT_EQ(kOutputNormal, type); 472 EXPECT_EQ(AudioFrame::kNormalSpeech, output.speech_type_);
474 473
475 // Start with a simple check that the fake decoder is behaving as expected. 474 // Start with a simple check that the fake decoder is behaving as expected.
476 EXPECT_EQ(kPayloadLengthSamples, 475 EXPECT_EQ(kPayloadLengthSamples,
477 static_cast<size_t>(decoder_.next_value() - 1)); 476 static_cast<size_t>(decoder_.next_value() - 1));
478 477
479 // The value of the last of the output samples is the same as the number of 478 // The value of the last of the output samples is the same as the number of
480 // samples played from the decoded packet. Thus, this number + the RTP 479 // samples played from the decoded packet. Thus, this number + the RTP
481 // timestamp should match the playout timestamp. 480 // timestamp should match the playout timestamp.
482 uint32_t timestamp = 0; 481 uint32_t timestamp = 0;
483 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp)); 482 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 &mock_decoder, NetEqDecoder::kDecoderPCM16B, 534 &mock_decoder, NetEqDecoder::kDecoderPCM16B,
536 "dummy name", kPayloadType, kSampleRateHz)); 535 "dummy name", kPayloadType, kSampleRateHz));
537 536
538 // Insert one packet. 537 // Insert one packet.
539 EXPECT_EQ(NetEq::kOK, 538 EXPECT_EQ(NetEq::kOK,
540 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); 539 neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
541 540
542 // Pull audio once. 541 // Pull audio once.
543 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); 542 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000);
544 AudioFrame output; 543 AudioFrame output;
545 NetEqOutputType type; 544 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
546 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type));
547 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); 545 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_);
548 EXPECT_EQ(1u, output.num_channels_); 546 EXPECT_EQ(1u, output.num_channels_);
549 EXPECT_EQ(kOutputNormal, type); 547 EXPECT_EQ(AudioFrame::kNormalSpeech, output.speech_type_);
550 548
551 // Insert two more packets. The first one is out of order, and is already too 549 // Insert two more packets. The first one is out of order, and is already too
552 // old, the second one is the expected next packet. 550 // old, the second one is the expected next packet.
553 rtp_header.header.sequenceNumber -= 1; 551 rtp_header.header.sequenceNumber -= 1;
554 rtp_header.header.timestamp -= kPayloadLengthSamples; 552 rtp_header.header.timestamp -= kPayloadLengthSamples;
555 payload[0] = 1; 553 payload[0] = 1;
556 EXPECT_EQ(NetEq::kOK, 554 EXPECT_EQ(NetEq::kOK,
557 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); 555 neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
558 rtp_header.header.sequenceNumber += 2; 556 rtp_header.header.sequenceNumber += 2;
559 rtp_header.header.timestamp += 2 * kPayloadLengthSamples; 557 rtp_header.header.timestamp += 2 * kPayloadLengthSamples;
560 payload[0] = 2; 558 payload[0] = 2;
561 EXPECT_EQ(NetEq::kOK, 559 EXPECT_EQ(NetEq::kOK,
562 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); 560 neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
563 561
564 // Expect only the second packet to be decoded (the one with "2" as the first 562 // Expect only the second packet to be decoded (the one with "2" as the first
565 // payload byte). 563 // payload byte).
566 EXPECT_CALL(mock_decoder, DecodeInternal(Pointee(2), kPayloadLengthBytes, 564 EXPECT_CALL(mock_decoder, DecodeInternal(Pointee(2), kPayloadLengthBytes,
567 kSampleRateHz, _, _)) 565 kSampleRateHz, _, _))
568 .WillOnce(DoAll(SetArrayArgument<3>(dummy_output, 566 .WillOnce(DoAll(SetArrayArgument<3>(dummy_output,
569 dummy_output + kPayloadLengthSamples), 567 dummy_output + kPayloadLengthSamples),
570 SetArgPointee<4>(AudioDecoder::kSpeech), 568 SetArgPointee<4>(AudioDecoder::kSpeech),
571 Return(kPayloadLengthSamples))); 569 Return(kPayloadLengthSamples)));
572 570
573 // Pull audio once. 571 // Pull audio once.
574 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); 572 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
575 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); 573 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_);
576 EXPECT_EQ(1u, output.num_channels_); 574 EXPECT_EQ(1u, output.num_channels_);
577 EXPECT_EQ(kOutputNormal, type); 575 EXPECT_EQ(AudioFrame::kNormalSpeech, output.speech_type_);
578 576
579 // Now check the packet buffer, and make sure it is empty, since the 577 // Now check the packet buffer, and make sure it is empty, since the
580 // out-of-order packet should have been discarded. 578 // out-of-order packet should have been discarded.
581 EXPECT_TRUE(packet_buffer_->Empty()); 579 EXPECT_TRUE(packet_buffer_->Empty());
582 580
583 EXPECT_CALL(mock_decoder, Die()); 581 EXPECT_CALL(mock_decoder, Die());
584 } 582 }
585 583
586 // This test verifies that NetEq can handle the situation where the first 584 // This test verifies that NetEq can handle the situation where the first
587 // incoming packet is rejected. 585 // incoming packet is rejected.
(...skipping 16 matching lines...) Expand all
604 602
605 // Insert one packet. Note that we have not registered any payload type, so 603 // Insert one packet. Note that we have not registered any payload type, so
606 // this packet will be rejected. 604 // this packet will be rejected.
607 EXPECT_EQ(NetEq::kFail, 605 EXPECT_EQ(NetEq::kFail,
608 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); 606 neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
609 EXPECT_EQ(NetEq::kUnknownRtpPayloadType, neteq_->LastError()); 607 EXPECT_EQ(NetEq::kUnknownRtpPayloadType, neteq_->LastError());
610 608
611 // Pull audio once. 609 // Pull audio once.
612 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); 610 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000);
613 AudioFrame output; 611 AudioFrame output;
614 NetEqOutputType type; 612 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
615 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type));
616 ASSERT_LE(output.samples_per_channel_, kMaxOutputSize); 613 ASSERT_LE(output.samples_per_channel_, kMaxOutputSize);
617 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); 614 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_);
618 EXPECT_EQ(1u, output.num_channels_); 615 EXPECT_EQ(1u, output.num_channels_);
619 EXPECT_EQ(kOutputPLC, type); 616 EXPECT_EQ(AudioFrame::kPLC, output.speech_type_);
620 617
621 // Register the payload type. 618 // Register the payload type.
622 EXPECT_EQ(NetEq::kOK, neteq_->RegisterPayloadType( 619 EXPECT_EQ(NetEq::kOK, neteq_->RegisterPayloadType(
623 NetEqDecoder::kDecoderPCM16B, "", kPayloadType)); 620 NetEqDecoder::kDecoderPCM16B, "", kPayloadType));
624 621
625 // Insert 10 packets. 622 // Insert 10 packets.
626 for (size_t i = 0; i < 10; ++i) { 623 for (size_t i = 0; i < 10; ++i) {
627 rtp_header.header.sequenceNumber++; 624 rtp_header.header.sequenceNumber++;
628 rtp_header.header.timestamp += kPayloadLengthSamples; 625 rtp_header.header.timestamp += kPayloadLengthSamples;
629 EXPECT_EQ(NetEq::kOK, 626 EXPECT_EQ(NetEq::kOK,
630 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); 627 neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
631 EXPECT_EQ(i + 1, packet_buffer_->NumPacketsInBuffer()); 628 EXPECT_EQ(i + 1, packet_buffer_->NumPacketsInBuffer());
632 } 629 }
633 630
634 // Pull audio repeatedly and make sure we get normal output, that is not PLC. 631 // Pull audio repeatedly and make sure we get normal output, that is not PLC.
635 for (size_t i = 0; i < 3; ++i) { 632 for (size_t i = 0; i < 3; ++i) {
636 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); 633 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
637 ASSERT_LE(output.samples_per_channel_, kMaxOutputSize); 634 ASSERT_LE(output.samples_per_channel_, kMaxOutputSize);
638 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); 635 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_);
639 EXPECT_EQ(1u, output.num_channels_); 636 EXPECT_EQ(1u, output.num_channels_);
640 EXPECT_EQ(kOutputNormal, type) 637 EXPECT_EQ(AudioFrame::kNormalSpeech, output.speech_type_)
641 << "NetEq did not decode the packets as expected."; 638 << "NetEq did not decode the packets as expected.";
642 } 639 }
643 } 640 }
644 641
645 // This test verifies that NetEq can handle comfort noise and enters/quits codec 642 // This test verifies that NetEq can handle comfort noise and enters/quits codec
646 // internal CNG mode properly. 643 // internal CNG mode properly.
647 TEST_F(NetEqImplTest, CodecInternalCng) { 644 TEST_F(NetEqImplTest, CodecInternalCng) {
648 UseNoMocks(); 645 UseNoMocks();
649 CreateInstance(); 646 CreateInstance();
650 647
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 payload[0] = 1; 709 payload[0] = 1;
713 rtp_header.header.sequenceNumber++; 710 rtp_header.header.sequenceNumber++;
714 rtp_header.header.timestamp += kPayloadLengthSamples; 711 rtp_header.header.timestamp += kPayloadLengthSamples;
715 EXPECT_EQ(NetEq::kOK, 712 EXPECT_EQ(NetEq::kOK,
716 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); 713 neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
717 714
718 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateKhz); 715 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateKhz);
719 AudioFrame output; 716 AudioFrame output;
720 uint32_t timestamp; 717 uint32_t timestamp;
721 uint32_t last_timestamp; 718 uint32_t last_timestamp;
722 NetEqOutputType type; 719 AudioFrame::SpeechType expected_type[8] = {
723 NetEqOutputType expected_type[8] = { 720 AudioFrame::kNormalSpeech, AudioFrame::kNormalSpeech,
724 kOutputNormal, kOutputNormal, 721 AudioFrame::kCNG, AudioFrame::kCNG,
725 kOutputCNG, kOutputCNG, 722 AudioFrame::kCNG, AudioFrame::kCNG,
726 kOutputCNG, kOutputCNG, 723 AudioFrame::kNormalSpeech, AudioFrame::kNormalSpeech
727 kOutputNormal, kOutputNormal
728 }; 724 };
729 int expected_timestamp_increment[8] = { 725 int expected_timestamp_increment[8] = {
730 -1, // will not be used. 726 -1, // will not be used.
731 10 * kSampleRateKhz, 727 10 * kSampleRateKhz,
732 0, 0, // timestamp does not increase during CNG mode. 728 0, 0, // timestamp does not increase during CNG mode.
733 0, 0, 729 0, 0,
734 50 * kSampleRateKhz, 10 * kSampleRateKhz 730 50 * kSampleRateKhz, 10 * kSampleRateKhz
735 }; 731 };
736 732
737 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); 733 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
738 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&last_timestamp)); 734 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&last_timestamp));
739 735
740 for (size_t i = 1; i < 6; ++i) { 736 for (size_t i = 1; i < 6; ++i) {
741 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); 737 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_);
742 EXPECT_EQ(1u, output.num_channels_); 738 EXPECT_EQ(1u, output.num_channels_);
743 EXPECT_EQ(expected_type[i - 1], type); 739 EXPECT_EQ(expected_type[i - 1], output.speech_type_);
744 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp)); 740 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp));
745 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); 741 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
746 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp)); 742 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp));
747 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]); 743 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]);
748 last_timestamp = timestamp; 744 last_timestamp = timestamp;
749 } 745 }
750 746
751 // Insert third packet, which leaves a gap from last packet. 747 // Insert third packet, which leaves a gap from last packet.
752 payload[0] = 2; 748 payload[0] = 2;
753 rtp_header.header.sequenceNumber += 2; 749 rtp_header.header.sequenceNumber += 2;
754 rtp_header.header.timestamp += 2 * kPayloadLengthSamples; 750 rtp_header.header.timestamp += 2 * kPayloadLengthSamples;
755 EXPECT_EQ(NetEq::kOK, 751 EXPECT_EQ(NetEq::kOK,
756 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); 752 neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
757 753
758 for (size_t i = 6; i < 8; ++i) { 754 for (size_t i = 6; i < 8; ++i) {
759 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); 755 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_);
760 EXPECT_EQ(1u, output.num_channels_); 756 EXPECT_EQ(1u, output.num_channels_);
761 EXPECT_EQ(expected_type[i - 1], type); 757 EXPECT_EQ(expected_type[i - 1], output.speech_type_);
762 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); 758 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
763 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp)); 759 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp));
764 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]); 760 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]);
765 last_timestamp = timestamp; 761 last_timestamp = timestamp;
766 } 762 }
767 763
768 // Now check the packet buffer, and make sure it is empty. 764 // Now check the packet buffer, and make sure it is empty.
769 EXPECT_TRUE(packet_buffer_->Empty()); 765 EXPECT_TRUE(packet_buffer_->Empty());
770 766
771 EXPECT_CALL(mock_decoder, Die()); 767 EXPECT_CALL(mock_decoder, Die());
772 } 768 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 // Insert another packet. 837 // Insert another packet.
842 payload[0] = kSecondPayloadValue; // This will make Decode() successful. 838 payload[0] = kSecondPayloadValue; // This will make Decode() successful.
843 rtp_header.header.sequenceNumber++; 839 rtp_header.header.sequenceNumber++;
844 // The second timestamp needs to be at least 30 ms after the first to make 840 // The second timestamp needs to be at least 30 ms after the first to make
845 // the second packet get decoded. 841 // the second packet get decoded.
846 rtp_header.header.timestamp += 3 * kPayloadLengthSamples; 842 rtp_header.header.timestamp += 3 * kPayloadLengthSamples;
847 EXPECT_EQ(NetEq::kOK, 843 EXPECT_EQ(NetEq::kOK,
848 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); 844 neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
849 845
850 AudioFrame output; 846 AudioFrame output;
851 NetEqOutputType type;
852 // First call to GetAudio will try to decode the "faulty" packet. 847 // First call to GetAudio will try to decode the "faulty" packet.
853 // Expect kFail return value... 848 // Expect kFail return value...
854 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&output, &type)); 849 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&output));
855 // ... and kOtherDecoderError error code. 850 // ... and kOtherDecoderError error code.
856 EXPECT_EQ(NetEq::kOtherDecoderError, neteq_->LastError()); 851 EXPECT_EQ(NetEq::kOtherDecoderError, neteq_->LastError());
857 // Output size and number of channels should be correct. 852 // Output size and number of channels should be correct.
858 const size_t kExpectedOutputSize = 10 * (kSampleRateHz / 1000) * kChannels; 853 const size_t kExpectedOutputSize = 10 * (kSampleRateHz / 1000) * kChannels;
859 EXPECT_EQ(kExpectedOutputSize, output.samples_per_channel_ * kChannels); 854 EXPECT_EQ(kExpectedOutputSize, output.samples_per_channel_ * kChannels);
860 EXPECT_EQ(kChannels, output.num_channels_); 855 EXPECT_EQ(kChannels, output.num_channels_);
861 856
862 // Second call to GetAudio will decode the packet that is ok. No errors are 857 // Second call to GetAudio will decode the packet that is ok. No errors are
863 // expected. 858 // expected.
864 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); 859 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
865 EXPECT_EQ(kExpectedOutputSize, output.samples_per_channel_ * kChannels); 860 EXPECT_EQ(kExpectedOutputSize, output.samples_per_channel_ * kChannels);
866 EXPECT_EQ(kChannels, output.num_channels_); 861 EXPECT_EQ(kChannels, output.num_channels_);
867 } 862 }
868 863
869 // This test inserts packets until the buffer is flushed. After that, it asks 864 // This test inserts packets until the buffer is flushed. After that, it asks
870 // NetEq for the network statistics. The purpose of the test is to make sure 865 // NetEq for the network statistics. The purpose of the test is to make sure
871 // that even though the buffer size increment is negative (which it becomes when 866 // that even though the buffer size increment is negative (which it becomes when
872 // the packet causing a flush is inserted), the packet length stored in the 867 // the packet causing a flush is inserted), the packet length stored in the
873 // decision logic remains valid. 868 // decision logic remains valid.
874 TEST_F(NetEqImplTest, FloodBufferAndGetNetworkStats) { 869 TEST_F(NetEqImplTest, FloodBufferAndGetNetworkStats) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 942
948 // Insert one packet. 943 // Insert one packet.
949 EXPECT_EQ(NetEq::kOK, 944 EXPECT_EQ(NetEq::kOK,
950 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); 945 neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
951 946
952 EXPECT_EQ(5u, neteq_->sync_buffer_for_test()->FutureLength()); 947 EXPECT_EQ(5u, neteq_->sync_buffer_for_test()->FutureLength());
953 948
954 // Pull audio once. 949 // Pull audio once.
955 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); 950 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000);
956 AudioFrame output; 951 AudioFrame output;
957 NetEqOutputType type; 952 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
958 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type));
959 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); 953 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_);
960 EXPECT_EQ(1u, output.num_channels_); 954 EXPECT_EQ(1u, output.num_channels_);
961 EXPECT_EQ(kOutputNormal, type); 955 EXPECT_EQ(AudioFrame::kNormalSpeech, output.speech_type_);
962 956
963 EXPECT_CALL(mock_decoder, Die()); 957 EXPECT_CALL(mock_decoder, Die());
964 } 958 }
965 959
966 // This test checks the behavior of NetEq when audio decoder fails. 960 // This test checks the behavior of NetEq when audio decoder fails.
967 TEST_F(NetEqImplTest, DecodingError) { 961 TEST_F(NetEqImplTest, DecodingError) {
968 UseNoMocks(); 962 UseNoMocks();
969 CreateInstance(); 963 CreateInstance();
970 964
971 const uint8_t kPayloadType = 17; // Just an arbitrary number. 965 const uint8_t kPayloadType = 17; // Just an arbitrary number.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 for (int i = 0; i < 6; ++i) { 1034 for (int i = 0; i < 6; ++i) {
1041 rtp_header.header.sequenceNumber += 1; 1035 rtp_header.header.sequenceNumber += 1;
1042 rtp_header.header.timestamp += kFrameLengthSamples; 1036 rtp_header.header.timestamp += kFrameLengthSamples;
1043 EXPECT_EQ(NetEq::kOK, 1037 EXPECT_EQ(NetEq::kOK,
1044 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); 1038 neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
1045 } 1039 }
1046 1040
1047 // Pull audio. 1041 // Pull audio.
1048 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); 1042 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000);
1049 AudioFrame output; 1043 AudioFrame output;
1050 NetEqOutputType type; 1044 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
1051 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type));
1052 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); 1045 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_);
1053 EXPECT_EQ(1u, output.num_channels_); 1046 EXPECT_EQ(1u, output.num_channels_);
1054 EXPECT_EQ(kOutputNormal, type); 1047 EXPECT_EQ(AudioFrame::kNormalSpeech, output.speech_type_);
1055 1048
1056 // Pull audio again. Decoder fails. 1049 // Pull audio again. Decoder fails.
1057 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&output, &type)); 1050 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&output));
1058 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); 1051 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError());
1059 EXPECT_EQ(kDecoderErrorCode, neteq_->LastDecoderError()); 1052 EXPECT_EQ(kDecoderErrorCode, neteq_->LastDecoderError());
1060 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); 1053 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_);
1061 EXPECT_EQ(1u, output.num_channels_); 1054 EXPECT_EQ(1u, output.num_channels_);
1062 // TODO(minyue): should NetEq better give kOutputPLC, since it is actually an 1055 // We are not expecting anything for output.speech_type_, since an error was
1063 // expansion. 1056 // returned.
1064 EXPECT_EQ(kOutputNormal, type);
1065 1057
1066 // Pull audio again, should continue an expansion. 1058 // Pull audio again, should continue an expansion.
1067 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); 1059 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
1068 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); 1060 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_);
1069 EXPECT_EQ(1u, output.num_channels_); 1061 EXPECT_EQ(1u, output.num_channels_);
1070 EXPECT_EQ(kOutputPLC, type); 1062 EXPECT_EQ(AudioFrame::kPLC, output.speech_type_);
1071 1063
1072 // Pull audio again, should behave normal. 1064 // Pull audio again, should behave normal.
1073 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); 1065 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
1074 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); 1066 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_);
1075 EXPECT_EQ(1u, output.num_channels_); 1067 EXPECT_EQ(1u, output.num_channels_);
1076 EXPECT_EQ(kOutputNormal, type); 1068 EXPECT_EQ(AudioFrame::kNormalSpeech, output.speech_type_);
1077 1069
1078 EXPECT_CALL(mock_decoder, Die()); 1070 EXPECT_CALL(mock_decoder, Die());
1079 } 1071 }
1080 1072
1081 // This test checks the behavior of NetEq when audio decoder fails during CNG. 1073 // This test checks the behavior of NetEq when audio decoder fails during CNG.
1082 TEST_F(NetEqImplTest, DecodingErrorDuringInternalCng) { 1074 TEST_F(NetEqImplTest, DecodingErrorDuringInternalCng) {
1083 UseNoMocks(); 1075 UseNoMocks();
1084 CreateInstance(); 1076 CreateInstance();
1085 1077
1086 const uint8_t kPayloadType = 17; // Just an arbitrary number. 1078 const uint8_t kPayloadType = 17; // Just an arbitrary number.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 for (int i = 0; i < 2; ++i) { 1143 for (int i = 0; i < 2; ++i) {
1152 rtp_header.header.sequenceNumber += 1; 1144 rtp_header.header.sequenceNumber += 1;
1153 rtp_header.header.timestamp += kFrameLengthSamples; 1145 rtp_header.header.timestamp += kFrameLengthSamples;
1154 EXPECT_EQ(NetEq::kOK, 1146 EXPECT_EQ(NetEq::kOK,
1155 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); 1147 neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
1156 } 1148 }
1157 1149
1158 // Pull audio. 1150 // Pull audio.
1159 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); 1151 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000);
1160 AudioFrame output; 1152 AudioFrame output;
1161 NetEqOutputType type; 1153 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
1162 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type));
1163 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); 1154 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_);
1164 EXPECT_EQ(1u, output.num_channels_); 1155 EXPECT_EQ(1u, output.num_channels_);
1165 EXPECT_EQ(kOutputCNG, type); 1156 EXPECT_EQ(AudioFrame::kCNG, output.speech_type_);
1166 1157
1167 // Pull audio again. Decoder fails. 1158 // Pull audio again. Decoder fails.
1168 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&output, &type)); 1159 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&output));
1169 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); 1160 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError());
1170 EXPECT_EQ(kDecoderErrorCode, neteq_->LastDecoderError()); 1161 EXPECT_EQ(kDecoderErrorCode, neteq_->LastDecoderError());
1171 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); 1162 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_);
1172 EXPECT_EQ(1u, output.num_channels_); 1163 EXPECT_EQ(1u, output.num_channels_);
1173 // TODO(minyue): should NetEq better give kOutputPLC, since it is actually an 1164 // We are not expecting anything for output.speech_type_, since an error was
1174 // expansion. 1165 // returned.
1175 EXPECT_EQ(kOutputCNG, type);
1176 1166
1177 // Pull audio again, should resume codec CNG. 1167 // Pull audio again, should resume codec CNG.
1178 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &type)); 1168 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
1179 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_); 1169 EXPECT_EQ(kMaxOutputSize, output.samples_per_channel_);
1180 EXPECT_EQ(1u, output.num_channels_); 1170 EXPECT_EQ(1u, output.num_channels_);
1181 EXPECT_EQ(kOutputCNG, type); 1171 EXPECT_EQ(AudioFrame::kCNG, output.speech_type_);
1182 1172
1183 EXPECT_CALL(mock_decoder, Die()); 1173 EXPECT_CALL(mock_decoder, Die());
1184 } 1174 }
1185 1175
1186 // Tests that the return value from last_output_sample_rate_hz() is equal to the 1176 // Tests that the return value from last_output_sample_rate_hz() is equal to the
1187 // configured inital sample rate. 1177 // configured inital sample rate.
1188 TEST_F(NetEqImplTest, InitialLastOutputSampleRate) { 1178 TEST_F(NetEqImplTest, InitialLastOutputSampleRate) {
1189 UseNoMocks(); 1179 UseNoMocks();
1190 config_.sample_rate_hz = 48000; 1180 config_.sample_rate_hz = 48000;
1191 CreateInstance(); 1181 CreateInstance();
1192 EXPECT_EQ(48000, neteq_->last_output_sample_rate_hz()); 1182 EXPECT_EQ(48000, neteq_->last_output_sample_rate_hz());
1193 } 1183 }
1194 1184
1195 }// namespace webrtc 1185 }// namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/neteq_impl.cc ('k') | webrtc/modules/audio_coding/neteq/neteq_network_stats_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698