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