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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 using webrtc::StreamCollectionInterface; | 91 using webrtc::StreamCollectionInterface; |
92 | 92 |
93 static const int kMaxWaitMs = 10000; | 93 static const int kMaxWaitMs = 10000; |
94 // Disable for TSan v2, see | 94 // Disable for TSan v2, see |
95 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. | 95 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. |
96 // This declaration is also #ifdef'd as it causes uninitialized-variable | 96 // This declaration is also #ifdef'd as it causes uninitialized-variable |
97 // warnings. | 97 // warnings. |
98 #if !defined(THREAD_SANITIZER) | 98 #if !defined(THREAD_SANITIZER) |
99 static const int kMaxWaitForStatsMs = 3000; | 99 static const int kMaxWaitForStatsMs = 3000; |
100 #endif | 100 #endif |
| 101 static const int kMaxWaitForActivationMs = 5000; |
101 static const int kMaxWaitForFramesMs = 10000; | 102 static const int kMaxWaitForFramesMs = 10000; |
102 static const int kEndAudioFrameCount = 3; | 103 static const int kEndAudioFrameCount = 3; |
103 static const int kEndVideoFrameCount = 3; | 104 static const int kEndVideoFrameCount = 3; |
104 | 105 |
105 static const char kStreamLabelBase[] = "stream_label"; | 106 static const char kStreamLabelBase[] = "stream_label"; |
106 static const char kVideoTrackLabelBase[] = "video_track"; | 107 static const char kVideoTrackLabelBase[] = "video_track"; |
107 static const char kAudioTrackLabelBase[] = "audio_track"; | 108 static const char kAudioTrackLabelBase[] = "audio_track"; |
108 static const char kDataChannelLabel[] = "data_channel"; | 109 static const char kDataChannelLabel[] = "data_channel"; |
109 | 110 |
110 // Disable for TSan v2, see | 111 // Disable for TSan v2, see |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 } | 282 } |
282 | 283 |
283 void AddMediaStream(bool audio, bool video) { | 284 void AddMediaStream(bool audio, bool video) { |
284 std::string stream_label = | 285 std::string stream_label = |
285 kStreamLabelBase + | 286 kStreamLabelBase + |
286 rtc::ToString<int>(static_cast<int>(pc()->local_streams()->count())); | 287 rtc::ToString<int>(static_cast<int>(pc()->local_streams()->count())); |
287 rtc::scoped_refptr<MediaStreamInterface> stream = | 288 rtc::scoped_refptr<MediaStreamInterface> stream = |
288 peer_connection_factory_->CreateLocalMediaStream(stream_label); | 289 peer_connection_factory_->CreateLocalMediaStream(stream_label); |
289 | 290 |
290 if (audio && can_receive_audio()) { | 291 if (audio && can_receive_audio()) { |
291 FakeConstraints constraints; | 292 stream->AddTrack(CreateLocalAudioTrack(stream_label)); |
292 // Disable highpass filter so that we can get all the test audio frames. | |
293 constraints.AddMandatory( | |
294 MediaConstraintsInterface::kHighpassFilter, false); | |
295 rtc::scoped_refptr<webrtc::AudioSourceInterface> source = | |
296 peer_connection_factory_->CreateAudioSource(&constraints); | |
297 // TODO(perkj): Test audio source when it is implemented. Currently audio | |
298 // always use the default input. | |
299 std::string label = stream_label + kAudioTrackLabelBase; | |
300 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( | |
301 peer_connection_factory_->CreateAudioTrack(label, source)); | |
302 stream->AddTrack(audio_track); | |
303 } | 293 } |
304 if (video && can_receive_video()) { | 294 if (video && can_receive_video()) { |
305 stream->AddTrack(CreateLocalVideoTrack(stream_label)); | 295 stream->AddTrack(CreateLocalVideoTrack(stream_label)); |
306 } | 296 } |
307 | 297 |
308 EXPECT_TRUE(pc()->AddStream(stream)); | 298 EXPECT_TRUE(pc()->AddStream(stream)); |
309 } | 299 } |
310 | 300 |
311 size_t NumberOfLocalMediaStreams() { return pc()->local_streams()->count(); } | 301 size_t NumberOfLocalMediaStreams() { return pc()->local_streams()->count(); } |
312 | 302 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 data_channel_ = data_channel; | 384 data_channel_ = data_channel; |
395 data_observer_.reset(new MockDataChannelObserver(data_channel)); | 385 data_observer_.reset(new MockDataChannelObserver(data_channel)); |
396 } | 386 } |
397 | 387 |
398 void CreateDataChannel() { | 388 void CreateDataChannel() { |
399 data_channel_ = pc()->CreateDataChannel(kDataChannelLabel, nullptr); | 389 data_channel_ = pc()->CreateDataChannel(kDataChannelLabel, nullptr); |
400 ASSERT_TRUE(data_channel_.get() != nullptr); | 390 ASSERT_TRUE(data_channel_.get() != nullptr); |
401 data_observer_.reset(new MockDataChannelObserver(data_channel_)); | 391 data_observer_.reset(new MockDataChannelObserver(data_channel_)); |
402 } | 392 } |
403 | 393 |
| 394 rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack( |
| 395 const std::string& stream_label) { |
| 396 FakeConstraints constraints; |
| 397 // Disable highpass filter so that we can get all the test audio frames. |
| 398 constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false); |
| 399 rtc::scoped_refptr<webrtc::AudioSourceInterface> source = |
| 400 peer_connection_factory_->CreateAudioSource(&constraints); |
| 401 // TODO(perkj): Test audio source when it is implemented. Currently audio |
| 402 // always use the default input. |
| 403 std::string label = stream_label + kAudioTrackLabelBase; |
| 404 return peer_connection_factory_->CreateAudioTrack(label, source); |
| 405 } |
| 406 |
| 407 rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack( |
| 408 const std::string& stream_label) { |
| 409 // Set max frame rate to 10fps to reduce the risk of the tests to be flaky. |
| 410 FakeConstraints source_constraints = video_constraints_; |
| 411 source_constraints.SetMandatoryMaxFrameRate(10); |
| 412 |
| 413 cricket::FakeVideoCapturer* fake_capturer = |
| 414 new webrtc::FakePeriodicVideoCapturer(); |
| 415 video_capturers_.push_back(fake_capturer); |
| 416 rtc::scoped_refptr<webrtc::VideoSourceInterface> source = |
| 417 peer_connection_factory_->CreateVideoSource(fake_capturer, |
| 418 &source_constraints); |
| 419 std::string label = stream_label + kVideoTrackLabelBase; |
| 420 return peer_connection_factory_->CreateVideoTrack(label, source); |
| 421 } |
| 422 |
404 DataChannelInterface* data_channel() { return data_channel_; } | 423 DataChannelInterface* data_channel() { return data_channel_; } |
405 const MockDataChannelObserver* data_observer() const { | 424 const MockDataChannelObserver* data_observer() const { |
406 return data_observer_.get(); | 425 return data_observer_.get(); |
407 } | 426 } |
408 | 427 |
409 webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); } | 428 webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); } |
410 | 429 |
411 void StopVideoCapturers() { | 430 void StopVideoCapturers() { |
412 for (std::vector<cricket::VideoCapturer*>::iterator it = | 431 for (std::vector<cricket::VideoCapturer*>::iterator it = |
413 video_capturers_.begin(); | 432 video_capturers_.begin(); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 return false; | 727 return false; |
709 } | 728 } |
710 if (options) { | 729 if (options) { |
711 peer_connection_factory_->SetOptions(*options); | 730 peer_connection_factory_->SetOptions(*options); |
712 } | 731 } |
713 peer_connection_ = CreatePeerConnection(allocator_factory_.get(), | 732 peer_connection_ = CreatePeerConnection(allocator_factory_.get(), |
714 constraints); | 733 constraints); |
715 return peer_connection_.get() != nullptr; | 734 return peer_connection_.get() != nullptr; |
716 } | 735 } |
717 | 736 |
718 rtc::scoped_refptr<webrtc::VideoTrackInterface> | |
719 CreateLocalVideoTrack(const std::string stream_label) { | |
720 // Set max frame rate to 10fps to reduce the risk of the tests to be flaky. | |
721 FakeConstraints source_constraints = video_constraints_; | |
722 source_constraints.SetMandatoryMaxFrameRate(10); | |
723 | |
724 cricket::FakeVideoCapturer* fake_capturer = | |
725 new webrtc::FakePeriodicVideoCapturer(); | |
726 video_capturers_.push_back(fake_capturer); | |
727 rtc::scoped_refptr<webrtc::VideoSourceInterface> source = | |
728 peer_connection_factory_->CreateVideoSource( | |
729 fake_capturer, &source_constraints); | |
730 std::string label = stream_label + kVideoTrackLabelBase; | |
731 return peer_connection_factory_->CreateVideoTrack(label, source); | |
732 } | |
733 | |
734 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( | 737 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( |
735 webrtc::PortAllocatorFactoryInterface* factory, | 738 webrtc::PortAllocatorFactoryInterface* factory, |
736 const MediaConstraintsInterface* constraints) { | 739 const MediaConstraintsInterface* constraints) { |
737 // CreatePeerConnection with IceServers. | 740 // CreatePeerConnection with IceServers. |
738 webrtc::PeerConnectionInterface::IceServers ice_servers; | 741 webrtc::PeerConnectionInterface::IceServers ice_servers; |
739 webrtc::PeerConnectionInterface::IceServer ice_server; | 742 webrtc::PeerConnectionInterface::IceServer ice_server; |
740 ice_server.uri = "stun:stun.l.google.com:19302"; | 743 ice_server.uri = "stun:stun.l.google.com:19302"; |
741 ice_servers.push_back(ice_server); | 744 ice_servers.push_back(ice_server); |
742 | 745 |
743 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store( | 746 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store( |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 } | 1007 } |
1005 | 1008 |
1006 // This test sets up a call between two parties. Both parties send static | 1009 // This test sets up a call between two parties. Both parties send static |
1007 // frames to each other. Once the test is finished the number of sent frames | 1010 // frames to each other. Once the test is finished the number of sent frames |
1008 // is compared to the number of received frames. | 1011 // is compared to the number of received frames. |
1009 void LocalP2PTest() { | 1012 void LocalP2PTest() { |
1010 if (initiating_client_->NumberOfLocalMediaStreams() == 0) { | 1013 if (initiating_client_->NumberOfLocalMediaStreams() == 0) { |
1011 initiating_client_->AddMediaStream(true, true); | 1014 initiating_client_->AddMediaStream(true, true); |
1012 } | 1015 } |
1013 initiating_client_->Negotiate(); | 1016 initiating_client_->Negotiate(); |
1014 const int kMaxWaitForActivationMs = 5000; | |
1015 // Assert true is used here since next tests are guaranteed to fail and | 1017 // Assert true is used here since next tests are guaranteed to fail and |
1016 // would eat up 5 seconds. | 1018 // would eat up 5 seconds. |
1017 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); | 1019 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); |
1018 VerifySessionDescriptions(); | 1020 VerifySessionDescriptions(); |
1019 | 1021 |
1020 int audio_frame_count = kEndAudioFrameCount; | 1022 int audio_frame_count = kEndAudioFrameCount; |
1021 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly. | 1023 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly. |
1022 if (!initiating_client_->can_receive_audio() || | 1024 if (!initiating_client_->can_receive_audio() || |
1023 !receiving_client_->can_receive_audio()) { | 1025 !receiving_client_->can_receive_audio()) { |
1024 audio_frame_count = -1; | 1026 audio_frame_count = -1; |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 // VideoDecoderFactory. | 1648 // VideoDecoderFactory. |
1647 // TODO(holmer): Disabled due to sometimes crashing on buildbots. | 1649 // TODO(holmer): Disabled due to sometimes crashing on buildbots. |
1648 // See issue webrtc/2378. | 1650 // See issue webrtc/2378. |
1649 TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, | 1651 TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, |
1650 DISABLED_LocalP2PTestWithVideoDecoderFactory) { | 1652 DISABLED_LocalP2PTestWithVideoDecoderFactory) { |
1651 ASSERT_TRUE(CreateTestClients()); | 1653 ASSERT_TRUE(CreateTestClients()); |
1652 EnableVideoDecoderFactory(); | 1654 EnableVideoDecoderFactory(); |
1653 LocalP2PTest(); | 1655 LocalP2PTest(); |
1654 } | 1656 } |
1655 | 1657 |
| 1658 // This tests that if we negotiate after calling CreateSender but before we |
| 1659 // have a track, then set a track later, frames from the newly-set track are |
| 1660 // received end-to-end. |
| 1661 TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, EarlyWarmupTest) { |
| 1662 ASSERT_TRUE(CreateTestClients()); |
| 1663 auto audio_sender = initializing_client()->pc()->CreateSender("audio"); |
| 1664 auto video_sender = initializing_client()->pc()->CreateSender("video"); |
| 1665 initializing_client()->Negotiate(); |
| 1666 // Wait for ICE connection to complete, without any tracks. |
| 1667 // Note that the receiving client WILL (in HandleIncomingOffer) create |
| 1668 // tracks, so it's only the initiator here that's doing early warmup. |
| 1669 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); |
| 1670 VerifySessionDescriptions(); |
| 1671 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 1672 initializing_client()->ice_connection_state(), |
| 1673 kMaxWaitForFramesMs); |
| 1674 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 1675 receiving_client()->ice_connection_state(), |
| 1676 kMaxWaitForFramesMs); |
| 1677 // Now set the tracks, and expect frames to immediately start flowing. |
| 1678 EXPECT_TRUE( |
| 1679 audio_sender->SetTrack(initializing_client()->CreateLocalAudioTrack(""))); |
| 1680 EXPECT_TRUE( |
| 1681 video_sender->SetTrack(initializing_client()->CreateLocalVideoTrack(""))); |
| 1682 EXPECT_TRUE_WAIT(FramesNotPending(kEndAudioFrameCount, kEndVideoFrameCount), |
| 1683 kMaxWaitForFramesMs); |
| 1684 } |
| 1685 |
1656 class IceServerParsingTest : public testing::Test { | 1686 class IceServerParsingTest : public testing::Test { |
1657 public: | 1687 public: |
1658 // Convenience for parsing a single URL. | 1688 // Convenience for parsing a single URL. |
1659 bool ParseUrl(const std::string& url) { | 1689 bool ParseUrl(const std::string& url) { |
1660 return ParseUrl(url, std::string(), std::string()); | 1690 return ParseUrl(url, std::string(), std::string()); |
1661 } | 1691 } |
1662 | 1692 |
1663 bool ParseUrl(const std::string& url, | 1693 bool ParseUrl(const std::string& url, |
1664 const std::string& username, | 1694 const std::string& username, |
1665 const std::string& password) { | 1695 const std::string& password) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1823 server.urls.push_back("stun:hostname"); | 1853 server.urls.push_back("stun:hostname"); |
1824 server.urls.push_back("turn:hostname"); | 1854 server.urls.push_back("turn:hostname"); |
1825 servers.push_back(server); | 1855 servers.push_back(server); |
1826 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_, | 1856 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_, |
1827 &turn_configurations_)); | 1857 &turn_configurations_)); |
1828 EXPECT_EQ(1U, stun_configurations_.size()); | 1858 EXPECT_EQ(1U, stun_configurations_.size()); |
1829 EXPECT_EQ(1U, turn_configurations_.size()); | 1859 EXPECT_EQ(1U, turn_configurations_.size()); |
1830 } | 1860 } |
1831 | 1861 |
1832 #endif // if !defined(THREAD_SANITIZER) | 1862 #endif // if !defined(THREAD_SANITIZER) |
OLD | NEW |