OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "webrtc/api/test/mock_audio_mixer.h" | 14 #include "webrtc/api/test/mock_audio_mixer.h" |
15 #include "webrtc/audio/audio_receive_stream.h" | 15 #include "webrtc/audio/audio_receive_stream.h" |
16 #include "webrtc/audio/conversion.h" | 16 #include "webrtc/audio/conversion.h" |
17 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" | 17 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" |
18 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h" | 18 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h" |
19 #include "webrtc/modules/bitrate_controller/include/mock/mock_bitrate_controller
.h" | 19 #include "webrtc/modules/bitrate_controller/include/mock/mock_bitrate_controller
.h" |
20 #include "webrtc/modules/pacing/packet_router.h" | 20 #include "webrtc/modules/pacing/packet_router.h" |
21 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra
te_estimator.h" | |
22 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 21 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
23 #include "webrtc/test/gtest.h" | 22 #include "webrtc/test/gtest.h" |
24 #include "webrtc/test/mock_voe_channel_proxy.h" | 23 #include "webrtc/test/mock_voe_channel_proxy.h" |
25 #include "webrtc/test/mock_voice_engine.h" | 24 #include "webrtc/test/mock_voice_engine.h" |
26 | 25 |
27 namespace webrtc { | 26 namespace webrtc { |
28 namespace test { | 27 namespace test { |
29 namespace { | 28 namespace { |
30 | 29 |
31 using testing::_; | 30 using testing::_; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 stream_config_.rtp.remote_ssrc = kRemoteSsrc; | 118 stream_config_.rtp.remote_ssrc = kRemoteSsrc; |
120 stream_config_.rtp.nack.rtp_history_ms = 300; | 119 stream_config_.rtp.nack.rtp_history_ms = 300; |
121 stream_config_.rtp.extensions.push_back( | 120 stream_config_.rtp.extensions.push_back( |
122 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId)); | 121 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId)); |
123 stream_config_.rtp.extensions.push_back(RtpExtension( | 122 stream_config_.rtp.extensions.push_back(RtpExtension( |
124 RtpExtension::kTransportSequenceNumberUri, kTransportSequenceNumberId)); | 123 RtpExtension::kTransportSequenceNumberUri, kTransportSequenceNumberId)); |
125 stream_config_.decoder_factory = decoder_factory_; | 124 stream_config_.decoder_factory = decoder_factory_; |
126 } | 125 } |
127 | 126 |
128 PacketRouter* packet_router() { return &packet_router_; } | 127 PacketRouter* packet_router() { return &packet_router_; } |
129 MockRemoteBitrateEstimator* remote_bitrate_estimator() { | |
130 return &remote_bitrate_estimator_; | |
131 } | |
132 MockRtcEventLog* event_log() { return &event_log_; } | 128 MockRtcEventLog* event_log() { return &event_log_; } |
133 AudioReceiveStream::Config& config() { return stream_config_; } | 129 AudioReceiveStream::Config& config() { return stream_config_; } |
134 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } | 130 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } |
135 rtc::scoped_refptr<MockAudioMixer> audio_mixer() { return audio_mixer_; } | 131 rtc::scoped_refptr<MockAudioMixer> audio_mixer() { return audio_mixer_; } |
136 MockVoiceEngine& voice_engine() { return voice_engine_; } | 132 MockVoiceEngine& voice_engine() { return voice_engine_; } |
137 MockVoEChannelProxy* channel_proxy() { return channel_proxy_; } | 133 MockVoEChannelProxy* channel_proxy() { return channel_proxy_; } |
138 | 134 |
139 void SetupMockForBweFeedback(bool send_side_bwe) { | |
140 EXPECT_CALL(remote_bitrate_estimator_, | |
141 RemoveStream(stream_config_.rtp.remote_ssrc)); | |
142 } | |
143 | |
144 void SetupMockForGetStats() { | 135 void SetupMockForGetStats() { |
145 using testing::DoAll; | 136 using testing::DoAll; |
146 using testing::SetArgPointee; | 137 using testing::SetArgPointee; |
147 | 138 |
148 ASSERT_TRUE(channel_proxy_); | 139 ASSERT_TRUE(channel_proxy_); |
149 EXPECT_CALL(*channel_proxy_, GetRTCPStatistics()) | 140 EXPECT_CALL(*channel_proxy_, GetRTCPStatistics()) |
150 .WillOnce(Return(kCallStats)); | 141 .WillOnce(Return(kCallStats)); |
151 EXPECT_CALL(*channel_proxy_, GetDelayEstimate()) | 142 EXPECT_CALL(*channel_proxy_, GetDelayEstimate()) |
152 .WillOnce(Return(kJitterBufferDelay + kPlayoutBufferDelay)); | 143 .WillOnce(Return(kJitterBufferDelay + kPlayoutBufferDelay)); |
153 EXPECT_CALL(*channel_proxy_, GetSpeechOutputLevelFullRange()) | 144 EXPECT_CALL(*channel_proxy_, GetSpeechOutputLevelFullRange()) |
154 .WillOnce(Return(kSpeechOutputLevel)); | 145 .WillOnce(Return(kSpeechOutputLevel)); |
155 EXPECT_CALL(*channel_proxy_, GetNetworkStatistics()) | 146 EXPECT_CALL(*channel_proxy_, GetNetworkStatistics()) |
156 .WillOnce(Return(kNetworkStats)); | 147 .WillOnce(Return(kNetworkStats)); |
157 EXPECT_CALL(*channel_proxy_, GetDecodingCallStatistics()) | 148 EXPECT_CALL(*channel_proxy_, GetDecodingCallStatistics()) |
158 .WillOnce(Return(kAudioDecodeStats)); | 149 .WillOnce(Return(kAudioDecodeStats)); |
159 EXPECT_CALL(*channel_proxy_, GetRecCodec(_)) | 150 EXPECT_CALL(*channel_proxy_, GetRecCodec(_)) |
160 .WillOnce(DoAll(SetArgPointee<0>(kCodecInst), Return(true))); | 151 .WillOnce(DoAll(SetArgPointee<0>(kCodecInst), Return(true))); |
161 } | 152 } |
162 | 153 |
163 private: | 154 private: |
164 PacketRouter packet_router_; | 155 PacketRouter packet_router_; |
165 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; | 156 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; |
166 MockRemoteBitrateEstimator remote_bitrate_estimator_; | |
167 MockRtcEventLog event_log_; | 157 MockRtcEventLog event_log_; |
168 testing::StrictMock<MockVoiceEngine> voice_engine_; | 158 testing::StrictMock<MockVoiceEngine> voice_engine_; |
169 rtc::scoped_refptr<AudioState> audio_state_; | 159 rtc::scoped_refptr<AudioState> audio_state_; |
170 rtc::scoped_refptr<MockAudioMixer> audio_mixer_; | 160 rtc::scoped_refptr<MockAudioMixer> audio_mixer_; |
171 AudioReceiveStream::Config stream_config_; | 161 AudioReceiveStream::Config stream_config_; |
172 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr; | 162 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr; |
173 }; | 163 }; |
174 | 164 |
175 void BuildOneByteExtension(std::vector<uint8_t>::iterator it, | 165 void BuildOneByteExtension(std::vector<uint8_t>::iterator it, |
176 int id, | 166 int id, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 "{rtp_history_ms: 0}, extensions: [{uri: " | 226 "{rtp_history_ms: 0}, extensions: [{uri: " |
237 "urn:ietf:params:rtp-hdrext:ssrc-audio-level, id: 3}]}, " | 227 "urn:ietf:params:rtp-hdrext:ssrc-audio-level, id: 3}]}, " |
238 "rtcp_send_transport: nullptr, voe_channel_id: 2}", | 228 "rtcp_send_transport: nullptr, voe_channel_id: 2}", |
239 config.ToString()); | 229 config.ToString()); |
240 } | 230 } |
241 | 231 |
242 TEST(AudioReceiveStreamTest, ConstructDestruct) { | 232 TEST(AudioReceiveStreamTest, ConstructDestruct) { |
243 ConfigHelper helper; | 233 ConfigHelper helper; |
244 internal::AudioReceiveStream recv_stream( | 234 internal::AudioReceiveStream recv_stream( |
245 helper.packet_router(), | 235 helper.packet_router(), |
246 helper.remote_bitrate_estimator(), | |
247 helper.config(), helper.audio_state(), helper.event_log()); | 236 helper.config(), helper.audio_state(), helper.event_log()); |
248 } | 237 } |
249 | 238 |
250 TEST(AudioReceiveStreamTest, ReceiveRtpPacket) { | 239 TEST(AudioReceiveStreamTest, ReceiveRtpPacket) { |
251 ConfigHelper helper; | 240 ConfigHelper helper; |
252 helper.config().rtp.transport_cc = true; | 241 helper.config().rtp.transport_cc = true; |
253 helper.SetupMockForBweFeedback(true); | |
254 internal::AudioReceiveStream recv_stream( | 242 internal::AudioReceiveStream recv_stream( |
255 helper.packet_router(), | 243 helper.packet_router(), |
256 helper.remote_bitrate_estimator(), | |
257 helper.config(), helper.audio_state(), helper.event_log()); | 244 helper.config(), helper.audio_state(), helper.event_log()); |
258 const int kTransportSequenceNumberValue = 1234; | 245 const int kTransportSequenceNumberValue = 1234; |
259 std::vector<uint8_t> rtp_packet = CreateRtpHeaderWithOneByteExtension( | 246 std::vector<uint8_t> rtp_packet = CreateRtpHeaderWithOneByteExtension( |
260 kTransportSequenceNumberId, kTransportSequenceNumberValue, 2); | 247 kTransportSequenceNumberId, kTransportSequenceNumberValue, 2); |
261 PacketTime packet_time(5678000, 0); | 248 PacketTime packet_time(5678000, 0); |
262 EXPECT_CALL(*helper.channel_proxy(), | 249 EXPECT_CALL(*helper.channel_proxy(), |
263 ReceivedRTPPacket(&rtp_packet[0], | 250 ReceivedRTPPacket(&rtp_packet[0], |
264 rtp_packet.size(), | 251 rtp_packet.size(), |
265 _)) | 252 _)) |
266 .WillOnce(Return(true)); | 253 .WillOnce(Return(true)); |
267 EXPECT_TRUE( | 254 EXPECT_TRUE( |
268 recv_stream.DeliverRtp(&rtp_packet[0], rtp_packet.size(), packet_time)); | 255 recv_stream.DeliverRtp(&rtp_packet[0], rtp_packet.size(), packet_time)); |
269 } | 256 } |
270 | 257 |
271 TEST(AudioReceiveStreamTest, ReceiveRtcpPacket) { | 258 TEST(AudioReceiveStreamTest, ReceiveRtcpPacket) { |
272 ConfigHelper helper; | 259 ConfigHelper helper; |
273 helper.config().rtp.transport_cc = true; | 260 helper.config().rtp.transport_cc = true; |
274 helper.SetupMockForBweFeedback(true); | |
275 internal::AudioReceiveStream recv_stream( | 261 internal::AudioReceiveStream recv_stream( |
276 helper.packet_router(), | 262 helper.packet_router(), |
277 helper.remote_bitrate_estimator(), | |
278 helper.config(), helper.audio_state(), helper.event_log()); | 263 helper.config(), helper.audio_state(), helper.event_log()); |
279 | 264 |
280 std::vector<uint8_t> rtcp_packet = CreateRtcpSenderReport(); | 265 std::vector<uint8_t> rtcp_packet = CreateRtcpSenderReport(); |
281 EXPECT_CALL(*helper.channel_proxy(), | 266 EXPECT_CALL(*helper.channel_proxy(), |
282 ReceivedRTCPPacket(&rtcp_packet[0], rtcp_packet.size())) | 267 ReceivedRTCPPacket(&rtcp_packet[0], rtcp_packet.size())) |
283 .WillOnce(Return(true)); | 268 .WillOnce(Return(true)); |
284 EXPECT_TRUE(recv_stream.DeliverRtcp(&rtcp_packet[0], rtcp_packet.size())); | 269 EXPECT_TRUE(recv_stream.DeliverRtcp(&rtcp_packet[0], rtcp_packet.size())); |
285 } | 270 } |
286 | 271 |
287 TEST(AudioReceiveStreamTest, GetStats) { | 272 TEST(AudioReceiveStreamTest, GetStats) { |
288 ConfigHelper helper; | 273 ConfigHelper helper; |
289 internal::AudioReceiveStream recv_stream( | 274 internal::AudioReceiveStream recv_stream( |
290 helper.packet_router(), | 275 helper.packet_router(), |
291 helper.remote_bitrate_estimator(), | |
292 helper.config(), helper.audio_state(), helper.event_log()); | 276 helper.config(), helper.audio_state(), helper.event_log()); |
293 helper.SetupMockForGetStats(); | 277 helper.SetupMockForGetStats(); |
294 AudioReceiveStream::Stats stats = recv_stream.GetStats(); | 278 AudioReceiveStream::Stats stats = recv_stream.GetStats(); |
295 EXPECT_EQ(kRemoteSsrc, stats.remote_ssrc); | 279 EXPECT_EQ(kRemoteSsrc, stats.remote_ssrc); |
296 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesReceived), stats.bytes_rcvd); | 280 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesReceived), stats.bytes_rcvd); |
297 EXPECT_EQ(static_cast<uint32_t>(kCallStats.packetsReceived), | 281 EXPECT_EQ(static_cast<uint32_t>(kCallStats.packetsReceived), |
298 stats.packets_rcvd); | 282 stats.packets_rcvd); |
299 EXPECT_EQ(kCallStats.cumulativeLost, stats.packets_lost); | 283 EXPECT_EQ(kCallStats.cumulativeLost, stats.packets_lost); |
300 EXPECT_EQ(Q8ToFloat(kCallStats.fractionLost), stats.fraction_lost); | 284 EXPECT_EQ(Q8ToFloat(kCallStats.fractionLost), stats.fraction_lost); |
301 EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name); | 285 EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name); |
(...skipping 25 matching lines...) Expand all Loading... |
327 EXPECT_EQ(kAudioDecodeStats.decoded_muted_output, | 311 EXPECT_EQ(kAudioDecodeStats.decoded_muted_output, |
328 stats.decoding_muted_output); | 312 stats.decoding_muted_output); |
329 EXPECT_EQ(kCallStats.capture_start_ntp_time_ms_, | 313 EXPECT_EQ(kCallStats.capture_start_ntp_time_ms_, |
330 stats.capture_start_ntp_time_ms); | 314 stats.capture_start_ntp_time_ms); |
331 } | 315 } |
332 | 316 |
333 TEST(AudioReceiveStreamTest, SetGain) { | 317 TEST(AudioReceiveStreamTest, SetGain) { |
334 ConfigHelper helper; | 318 ConfigHelper helper; |
335 internal::AudioReceiveStream recv_stream( | 319 internal::AudioReceiveStream recv_stream( |
336 helper.packet_router(), | 320 helper.packet_router(), |
337 helper.remote_bitrate_estimator(), | |
338 helper.config(), helper.audio_state(), helper.event_log()); | 321 helper.config(), helper.audio_state(), helper.event_log()); |
339 EXPECT_CALL(*helper.channel_proxy(), | 322 EXPECT_CALL(*helper.channel_proxy(), |
340 SetChannelOutputVolumeScaling(FloatEq(0.765f))); | 323 SetChannelOutputVolumeScaling(FloatEq(0.765f))); |
341 recv_stream.SetGain(0.765f); | 324 recv_stream.SetGain(0.765f); |
342 } | 325 } |
343 | 326 |
344 TEST(AudioReceiveStreamTest, StreamShouldNotBeAddedToMixerWhenVoEReturnsError) { | 327 TEST(AudioReceiveStreamTest, StreamShouldNotBeAddedToMixerWhenVoEReturnsError) { |
345 ConfigHelper helper; | 328 ConfigHelper helper; |
346 internal::AudioReceiveStream recv_stream( | 329 internal::AudioReceiveStream recv_stream( |
347 helper.packet_router(), | 330 helper.packet_router(), |
348 helper.remote_bitrate_estimator(), | |
349 helper.config(), helper.audio_state(), helper.event_log()); | 331 helper.config(), helper.audio_state(), helper.event_log()); |
350 | 332 |
351 EXPECT_CALL(helper.voice_engine(), StartPlayout(_)).WillOnce(Return(-1)); | 333 EXPECT_CALL(helper.voice_engine(), StartPlayout(_)).WillOnce(Return(-1)); |
352 EXPECT_CALL(*helper.audio_mixer(), AddSource(_)).Times(0); | 334 EXPECT_CALL(*helper.audio_mixer(), AddSource(_)).Times(0); |
353 | 335 |
354 recv_stream.Start(); | 336 recv_stream.Start(); |
355 } | 337 } |
356 | 338 |
357 TEST(AudioReceiveStreamTest, StreamShouldBeAddedToMixerOnStart) { | 339 TEST(AudioReceiveStreamTest, StreamShouldBeAddedToMixerOnStart) { |
358 ConfigHelper helper; | 340 ConfigHelper helper; |
359 internal::AudioReceiveStream recv_stream( | 341 internal::AudioReceiveStream recv_stream( |
360 helper.packet_router(), | 342 helper.packet_router(), |
361 helper.remote_bitrate_estimator(), | |
362 helper.config(), helper.audio_state(), helper.event_log()); | 343 helper.config(), helper.audio_state(), helper.event_log()); |
363 | 344 |
364 EXPECT_CALL(helper.voice_engine(), StartPlayout(_)).WillOnce(Return(0)); | 345 EXPECT_CALL(helper.voice_engine(), StartPlayout(_)).WillOnce(Return(0)); |
365 EXPECT_CALL(helper.voice_engine(), StopPlayout(_)); | 346 EXPECT_CALL(helper.voice_engine(), StopPlayout(_)); |
366 EXPECT_CALL(*helper.audio_mixer(), AddSource(&recv_stream)) | 347 EXPECT_CALL(*helper.audio_mixer(), AddSource(&recv_stream)) |
367 .WillOnce(Return(true)); | 348 .WillOnce(Return(true)); |
368 | 349 |
369 recv_stream.Start(); | 350 recv_stream.Start(); |
370 } | 351 } |
371 } // namespace test | 352 } // namespace test |
372 } // namespace webrtc | 353 } // namespace webrtc |
OLD | NEW |