OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 using webrtc::StreamCollectionInterface; | 89 using webrtc::StreamCollectionInterface; |
90 | 90 |
91 static const int kMaxWaitMs = 10000; | 91 static const int kMaxWaitMs = 10000; |
92 // Disable for TSan v2, see | 92 // Disable for TSan v2, see |
93 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. | 93 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. |
94 // This declaration is also #ifdef'd as it causes uninitialized-variable | 94 // This declaration is also #ifdef'd as it causes uninitialized-variable |
95 // warnings. | 95 // warnings. |
96 #if !defined(THREAD_SANITIZER) | 96 #if !defined(THREAD_SANITIZER) |
97 static const int kMaxWaitForStatsMs = 3000; | 97 static const int kMaxWaitForStatsMs = 3000; |
98 #endif | 98 #endif |
| 99 static const int kMaxWaitForActivationMs = 5000; |
99 static const int kMaxWaitForFramesMs = 10000; | 100 static const int kMaxWaitForFramesMs = 10000; |
100 static const int kEndAudioFrameCount = 3; | 101 static const int kEndAudioFrameCount = 3; |
101 static const int kEndVideoFrameCount = 3; | 102 static const int kEndVideoFrameCount = 3; |
102 | 103 |
103 static const char kStreamLabelBase[] = "stream_label"; | 104 static const char kStreamLabelBase[] = "stream_label"; |
104 static const char kVideoTrackLabelBase[] = "video_track"; | 105 static const char kVideoTrackLabelBase[] = "video_track"; |
105 static const char kAudioTrackLabelBase[] = "audio_track"; | 106 static const char kAudioTrackLabelBase[] = "audio_track"; |
106 static const char kDataChannelLabel[] = "data_channel"; | 107 static const char kDataChannelLabel[] = "data_channel"; |
107 | 108 |
108 // Disable for TSan v2, see | 109 // Disable for TSan v2, see |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 } | 244 } |
244 | 245 |
245 void AddMediaStream(bool audio, bool video) { | 246 void AddMediaStream(bool audio, bool video) { |
246 std::string stream_label = | 247 std::string stream_label = |
247 kStreamLabelBase + | 248 kStreamLabelBase + |
248 rtc::ToString<int>(static_cast<int>(pc()->local_streams()->count())); | 249 rtc::ToString<int>(static_cast<int>(pc()->local_streams()->count())); |
249 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream = | 250 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream = |
250 peer_connection_factory_->CreateLocalMediaStream(stream_label); | 251 peer_connection_factory_->CreateLocalMediaStream(stream_label); |
251 | 252 |
252 if (audio && can_receive_audio()) { | 253 if (audio && can_receive_audio()) { |
253 FakeConstraints constraints; | 254 stream->AddTrack(CreateLocalAudioTrack(stream_label)); |
254 // Disable highpass filter so that we can get all the test audio frames. | |
255 constraints.AddMandatory( | |
256 MediaConstraintsInterface::kHighpassFilter, false); | |
257 rtc::scoped_refptr<webrtc::AudioSourceInterface> source = | |
258 peer_connection_factory_->CreateAudioSource(&constraints); | |
259 // TODO(perkj): Test audio source when it is implemented. Currently audio | |
260 // always use the default input. | |
261 std::string label = stream_label + kAudioTrackLabelBase; | |
262 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( | |
263 peer_connection_factory_->CreateAudioTrack(label, source)); | |
264 stream->AddTrack(audio_track); | |
265 } | 255 } |
266 if (video && can_receive_video()) { | 256 if (video && can_receive_video()) { |
267 stream->AddTrack(CreateLocalVideoTrack(stream_label)); | 257 stream->AddTrack(CreateLocalVideoTrack(stream_label)); |
268 } | 258 } |
269 | 259 |
270 EXPECT_TRUE(pc()->AddStream(stream)); | 260 EXPECT_TRUE(pc()->AddStream(stream)); |
271 } | 261 } |
272 | 262 |
273 size_t NumberOfLocalMediaStreams() { return pc()->local_streams()->count(); } | 263 size_t NumberOfLocalMediaStreams() { return pc()->local_streams()->count(); } |
274 | 264 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 data_channel_ = data_channel; | 340 data_channel_ = data_channel; |
351 data_observer_.reset(new MockDataChannelObserver(data_channel)); | 341 data_observer_.reset(new MockDataChannelObserver(data_channel)); |
352 } | 342 } |
353 | 343 |
354 void CreateDataChannel() { | 344 void CreateDataChannel() { |
355 data_channel_ = pc()->CreateDataChannel(kDataChannelLabel, nullptr); | 345 data_channel_ = pc()->CreateDataChannel(kDataChannelLabel, nullptr); |
356 ASSERT_TRUE(data_channel_.get() != nullptr); | 346 ASSERT_TRUE(data_channel_.get() != nullptr); |
357 data_observer_.reset(new MockDataChannelObserver(data_channel_)); | 347 data_observer_.reset(new MockDataChannelObserver(data_channel_)); |
358 } | 348 } |
359 | 349 |
| 350 rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack( |
| 351 const std::string& stream_label) { |
| 352 FakeConstraints constraints; |
| 353 // Disable highpass filter so that we can get all the test audio frames. |
| 354 constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false); |
| 355 rtc::scoped_refptr<webrtc::AudioSourceInterface> source = |
| 356 peer_connection_factory_->CreateAudioSource(&constraints); |
| 357 // TODO(perkj): Test audio source when it is implemented. Currently audio |
| 358 // always use the default input. |
| 359 std::string label = stream_label + kAudioTrackLabelBase; |
| 360 return peer_connection_factory_->CreateAudioTrack(label, source); |
| 361 } |
| 362 |
| 363 rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack( |
| 364 const std::string& stream_label) { |
| 365 // Set max frame rate to 10fps to reduce the risk of the tests to be flaky. |
| 366 FakeConstraints source_constraints = video_constraints_; |
| 367 source_constraints.SetMandatoryMaxFrameRate(10); |
| 368 |
| 369 cricket::FakeVideoCapturer* fake_capturer = |
| 370 new webrtc::FakePeriodicVideoCapturer(); |
| 371 video_capturers_.push_back(fake_capturer); |
| 372 rtc::scoped_refptr<webrtc::VideoSourceInterface> source = |
| 373 peer_connection_factory_->CreateVideoSource(fake_capturer, |
| 374 &source_constraints); |
| 375 std::string label = stream_label + kVideoTrackLabelBase; |
| 376 return peer_connection_factory_->CreateVideoTrack(label, source); |
| 377 } |
| 378 |
360 DataChannelInterface* data_channel() { return data_channel_; } | 379 DataChannelInterface* data_channel() { return data_channel_; } |
361 const MockDataChannelObserver* data_observer() const { | 380 const MockDataChannelObserver* data_observer() const { |
362 return data_observer_.get(); | 381 return data_observer_.get(); |
363 } | 382 } |
364 | 383 |
365 webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); } | 384 webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); } |
366 | 385 |
367 void StopVideoCapturers() { | 386 void StopVideoCapturers() { |
368 for (std::vector<cricket::VideoCapturer*>::iterator it = | 387 for (std::vector<cricket::VideoCapturer*>::iterator it = |
369 video_capturers_.begin(); | 388 video_capturers_.begin(); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 return false; | 683 return false; |
665 } | 684 } |
666 if (options) { | 685 if (options) { |
667 peer_connection_factory_->SetOptions(*options); | 686 peer_connection_factory_->SetOptions(*options); |
668 } | 687 } |
669 peer_connection_ = CreatePeerConnection(allocator_factory_.get(), | 688 peer_connection_ = CreatePeerConnection(allocator_factory_.get(), |
670 constraints); | 689 constraints); |
671 return peer_connection_.get() != nullptr; | 690 return peer_connection_.get() != nullptr; |
672 } | 691 } |
673 | 692 |
674 rtc::scoped_refptr<webrtc::VideoTrackInterface> | |
675 CreateLocalVideoTrack(const std::string stream_label) { | |
676 // Set max frame rate to 10fps to reduce the risk of the tests to be flaky. | |
677 FakeConstraints source_constraints = video_constraints_; | |
678 source_constraints.SetMandatoryMaxFrameRate(10); | |
679 | |
680 cricket::FakeVideoCapturer* fake_capturer = | |
681 new webrtc::FakePeriodicVideoCapturer(); | |
682 video_capturers_.push_back(fake_capturer); | |
683 rtc::scoped_refptr<webrtc::VideoSourceInterface> source = | |
684 peer_connection_factory_->CreateVideoSource( | |
685 fake_capturer, &source_constraints); | |
686 std::string label = stream_label + kVideoTrackLabelBase; | |
687 return peer_connection_factory_->CreateVideoTrack(label, source); | |
688 } | |
689 | |
690 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( | 693 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( |
691 webrtc::PortAllocatorFactoryInterface* factory, | 694 webrtc::PortAllocatorFactoryInterface* factory, |
692 const MediaConstraintsInterface* constraints) { | 695 const MediaConstraintsInterface* constraints) { |
693 // CreatePeerConnection with IceServers. | 696 // CreatePeerConnection with IceServers. |
694 webrtc::PeerConnectionInterface::IceServers ice_servers; | 697 webrtc::PeerConnectionInterface::IceServers ice_servers; |
695 webrtc::PeerConnectionInterface::IceServer ice_server; | 698 webrtc::PeerConnectionInterface::IceServer ice_server; |
696 ice_server.uri = "stun:stun.l.google.com:19302"; | 699 ice_server.uri = "stun:stun.l.google.com:19302"; |
697 ice_servers.push_back(ice_server); | 700 ice_servers.push_back(ice_server); |
698 | 701 |
699 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store( | 702 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store( |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 } | 953 } |
951 | 954 |
952 // This test sets up a call between two parties. Both parties send static | 955 // This test sets up a call between two parties. Both parties send static |
953 // frames to each other. Once the test is finished the number of sent frames | 956 // frames to each other. Once the test is finished the number of sent frames |
954 // is compared to the number of received frames. | 957 // is compared to the number of received frames. |
955 void LocalP2PTest() { | 958 void LocalP2PTest() { |
956 if (initiating_client_->NumberOfLocalMediaStreams() == 0) { | 959 if (initiating_client_->NumberOfLocalMediaStreams() == 0) { |
957 initiating_client_->AddMediaStream(true, true); | 960 initiating_client_->AddMediaStream(true, true); |
958 } | 961 } |
959 initiating_client_->Negotiate(); | 962 initiating_client_->Negotiate(); |
960 const int kMaxWaitForActivationMs = 5000; | |
961 // Assert true is used here since next tests are guaranteed to fail and | 963 // Assert true is used here since next tests are guaranteed to fail and |
962 // would eat up 5 seconds. | 964 // would eat up 5 seconds. |
963 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); | 965 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); |
964 VerifySessionDescriptions(); | 966 VerifySessionDescriptions(); |
965 | 967 |
966 | |
967 int audio_frame_count = kEndAudioFrameCount; | 968 int audio_frame_count = kEndAudioFrameCount; |
968 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly. | 969 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly. |
969 if (!initiating_client_->can_receive_audio() || | 970 if (!initiating_client_->can_receive_audio() || |
970 !receiving_client_->can_receive_audio()) { | 971 !receiving_client_->can_receive_audio()) { |
971 audio_frame_count = -1; | 972 audio_frame_count = -1; |
972 } | 973 } |
973 int video_frame_count = kEndVideoFrameCount; | 974 int video_frame_count = kEndVideoFrameCount; |
974 if (!initiating_client_->can_receive_video() || | 975 if (!initiating_client_->can_receive_video() || |
975 !receiving_client_->can_receive_video()) { | 976 !receiving_client_->can_receive_video()) { |
976 video_frame_count = -1; | 977 video_frame_count = -1; |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 // VideoDecoderFactory. | 1567 // VideoDecoderFactory. |
1567 // TODO(holmer): Disabled due to sometimes crashing on buildbots. | 1568 // TODO(holmer): Disabled due to sometimes crashing on buildbots. |
1568 // See issue webrtc/2378. | 1569 // See issue webrtc/2378. |
1569 TEST_F(JsepPeerConnectionP2PTestClient, | 1570 TEST_F(JsepPeerConnectionP2PTestClient, |
1570 DISABLED_LocalP2PTestWithVideoDecoderFactory) { | 1571 DISABLED_LocalP2PTestWithVideoDecoderFactory) { |
1571 ASSERT_TRUE(CreateTestClients()); | 1572 ASSERT_TRUE(CreateTestClients()); |
1572 EnableVideoDecoderFactory(); | 1573 EnableVideoDecoderFactory(); |
1573 LocalP2PTest(); | 1574 LocalP2PTest(); |
1574 } | 1575 } |
1575 | 1576 |
| 1577 // This tests that if we negotiate after calling CreateSender but before we |
| 1578 // have a track, then set a track later, frames from the newly-set track are |
| 1579 // received end-to-end. |
| 1580 TEST_F(JsepPeerConnectionP2PTestClient, EarlyWarmupTest) { |
| 1581 ASSERT_TRUE(CreateTestClients()); |
| 1582 auto audio_sender = initializing_client()->pc()->CreateSender("audio"); |
| 1583 auto video_sender = initializing_client()->pc()->CreateSender("video"); |
| 1584 initializing_client()->Negotiate(); |
| 1585 // Wait for ICE connection to complete, without any tracks. |
| 1586 // Note that the receiving client WILL (in HandleIncomingOffer) create |
| 1587 // tracks, so it's only the initiator here that's doing early warmup. |
| 1588 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); |
| 1589 VerifySessionDescriptions(); |
| 1590 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 1591 initializing_client()->ice_connection_state(), |
| 1592 kMaxWaitForFramesMs); |
| 1593 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 1594 receiving_client()->ice_connection_state(), |
| 1595 kMaxWaitForFramesMs); |
| 1596 // Now set the tracks, and expect frames to immediately start flowing. |
| 1597 EXPECT_TRUE( |
| 1598 audio_sender->SetTrack(initializing_client()->CreateLocalAudioTrack(""))); |
| 1599 EXPECT_TRUE( |
| 1600 video_sender->SetTrack(initializing_client()->CreateLocalVideoTrack(""))); |
| 1601 EXPECT_TRUE_WAIT(FramesNotPending(kEndAudioFrameCount, kEndVideoFrameCount), |
| 1602 kMaxWaitForFramesMs); |
| 1603 } |
| 1604 |
1576 class IceServerParsingTest : public testing::Test { | 1605 class IceServerParsingTest : public testing::Test { |
1577 public: | 1606 public: |
1578 // Convenience for parsing a single URL. | 1607 // Convenience for parsing a single URL. |
1579 bool ParseUrl(const std::string& url) { | 1608 bool ParseUrl(const std::string& url) { |
1580 return ParseUrl(url, std::string(), std::string()); | 1609 return ParseUrl(url, std::string(), std::string()); |
1581 } | 1610 } |
1582 | 1611 |
1583 bool ParseUrl(const std::string& url, | 1612 bool ParseUrl(const std::string& url, |
1584 const std::string& username, | 1613 const std::string& username, |
1585 const std::string& password) { | 1614 const std::string& password) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1743 server.urls.push_back("stun:hostname"); | 1772 server.urls.push_back("stun:hostname"); |
1744 server.urls.push_back("turn:hostname"); | 1773 server.urls.push_back("turn:hostname"); |
1745 servers.push_back(server); | 1774 servers.push_back(server); |
1746 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_, | 1775 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_, |
1747 &turn_configurations_)); | 1776 &turn_configurations_)); |
1748 EXPECT_EQ(1U, stun_configurations_.size()); | 1777 EXPECT_EQ(1U, stun_configurations_.size()); |
1749 EXPECT_EQ(1U, turn_configurations_.size()); | 1778 EXPECT_EQ(1U, turn_configurations_.size()); |
1750 } | 1779 } |
1751 | 1780 |
1752 #endif // if !defined(THREAD_SANITIZER) | 1781 #endif // if !defined(THREAD_SANITIZER) |
OLD | NEW |