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