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 "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 #include "webrtc/audio/audio_send_stream.h" | 16 #include "webrtc/audio/audio_send_stream.h" |
17 #include "webrtc/audio/audio_state.h" | 17 #include "webrtc/audio/audio_state.h" |
18 #include "webrtc/audio/conversion.h" | 18 #include "webrtc/audio/conversion.h" |
| 19 #include "webrtc/base/task_queue.h" |
19 #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" |
20 #include "webrtc/call/mock/mock_rtc_event_log.h" | 21 #include "webrtc/call/mock/mock_rtc_event_log.h" |
21 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 22 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
22 #include "webrtc/modules/pacing/paced_sender.h" | 23 #include "webrtc/modules/pacing/paced_sender.h" |
23 #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" |
24 #include "webrtc/test/mock_voe_channel_proxy.h" | 25 #include "webrtc/test/mock_voe_channel_proxy.h" |
25 #include "webrtc/test/mock_voice_engine.h" | 26 #include "webrtc/test/mock_voice_engine.h" |
26 | 27 |
27 namespace webrtc { | 28 namespace webrtc { |
28 namespace test { | 29 namespace test { |
(...skipping 29 matching lines...) Expand all Loading... |
58 }; | 59 }; |
59 | 60 |
60 struct ConfigHelper { | 61 struct ConfigHelper { |
61 ConfigHelper() | 62 ConfigHelper() |
62 : simulated_clock_(123456), | 63 : simulated_clock_(123456), |
63 stream_config_(nullptr), | 64 stream_config_(nullptr), |
64 congestion_controller_(&simulated_clock_, | 65 congestion_controller_(&simulated_clock_, |
65 &bitrate_observer_, | 66 &bitrate_observer_, |
66 &remote_bitrate_observer_, | 67 &remote_bitrate_observer_, |
67 &event_log_), | 68 &event_log_), |
68 bitrate_allocator_(&limit_observer_) { | 69 bitrate_allocator_(&limit_observer_), |
| 70 worker_queue_("ConfigHelper_worker_queue") { |
69 using testing::Invoke; | 71 using testing::Invoke; |
70 using testing::StrEq; | 72 using testing::StrEq; |
71 | 73 |
72 EXPECT_CALL(voice_engine_, | 74 EXPECT_CALL(voice_engine_, |
73 RegisterVoiceEngineObserver(_)).WillOnce(Return(0)); | 75 RegisterVoiceEngineObserver(_)).WillOnce(Return(0)); |
74 EXPECT_CALL(voice_engine_, | 76 EXPECT_CALL(voice_engine_, |
75 DeRegisterVoiceEngineObserver()).WillOnce(Return(0)); | 77 DeRegisterVoiceEngineObserver()).WillOnce(Return(0)); |
76 AudioState::Config config; | 78 AudioState::Config config; |
77 config.voice_engine = &voice_engine_; | 79 config.voice_engine = &voice_engine_; |
78 audio_state_ = AudioState::Create(config); | 80 audio_state_ = AudioState::Create(config); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 RtpExtension::kTransportSequenceNumberUri, kTransportSequenceNumberId)); | 120 RtpExtension::kTransportSequenceNumberUri, kTransportSequenceNumberId)); |
119 } | 121 } |
120 | 122 |
121 AudioSendStream::Config& config() { return stream_config_; } | 123 AudioSendStream::Config& config() { return stream_config_; } |
122 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } | 124 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } |
123 MockVoEChannelProxy* channel_proxy() { return channel_proxy_; } | 125 MockVoEChannelProxy* channel_proxy() { return channel_proxy_; } |
124 CongestionController* congestion_controller() { | 126 CongestionController* congestion_controller() { |
125 return &congestion_controller_; | 127 return &congestion_controller_; |
126 } | 128 } |
127 BitrateAllocator* bitrate_allocator() { return &bitrate_allocator_; } | 129 BitrateAllocator* bitrate_allocator() { return &bitrate_allocator_; } |
| 130 rtc::TaskQueue* worker_queue() { return &worker_queue_; } |
128 | 131 |
129 void SetupMockForSendTelephoneEvent() { | 132 void SetupMockForSendTelephoneEvent() { |
130 EXPECT_TRUE(channel_proxy_); | 133 EXPECT_TRUE(channel_proxy_); |
131 EXPECT_CALL(*channel_proxy_, | 134 EXPECT_CALL(*channel_proxy_, |
132 SetSendTelephoneEventPayloadType(kTelephoneEventPayloadType)) | 135 SetSendTelephoneEventPayloadType(kTelephoneEventPayloadType)) |
133 .WillOnce(Return(true)); | 136 .WillOnce(Return(true)); |
134 EXPECT_CALL(*channel_proxy_, | 137 EXPECT_CALL(*channel_proxy_, |
135 SendTelephoneEventOutband(kTelephoneEventCode, kTelephoneEventDuration)) | 138 SendTelephoneEventOutband(kTelephoneEventCode, kTelephoneEventDuration)) |
136 .WillOnce(Return(true)); | 139 .WillOnce(Return(true)); |
137 } | 140 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 testing::StrictMock<MockVoiceEngine> voice_engine_; | 177 testing::StrictMock<MockVoiceEngine> voice_engine_; |
175 rtc::scoped_refptr<AudioState> audio_state_; | 178 rtc::scoped_refptr<AudioState> audio_state_; |
176 AudioSendStream::Config stream_config_; | 179 AudioSendStream::Config stream_config_; |
177 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr; | 180 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr; |
178 testing::NiceMock<MockCongestionObserver> bitrate_observer_; | 181 testing::NiceMock<MockCongestionObserver> bitrate_observer_; |
179 testing::NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; | 182 testing::NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; |
180 CongestionController congestion_controller_; | 183 CongestionController congestion_controller_; |
181 MockRtcEventLog event_log_; | 184 MockRtcEventLog event_log_; |
182 testing::NiceMock<MockLimitObserver> limit_observer_; | 185 testing::NiceMock<MockLimitObserver> limit_observer_; |
183 BitrateAllocator bitrate_allocator_; | 186 BitrateAllocator bitrate_allocator_; |
| 187 // |worker_queue| is defined last to ensure all pending tasks are cancelled |
| 188 // and deleted before any other members. |
| 189 rtc::TaskQueue worker_queue_; |
184 }; | 190 }; |
185 } // namespace | 191 } // namespace |
186 | 192 |
187 TEST(AudioSendStreamTest, ConfigToString) { | 193 TEST(AudioSendStreamTest, ConfigToString) { |
188 AudioSendStream::Config config(nullptr); | 194 AudioSendStream::Config config(nullptr); |
189 config.rtp.ssrc = kSsrc; | 195 config.rtp.ssrc = kSsrc; |
190 config.rtp.extensions.push_back( | 196 config.rtp.extensions.push_back( |
191 RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId)); | 197 RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId)); |
192 config.rtp.c_name = kCName; | 198 config.rtp.c_name = kCName; |
193 config.voe_channel_id = kChannelId; | 199 config.voe_channel_id = kChannelId; |
194 config.cng_payload_type = 42; | 200 config.cng_payload_type = 42; |
195 EXPECT_EQ( | 201 EXPECT_EQ( |
196 "{rtp: {ssrc: 1234, extensions: [{uri: " | 202 "{rtp: {ssrc: 1234, extensions: [{uri: " |
197 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}], " | 203 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}], " |
198 "nack: {rtp_history_ms: 0}, c_name: foo_name}, voe_channel_id: 1, " | 204 "nack: {rtp_history_ms: 0}, c_name: foo_name}, voe_channel_id: 1, " |
199 "cng_payload_type: 42}", | 205 "cng_payload_type: 42}", |
200 config.ToString()); | 206 config.ToString()); |
201 } | 207 } |
202 | 208 |
203 TEST(AudioSendStreamTest, ConstructDestruct) { | 209 TEST(AudioSendStreamTest, ConstructDestruct) { |
204 ConfigHelper helper; | 210 ConfigHelper helper; |
205 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(), | 211 internal::AudioSendStream send_stream( |
206 helper.congestion_controller(), | 212 helper.config(), helper.audio_state(), helper.worker_queue(), |
207 helper.bitrate_allocator()); | 213 helper.congestion_controller(), helper.bitrate_allocator()); |
208 } | 214 } |
209 | 215 |
210 TEST(AudioSendStreamTest, SendTelephoneEvent) { | 216 TEST(AudioSendStreamTest, SendTelephoneEvent) { |
211 ConfigHelper helper; | 217 ConfigHelper helper; |
212 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(), | 218 internal::AudioSendStream send_stream( |
213 helper.congestion_controller(), | 219 helper.config(), helper.audio_state(), helper.worker_queue(), |
214 helper.bitrate_allocator()); | 220 helper.congestion_controller(), helper.bitrate_allocator()); |
215 helper.SetupMockForSendTelephoneEvent(); | 221 helper.SetupMockForSendTelephoneEvent(); |
216 EXPECT_TRUE(send_stream.SendTelephoneEvent(kTelephoneEventPayloadType, | 222 EXPECT_TRUE(send_stream.SendTelephoneEvent(kTelephoneEventPayloadType, |
217 kTelephoneEventCode, kTelephoneEventDuration)); | 223 kTelephoneEventCode, kTelephoneEventDuration)); |
218 } | 224 } |
219 | 225 |
220 TEST(AudioSendStreamTest, SetMuted) { | 226 TEST(AudioSendStreamTest, SetMuted) { |
221 ConfigHelper helper; | 227 ConfigHelper helper; |
222 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(), | 228 internal::AudioSendStream send_stream( |
223 helper.congestion_controller(), | 229 helper.config(), helper.audio_state(), helper.worker_queue(), |
224 helper.bitrate_allocator()); | 230 helper.congestion_controller(), helper.bitrate_allocator()); |
225 EXPECT_CALL(*helper.channel_proxy(), SetInputMute(true)); | 231 EXPECT_CALL(*helper.channel_proxy(), SetInputMute(true)); |
226 send_stream.SetMuted(true); | 232 send_stream.SetMuted(true); |
227 } | 233 } |
228 | 234 |
229 TEST(AudioSendStreamTest, GetStats) { | 235 TEST(AudioSendStreamTest, GetStats) { |
230 ConfigHelper helper; | 236 ConfigHelper helper; |
231 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(), | 237 internal::AudioSendStream send_stream( |
232 helper.congestion_controller(), | 238 helper.config(), helper.audio_state(), helper.worker_queue(), |
233 helper.bitrate_allocator()); | 239 helper.congestion_controller(), helper.bitrate_allocator()); |
234 helper.SetupMockForGetStats(); | 240 helper.SetupMockForGetStats(); |
235 AudioSendStream::Stats stats = send_stream.GetStats(); | 241 AudioSendStream::Stats stats = send_stream.GetStats(); |
236 EXPECT_EQ(kSsrc, stats.local_ssrc); | 242 EXPECT_EQ(kSsrc, stats.local_ssrc); |
237 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesSent), stats.bytes_sent); | 243 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesSent), stats.bytes_sent); |
238 EXPECT_EQ(kCallStats.packetsSent, stats.packets_sent); | 244 EXPECT_EQ(kCallStats.packetsSent, stats.packets_sent); |
239 EXPECT_EQ(static_cast<int32_t>(kReportBlock.cumulative_num_packets_lost), | 245 EXPECT_EQ(static_cast<int32_t>(kReportBlock.cumulative_num_packets_lost), |
240 stats.packets_lost); | 246 stats.packets_lost); |
241 EXPECT_EQ(Q8ToFloat(kReportBlock.fraction_lost), stats.fraction_lost); | 247 EXPECT_EQ(Q8ToFloat(kReportBlock.fraction_lost), stats.fraction_lost); |
242 EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name); | 248 EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name); |
243 EXPECT_EQ(static_cast<int32_t>(kReportBlock.extended_highest_sequence_number), | 249 EXPECT_EQ(static_cast<int32_t>(kReportBlock.extended_highest_sequence_number), |
244 stats.ext_seqnum); | 250 stats.ext_seqnum); |
245 EXPECT_EQ(static_cast<int32_t>(kReportBlock.interarrival_jitter / | 251 EXPECT_EQ(static_cast<int32_t>(kReportBlock.interarrival_jitter / |
246 (kCodecInst.plfreq / 1000)), | 252 (kCodecInst.plfreq / 1000)), |
247 stats.jitter_ms); | 253 stats.jitter_ms); |
248 EXPECT_EQ(kCallStats.rttMs, stats.rtt_ms); | 254 EXPECT_EQ(kCallStats.rttMs, stats.rtt_ms); |
249 EXPECT_EQ(static_cast<int32_t>(kSpeechInputLevel), stats.audio_level); | 255 EXPECT_EQ(static_cast<int32_t>(kSpeechInputLevel), stats.audio_level); |
250 EXPECT_EQ(-1, stats.aec_quality_min); | 256 EXPECT_EQ(-1, stats.aec_quality_min); |
251 EXPECT_EQ(kEchoDelayMedian, stats.echo_delay_median_ms); | 257 EXPECT_EQ(kEchoDelayMedian, stats.echo_delay_median_ms); |
252 EXPECT_EQ(kEchoDelayStdDev, stats.echo_delay_std_ms); | 258 EXPECT_EQ(kEchoDelayStdDev, stats.echo_delay_std_ms); |
253 EXPECT_EQ(kEchoReturnLoss, stats.echo_return_loss); | 259 EXPECT_EQ(kEchoReturnLoss, stats.echo_return_loss); |
254 EXPECT_EQ(kEchoReturnLossEnhancement, stats.echo_return_loss_enhancement); | 260 EXPECT_EQ(kEchoReturnLossEnhancement, stats.echo_return_loss_enhancement); |
255 EXPECT_FALSE(stats.typing_noise_detected); | 261 EXPECT_FALSE(stats.typing_noise_detected); |
256 } | 262 } |
257 | 263 |
258 TEST(AudioSendStreamTest, GetStatsTypingNoiseDetected) { | 264 TEST(AudioSendStreamTest, GetStatsTypingNoiseDetected) { |
259 ConfigHelper helper; | 265 ConfigHelper helper; |
260 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(), | 266 internal::AudioSendStream send_stream( |
261 helper.congestion_controller(), | 267 helper.config(), helper.audio_state(), helper.worker_queue(), |
262 helper.bitrate_allocator()); | 268 helper.congestion_controller(), helper.bitrate_allocator()); |
263 helper.SetupMockForGetStats(); | 269 helper.SetupMockForGetStats(); |
264 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); | 270 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); |
265 | 271 |
266 internal::AudioState* internal_audio_state = | 272 internal::AudioState* internal_audio_state = |
267 static_cast<internal::AudioState*>(helper.audio_state().get()); | 273 static_cast<internal::AudioState*>(helper.audio_state().get()); |
268 VoiceEngineObserver* voe_observer = | 274 VoiceEngineObserver* voe_observer = |
269 static_cast<VoiceEngineObserver*>(internal_audio_state); | 275 static_cast<VoiceEngineObserver*>(internal_audio_state); |
270 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING); | 276 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING); |
271 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected); | 277 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected); |
272 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING); | 278 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING); |
273 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); | 279 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); |
274 } | 280 } |
275 } // namespace test | 281 } // namespace test |
276 } // namespace webrtc | 282 } // namespace webrtc |
OLD | NEW |