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 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 rtp_header.header.timestamp += | 935 rtp_header.header.timestamp += |
936 rtc::checked_cast<uint32_t>(kPayloadLengthSamples); | 936 rtc::checked_cast<uint32_t>(kPayloadLengthSamples); |
937 ++rtp_header.header.sequenceNumber; | 937 ++rtp_header.header.sequenceNumber; |
938 } | 938 } |
939 EXPECT_EQ(1u, packet_buffer_->NumPacketsInBuffer()); | 939 EXPECT_EQ(1u, packet_buffer_->NumPacketsInBuffer()); |
940 | 940 |
941 // Ask for network statistics. This should not crash. | 941 // Ask for network statistics. This should not crash. |
942 NetEqNetworkStatistics stats; | 942 NetEqNetworkStatistics stats; |
943 EXPECT_EQ(NetEq::kOK, neteq_->NetworkStatistics(&stats)); | 943 EXPECT_EQ(NetEq::kOK, neteq_->NetworkStatistics(&stats)); |
944 } | 944 } |
| 945 |
| 946 TEST_F(NetEqImplTest, DecodedPayloadTooShort) { |
| 947 UseNoMocks(); |
| 948 CreateInstance(); |
| 949 |
| 950 const uint8_t kPayloadType = 17; // Just an arbitrary number. |
| 951 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test. |
| 952 const int kSampleRateHz = 8000; |
| 953 const size_t kPayloadLengthSamples = |
| 954 static_cast<size_t>(10 * kSampleRateHz / 1000); // 10 ms. |
| 955 const size_t kPayloadLengthBytes = 2 * kPayloadLengthSamples; |
| 956 uint8_t payload[kPayloadLengthBytes] = {0}; |
| 957 WebRtcRTPHeader rtp_header; |
| 958 rtp_header.header.payloadType = kPayloadType; |
| 959 rtp_header.header.sequenceNumber = 0x1234; |
| 960 rtp_header.header.timestamp = 0x12345678; |
| 961 rtp_header.header.ssrc = 0x87654321; |
| 962 |
| 963 // Create a mock decoder object. |
| 964 MockAudioDecoder mock_decoder; |
| 965 EXPECT_CALL(mock_decoder, Reset()).WillRepeatedly(Return()); |
| 966 EXPECT_CALL(mock_decoder, Channels()).WillRepeatedly(Return(1)); |
| 967 EXPECT_CALL(mock_decoder, IncomingPacket(_, kPayloadLengthBytes, _, _, _)) |
| 968 .WillRepeatedly(Return(0)); |
| 969 EXPECT_CALL(mock_decoder, PacketDuration(_, _)) |
| 970 .WillRepeatedly(Return(kPayloadLengthSamples)); |
| 971 int16_t dummy_output[kPayloadLengthSamples] = {0}; |
| 972 // The below expectation will make the mock decoder write |
| 973 // |kPayloadLengthSamples| - 5 zeros to the output array, and mark it as |
| 974 // speech. That is, the decoded length is 5 samples shorter than the expected. |
| 975 EXPECT_CALL(mock_decoder, |
| 976 Decode(_, kPayloadLengthBytes, kSampleRateHz, _, _, _)) |
| 977 .WillOnce( |
| 978 DoAll(SetArrayArgument<4>(dummy_output, |
| 979 dummy_output + kPayloadLengthSamples - 5), |
| 980 SetArgPointee<5>(AudioDecoder::kSpeech), |
| 981 Return(kPayloadLengthSamples - 5))); |
| 982 EXPECT_EQ(NetEq::kOK, |
| 983 neteq_->RegisterExternalDecoder(&mock_decoder, kDecoderPCM16B, |
| 984 kPayloadType, kSampleRateHz)); |
| 985 |
| 986 // Insert one packet. |
| 987 EXPECT_EQ(NetEq::kOK, |
| 988 neteq_->InsertPacket(rtp_header, payload, kPayloadLengthBytes, |
| 989 kReceiveTime)); |
| 990 |
| 991 EXPECT_EQ(5u, neteq_->sync_buffer_for_test()->FutureLength()); |
| 992 |
| 993 // Pull audio once. |
| 994 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); |
| 995 int16_t output[kMaxOutputSize]; |
| 996 size_t samples_per_channel; |
| 997 int num_channels; |
| 998 NetEqOutputType type; |
| 999 EXPECT_EQ(NetEq::kOK, |
| 1000 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 1001 &num_channels, &type)); |
| 1002 ASSERT_EQ(kMaxOutputSize, samples_per_channel); |
| 1003 EXPECT_EQ(1, num_channels); |
| 1004 EXPECT_EQ(kOutputNormal, type); |
| 1005 |
| 1006 EXPECT_CALL(mock_decoder, Die()); |
| 1007 } |
945 } // namespace webrtc | 1008 } // namespace webrtc |
OLD | NEW |