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...) Expand 10 before | Expand all | Expand 10 after 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 | |
396 } // namespace | 379 } // namespace |
397 | 380 |
398 namespace webrtc { | 381 namespace webrtc { |
399 | 382 |
400 // Generate a RTCP CNAME when a PeerConnection is created. | 383 // Generate a RTCP CNAME when a PeerConnection is created. |
401 std::string GenerateRtcpCname() { | 384 std::string GenerateRtcpCname() { |
402 std::string cname; | 385 std::string cname; |
403 if (!rtc::CreateRandomString(kRtcpCnameLength, &cname)) { | 386 if (!rtc::CreateRandomString(kRtcpCnameLength, &cname)) { |
404 LOG(LS_ERROR) << "Failed to generate CNAME."; | 387 LOG(LS_ERROR) << "Failed to generate CNAME."; |
405 RTC_DCHECK(false); | 388 RTC_DCHECK(false); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 TRACE_EVENT0("webrtc", "PeerConnection::~PeerConnection"); | 529 TRACE_EVENT0("webrtc", "PeerConnection::~PeerConnection"); |
547 RTC_DCHECK(signaling_thread()->IsCurrent()); | 530 RTC_DCHECK(signaling_thread()->IsCurrent()); |
548 // Need to detach RTP senders/receivers from WebRtcSession, | 531 // Need to detach RTP senders/receivers from WebRtcSession, |
549 // since it's about to be destroyed. | 532 // since it's about to be destroyed. |
550 for (const auto& sender : senders_) { | 533 for (const auto& sender : senders_) { |
551 sender->Stop(); | 534 sender->Stop(); |
552 } | 535 } |
553 for (const auto& receiver : receivers_) { | 536 for (const auto& receiver : receivers_) { |
554 receiver->Stop(); | 537 receiver->Stop(); |
555 } | 538 } |
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); }); | |
564 } | 539 } |
565 | 540 |
566 bool PeerConnection::Initialize( | 541 bool PeerConnection::Initialize( |
567 const PeerConnectionInterface::RTCConfiguration& configuration, | 542 const PeerConnectionInterface::RTCConfiguration& configuration, |
568 std::unique_ptr<cricket::PortAllocator> allocator, | 543 std::unique_ptr<cricket::PortAllocator> allocator, |
569 std::unique_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | 544 std::unique_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
570 PeerConnectionObserver* observer) { | 545 PeerConnectionObserver* observer) { |
571 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); | 546 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); |
572 RTC_DCHECK(observer != nullptr); | 547 RTC_DCHECK(observer != nullptr); |
573 if (!observer) { | 548 if (!observer) { |
574 return false; | 549 return false; |
575 } | 550 } |
576 observer_ = observer; | 551 observer_ = observer; |
577 | 552 |
578 port_allocator_ = std::move(allocator); | 553 port_allocator_ = std::move(allocator); |
579 | 554 |
580 // The port allocator lives on the worker thread and should be initialized | 555 cricket::ServerAddresses stun_servers; |
581 // there. | 556 std::vector<cricket::RelayServerConfig> turn_servers; |
582 if (!worker_thread()->Invoke<bool>(rtc::Bind( | 557 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { |
583 &PeerConnection::InitializePortAllocator_w, this, configuration))) { | |
584 return false; | 558 return false; |
585 } | 559 } |
| 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); |
586 | 584 |
587 media_controller_.reset( | 585 media_controller_.reset( |
588 factory_->CreateMediaController(configuration.media_config)); | 586 factory_->CreateMediaController(configuration.media_config)); |
589 | 587 |
590 session_.reset( | 588 session_.reset( |
591 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), | 589 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), |
592 factory_->worker_thread(), port_allocator_.get())); | 590 factory_->worker_thread(), port_allocator_.get())); |
593 stats_.reset(new StatsCollector(this)); | 591 stats_.reset(new StatsCollector(this)); |
594 | 592 |
595 // Initialize the WebRtcSession. It creates transport channels etc. | 593 // Initialize the WebRtcSession. It creates transport channels etc. |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 stats_->AddStream(new_stream); | 1151 stats_->AddStream(new_stream); |
1154 observer_->OnAddStream(new_stream); | 1152 observer_->OnAddStream(new_stream); |
1155 } | 1153 } |
1156 | 1154 |
1157 UpdateEndedRemoteMediaStreams(); | 1155 UpdateEndedRemoteMediaStreams(); |
1158 | 1156 |
1159 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); | 1157 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); |
1160 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); | 1158 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); |
1161 } | 1159 } |
1162 | 1160 |
1163 bool PeerConnection::SetConfiguration(const RTCConfiguration& configuration) { | 1161 bool PeerConnection::SetConfiguration(const RTCConfiguration& config) { |
1164 TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration"); | 1162 TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration"); |
1165 if (port_allocator_) { | 1163 if (port_allocator_) { |
1166 if (!worker_thread()->Invoke<bool>( | 1164 cricket::ServerAddresses stun_servers; |
1167 rtc::Bind(&PeerConnection::ReconfigurePortAllocator_w, this, | 1165 std::vector<cricket::RelayServerConfig> turn_servers; |
1168 configuration))) { | 1166 if (!ParseIceServers(config.servers, &stun_servers, &turn_servers)) { |
1169 return false; | 1167 return false; |
1170 } | 1168 } |
| 1169 port_allocator_->SetIceServers(stun_servers, turn_servers); |
1171 } | 1170 } |
1172 | 1171 session_->SetIceConfig(session_->ParseIceConfig(config)); |
1173 // TODO(deadbeef): Shouldn't have to hop to the worker thread twice... | 1172 return session_->SetIceTransports(config.type); |
1174 session_->SetIceConfig(session_->ParseIceConfig(configuration)); | |
1175 return true; | |
1176 } | 1173 } |
1177 | 1174 |
1178 bool PeerConnection::AddIceCandidate( | 1175 bool PeerConnection::AddIceCandidate( |
1179 const IceCandidateInterface* ice_candidate) { | 1176 const IceCandidateInterface* ice_candidate) { |
1180 TRACE_EVENT0("webrtc", "PeerConnection::AddIceCandidate"); | 1177 TRACE_EVENT0("webrtc", "PeerConnection::AddIceCandidate"); |
1181 return session_->ProcessIceMessage(ice_candidate); | 1178 return session_->ProcessIceMessage(ice_candidate); |
1182 } | 1179 } |
1183 | 1180 |
1184 bool PeerConnection::RemoveIceCandidates( | 1181 bool PeerConnection::RemoveIceCandidates( |
1185 const std::vector<cricket::Candidate>& candidates) { | 1182 const std::vector<cricket::Candidate>& candidates) { |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2080 | 2077 |
2081 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { | 2078 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { |
2082 for (const auto& channel : sctp_data_channels_) { | 2079 for (const auto& channel : sctp_data_channels_) { |
2083 if (channel->id() == sid) { | 2080 if (channel->id() == sid) { |
2084 return channel; | 2081 return channel; |
2085 } | 2082 } |
2086 } | 2083 } |
2087 return nullptr; | 2084 return nullptr; |
2088 } | 2085 } |
2089 | 2086 |
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 | |
2146 } // namespace webrtc | 2087 } // namespace webrtc |
OLD | NEW |