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 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store, | 157 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store, |
158 bool prefer_constraint_apis, | 158 bool prefer_constraint_apis) { |
159 rtc::Thread* worker_thread) { | |
160 PeerConnectionTestClient* client(new PeerConnectionTestClient(id)); | 159 PeerConnectionTestClient* client(new PeerConnectionTestClient(id)); |
161 if (!client->Init(constraints, options, std::move(dtls_identity_store), | 160 if (!client->Init(constraints, options, std::move(dtls_identity_store), |
162 prefer_constraint_apis, worker_thread)) { | 161 prefer_constraint_apis)) { |
163 delete client; | 162 delete client; |
164 return nullptr; | 163 return nullptr; |
165 } | 164 } |
166 return client; | 165 return client; |
167 } | 166 } |
168 | 167 |
169 static PeerConnectionTestClient* CreateClient( | 168 static PeerConnectionTestClient* CreateClient( |
170 const std::string& id, | 169 const std::string& id, |
171 const MediaConstraintsInterface* constraints, | 170 const MediaConstraintsInterface* constraints, |
172 const PeerConnectionFactory::Options* options, | 171 const PeerConnectionFactory::Options* options) { |
173 rtc::Thread* worker_thread) { | |
174 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store( | 172 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store( |
175 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() | 173 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() |
176 : nullptr); | 174 : nullptr); |
177 | 175 |
178 return CreateClientWithDtlsIdentityStore(id, constraints, options, | 176 return CreateClientWithDtlsIdentityStore( |
179 std::move(dtls_identity_store), | 177 id, constraints, options, std::move(dtls_identity_store), true); |
180 true, worker_thread); | |
181 } | 178 } |
182 | 179 |
183 static PeerConnectionTestClient* CreateClientPreferNoConstraints( | 180 static PeerConnectionTestClient* CreateClientPreferNoConstraints( |
184 const std::string& id, | 181 const std::string& id, |
185 const PeerConnectionFactory::Options* options, | 182 const PeerConnectionFactory::Options* options) { |
186 rtc::Thread* worker_thread) { | |
187 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store( | 183 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store( |
188 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() | 184 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() |
189 : nullptr); | 185 : nullptr); |
190 | 186 |
191 return CreateClientWithDtlsIdentityStore(id, nullptr, options, | 187 return CreateClientWithDtlsIdentityStore( |
192 std::move(dtls_identity_store), | 188 id, nullptr, options, std::move(dtls_identity_store), false); |
193 false, worker_thread); | |
194 } | 189 } |
195 | 190 |
196 ~PeerConnectionTestClient() { | 191 ~PeerConnectionTestClient() { |
197 } | 192 } |
198 | 193 |
199 void Negotiate() { Negotiate(true, true); } | 194 void Negotiate() { Negotiate(true, true); } |
200 | 195 |
201 void Negotiate(bool audio, bool video) { | 196 void Negotiate(bool audio, bool video) { |
202 rtc::scoped_ptr<SessionDescriptionInterface> offer; | 197 rtc::scoped_ptr<SessionDescriptionInterface> offer; |
203 ASSERT_TRUE(DoCreateOffer(&offer)); | 198 ASSERT_TRUE(DoCreateOffer(&offer)); |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 bool completed_; | 793 bool completed_; |
799 std::vector<std::string> tones_; | 794 std::vector<std::string> tones_; |
800 }; | 795 }; |
801 | 796 |
802 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {} | 797 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {} |
803 | 798 |
804 bool Init( | 799 bool Init( |
805 const MediaConstraintsInterface* constraints, | 800 const MediaConstraintsInterface* constraints, |
806 const PeerConnectionFactory::Options* options, | 801 const PeerConnectionFactory::Options* options, |
807 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store, | 802 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store, |
808 bool prefer_constraint_apis, | 803 bool prefer_constraint_apis) { |
809 rtc::Thread* worker_thread) { | |
810 EXPECT_TRUE(!peer_connection_); | 804 EXPECT_TRUE(!peer_connection_); |
811 EXPECT_TRUE(!peer_connection_factory_); | 805 EXPECT_TRUE(!peer_connection_factory_); |
812 if (!prefer_constraint_apis) { | 806 if (!prefer_constraint_apis) { |
813 EXPECT_TRUE(!constraints); | 807 EXPECT_TRUE(!constraints); |
814 } | 808 } |
815 prefer_constraint_apis_ = prefer_constraint_apis; | 809 prefer_constraint_apis_ = prefer_constraint_apis; |
816 | 810 |
817 rtc::scoped_ptr<cricket::PortAllocator> port_allocator( | 811 rtc::scoped_ptr<cricket::PortAllocator> port_allocator( |
818 new cricket::FakePortAllocator(worker_thread, nullptr)); | 812 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
819 fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); | 813 fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); |
820 | 814 |
821 if (fake_audio_capture_module_ == nullptr) { | 815 if (fake_audio_capture_module_ == nullptr) { |
822 return false; | 816 return false; |
823 } | 817 } |
824 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory(); | 818 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory(); |
825 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory(); | 819 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory(); |
826 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( | 820 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( |
827 worker_thread, rtc::Thread::Current(), fake_audio_capture_module_, | 821 rtc::Thread::Current(), rtc::Thread::Current(), |
828 fake_video_encoder_factory_, fake_video_decoder_factory_); | 822 fake_audio_capture_module_, fake_video_encoder_factory_, |
| 823 fake_video_decoder_factory_); |
829 if (!peer_connection_factory_) { | 824 if (!peer_connection_factory_) { |
830 return false; | 825 return false; |
831 } | 826 } |
832 if (options) { | 827 if (options) { |
833 peer_connection_factory_->SetOptions(*options); | 828 peer_connection_factory_->SetOptions(*options); |
834 } | 829 } |
835 peer_connection_ = CreatePeerConnection( | 830 peer_connection_ = CreatePeerConnection( |
836 std::move(port_allocator), constraints, std::move(dtls_identity_store)); | 831 std::move(port_allocator), constraints, std::move(dtls_identity_store)); |
837 return peer_connection_.get() != nullptr; | 832 return peer_connection_.get() != nullptr; |
838 } | 833 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 | 1012 |
1018 rtc::scoped_refptr<DataChannelInterface> data_channel_; | 1013 rtc::scoped_refptr<DataChannelInterface> data_channel_; |
1019 rtc::scoped_ptr<MockDataChannelObserver> data_observer_; | 1014 rtc::scoped_ptr<MockDataChannelObserver> data_observer_; |
1020 }; | 1015 }; |
1021 | 1016 |
1022 class P2PTestConductor : public testing::Test { | 1017 class P2PTestConductor : public testing::Test { |
1023 public: | 1018 public: |
1024 P2PTestConductor() | 1019 P2PTestConductor() |
1025 : pss_(new rtc::PhysicalSocketServer), | 1020 : pss_(new rtc::PhysicalSocketServer), |
1026 ss_(new rtc::VirtualSocketServer(pss_.get())), | 1021 ss_(new rtc::VirtualSocketServer(pss_.get())), |
1027 ss_scope_(ss_.get()) { | 1022 ss_scope_(ss_.get()) {} |
1028 RTC_CHECK(worker_thread_.Start()); | |
1029 } | |
1030 | 1023 |
1031 bool SessionActive() { | 1024 bool SessionActive() { |
1032 return initiating_client_->SessionActive() && | 1025 return initiating_client_->SessionActive() && |
1033 receiving_client_->SessionActive(); | 1026 receiving_client_->SessionActive(); |
1034 } | 1027 } |
1035 | 1028 |
1036 // Return true if the number of frames provided have been received | 1029 // Return true if the number of frames provided have been received |
1037 // on the video and audio tracks provided. | 1030 // on the video and audio tracks provided. |
1038 bool FramesHaveArrived(int audio_frames_to_receive, | 1031 bool FramesHaveArrived(int audio_frames_to_receive, |
1039 int video_frames_to_receive) { | 1032 int video_frames_to_receive) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 bool CreateTestClients() { return CreateTestClients(nullptr, nullptr); } | 1120 bool CreateTestClients() { return CreateTestClients(nullptr, nullptr); } |
1128 | 1121 |
1129 bool CreateTestClients(MediaConstraintsInterface* init_constraints, | 1122 bool CreateTestClients(MediaConstraintsInterface* init_constraints, |
1130 MediaConstraintsInterface* recv_constraints) { | 1123 MediaConstraintsInterface* recv_constraints) { |
1131 return CreateTestClients(init_constraints, nullptr, recv_constraints, | 1124 return CreateTestClients(init_constraints, nullptr, recv_constraints, |
1132 nullptr); | 1125 nullptr); |
1133 } | 1126 } |
1134 | 1127 |
1135 bool CreateTestClientsThatPreferNoConstraints() { | 1128 bool CreateTestClientsThatPreferNoConstraints() { |
1136 initiating_client_.reset( | 1129 initiating_client_.reset( |
1137 PeerConnectionTestClient::CreateClientPreferNoConstraints( | 1130 PeerConnectionTestClient::CreateClientPreferNoConstraints("Caller: ", |
1138 "Caller: ", nullptr, &worker_thread_)); | 1131 nullptr)); |
1139 receiving_client_.reset( | 1132 receiving_client_.reset( |
1140 PeerConnectionTestClient::CreateClientPreferNoConstraints( | 1133 PeerConnectionTestClient::CreateClientPreferNoConstraints("Callee: ", |
1141 "Callee: ", nullptr, &worker_thread_)); | 1134 nullptr)); |
1142 if (!initiating_client_ || !receiving_client_) { | 1135 if (!initiating_client_ || !receiving_client_) { |
1143 return false; | 1136 return false; |
1144 } | 1137 } |
1145 // Remember the choice for possible later resets of the clients. | 1138 // Remember the choice for possible later resets of the clients. |
1146 prefer_constraint_apis_ = false; | 1139 prefer_constraint_apis_ = false; |
1147 SetSignalingReceivers(); | 1140 SetSignalingReceivers(); |
1148 return true; | 1141 return true; |
1149 } | 1142 } |
1150 | 1143 |
1151 void SetSignalingReceivers() { | 1144 void SetSignalingReceivers() { |
1152 initiating_client_->set_signaling_message_receiver(receiving_client_.get()); | 1145 initiating_client_->set_signaling_message_receiver(receiving_client_.get()); |
1153 receiving_client_->set_signaling_message_receiver(initiating_client_.get()); | 1146 receiving_client_->set_signaling_message_receiver(initiating_client_.get()); |
1154 } | 1147 } |
1155 | 1148 |
1156 bool CreateTestClients(MediaConstraintsInterface* init_constraints, | 1149 bool CreateTestClients(MediaConstraintsInterface* init_constraints, |
1157 PeerConnectionFactory::Options* init_options, | 1150 PeerConnectionFactory::Options* init_options, |
1158 MediaConstraintsInterface* recv_constraints, | 1151 MediaConstraintsInterface* recv_constraints, |
1159 PeerConnectionFactory::Options* recv_options) { | 1152 PeerConnectionFactory::Options* recv_options) { |
1160 initiating_client_.reset(PeerConnectionTestClient::CreateClient( | 1153 initiating_client_.reset(PeerConnectionTestClient::CreateClient( |
1161 "Caller: ", init_constraints, init_options, &worker_thread_)); | 1154 "Caller: ", init_constraints, init_options)); |
1162 receiving_client_.reset(PeerConnectionTestClient::CreateClient( | 1155 receiving_client_.reset(PeerConnectionTestClient::CreateClient( |
1163 "Callee: ", recv_constraints, recv_options, &worker_thread_)); | 1156 "Callee: ", recv_constraints, recv_options)); |
1164 if (!initiating_client_ || !receiving_client_) { | 1157 if (!initiating_client_ || !receiving_client_) { |
1165 return false; | 1158 return false; |
1166 } | 1159 } |
1167 SetSignalingReceivers(); | 1160 SetSignalingReceivers(); |
1168 return true; | 1161 return true; |
1169 } | 1162 } |
1170 | 1163 |
1171 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints, | 1164 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints, |
1172 const webrtc::FakeConstraints& recv_constraints) { | 1165 const webrtc::FakeConstraints& recv_constraints) { |
1173 initiating_client_->SetVideoConstraints(init_constraints); | 1166 initiating_client_->SetVideoConstraints(init_constraints); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 true); | 1247 true); |
1255 | 1248 |
1256 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store( | 1249 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store( |
1257 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() | 1250 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() |
1258 : nullptr); | 1251 : nullptr); |
1259 dtls_identity_store->use_alternate_key(); | 1252 dtls_identity_store->use_alternate_key(); |
1260 | 1253 |
1261 // Make sure the new client is using a different certificate. | 1254 // Make sure the new client is using a different certificate. |
1262 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore( | 1255 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore( |
1263 "New Peer: ", &setup_constraints, nullptr, | 1256 "New Peer: ", &setup_constraints, nullptr, |
1264 std::move(dtls_identity_store), prefer_constraint_apis_, | 1257 std::move(dtls_identity_store), prefer_constraint_apis_); |
1265 &worker_thread_); | |
1266 } | 1258 } |
1267 | 1259 |
1268 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { | 1260 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { |
1269 // Messages may get lost on the unreliable DataChannel, so we send multiple | 1261 // Messages may get lost on the unreliable DataChannel, so we send multiple |
1270 // times to avoid test flakiness. | 1262 // times to avoid test flakiness. |
1271 static const size_t kSendAttempts = 5; | 1263 static const size_t kSendAttempts = 5; |
1272 | 1264 |
1273 for (size_t i = 0; i < kSendAttempts; ++i) { | 1265 for (size_t i = 0; i < kSendAttempts; ++i) { |
1274 dc->Send(DataBuffer(data)); | 1266 dc->Send(DataBuffer(data)); |
1275 } | 1267 } |
(...skipping 19 matching lines...) Expand all Loading... |
1295 // Set the |receiving_client_| to the |client| passed in and return the | 1287 // Set the |receiving_client_| to the |client| passed in and return the |
1296 // original |receiving_client_|. | 1288 // original |receiving_client_|. |
1297 PeerConnectionTestClient* set_receiving_client( | 1289 PeerConnectionTestClient* set_receiving_client( |
1298 PeerConnectionTestClient* client) { | 1290 PeerConnectionTestClient* client) { |
1299 PeerConnectionTestClient* old = receiving_client_.release(); | 1291 PeerConnectionTestClient* old = receiving_client_.release(); |
1300 receiving_client_.reset(client); | 1292 receiving_client_.reset(client); |
1301 return old; | 1293 return old; |
1302 } | 1294 } |
1303 | 1295 |
1304 private: | 1296 private: |
1305 // |worker_thread_| is used by both |initiating_client_| and | |
1306 // |receiving_client_|. Must be destroyed last. | |
1307 rtc::Thread worker_thread_; | |
1308 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; | 1297 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
1309 rtc::scoped_ptr<rtc::VirtualSocketServer> ss_; | 1298 rtc::scoped_ptr<rtc::VirtualSocketServer> ss_; |
1310 rtc::SocketServerScope ss_scope_; | 1299 rtc::SocketServerScope ss_scope_; |
1311 rtc::scoped_ptr<PeerConnectionTestClient> initiating_client_; | 1300 rtc::scoped_ptr<PeerConnectionTestClient> initiating_client_; |
1312 rtc::scoped_ptr<PeerConnectionTestClient> receiving_client_; | 1301 rtc::scoped_ptr<PeerConnectionTestClient> receiving_client_; |
1313 bool prefer_constraint_apis_ = true; | 1302 bool prefer_constraint_apis_ = true; |
1314 }; | 1303 }; |
1315 | 1304 |
1316 // Disable for TSan v2, see | 1305 // Disable for TSan v2, see |
1317 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. | 1306 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. |
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2166 server.urls.push_back("turn:hostname2"); | 2155 server.urls.push_back("turn:hostname2"); |
2167 servers.push_back(server); | 2156 servers.push_back(server); |
2168 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); | 2157 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); |
2169 EXPECT_EQ(2U, turn_servers_.size()); | 2158 EXPECT_EQ(2U, turn_servers_.size()); |
2170 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); | 2159 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); |
2171 } | 2160 } |
2172 | 2161 |
2173 #endif // if !defined(THREAD_SANITIZER) | 2162 #endif // if !defined(THREAD_SANITIZER) |
2174 | 2163 |
2175 } // namespace | 2164 } // namespace |
OLD | NEW |