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 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 ConfigHelper() | 62 ConfigHelper() |
63 : simulated_clock_(123456), | 63 : simulated_clock_(123456), |
64 stream_config_(nullptr), | 64 stream_config_(nullptr), |
65 congestion_controller_(&simulated_clock_, | 65 congestion_controller_(&simulated_clock_, |
66 &bitrate_observer_, | 66 &bitrate_observer_, |
67 &remote_bitrate_observer_, | 67 &remote_bitrate_observer_, |
68 &event_log_), | 68 &event_log_), |
69 bitrate_allocator_(&limit_observer_), | 69 bitrate_allocator_(&limit_observer_), |
70 worker_queue_("ConfigHelper_worker_queue") { | 70 worker_queue_("ConfigHelper_worker_queue") { |
71 using testing::Invoke; | 71 using testing::Invoke; |
72 using testing::StrEq; | |
73 | 72 |
74 EXPECT_CALL(voice_engine_, | 73 EXPECT_CALL(voice_engine_, |
75 RegisterVoiceEngineObserver(_)).WillOnce(Return(0)); | 74 RegisterVoiceEngineObserver(_)).WillOnce(Return(0)); |
76 EXPECT_CALL(voice_engine_, | 75 EXPECT_CALL(voice_engine_, |
77 DeRegisterVoiceEngineObserver()).WillOnce(Return(0)); | 76 DeRegisterVoiceEngineObserver()).WillOnce(Return(0)); |
78 AudioState::Config config; | 77 AudioState::Config config; |
79 config.voice_engine = &voice_engine_; | 78 config.voice_engine = &voice_engine_; |
80 audio_state_ = AudioState::Create(config); | 79 audio_state_ = AudioState::Create(config); |
81 | 80 |
| 81 SetupDefaultChannelProxy(); |
| 82 |
82 EXPECT_CALL(voice_engine_, ChannelProxyFactory(kChannelId)) | 83 EXPECT_CALL(voice_engine_, ChannelProxyFactory(kChannelId)) |
83 .WillOnce(Invoke([this](int channel_id) { | 84 .WillOnce(Invoke([this](int channel_id) { |
84 EXPECT_FALSE(channel_proxy_); | |
85 channel_proxy_ = new testing::StrictMock<MockVoEChannelProxy>(); | |
86 EXPECT_CALL(*channel_proxy_, SetRTCPStatus(true)).Times(1); | |
87 EXPECT_CALL(*channel_proxy_, SetLocalSSRC(kSsrc)).Times(1); | |
88 EXPECT_CALL(*channel_proxy_, SetRTCP_CNAME(StrEq(kCName))).Times(1); | |
89 EXPECT_CALL(*channel_proxy_, SetNACKStatus(true, 10)).Times(1); | |
90 EXPECT_CALL(*channel_proxy_, | |
91 SetSendAbsoluteSenderTimeStatus(true, kAbsSendTimeId)).Times(1); | |
92 EXPECT_CALL(*channel_proxy_, | |
93 SetSendAudioLevelIndicationStatus(true, kAudioLevelId)).Times(1); | |
94 EXPECT_CALL(*channel_proxy_, EnableSendTransportSequenceNumber( | |
95 kTransportSequenceNumberId)) | |
96 .Times(1); | |
97 EXPECT_CALL(*channel_proxy_, | |
98 RegisterSenderCongestionControlObjects( | |
99 congestion_controller_.pacer(), | |
100 congestion_controller_.GetTransportFeedbackObserver(), | |
101 congestion_controller_.packet_router())) | |
102 .Times(1); | |
103 EXPECT_CALL(*channel_proxy_, ResetCongestionControlObjects()) | |
104 .Times(1); | |
105 EXPECT_CALL(*channel_proxy_, RegisterExternalTransport(nullptr)) | |
106 .Times(1); | |
107 EXPECT_CALL(*channel_proxy_, DeRegisterExternalTransport()) | |
108 .Times(1); | |
109 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::NotNull())) | |
110 .Times(1); | |
111 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::IsNull())) | |
112 .Times(1); // Destructor resets the event log | |
113 return channel_proxy_; | 85 return channel_proxy_; |
114 })); | 86 })); |
| 87 |
115 SetupMockForSetupSendCodec(); | 88 SetupMockForSetupSendCodec(); |
| 89 |
116 stream_config_.voe_channel_id = kChannelId; | 90 stream_config_.voe_channel_id = kChannelId; |
117 stream_config_.rtp.ssrc = kSsrc; | 91 stream_config_.rtp.ssrc = kSsrc; |
118 stream_config_.rtp.nack.rtp_history_ms = 200; | 92 stream_config_.rtp.nack.rtp_history_ms = 200; |
119 stream_config_.rtp.c_name = kCName; | 93 stream_config_.rtp.c_name = kCName; |
120 stream_config_.rtp.extensions.push_back( | 94 stream_config_.rtp.extensions.push_back( |
121 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId)); | 95 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId)); |
122 stream_config_.rtp.extensions.push_back( | 96 stream_config_.rtp.extensions.push_back( |
123 RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId)); | 97 RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId)); |
124 stream_config_.rtp.extensions.push_back(RtpExtension( | 98 stream_config_.rtp.extensions.push_back(RtpExtension( |
125 RtpExtension::kTransportSequenceNumberUri, kTransportSequenceNumberId)); | 99 RtpExtension::kTransportSequenceNumberUri, kTransportSequenceNumberId)); |
126 // Use ISAC as default codec so as to prevent unnecessary |voice_engine_| | 100 // Use ISAC as default codec so as to prevent unnecessary |voice_engine_| |
127 // calls from the default ctor behavior. | 101 // calls from the default ctor behavior. |
128 stream_config_.send_codec_spec.codec_inst = kIsacCodec; | 102 stream_config_.send_codec_spec.codec_inst = kIsacCodec; |
129 } | 103 } |
130 | 104 |
131 AudioSendStream::Config& config() { return stream_config_; } | 105 AudioSendStream::Config& config() { return stream_config_; } |
132 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } | 106 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } |
133 MockVoEChannelProxy* channel_proxy() { return channel_proxy_; } | 107 MockVoEChannelProxy* channel_proxy() { return channel_proxy_; } |
134 CongestionController* congestion_controller() { | 108 CongestionController* congestion_controller() { |
135 return &congestion_controller_; | 109 return &congestion_controller_; |
136 } | 110 } |
137 BitrateAllocator* bitrate_allocator() { return &bitrate_allocator_; } | 111 BitrateAllocator* bitrate_allocator() { return &bitrate_allocator_; } |
138 rtc::TaskQueue* worker_queue() { return &worker_queue_; } | 112 rtc::TaskQueue* worker_queue() { return &worker_queue_; } |
139 RtcEventLog* event_log() { return &event_log_; } | 113 RtcEventLog* event_log() { return &event_log_; } |
140 MockVoiceEngine* voice_engine() { return &voice_engine_; } | 114 MockVoiceEngine* voice_engine() { return &voice_engine_; } |
141 | 115 |
| 116 void SetupDefaultChannelProxy() { |
| 117 using testing::StrEq; |
| 118 channel_proxy_ = new testing::StrictMock<MockVoEChannelProxy>(); |
| 119 EXPECT_CALL(*channel_proxy_, SetRTCPStatus(true)).Times(1); |
| 120 EXPECT_CALL(*channel_proxy_, SetLocalSSRC(kSsrc)).Times(1); |
| 121 EXPECT_CALL(*channel_proxy_, SetRTCP_CNAME(StrEq(kCName))).Times(1); |
| 122 EXPECT_CALL(*channel_proxy_, SetNACKStatus(true, 10)).Times(1); |
| 123 EXPECT_CALL(*channel_proxy_, |
| 124 SetSendAbsoluteSenderTimeStatus(true, kAbsSendTimeId)) |
| 125 .Times(1); |
| 126 EXPECT_CALL(*channel_proxy_, |
| 127 SetSendAudioLevelIndicationStatus(true, kAudioLevelId)) |
| 128 .Times(1); |
| 129 EXPECT_CALL(*channel_proxy_, |
| 130 EnableSendTransportSequenceNumber(kTransportSequenceNumberId)) |
| 131 .Times(1); |
| 132 EXPECT_CALL(*channel_proxy_, |
| 133 RegisterSenderCongestionControlObjects( |
| 134 congestion_controller_.pacer(), |
| 135 congestion_controller_.GetTransportFeedbackObserver(), |
| 136 congestion_controller_.packet_router())) |
| 137 .Times(1); |
| 138 EXPECT_CALL(*channel_proxy_, ResetCongestionControlObjects()).Times(1); |
| 139 EXPECT_CALL(*channel_proxy_, RegisterExternalTransport(nullptr)).Times(1); |
| 140 EXPECT_CALL(*channel_proxy_, DeRegisterExternalTransport()).Times(1); |
| 141 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::NotNull())).Times(1); |
| 142 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::IsNull())) |
| 143 .Times(1); // Destructor resets the event log |
| 144 } |
| 145 |
142 void SetupMockForSetupSendCodec() { | 146 void SetupMockForSetupSendCodec() { |
143 EXPECT_CALL(voice_engine_, SetVADStatus(kChannelId, false, _, _)) | 147 EXPECT_CALL(voice_engine_, SetVADStatus(kChannelId, false, _, _)) |
144 .WillOnce(Return(0)); | 148 .WillOnce(Return(0)); |
145 EXPECT_CALL(voice_engine_, SetFECStatus(kChannelId, false)) | 149 EXPECT_CALL(voice_engine_, SetFECStatus(kChannelId, false)) |
146 .WillOnce(Return(0)); | 150 .WillOnce(Return(0)); |
147 // Let |GetSendCodec| return -1 for the first time to indicate that no send | 151 // Let |GetSendCodec| return -1 for the first time to indicate that no send |
148 // codec has been set. | 152 // codec has been set. |
149 EXPECT_CALL(voice_engine_, GetSendCodec(kChannelId, _)) | 153 EXPECT_CALL(voice_engine_, GetSendCodec(kChannelId, _)) |
150 .WillOnce(Return(-1)); | 154 .WillOnce(Return(-1)); |
151 EXPECT_CALL(voice_engine_, SetSendCodec(kChannelId, _)).WillOnce(Return(0)); | 155 EXPECT_CALL(voice_engine_, SetSendCodec(kChannelId, _)).WillOnce(Return(0)); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 config.voe_channel_id = kChannelId; | 225 config.voe_channel_id = kChannelId; |
222 config.min_bitrate_kbps = 12; | 226 config.min_bitrate_kbps = 12; |
223 config.max_bitrate_kbps = 34; | 227 config.max_bitrate_kbps = 34; |
224 config.send_codec_spec.nack_enabled = true; | 228 config.send_codec_spec.nack_enabled = true; |
225 config.send_codec_spec.transport_cc_enabled = false; | 229 config.send_codec_spec.transport_cc_enabled = false; |
226 config.send_codec_spec.enable_codec_fec = true; | 230 config.send_codec_spec.enable_codec_fec = true; |
227 config.send_codec_spec.enable_opus_dtx = false; | 231 config.send_codec_spec.enable_opus_dtx = false; |
228 config.send_codec_spec.opus_max_playback_rate = 32000; | 232 config.send_codec_spec.opus_max_playback_rate = 32000; |
229 config.send_codec_spec.cng_payload_type = 42; | 233 config.send_codec_spec.cng_payload_type = 42; |
230 config.send_codec_spec.cng_plfreq = 56; | 234 config.send_codec_spec.cng_plfreq = 56; |
| 235 config.send_codec_spec.min_ptime_ms = 20; |
| 236 config.send_codec_spec.max_ptime_ms = 60; |
231 config.send_codec_spec.codec_inst = kIsacCodec; | 237 config.send_codec_spec.codec_inst = kIsacCodec; |
232 EXPECT_EQ( | 238 EXPECT_EQ( |
233 "{rtp: {ssrc: 1234, extensions: [{uri: " | 239 "{rtp: {ssrc: 1234, extensions: [{uri: " |
234 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}], " | 240 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}], " |
235 "nack: {rtp_history_ms: 0}, c_name: foo_name}, send_transport: nullptr, " | 241 "nack: {rtp_history_ms: 0}, c_name: foo_name}, send_transport: nullptr, " |
236 "voe_channel_id: 1, min_bitrate_kbps: 12, max_bitrate_kbps: 34, " | 242 "voe_channel_id: 1, min_bitrate_kbps: 12, max_bitrate_kbps: 34, " |
237 "send_codec_spec: {nack_enabled: true, transport_cc_enabled: false, " | 243 "send_codec_spec: {nack_enabled: true, transport_cc_enabled: false, " |
238 "enable_codec_fec: true, enable_opus_dtx: false, opus_max_playback_rate: " | 244 "enable_codec_fec: true, enable_opus_dtx: false, opus_max_playback_rate: " |
239 "32000, cng_payload_type: 42, cng_plfreq: 56, codec_inst: {pltype: " | 245 "32000, cng_payload_type: 42, cng_plfreq: 56, min_ptime: 20, max_ptime: " |
240 "103, plname: \"isac\", plfreq: 16000, pacsize: 320, channels: 1, rate: " | 246 "60, codec_inst: {pltype: 103, plname: \"isac\", plfreq: 16000, pacsize: " |
241 "32000}}}", | 247 "320, channels: 1, rate: 32000}}}", |
242 config.ToString()); | 248 config.ToString()); |
243 } | 249 } |
244 | 250 |
245 TEST(AudioSendStreamTest, ConstructDestruct) { | 251 TEST(AudioSendStreamTest, ConstructDestruct) { |
246 ConfigHelper helper; | 252 ConfigHelper helper; |
247 internal::AudioSendStream send_stream( | 253 internal::AudioSendStream send_stream( |
248 helper.config(), helper.audio_state(), helper.worker_queue(), | 254 helper.config(), helper.audio_state(), helper.worker_queue(), |
249 helper.congestion_controller(), helper.bitrate_allocator(), | 255 helper.congestion_controller(), helper.bitrate_allocator(), |
250 helper.event_log()); | 256 helper.event_log()); |
251 } | 257 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 TEST(AudioSendStreamTest, SendCodecAppliesConfigParams) { | 330 TEST(AudioSendStreamTest, SendCodecAppliesConfigParams) { |
325 ConfigHelper helper; | 331 ConfigHelper helper; |
326 auto stream_config = helper.config(); | 332 auto stream_config = helper.config(); |
327 const CodecInst kOpusCodec = {111, "opus", 48000, 960, 2, 64000}; | 333 const CodecInst kOpusCodec = {111, "opus", 48000, 960, 2, 64000}; |
328 stream_config.send_codec_spec.codec_inst = kOpusCodec; | 334 stream_config.send_codec_spec.codec_inst = kOpusCodec; |
329 stream_config.send_codec_spec.enable_codec_fec = true; | 335 stream_config.send_codec_spec.enable_codec_fec = true; |
330 stream_config.send_codec_spec.enable_opus_dtx = true; | 336 stream_config.send_codec_spec.enable_opus_dtx = true; |
331 stream_config.send_codec_spec.opus_max_playback_rate = 12345; | 337 stream_config.send_codec_spec.opus_max_playback_rate = 12345; |
332 stream_config.send_codec_spec.cng_plfreq = 16000; | 338 stream_config.send_codec_spec.cng_plfreq = 16000; |
333 stream_config.send_codec_spec.cng_payload_type = 105; | 339 stream_config.send_codec_spec.cng_payload_type = 105; |
| 340 stream_config.send_codec_spec.min_ptime_ms = 10; |
| 341 stream_config.send_codec_spec.max_ptime_ms = 60; |
| 342 stream_config.audio_network_adaptor_config = |
| 343 rtc::Optional<std::string>("abced"); |
334 EXPECT_CALL(*helper.voice_engine(), SetFECStatus(kChannelId, true)) | 344 EXPECT_CALL(*helper.voice_engine(), SetFECStatus(kChannelId, true)) |
335 .WillOnce(Return(0)); | 345 .WillOnce(Return(0)); |
336 EXPECT_CALL( | 346 EXPECT_CALL( |
337 *helper.voice_engine(), | 347 *helper.voice_engine(), |
338 SetOpusDtx(kChannelId, stream_config.send_codec_spec.enable_opus_dtx)) | 348 SetOpusDtx(kChannelId, stream_config.send_codec_spec.enable_opus_dtx)) |
339 .WillOnce(Return(0)); | 349 .WillOnce(Return(0)); |
340 EXPECT_CALL( | 350 EXPECT_CALL( |
341 *helper.voice_engine(), | 351 *helper.voice_engine(), |
342 SetOpusMaxPlaybackRate( | 352 SetOpusMaxPlaybackRate( |
343 kChannelId, stream_config.send_codec_spec.opus_max_playback_rate)) | 353 kChannelId, stream_config.send_codec_spec.opus_max_playback_rate)) |
344 .WillOnce(Return(0)); | 354 .WillOnce(Return(0)); |
345 EXPECT_CALL(*helper.voice_engine(), | 355 EXPECT_CALL(*helper.voice_engine(), |
346 SetSendCNPayloadType( | 356 SetSendCNPayloadType( |
347 kChannelId, stream_config.send_codec_spec.cng_payload_type, | 357 kChannelId, stream_config.send_codec_spec.cng_payload_type, |
348 webrtc::kFreq16000Hz)) | 358 webrtc::kFreq16000Hz)) |
349 .WillOnce(Return(0)); | 359 .WillOnce(Return(0)); |
| 360 EXPECT_CALL( |
| 361 *helper.channel_proxy(), |
| 362 SetReceiverFrameLengthRange(stream_config.send_codec_spec.min_ptime_ms, |
| 363 stream_config.send_codec_spec.max_ptime_ms)); |
| 364 EXPECT_CALL( |
| 365 *helper.channel_proxy(), |
| 366 EnableAudioNetworkAdaptor(*stream_config.audio_network_adaptor_config)); |
350 internal::AudioSendStream send_stream( | 367 internal::AudioSendStream send_stream( |
351 stream_config, helper.audio_state(), helper.worker_queue(), | 368 stream_config, helper.audio_state(), helper.worker_queue(), |
352 helper.congestion_controller(), helper.bitrate_allocator(), | 369 helper.congestion_controller(), helper.bitrate_allocator(), |
353 helper.event_log()); | 370 helper.event_log()); |
354 } | 371 } |
355 | 372 |
356 // VAD is applied when codec is mono and the CNG frequency matches the codec | 373 // VAD is applied when codec is mono and the CNG frequency matches the codec |
357 // sample rate. | 374 // sample rate. |
358 TEST(AudioSendStreamTest, SendCodecCanApplyVad) { | 375 TEST(AudioSendStreamTest, SendCodecCanApplyVad) { |
359 ConfigHelper helper; | 376 ConfigHelper helper; |
360 auto stream_config = helper.config(); | 377 auto stream_config = helper.config(); |
361 const CodecInst kG722Codec = {9, "g722", 8000, 160, 1, 16000}; | 378 const CodecInst kG722Codec = {9, "g722", 8000, 160, 1, 16000}; |
362 stream_config.send_codec_spec.codec_inst = kG722Codec; | 379 stream_config.send_codec_spec.codec_inst = kG722Codec; |
363 stream_config.send_codec_spec.cng_plfreq = 8000; | 380 stream_config.send_codec_spec.cng_plfreq = 8000; |
364 stream_config.send_codec_spec.cng_payload_type = 105; | 381 stream_config.send_codec_spec.cng_payload_type = 105; |
365 EXPECT_CALL(*helper.voice_engine(), SetVADStatus(kChannelId, true, _, _)) | 382 EXPECT_CALL(*helper.voice_engine(), SetVADStatus(kChannelId, true, _, _)) |
366 .WillOnce(Return(0)); | 383 .WillOnce(Return(0)); |
367 internal::AudioSendStream send_stream( | 384 internal::AudioSendStream send_stream( |
368 stream_config, helper.audio_state(), helper.worker_queue(), | 385 stream_config, helper.audio_state(), helper.worker_queue(), |
369 helper.congestion_controller(), helper.bitrate_allocator(), | 386 helper.congestion_controller(), helper.bitrate_allocator(), |
370 helper.event_log()); | 387 helper.event_log()); |
371 } | 388 } |
372 | 389 |
373 } // namespace test | 390 } // namespace test |
374 } // namespace webrtc | 391 } // namespace webrtc |
OLD | NEW |