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/call/mock/mock_rtc_event_log.h" | 18 #include "webrtc/call/mock/mock_rtc_event_log.h" |
19 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 19 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
20 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont
roller.h" | 20 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont
roller.h" |
21 #include "webrtc/modules/pacing/paced_sender.h" | 21 #include "webrtc/modules/pacing/paced_sender.h" |
22 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra
te_estimator.h" | 22 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra
te_estimator.h" |
23 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtcp_rtt_stats.h" | |
24 #include "webrtc/test/gtest.h" | 23 #include "webrtc/test/gtest.h" |
25 #include "webrtc/test/mock_voe_channel_proxy.h" | 24 #include "webrtc/test/mock_voe_channel_proxy.h" |
26 #include "webrtc/test/mock_voice_engine.h" | 25 #include "webrtc/test/mock_voice_engine.h" |
27 | 26 |
28 namespace webrtc { | 27 namespace webrtc { |
29 namespace test { | 28 namespace test { |
30 namespace { | 29 namespace { |
31 | 30 |
32 using testing::_; | 31 using testing::_; |
33 using testing::Return; | 32 using testing::Return; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 EXPECT_CALL(*channel_proxy_, ResetCongestionControlObjects()) | 102 EXPECT_CALL(*channel_proxy_, ResetCongestionControlObjects()) |
104 .Times(1); | 103 .Times(1); |
105 EXPECT_CALL(*channel_proxy_, RegisterExternalTransport(nullptr)) | 104 EXPECT_CALL(*channel_proxy_, RegisterExternalTransport(nullptr)) |
106 .Times(1); | 105 .Times(1); |
107 EXPECT_CALL(*channel_proxy_, DeRegisterExternalTransport()) | 106 EXPECT_CALL(*channel_proxy_, DeRegisterExternalTransport()) |
108 .Times(1); | 107 .Times(1); |
109 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::NotNull())) | 108 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::NotNull())) |
110 .Times(1); | 109 .Times(1); |
111 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::IsNull())) | 110 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::IsNull())) |
112 .Times(1); // Destructor resets the event log | 111 .Times(1); // Destructor resets the event log |
113 EXPECT_CALL(*channel_proxy_, SetRtcpRttStats(&rtcp_rtt_stats_)) | |
114 .Times(1); | |
115 return channel_proxy_; | 112 return channel_proxy_; |
116 })); | 113 })); |
117 stream_config_.voe_channel_id = kChannelId; | 114 stream_config_.voe_channel_id = kChannelId; |
118 stream_config_.rtp.ssrc = kSsrc; | 115 stream_config_.rtp.ssrc = kSsrc; |
119 stream_config_.rtp.nack.rtp_history_ms = 200; | 116 stream_config_.rtp.nack.rtp_history_ms = 200; |
120 stream_config_.rtp.c_name = kCName; | 117 stream_config_.rtp.c_name = kCName; |
121 stream_config_.rtp.extensions.push_back( | 118 stream_config_.rtp.extensions.push_back( |
122 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId)); | 119 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId)); |
123 stream_config_.rtp.extensions.push_back( | 120 stream_config_.rtp.extensions.push_back( |
124 RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId)); | 121 RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId)); |
125 stream_config_.rtp.extensions.push_back(RtpExtension( | 122 stream_config_.rtp.extensions.push_back(RtpExtension( |
126 RtpExtension::kTransportSequenceNumberUri, kTransportSequenceNumberId)); | 123 RtpExtension::kTransportSequenceNumberUri, kTransportSequenceNumberId)); |
127 } | 124 } |
128 | 125 |
129 AudioSendStream::Config& config() { return stream_config_; } | 126 AudioSendStream::Config& config() { return stream_config_; } |
130 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } | 127 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } |
131 MockVoEChannelProxy* channel_proxy() { return channel_proxy_; } | 128 MockVoEChannelProxy* channel_proxy() { return channel_proxy_; } |
132 CongestionController* congestion_controller() { | 129 CongestionController* congestion_controller() { |
133 return &congestion_controller_; | 130 return &congestion_controller_; |
134 } | 131 } |
135 BitrateAllocator* bitrate_allocator() { return &bitrate_allocator_; } | 132 BitrateAllocator* bitrate_allocator() { return &bitrate_allocator_; } |
136 rtc::TaskQueue* worker_queue() { return &worker_queue_; } | 133 rtc::TaskQueue* worker_queue() { return &worker_queue_; } |
137 RtcEventLog* event_log() { return &event_log_; } | 134 RtcEventLog* event_log() { return &event_log_; } |
138 RtcpRttStats* rtcp_rtt_stats() { return &rtcp_rtt_stats_; } | |
139 | 135 |
140 void SetupMockForSendTelephoneEvent() { | 136 void SetupMockForSendTelephoneEvent() { |
141 EXPECT_TRUE(channel_proxy_); | 137 EXPECT_TRUE(channel_proxy_); |
142 EXPECT_CALL(*channel_proxy_, | 138 EXPECT_CALL(*channel_proxy_, |
143 SetSendTelephoneEventPayloadType(kTelephoneEventPayloadType)) | 139 SetSendTelephoneEventPayloadType(kTelephoneEventPayloadType)) |
144 .WillOnce(Return(true)); | 140 .WillOnce(Return(true)); |
145 EXPECT_CALL(*channel_proxy_, | 141 EXPECT_CALL(*channel_proxy_, |
146 SendTelephoneEventOutband(kTelephoneEventCode, kTelephoneEventDuration)) | 142 SendTelephoneEventOutband(kTelephoneEventCode, kTelephoneEventDuration)) |
147 .WillOnce(Return(true)); | 143 .WillOnce(Return(true)); |
148 } | 144 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 private: | 179 private: |
184 SimulatedClock simulated_clock_; | 180 SimulatedClock simulated_clock_; |
185 testing::StrictMock<MockVoiceEngine> voice_engine_; | 181 testing::StrictMock<MockVoiceEngine> voice_engine_; |
186 rtc::scoped_refptr<AudioState> audio_state_; | 182 rtc::scoped_refptr<AudioState> audio_state_; |
187 AudioSendStream::Config stream_config_; | 183 AudioSendStream::Config stream_config_; |
188 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr; | 184 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr; |
189 testing::NiceMock<MockCongestionObserver> bitrate_observer_; | 185 testing::NiceMock<MockCongestionObserver> bitrate_observer_; |
190 testing::NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; | 186 testing::NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; |
191 CongestionController congestion_controller_; | 187 CongestionController congestion_controller_; |
192 MockRtcEventLog event_log_; | 188 MockRtcEventLog event_log_; |
193 MockRtcpRttStats rtcp_rtt_stats_; | |
194 testing::NiceMock<MockLimitObserver> limit_observer_; | 189 testing::NiceMock<MockLimitObserver> limit_observer_; |
195 BitrateAllocator bitrate_allocator_; | 190 BitrateAllocator bitrate_allocator_; |
196 // |worker_queue| is defined last to ensure all pending tasks are cancelled | 191 // |worker_queue| is defined last to ensure all pending tasks are cancelled |
197 // and deleted before any other members. | 192 // and deleted before any other members. |
198 rtc::TaskQueue worker_queue_; | 193 rtc::TaskQueue worker_queue_; |
199 }; | 194 }; |
200 } // namespace | 195 } // namespace |
201 | 196 |
202 TEST(AudioSendStreamTest, ConfigToString) { | 197 TEST(AudioSendStreamTest, ConfigToString) { |
203 AudioSendStream::Config config(nullptr); | 198 AudioSendStream::Config config(nullptr); |
204 config.rtp.ssrc = kSsrc; | 199 config.rtp.ssrc = kSsrc; |
205 config.rtp.extensions.push_back( | 200 config.rtp.extensions.push_back( |
206 RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId)); | 201 RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId)); |
207 config.rtp.c_name = kCName; | 202 config.rtp.c_name = kCName; |
208 config.voe_channel_id = kChannelId; | 203 config.voe_channel_id = kChannelId; |
209 config.cng_payload_type = 42; | 204 config.cng_payload_type = 42; |
210 EXPECT_EQ( | 205 EXPECT_EQ( |
211 "{rtp: {ssrc: 1234, extensions: [{uri: " | 206 "{rtp: {ssrc: 1234, extensions: [{uri: " |
212 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}], " | 207 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}], " |
213 "nack: {rtp_history_ms: 0}, c_name: foo_name}, voe_channel_id: 1, " | 208 "nack: {rtp_history_ms: 0}, c_name: foo_name}, voe_channel_id: 1, " |
214 "cng_payload_type: 42}", | 209 "cng_payload_type: 42}", |
215 config.ToString()); | 210 config.ToString()); |
216 } | 211 } |
217 | 212 |
218 TEST(AudioSendStreamTest, ConstructDestruct) { | 213 TEST(AudioSendStreamTest, ConstructDestruct) { |
219 ConfigHelper helper; | 214 ConfigHelper helper; |
220 internal::AudioSendStream send_stream( | 215 internal::AudioSendStream send_stream( |
221 helper.config(), helper.audio_state(), helper.worker_queue(), | 216 helper.config(), helper.audio_state(), helper.worker_queue(), |
222 helper.congestion_controller(), helper.bitrate_allocator(), | 217 helper.congestion_controller(), helper.bitrate_allocator(), |
223 helper.event_log(), helper.rtcp_rtt_stats()); | 218 helper.event_log()); |
224 } | 219 } |
225 | 220 |
226 TEST(AudioSendStreamTest, SendTelephoneEvent) { | 221 TEST(AudioSendStreamTest, SendTelephoneEvent) { |
227 ConfigHelper helper; | 222 ConfigHelper helper; |
228 internal::AudioSendStream send_stream( | 223 internal::AudioSendStream send_stream( |
229 helper.config(), helper.audio_state(), helper.worker_queue(), | 224 helper.config(), helper.audio_state(), helper.worker_queue(), |
230 helper.congestion_controller(), helper.bitrate_allocator(), | 225 helper.congestion_controller(), helper.bitrate_allocator(), |
231 helper.event_log(), helper.rtcp_rtt_stats()); | 226 helper.event_log()); |
232 helper.SetupMockForSendTelephoneEvent(); | 227 helper.SetupMockForSendTelephoneEvent(); |
233 EXPECT_TRUE(send_stream.SendTelephoneEvent(kTelephoneEventPayloadType, | 228 EXPECT_TRUE(send_stream.SendTelephoneEvent(kTelephoneEventPayloadType, |
234 kTelephoneEventCode, kTelephoneEventDuration)); | 229 kTelephoneEventCode, kTelephoneEventDuration)); |
235 } | 230 } |
236 | 231 |
237 TEST(AudioSendStreamTest, SetMuted) { | 232 TEST(AudioSendStreamTest, SetMuted) { |
238 ConfigHelper helper; | 233 ConfigHelper helper; |
239 internal::AudioSendStream send_stream( | 234 internal::AudioSendStream send_stream( |
240 helper.config(), helper.audio_state(), helper.worker_queue(), | 235 helper.config(), helper.audio_state(), helper.worker_queue(), |
241 helper.congestion_controller(), helper.bitrate_allocator(), | 236 helper.congestion_controller(), helper.bitrate_allocator(), |
242 helper.event_log(), helper.rtcp_rtt_stats()); | 237 helper.event_log()); |
243 EXPECT_CALL(*helper.channel_proxy(), SetInputMute(true)); | 238 EXPECT_CALL(*helper.channel_proxy(), SetInputMute(true)); |
244 send_stream.SetMuted(true); | 239 send_stream.SetMuted(true); |
245 } | 240 } |
246 | 241 |
247 TEST(AudioSendStreamTest, GetStats) { | 242 TEST(AudioSendStreamTest, GetStats) { |
248 ConfigHelper helper; | 243 ConfigHelper helper; |
249 internal::AudioSendStream send_stream( | 244 internal::AudioSendStream send_stream( |
250 helper.config(), helper.audio_state(), helper.worker_queue(), | 245 helper.config(), helper.audio_state(), helper.worker_queue(), |
251 helper.congestion_controller(), helper.bitrate_allocator(), | 246 helper.congestion_controller(), helper.bitrate_allocator(), |
252 helper.event_log(), helper.rtcp_rtt_stats()); | 247 helper.event_log()); |
253 helper.SetupMockForGetStats(); | 248 helper.SetupMockForGetStats(); |
254 AudioSendStream::Stats stats = send_stream.GetStats(); | 249 AudioSendStream::Stats stats = send_stream.GetStats(); |
255 EXPECT_EQ(kSsrc, stats.local_ssrc); | 250 EXPECT_EQ(kSsrc, stats.local_ssrc); |
256 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesSent), stats.bytes_sent); | 251 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesSent), stats.bytes_sent); |
257 EXPECT_EQ(kCallStats.packetsSent, stats.packets_sent); | 252 EXPECT_EQ(kCallStats.packetsSent, stats.packets_sent); |
258 EXPECT_EQ(static_cast<int32_t>(kReportBlock.cumulative_num_packets_lost), | 253 EXPECT_EQ(static_cast<int32_t>(kReportBlock.cumulative_num_packets_lost), |
259 stats.packets_lost); | 254 stats.packets_lost); |
260 EXPECT_EQ(Q8ToFloat(kReportBlock.fraction_lost), stats.fraction_lost); | 255 EXPECT_EQ(Q8ToFloat(kReportBlock.fraction_lost), stats.fraction_lost); |
261 EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name); | 256 EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name); |
262 EXPECT_EQ(static_cast<int32_t>(kReportBlock.extended_highest_sequence_number), | 257 EXPECT_EQ(static_cast<int32_t>(kReportBlock.extended_highest_sequence_number), |
263 stats.ext_seqnum); | 258 stats.ext_seqnum); |
264 EXPECT_EQ(static_cast<int32_t>(kReportBlock.interarrival_jitter / | 259 EXPECT_EQ(static_cast<int32_t>(kReportBlock.interarrival_jitter / |
265 (kCodecInst.plfreq / 1000)), | 260 (kCodecInst.plfreq / 1000)), |
266 stats.jitter_ms); | 261 stats.jitter_ms); |
267 EXPECT_EQ(kCallStats.rttMs, stats.rtt_ms); | 262 EXPECT_EQ(kCallStats.rttMs, stats.rtt_ms); |
268 EXPECT_EQ(static_cast<int32_t>(kSpeechInputLevel), stats.audio_level); | 263 EXPECT_EQ(static_cast<int32_t>(kSpeechInputLevel), stats.audio_level); |
269 EXPECT_EQ(-1, stats.aec_quality_min); | 264 EXPECT_EQ(-1, stats.aec_quality_min); |
270 EXPECT_EQ(kEchoDelayMedian, stats.echo_delay_median_ms); | 265 EXPECT_EQ(kEchoDelayMedian, stats.echo_delay_median_ms); |
271 EXPECT_EQ(kEchoDelayStdDev, stats.echo_delay_std_ms); | 266 EXPECT_EQ(kEchoDelayStdDev, stats.echo_delay_std_ms); |
272 EXPECT_EQ(kEchoReturnLoss, stats.echo_return_loss); | 267 EXPECT_EQ(kEchoReturnLoss, stats.echo_return_loss); |
273 EXPECT_EQ(kEchoReturnLossEnhancement, stats.echo_return_loss_enhancement); | 268 EXPECT_EQ(kEchoReturnLossEnhancement, stats.echo_return_loss_enhancement); |
274 EXPECT_FALSE(stats.typing_noise_detected); | 269 EXPECT_FALSE(stats.typing_noise_detected); |
275 } | 270 } |
276 | 271 |
277 TEST(AudioSendStreamTest, GetStatsTypingNoiseDetected) { | 272 TEST(AudioSendStreamTest, GetStatsTypingNoiseDetected) { |
278 ConfigHelper helper; | 273 ConfigHelper helper; |
279 internal::AudioSendStream send_stream( | 274 internal::AudioSendStream send_stream( |
280 helper.config(), helper.audio_state(), helper.worker_queue(), | 275 helper.config(), helper.audio_state(), helper.worker_queue(), |
281 helper.congestion_controller(), helper.bitrate_allocator(), | 276 helper.congestion_controller(), helper.bitrate_allocator(), |
282 helper.event_log(), helper.rtcp_rtt_stats()); | 277 helper.event_log()); |
283 helper.SetupMockForGetStats(); | 278 helper.SetupMockForGetStats(); |
284 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); | 279 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); |
285 | 280 |
286 internal::AudioState* internal_audio_state = | 281 internal::AudioState* internal_audio_state = |
287 static_cast<internal::AudioState*>(helper.audio_state().get()); | 282 static_cast<internal::AudioState*>(helper.audio_state().get()); |
288 VoiceEngineObserver* voe_observer = | 283 VoiceEngineObserver* voe_observer = |
289 static_cast<VoiceEngineObserver*>(internal_audio_state); | 284 static_cast<VoiceEngineObserver*>(internal_audio_state); |
290 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING); | 285 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING); |
291 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected); | 286 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected); |
292 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING); | 287 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING); |
293 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); | 288 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); |
294 } | 289 } |
295 } // namespace test | 290 } // namespace test |
296 } // namespace webrtc | 291 } // namespace webrtc |
OLD | NEW |