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/audio/audio_send_stream.h" | 14 #include "webrtc/audio/audio_send_stream.h" |
15 #include "webrtc/audio/audio_state.h" | 15 #include "webrtc/audio/audio_state.h" |
16 #include "webrtc/audio/conversion.h" | 16 #include "webrtc/audio/conversion.h" |
17 #include "webrtc/base/task_queue.h" | 17 #include "webrtc/base/task_queue.h" |
18 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" | 18 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" |
19 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" | 19 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" |
20 #include "webrtc/modules/audio_processing/include/mock_audio_processing.h" | 20 #include "webrtc/modules/audio_processing/include/mock_audio_processing.h" |
21 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 21 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
22 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont
roller.h" | 22 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont
roller.h" |
23 #include "webrtc/modules/pacing/paced_sender.h" | 23 #include "webrtc/modules/pacing/paced_sender.h" |
24 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra
te_estimator.h" | 24 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra
te_estimator.h" |
| 25 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtcp_rtt_stats.h" |
25 #include "webrtc/test/gtest.h" | 26 #include "webrtc/test/gtest.h" |
26 #include "webrtc/test/mock_voe_channel_proxy.h" | 27 #include "webrtc/test/mock_voe_channel_proxy.h" |
27 #include "webrtc/test/mock_voice_engine.h" | 28 #include "webrtc/test/mock_voice_engine.h" |
28 | 29 |
29 namespace webrtc { | 30 namespace webrtc { |
30 namespace test { | 31 namespace test { |
31 namespace { | 32 namespace { |
32 | 33 |
33 using testing::_; | 34 using testing::_; |
34 using testing::Return; | 35 using testing::Return; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 congestion_controller_.pacer(), | 137 congestion_controller_.pacer(), |
137 congestion_controller_.GetTransportFeedbackObserver(), | 138 congestion_controller_.GetTransportFeedbackObserver(), |
138 congestion_controller_.packet_router())) | 139 congestion_controller_.packet_router())) |
139 .Times(1); | 140 .Times(1); |
140 EXPECT_CALL(*channel_proxy_, ResetCongestionControlObjects()).Times(1); | 141 EXPECT_CALL(*channel_proxy_, ResetCongestionControlObjects()).Times(1); |
141 EXPECT_CALL(*channel_proxy_, RegisterExternalTransport(nullptr)).Times(1); | 142 EXPECT_CALL(*channel_proxy_, RegisterExternalTransport(nullptr)).Times(1); |
142 EXPECT_CALL(*channel_proxy_, DeRegisterExternalTransport()).Times(1); | 143 EXPECT_CALL(*channel_proxy_, DeRegisterExternalTransport()).Times(1); |
143 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::NotNull())).Times(1); | 144 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::NotNull())).Times(1); |
144 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::IsNull())) | 145 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::IsNull())) |
145 .Times(1); // Destructor resets the event log | 146 .Times(1); // Destructor resets the event log |
| 147 EXPECT_CALL(*channel_proxy_, SetRtcpRttStats(&rtcp_rtt_stats_)) |
| 148 .Times(1); |
146 } | 149 } |
147 | 150 |
148 void SetupMockForSetupSendCodec() { | 151 void SetupMockForSetupSendCodec() { |
149 EXPECT_CALL(voice_engine_, SetVADStatus(kChannelId, false, _, _)) | 152 EXPECT_CALL(voice_engine_, SetVADStatus(kChannelId, false, _, _)) |
150 .WillOnce(Return(0)); | 153 .WillOnce(Return(0)); |
151 EXPECT_CALL(voice_engine_, SetFECStatus(kChannelId, false)) | 154 EXPECT_CALL(voice_engine_, SetFECStatus(kChannelId, false)) |
152 .WillOnce(Return(0)); | 155 .WillOnce(Return(0)); |
153 EXPECT_CALL(*channel_proxy_, DisableAudioNetworkAdaptor()); | 156 EXPECT_CALL(*channel_proxy_, DisableAudioNetworkAdaptor()); |
154 // Let |GetSendCodec| return -1 for the first time to indicate that no send | 157 // Let |GetSendCodec| return -1 for the first time to indicate that no send |
155 // codec has been set. | 158 // codec has been set. |
156 EXPECT_CALL(voice_engine_, GetSendCodec(kChannelId, _)) | 159 EXPECT_CALL(voice_engine_, GetSendCodec(kChannelId, _)) |
157 .WillOnce(Return(-1)); | 160 .WillOnce(Return(-1)); |
158 EXPECT_CALL(voice_engine_, SetSendCodec(kChannelId, _)).WillOnce(Return(0)); | 161 EXPECT_CALL(voice_engine_, SetSendCodec(kChannelId, _)).WillOnce(Return(0)); |
159 } | 162 } |
| 163 RtcpRttStats* rtcp_rtt_stats() { return &rtcp_rtt_stats_; } |
160 | 164 |
161 void SetupMockForSendTelephoneEvent() { | 165 void SetupMockForSendTelephoneEvent() { |
162 EXPECT_TRUE(channel_proxy_); | 166 EXPECT_TRUE(channel_proxy_); |
163 EXPECT_CALL(*channel_proxy_, | 167 EXPECT_CALL(*channel_proxy_, |
164 SetSendTelephoneEventPayloadType(kTelephoneEventPayloadType, | 168 SetSendTelephoneEventPayloadType(kTelephoneEventPayloadType, |
165 kTelephoneEventPayloadFrequency)) | 169 kTelephoneEventPayloadFrequency)) |
166 .WillOnce(Return(true)); | 170 .WillOnce(Return(true)); |
167 EXPECT_CALL(*channel_proxy_, | 171 EXPECT_CALL(*channel_proxy_, |
168 SendTelephoneEventOutband(kTelephoneEventCode, kTelephoneEventDuration)) | 172 SendTelephoneEventOutband(kTelephoneEventCode, kTelephoneEventDuration)) |
169 .WillOnce(Return(true)); | 173 .WillOnce(Return(true)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 testing::StrictMock<MockVoiceEngine> voice_engine_; | 217 testing::StrictMock<MockVoiceEngine> voice_engine_; |
214 rtc::scoped_refptr<AudioState> audio_state_; | 218 rtc::scoped_refptr<AudioState> audio_state_; |
215 AudioSendStream::Config stream_config_; | 219 AudioSendStream::Config stream_config_; |
216 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr; | 220 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr; |
217 testing::NiceMock<MockCongestionObserver> bitrate_observer_; | 221 testing::NiceMock<MockCongestionObserver> bitrate_observer_; |
218 testing::NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; | 222 testing::NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; |
219 MockAudioProcessing audio_processing_; | 223 MockAudioProcessing audio_processing_; |
220 AudioProcessing::AudioProcessingStatistics audio_processing_stats_; | 224 AudioProcessing::AudioProcessingStatistics audio_processing_stats_; |
221 CongestionController congestion_controller_; | 225 CongestionController congestion_controller_; |
222 MockRtcEventLog event_log_; | 226 MockRtcEventLog event_log_; |
| 227 MockRtcpRttStats rtcp_rtt_stats_; |
223 testing::NiceMock<MockLimitObserver> limit_observer_; | 228 testing::NiceMock<MockLimitObserver> limit_observer_; |
224 BitrateAllocator bitrate_allocator_; | 229 BitrateAllocator bitrate_allocator_; |
225 // |worker_queue| is defined last to ensure all pending tasks are cancelled | 230 // |worker_queue| is defined last to ensure all pending tasks are cancelled |
226 // and deleted before any other members. | 231 // and deleted before any other members. |
227 rtc::TaskQueue worker_queue_; | 232 rtc::TaskQueue worker_queue_; |
228 }; | 233 }; |
229 } // namespace | 234 } // namespace |
230 | 235 |
231 TEST(AudioSendStreamTest, ConfigToString) { | 236 TEST(AudioSendStreamTest, ConfigToString) { |
232 AudioSendStream::Config config(nullptr); | 237 AudioSendStream::Config config(nullptr); |
(...skipping 25 matching lines...) Expand all Loading... |
258 "60, codec_inst: {pltype: 103, plname: \"isac\", plfreq: 16000, pacsize: " | 263 "60, codec_inst: {pltype: 103, plname: \"isac\", plfreq: 16000, pacsize: " |
259 "320, channels: 1, rate: 32000}}}", | 264 "320, channels: 1, rate: 32000}}}", |
260 config.ToString()); | 265 config.ToString()); |
261 } | 266 } |
262 | 267 |
263 TEST(AudioSendStreamTest, ConstructDestruct) { | 268 TEST(AudioSendStreamTest, ConstructDestruct) { |
264 ConfigHelper helper; | 269 ConfigHelper helper; |
265 internal::AudioSendStream send_stream( | 270 internal::AudioSendStream send_stream( |
266 helper.config(), helper.audio_state(), helper.worker_queue(), | 271 helper.config(), helper.audio_state(), helper.worker_queue(), |
267 helper.congestion_controller(), helper.bitrate_allocator(), | 272 helper.congestion_controller(), helper.bitrate_allocator(), |
268 helper.event_log()); | 273 helper.event_log(), helper.rtcp_rtt_stats()); |
269 } | 274 } |
270 | 275 |
271 TEST(AudioSendStreamTest, SendTelephoneEvent) { | 276 TEST(AudioSendStreamTest, SendTelephoneEvent) { |
272 ConfigHelper helper; | 277 ConfigHelper helper; |
273 internal::AudioSendStream send_stream( | 278 internal::AudioSendStream send_stream( |
274 helper.config(), helper.audio_state(), helper.worker_queue(), | 279 helper.config(), helper.audio_state(), helper.worker_queue(), |
275 helper.congestion_controller(), helper.bitrate_allocator(), | 280 helper.congestion_controller(), helper.bitrate_allocator(), |
276 helper.event_log()); | 281 helper.event_log(), helper.rtcp_rtt_stats()); |
277 helper.SetupMockForSendTelephoneEvent(); | 282 helper.SetupMockForSendTelephoneEvent(); |
278 EXPECT_TRUE(send_stream.SendTelephoneEvent(kTelephoneEventPayloadType, | 283 EXPECT_TRUE(send_stream.SendTelephoneEvent(kTelephoneEventPayloadType, |
279 kTelephoneEventPayloadFrequency, kTelephoneEventCode, | 284 kTelephoneEventPayloadFrequency, kTelephoneEventCode, |
280 kTelephoneEventDuration)); | 285 kTelephoneEventDuration)); |
281 } | 286 } |
282 | 287 |
283 TEST(AudioSendStreamTest, SetMuted) { | 288 TEST(AudioSendStreamTest, SetMuted) { |
284 ConfigHelper helper; | 289 ConfigHelper helper; |
285 internal::AudioSendStream send_stream( | 290 internal::AudioSendStream send_stream( |
286 helper.config(), helper.audio_state(), helper.worker_queue(), | 291 helper.config(), helper.audio_state(), helper.worker_queue(), |
287 helper.congestion_controller(), helper.bitrate_allocator(), | 292 helper.congestion_controller(), helper.bitrate_allocator(), |
288 helper.event_log()); | 293 helper.event_log(), helper.rtcp_rtt_stats()); |
289 EXPECT_CALL(*helper.channel_proxy(), SetInputMute(true)); | 294 EXPECT_CALL(*helper.channel_proxy(), SetInputMute(true)); |
290 send_stream.SetMuted(true); | 295 send_stream.SetMuted(true); |
291 } | 296 } |
292 | 297 |
293 TEST(AudioSendStreamTest, GetStats) { | 298 TEST(AudioSendStreamTest, GetStats) { |
294 ConfigHelper helper; | 299 ConfigHelper helper; |
295 internal::AudioSendStream send_stream( | 300 internal::AudioSendStream send_stream( |
296 helper.config(), helper.audio_state(), helper.worker_queue(), | 301 helper.config(), helper.audio_state(), helper.worker_queue(), |
297 helper.congestion_controller(), helper.bitrate_allocator(), | 302 helper.congestion_controller(), helper.bitrate_allocator(), |
298 helper.event_log()); | 303 helper.event_log(), helper.rtcp_rtt_stats()); |
299 helper.SetupMockForGetStats(); | 304 helper.SetupMockForGetStats(); |
300 AudioSendStream::Stats stats = send_stream.GetStats(); | 305 AudioSendStream::Stats stats = send_stream.GetStats(); |
301 EXPECT_EQ(kSsrc, stats.local_ssrc); | 306 EXPECT_EQ(kSsrc, stats.local_ssrc); |
302 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesSent), stats.bytes_sent); | 307 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesSent), stats.bytes_sent); |
303 EXPECT_EQ(kCallStats.packetsSent, stats.packets_sent); | 308 EXPECT_EQ(kCallStats.packetsSent, stats.packets_sent); |
304 EXPECT_EQ(static_cast<int32_t>(kReportBlock.cumulative_num_packets_lost), | 309 EXPECT_EQ(static_cast<int32_t>(kReportBlock.cumulative_num_packets_lost), |
305 stats.packets_lost); | 310 stats.packets_lost); |
306 EXPECT_EQ(Q8ToFloat(kReportBlock.fraction_lost), stats.fraction_lost); | 311 EXPECT_EQ(Q8ToFloat(kReportBlock.fraction_lost), stats.fraction_lost); |
307 EXPECT_EQ(std::string(kIsacCodec.plname), stats.codec_name); | 312 EXPECT_EQ(std::string(kIsacCodec.plname), stats.codec_name); |
308 EXPECT_EQ(static_cast<int32_t>(kReportBlock.extended_highest_sequence_number), | 313 EXPECT_EQ(static_cast<int32_t>(kReportBlock.extended_highest_sequence_number), |
(...skipping 10 matching lines...) Expand all Loading... |
319 EXPECT_EQ(kEchoReturnLossEnhancement, stats.echo_return_loss_enhancement); | 324 EXPECT_EQ(kEchoReturnLossEnhancement, stats.echo_return_loss_enhancement); |
320 EXPECT_EQ(kResidualEchoLikelihood, stats.residual_echo_likelihood); | 325 EXPECT_EQ(kResidualEchoLikelihood, stats.residual_echo_likelihood); |
321 EXPECT_FALSE(stats.typing_noise_detected); | 326 EXPECT_FALSE(stats.typing_noise_detected); |
322 } | 327 } |
323 | 328 |
324 TEST(AudioSendStreamTest, GetStatsTypingNoiseDetected) { | 329 TEST(AudioSendStreamTest, GetStatsTypingNoiseDetected) { |
325 ConfigHelper helper; | 330 ConfigHelper helper; |
326 internal::AudioSendStream send_stream( | 331 internal::AudioSendStream send_stream( |
327 helper.config(), helper.audio_state(), helper.worker_queue(), | 332 helper.config(), helper.audio_state(), helper.worker_queue(), |
328 helper.congestion_controller(), helper.bitrate_allocator(), | 333 helper.congestion_controller(), helper.bitrate_allocator(), |
329 helper.event_log()); | 334 helper.event_log(), helper.rtcp_rtt_stats()); |
330 helper.SetupMockForGetStats(); | 335 helper.SetupMockForGetStats(); |
331 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); | 336 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); |
332 | 337 |
333 internal::AudioState* internal_audio_state = | 338 internal::AudioState* internal_audio_state = |
334 static_cast<internal::AudioState*>(helper.audio_state().get()); | 339 static_cast<internal::AudioState*>(helper.audio_state().get()); |
335 VoiceEngineObserver* voe_observer = | 340 VoiceEngineObserver* voe_observer = |
336 static_cast<VoiceEngineObserver*>(internal_audio_state); | 341 static_cast<VoiceEngineObserver*>(internal_audio_state); |
337 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING); | 342 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING); |
338 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected); | 343 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected); |
339 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING); | 344 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 EXPECT_CALL( | 378 EXPECT_CALL( |
374 *helper.channel_proxy(), | 379 *helper.channel_proxy(), |
375 SetReceiverFrameLengthRange(stream_config.send_codec_spec.min_ptime_ms, | 380 SetReceiverFrameLengthRange(stream_config.send_codec_spec.min_ptime_ms, |
376 stream_config.send_codec_spec.max_ptime_ms)); | 381 stream_config.send_codec_spec.max_ptime_ms)); |
377 EXPECT_CALL( | 382 EXPECT_CALL( |
378 *helper.channel_proxy(), | 383 *helper.channel_proxy(), |
379 EnableAudioNetworkAdaptor(*stream_config.audio_network_adaptor_config)); | 384 EnableAudioNetworkAdaptor(*stream_config.audio_network_adaptor_config)); |
380 internal::AudioSendStream send_stream( | 385 internal::AudioSendStream send_stream( |
381 stream_config, helper.audio_state(), helper.worker_queue(), | 386 stream_config, helper.audio_state(), helper.worker_queue(), |
382 helper.congestion_controller(), helper.bitrate_allocator(), | 387 helper.congestion_controller(), helper.bitrate_allocator(), |
383 helper.event_log()); | 388 helper.event_log(), helper.rtcp_rtt_stats()); |
384 } | 389 } |
385 | 390 |
386 // VAD is applied when codec is mono and the CNG frequency matches the codec | 391 // VAD is applied when codec is mono and the CNG frequency matches the codec |
387 // sample rate. | 392 // sample rate. |
388 TEST(AudioSendStreamTest, SendCodecCanApplyVad) { | 393 TEST(AudioSendStreamTest, SendCodecCanApplyVad) { |
389 ConfigHelper helper; | 394 ConfigHelper helper; |
390 auto stream_config = helper.config(); | 395 auto stream_config = helper.config(); |
391 const CodecInst kG722Codec = {9, "g722", 8000, 160, 1, 16000}; | 396 const CodecInst kG722Codec = {9, "g722", 8000, 160, 1, 16000}; |
392 stream_config.send_codec_spec.codec_inst = kG722Codec; | 397 stream_config.send_codec_spec.codec_inst = kG722Codec; |
393 stream_config.send_codec_spec.cng_plfreq = 8000; | 398 stream_config.send_codec_spec.cng_plfreq = 8000; |
394 stream_config.send_codec_spec.cng_payload_type = 105; | 399 stream_config.send_codec_spec.cng_payload_type = 105; |
395 EXPECT_CALL(*helper.voice_engine(), SetVADStatus(kChannelId, true, _, _)) | 400 EXPECT_CALL(*helper.voice_engine(), SetVADStatus(kChannelId, true, _, _)) |
396 .WillOnce(Return(0)); | 401 .WillOnce(Return(0)); |
397 internal::AudioSendStream send_stream( | 402 internal::AudioSendStream send_stream( |
398 stream_config, helper.audio_state(), helper.worker_queue(), | 403 stream_config, helper.audio_state(), helper.worker_queue(), |
399 helper.congestion_controller(), helper.bitrate_allocator(), | 404 helper.congestion_controller(), helper.bitrate_allocator(), |
400 helper.event_log()); | 405 helper.event_log(), helper.rtcp_rtt_stats()); |
401 } | 406 } |
402 | 407 |
403 } // namespace test | 408 } // namespace test |
404 } // namespace webrtc | 409 } // namespace webrtc |
OLD | NEW |