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