OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <list> | 14 #include <list> |
15 #include <map> | 15 #include <map> |
16 #include <memory> | 16 #include <memory> |
17 #include <utility> | 17 #include <utility> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include "webrtc/api/dtmfsender.h" | 20 #include "webrtc/api/dtmfsender.h" |
21 #include "webrtc/api/fakemetricsobserver.h" | 21 #include "webrtc/api/fakemetricsobserver.h" |
22 #include "webrtc/api/localaudiosource.h" | 22 #include "webrtc/api/localaudiosource.h" |
23 #include "webrtc/api/mediastreaminterface.h" | 23 #include "webrtc/api/mediastreaminterface.h" |
24 #include "webrtc/api/peerconnection.h" | 24 #include "webrtc/api/peerconnection.h" |
25 #include "webrtc/api/peerconnectionfactory.h" | 25 #include "webrtc/api/peerconnectionfactory.h" |
26 #include "webrtc/api/peerconnectioninterface.h" | 26 #include "webrtc/api/peerconnectioninterface.h" |
27 #include "webrtc/api/test/fakeaudiocapturemodule.h" | 27 #include "webrtc/api/test/fakeaudiocapturemodule.h" |
28 #include "webrtc/api/test/fakeconstraints.h" | 28 #include "webrtc/api/test/fakeconstraints.h" |
29 #include "webrtc/api/test/fakedtlsidentitystore.h" | |
30 #include "webrtc/api/test/fakeperiodicvideocapturer.h" | 29 #include "webrtc/api/test/fakeperiodicvideocapturer.h" |
| 30 #include "webrtc/api/test/fakertccertificategenerator.h" |
31 #include "webrtc/api/test/fakevideotrackrenderer.h" | 31 #include "webrtc/api/test/fakevideotrackrenderer.h" |
32 #include "webrtc/api/test/mockpeerconnectionobservers.h" | 32 #include "webrtc/api/test/mockpeerconnectionobservers.h" |
33 #include "webrtc/base/gunit.h" | 33 #include "webrtc/base/gunit.h" |
34 #include "webrtc/base/physicalsocketserver.h" | 34 #include "webrtc/base/physicalsocketserver.h" |
35 #include "webrtc/base/ssladapter.h" | 35 #include "webrtc/base/ssladapter.h" |
36 #include "webrtc/base/sslstreamadapter.h" | 36 #include "webrtc/base/sslstreamadapter.h" |
37 #include "webrtc/base/thread.h" | 37 #include "webrtc/base/thread.h" |
38 #include "webrtc/base/virtualsocketserver.h" | 38 #include "webrtc/base/virtualsocketserver.h" |
39 #include "webrtc/media/engine/fakewebrtcvideoengine.h" | 39 #include "webrtc/media/engine/fakewebrtcvideoengine.h" |
40 #include "webrtc/p2p/base/fakeportallocator.h" | 40 #include "webrtc/p2p/base/fakeportallocator.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 }; | 147 }; |
148 | 148 |
149 class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, | 149 class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
150 public SignalingMessageReceiver, | 150 public SignalingMessageReceiver, |
151 public ObserverInterface { | 151 public ObserverInterface { |
152 public: | 152 public: |
153 static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore( | 153 static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore( |
154 const std::string& id, | 154 const std::string& id, |
155 const MediaConstraintsInterface* constraints, | 155 const MediaConstraintsInterface* constraints, |
156 const PeerConnectionFactory::Options* options, | 156 const PeerConnectionFactory::Options* options, |
157 std::unique_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store, | 157 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
158 bool prefer_constraint_apis, | 158 bool prefer_constraint_apis, |
159 rtc::Thread* network_thread, | 159 rtc::Thread* network_thread, |
160 rtc::Thread* worker_thread) { | 160 rtc::Thread* worker_thread) { |
161 PeerConnectionTestClient* client(new PeerConnectionTestClient(id)); | 161 PeerConnectionTestClient* client(new PeerConnectionTestClient(id)); |
162 if (!client->Init(constraints, options, std::move(dtls_identity_store), | 162 if (!client->Init(constraints, options, std::move(cert_generator), |
163 prefer_constraint_apis, network_thread, worker_thread)) { | 163 prefer_constraint_apis, network_thread, worker_thread)) { |
164 delete client; | 164 delete client; |
165 return nullptr; | 165 return nullptr; |
166 } | 166 } |
167 return client; | 167 return client; |
168 } | 168 } |
169 | 169 |
170 static PeerConnectionTestClient* CreateClient( | 170 static PeerConnectionTestClient* CreateClient( |
171 const std::string& id, | 171 const std::string& id, |
172 const MediaConstraintsInterface* constraints, | 172 const MediaConstraintsInterface* constraints, |
173 const PeerConnectionFactory::Options* options, | 173 const PeerConnectionFactory::Options* options, |
174 rtc::Thread* network_thread, | 174 rtc::Thread* network_thread, |
175 rtc::Thread* worker_thread) { | 175 rtc::Thread* worker_thread) { |
176 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store( | 176 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
177 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() | 177 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? |
178 : nullptr); | 178 new FakeRTCCertificateGenerator() : nullptr); |
179 | 179 |
180 return CreateClientWithDtlsIdentityStore( | 180 return CreateClientWithDtlsIdentityStore( |
181 id, constraints, options, std::move(dtls_identity_store), true, | 181 id, constraints, options, std::move(cert_generator), true, |
182 network_thread, worker_thread); | 182 network_thread, worker_thread); |
183 } | 183 } |
184 | 184 |
185 static PeerConnectionTestClient* CreateClientPreferNoConstraints( | 185 static PeerConnectionTestClient* CreateClientPreferNoConstraints( |
186 const std::string& id, | 186 const std::string& id, |
187 const PeerConnectionFactory::Options* options, | 187 const PeerConnectionFactory::Options* options, |
188 rtc::Thread* network_thread, | 188 rtc::Thread* network_thread, |
189 rtc::Thread* worker_thread) { | 189 rtc::Thread* worker_thread) { |
190 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store( | 190 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
191 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() | 191 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? |
192 : nullptr); | 192 new FakeRTCCertificateGenerator() : nullptr); |
193 | 193 |
194 return CreateClientWithDtlsIdentityStore( | 194 return CreateClientWithDtlsIdentityStore( |
195 id, nullptr, options, std::move(dtls_identity_store), false, | 195 id, nullptr, options, std::move(cert_generator), false, |
196 network_thread, worker_thread); | 196 network_thread, worker_thread); |
197 } | 197 } |
198 | 198 |
199 ~PeerConnectionTestClient() { | 199 ~PeerConnectionTestClient() { |
200 } | 200 } |
201 | 201 |
202 void Negotiate() { Negotiate(true, true); } | 202 void Negotiate() { Negotiate(true, true); } |
203 | 203 |
204 void Negotiate(bool audio, bool video) { | 204 void Negotiate(bool audio, bool video) { |
205 std::unique_ptr<SessionDescriptionInterface> offer; | 205 std::unique_ptr<SessionDescriptionInterface> offer; |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 private: | 803 private: |
804 bool completed_; | 804 bool completed_; |
805 std::vector<std::string> tones_; | 805 std::vector<std::string> tones_; |
806 }; | 806 }; |
807 | 807 |
808 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {} | 808 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {} |
809 | 809 |
810 bool Init( | 810 bool Init( |
811 const MediaConstraintsInterface* constraints, | 811 const MediaConstraintsInterface* constraints, |
812 const PeerConnectionFactory::Options* options, | 812 const PeerConnectionFactory::Options* options, |
813 std::unique_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store, | 813 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
814 bool prefer_constraint_apis, | 814 bool prefer_constraint_apis, |
815 rtc::Thread* network_thread, | 815 rtc::Thread* network_thread, |
816 rtc::Thread* worker_thread) { | 816 rtc::Thread* worker_thread) { |
817 EXPECT_TRUE(!peer_connection_); | 817 EXPECT_TRUE(!peer_connection_); |
818 EXPECT_TRUE(!peer_connection_factory_); | 818 EXPECT_TRUE(!peer_connection_factory_); |
819 if (!prefer_constraint_apis) { | 819 if (!prefer_constraint_apis) { |
820 EXPECT_TRUE(!constraints); | 820 EXPECT_TRUE(!constraints); |
821 } | 821 } |
822 prefer_constraint_apis_ = prefer_constraint_apis; | 822 prefer_constraint_apis_ = prefer_constraint_apis; |
823 | 823 |
(...skipping 11 matching lines...) Expand all Loading... |
835 network_thread, worker_thread, signaling_thread, | 835 network_thread, worker_thread, signaling_thread, |
836 fake_audio_capture_module_, fake_video_encoder_factory_, | 836 fake_audio_capture_module_, fake_video_encoder_factory_, |
837 fake_video_decoder_factory_); | 837 fake_video_decoder_factory_); |
838 if (!peer_connection_factory_) { | 838 if (!peer_connection_factory_) { |
839 return false; | 839 return false; |
840 } | 840 } |
841 if (options) { | 841 if (options) { |
842 peer_connection_factory_->SetOptions(*options); | 842 peer_connection_factory_->SetOptions(*options); |
843 } | 843 } |
844 peer_connection_ = CreatePeerConnection( | 844 peer_connection_ = CreatePeerConnection( |
845 std::move(port_allocator), constraints, std::move(dtls_identity_store)); | 845 std::move(port_allocator), constraints, std::move(cert_generator)); |
846 return peer_connection_.get() != nullptr; | 846 return peer_connection_.get() != nullptr; |
847 } | 847 } |
848 | 848 |
849 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( | 849 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( |
850 std::unique_ptr<cricket::PortAllocator> port_allocator, | 850 std::unique_ptr<cricket::PortAllocator> port_allocator, |
851 const MediaConstraintsInterface* constraints, | 851 const MediaConstraintsInterface* constraints, |
852 std::unique_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { | 852 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) { |
853 // CreatePeerConnection with RTCConfiguration. | 853 // CreatePeerConnection with RTCConfiguration. |
854 webrtc::PeerConnectionInterface::RTCConfiguration config; | 854 webrtc::PeerConnectionInterface::RTCConfiguration config; |
855 webrtc::PeerConnectionInterface::IceServer ice_server; | 855 webrtc::PeerConnectionInterface::IceServer ice_server; |
856 ice_server.uri = "stun:stun.l.google.com:19302"; | 856 ice_server.uri = "stun:stun.l.google.com:19302"; |
857 config.servers.push_back(ice_server); | 857 config.servers.push_back(ice_server); |
858 | 858 |
859 return peer_connection_factory_->CreatePeerConnectionWithStore( | 859 return peer_connection_factory_->CreatePeerConnection( |
860 config, constraints, std::move(port_allocator), | 860 config, constraints, std::move(port_allocator), |
861 std::move(dtls_identity_store), this); | 861 std::move(cert_generator), this); |
862 } | 862 } |
863 | 863 |
864 void HandleIncomingOffer(const std::string& msg) { | 864 void HandleIncomingOffer(const std::string& msg) { |
865 LOG(INFO) << id_ << "HandleIncomingOffer "; | 865 LOG(INFO) << id_ << "HandleIncomingOffer "; |
866 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) { | 866 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) { |
867 // If we are not sending any streams ourselves it is time to add some. | 867 // If we are not sending any streams ourselves it is time to add some. |
868 AddMediaStream(true, true); | 868 AddMediaStream(true, true); |
869 } | 869 } |
870 std::unique_ptr<SessionDescriptionInterface> desc( | 870 std::unique_ptr<SessionDescriptionInterface> desc( |
871 webrtc::CreateSessionDescription("offer", msg, nullptr)); | 871 webrtc::CreateSessionDescription("offer", msg, nullptr)); |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); | 1259 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
1260 LocalP2PTest(); | 1260 LocalP2PTest(); |
1261 VerifyRenderedSize(640, 480); | 1261 VerifyRenderedSize(640, 480); |
1262 } | 1262 } |
1263 | 1263 |
1264 PeerConnectionTestClient* CreateDtlsClientWithAlternateKey() { | 1264 PeerConnectionTestClient* CreateDtlsClientWithAlternateKey() { |
1265 FakeConstraints setup_constraints; | 1265 FakeConstraints setup_constraints; |
1266 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, | 1266 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
1267 true); | 1267 true); |
1268 | 1268 |
1269 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store( | 1269 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
1270 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() | 1270 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? |
1271 : nullptr); | 1271 new FakeRTCCertificateGenerator() : nullptr); |
1272 dtls_identity_store->use_alternate_key(); | 1272 cert_generator->use_alternate_key(); |
1273 | 1273 |
1274 // Make sure the new client is using a different certificate. | 1274 // Make sure the new client is using a different certificate. |
1275 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore( | 1275 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore( |
1276 "New Peer: ", &setup_constraints, nullptr, | 1276 "New Peer: ", &setup_constraints, nullptr, |
1277 std::move(dtls_identity_store), prefer_constraint_apis_, | 1277 std::move(cert_generator), prefer_constraint_apis_, |
1278 network_thread_.get(), worker_thread_.get()); | 1278 network_thread_.get(), worker_thread_.get()); |
1279 } | 1279 } |
1280 | 1280 |
1281 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { | 1281 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { |
1282 // Messages may get lost on the unreliable DataChannel, so we send multiple | 1282 // Messages may get lost on the unreliable DataChannel, so we send multiple |
1283 // times to avoid test flakiness. | 1283 // times to avoid test flakiness. |
1284 static const size_t kSendAttempts = 5; | 1284 static const size_t kSendAttempts = 5; |
1285 | 1285 |
1286 for (size_t i = 0; i < kSendAttempts; ++i) { | 1286 for (size_t i = 0; i < kSendAttempts; ++i) { |
1287 dc->Send(DataBuffer(data)); | 1287 dc->Send(DataBuffer(data)); |
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2214 server.urls.push_back("turn:hostname2"); | 2214 server.urls.push_back("turn:hostname2"); |
2215 servers.push_back(server); | 2215 servers.push_back(server); |
2216 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); | 2216 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); |
2217 EXPECT_EQ(2U, turn_servers_.size()); | 2217 EXPECT_EQ(2U, turn_servers_.size()); |
2218 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); | 2218 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); |
2219 } | 2219 } |
2220 | 2220 |
2221 #endif // if !defined(THREAD_SANITIZER) | 2221 #endif // if !defined(THREAD_SANITIZER) |
2222 | 2222 |
2223 } // namespace | 2223 } // namespace |
OLD | NEW |