| 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 bitrate_config.start_bitrate_bps = 2; | 418 bitrate_config.start_bitrate_bps = 2; |
| 410 bitrate_config.max_bitrate_bps = 3; | 419 bitrate_config.max_bitrate_bps = 3; |
| 411 | 420 |
| 412 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1, 2, 3)).Times(1); | 421 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1, 2, 3)).Times(1); |
| 413 call->SetBitrateConfig(bitrate_config); | 422 call->SetBitrateConfig(bitrate_config); |
| 414 | 423 |
| 415 bitrate_config.start_bitrate_bps = -1; | 424 bitrate_config.start_bitrate_bps = -1; |
| 416 call->SetBitrateConfig(bitrate_config); | 425 call->SetBitrateConfig(bitrate_config); |
| 417 } | 426 } |
| 418 | 427 |
| 428 TEST(CallTest, RecreatingAudioStreamWithSameSsrcReusesRtpState) { |
| 429 constexpr uint32_t kSSRC = 12345; |
| 430 testing::NiceMock<test::MockAudioDeviceModule> mock_adm; |
| 431 // Reply with a 10ms timer every time TimeUntilNextProcess is called to |
| 432 // avoid entering a tight loop on the process thread. |
| 433 EXPECT_CALL(mock_adm, TimeUntilNextProcess()) |
| 434 .WillRepeatedly(testing::Return(10)); |
| 435 rtc::scoped_refptr<test::MockAudioMixer> mock_mixer( |
| 436 new rtc::RefCountedObject<test::MockAudioMixer>); |
| 437 |
| 438 // There's similar functionality in cricket::VoEWrapper but it's not reachable |
| 439 // from here. Since we're working on removing VoE interfaces, I doubt it's |
| 440 // worth making VoEWrapper more easily available. |
| 441 struct ScopedVoiceEngine { |
| 442 ScopedVoiceEngine() |
| 443 : voe(VoiceEngine::Create()), |
| 444 base(VoEBase::GetInterface(voe)) {} |
| 445 ~ScopedVoiceEngine() { |
| 446 base->Release(); |
| 447 EXPECT_TRUE(VoiceEngine::Delete(voe)); |
| 448 } |
| 449 |
| 450 VoiceEngine* voe; |
| 451 VoEBase* base; |
| 452 }; |
| 453 ScopedVoiceEngine voice_engine; |
| 454 |
| 455 voice_engine.base->Init(&mock_adm); |
| 456 AudioState::Config audio_state_config; |
| 457 audio_state_config.voice_engine = voice_engine.voe; |
| 458 audio_state_config.audio_mixer = mock_mixer; |
| 459 auto audio_state = AudioState::Create(audio_state_config); |
| 460 RtcEventLogNullImpl event_log; |
| 461 Call::Config call_config(&event_log); |
| 462 call_config.audio_state = audio_state; |
| 463 std::unique_ptr<Call> call(Call::Create(call_config)); |
| 464 |
| 465 auto create_stream_and_get_rtp_state = [&](uint32_t ssrc) { |
| 466 AudioSendStream::Config config(nullptr); |
| 467 config.rtp.ssrc = ssrc; |
| 468 config.voe_channel_id = voice_engine.base->CreateChannel(); |
| 469 AudioSendStream* stream = call->CreateAudioSendStream(config); |
| 470 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine.voe); |
| 471 auto channel_proxy = voe_impl->GetChannelProxy(config.voe_channel_id); |
| 472 RtpRtcp* rtp_rtcp = nullptr; |
| 473 RtpReceiver* rtp_receiver = nullptr; // Unused but required for call. |
| 474 channel_proxy->GetRtpRtcp(&rtp_rtcp, &rtp_receiver); |
| 475 const RtpState rtp_state = rtp_rtcp->GetRtpState(); |
| 476 call->DestroyAudioSendStream(stream); |
| 477 voice_engine.base->DeleteChannel(config.voe_channel_id); |
| 478 return rtp_state; |
| 479 }; |
| 480 |
| 481 const RtpState rtp_state1 = create_stream_and_get_rtp_state(kSSRC); |
| 482 const RtpState rtp_state2 = create_stream_and_get_rtp_state(kSSRC); |
| 483 |
| 484 EXPECT_EQ(rtp_state1.sequence_number, rtp_state2.sequence_number); |
| 485 EXPECT_EQ(rtp_state1.start_timestamp, rtp_state2.start_timestamp); |
| 486 EXPECT_EQ(rtp_state1.timestamp, rtp_state2.timestamp); |
| 487 EXPECT_EQ(rtp_state1.capture_time_ms, rtp_state2.capture_time_ms); |
| 488 EXPECT_EQ(rtp_state1.last_timestamp_time_ms, |
| 489 rtp_state2.last_timestamp_time_ms); |
| 490 EXPECT_EQ(rtp_state1.media_has_been_sent, rtp_state2.media_has_been_sent); |
| 491 } |
| 492 |
| 419 } // namespace webrtc | 493 } // namespace webrtc |
| OLD | NEW |