Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: webrtc/api/peerconnection_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698