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/api/test/mock_audio_mixer.h" |
14 #include "webrtc/audio/audio_receive_stream.h" | 15 #include "webrtc/audio/audio_receive_stream.h" |
15 #include "webrtc/audio/conversion.h" | 16 #include "webrtc/audio/conversion.h" |
16 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" | 17 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" |
17 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h" | 18 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h" |
18 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" | |
19 #include "webrtc/modules/bitrate_controller/include/mock/mock_bitrate_controller
.h" | 19 #include "webrtc/modules/bitrate_controller/include/mock/mock_bitrate_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/packet_router.h" | 21 #include "webrtc/modules/pacing/packet_router.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/source/byte_io.h" | 23 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
24 #include "webrtc/system_wrappers/include/clock.h" | 24 #include "webrtc/system_wrappers/include/clock.h" |
25 #include "webrtc/test/gtest.h" | 25 #include "webrtc/test/gtest.h" |
26 #include "webrtc/test/mock_voe_channel_proxy.h" | 26 #include "webrtc/test/mock_voe_channel_proxy.h" |
27 #include "webrtc/test/mock_voice_engine.h" | 27 #include "webrtc/test/mock_voice_engine.h" |
28 | 28 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 123, 456, false, 0, 0, 789, 12, 345, 678, 901, -1, -1, -1, -1, -1, 0}; | 65 123, 456, false, 0, 0, 789, 12, 345, 678, 901, -1, -1, -1, -1, -1, 0}; |
66 const AudioDecodingCallStats kAudioDecodeStats = MakeAudioDecodeStatsForTest(); | 66 const AudioDecodingCallStats kAudioDecodeStats = MakeAudioDecodeStatsForTest(); |
67 | 67 |
68 struct ConfigHelper { | 68 struct ConfigHelper { |
69 ConfigHelper() | 69 ConfigHelper() |
70 : simulated_clock_(123456), | 70 : simulated_clock_(123456), |
71 decoder_factory_(new rtc::RefCountedObject<MockAudioDecoderFactory>), | 71 decoder_factory_(new rtc::RefCountedObject<MockAudioDecoderFactory>), |
72 congestion_controller_(&simulated_clock_, | 72 congestion_controller_(&simulated_clock_, |
73 &bitrate_observer_, | 73 &bitrate_observer_, |
74 &remote_bitrate_observer_, | 74 &remote_bitrate_observer_, |
75 &event_log_) { | 75 &event_log_), |
| 76 audio_mixer_(new rtc::RefCountedObject<MockAudioMixer>()) { |
76 using testing::Invoke; | 77 using testing::Invoke; |
77 | 78 |
78 EXPECT_CALL(voice_engine_, | 79 EXPECT_CALL(voice_engine_, |
79 RegisterVoiceEngineObserver(_)).WillOnce(Return(0)); | 80 RegisterVoiceEngineObserver(_)).WillOnce(Return(0)); |
80 EXPECT_CALL(voice_engine_, | 81 EXPECT_CALL(voice_engine_, |
81 DeRegisterVoiceEngineObserver()).WillOnce(Return(0)); | 82 DeRegisterVoiceEngineObserver()).WillOnce(Return(0)); |
82 EXPECT_CALL(voice_engine_, audio_processing()); | 83 EXPECT_CALL(voice_engine_, audio_processing()); |
83 EXPECT_CALL(voice_engine_, audio_device_module()); | 84 EXPECT_CALL(voice_engine_, audio_device_module()); |
84 EXPECT_CALL(voice_engine_, audio_transport()); | 85 EXPECT_CALL(voice_engine_, audio_transport()); |
85 | 86 |
86 AudioState::Config config; | 87 AudioState::Config config; |
87 config.voice_engine = &voice_engine_; | 88 config.voice_engine = &voice_engine_; |
88 config.audio_mixer = AudioMixerImpl::Create(); | 89 config.audio_mixer = audio_mixer_; |
89 audio_state_ = AudioState::Create(config); | 90 audio_state_ = AudioState::Create(config); |
90 | 91 |
91 EXPECT_CALL(voice_engine_, ChannelProxyFactory(kChannelId)) | 92 EXPECT_CALL(voice_engine_, ChannelProxyFactory(kChannelId)) |
92 .WillOnce(Invoke([this](int channel_id) { | 93 .WillOnce(Invoke([this](int channel_id) { |
93 EXPECT_FALSE(channel_proxy_); | 94 EXPECT_FALSE(channel_proxy_); |
94 channel_proxy_ = new testing::StrictMock<MockVoEChannelProxy>(); | 95 channel_proxy_ = new testing::StrictMock<MockVoEChannelProxy>(); |
95 EXPECT_CALL(*channel_proxy_, SetLocalSSRC(kLocalSsrc)).Times(1); | 96 EXPECT_CALL(*channel_proxy_, SetLocalSSRC(kLocalSsrc)).Times(1); |
96 EXPECT_CALL(*channel_proxy_, SetNACKStatus(true, 15)).Times(1); | 97 EXPECT_CALL(*channel_proxy_, SetNACKStatus(true, 15)).Times(1); |
97 EXPECT_CALL(*channel_proxy_, | 98 EXPECT_CALL(*channel_proxy_, |
98 SetReceiveAudioLevelIndicationStatus(true, kAudioLevelId)) | 99 SetReceiveAudioLevelIndicationStatus(true, kAudioLevelId)) |
(...skipping 16 matching lines...) Expand all Loading... |
115 .WillOnce(ReturnRef(decoder_factory_)); | 116 .WillOnce(ReturnRef(decoder_factory_)); |
116 testing::Expectation expect_set = | 117 testing::Expectation expect_set = |
117 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(&event_log_)) | 118 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(&event_log_)) |
118 .Times(1); | 119 .Times(1); |
119 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::IsNull())) | 120 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::IsNull())) |
120 .Times(1) | 121 .Times(1) |
121 .After(expect_set); | 122 .After(expect_set); |
122 EXPECT_CALL(*channel_proxy_, DisassociateSendChannel()).Times(1); | 123 EXPECT_CALL(*channel_proxy_, DisassociateSendChannel()).Times(1); |
123 return channel_proxy_; | 124 return channel_proxy_; |
124 })); | 125 })); |
125 EXPECT_CALL(voice_engine_, StopPlayout(kChannelId)).WillOnce(Return(0)); | |
126 stream_config_.voe_channel_id = kChannelId; | 126 stream_config_.voe_channel_id = kChannelId; |
127 stream_config_.rtp.local_ssrc = kLocalSsrc; | 127 stream_config_.rtp.local_ssrc = kLocalSsrc; |
128 stream_config_.rtp.remote_ssrc = kRemoteSsrc; | 128 stream_config_.rtp.remote_ssrc = kRemoteSsrc; |
129 stream_config_.rtp.nack.rtp_history_ms = 300; | 129 stream_config_.rtp.nack.rtp_history_ms = 300; |
130 stream_config_.rtp.extensions.push_back( | 130 stream_config_.rtp.extensions.push_back( |
131 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId)); | 131 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId)); |
132 stream_config_.rtp.extensions.push_back(RtpExtension( | 132 stream_config_.rtp.extensions.push_back(RtpExtension( |
133 RtpExtension::kTransportSequenceNumberUri, kTransportSequenceNumberId)); | 133 RtpExtension::kTransportSequenceNumberUri, kTransportSequenceNumberId)); |
134 stream_config_.decoder_factory = decoder_factory_; | 134 stream_config_.decoder_factory = decoder_factory_; |
135 } | 135 } |
136 | 136 |
137 MockCongestionController* congestion_controller() { | 137 MockCongestionController* congestion_controller() { |
138 return &congestion_controller_; | 138 return &congestion_controller_; |
139 } | 139 } |
140 MockRemoteBitrateEstimator* remote_bitrate_estimator() { | 140 MockRemoteBitrateEstimator* remote_bitrate_estimator() { |
141 return &remote_bitrate_estimator_; | 141 return &remote_bitrate_estimator_; |
142 } | 142 } |
143 MockRtcEventLog* event_log() { return &event_log_; } | 143 MockRtcEventLog* event_log() { return &event_log_; } |
144 AudioReceiveStream::Config& config() { return stream_config_; } | 144 AudioReceiveStream::Config& config() { return stream_config_; } |
145 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } | 145 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } |
| 146 rtc::scoped_refptr<MockAudioMixer> audio_mixer() { return audio_mixer_; } |
146 MockVoiceEngine& voice_engine() { return voice_engine_; } | 147 MockVoiceEngine& voice_engine() { return voice_engine_; } |
147 MockVoEChannelProxy* channel_proxy() { return channel_proxy_; } | 148 MockVoEChannelProxy* channel_proxy() { return channel_proxy_; } |
148 | 149 |
149 void SetupMockForBweFeedback(bool send_side_bwe) { | 150 void SetupMockForBweFeedback(bool send_side_bwe) { |
150 EXPECT_CALL(congestion_controller_, | 151 EXPECT_CALL(congestion_controller_, |
151 GetRemoteBitrateEstimator(send_side_bwe)) | 152 GetRemoteBitrateEstimator(send_side_bwe)) |
152 .WillOnce(Return(&remote_bitrate_estimator_)); | 153 .WillOnce(Return(&remote_bitrate_estimator_)); |
153 EXPECT_CALL(remote_bitrate_estimator_, | 154 EXPECT_CALL(remote_bitrate_estimator_, |
154 RemoveStream(stream_config_.rtp.remote_ssrc)); | 155 RemoveStream(stream_config_.rtp.remote_ssrc)); |
155 } | 156 } |
(...skipping 22 matching lines...) Expand all Loading... |
178 SimulatedClock simulated_clock_; | 179 SimulatedClock simulated_clock_; |
179 PacketRouter packet_router_; | 180 PacketRouter packet_router_; |
180 testing::NiceMock<MockCongestionObserver> bitrate_observer_; | 181 testing::NiceMock<MockCongestionObserver> bitrate_observer_; |
181 testing::NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; | 182 testing::NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; |
182 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; | 183 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; |
183 MockCongestionController congestion_controller_; | 184 MockCongestionController congestion_controller_; |
184 MockRemoteBitrateEstimator remote_bitrate_estimator_; | 185 MockRemoteBitrateEstimator remote_bitrate_estimator_; |
185 MockRtcEventLog event_log_; | 186 MockRtcEventLog event_log_; |
186 testing::StrictMock<MockVoiceEngine> voice_engine_; | 187 testing::StrictMock<MockVoiceEngine> voice_engine_; |
187 rtc::scoped_refptr<AudioState> audio_state_; | 188 rtc::scoped_refptr<AudioState> audio_state_; |
| 189 rtc::scoped_refptr<MockAudioMixer> audio_mixer_; |
188 AudioReceiveStream::Config stream_config_; | 190 AudioReceiveStream::Config stream_config_; |
189 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr; | 191 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr; |
190 }; | 192 }; |
191 | 193 |
192 void BuildOneByteExtension(std::vector<uint8_t>::iterator it, | 194 void BuildOneByteExtension(std::vector<uint8_t>::iterator it, |
193 int id, | 195 int id, |
194 uint32_t extension_value, | 196 uint32_t extension_value, |
195 size_t value_length) { | 197 size_t value_length) { |
196 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE; | 198 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE; |
197 ByteWriter<uint16_t>::WriteBigEndian(&(*it), kRtpOneByteHeaderExtensionId); | 199 ByteWriter<uint16_t>::WriteBigEndian(&(*it), kRtpOneByteHeaderExtensionId); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 363 |
362 TEST(AudioReceiveStreamTest, SetGain) { | 364 TEST(AudioReceiveStreamTest, SetGain) { |
363 ConfigHelper helper; | 365 ConfigHelper helper; |
364 internal::AudioReceiveStream recv_stream( | 366 internal::AudioReceiveStream recv_stream( |
365 helper.congestion_controller(), helper.config(), helper.audio_state(), | 367 helper.congestion_controller(), helper.config(), helper.audio_state(), |
366 helper.event_log()); | 368 helper.event_log()); |
367 EXPECT_CALL(*helper.channel_proxy(), | 369 EXPECT_CALL(*helper.channel_proxy(), |
368 SetChannelOutputVolumeScaling(FloatEq(0.765f))); | 370 SetChannelOutputVolumeScaling(FloatEq(0.765f))); |
369 recv_stream.SetGain(0.765f); | 371 recv_stream.SetGain(0.765f); |
370 } | 372 } |
| 373 |
| 374 TEST(AudioReceiveStreamTest, StreamShouldNotBeAddedToMixerWhenVoEReturnsError) { |
| 375 ConfigHelper helper; |
| 376 internal::AudioReceiveStream recv_stream( |
| 377 helper.congestion_controller(), helper.config(), helper.audio_state(), |
| 378 helper.event_log()); |
| 379 |
| 380 EXPECT_CALL(helper.voice_engine(), StartPlayout(_)).WillOnce(Return(-1)); |
| 381 EXPECT_CALL(*helper.audio_mixer(), AddSource(_)).Times(0); |
| 382 |
| 383 recv_stream.Start(); |
| 384 } |
| 385 |
| 386 TEST(AudioReceiveStreamTest, StreamShouldBeAddedToMixerOnStart) { |
| 387 ConfigHelper helper; |
| 388 internal::AudioReceiveStream recv_stream( |
| 389 helper.congestion_controller(), helper.config(), helper.audio_state(), |
| 390 helper.event_log()); |
| 391 |
| 392 EXPECT_CALL(helper.voice_engine(), StartPlayout(_)).WillOnce(Return(0)); |
| 393 EXPECT_CALL(helper.voice_engine(), StopPlayout(_)); |
| 394 EXPECT_CALL(*helper.audio_mixer(), AddSource(&recv_stream)) |
| 395 .WillOnce(Return(true)); |
| 396 |
| 397 recv_stream.Start(); |
| 398 } |
371 } // namespace test | 399 } // namespace test |
372 } // namespace webrtc | 400 } // namespace webrtc |
OLD | NEW |