| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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<webrtc::DtlsIdentityStoreInterface> dtls_identity_store, |
| 158 bool prefer_constraint_apis, | 158 bool prefer_constraint_apis, |
| 159 rtc::Thread* network_thread, |
| 159 rtc::Thread* worker_thread) { | 160 rtc::Thread* worker_thread) { |
| 160 PeerConnectionTestClient* client(new PeerConnectionTestClient(id)); | 161 PeerConnectionTestClient* client(new PeerConnectionTestClient(id)); |
| 161 if (!client->Init(constraints, options, std::move(dtls_identity_store), | 162 if (!client->Init(constraints, options, std::move(dtls_identity_store), |
| 162 prefer_constraint_apis, worker_thread)) { | 163 prefer_constraint_apis, network_thread, worker_thread)) { |
| 163 delete client; | 164 delete client; |
| 164 return nullptr; | 165 return nullptr; |
| 165 } | 166 } |
| 166 return client; | 167 return client; |
| 167 } | 168 } |
| 168 | 169 |
| 169 static PeerConnectionTestClient* CreateClient( | 170 static PeerConnectionTestClient* CreateClient( |
| 170 const std::string& id, | 171 const std::string& id, |
| 171 const MediaConstraintsInterface* constraints, | 172 const MediaConstraintsInterface* constraints, |
| 172 const PeerConnectionFactory::Options* options, | 173 const PeerConnectionFactory::Options* options, |
| 174 rtc::Thread* network_thread, |
| 173 rtc::Thread* worker_thread) { | 175 rtc::Thread* worker_thread) { |
| 174 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store( | 176 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store( |
| 175 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() | 177 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() |
| 176 : nullptr); | 178 : nullptr); |
| 177 | 179 |
| 178 return CreateClientWithDtlsIdentityStore(id, constraints, options, | 180 return CreateClientWithDtlsIdentityStore( |
| 179 std::move(dtls_identity_store), | 181 id, constraints, options, std::move(dtls_identity_store), true, |
| 180 true, worker_thread); | 182 network_thread, worker_thread); |
| 181 } | 183 } |
| 182 | 184 |
| 183 static PeerConnectionTestClient* CreateClientPreferNoConstraints( | 185 static PeerConnectionTestClient* CreateClientPreferNoConstraints( |
| 184 const std::string& id, | 186 const std::string& id, |
| 185 const PeerConnectionFactory::Options* options, | 187 const PeerConnectionFactory::Options* options, |
| 188 rtc::Thread* network_thread, |
| 186 rtc::Thread* worker_thread) { | 189 rtc::Thread* worker_thread) { |
| 187 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store( | 190 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store( |
| 188 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() | 191 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() |
| 189 : nullptr); | 192 : nullptr); |
| 190 | 193 |
| 191 return CreateClientWithDtlsIdentityStore(id, nullptr, options, | 194 return CreateClientWithDtlsIdentityStore( |
| 192 std::move(dtls_identity_store), | 195 id, nullptr, options, std::move(dtls_identity_store), false, |
| 193 false, worker_thread); | 196 network_thread, worker_thread); |
| 194 } | 197 } |
| 195 | 198 |
| 196 ~PeerConnectionTestClient() { | 199 ~PeerConnectionTestClient() { |
| 197 } | 200 } |
| 198 | 201 |
| 199 void Negotiate() { Negotiate(true, true); } | 202 void Negotiate() { Negotiate(true, true); } |
| 200 | 203 |
| 201 void Negotiate(bool audio, bool video) { | 204 void Negotiate(bool audio, bool video) { |
| 202 std::unique_ptr<SessionDescriptionInterface> offer; | 205 std::unique_ptr<SessionDescriptionInterface> offer; |
| 203 ASSERT_TRUE(DoCreateOffer(&offer)); | 206 ASSERT_TRUE(DoCreateOffer(&offer)); |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 std::vector<std::string> tones_; | 802 std::vector<std::string> tones_; |
| 800 }; | 803 }; |
| 801 | 804 |
| 802 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {} | 805 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {} |
| 803 | 806 |
| 804 bool Init( | 807 bool Init( |
| 805 const MediaConstraintsInterface* constraints, | 808 const MediaConstraintsInterface* constraints, |
| 806 const PeerConnectionFactory::Options* options, | 809 const PeerConnectionFactory::Options* options, |
| 807 std::unique_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store, | 810 std::unique_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store, |
| 808 bool prefer_constraint_apis, | 811 bool prefer_constraint_apis, |
| 812 rtc::Thread* network_thread, |
| 809 rtc::Thread* worker_thread) { | 813 rtc::Thread* worker_thread) { |
| 810 EXPECT_TRUE(!peer_connection_); | 814 EXPECT_TRUE(!peer_connection_); |
| 811 EXPECT_TRUE(!peer_connection_factory_); | 815 EXPECT_TRUE(!peer_connection_factory_); |
| 812 if (!prefer_constraint_apis) { | 816 if (!prefer_constraint_apis) { |
| 813 EXPECT_TRUE(!constraints); | 817 EXPECT_TRUE(!constraints); |
| 814 } | 818 } |
| 815 prefer_constraint_apis_ = prefer_constraint_apis; | 819 prefer_constraint_apis_ = prefer_constraint_apis; |
| 816 | 820 |
| 817 std::unique_ptr<cricket::PortAllocator> port_allocator( | 821 std::unique_ptr<cricket::PortAllocator> port_allocator( |
| 818 new cricket::FakePortAllocator(worker_thread, nullptr)); | 822 new cricket::FakePortAllocator(network_thread, nullptr)); |
| 819 fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); | 823 fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); |
| 820 | 824 |
| 821 if (fake_audio_capture_module_ == nullptr) { | 825 if (fake_audio_capture_module_ == nullptr) { |
| 822 return false; | 826 return false; |
| 823 } | 827 } |
| 824 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory(); | 828 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory(); |
| 825 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory(); | 829 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory(); |
| 830 rtc::Thread* const signaling_thread = rtc::Thread::Current(); |
| 826 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( | 831 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( |
| 827 worker_thread, rtc::Thread::Current(), fake_audio_capture_module_, | 832 network_thread, worker_thread, signaling_thread, |
| 828 fake_video_encoder_factory_, fake_video_decoder_factory_); | 833 fake_audio_capture_module_, fake_video_encoder_factory_, |
| 834 fake_video_decoder_factory_); |
| 829 if (!peer_connection_factory_) { | 835 if (!peer_connection_factory_) { |
| 830 return false; | 836 return false; |
| 831 } | 837 } |
| 832 if (options) { | 838 if (options) { |
| 833 peer_connection_factory_->SetOptions(*options); | 839 peer_connection_factory_->SetOptions(*options); |
| 834 } | 840 } |
| 835 peer_connection_ = CreatePeerConnection( | 841 peer_connection_ = CreatePeerConnection( |
| 836 std::move(port_allocator), constraints, std::move(dtls_identity_store)); | 842 std::move(port_allocator), constraints, std::move(dtls_identity_store)); |
| 837 return peer_connection_.get() != nullptr; | 843 return peer_connection_.get() != nullptr; |
| 838 } | 844 } |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 // removed in the received SDP. | 1021 // removed in the received SDP. |
| 1016 bool remove_cvo_ = false; | 1022 bool remove_cvo_ = false; |
| 1017 | 1023 |
| 1018 rtc::scoped_refptr<DataChannelInterface> data_channel_; | 1024 rtc::scoped_refptr<DataChannelInterface> data_channel_; |
| 1019 std::unique_ptr<MockDataChannelObserver> data_observer_; | 1025 std::unique_ptr<MockDataChannelObserver> data_observer_; |
| 1020 }; | 1026 }; |
| 1021 | 1027 |
| 1022 class P2PTestConductor : public testing::Test { | 1028 class P2PTestConductor : public testing::Test { |
| 1023 public: | 1029 public: |
| 1024 P2PTestConductor() | 1030 P2PTestConductor() |
| 1025 : pss_(new rtc::PhysicalSocketServer), | 1031 : network_thread_(rtc::Thread::CreateWithSocketServer()), |
| 1032 worker_thread_(rtc::Thread::Create()), |
| 1033 pss_(new rtc::PhysicalSocketServer), |
| 1026 ss_(new rtc::VirtualSocketServer(pss_.get())), | 1034 ss_(new rtc::VirtualSocketServer(pss_.get())), |
| 1027 ss_scope_(ss_.get()) { | 1035 ss_scope_(ss_.get()) { |
| 1028 RTC_CHECK(worker_thread_.Start()); | 1036 RTC_CHECK(network_thread_->Start()); |
| 1037 RTC_CHECK(worker_thread_->Start()); |
| 1029 } | 1038 } |
| 1030 | 1039 |
| 1031 bool SessionActive() { | 1040 bool SessionActive() { |
| 1032 return initiating_client_->SessionActive() && | 1041 return initiating_client_->SessionActive() && |
| 1033 receiving_client_->SessionActive(); | 1042 receiving_client_->SessionActive(); |
| 1034 } | 1043 } |
| 1035 | 1044 |
| 1036 // Return true if the number of frames provided have been received | 1045 // Return true if the number of frames provided have been received |
| 1037 // on the video and audio tracks provided. | 1046 // on the video and audio tracks provided. |
| 1038 bool FramesHaveArrived(int audio_frames_to_receive, | 1047 bool FramesHaveArrived(int audio_frames_to_receive, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 | 1137 |
| 1129 bool CreateTestClients(MediaConstraintsInterface* init_constraints, | 1138 bool CreateTestClients(MediaConstraintsInterface* init_constraints, |
| 1130 MediaConstraintsInterface* recv_constraints) { | 1139 MediaConstraintsInterface* recv_constraints) { |
| 1131 return CreateTestClients(init_constraints, nullptr, recv_constraints, | 1140 return CreateTestClients(init_constraints, nullptr, recv_constraints, |
| 1132 nullptr); | 1141 nullptr); |
| 1133 } | 1142 } |
| 1134 | 1143 |
| 1135 bool CreateTestClientsThatPreferNoConstraints() { | 1144 bool CreateTestClientsThatPreferNoConstraints() { |
| 1136 initiating_client_.reset( | 1145 initiating_client_.reset( |
| 1137 PeerConnectionTestClient::CreateClientPreferNoConstraints( | 1146 PeerConnectionTestClient::CreateClientPreferNoConstraints( |
| 1138 "Caller: ", nullptr, &worker_thread_)); | 1147 "Caller: ", nullptr, network_thread_.get(), worker_thread_.get())); |
| 1139 receiving_client_.reset( | 1148 receiving_client_.reset( |
| 1140 PeerConnectionTestClient::CreateClientPreferNoConstraints( | 1149 PeerConnectionTestClient::CreateClientPreferNoConstraints( |
| 1141 "Callee: ", nullptr, &worker_thread_)); | 1150 "Callee: ", nullptr, network_thread_.get(), worker_thread_.get())); |
| 1142 if (!initiating_client_ || !receiving_client_) { | 1151 if (!initiating_client_ || !receiving_client_) { |
| 1143 return false; | 1152 return false; |
| 1144 } | 1153 } |
| 1145 // Remember the choice for possible later resets of the clients. | 1154 // Remember the choice for possible later resets of the clients. |
| 1146 prefer_constraint_apis_ = false; | 1155 prefer_constraint_apis_ = false; |
| 1147 SetSignalingReceivers(); | 1156 SetSignalingReceivers(); |
| 1148 return true; | 1157 return true; |
| 1149 } | 1158 } |
| 1150 | 1159 |
| 1151 void SetSignalingReceivers() { | 1160 void SetSignalingReceivers() { |
| 1152 initiating_client_->set_signaling_message_receiver(receiving_client_.get()); | 1161 initiating_client_->set_signaling_message_receiver(receiving_client_.get()); |
| 1153 receiving_client_->set_signaling_message_receiver(initiating_client_.get()); | 1162 receiving_client_->set_signaling_message_receiver(initiating_client_.get()); |
| 1154 } | 1163 } |
| 1155 | 1164 |
| 1156 bool CreateTestClients(MediaConstraintsInterface* init_constraints, | 1165 bool CreateTestClients(MediaConstraintsInterface* init_constraints, |
| 1157 PeerConnectionFactory::Options* init_options, | 1166 PeerConnectionFactory::Options* init_options, |
| 1158 MediaConstraintsInterface* recv_constraints, | 1167 MediaConstraintsInterface* recv_constraints, |
| 1159 PeerConnectionFactory::Options* recv_options) { | 1168 PeerConnectionFactory::Options* recv_options) { |
| 1160 initiating_client_.reset(PeerConnectionTestClient::CreateClient( | 1169 initiating_client_.reset(PeerConnectionTestClient::CreateClient( |
| 1161 "Caller: ", init_constraints, init_options, &worker_thread_)); | 1170 "Caller: ", init_constraints, init_options, network_thread_.get(), |
| 1171 worker_thread_.get())); |
| 1162 receiving_client_.reset(PeerConnectionTestClient::CreateClient( | 1172 receiving_client_.reset(PeerConnectionTestClient::CreateClient( |
| 1163 "Callee: ", recv_constraints, recv_options, &worker_thread_)); | 1173 "Callee: ", recv_constraints, recv_options, network_thread_.get(), |
| 1174 worker_thread_.get())); |
| 1164 if (!initiating_client_ || !receiving_client_) { | 1175 if (!initiating_client_ || !receiving_client_) { |
| 1165 return false; | 1176 return false; |
| 1166 } | 1177 } |
| 1167 SetSignalingReceivers(); | 1178 SetSignalingReceivers(); |
| 1168 return true; | 1179 return true; |
| 1169 } | 1180 } |
| 1170 | 1181 |
| 1171 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints, | 1182 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints, |
| 1172 const webrtc::FakeConstraints& recv_constraints) { | 1183 const webrtc::FakeConstraints& recv_constraints) { |
| 1173 initiating_client_->SetVideoConstraints(init_constraints); | 1184 initiating_client_->SetVideoConstraints(init_constraints); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 | 1266 |
| 1256 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store( | 1267 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store( |
| 1257 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() | 1268 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() |
| 1258 : nullptr); | 1269 : nullptr); |
| 1259 dtls_identity_store->use_alternate_key(); | 1270 dtls_identity_store->use_alternate_key(); |
| 1260 | 1271 |
| 1261 // Make sure the new client is using a different certificate. | 1272 // Make sure the new client is using a different certificate. |
| 1262 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore( | 1273 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore( |
| 1263 "New Peer: ", &setup_constraints, nullptr, | 1274 "New Peer: ", &setup_constraints, nullptr, |
| 1264 std::move(dtls_identity_store), prefer_constraint_apis_, | 1275 std::move(dtls_identity_store), prefer_constraint_apis_, |
| 1265 &worker_thread_); | 1276 network_thread_.get(), worker_thread_.get()); |
| 1266 } | 1277 } |
| 1267 | 1278 |
| 1268 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { | 1279 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { |
| 1269 // Messages may get lost on the unreliable DataChannel, so we send multiple | 1280 // Messages may get lost on the unreliable DataChannel, so we send multiple |
| 1270 // times to avoid test flakiness. | 1281 // times to avoid test flakiness. |
| 1271 static const size_t kSendAttempts = 5; | 1282 static const size_t kSendAttempts = 5; |
| 1272 | 1283 |
| 1273 for (size_t i = 0; i < kSendAttempts; ++i) { | 1284 for (size_t i = 0; i < kSendAttempts; ++i) { |
| 1274 dc->Send(DataBuffer(data)); | 1285 dc->Send(DataBuffer(data)); |
| 1275 } | 1286 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1297 PeerConnectionTestClient* set_receiving_client( | 1308 PeerConnectionTestClient* set_receiving_client( |
| 1298 PeerConnectionTestClient* client) { | 1309 PeerConnectionTestClient* client) { |
| 1299 PeerConnectionTestClient* old = receiving_client_.release(); | 1310 PeerConnectionTestClient* old = receiving_client_.release(); |
| 1300 receiving_client_.reset(client); | 1311 receiving_client_.reset(client); |
| 1301 return old; | 1312 return old; |
| 1302 } | 1313 } |
| 1303 | 1314 |
| 1304 private: | 1315 private: |
| 1305 // |worker_thread_| is used by both |initiating_client_| and | 1316 // |worker_thread_| is used by both |initiating_client_| and |
| 1306 // |receiving_client_|. Must be destroyed last. | 1317 // |receiving_client_|. Must be destroyed last. |
| 1307 rtc::Thread worker_thread_; | 1318 std::unique_ptr<rtc::Thread> network_thread_; |
| 1319 std::unique_ptr<rtc::Thread> worker_thread_; |
| 1308 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 1320 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
| 1309 std::unique_ptr<rtc::VirtualSocketServer> ss_; | 1321 std::unique_ptr<rtc::VirtualSocketServer> ss_; |
| 1310 rtc::SocketServerScope ss_scope_; | 1322 rtc::SocketServerScope ss_scope_; |
| 1311 std::unique_ptr<PeerConnectionTestClient> initiating_client_; | 1323 std::unique_ptr<PeerConnectionTestClient> initiating_client_; |
| 1312 std::unique_ptr<PeerConnectionTestClient> receiving_client_; | 1324 std::unique_ptr<PeerConnectionTestClient> receiving_client_; |
| 1313 bool prefer_constraint_apis_ = true; | 1325 bool prefer_constraint_apis_ = true; |
| 1314 }; | 1326 }; |
| 1315 | 1327 |
| 1316 // Disable for TSan v2, see | 1328 // Disable for TSan v2, see |
| 1317 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. | 1329 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. |
| (...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2199 server.urls.push_back("turn:hostname2"); | 2211 server.urls.push_back("turn:hostname2"); |
| 2200 servers.push_back(server); | 2212 servers.push_back(server); |
| 2201 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); | 2213 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); |
| 2202 EXPECT_EQ(2U, turn_servers_.size()); | 2214 EXPECT_EQ(2U, turn_servers_.size()); |
| 2203 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); | 2215 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); |
| 2204 } | 2216 } |
| 2205 | 2217 |
| 2206 #endif // if !defined(THREAD_SANITIZER) | 2218 #endif // if !defined(THREAD_SANITIZER) |
| 2207 | 2219 |
| 2208 } // namespace | 2220 } // namespace |
| OLD | NEW |