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

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

Issue 1987093002: Only use PortAllocator on the network thread. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 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 | « webrtc/api/peerconnection.h ('k') | webrtc/api/peerconnectionfactory.cc » ('j') | 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 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 } 552 }
553 for (const auto& receiver : receivers_) { 553 for (const auto& receiver : receivers_) {
554 receiver->Stop(); 554 receiver->Stop();
555 } 555 }
556 // Destroy stats_ because it depends on session_. 556 // Destroy stats_ because it depends on session_.
557 stats_.reset(nullptr); 557 stats_.reset(nullptr);
558 // Now destroy session_ before destroying other members, 558 // Now destroy session_ before destroying other members,
559 // because its destruction fires signals (such as VoiceChannelDestroyed) 559 // because its destruction fires signals (such as VoiceChannelDestroyed)
560 // which will trigger some final actions in PeerConnection... 560 // which will trigger some final actions in PeerConnection...
561 session_.reset(nullptr); 561 session_.reset(nullptr);
562 // port_allocator_ lives on the worker thread and should be destroyed there. 562 // port_allocator_ lives on the network thread and should be destroyed there.
563 worker_thread()->Invoke<void>([this] { port_allocator_.reset(nullptr); }); 563 network_thread()->Invoke<void>([this] { port_allocator_.reset(nullptr); });
564 } 564 }
565 565
566 bool PeerConnection::Initialize( 566 bool PeerConnection::Initialize(
567 const PeerConnectionInterface::RTCConfiguration& configuration, 567 const PeerConnectionInterface::RTCConfiguration& configuration,
568 std::unique_ptr<cricket::PortAllocator> allocator, 568 std::unique_ptr<cricket::PortAllocator> allocator,
569 std::unique_ptr<DtlsIdentityStoreInterface> dtls_identity_store, 569 std::unique_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
570 PeerConnectionObserver* observer) { 570 PeerConnectionObserver* observer) {
571 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); 571 TRACE_EVENT0("webrtc", "PeerConnection::Initialize");
572 RTC_DCHECK(observer != nullptr); 572 RTC_DCHECK(observer != nullptr);
573 if (!observer) { 573 if (!observer) {
574 return false; 574 return false;
575 } 575 }
576 observer_ = observer; 576 observer_ = observer;
577 577
578 port_allocator_ = std::move(allocator); 578 port_allocator_ = std::move(allocator);
579 579
580 // The port allocator lives on the worker thread and should be initialized 580 // The port allocator lives on the network thread and should be initialized
581 // there. 581 // there.
582 if (!worker_thread()->Invoke<bool>(rtc::Bind( 582 if (!network_thread()->Invoke<bool>(rtc::Bind(
583 &PeerConnection::InitializePortAllocator_w, this, configuration))) { 583 &PeerConnection::InitializePortAllocator_n, this, configuration))) {
584 return false; 584 return false;
585 } 585 }
586 586
587 media_controller_.reset( 587 media_controller_.reset(
588 factory_->CreateMediaController(configuration.media_config)); 588 factory_->CreateMediaController(configuration.media_config));
589 589
590 session_.reset( 590 session_.reset(
591 new WebRtcSession(media_controller_.get(), factory_->network_thread(), 591 new WebRtcSession(media_controller_.get(), factory_->network_thread(),
592 factory_->worker_thread(), factory_->signaling_thread(), 592 factory_->worker_thread(), factory_->signaling_thread(),
593 port_allocator_.get())); 593 port_allocator_.get()));
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 1157
1158 UpdateEndedRemoteMediaStreams(); 1158 UpdateEndedRemoteMediaStreams();
1159 1159
1160 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); 1160 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer);
1161 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); 1161 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg);
1162 } 1162 }
1163 1163
1164 bool PeerConnection::SetConfiguration(const RTCConfiguration& configuration) { 1164 bool PeerConnection::SetConfiguration(const RTCConfiguration& configuration) {
1165 TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration"); 1165 TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration");
1166 if (port_allocator_) { 1166 if (port_allocator_) {
1167 if (!worker_thread()->Invoke<bool>( 1167 if (!network_thread()->Invoke<bool>(
1168 rtc::Bind(&PeerConnection::ReconfigurePortAllocator_w, this, 1168 rtc::Bind(&PeerConnection::ReconfigurePortAllocator_n, this,
1169 configuration))) { 1169 configuration))) {
1170 return false; 1170 return false;
1171 } 1171 }
1172 } 1172 }
1173 1173
1174 // TODO(deadbeef): Shouldn't have to hop to the worker thread twice... 1174 // TODO(deadbeef): Shouldn't have to hop to the worker thread twice...
1175 session_->SetIceConfig(session_->ParseIceConfig(configuration)); 1175 session_->SetIceConfig(session_->ParseIceConfig(configuration));
1176 return true; 1176 return true;
1177 } 1177 }
1178 1178
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after
2081 2081
2082 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { 2082 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const {
2083 for (const auto& channel : sctp_data_channels_) { 2083 for (const auto& channel : sctp_data_channels_) {
2084 if (channel->id() == sid) { 2084 if (channel->id() == sid) {
2085 return channel; 2085 return channel;
2086 } 2086 }
2087 } 2087 }
2088 return nullptr; 2088 return nullptr;
2089 } 2089 }
2090 2090
2091 bool PeerConnection::InitializePortAllocator_w( 2091 bool PeerConnection::InitializePortAllocator_n(
2092 const RTCConfiguration& configuration) { 2092 const RTCConfiguration& configuration) {
2093 cricket::ServerAddresses stun_servers; 2093 cricket::ServerAddresses stun_servers;
2094 std::vector<cricket::RelayServerConfig> turn_servers; 2094 std::vector<cricket::RelayServerConfig> turn_servers;
2095 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { 2095 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) {
2096 return false; 2096 return false;
2097 } 2097 }
2098 2098
2099 // To handle both internal and externally created port allocator, we will 2099 // To handle both internal and externally created port allocator, we will
2100 // enable BUNDLE here. 2100 // enable BUNDLE here.
2101 int portallocator_flags = port_allocator_->flags(); 2101 int portallocator_flags = port_allocator_->flags();
(...skipping 19 matching lines...) Expand all
2121 port_allocator_->set_candidate_filter( 2121 port_allocator_->set_candidate_filter(
2122 ConvertIceTransportTypeToCandidateFilter(configuration.type)); 2122 ConvertIceTransportTypeToCandidateFilter(configuration.type));
2123 2123
2124 // Call this last since it may create pooled allocator sessions using the 2124 // Call this last since it may create pooled allocator sessions using the
2125 // properties set above. 2125 // properties set above.
2126 port_allocator_->SetConfiguration(stun_servers, turn_servers, 2126 port_allocator_->SetConfiguration(stun_servers, turn_servers,
2127 configuration.ice_candidate_pool_size); 2127 configuration.ice_candidate_pool_size);
2128 return true; 2128 return true;
2129 } 2129 }
2130 2130
2131 bool PeerConnection::ReconfigurePortAllocator_w( 2131 bool PeerConnection::ReconfigurePortAllocator_n(
2132 const RTCConfiguration& configuration) { 2132 const RTCConfiguration& configuration) {
2133 cricket::ServerAddresses stun_servers; 2133 cricket::ServerAddresses stun_servers;
2134 std::vector<cricket::RelayServerConfig> turn_servers; 2134 std::vector<cricket::RelayServerConfig> turn_servers;
2135 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { 2135 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) {
2136 return false; 2136 return false;
2137 } 2137 }
2138 port_allocator_->set_candidate_filter( 2138 port_allocator_->set_candidate_filter(
2139 ConvertIceTransportTypeToCandidateFilter(configuration.type)); 2139 ConvertIceTransportTypeToCandidateFilter(configuration.type));
2140 // Call this last since it may create pooled allocator sessions using the 2140 // Call this last since it may create pooled allocator sessions using the
2141 // candidate filter set above. 2141 // candidate filter set above.
2142 port_allocator_->SetConfiguration(stun_servers, turn_servers, 2142 port_allocator_->SetConfiguration(stun_servers, turn_servers,
2143 configuration.ice_candidate_pool_size); 2143 configuration.ice_candidate_pool_size);
2144 return true; 2144 return true;
2145 } 2145 }
2146 2146
2147 } // namespace webrtc 2147 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/peerconnection.h ('k') | webrtc/api/peerconnectionfactory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698