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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 } | 951 } |
949 | 952 |
950 // This test sets up a call between two parties. Both parties send static | 953 // This test sets up a call between two parties. Both parties send static |
951 // frames to each other. Once the test is finished the number of sent frames | 954 // frames to each other. Once the test is finished the number of sent frames |
952 // is compared to the number of received frames. | 955 // is compared to the number of received frames. |
953 void LocalP2PTest() { | 956 void LocalP2PTest() { |
954 if (initiating_client_->NumberOfLocalMediaStreams() == 0) { | 957 if (initiating_client_->NumberOfLocalMediaStreams() == 0) { |
955 initiating_client_->AddMediaStream(true, true); | 958 initiating_client_->AddMediaStream(true, true); |
956 } | 959 } |
957 initiating_client_->Negotiate(); | 960 initiating_client_->Negotiate(); |
958 const int kMaxWaitForActivationMs = 5000; | |
959 // Assert true is used here since next tests are guaranteed to fail and | 961 // Assert true is used here since next tests are guaranteed to fail and |
960 // would eat up 5 seconds. | 962 // would eat up 5 seconds. |
961 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); | 963 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); |
962 VerifySessionDescriptions(); | 964 VerifySessionDescriptions(); |
963 | 965 |
964 | |
965 int audio_frame_count = kEndAudioFrameCount; | 966 int audio_frame_count = kEndAudioFrameCount; |
966 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly. | 967 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly. |
967 if (!initiating_client_->can_receive_audio() || | 968 if (!initiating_client_->can_receive_audio() || |
968 !receiving_client_->can_receive_audio()) { | 969 !receiving_client_->can_receive_audio()) { |
969 audio_frame_count = -1; | 970 audio_frame_count = -1; |
970 } | 971 } |
971 int video_frame_count = kEndVideoFrameCount; | 972 int video_frame_count = kEndVideoFrameCount; |
972 if (!initiating_client_->can_receive_video() || | 973 if (!initiating_client_->can_receive_video() || |
973 !receiving_client_->can_receive_video()) { | 974 !receiving_client_->can_receive_video()) { |
974 video_frame_count = -1; | 975 video_frame_count = -1; |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 // This test sets up a Jsep call between two parties with external | 1563 // This test sets up a Jsep call between two parties with external |
1563 // VideoDecoderFactory. | 1564 // VideoDecoderFactory. |
1564 // TODO(holmer): Disabled due to sometimes crashing on buildbots. | 1565 // TODO(holmer): Disabled due to sometimes crashing on buildbots. |
1565 // See issue webrtc/2378. | 1566 // See issue webrtc/2378. |
1566 TEST_F(P2PTestConductor, DISABLED_LocalP2PTestWithVideoDecoderFactory) { | 1567 TEST_F(P2PTestConductor, DISABLED_LocalP2PTestWithVideoDecoderFactory) { |
1567 ASSERT_TRUE(CreateTestClients()); | 1568 ASSERT_TRUE(CreateTestClients()); |
1568 EnableVideoDecoderFactory(); | 1569 EnableVideoDecoderFactory(); |
1569 LocalP2PTest(); | 1570 LocalP2PTest(); |
1570 } | 1571 } |
1571 | 1572 |
| 1573 // This tests that if we negotiate after calling CreateSender but before we |
| 1574 // have a track, then set a track later, frames from the newly-set track are |
| 1575 // received end-to-end. |
| 1576 TEST_F(P2PTestConductor, EarlyWarmupTest) { |
| 1577 ASSERT_TRUE(CreateTestClients()); |
| 1578 auto audio_sender = initializing_client()->pc()->CreateSender("audio"); |
| 1579 auto video_sender = initializing_client()->pc()->CreateSender("video"); |
| 1580 initializing_client()->Negotiate(); |
| 1581 // Wait for ICE connection to complete, without any tracks. |
| 1582 // Note that the receiving client WILL (in HandleIncomingOffer) create |
| 1583 // tracks, so it's only the initiator here that's doing early warmup. |
| 1584 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); |
| 1585 VerifySessionDescriptions(); |
| 1586 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 1587 initializing_client()->ice_connection_state(), |
| 1588 kMaxWaitForFramesMs); |
| 1589 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 1590 receiving_client()->ice_connection_state(), |
| 1591 kMaxWaitForFramesMs); |
| 1592 // Now set the tracks, and expect frames to immediately start flowing. |
| 1593 EXPECT_TRUE( |
| 1594 audio_sender->SetTrack(initializing_client()->CreateLocalAudioTrack(""))); |
| 1595 EXPECT_TRUE( |
| 1596 video_sender->SetTrack(initializing_client()->CreateLocalVideoTrack(""))); |
| 1597 EXPECT_TRUE_WAIT(FramesNotPending(kEndAudioFrameCount, kEndVideoFrameCount), |
| 1598 kMaxWaitForFramesMs); |
| 1599 } |
| 1600 |
1572 class IceServerParsingTest : public testing::Test { | 1601 class IceServerParsingTest : public testing::Test { |
1573 public: | 1602 public: |
1574 // Convenience for parsing a single URL. | 1603 // Convenience for parsing a single URL. |
1575 bool ParseUrl(const std::string& url) { | 1604 bool ParseUrl(const std::string& url) { |
1576 return ParseUrl(url, std::string(), std::string()); | 1605 return ParseUrl(url, std::string(), std::string()); |
1577 } | 1606 } |
1578 | 1607 |
1579 bool ParseUrl(const std::string& url, | 1608 bool ParseUrl(const std::string& url, |
1580 const std::string& username, | 1609 const std::string& username, |
1581 const std::string& password) { | 1610 const std::string& password) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1739 server.urls.push_back("stun:hostname"); | 1768 server.urls.push_back("stun:hostname"); |
1740 server.urls.push_back("turn:hostname"); | 1769 server.urls.push_back("turn:hostname"); |
1741 servers.push_back(server); | 1770 servers.push_back(server); |
1742 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_, | 1771 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_, |
1743 &turn_configurations_)); | 1772 &turn_configurations_)); |
1744 EXPECT_EQ(1U, stun_configurations_.size()); | 1773 EXPECT_EQ(1U, stun_configurations_.size()); |
1745 EXPECT_EQ(1U, turn_configurations_.size()); | 1774 EXPECT_EQ(1U, turn_configurations_.size()); |
1746 } | 1775 } |
1747 | 1776 |
1748 #endif // if !defined(THREAD_SANITIZER) | 1777 #endif // if !defined(THREAD_SANITIZER) |
OLD | NEW |