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 358 matching lines...) Loading... |
369 // For MediaStreams, the sync_label is the MediaStream label and the | 369 // For MediaStreams, the sync_label is the MediaStream label and the |
370 // track label is the same as |streamid|. | 370 // track label is the same as |streamid|. |
371 const std::string& streamid = channel->label(); | 371 const std::string& streamid = channel->label(); |
372 const std::string& sync_label = channel->label(); | 372 const std::string& sync_label = channel->label(); |
373 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA, streamid, | 373 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA, streamid, |
374 sync_label); | 374 sync_label); |
375 } | 375 } |
376 } | 376 } |
377 } | 377 } |
378 | 378 |
| 379 uint32_t ConvertIceTransportTypeToCandidateFilter( |
| 380 PeerConnectionInterface::IceTransportsType type) { |
| 381 switch (type) { |
| 382 case PeerConnectionInterface::kNone: |
| 383 return cricket::CF_NONE; |
| 384 case PeerConnectionInterface::kRelay: |
| 385 return cricket::CF_RELAY; |
| 386 case PeerConnectionInterface::kNoHost: |
| 387 return (cricket::CF_ALL & ~cricket::CF_HOST); |
| 388 case PeerConnectionInterface::kAll: |
| 389 return cricket::CF_ALL; |
| 390 default: |
| 391 ASSERT(false); |
| 392 } |
| 393 return cricket::CF_NONE; |
| 394 } |
| 395 |
379 } // namespace | 396 } // namespace |
380 | 397 |
381 namespace webrtc { | 398 namespace webrtc { |
382 | 399 |
383 // Generate a RTCP CNAME when a PeerConnection is created. | 400 // Generate a RTCP CNAME when a PeerConnection is created. |
384 std::string GenerateRtcpCname() { | 401 std::string GenerateRtcpCname() { |
385 std::string cname; | 402 std::string cname; |
386 if (!rtc::CreateRandomString(kRtcpCnameLength, &cname)) { | 403 if (!rtc::CreateRandomString(kRtcpCnameLength, &cname)) { |
387 LOG(LS_ERROR) << "Failed to generate CNAME."; | 404 LOG(LS_ERROR) << "Failed to generate CNAME."; |
388 RTC_DCHECK(false); | 405 RTC_DCHECK(false); |
(...skipping 140 matching lines...) Loading... |
529 TRACE_EVENT0("webrtc", "PeerConnection::~PeerConnection"); | 546 TRACE_EVENT0("webrtc", "PeerConnection::~PeerConnection"); |
530 RTC_DCHECK(signaling_thread()->IsCurrent()); | 547 RTC_DCHECK(signaling_thread()->IsCurrent()); |
531 // Need to detach RTP senders/receivers from WebRtcSession, | 548 // Need to detach RTP senders/receivers from WebRtcSession, |
532 // since it's about to be destroyed. | 549 // since it's about to be destroyed. |
533 for (const auto& sender : senders_) { | 550 for (const auto& sender : senders_) { |
534 sender->Stop(); | 551 sender->Stop(); |
535 } | 552 } |
536 for (const auto& receiver : receivers_) { | 553 for (const auto& receiver : receivers_) { |
537 receiver->Stop(); | 554 receiver->Stop(); |
538 } | 555 } |
| 556 // Destroy stats_ because it depends on session_. |
| 557 stats_.reset(nullptr); |
| 558 // Now destroy session_ before destroying other members, |
| 559 // because its destruction fires signals (such as VoiceChannelDestroyed) |
| 560 // which will trigger some final actions in PeerConnection... |
| 561 session_.reset(nullptr); |
| 562 // port_allocator_ lives on the worker thread and should be destroyed there. |
| 563 worker_thread()->Invoke<void>([this] { port_allocator_.reset(nullptr); }); |
539 } | 564 } |
540 | 565 |
541 bool PeerConnection::Initialize( | 566 bool PeerConnection::Initialize( |
542 const PeerConnectionInterface::RTCConfiguration& configuration, | 567 const PeerConnectionInterface::RTCConfiguration& configuration, |
543 std::unique_ptr<cricket::PortAllocator> allocator, | 568 std::unique_ptr<cricket::PortAllocator> allocator, |
544 std::unique_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | 569 std::unique_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
545 PeerConnectionObserver* observer) { | 570 PeerConnectionObserver* observer) { |
546 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); | 571 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); |
547 RTC_DCHECK(observer != nullptr); | 572 RTC_DCHECK(observer != nullptr); |
548 if (!observer) { | 573 if (!observer) { |
549 return false; | 574 return false; |
550 } | 575 } |
551 observer_ = observer; | 576 observer_ = observer; |
552 | 577 |
553 port_allocator_ = std::move(allocator); | 578 port_allocator_ = std::move(allocator); |
554 | 579 |
555 cricket::ServerAddresses stun_servers; | 580 // The port allocator lives on the worker thread and should be initialized |
556 std::vector<cricket::RelayServerConfig> turn_servers; | 581 // there. |
557 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { | 582 if (!worker_thread()->Invoke<bool>(rtc::Bind( |
| 583 &PeerConnection::InitializePortAllocator_w, this, configuration))) { |
558 return false; | 584 return false; |
559 } | 585 } |
560 port_allocator_->SetIceServers(stun_servers, turn_servers); | |
561 | |
562 // To handle both internal and externally created port allocator, we will | |
563 // enable BUNDLE here. | |
564 int portallocator_flags = port_allocator_->flags(); | |
565 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | |
566 cricket::PORTALLOCATOR_ENABLE_IPV6; | |
567 // If the disable-IPv6 flag was specified, we'll not override it | |
568 // by experiment. | |
569 if (configuration.disable_ipv6) { | |
570 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); | |
571 } else if (webrtc::field_trial::FindFullName("WebRTC-IPv6Default") == | |
572 "Disabled") { | |
573 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); | |
574 } | |
575 | |
576 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) { | |
577 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; | |
578 LOG(LS_INFO) << "TCP candidates are disabled."; | |
579 } | |
580 | |
581 port_allocator_->set_flags(portallocator_flags); | |
582 // No step delay is used while allocating ports. | |
583 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); | |
584 | 586 |
585 media_controller_.reset( | 587 media_controller_.reset( |
586 factory_->CreateMediaController(configuration.media_config)); | 588 factory_->CreateMediaController(configuration.media_config)); |
587 | 589 |
588 session_.reset( | 590 session_.reset( |
589 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), | 591 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), |
590 factory_->worker_thread(), port_allocator_.get())); | 592 factory_->worker_thread(), port_allocator_.get())); |
591 stats_.reset(new StatsCollector(this)); | 593 stats_.reset(new StatsCollector(this)); |
592 | 594 |
593 // Initialize the WebRtcSession. It creates transport channels etc. | 595 // Initialize the WebRtcSession. It creates transport channels etc. |
(...skipping 557 matching lines...) Loading... |
1151 stats_->AddStream(new_stream); | 1153 stats_->AddStream(new_stream); |
1152 observer_->OnAddStream(new_stream); | 1154 observer_->OnAddStream(new_stream); |
1153 } | 1155 } |
1154 | 1156 |
1155 UpdateEndedRemoteMediaStreams(); | 1157 UpdateEndedRemoteMediaStreams(); |
1156 | 1158 |
1157 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); | 1159 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); |
1158 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); | 1160 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); |
1159 } | 1161 } |
1160 | 1162 |
1161 bool PeerConnection::SetConfiguration(const RTCConfiguration& config) { | 1163 bool PeerConnection::SetConfiguration(const RTCConfiguration& configuration) { |
1162 TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration"); | 1164 TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration"); |
1163 if (port_allocator_) { | 1165 if (port_allocator_) { |
1164 cricket::ServerAddresses stun_servers; | 1166 if (!worker_thread()->Invoke<bool>( |
1165 std::vector<cricket::RelayServerConfig> turn_servers; | 1167 rtc::Bind(&PeerConnection::ReconfigurePortAllocator_w, this, |
1166 if (!ParseIceServers(config.servers, &stun_servers, &turn_servers)) { | 1168 configuration))) { |
1167 return false; | 1169 return false; |
1168 } | 1170 } |
1169 port_allocator_->SetIceServers(stun_servers, turn_servers); | |
1170 } | 1171 } |
1171 session_->SetIceConfig(session_->ParseIceConfig(config)); | 1172 |
1172 return session_->SetIceTransports(config.type); | 1173 // TODO(deadbeef): Shouldn't have to hop to the worker thread twice... |
| 1174 session_->SetIceConfig(session_->ParseIceConfig(configuration)); |
| 1175 return true; |
1173 } | 1176 } |
1174 | 1177 |
1175 bool PeerConnection::AddIceCandidate( | 1178 bool PeerConnection::AddIceCandidate( |
1176 const IceCandidateInterface* ice_candidate) { | 1179 const IceCandidateInterface* ice_candidate) { |
1177 TRACE_EVENT0("webrtc", "PeerConnection::AddIceCandidate"); | 1180 TRACE_EVENT0("webrtc", "PeerConnection::AddIceCandidate"); |
1178 return session_->ProcessIceMessage(ice_candidate); | 1181 return session_->ProcessIceMessage(ice_candidate); |
1179 } | 1182 } |
1180 | 1183 |
1181 bool PeerConnection::RemoveIceCandidates( | 1184 bool PeerConnection::RemoveIceCandidates( |
1182 const std::vector<cricket::Candidate>& candidates) { | 1185 const std::vector<cricket::Candidate>& candidates) { |
(...skipping 894 matching lines...) Loading... |
2077 | 2080 |
2078 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { | 2081 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { |
2079 for (const auto& channel : sctp_data_channels_) { | 2082 for (const auto& channel : sctp_data_channels_) { |
2080 if (channel->id() == sid) { | 2083 if (channel->id() == sid) { |
2081 return channel; | 2084 return channel; |
2082 } | 2085 } |
2083 } | 2086 } |
2084 return nullptr; | 2087 return nullptr; |
2085 } | 2088 } |
2086 | 2089 |
| 2090 bool PeerConnection::InitializePortAllocator_w( |
| 2091 const RTCConfiguration& configuration) { |
| 2092 cricket::ServerAddresses stun_servers; |
| 2093 std::vector<cricket::RelayServerConfig> turn_servers; |
| 2094 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { |
| 2095 return false; |
| 2096 } |
| 2097 |
| 2098 // To handle both internal and externally created port allocator, we will |
| 2099 // enable BUNDLE here. |
| 2100 int portallocator_flags = port_allocator_->flags(); |
| 2101 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
| 2102 cricket::PORTALLOCATOR_ENABLE_IPV6; |
| 2103 // If the disable-IPv6 flag was specified, we'll not override it |
| 2104 // by experiment. |
| 2105 if (configuration.disable_ipv6) { |
| 2106 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 2107 } else if (webrtc::field_trial::FindFullName("WebRTC-IPv6Default") == |
| 2108 "Disabled") { |
| 2109 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 2110 } |
| 2111 |
| 2112 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) { |
| 2113 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; |
| 2114 LOG(LS_INFO) << "TCP candidates are disabled."; |
| 2115 } |
| 2116 |
| 2117 port_allocator_->set_flags(portallocator_flags); |
| 2118 // No step delay is used while allocating ports. |
| 2119 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); |
| 2120 port_allocator_->set_candidate_filter( |
| 2121 ConvertIceTransportTypeToCandidateFilter(configuration.type)); |
| 2122 |
| 2123 // Call this last since it may create pooled allocator sessions using the |
| 2124 // properties set above. |
| 2125 port_allocator_->SetConfiguration(stun_servers, turn_servers, |
| 2126 configuration.ice_candidate_pool_size); |
| 2127 return true; |
| 2128 } |
| 2129 |
| 2130 bool PeerConnection::ReconfigurePortAllocator_w( |
| 2131 const RTCConfiguration& configuration) { |
| 2132 cricket::ServerAddresses stun_servers; |
| 2133 std::vector<cricket::RelayServerConfig> turn_servers; |
| 2134 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { |
| 2135 return false; |
| 2136 } |
| 2137 port_allocator_->set_candidate_filter( |
| 2138 ConvertIceTransportTypeToCandidateFilter(configuration.type)); |
| 2139 // Call this last since it may create pooled allocator sessions using the |
| 2140 // candidate filter set above. |
| 2141 port_allocator_->SetConfiguration(stun_servers, turn_servers, |
| 2142 configuration.ice_candidate_pool_size); |
| 2143 return true; |
| 2144 } |
| 2145 |
2087 } // namespace webrtc | 2146 } // namespace webrtc |
OLD | NEW |