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 10 matching lines...) Expand all Loading... |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #include <string> | 28 #include <string> |
29 | 29 |
30 #include "talk/app/webrtc/audiotrack.h" | 30 #include "talk/app/webrtc/audiotrack.h" |
31 #include "talk/app/webrtc/fakeportallocatorfactory.h" | |
32 #include "talk/app/webrtc/jsepsessiondescription.h" | 31 #include "talk/app/webrtc/jsepsessiondescription.h" |
33 #include "talk/app/webrtc/mediastream.h" | 32 #include "talk/app/webrtc/mediastream.h" |
34 #include "talk/app/webrtc/mediastreaminterface.h" | 33 #include "talk/app/webrtc/mediastreaminterface.h" |
35 #include "talk/app/webrtc/peerconnection.h" | 34 #include "talk/app/webrtc/peerconnection.h" |
36 #include "talk/app/webrtc/peerconnectioninterface.h" | 35 #include "talk/app/webrtc/peerconnectioninterface.h" |
37 #include "talk/app/webrtc/rtpreceiverinterface.h" | 36 #include "talk/app/webrtc/rtpreceiverinterface.h" |
38 #include "talk/app/webrtc/rtpsenderinterface.h" | 37 #include "talk/app/webrtc/rtpsenderinterface.h" |
39 #include "talk/app/webrtc/streamcollection.h" | 38 #include "talk/app/webrtc/streamcollection.h" |
40 #include "talk/app/webrtc/test/fakeconstraints.h" | 39 #include "talk/app/webrtc/test/fakeconstraints.h" |
41 #include "talk/app/webrtc/test/fakedtlsidentitystore.h" | 40 #include "talk/app/webrtc/test/fakedtlsidentitystore.h" |
42 #include "talk/app/webrtc/test/mockpeerconnectionobservers.h" | 41 #include "talk/app/webrtc/test/mockpeerconnectionobservers.h" |
43 #include "talk/app/webrtc/test/testsdpstrings.h" | 42 #include "talk/app/webrtc/test/testsdpstrings.h" |
44 #include "talk/app/webrtc/videosource.h" | 43 #include "talk/app/webrtc/videosource.h" |
45 #include "talk/app/webrtc/videotrack.h" | 44 #include "talk/app/webrtc/videotrack.h" |
46 #include "talk/media/base/fakevideocapturer.h" | 45 #include "talk/media/base/fakevideocapturer.h" |
47 #include "talk/media/sctp/sctpdataengine.h" | 46 #include "talk/media/sctp/sctpdataengine.h" |
48 #include "talk/session/media/mediasession.h" | 47 #include "talk/session/media/mediasession.h" |
49 #include "webrtc/base/gunit.h" | 48 #include "webrtc/base/gunit.h" |
50 #include "webrtc/base/scoped_ptr.h" | 49 #include "webrtc/base/scoped_ptr.h" |
51 #include "webrtc/base/ssladapter.h" | 50 #include "webrtc/base/ssladapter.h" |
52 #include "webrtc/base/sslstreamadapter.h" | 51 #include "webrtc/base/sslstreamadapter.h" |
53 #include "webrtc/base/stringutils.h" | 52 #include "webrtc/base/stringutils.h" |
54 #include "webrtc/base/thread.h" | 53 #include "webrtc/base/thread.h" |
| 54 #include "webrtc/p2p/client/fakeportallocator.h" |
55 | 55 |
56 static const char kStreamLabel1[] = "local_stream_1"; | 56 static const char kStreamLabel1[] = "local_stream_1"; |
57 static const char kStreamLabel2[] = "local_stream_2"; | 57 static const char kStreamLabel2[] = "local_stream_2"; |
58 static const char kStreamLabel3[] = "local_stream_3"; | 58 static const char kStreamLabel3[] = "local_stream_3"; |
59 static const int kDefaultStunPort = 3478; | 59 static const int kDefaultStunPort = 3478; |
60 static const char kStunAddressOnly[] = "stun:address"; | 60 static const char kStunAddressOnly[] = "stun:address"; |
61 static const char kStunInvalidPort[] = "stun:address:-1"; | 61 static const char kStunInvalidPort[] = "stun:address:-1"; |
62 static const char kStunAddressPortAndMore1[] = "stun:address:port:more"; | 62 static const char kStunAddressPortAndMore1[] = "stun:address:port:more"; |
63 static const char kStunAddressPortAndMore2[] = "stun:address:port more"; | 63 static const char kStunAddressPortAndMore2[] = "stun:address:port more"; |
64 static const char kTurnIceServerUri[] = "turn:user@turn.example.org"; | 64 static const char kTurnIceServerUri[] = "turn:user@turn.example.org"; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 251 } |
252 | 252 |
253 using rtc::scoped_ptr; | 253 using rtc::scoped_ptr; |
254 using rtc::scoped_refptr; | 254 using rtc::scoped_refptr; |
255 using webrtc::AudioSourceInterface; | 255 using webrtc::AudioSourceInterface; |
256 using webrtc::AudioTrack; | 256 using webrtc::AudioTrack; |
257 using webrtc::AudioTrackInterface; | 257 using webrtc::AudioTrackInterface; |
258 using webrtc::DataBuffer; | 258 using webrtc::DataBuffer; |
259 using webrtc::DataChannelInterface; | 259 using webrtc::DataChannelInterface; |
260 using webrtc::FakeConstraints; | 260 using webrtc::FakeConstraints; |
261 using webrtc::FakePortAllocatorFactory; | |
262 using webrtc::IceCandidateInterface; | 261 using webrtc::IceCandidateInterface; |
263 using webrtc::MediaConstraintsInterface; | 262 using webrtc::MediaConstraintsInterface; |
264 using webrtc::MediaStream; | 263 using webrtc::MediaStream; |
265 using webrtc::MediaStreamInterface; | 264 using webrtc::MediaStreamInterface; |
266 using webrtc::MediaStreamTrackInterface; | 265 using webrtc::MediaStreamTrackInterface; |
267 using webrtc::MockCreateSessionDescriptionObserver; | 266 using webrtc::MockCreateSessionDescriptionObserver; |
268 using webrtc::MockDataChannelObserver; | 267 using webrtc::MockDataChannelObserver; |
269 using webrtc::MockSetSessionDescriptionObserver; | 268 using webrtc::MockSetSessionDescriptionObserver; |
270 using webrtc::MockStatsObserver; | 269 using webrtc::MockStatsObserver; |
271 using webrtc::PeerConnectionInterface; | 270 using webrtc::PeerConnectionInterface; |
272 using webrtc::PeerConnectionObserver; | 271 using webrtc::PeerConnectionObserver; |
273 using webrtc::PortAllocatorFactoryInterface; | |
274 using webrtc::RtpReceiverInterface; | 272 using webrtc::RtpReceiverInterface; |
275 using webrtc::RtpSenderInterface; | 273 using webrtc::RtpSenderInterface; |
276 using webrtc::SdpParseError; | 274 using webrtc::SdpParseError; |
277 using webrtc::SessionDescriptionInterface; | 275 using webrtc::SessionDescriptionInterface; |
278 using webrtc::StreamCollection; | 276 using webrtc::StreamCollection; |
279 using webrtc::StreamCollectionInterface; | 277 using webrtc::StreamCollectionInterface; |
280 using webrtc::VideoSourceInterface; | 278 using webrtc::VideoSourceInterface; |
281 using webrtc::VideoTrack; | 279 using webrtc::VideoTrack; |
282 using webrtc::VideoTrackInterface; | 280 using webrtc::VideoTrackInterface; |
283 | 281 |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 CreatePeerConnection("", "", NULL); | 524 CreatePeerConnection("", "", NULL); |
527 } | 525 } |
528 | 526 |
529 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) { | 527 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) { |
530 CreatePeerConnection("", "", constraints); | 528 CreatePeerConnection("", "", constraints); |
531 } | 529 } |
532 | 530 |
533 void CreatePeerConnection(const std::string& uri, | 531 void CreatePeerConnection(const std::string& uri, |
534 const std::string& password, | 532 const std::string& password, |
535 webrtc::MediaConstraintsInterface* constraints) { | 533 webrtc::MediaConstraintsInterface* constraints) { |
| 534 PeerConnectionInterface::RTCConfiguration config; |
536 PeerConnectionInterface::IceServer server; | 535 PeerConnectionInterface::IceServer server; |
537 PeerConnectionInterface::IceServers servers; | |
538 if (!uri.empty()) { | 536 if (!uri.empty()) { |
539 server.uri = uri; | 537 server.uri = uri; |
540 server.password = password; | 538 server.password = password; |
541 servers.push_back(server); | 539 config.servers.push_back(server); |
542 } | 540 } |
543 | 541 |
544 port_allocator_factory_ = FakePortAllocatorFactory::Create(); | 542 rtc::scoped_ptr<cricket::FakePortAllocator> port_allocator( |
| 543 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
| 544 port_allocator_ = port_allocator.get(); |
545 | 545 |
546 // DTLS does not work in a loopback call, so is disabled for most of the | 546 // DTLS does not work in a loopback call, so is disabled for most of the |
547 // tests in this file. We only create a FakeIdentityService if the test | 547 // tests in this file. We only create a FakeIdentityService if the test |
548 // explicitly sets the constraint. | 548 // explicitly sets the constraint. |
549 FakeConstraints default_constraints; | 549 FakeConstraints default_constraints; |
550 if (!constraints) { | 550 if (!constraints) { |
551 constraints = &default_constraints; | 551 constraints = &default_constraints; |
552 | 552 |
553 default_constraints.AddMandatory( | 553 default_constraints.AddMandatory( |
554 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false); | 554 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false); |
555 } | 555 } |
556 | 556 |
557 scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store; | 557 scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store; |
558 bool dtls; | 558 bool dtls; |
559 if (FindConstraint(constraints, | 559 if (FindConstraint(constraints, |
560 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | 560 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
561 &dtls, | 561 &dtls, |
562 nullptr) && dtls) { | 562 nullptr) && dtls) { |
563 dtls_identity_store.reset(new FakeDtlsIdentityStore()); | 563 dtls_identity_store.reset(new FakeDtlsIdentityStore()); |
564 } | 564 } |
565 pc_ = pc_factory_->CreatePeerConnection(servers, constraints, | 565 pc_ = pc_factory_->CreatePeerConnection( |
566 port_allocator_factory_.get(), | 566 config, constraints, std::move(port_allocator), |
567 dtls_identity_store.Pass(), | 567 std::move(dtls_identity_store), &observer_); |
568 &observer_); | |
569 ASSERT_TRUE(pc_.get() != NULL); | 568 ASSERT_TRUE(pc_.get() != NULL); |
570 observer_.SetPeerConnectionInterface(pc_.get()); | 569 observer_.SetPeerConnectionInterface(pc_.get()); |
571 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); | 570 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); |
572 } | 571 } |
573 | 572 |
574 void CreatePeerConnectionExpectFail(const std::string& uri) { | 573 void CreatePeerConnectionExpectFail(const std::string& uri) { |
| 574 PeerConnectionInterface::RTCConfiguration config; |
575 PeerConnectionInterface::IceServer server; | 575 PeerConnectionInterface::IceServer server; |
576 PeerConnectionInterface::IceServers servers; | |
577 server.uri = uri; | 576 server.uri = uri; |
578 servers.push_back(server); | 577 config.servers.push_back(server); |
579 | 578 |
580 scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store; | |
581 port_allocator_factory_ = FakePortAllocatorFactory::Create(); | |
582 scoped_refptr<PeerConnectionInterface> pc; | 579 scoped_refptr<PeerConnectionInterface> pc; |
583 pc = pc_factory_->CreatePeerConnection( | 580 pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr, |
584 servers, nullptr, port_allocator_factory_.get(), | 581 &observer_); |
585 dtls_identity_store.Pass(), &observer_); | 582 EXPECT_EQ(nullptr, pc); |
586 ASSERT_EQ(nullptr, pc); | |
587 } | 583 } |
588 | 584 |
589 void CreatePeerConnectionWithDifferentConfigurations() { | 585 void CreatePeerConnectionWithDifferentConfigurations() { |
590 CreatePeerConnection(kStunAddressOnly, "", NULL); | 586 CreatePeerConnection(kStunAddressOnly, "", NULL); |
591 EXPECT_EQ(1u, port_allocator_factory_->stun_configs().size()); | 587 EXPECT_EQ(1u, port_allocator_->stun_servers().size()); |
592 EXPECT_EQ(0u, port_allocator_factory_->turn_configs().size()); | 588 EXPECT_EQ(0u, port_allocator_->turn_servers().size()); |
593 EXPECT_EQ("address", | 589 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname()); |
594 port_allocator_factory_->stun_configs()[0].server.hostname()); | |
595 EXPECT_EQ(kDefaultStunPort, | 590 EXPECT_EQ(kDefaultStunPort, |
596 port_allocator_factory_->stun_configs()[0].server.port()); | 591 port_allocator_->stun_servers().begin()->port()); |
597 | 592 |
598 CreatePeerConnectionExpectFail(kStunInvalidPort); | 593 CreatePeerConnectionExpectFail(kStunInvalidPort); |
599 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1); | 594 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1); |
600 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2); | 595 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2); |
601 | 596 |
602 CreatePeerConnection(kTurnIceServerUri, kTurnPassword, NULL); | 597 CreatePeerConnection(kTurnIceServerUri, kTurnPassword, NULL); |
603 EXPECT_EQ(0u, port_allocator_factory_->stun_configs().size()); | 598 EXPECT_EQ(0u, port_allocator_->stun_servers().size()); |
604 EXPECT_EQ(1u, port_allocator_factory_->turn_configs().size()); | 599 EXPECT_EQ(1u, port_allocator_->turn_servers().size()); |
605 EXPECT_EQ(kTurnUsername, | 600 EXPECT_EQ(kTurnUsername, |
606 port_allocator_factory_->turn_configs()[0].username); | 601 port_allocator_->turn_servers()[0].credentials.username); |
607 EXPECT_EQ(kTurnPassword, | 602 EXPECT_EQ(kTurnPassword, |
608 port_allocator_factory_->turn_configs()[0].password); | 603 port_allocator_->turn_servers()[0].credentials.password); |
609 EXPECT_EQ(kTurnHostname, | 604 EXPECT_EQ(kTurnHostname, |
610 port_allocator_factory_->turn_configs()[0].server.hostname()); | 605 port_allocator_->turn_servers()[0].ports[0].address.hostname()); |
611 } | 606 } |
612 | 607 |
613 void ReleasePeerConnection() { | 608 void ReleasePeerConnection() { |
614 pc_ = NULL; | 609 pc_ = NULL; |
615 observer_.SetPeerConnectionInterface(NULL); | 610 observer_.SetPeerConnectionInterface(NULL); |
616 } | 611 } |
617 | 612 |
618 void AddVideoStream(const std::string& label) { | 613 void AddVideoStream(const std::string& label) { |
619 // Create a local stream. | 614 // Create a local stream. |
620 scoped_refptr<MediaStreamInterface> stream( | 615 scoped_refptr<MediaStreamInterface> stream( |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 ASSERT_TRUE(stream->AddTrack(audio_track)); | 914 ASSERT_TRUE(stream->AddTrack(audio_track)); |
920 } | 915 } |
921 | 916 |
922 void AddVideoTrack(const std::string& track_id, | 917 void AddVideoTrack(const std::string& track_id, |
923 MediaStreamInterface* stream) { | 918 MediaStreamInterface* stream) { |
924 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( | 919 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( |
925 webrtc::VideoTrack::Create(track_id, nullptr)); | 920 webrtc::VideoTrack::Create(track_id, nullptr)); |
926 ASSERT_TRUE(stream->AddTrack(video_track)); | 921 ASSERT_TRUE(stream->AddTrack(video_track)); |
927 } | 922 } |
928 | 923 |
929 scoped_refptr<FakePortAllocatorFactory> port_allocator_factory_; | 924 cricket::FakePortAllocator* port_allocator_ = nullptr; |
930 scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; | 925 scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; |
931 scoped_refptr<PeerConnectionInterface> pc_; | 926 scoped_refptr<PeerConnectionInterface> pc_; |
932 MockPeerConnectionObserver observer_; | 927 MockPeerConnectionObserver observer_; |
933 rtc::scoped_refptr<StreamCollection> reference_collection_; | 928 rtc::scoped_refptr<StreamCollection> reference_collection_; |
934 }; | 929 }; |
935 | 930 |
936 TEST_F(PeerConnectionInterfaceTest, | 931 TEST_F(PeerConnectionInterfaceTest, |
937 CreatePeerConnectionWithDifferentConfigurations) { | 932 CreatePeerConnectionWithDifferentConfigurations) { |
938 CreatePeerConnectionWithDifferentConfigurations(); | 933 CreatePeerConnectionWithDifferentConfigurations(); |
939 } | 934 } |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1664 // PortAllocator. | 1659 // PortAllocator. |
1665 TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) { | 1660 TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) { |
1666 CreatePeerConnection(); | 1661 CreatePeerConnection(); |
1667 | 1662 |
1668 PeerConnectionInterface::RTCConfiguration config; | 1663 PeerConnectionInterface::RTCConfiguration config; |
1669 PeerConnectionInterface::IceServer server; | 1664 PeerConnectionInterface::IceServer server; |
1670 server.uri = "stun:test_hostname"; | 1665 server.uri = "stun:test_hostname"; |
1671 config.servers.push_back(server); | 1666 config.servers.push_back(server); |
1672 EXPECT_TRUE(pc_->SetConfiguration(config)); | 1667 EXPECT_TRUE(pc_->SetConfiguration(config)); |
1673 | 1668 |
1674 cricket::FakePortAllocator* allocator = | 1669 EXPECT_EQ(1u, port_allocator_->stun_servers().size()); |
1675 port_allocator_factory_->last_created_allocator(); | 1670 EXPECT_EQ("test_hostname", |
1676 EXPECT_EQ(1u, allocator->stun_servers().size()); | 1671 port_allocator_->stun_servers().begin()->hostname()); |
1677 EXPECT_EQ("test_hostname", allocator->stun_servers().begin()->hostname()); | |
1678 } | 1672 } |
1679 | 1673 |
1680 // Test that PeerConnection::Close changes the states to closed and all remote | 1674 // Test that PeerConnection::Close changes the states to closed and all remote |
1681 // tracks change state to ended. | 1675 // tracks change state to ended. |
1682 TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) { | 1676 TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) { |
1683 // Initialize a PeerConnection and negotiate local and remote session | 1677 // Initialize a PeerConnection and negotiate local and remote session |
1684 // description. | 1678 // description. |
1685 InitiateCall(); | 1679 InitiateCall(); |
1686 ASSERT_EQ(1u, pc_->local_streams()->count()); | 1680 ASSERT_EQ(1u, pc_->local_streams()->count()); |
1687 ASSERT_EQ(1u, pc_->remote_streams()->count()); | 1681 ASSERT_EQ(1u, pc_->remote_streams()->count()); |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2349 FakeConstraints updated_answer_c; | 2343 FakeConstraints updated_answer_c; |
2350 answer_c.SetMandatoryReceiveAudio(false); | 2344 answer_c.SetMandatoryReceiveAudio(false); |
2351 answer_c.SetMandatoryReceiveVideo(false); | 2345 answer_c.SetMandatoryReceiveVideo(false); |
2352 | 2346 |
2353 cricket::MediaSessionOptions updated_answer_options; | 2347 cricket::MediaSessionOptions updated_answer_options; |
2354 EXPECT_TRUE( | 2348 EXPECT_TRUE( |
2355 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); | 2349 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); |
2356 EXPECT_TRUE(updated_answer_options.has_audio()); | 2350 EXPECT_TRUE(updated_answer_options.has_audio()); |
2357 EXPECT_TRUE(updated_answer_options.has_video()); | 2351 EXPECT_TRUE(updated_answer_options.has_video()); |
2358 } | 2352 } |
OLD | NEW |