Stefan Holmer | 8bffba7 | 2015-09-23 15:53:52 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
kwiberg | 1c07c70 | 2017-03-27 07:15:49 -0700 | [diff] [blame] | 11 | #include <map> |
Fredrik Solenberg | ea07373 | 2015-12-01 11:26:34 +0100 | [diff] [blame] | 12 | #include <string> |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 13 | #include <utility> |
stefan | 3313ec9 | 2016-01-21 06:32:43 -0800 | [diff] [blame] | 14 | #include <vector> |
Fredrik Solenberg | ea07373 | 2015-12-01 11:26:34 +0100 | [diff] [blame] | 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "api/test/mock_audio_mixer.h" |
Benjamin Wright | 78410ad | 2018-10-25 09:52:57 -0700 | [diff] [blame] | 17 | #include "api/test/mock_frame_decryptor.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "audio/audio_receive_stream.h" |
| 19 | #include "audio/conversion.h" |
Fredrik Solenberg | a8b7c7f | 2018-01-17 11:18:31 +0100 | [diff] [blame] | 20 | #include "audio/mock_voe_channel_proxy.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "call/rtp_stream_receiver_controller.h" |
| 22 | #include "logging/rtc_event_log/mock/mock_rtc_event_log.h" |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 23 | #include "modules/audio_device/include/mock_audio_device.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "modules/audio_processing/include/mock_audio_processing.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "modules/pacing/packet_router.h" |
| 26 | #include "modules/rtp_rtcp/source/byte_io.h" |
Bjorn Terelius | 5c2f1f0 | 2019-01-16 17:45:05 +0100 | [diff] [blame] | 27 | #include "rtc_base/time_utils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 28 | #include "test/gtest.h" |
| 29 | #include "test/mock_audio_decoder_factory.h" |
Niels Möller | ae4237e | 2018-10-05 11:28:38 +0200 | [diff] [blame] | 30 | #include "test/mock_transport.h" |
Stefan Holmer | 8bffba7 | 2015-09-23 15:53:52 +0200 | [diff] [blame] | 31 | |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 32 | namespace webrtc { |
| 33 | namespace test { |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 34 | namespace { |
| 35 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame^] | 36 | using ::testing::_; |
| 37 | using ::testing::FloatEq; |
| 38 | using ::testing::Return; |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 39 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 40 | AudioDecodingCallStats MakeAudioDecodeStatsForTest() { |
| 41 | AudioDecodingCallStats audio_decode_stats; |
| 42 | audio_decode_stats.calls_to_silence_generator = 234; |
| 43 | audio_decode_stats.calls_to_neteq = 567; |
| 44 | audio_decode_stats.decoded_normal = 890; |
| 45 | audio_decode_stats.decoded_plc = 123; |
| 46 | audio_decode_stats.decoded_cng = 456; |
| 47 | audio_decode_stats.decoded_plc_cng = 789; |
henrik.lundin | 6348978 | 2016-09-20 01:47:12 -0700 | [diff] [blame] | 48 | audio_decode_stats.decoded_muted_output = 987; |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 49 | return audio_decode_stats; |
| 50 | } |
| 51 | |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 52 | const uint32_t kRemoteSsrc = 1234; |
| 53 | const uint32_t kLocalSsrc = 5678; |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 54 | const size_t kOneByteExtensionHeaderLength = 4; |
| 55 | const size_t kOneByteExtensionLength = 4; |
solenberg | 7add058 | 2015-11-20 09:59:34 -0800 | [diff] [blame] | 56 | const int kAudioLevelId = 3; |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 57 | const int kTransportSequenceNumberId = 4; |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 58 | const int kJitterBufferDelay = -7; |
| 59 | const int kPlayoutBufferDelay = 302; |
| 60 | const unsigned int kSpeechOutputLevel = 99; |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 61 | const double kTotalOutputEnergy = 0.25; |
| 62 | const double kTotalOutputDuration = 0.5; |
| 63 | |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 64 | const CallReceiveStatistics kCallStats = {345, 678, 901, 234, |
| 65 | -12, 567, 890, 123}; |
Benjamin Wright | 17b050f | 2019-03-13 17:35:46 -0700 | [diff] [blame] | 66 | const std::pair<int, SdpAudioFormat> kReceiveCodec = { |
| 67 | 123, |
| 68 | {"codec_name_recv", 96000, 0}}; |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 69 | const NetworkStatistics kNetworkStats = { |
Chen Xing | 0acffb5 | 2019-01-15 15:46:29 +0100 | [diff] [blame] | 70 | 123, 456, false, 789012, 3456, 123, 456, 789, 0, {}, 789, |
| 71 | 12, 345, 678, 901, 0, -1, -1, -1, -1, -1, 0}; |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 72 | const AudioDecodingCallStats kAudioDecodeStats = MakeAudioDecodeStatsForTest(); |
| 73 | |
| 74 | struct ConfigHelper { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 75 | ConfigHelper() : ConfigHelper(new rtc::RefCountedObject<MockAudioMixer>()) {} |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 76 | |
| 77 | explicit ConfigHelper(rtc::scoped_refptr<MockAudioMixer> audio_mixer) |
| 78 | : audio_mixer_(audio_mixer) { |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame^] | 79 | using ::testing::Invoke; |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 80 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 81 | AudioState::Config config; |
aleloi | 04c0722 | 2016-11-22 06:42:53 -0800 | [diff] [blame] | 82 | config.audio_mixer = audio_mixer_; |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 83 | config.audio_processing = new rtc::RefCountedObject<MockAudioProcessing>(); |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 84 | config.audio_device_module = |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 85 | new rtc::RefCountedObject<testing::NiceMock<MockAudioDeviceModule>>(); |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 86 | audio_state_ = AudioState::Create(config); |
solenberg | 7add058 | 2015-11-20 09:59:34 -0800 | [diff] [blame] | 87 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame^] | 88 | channel_receive_ = new ::testing::StrictMock<MockChannelReceive>(); |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 89 | EXPECT_CALL(*channel_receive_, SetLocalSSRC(kLocalSsrc)).Times(1); |
| 90 | EXPECT_CALL(*channel_receive_, SetNACKStatus(true, 15)).Times(1); |
| 91 | EXPECT_CALL(*channel_receive_, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 92 | RegisterReceiverCongestionControlObjects(&packet_router_)) |
| 93 | .Times(1); |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 94 | EXPECT_CALL(*channel_receive_, ResetReceiverCongestionControlObjects()) |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 95 | .Times(1); |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 96 | EXPECT_CALL(*channel_receive_, SetAssociatedSendChannel(nullptr)).Times(1); |
| 97 | EXPECT_CALL(*channel_receive_, SetReceiveCodecs(_)) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 98 | .WillRepeatedly(Invoke([](const std::map<int, SdpAudioFormat>& codecs) { |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame^] | 99 | EXPECT_THAT(codecs, ::testing::IsEmpty()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 100 | })); |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 101 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 102 | stream_config_.rtp.local_ssrc = kLocalSsrc; |
| 103 | stream_config_.rtp.remote_ssrc = kRemoteSsrc; |
solenberg | 8189b02 | 2016-06-14 12:13:00 -0700 | [diff] [blame] | 104 | stream_config_.rtp.nack.rtp_history_ms = 300; |
solenberg | 7add058 | 2015-11-20 09:59:34 -0800 | [diff] [blame] | 105 | stream_config_.rtp.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 106 | RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId)); |
stefan | 3313ec9 | 2016-01-21 06:32:43 -0800 | [diff] [blame] | 107 | stream_config_.rtp.extensions.push_back(RtpExtension( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 108 | RtpExtension::kTransportSequenceNumberUri, kTransportSequenceNumberId)); |
Niels Möller | ae4237e | 2018-10-05 11:28:38 +0200 | [diff] [blame] | 109 | stream_config_.rtcp_send_transport = &rtcp_send_transport_; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 110 | stream_config_.decoder_factory = |
| 111 | new rtc::RefCountedObject<MockAudioDecoderFactory>; |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 112 | } |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 113 | |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 114 | std::unique_ptr<internal::AudioReceiveStream> CreateAudioReceiveStream() { |
| 115 | return std::unique_ptr<internal::AudioReceiveStream>( |
| 116 | new internal::AudioReceiveStream( |
Sebastian Jansson | 977b335 | 2019-03-04 17:43:34 +0100 | [diff] [blame] | 117 | Clock::GetRealTimeClock(), &rtp_stream_receiver_controller_, |
| 118 | &packet_router_, stream_config_, audio_state_, &event_log_, |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 119 | std::unique_ptr<voe::ChannelReceiveInterface>(channel_receive_))); |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 120 | } |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 121 | |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 122 | AudioReceiveStream::Config& config() { return stream_config_; } |
| 123 | rtc::scoped_refptr<MockAudioMixer> audio_mixer() { return audio_mixer_; } |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 124 | MockChannelReceive* channel_receive() { return channel_receive_; } |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 125 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 126 | void SetupMockForGetStats() { |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame^] | 127 | using ::testing::DoAll; |
| 128 | using ::testing::SetArgPointee; |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 129 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 130 | ASSERT_TRUE(channel_receive_); |
| 131 | EXPECT_CALL(*channel_receive_, GetRTCPStatistics()) |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 132 | .WillOnce(Return(kCallStats)); |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 133 | EXPECT_CALL(*channel_receive_, GetDelayEstimate()) |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 134 | .WillOnce(Return(kJitterBufferDelay + kPlayoutBufferDelay)); |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 135 | EXPECT_CALL(*channel_receive_, GetSpeechOutputLevelFullRange()) |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 136 | .WillOnce(Return(kSpeechOutputLevel)); |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 137 | EXPECT_CALL(*channel_receive_, GetTotalOutputEnergy()) |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 138 | .WillOnce(Return(kTotalOutputEnergy)); |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 139 | EXPECT_CALL(*channel_receive_, GetTotalOutputDuration()) |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 140 | .WillOnce(Return(kTotalOutputDuration)); |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 141 | EXPECT_CALL(*channel_receive_, GetNetworkStatistics()) |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 142 | .WillOnce(Return(kNetworkStats)); |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 143 | EXPECT_CALL(*channel_receive_, GetDecodingCallStatistics()) |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 144 | .WillOnce(Return(kAudioDecodeStats)); |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 145 | EXPECT_CALL(*channel_receive_, GetReceiveCodec()) |
| 146 | .WillOnce(Return(kReceiveCodec)); |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | private: |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 150 | PacketRouter packet_router_; |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 151 | MockRtcEventLog event_log_; |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 152 | rtc::scoped_refptr<AudioState> audio_state_; |
aleloi | 04c0722 | 2016-11-22 06:42:53 -0800 | [diff] [blame] | 153 | rtc::scoped_refptr<MockAudioMixer> audio_mixer_; |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 154 | AudioReceiveStream::Config stream_config_; |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame^] | 155 | ::testing::StrictMock<MockChannelReceive>* channel_receive_ = nullptr; |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 156 | RtpStreamReceiverController rtp_stream_receiver_controller_; |
Niels Möller | ae4237e | 2018-10-05 11:28:38 +0200 | [diff] [blame] | 157 | MockTransport rtcp_send_transport_; |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 158 | }; |
Stefan Holmer | 8bffba7 | 2015-09-23 15:53:52 +0200 | [diff] [blame] | 159 | |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 160 | void BuildOneByteExtension(std::vector<uint8_t>::iterator it, |
| 161 | int id, |
| 162 | uint32_t extension_value, |
| 163 | size_t value_length) { |
Stefan Holmer | 8bffba7 | 2015-09-23 15:53:52 +0200 | [diff] [blame] | 164 | const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE; |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 165 | ByteWriter<uint16_t>::WriteBigEndian(&(*it), kRtpOneByteHeaderExtensionId); |
| 166 | it += 2; |
Stefan Holmer | 8bffba7 | 2015-09-23 15:53:52 +0200 | [diff] [blame] | 167 | |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 168 | ByteWriter<uint16_t>::WriteBigEndian(&(*it), kOneByteExtensionLength / 4); |
| 169 | it += 2; |
| 170 | const size_t kExtensionDataLength = kOneByteExtensionLength - 1; |
| 171 | uint32_t shifted_value = extension_value |
| 172 | << (8 * (kExtensionDataLength - value_length)); |
Peter Boström | 0208322 | 2016-06-14 12:52:54 +0200 | [diff] [blame] | 173 | *it = (id << 4) + (static_cast<uint8_t>(value_length) - 1); |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 174 | ++it; |
| 175 | ByteWriter<uint32_t, kExtensionDataLength>::WriteBigEndian(&(*it), |
| 176 | shifted_value); |
Stefan Holmer | 8bffba7 | 2015-09-23 15:53:52 +0200 | [diff] [blame] | 177 | } |
| 178 | |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 179 | const std::vector<uint8_t> CreateRtpHeaderWithOneByteExtension( |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 180 | int extension_id, |
| 181 | uint32_t extension_value, |
| 182 | size_t value_length) { |
| 183 | std::vector<uint8_t> header; |
| 184 | header.resize(webrtc::kRtpHeaderSize + kOneByteExtensionHeaderLength + |
| 185 | kOneByteExtensionLength); |
Stefan Holmer | 8bffba7 | 2015-09-23 15:53:52 +0200 | [diff] [blame] | 186 | header[0] = 0x80; // Version 2. |
| 187 | header[0] |= 0x10; // Set extension bit. |
| 188 | header[1] = 100; // Payload type. |
| 189 | header[1] |= 0x80; // Marker bit is set. |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 190 | ByteWriter<uint16_t>::WriteBigEndian(&header[2], 0x1234); // Sequence number. |
| 191 | ByteWriter<uint32_t>::WriteBigEndian(&header[4], 0x5678); // Timestamp. |
| 192 | ByteWriter<uint32_t>::WriteBigEndian(&header[8], 0x4321); // SSRC. |
Stefan Holmer | 8bffba7 | 2015-09-23 15:53:52 +0200 | [diff] [blame] | 193 | |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 194 | BuildOneByteExtension(header.begin() + webrtc::kRtpHeaderSize, extension_id, |
| 195 | extension_value, value_length); |
| 196 | return header; |
Stefan Holmer | 8bffba7 | 2015-09-23 15:53:52 +0200 | [diff] [blame] | 197 | } |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 198 | |
| 199 | const std::vector<uint8_t> CreateRtcpSenderReport() { |
| 200 | std::vector<uint8_t> packet; |
| 201 | const size_t kRtcpSrLength = 28; // In bytes. |
| 202 | packet.resize(kRtcpSrLength); |
| 203 | packet[0] = 0x80; // Version 2. |
| 204 | packet[1] = 0xc8; // PT = 200, SR. |
| 205 | // Length in number of 32-bit words - 1. |
| 206 | ByteWriter<uint16_t>::WriteBigEndian(&packet[2], 6); |
| 207 | ByteWriter<uint32_t>::WriteBigEndian(&packet[4], kLocalSsrc); |
| 208 | return packet; |
| 209 | } |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 210 | } // namespace |
| 211 | |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 212 | TEST(AudioReceiveStreamTest, ConfigToString) { |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 213 | AudioReceiveStream::Config config; |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 214 | config.rtp.remote_ssrc = kRemoteSsrc; |
| 215 | config.rtp.local_ssrc = kLocalSsrc; |
stefan | b521aa7 | 2016-11-01 03:17:16 -0700 | [diff] [blame] | 216 | config.rtp.extensions.push_back( |
| 217 | RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId)); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 218 | EXPECT_EQ( |
stefan | b521aa7 | 2016-11-01 03:17:16 -0700 | [diff] [blame] | 219 | "{rtp: {remote_ssrc: 1234, local_ssrc: 5678, transport_cc: off, nack: " |
| 220 | "{rtp_history_ms: 0}, extensions: [{uri: " |
| 221 | "urn:ietf:params:rtp-hdrext:ssrc-audio-level, id: 3}]}, " |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 222 | "rtcp_send_transport: null, media_transport: null}", |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 223 | config.ToString()); |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | TEST(AudioReceiveStreamTest, ConstructDestruct) { |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 227 | ConfigHelper helper; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 228 | auto recv_stream = helper.CreateAudioReceiveStream(); |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 229 | } |
| 230 | |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 231 | TEST(AudioReceiveStreamTest, ReceiveRtpPacket) { |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 232 | ConfigHelper helper; |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 233 | helper.config().rtp.transport_cc = true; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 234 | auto recv_stream = helper.CreateAudioReceiveStream(); |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 235 | const int kTransportSequenceNumberValue = 1234; |
| 236 | std::vector<uint8_t> rtp_packet = CreateRtpHeaderWithOneByteExtension( |
| 237 | kTransportSequenceNumberId, kTransportSequenceNumberValue, 2); |
Niels Möller | 7008287 | 2018-08-07 11:03:12 +0200 | [diff] [blame] | 238 | constexpr int64_t packet_time_us = 5678000; |
nisse | 657bab2 | 2017-02-21 06:28:10 -0800 | [diff] [blame] | 239 | |
| 240 | RtpPacketReceived parsed_packet; |
| 241 | ASSERT_TRUE(parsed_packet.Parse(&rtp_packet[0], rtp_packet.size())); |
Niels Möller | 7008287 | 2018-08-07 11:03:12 +0200 | [diff] [blame] | 242 | parsed_packet.set_arrival_time_ms((packet_time_us + 500) / 1000); |
nisse | 657bab2 | 2017-02-21 06:28:10 -0800 | [diff] [blame] | 243 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 244 | EXPECT_CALL(*helper.channel_receive(), |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame^] | 245 | OnRtpPacket(::testing::Ref(parsed_packet))); |
nisse | 657bab2 | 2017-02-21 06:28:10 -0800 | [diff] [blame] | 246 | |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 247 | recv_stream->OnRtpPacket(parsed_packet); |
Stefan Holmer | 8bffba7 | 2015-09-23 15:53:52 +0200 | [diff] [blame] | 248 | } |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 249 | |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 250 | TEST(AudioReceiveStreamTest, ReceiveRtcpPacket) { |
| 251 | ConfigHelper helper; |
| 252 | helper.config().rtp.transport_cc = true; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 253 | auto recv_stream = helper.CreateAudioReceiveStream(); |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 254 | std::vector<uint8_t> rtcp_packet = CreateRtcpSenderReport(); |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 255 | EXPECT_CALL(*helper.channel_receive(), |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 256 | ReceivedRTCPPacket(&rtcp_packet[0], rtcp_packet.size())) |
Niels Möller | 8fb1a6a | 2019-03-05 14:29:42 +0100 | [diff] [blame] | 257 | .WillOnce(Return()); |
| 258 | recv_stream->DeliverRtcp(&rtcp_packet[0], rtcp_packet.size()); |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 261 | TEST(AudioReceiveStreamTest, GetStats) { |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 262 | ConfigHelper helper; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 263 | auto recv_stream = helper.CreateAudioReceiveStream(); |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 264 | helper.SetupMockForGetStats(); |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 265 | AudioReceiveStream::Stats stats = recv_stream->GetStats(); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 266 | EXPECT_EQ(kRemoteSsrc, stats.remote_ssrc); |
| 267 | EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesReceived), stats.bytes_rcvd); |
| 268 | EXPECT_EQ(static_cast<uint32_t>(kCallStats.packetsReceived), |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 269 | stats.packets_rcvd); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 270 | EXPECT_EQ(kCallStats.cumulativeLost, stats.packets_lost); |
| 271 | EXPECT_EQ(Q8ToFloat(kCallStats.fractionLost), stats.fraction_lost); |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 272 | EXPECT_EQ(kReceiveCodec.second.name, stats.codec_name); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 273 | EXPECT_EQ(kCallStats.extendedMax, stats.ext_seqnum); |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 274 | EXPECT_EQ( |
| 275 | kCallStats.jitterSamples / (kReceiveCodec.second.clockrate_hz / 1000), |
| 276 | stats.jitter_ms); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 277 | EXPECT_EQ(kNetworkStats.currentBufferSize, stats.jitter_buffer_ms); |
| 278 | EXPECT_EQ(kNetworkStats.preferredBufferSize, |
| 279 | stats.jitter_buffer_preferred_ms); |
| 280 | EXPECT_EQ(static_cast<uint32_t>(kJitterBufferDelay + kPlayoutBufferDelay), |
| 281 | stats.delay_estimate_ms); |
| 282 | EXPECT_EQ(static_cast<int32_t>(kSpeechOutputLevel), stats.audio_level); |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 283 | EXPECT_EQ(kTotalOutputEnergy, stats.total_output_energy); |
Steve Anton | 2dbc69f | 2017-08-24 17:15:13 -0700 | [diff] [blame] | 284 | EXPECT_EQ(kNetworkStats.totalSamplesReceived, stats.total_samples_received); |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 285 | EXPECT_EQ(kTotalOutputDuration, stats.total_output_duration); |
Steve Anton | 2dbc69f | 2017-08-24 17:15:13 -0700 | [diff] [blame] | 286 | EXPECT_EQ(kNetworkStats.concealedSamples, stats.concealed_samples); |
Gustaf Ullberg | 9a2e906 | 2017-09-18 09:28:20 +0200 | [diff] [blame] | 287 | EXPECT_EQ(kNetworkStats.concealmentEvents, stats.concealment_events); |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 288 | EXPECT_EQ(static_cast<double>(kNetworkStats.jitterBufferDelayMs) / |
| 289 | static_cast<double>(rtc::kNumMillisecsPerSec), |
| 290 | stats.jitter_buffer_delay_seconds); |
Chen Xing | 0acffb5 | 2019-01-15 15:46:29 +0100 | [diff] [blame] | 291 | EXPECT_EQ(kNetworkStats.jitterBufferEmittedCount, |
| 292 | stats.jitter_buffer_emitted_count); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 293 | EXPECT_EQ(Q14ToFloat(kNetworkStats.currentExpandRate), stats.expand_rate); |
| 294 | EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSpeechExpandRate), |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 295 | stats.speech_expand_rate); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 296 | EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSecondaryDecodedRate), |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 297 | stats.secondary_decoded_rate); |
minyue-webrtc | 0e320ec | 2017-08-28 13:51:27 +0200 | [diff] [blame] | 298 | EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSecondaryDiscardedRate), |
| 299 | stats.secondary_discarded_rate); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 300 | EXPECT_EQ(Q14ToFloat(kNetworkStats.currentAccelerateRate), |
| 301 | stats.accelerate_rate); |
| 302 | EXPECT_EQ(Q14ToFloat(kNetworkStats.currentPreemptiveRate), |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 303 | stats.preemptive_expand_rate); |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 304 | EXPECT_EQ(kAudioDecodeStats.calls_to_silence_generator, |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 305 | stats.decoding_calls_to_silence_generator); |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 306 | EXPECT_EQ(kAudioDecodeStats.calls_to_neteq, stats.decoding_calls_to_neteq); |
| 307 | EXPECT_EQ(kAudioDecodeStats.decoded_normal, stats.decoding_normal); |
| 308 | EXPECT_EQ(kAudioDecodeStats.decoded_plc, stats.decoding_plc); |
| 309 | EXPECT_EQ(kAudioDecodeStats.decoded_cng, stats.decoding_cng); |
| 310 | EXPECT_EQ(kAudioDecodeStats.decoded_plc_cng, stats.decoding_plc_cng); |
henrik.lundin | 6348978 | 2016-09-20 01:47:12 -0700 | [diff] [blame] | 311 | EXPECT_EQ(kAudioDecodeStats.decoded_muted_output, |
| 312 | stats.decoding_muted_output); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 313 | EXPECT_EQ(kCallStats.capture_start_ntp_time_ms_, |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 314 | stats.capture_start_ntp_time_ms); |
| 315 | } |
solenberg | 217fb66 | 2016-06-17 08:30:54 -0700 | [diff] [blame] | 316 | |
| 317 | TEST(AudioReceiveStreamTest, SetGain) { |
| 318 | ConfigHelper helper; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 319 | auto recv_stream = helper.CreateAudioReceiveStream(); |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 320 | EXPECT_CALL(*helper.channel_receive(), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 321 | SetChannelOutputVolumeScaling(FloatEq(0.765f))); |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 322 | recv_stream->SetGain(0.765f); |
solenberg | 217fb66 | 2016-06-17 08:30:54 -0700 | [diff] [blame] | 323 | } |
aleloi | 04c0722 | 2016-11-22 06:42:53 -0800 | [diff] [blame] | 324 | |
Fredrik Solenberg | d524751 | 2017-12-18 22:41:03 +0100 | [diff] [blame] | 325 | TEST(AudioReceiveStreamTest, StreamsShouldBeAddedToMixerOnceOnStart) { |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 326 | ConfigHelper helper1; |
| 327 | ConfigHelper helper2(helper1.audio_mixer()); |
| 328 | auto recv_stream1 = helper1.CreateAudioReceiveStream(); |
| 329 | auto recv_stream2 = helper2.CreateAudioReceiveStream(); |
aleloi | 04c0722 | 2016-11-22 06:42:53 -0800 | [diff] [blame] | 330 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 331 | EXPECT_CALL(*helper1.channel_receive(), StartPlayout()).Times(1); |
| 332 | EXPECT_CALL(*helper2.channel_receive(), StartPlayout()).Times(1); |
| 333 | EXPECT_CALL(*helper1.channel_receive(), StopPlayout()).Times(1); |
| 334 | EXPECT_CALL(*helper2.channel_receive(), StopPlayout()).Times(1); |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 335 | EXPECT_CALL(*helper1.audio_mixer(), AddSource(recv_stream1.get())) |
aleloi | 04c0722 | 2016-11-22 06:42:53 -0800 | [diff] [blame] | 336 | .WillOnce(Return(true)); |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 337 | EXPECT_CALL(*helper1.audio_mixer(), AddSource(recv_stream2.get())) |
Fredrik Solenberg | d524751 | 2017-12-18 22:41:03 +0100 | [diff] [blame] | 338 | .WillOnce(Return(true)); |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 339 | EXPECT_CALL(*helper1.audio_mixer(), RemoveSource(recv_stream1.get())) |
| 340 | .Times(1); |
| 341 | EXPECT_CALL(*helper1.audio_mixer(), RemoveSource(recv_stream2.get())) |
| 342 | .Times(1); |
aleloi | 04c0722 | 2016-11-22 06:42:53 -0800 | [diff] [blame] | 343 | |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 344 | recv_stream1->Start(); |
| 345 | recv_stream2->Start(); |
Fredrik Solenberg | d524751 | 2017-12-18 22:41:03 +0100 | [diff] [blame] | 346 | |
| 347 | // One more should not result in any more mixer sources added. |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 348 | recv_stream1->Start(); |
Fredrik Solenberg | d524751 | 2017-12-18 22:41:03 +0100 | [diff] [blame] | 349 | |
| 350 | // Stop stream before it is being destructed. |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 351 | recv_stream2->Stop(); |
aleloi | 04c0722 | 2016-11-22 06:42:53 -0800 | [diff] [blame] | 352 | } |
Fredrik Solenberg | 3b903d0 | 2018-01-10 15:17:10 +0100 | [diff] [blame] | 353 | |
| 354 | TEST(AudioReceiveStreamTest, ReconfigureWithSameConfig) { |
| 355 | ConfigHelper helper; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 356 | auto recv_stream = helper.CreateAudioReceiveStream(); |
| 357 | recv_stream->Reconfigure(helper.config()); |
Fredrik Solenberg | 3b903d0 | 2018-01-10 15:17:10 +0100 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | TEST(AudioReceiveStreamTest, ReconfigureWithUpdatedConfig) { |
| 361 | ConfigHelper helper; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 362 | auto recv_stream = helper.CreateAudioReceiveStream(); |
Fredrik Solenberg | 3b903d0 | 2018-01-10 15:17:10 +0100 | [diff] [blame] | 363 | |
| 364 | auto new_config = helper.config(); |
| 365 | new_config.rtp.local_ssrc = kLocalSsrc + 1; |
| 366 | new_config.rtp.nack.rtp_history_ms = 300 + 20; |
| 367 | new_config.rtp.extensions.clear(); |
| 368 | new_config.rtp.extensions.push_back( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 369 | RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId + 1)); |
| 370 | new_config.rtp.extensions.push_back( |
| 371 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
| 372 | kTransportSequenceNumberId + 1)); |
Fredrik Solenberg | 3b903d0 | 2018-01-10 15:17:10 +0100 | [diff] [blame] | 373 | new_config.decoder_map.emplace(1, SdpAudioFormat("foo", 8000, 1)); |
| 374 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 375 | MockChannelReceive& channel_receive = *helper.channel_receive(); |
| 376 | EXPECT_CALL(channel_receive, SetLocalSSRC(kLocalSsrc + 1)).Times(1); |
| 377 | EXPECT_CALL(channel_receive, SetNACKStatus(true, 15 + 1)).Times(1); |
| 378 | EXPECT_CALL(channel_receive, SetReceiveCodecs(new_config.decoder_map)); |
Fredrik Solenberg | 3b903d0 | 2018-01-10 15:17:10 +0100 | [diff] [blame] | 379 | |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 380 | recv_stream->Reconfigure(new_config); |
Fredrik Solenberg | 3b903d0 | 2018-01-10 15:17:10 +0100 | [diff] [blame] | 381 | } |
Benjamin Wright | 78410ad | 2018-10-25 09:52:57 -0700 | [diff] [blame] | 382 | |
| 383 | TEST(AudioReceiveStreamTest, ReconfigureWithFrameDecryptor) { |
| 384 | ConfigHelper helper; |
| 385 | auto recv_stream = helper.CreateAudioReceiveStream(); |
| 386 | |
| 387 | auto new_config_0 = helper.config(); |
| 388 | rtc::scoped_refptr<FrameDecryptorInterface> mock_frame_decryptor_0( |
| 389 | new rtc::RefCountedObject<MockFrameDecryptor>()); |
| 390 | new_config_0.frame_decryptor = mock_frame_decryptor_0; |
| 391 | |
| 392 | recv_stream->Reconfigure(new_config_0); |
| 393 | |
| 394 | auto new_config_1 = helper.config(); |
| 395 | rtc::scoped_refptr<FrameDecryptorInterface> mock_frame_decryptor_1( |
| 396 | new rtc::RefCountedObject<MockFrameDecryptor>()); |
| 397 | new_config_1.frame_decryptor = mock_frame_decryptor_1; |
| 398 | new_config_1.crypto_options.sframe.require_frame_encryption = true; |
| 399 | recv_stream->Reconfigure(new_config_1); |
| 400 | } |
| 401 | |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 402 | } // namespace test |
Stefan Holmer | 8bffba7 | 2015-09-23 15:53:52 +0200 | [diff] [blame] | 403 | } // namespace webrtc |