Chromium Code Reviews| 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 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 659 rtp_header.header.sequenceNumber = 0x1234; | 659 rtp_header.header.sequenceNumber = 0x1234; |
| 660 rtp_header.header.timestamp = 0x12345678; | 660 rtp_header.header.timestamp = 0x12345678; |
| 661 rtp_header.header.ssrc = 0x87654321; | 661 rtp_header.header.ssrc = 0x87654321; |
| 662 | 662 |
| 663 // Create a mock decoder object. | 663 // Create a mock decoder object. |
| 664 MockAudioDecoder mock_decoder; | 664 MockAudioDecoder mock_decoder; |
| 665 EXPECT_CALL(mock_decoder, Reset()).WillRepeatedly(Return()); | 665 EXPECT_CALL(mock_decoder, Reset()).WillRepeatedly(Return()); |
| 666 EXPECT_CALL(mock_decoder, Channels()).WillRepeatedly(Return(1)); | 666 EXPECT_CALL(mock_decoder, Channels()).WillRepeatedly(Return(1)); |
| 667 EXPECT_CALL(mock_decoder, IncomingPacket(_, kPayloadLengthBytes, _, _, _)) | 667 EXPECT_CALL(mock_decoder, IncomingPacket(_, kPayloadLengthBytes, _, _, _)) |
| 668 .WillRepeatedly(Return(0)); | 668 .WillRepeatedly(Return(0)); |
| 669 EXPECT_CALL(mock_decoder, PacketDuration(_, kPayloadLengthBytes)) | |
| 670 .WillRepeatedly(Return(kPayloadLengthSamples)); | |
| 671 // Packed duration when asking the decoder for more CNG data (without a new | |
| 672 // packet). | |
| 673 EXPECT_CALL(mock_decoder, PacketDuration(nullptr, 0)) | |
| 674 .WillRepeatedly(Return(kPayloadLengthSamples)); | |
| 669 | 675 |
| 670 // Pointee(x) verifies that first byte of the payload equals x, this makes it | 676 // Pointee(x) verifies that first byte of the payload equals x, this makes it |
| 671 // possible to verify that the correct payload is fed to Decode(). | 677 // possible to verify that the correct payload is fed to Decode(). |
| 672 EXPECT_CALL(mock_decoder, DecodeInternal(Pointee(0), kPayloadLengthBytes, | 678 EXPECT_CALL(mock_decoder, DecodeInternal(Pointee(0), kPayloadLengthBytes, |
| 673 kSampleRateKhz * 1000, _, _)) | 679 kSampleRateKhz * 1000, _, _)) |
| 674 .WillOnce(DoAll(SetArrayArgument<3>(dummy_output, | 680 .WillOnce(DoAll(SetArrayArgument<3>(dummy_output, |
| 675 dummy_output + kPayloadLengthSamples), | 681 dummy_output + kPayloadLengthSamples), |
| 676 SetArgPointee<4>(AudioDecoder::kSpeech), | 682 SetArgPointee<4>(AudioDecoder::kSpeech), |
| 677 Return(kPayloadLengthSamples))); | 683 Return(kPayloadLengthSamples))); |
| 678 | 684 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 716 AudioFrame output; | 722 AudioFrame output; |
| 717 AudioFrame::SpeechType expected_type[8] = { | 723 AudioFrame::SpeechType expected_type[8] = { |
| 718 AudioFrame::kNormalSpeech, AudioFrame::kNormalSpeech, | 724 AudioFrame::kNormalSpeech, AudioFrame::kNormalSpeech, |
| 719 AudioFrame::kCNG, AudioFrame::kCNG, | 725 AudioFrame::kCNG, AudioFrame::kCNG, |
| 720 AudioFrame::kCNG, AudioFrame::kCNG, | 726 AudioFrame::kCNG, AudioFrame::kCNG, |
| 721 AudioFrame::kNormalSpeech, AudioFrame::kNormalSpeech | 727 AudioFrame::kNormalSpeech, AudioFrame::kNormalSpeech |
| 722 }; | 728 }; |
| 723 int expected_timestamp_increment[8] = { | 729 int expected_timestamp_increment[8] = { |
| 724 -1, // will not be used. | 730 -1, // will not be used. |
| 725 10 * kSampleRateKhz, | 731 10 * kSampleRateKhz, |
| 726 0, 0, // timestamp does not increase during CNG mode. | 732 -1, -1, // timestamp will be empty during CNG mode; indicated by -1 here. |
| 727 0, 0, | 733 -1, -1, |
| 728 50 * kSampleRateKhz, 10 * kSampleRateKhz | 734 50 * kSampleRateKhz, 10 * kSampleRateKhz |
| 729 }; | 735 }; |
| 730 | 736 |
| 731 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output)); | 737 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output)); |
| 732 rtc::Optional<uint32_t> last_timestamp = neteq_->GetPlayoutTimestamp(); | 738 rtc::Optional<uint32_t> last_timestamp = neteq_->GetPlayoutTimestamp(); |
| 733 ASSERT_TRUE(last_timestamp); | 739 ASSERT_TRUE(last_timestamp); |
| 734 | 740 |
| 741 // Lambda for verifying the timestamps. | |
|
minyue-webrtc
2016/04/06 18:13:07
I like it
| |
| 742 auto verify_timestamp = [&last_timestamp, &expected_timestamp_increment]( | |
| 743 rtc::Optional<uint32_t> ts, size_t i) { | |
| 744 if (expected_timestamp_increment[i] == -1) { | |
| 745 // Expect to get an empty timestamp value during CNG and PLC. | |
| 746 EXPECT_FALSE(ts) << "i = " << i; | |
| 747 } else { | |
| 748 ASSERT_TRUE(ts) << "i = " << i; | |
| 749 EXPECT_EQ(*ts, *last_timestamp + expected_timestamp_increment[i]) | |
| 750 << "i = " << i; | |
| 751 last_timestamp = ts; | |
| 752 } | |
| 753 }; | |
| 754 | |
| 735 for (size_t i = 1; i < 6; ++i) { | 755 for (size_t i = 1; i < 6; ++i) { |
| 736 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); | 756 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 737 EXPECT_EQ(1u, output.num_channels_); | 757 EXPECT_EQ(1u, output.num_channels_); |
| 738 EXPECT_EQ(expected_type[i - 1], output.speech_type_); | 758 EXPECT_EQ(expected_type[i - 1], output.speech_type_); |
| 739 rtc::Optional<uint32_t> timestamp = neteq_->GetPlayoutTimestamp(); | |
| 740 EXPECT_TRUE(timestamp); | |
| 741 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output)); | 759 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output)); |
| 742 timestamp = neteq_->GetPlayoutTimestamp(); | 760 SCOPED_TRACE(""); |
|
minyue-webrtc
2016/04/06 18:13:07
what does this do?
hlundin-webrtc
2016/04/06 18:21:39
If a failure happens in the lambda, a printout wil
| |
| 743 ASSERT_TRUE(timestamp); | 761 verify_timestamp(neteq_->GetPlayoutTimestamp(), i); |
| 744 EXPECT_EQ(*timestamp, *last_timestamp + expected_timestamp_increment[i]); | |
| 745 last_timestamp = timestamp; | |
| 746 } | 762 } |
| 747 | 763 |
| 748 // Insert third packet, which leaves a gap from last packet. | 764 // Insert third packet, which leaves a gap from last packet. |
| 749 payload[0] = 2; | 765 payload[0] = 2; |
| 750 rtp_header.header.sequenceNumber += 2; | 766 rtp_header.header.sequenceNumber += 2; |
| 751 rtp_header.header.timestamp += 2 * kPayloadLengthSamples; | 767 rtp_header.header.timestamp += 2 * kPayloadLengthSamples; |
| 752 EXPECT_EQ(NetEq::kOK, | 768 EXPECT_EQ(NetEq::kOK, |
| 753 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); | 769 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); |
| 754 | 770 |
| 755 for (size_t i = 6; i < 8; ++i) { | 771 for (size_t i = 6; i < 8; ++i) { |
| 756 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); | 772 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); |
| 757 EXPECT_EQ(1u, output.num_channels_); | 773 EXPECT_EQ(1u, output.num_channels_); |
| 758 EXPECT_EQ(expected_type[i - 1], output.speech_type_); | 774 EXPECT_EQ(expected_type[i - 1], output.speech_type_); |
| 759 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output)); | 775 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output)); |
| 760 rtc::Optional<uint32_t> timestamp = neteq_->GetPlayoutTimestamp(); | 776 SCOPED_TRACE(""); |
| 761 ASSERT_TRUE(timestamp); | 777 verify_timestamp(neteq_->GetPlayoutTimestamp(), i); |
| 762 EXPECT_EQ(*timestamp, *last_timestamp + expected_timestamp_increment[i]); | |
| 763 last_timestamp = timestamp; | |
| 764 } | 778 } |
| 765 | 779 |
| 766 // Now check the packet buffer, and make sure it is empty. | 780 // Now check the packet buffer, and make sure it is empty. |
| 767 EXPECT_TRUE(packet_buffer_->Empty()); | 781 EXPECT_TRUE(packet_buffer_->Empty()); |
| 768 | 782 |
| 769 EXPECT_CALL(mock_decoder, Die()); | 783 EXPECT_CALL(mock_decoder, Die()); |
| 770 } | 784 } |
| 771 | 785 |
| 772 TEST_F(NetEqImplTest, UnsupportedDecoder) { | 786 TEST_F(NetEqImplTest, UnsupportedDecoder) { |
| 773 UseNoMocks(); | 787 UseNoMocks(); |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1178 // Tests that the return value from last_output_sample_rate_hz() is equal to the | 1192 // Tests that the return value from last_output_sample_rate_hz() is equal to the |
| 1179 // configured inital sample rate. | 1193 // configured inital sample rate. |
| 1180 TEST_F(NetEqImplTest, InitialLastOutputSampleRate) { | 1194 TEST_F(NetEqImplTest, InitialLastOutputSampleRate) { |
| 1181 UseNoMocks(); | 1195 UseNoMocks(); |
| 1182 config_.sample_rate_hz = 48000; | 1196 config_.sample_rate_hz = 48000; |
| 1183 CreateInstance(); | 1197 CreateInstance(); |
| 1184 EXPECT_EQ(48000, neteq_->last_output_sample_rate_hz()); | 1198 EXPECT_EQ(48000, neteq_->last_output_sample_rate_hz()); |
| 1185 } | 1199 } |
| 1186 | 1200 |
| 1187 }// namespace webrtc | 1201 }// namespace webrtc |
| OLD | NEW |