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(worker_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(); |
826 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( | 830 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( |
827 worker_thread, rtc::Thread::Current(), fake_audio_capture_module_, | 831 network_thread, worker_thread, rtc::Thread::Current(), |
828 fake_video_encoder_factory_, fake_video_decoder_factory_); | 832 fake_audio_capture_module_, fake_video_encoder_factory_, |
| 833 fake_video_decoder_factory_); |
829 if (!peer_connection_factory_) { | 834 if (!peer_connection_factory_) { |
830 return false; | 835 return false; |
831 } | 836 } |
832 if (options) { | 837 if (options) { |
833 peer_connection_factory_->SetOptions(*options); | 838 peer_connection_factory_->SetOptions(*options); |
834 } | 839 } |
835 peer_connection_ = CreatePeerConnection( | 840 peer_connection_ = CreatePeerConnection( |
836 std::move(port_allocator), constraints, std::move(dtls_identity_store)); | 841 std::move(port_allocator), constraints, std::move(dtls_identity_store)); |
837 return peer_connection_.get() != nullptr; | 842 return peer_connection_.get() != nullptr; |
838 } | 843 } |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 // removed in the received SDP. | 1020 // removed in the received SDP. |
1016 bool remove_cvo_ = false; | 1021 bool remove_cvo_ = false; |
1017 | 1022 |
1018 rtc::scoped_refptr<DataChannelInterface> data_channel_; | 1023 rtc::scoped_refptr<DataChannelInterface> data_channel_; |
1019 std::unique_ptr<MockDataChannelObserver> data_observer_; | 1024 std::unique_ptr<MockDataChannelObserver> data_observer_; |
1020 }; | 1025 }; |
1021 | 1026 |
1022 class P2PTestConductor : public testing::Test { | 1027 class P2PTestConductor : public testing::Test { |
1023 public: | 1028 public: |
1024 P2PTestConductor() | 1029 P2PTestConductor() |
1025 : pss_(new rtc::PhysicalSocketServer), | 1030 : network_thread_(rtc::Thread::CreateWithSocketServer()), |
| 1031 worker_thread_(rtc::Thread::Create()), |
| 1032 pss_(new rtc::PhysicalSocketServer), |
1026 ss_(new rtc::VirtualSocketServer(pss_.get())), | 1033 ss_(new rtc::VirtualSocketServer(pss_.get())), |
1027 ss_scope_(ss_.get()) { | 1034 ss_scope_(ss_.get()) { |
1028 RTC_CHECK(worker_thread_.Start()); | 1035 RTC_CHECK(network_thread_->Start()); |
| 1036 RTC_CHECK(worker_thread_->Start()); |
1029 } | 1037 } |
1030 | 1038 |
1031 bool SessionActive() { | 1039 bool SessionActive() { |
1032 return initiating_client_->SessionActive() && | 1040 return initiating_client_->SessionActive() && |
1033 receiving_client_->SessionActive(); | 1041 receiving_client_->SessionActive(); |
1034 } | 1042 } |
1035 | 1043 |
1036 // Return true if the number of frames provided have been received | 1044 // Return true if the number of frames provided have been received |
1037 // on the video and audio tracks provided. | 1045 // on the video and audio tracks provided. |
1038 bool FramesHaveArrived(int audio_frames_to_receive, | 1046 bool FramesHaveArrived(int audio_frames_to_receive, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 | 1136 |
1129 bool CreateTestClients(MediaConstraintsInterface* init_constraints, | 1137 bool CreateTestClients(MediaConstraintsInterface* init_constraints, |
1130 MediaConstraintsInterface* recv_constraints) { | 1138 MediaConstraintsInterface* recv_constraints) { |
1131 return CreateTestClients(init_constraints, nullptr, recv_constraints, | 1139 return CreateTestClients(init_constraints, nullptr, recv_constraints, |
1132 nullptr); | 1140 nullptr); |
1133 } | 1141 } |
1134 | 1142 |
1135 bool CreateTestClientsThatPreferNoConstraints() { | 1143 bool CreateTestClientsThatPreferNoConstraints() { |
1136 initiating_client_.reset( | 1144 initiating_client_.reset( |
1137 PeerConnectionTestClient::CreateClientPreferNoConstraints( | 1145 PeerConnectionTestClient::CreateClientPreferNoConstraints( |
1138 "Caller: ", nullptr, &worker_thread_)); | 1146 "Caller: ", nullptr, network_thread_.get(), worker_thread_.get())); |
1139 receiving_client_.reset( | 1147 receiving_client_.reset( |
1140 PeerConnectionTestClient::CreateClientPreferNoConstraints( | 1148 PeerConnectionTestClient::CreateClientPreferNoConstraints( |
1141 "Callee: ", nullptr, &worker_thread_)); | 1149 "Callee: ", nullptr, network_thread_.get(), worker_thread_.get())); |
1142 if (!initiating_client_ || !receiving_client_) { | 1150 if (!initiating_client_ || !receiving_client_) { |
1143 return false; | 1151 return false; |
1144 } | 1152 } |
1145 // Remember the choice for possible later resets of the clients. | 1153 // Remember the choice for possible later resets of the clients. |
1146 prefer_constraint_apis_ = false; | 1154 prefer_constraint_apis_ = false; |
1147 SetSignalingReceivers(); | 1155 SetSignalingReceivers(); |
1148 return true; | 1156 return true; |
1149 } | 1157 } |
1150 | 1158 |
1151 void SetSignalingReceivers() { | 1159 void SetSignalingReceivers() { |
1152 initiating_client_->set_signaling_message_receiver(receiving_client_.get()); | 1160 initiating_client_->set_signaling_message_receiver(receiving_client_.get()); |
1153 receiving_client_->set_signaling_message_receiver(initiating_client_.get()); | 1161 receiving_client_->set_signaling_message_receiver(initiating_client_.get()); |
1154 } | 1162 } |
1155 | 1163 |
1156 bool CreateTestClients(MediaConstraintsInterface* init_constraints, | 1164 bool CreateTestClients(MediaConstraintsInterface* init_constraints, |
1157 PeerConnectionFactory::Options* init_options, | 1165 PeerConnectionFactory::Options* init_options, |
1158 MediaConstraintsInterface* recv_constraints, | 1166 MediaConstraintsInterface* recv_constraints, |
1159 PeerConnectionFactory::Options* recv_options) { | 1167 PeerConnectionFactory::Options* recv_options) { |
1160 initiating_client_.reset(PeerConnectionTestClient::CreateClient( | 1168 initiating_client_.reset(PeerConnectionTestClient::CreateClient( |
1161 "Caller: ", init_constraints, init_options, &worker_thread_)); | 1169 "Caller: ", init_constraints, init_options, network_thread_.get(), |
| 1170 worker_thread_.get())); |
1162 receiving_client_.reset(PeerConnectionTestClient::CreateClient( | 1171 receiving_client_.reset(PeerConnectionTestClient::CreateClient( |
1163 "Callee: ", recv_constraints, recv_options, &worker_thread_)); | 1172 "Callee: ", recv_constraints, recv_options, network_thread_.get(), |
| 1173 worker_thread_.get())); |
1164 if (!initiating_client_ || !receiving_client_) { | 1174 if (!initiating_client_ || !receiving_client_) { |
1165 return false; | 1175 return false; |
1166 } | 1176 } |
1167 SetSignalingReceivers(); | 1177 SetSignalingReceivers(); |
1168 return true; | 1178 return true; |
1169 } | 1179 } |
1170 | 1180 |
1171 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints, | 1181 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints, |
1172 const webrtc::FakeConstraints& recv_constraints) { | 1182 const webrtc::FakeConstraints& recv_constraints) { |
1173 initiating_client_->SetVideoConstraints(init_constraints); | 1183 initiating_client_->SetVideoConstraints(init_constraints); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 | 1265 |
1256 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store( | 1266 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store( |
1257 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() | 1267 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() |
1258 : nullptr); | 1268 : nullptr); |
1259 dtls_identity_store->use_alternate_key(); | 1269 dtls_identity_store->use_alternate_key(); |
1260 | 1270 |
1261 // Make sure the new client is using a different certificate. | 1271 // Make sure the new client is using a different certificate. |
1262 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore( | 1272 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore( |
1263 "New Peer: ", &setup_constraints, nullptr, | 1273 "New Peer: ", &setup_constraints, nullptr, |
1264 std::move(dtls_identity_store), prefer_constraint_apis_, | 1274 std::move(dtls_identity_store), prefer_constraint_apis_, |
1265 &worker_thread_); | 1275 network_thread_.get(), worker_thread_.get()); |
1266 } | 1276 } |
1267 | 1277 |
1268 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { | 1278 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { |
1269 // Messages may get lost on the unreliable DataChannel, so we send multiple | 1279 // Messages may get lost on the unreliable DataChannel, so we send multiple |
1270 // times to avoid test flakiness. | 1280 // times to avoid test flakiness. |
1271 static const size_t kSendAttempts = 5; | 1281 static const size_t kSendAttempts = 5; |
1272 | 1282 |
1273 for (size_t i = 0; i < kSendAttempts; ++i) { | 1283 for (size_t i = 0; i < kSendAttempts; ++i) { |
1274 dc->Send(DataBuffer(data)); | 1284 dc->Send(DataBuffer(data)); |
1275 } | 1285 } |
(...skipping 21 matching lines...) Expand all Loading... |
1297 PeerConnectionTestClient* set_receiving_client( | 1307 PeerConnectionTestClient* set_receiving_client( |
1298 PeerConnectionTestClient* client) { | 1308 PeerConnectionTestClient* client) { |
1299 PeerConnectionTestClient* old = receiving_client_.release(); | 1309 PeerConnectionTestClient* old = receiving_client_.release(); |
1300 receiving_client_.reset(client); | 1310 receiving_client_.reset(client); |
1301 return old; | 1311 return old; |
1302 } | 1312 } |
1303 | 1313 |
1304 private: | 1314 private: |
1305 // |worker_thread_| is used by both |initiating_client_| and | 1315 // |worker_thread_| is used by both |initiating_client_| and |
1306 // |receiving_client_|. Must be destroyed last. | 1316 // |receiving_client_|. Must be destroyed last. |
1307 rtc::Thread worker_thread_; | 1317 std::unique_ptr<rtc::Thread> network_thread_; |
| 1318 std::unique_ptr<rtc::Thread> worker_thread_; |
1308 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 1319 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
1309 std::unique_ptr<rtc::VirtualSocketServer> ss_; | 1320 std::unique_ptr<rtc::VirtualSocketServer> ss_; |
1310 rtc::SocketServerScope ss_scope_; | 1321 rtc::SocketServerScope ss_scope_; |
1311 std::unique_ptr<PeerConnectionTestClient> initiating_client_; | 1322 std::unique_ptr<PeerConnectionTestClient> initiating_client_; |
1312 std::unique_ptr<PeerConnectionTestClient> receiving_client_; | 1323 std::unique_ptr<PeerConnectionTestClient> receiving_client_; |
1313 bool prefer_constraint_apis_ = true; | 1324 bool prefer_constraint_apis_ = true; |
1314 }; | 1325 }; |
1315 | 1326 |
1316 // Disable for TSan v2, see | 1327 // Disable for TSan v2, see |
1317 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. | 1328 // 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"); | 2210 server.urls.push_back("turn:hostname2"); |
2200 servers.push_back(server); | 2211 servers.push_back(server); |
2201 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); | 2212 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); |
2202 EXPECT_EQ(2U, turn_servers_.size()); | 2213 EXPECT_EQ(2U, turn_servers_.size()); |
2203 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); | 2214 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); |
2204 } | 2215 } |
2205 | 2216 |
2206 #endif // if !defined(THREAD_SANITIZER) | 2217 #endif // if !defined(THREAD_SANITIZER) |
2207 | 2218 |
2208 } // namespace | 2219 } // namespace |
OLD | NEW |