| 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; | |
| 100 static const int kMaxWaitForFramesMs = 10000; | 99 static const int kMaxWaitForFramesMs = 10000; |
| 101 static const int kEndAudioFrameCount = 3; | 100 static const int kEndAudioFrameCount = 3; |
| 102 static const int kEndVideoFrameCount = 3; | 101 static const int kEndVideoFrameCount = 3; |
| 103 | 102 |
| 104 static const char kStreamLabelBase[] = "stream_label"; | 103 static const char kStreamLabelBase[] = "stream_label"; |
| 105 static const char kVideoTrackLabelBase[] = "video_track"; | 104 static const char kVideoTrackLabelBase[] = "video_track"; |
| 106 static const char kAudioTrackLabelBase[] = "audio_track"; | 105 static const char kAudioTrackLabelBase[] = "audio_track"; |
| 107 static const char kDataChannelLabel[] = "data_channel"; | 106 static const char kDataChannelLabel[] = "data_channel"; |
| 108 | 107 |
| 109 // Disable for TSan v2, see | 108 // Disable for TSan v2, see |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 243 } |
| 245 | 244 |
| 246 void AddMediaStream(bool audio, bool video) { | 245 void AddMediaStream(bool audio, bool video) { |
| 247 std::string stream_label = | 246 std::string stream_label = |
| 248 kStreamLabelBase + | 247 kStreamLabelBase + |
| 249 rtc::ToString<int>(static_cast<int>(pc()->local_streams()->count())); | 248 rtc::ToString<int>(static_cast<int>(pc()->local_streams()->count())); |
| 250 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream = | 249 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream = |
| 251 peer_connection_factory_->CreateLocalMediaStream(stream_label); | 250 peer_connection_factory_->CreateLocalMediaStream(stream_label); |
| 252 | 251 |
| 253 if (audio && can_receive_audio()) { | 252 if (audio && can_receive_audio()) { |
| 254 stream->AddTrack(CreateLocalAudioTrack(stream_label)); | 253 FakeConstraints constraints; |
| 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); |
| 255 } | 265 } |
| 256 if (video && can_receive_video()) { | 266 if (video && can_receive_video()) { |
| 257 stream->AddTrack(CreateLocalVideoTrack(stream_label)); | 267 stream->AddTrack(CreateLocalVideoTrack(stream_label)); |
| 258 } | 268 } |
| 259 | 269 |
| 260 EXPECT_TRUE(pc()->AddStream(stream)); | 270 EXPECT_TRUE(pc()->AddStream(stream)); |
| 261 } | 271 } |
| 262 | 272 |
| 263 size_t NumberOfLocalMediaStreams() { return pc()->local_streams()->count(); } | 273 size_t NumberOfLocalMediaStreams() { return pc()->local_streams()->count(); } |
| 264 | 274 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 data_channel_ = data_channel; | 350 data_channel_ = data_channel; |
| 341 data_observer_.reset(new MockDataChannelObserver(data_channel)); | 351 data_observer_.reset(new MockDataChannelObserver(data_channel)); |
| 342 } | 352 } |
| 343 | 353 |
| 344 void CreateDataChannel() { | 354 void CreateDataChannel() { |
| 345 data_channel_ = pc()->CreateDataChannel(kDataChannelLabel, nullptr); | 355 data_channel_ = pc()->CreateDataChannel(kDataChannelLabel, nullptr); |
| 346 ASSERT_TRUE(data_channel_.get() != nullptr); | 356 ASSERT_TRUE(data_channel_.get() != nullptr); |
| 347 data_observer_.reset(new MockDataChannelObserver(data_channel_)); | 357 data_observer_.reset(new MockDataChannelObserver(data_channel_)); |
| 348 } | 358 } |
| 349 | 359 |
| 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 | |
| 379 DataChannelInterface* data_channel() { return data_channel_; } | 360 DataChannelInterface* data_channel() { return data_channel_; } |
| 380 const MockDataChannelObserver* data_observer() const { | 361 const MockDataChannelObserver* data_observer() const { |
| 381 return data_observer_.get(); | 362 return data_observer_.get(); |
| 382 } | 363 } |
| 383 | 364 |
| 384 webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); } | 365 webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); } |
| 385 | 366 |
| 386 void StopVideoCapturers() { | 367 void StopVideoCapturers() { |
| 387 for (std::vector<cricket::VideoCapturer*>::iterator it = | 368 for (std::vector<cricket::VideoCapturer*>::iterator it = |
| 388 video_capturers_.begin(); | 369 video_capturers_.begin(); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 return false; | 664 return false; |
| 684 } | 665 } |
| 685 if (options) { | 666 if (options) { |
| 686 peer_connection_factory_->SetOptions(*options); | 667 peer_connection_factory_->SetOptions(*options); |
| 687 } | 668 } |
| 688 peer_connection_ = CreatePeerConnection(allocator_factory_.get(), | 669 peer_connection_ = CreatePeerConnection(allocator_factory_.get(), |
| 689 constraints); | 670 constraints); |
| 690 return peer_connection_.get() != nullptr; | 671 return peer_connection_.get() != nullptr; |
| 691 } | 672 } |
| 692 | 673 |
| 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 |
| 693 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( | 690 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( |
| 694 webrtc::PortAllocatorFactoryInterface* factory, | 691 webrtc::PortAllocatorFactoryInterface* factory, |
| 695 const MediaConstraintsInterface* constraints) { | 692 const MediaConstraintsInterface* constraints) { |
| 696 // CreatePeerConnection with IceServers. | 693 // CreatePeerConnection with IceServers. |
| 697 webrtc::PeerConnectionInterface::IceServers ice_servers; | 694 webrtc::PeerConnectionInterface::IceServers ice_servers; |
| 698 webrtc::PeerConnectionInterface::IceServer ice_server; | 695 webrtc::PeerConnectionInterface::IceServer ice_server; |
| 699 ice_server.uri = "stun:stun.l.google.com:19302"; | 696 ice_server.uri = "stun:stun.l.google.com:19302"; |
| 700 ice_servers.push_back(ice_server); | 697 ice_servers.push_back(ice_server); |
| 701 | 698 |
| 702 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store( | 699 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store( |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 } | 950 } |
| 954 | 951 |
| 955 // This test sets up a call between two parties. Both parties send static | 952 // This test sets up a call between two parties. Both parties send static |
| 956 // frames to each other. Once the test is finished the number of sent frames | 953 // frames to each other. Once the test is finished the number of sent frames |
| 957 // is compared to the number of received frames. | 954 // is compared to the number of received frames. |
| 958 void LocalP2PTest() { | 955 void LocalP2PTest() { |
| 959 if (initiating_client_->NumberOfLocalMediaStreams() == 0) { | 956 if (initiating_client_->NumberOfLocalMediaStreams() == 0) { |
| 960 initiating_client_->AddMediaStream(true, true); | 957 initiating_client_->AddMediaStream(true, true); |
| 961 } | 958 } |
| 962 initiating_client_->Negotiate(); | 959 initiating_client_->Negotiate(); |
| 960 const int kMaxWaitForActivationMs = 5000; |
| 963 // 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 |
| 964 // would eat up 5 seconds. | 962 // would eat up 5 seconds. |
| 965 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); | 963 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); |
| 966 VerifySessionDescriptions(); | 964 VerifySessionDescriptions(); |
| 967 | 965 |
| 966 |
| 968 int audio_frame_count = kEndAudioFrameCount; | 967 int audio_frame_count = kEndAudioFrameCount; |
| 969 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly. | 968 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly. |
| 970 if (!initiating_client_->can_receive_audio() || | 969 if (!initiating_client_->can_receive_audio() || |
| 971 !receiving_client_->can_receive_audio()) { | 970 !receiving_client_->can_receive_audio()) { |
| 972 audio_frame_count = -1; | 971 audio_frame_count = -1; |
| 973 } | 972 } |
| 974 int video_frame_count = kEndVideoFrameCount; | 973 int video_frame_count = kEndVideoFrameCount; |
| 975 if (!initiating_client_->can_receive_video() || | 974 if (!initiating_client_->can_receive_video() || |
| 976 !receiving_client_->can_receive_video()) { | 975 !receiving_client_->can_receive_video()) { |
| 977 video_frame_count = -1; | 976 video_frame_count = -1; |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1567 // VideoDecoderFactory. | 1566 // VideoDecoderFactory. |
| 1568 // TODO(holmer): Disabled due to sometimes crashing on buildbots. | 1567 // TODO(holmer): Disabled due to sometimes crashing on buildbots. |
| 1569 // See issue webrtc/2378. | 1568 // See issue webrtc/2378. |
| 1570 TEST_F(JsepPeerConnectionP2PTestClient, | 1569 TEST_F(JsepPeerConnectionP2PTestClient, |
| 1571 DISABLED_LocalP2PTestWithVideoDecoderFactory) { | 1570 DISABLED_LocalP2PTestWithVideoDecoderFactory) { |
| 1572 ASSERT_TRUE(CreateTestClients()); | 1571 ASSERT_TRUE(CreateTestClients()); |
| 1573 EnableVideoDecoderFactory(); | 1572 EnableVideoDecoderFactory(); |
| 1574 LocalP2PTest(); | 1573 LocalP2PTest(); |
| 1575 } | 1574 } |
| 1576 | 1575 |
| 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 | |
| 1605 class IceServerParsingTest : public testing::Test { | 1576 class IceServerParsingTest : public testing::Test { |
| 1606 public: | 1577 public: |
| 1607 // Convenience for parsing a single URL. | 1578 // Convenience for parsing a single URL. |
| 1608 bool ParseUrl(const std::string& url) { | 1579 bool ParseUrl(const std::string& url) { |
| 1609 return ParseUrl(url, std::string(), std::string()); | 1580 return ParseUrl(url, std::string(), std::string()); |
| 1610 } | 1581 } |
| 1611 | 1582 |
| 1612 bool ParseUrl(const std::string& url, | 1583 bool ParseUrl(const std::string& url, |
| 1613 const std::string& username, | 1584 const std::string& username, |
| 1614 const std::string& password) { | 1585 const std::string& password) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1772 server.urls.push_back("stun:hostname"); | 1743 server.urls.push_back("stun:hostname"); |
| 1773 server.urls.push_back("turn:hostname"); | 1744 server.urls.push_back("turn:hostname"); |
| 1774 servers.push_back(server); | 1745 servers.push_back(server); |
| 1775 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_, | 1746 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_, |
| 1776 &turn_configurations_)); | 1747 &turn_configurations_)); |
| 1777 EXPECT_EQ(1U, stun_configurations_.size()); | 1748 EXPECT_EQ(1U, stun_configurations_.size()); |
| 1778 EXPECT_EQ(1U, turn_configurations_.size()); | 1749 EXPECT_EQ(1U, turn_configurations_.size()); |
| 1779 } | 1750 } |
| 1780 | 1751 |
| 1781 #endif // if !defined(THREAD_SANITIZER) | 1752 #endif // if !defined(THREAD_SANITIZER) |
| OLD | NEW |