| 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 <list> | 11 #include <list> |
| 12 #include <map> | 12 #include <map> |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <utility> | 14 #include <utility> |
| 15 | 15 |
| 16 #include "webrtc/api/test/mock_audio_mixer.h" |
| 16 #include "webrtc/base/ptr_util.h" | 17 #include "webrtc/base/ptr_util.h" |
| 17 #include "webrtc/call/audio_state.h" | 18 #include "webrtc/call/audio_state.h" |
| 18 #include "webrtc/call/call.h" | 19 #include "webrtc/call/call.h" |
| 19 #include "webrtc/call/fake_rtp_transport_controller_send.h" | 20 #include "webrtc/call/fake_rtp_transport_controller_send.h" |
| 20 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 21 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
| 22 #include "webrtc/modules/audio_device/include/mock_audio_device.h" |
| 21 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" | 23 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" |
| 22 #include "webrtc/modules/congestion_controller/include/mock/mock_send_side_conge
stion_controller.h" | 24 #include "webrtc/modules/congestion_controller/include/mock/mock_send_side_conge
stion_controller.h" |
| 25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| 23 #include "webrtc/test/gtest.h" | 26 #include "webrtc/test/gtest.h" |
| 24 #include "webrtc/test/mock_audio_decoder_factory.h" | 27 #include "webrtc/test/mock_audio_decoder_factory.h" |
| 25 #include "webrtc/test/mock_transport.h" | 28 #include "webrtc/test/mock_transport.h" |
| 26 #include "webrtc/test/mock_voice_engine.h" | 29 #include "webrtc/test/mock_voice_engine.h" |
| 27 | 30 |
| 28 namespace { | 31 namespace { |
| 29 | 32 |
| 30 struct CallHelper { | 33 struct CallHelper { |
| 31 explicit CallHelper( | 34 explicit CallHelper( |
| 32 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory = nullptr) | 35 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory = nullptr) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 call->DestroyAudioReceiveStream(s); | 130 call->DestroyAudioReceiveStream(s); |
| 128 } | 131 } |
| 129 streams.clear(); | 132 streams.clear(); |
| 130 } | 133 } |
| 131 } | 134 } |
| 132 | 135 |
| 133 TEST(CallTest, CreateDestroy_AssociateAudioSendReceiveStreams_RecvFirst) { | 136 TEST(CallTest, CreateDestroy_AssociateAudioSendReceiveStreams_RecvFirst) { |
| 134 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory( | 137 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory( |
| 135 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>); | 138 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>); |
| 136 CallHelper call(decoder_factory); | 139 CallHelper call(decoder_factory); |
| 140 ::testing::NiceMock<MockRtpRtcp> mock_rtp_rtcp; |
| 137 | 141 |
| 138 constexpr int kRecvChannelId = 101; | 142 constexpr int kRecvChannelId = 101; |
| 139 | 143 |
| 140 // Set up the mock to create a channel proxy which we know of, so that we can | 144 // Set up the mock to create a channel proxy which we know of, so that we can |
| 141 // add our expectations to it. | 145 // add our expectations to it. |
| 142 test::MockVoEChannelProxy* recv_channel_proxy = nullptr; | 146 test::MockVoEChannelProxy* recv_channel_proxy = nullptr; |
| 143 EXPECT_CALL(*call.voice_engine(), ChannelProxyFactory(testing::_)) | 147 EXPECT_CALL(*call.voice_engine(), ChannelProxyFactory(testing::_)) |
| 144 .WillRepeatedly(testing::Invoke([&](int channel_id) { | 148 .WillRepeatedly(testing::Invoke([&](int channel_id) { |
| 145 test::MockVoEChannelProxy* channel_proxy = | 149 test::MockVoEChannelProxy* channel_proxy = |
| 146 new testing::NiceMock<test::MockVoEChannelProxy>(); | 150 new testing::NiceMock<test::MockVoEChannelProxy>(); |
| 147 EXPECT_CALL(*channel_proxy, GetAudioDecoderFactory()) | 151 EXPECT_CALL(*channel_proxy, GetAudioDecoderFactory()) |
| 148 .WillRepeatedly(testing::ReturnRef(decoder_factory)); | 152 .WillRepeatedly(testing::ReturnRef(decoder_factory)); |
| 149 EXPECT_CALL(*channel_proxy, SetReceiveCodecs(testing::_)) | 153 EXPECT_CALL(*channel_proxy, SetReceiveCodecs(testing::_)) |
| 150 .WillRepeatedly(testing::Invoke( | 154 .WillRepeatedly(testing::Invoke( |
| 151 [](const std::map<int, SdpAudioFormat>& codecs) { | 155 [](const std::map<int, SdpAudioFormat>& codecs) { |
| 152 EXPECT_THAT(codecs, testing::IsEmpty()); | 156 EXPECT_THAT(codecs, testing::IsEmpty()); |
| 153 })); | 157 })); |
| 158 EXPECT_CALL(*channel_proxy, GetRtpRtcp(testing::_, testing::_)) |
| 159 .WillRepeatedly(testing::SetArgPointee<0>(&mock_rtp_rtcp)); |
| 154 // If being called for the send channel, save a pointer to the channel | 160 // If being called for the send channel, save a pointer to the channel |
| 155 // proxy for later. | 161 // proxy for later. |
| 156 if (channel_id == kRecvChannelId) { | 162 if (channel_id == kRecvChannelId) { |
| 157 EXPECT_FALSE(recv_channel_proxy); | 163 EXPECT_FALSE(recv_channel_proxy); |
| 158 recv_channel_proxy = channel_proxy; | 164 recv_channel_proxy = channel_proxy; |
| 159 } | 165 } |
| 160 return channel_proxy; | 166 return channel_proxy; |
| 161 })); | 167 })); |
| 162 | 168 |
| 163 AudioReceiveStream::Config recv_config; | 169 AudioReceiveStream::Config recv_config; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 179 call->DestroyAudioSendStream(send_stream); | 185 call->DestroyAudioSendStream(send_stream); |
| 180 | 186 |
| 181 EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1); | 187 EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1); |
| 182 call->DestroyAudioReceiveStream(recv_stream); | 188 call->DestroyAudioReceiveStream(recv_stream); |
| 183 } | 189 } |
| 184 | 190 |
| 185 TEST(CallTest, CreateDestroy_AssociateAudioSendReceiveStreams_SendFirst) { | 191 TEST(CallTest, CreateDestroy_AssociateAudioSendReceiveStreams_SendFirst) { |
| 186 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory( | 192 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory( |
| 187 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>); | 193 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>); |
| 188 CallHelper call(decoder_factory); | 194 CallHelper call(decoder_factory); |
| 195 ::testing::NiceMock<MockRtpRtcp> mock_rtp_rtcp; |
| 189 | 196 |
| 190 constexpr int kRecvChannelId = 101; | 197 constexpr int kRecvChannelId = 101; |
| 191 | 198 |
| 192 // Set up the mock to create a channel proxy which we know of, so that we can | 199 // Set up the mock to create a channel proxy which we know of, so that we can |
| 193 // add our expectations to it. | 200 // add our expectations to it. |
| 194 test::MockVoEChannelProxy* recv_channel_proxy = nullptr; | 201 test::MockVoEChannelProxy* recv_channel_proxy = nullptr; |
| 195 EXPECT_CALL(*call.voice_engine(), ChannelProxyFactory(testing::_)) | 202 EXPECT_CALL(*call.voice_engine(), ChannelProxyFactory(testing::_)) |
| 196 .WillRepeatedly(testing::Invoke([&](int channel_id) { | 203 .WillRepeatedly(testing::Invoke([&](int channel_id) { |
| 197 test::MockVoEChannelProxy* channel_proxy = | 204 test::MockVoEChannelProxy* channel_proxy = |
| 198 new testing::NiceMock<test::MockVoEChannelProxy>(); | 205 new testing::NiceMock<test::MockVoEChannelProxy>(); |
| 199 EXPECT_CALL(*channel_proxy, GetAudioDecoderFactory()) | 206 EXPECT_CALL(*channel_proxy, GetAudioDecoderFactory()) |
| 200 .WillRepeatedly(testing::ReturnRef(decoder_factory)); | 207 .WillRepeatedly(testing::ReturnRef(decoder_factory)); |
| 201 EXPECT_CALL(*channel_proxy, SetReceiveCodecs(testing::_)) | 208 EXPECT_CALL(*channel_proxy, SetReceiveCodecs(testing::_)) |
| 202 .WillRepeatedly(testing::Invoke( | 209 .WillRepeatedly(testing::Invoke( |
| 203 [](const std::map<int, SdpAudioFormat>& codecs) { | 210 [](const std::map<int, SdpAudioFormat>& codecs) { |
| 204 EXPECT_THAT(codecs, testing::IsEmpty()); | 211 EXPECT_THAT(codecs, testing::IsEmpty()); |
| 205 })); | 212 })); |
| 213 EXPECT_CALL(*channel_proxy, GetRtpRtcp(testing::_, testing::_)) |
| 214 .WillRepeatedly(testing::SetArgPointee<0>(&mock_rtp_rtcp)); |
| 206 // If being called for the send channel, save a pointer to the channel | 215 // If being called for the send channel, save a pointer to the channel |
| 207 // proxy for later. | 216 // proxy for later. |
| 208 if (channel_id == kRecvChannelId) { | 217 if (channel_id == kRecvChannelId) { |
| 209 EXPECT_FALSE(recv_channel_proxy); | 218 EXPECT_FALSE(recv_channel_proxy); |
| 210 recv_channel_proxy = channel_proxy; | 219 recv_channel_proxy = channel_proxy; |
| 211 // We need to set this expectation here since the channel proxy is | 220 // We need to set this expectation here since the channel proxy is |
| 212 // created as a side effect of CreateAudioReceiveStream(). | 221 // created as a side effect of CreateAudioReceiveStream(). |
| 213 EXPECT_CALL(*recv_channel_proxy, | 222 EXPECT_CALL(*recv_channel_proxy, |
| 214 AssociateSendChannel(testing::_)).Times(1); | 223 AssociateSendChannel(testing::_)).Times(1); |
| 215 } | 224 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 335 |
| 327 Call::Config::BitrateConfig bitrate_config; | 336 Call::Config::BitrateConfig bitrate_config; |
| 328 bitrate_config.min_bitrate_bps = 1; | 337 bitrate_config.min_bitrate_bps = 1; |
| 329 bitrate_config.start_bitrate_bps = 2; | 338 bitrate_config.start_bitrate_bps = 2; |
| 330 bitrate_config.max_bitrate_bps = 3; | 339 bitrate_config.max_bitrate_bps = 3; |
| 331 | 340 |
| 332 EXPECT_CALL(mock_cc, SetBweBitrates(1, 2, 3)); | 341 EXPECT_CALL(mock_cc, SetBweBitrates(1, 2, 3)); |
| 333 call->SetBitrateConfig(bitrate_config); | 342 call->SetBitrateConfig(bitrate_config); |
| 334 } | 343 } |
| 335 | 344 |
| 345 TEST(CallTest, RecreatingAudioStreamWithSameSsrcReusesRtpState) { |
| 346 constexpr uint32_t kSSRC = 12345; |
| 347 testing::NiceMock<test::MockAudioDeviceModule> mock_adm; |
| 348 // Reply with a 10ms timer every time TimeUntilNextProcess is called to |
| 349 // avoid entering a tight loop on the process thread. |
| 350 EXPECT_CALL(mock_adm, TimeUntilNextProcess()) |
| 351 .WillRepeatedly(testing::Return(10)); |
| 352 rtc::scoped_refptr<test::MockAudioMixer> mock_mixer( |
| 353 new rtc::RefCountedObject<test::MockAudioMixer>); |
| 354 |
| 355 // There's similar functionality in cricket::VoEWrapper but it's not reachable |
| 356 // from here. Since we're working on removing VoE interfaces, I doubt it's |
| 357 // worth making VoEWrapper more easily available. |
| 358 struct ScopedVoiceEngine { |
| 359 ScopedVoiceEngine() |
| 360 : voe(VoiceEngine::Create()), |
| 361 base(VoEBase::GetInterface(voe)) {} |
| 362 ~ScopedVoiceEngine() { |
| 363 base->Release(); |
| 364 EXPECT_TRUE(VoiceEngine::Delete(voe)); |
| 365 } |
| 366 |
| 367 VoiceEngine* voe; |
| 368 VoEBase* base; |
| 369 }; |
| 370 ScopedVoiceEngine voice_engine; |
| 371 |
| 372 voice_engine.base->Init(&mock_adm); |
| 373 AudioState::Config audio_state_config; |
| 374 audio_state_config.voice_engine = voice_engine.voe; |
| 375 audio_state_config.audio_mixer = mock_mixer; |
| 376 auto audio_state = AudioState::Create(audio_state_config); |
| 377 RtcEventLogNullImpl event_log; |
| 378 Call::Config call_config(&event_log); |
| 379 call_config.audio_state = audio_state; |
| 380 std::unique_ptr<Call> call(Call::Create(call_config)); |
| 381 |
| 382 auto create_stream_and_get_rtp_state = [&](uint32_t ssrc) { |
| 383 AudioSendStream::Config config(nullptr); |
| 384 config.rtp.ssrc = ssrc; |
| 385 config.voe_channel_id = voice_engine.base->CreateChannel(); |
| 386 AudioSendStream* stream = call->CreateAudioSendStream(config); |
| 387 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine.voe); |
| 388 auto channel_proxy = voe_impl->GetChannelProxy(config.voe_channel_id); |
| 389 RtpRtcp* rtp_rtcp = nullptr; |
| 390 RtpReceiver* rtp_receiver = nullptr; // Unused but required for call. |
| 391 channel_proxy->GetRtpRtcp(&rtp_rtcp, &rtp_receiver); |
| 392 const RtpState rtp_state = rtp_rtcp->GetRtpState(); |
| 393 call->DestroyAudioSendStream(stream); |
| 394 voice_engine.base->DeleteChannel(config.voe_channel_id); |
| 395 return rtp_state; |
| 396 }; |
| 397 |
| 398 const RtpState rtp_state1 = create_stream_and_get_rtp_state(kSSRC); |
| 399 const RtpState rtp_state2 = create_stream_and_get_rtp_state(kSSRC); |
| 400 |
| 401 EXPECT_EQ(rtp_state1.sequence_number, rtp_state2.sequence_number); |
| 402 EXPECT_EQ(rtp_state1.start_timestamp, rtp_state2.start_timestamp); |
| 403 EXPECT_EQ(rtp_state1.timestamp, rtp_state2.timestamp); |
| 404 EXPECT_EQ(rtp_state1.capture_time_ms, rtp_state2.capture_time_ms); |
| 405 EXPECT_EQ(rtp_state1.last_timestamp_time_ms, |
| 406 rtp_state2.last_timestamp_time_ms); |
| 407 EXPECT_EQ(rtp_state1.media_has_been_sent, rtp_state2.media_has_been_sent); |
| 408 } |
| 409 |
| 336 } // namespace webrtc | 410 } // namespace webrtc |
| OLD | NEW |