Chromium Code Reviews| 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 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 session_options->audio_transport_options.ice_restart = | 447 session_options->audio_transport_options.ice_restart = |
| 448 rtc_options.ice_restart; | 448 rtc_options.ice_restart; |
| 449 session_options->video_transport_options.ice_restart = | 449 session_options->video_transport_options.ice_restart = |
| 450 rtc_options.ice_restart; | 450 rtc_options.ice_restart; |
| 451 session_options->data_transport_options.ice_restart = rtc_options.ice_restart; | 451 session_options->data_transport_options.ice_restart = rtc_options.ice_restart; |
| 452 session_options->bundle_enabled = rtc_options.use_rtp_mux; | 452 session_options->bundle_enabled = rtc_options.use_rtp_mux; |
| 453 | 453 |
| 454 return true; | 454 return true; |
| 455 } | 455 } |
| 456 | 456 |
| 457 bool ConvertRtcOptionsForAnswer( | |
| 458 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, | |
| 459 cricket::MediaSessionOptions* session_options) { | |
| 460 // TODO(hta): Figure out if there's a difference | |
| 461 return ConvertRtcOptionsForOffer(rtc_options, session_options); | |
| 462 } | |
| 463 | |
| 457 bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints, | 464 bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints, |
| 458 cricket::MediaSessionOptions* session_options) { | 465 cricket::MediaSessionOptions* session_options) { |
| 459 bool value = false; | 466 bool value = false; |
| 460 size_t mandatory_constraints_satisfied = 0; | 467 size_t mandatory_constraints_satisfied = 0; |
| 461 | 468 |
| 462 // kOfferToReceiveAudio defaults to true according to spec. | 469 // kOfferToReceiveAudio defaults to true according to spec. |
| 463 if (!FindConstraint(constraints, | 470 if (!FindConstraint(constraints, |
| 464 MediaConstraintsInterface::kOfferToReceiveAudio, &value, | 471 MediaConstraintsInterface::kOfferToReceiveAudio, &value, |
| 465 &mandatory_constraints_satisfied) || | 472 &mandatory_constraints_satisfied) || |
| 466 value) { | 473 value) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 for (const auto& sender : senders_) { | 570 for (const auto& sender : senders_) { |
| 564 sender->Stop(); | 571 sender->Stop(); |
| 565 } | 572 } |
| 566 for (const auto& receiver : receivers_) { | 573 for (const auto& receiver : receivers_) { |
| 567 receiver->Stop(); | 574 receiver->Stop(); |
| 568 } | 575 } |
| 569 } | 576 } |
| 570 | 577 |
| 571 bool PeerConnection::Initialize( | 578 bool PeerConnection::Initialize( |
| 572 const PeerConnectionInterface::RTCConfiguration& configuration, | 579 const PeerConnectionInterface::RTCConfiguration& configuration, |
| 573 const MediaConstraintsInterface* constraints, | |
| 574 rtc::scoped_ptr<cricket::PortAllocator> allocator, | 580 rtc::scoped_ptr<cricket::PortAllocator> allocator, |
| 575 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | 581 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
| 576 PeerConnectionObserver* observer) { | 582 PeerConnectionObserver* observer) { |
| 577 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); | 583 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); |
| 578 RTC_DCHECK(observer != nullptr); | 584 RTC_DCHECK(observer != nullptr); |
| 579 if (!observer) { | 585 if (!observer) { |
| 580 return false; | 586 return false; |
| 581 } | 587 } |
| 582 observer_ = observer; | 588 observer_ = observer; |
| 583 | 589 |
| 584 port_allocator_ = std::move(allocator); | 590 port_allocator_ = std::move(allocator); |
| 585 | 591 |
| 586 cricket::ServerAddresses stun_servers; | 592 cricket::ServerAddresses stun_servers; |
| 587 std::vector<cricket::RelayServerConfig> turn_servers; | 593 std::vector<cricket::RelayServerConfig> turn_servers; |
| 588 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { | 594 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { |
| 589 return false; | 595 return false; |
| 590 } | 596 } |
| 591 port_allocator_->SetIceServers(stun_servers, turn_servers); | 597 port_allocator_->SetIceServers(stun_servers, turn_servers); |
| 592 | 598 |
| 593 // To handle both internal and externally created port allocator, we will | 599 // To handle both internal and externally created port allocator, we will |
| 594 // enable BUNDLE here. | 600 // enable BUNDLE here. |
| 595 int portallocator_flags = port_allocator_->flags(); | 601 int portallocator_flags = port_allocator_->flags(); |
| 596 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 602 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
| 597 cricket::PORTALLOCATOR_ENABLE_IPV6; | 603 cricket::PORTALLOCATOR_ENABLE_IPV6; |
| 598 bool value; | |
| 599 // If IPv6 flag was specified, we'll not override it by experiment. | 604 // If IPv6 flag was specified, we'll not override it by experiment. |
| 600 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6, | 605 if (configuration.disable_ipv6) { |
| 601 &value, nullptr)) { | 606 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 602 if (!value) { | |
| 603 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); | |
| 604 } | |
| 605 } else if (webrtc::field_trial::FindFullName("WebRTC-IPv6Default") == | 607 } else if (webrtc::field_trial::FindFullName("WebRTC-IPv6Default") == |
| 606 "Disabled") { | 608 "Disabled") { |
| 607 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); | 609 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 608 } | 610 } |
| 609 | 611 |
| 610 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) { | 612 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) { |
| 611 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; | 613 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; |
| 612 LOG(LS_INFO) << "TCP candidates are disabled."; | 614 LOG(LS_INFO) << "TCP candidates are disabled."; |
| 613 } | 615 } |
| 614 | 616 |
| 615 port_allocator_->set_flags(portallocator_flags); | 617 port_allocator_->set_flags(portallocator_flags); |
| 616 // No step delay is used while allocating ports. | 618 // No step delay is used while allocating ports. |
| 617 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); | 619 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); |
| 618 | 620 |
| 619 // We rely on default values when constraints aren't found. | 621 // We rely on default values when constraints aren't found. |
| 620 cricket::MediaConfig media_config; | 622 cricket::MediaConfig media_config; |
| 621 | 623 |
| 622 media_config.disable_prerenderer_smoothing = | 624 media_config.disable_prerenderer_smoothing = |
| 623 configuration.disable_prerenderer_smoothing; | 625 configuration.disable_prerenderer_smoothing; |
| 624 | 626 |
| 625 // Find DSCP constraint. | 627 // Find DSCP constraint. |
| 626 FindConstraint(constraints, MediaConstraintsInterface::kEnableDscp, | 628 if (configuration.override_dscp) { |
| 627 &media_config.enable_dscp, NULL); | 629 media_config.enable_dscp = configuration.enable_dscp; |
| 630 } | |
| 628 // Find constraints for cpu overuse detection. | 631 // Find constraints for cpu overuse detection. |
| 629 FindConstraint(constraints, MediaConstraintsInterface::kCpuOveruseDetection, | 632 if (configuration.override_cpu_overuse_detection) { |
| 630 &media_config.enable_cpu_overuse_detection, NULL); | 633 media_config.enable_cpu_overuse_detection = |
| 634 configuration.enable_cpu_overuse_detection; | |
| 635 } | |
| 631 | 636 |
| 632 media_controller_.reset(factory_->CreateMediaController(media_config)); | 637 media_controller_.reset(factory_->CreateMediaController(media_config)); |
| 633 | 638 |
| 634 remote_stream_factory_.reset(new RemoteMediaStreamFactory( | 639 remote_stream_factory_.reset(new RemoteMediaStreamFactory( |
| 635 factory_->signaling_thread(), media_controller_->channel_manager())); | 640 factory_->signaling_thread(), media_controller_->channel_manager())); |
| 636 | 641 |
| 637 session_.reset( | 642 session_.reset( |
| 638 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), | 643 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), |
| 639 factory_->worker_thread(), port_allocator_.get())); | 644 factory_->worker_thread(), port_allocator_.get())); |
| 640 stats_.reset(new StatsCollector(this)); | 645 stats_.reset(new StatsCollector(this)); |
| 641 | 646 |
| 642 // Initialize the WebRtcSession. It creates transport channels etc. | 647 // Initialize the WebRtcSession. It creates transport channels etc. |
| 643 if (!session_->Initialize(factory_->options(), constraints, | 648 if (!session_->Initialize(factory_->options(), std::move(dtls_identity_store), |
| 644 std::move(dtls_identity_store), configuration)) { | 649 configuration)) { |
| 645 return false; | 650 return false; |
| 646 } | 651 } |
| 647 | 652 |
| 648 // Register PeerConnection as receiver of local ice candidates. | 653 // Register PeerConnection as receiver of local ice candidates. |
| 649 // All the callbacks will be posted to the application from PeerConnection. | 654 // All the callbacks will be posted to the application from PeerConnection. |
| 650 session_->RegisterIceObserver(this); | 655 session_->RegisterIceObserver(this); |
| 651 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); | 656 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); |
| 652 session_->SignalVoiceChannelDestroyed.connect( | 657 session_->SignalVoiceChannelDestroyed.connect( |
| 653 this, &PeerConnection::OnVoiceChannelDestroyed); | 658 this, &PeerConnection::OnVoiceChannelDestroyed); |
| 654 session_->SignalVideoChannelDestroyed.connect( | 659 session_->SignalVideoChannelDestroyed.connect( |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 998 } | 1003 } |
| 999 | 1004 |
| 1000 cricket::MediaSessionOptions session_options; | 1005 cricket::MediaSessionOptions session_options; |
| 1001 if (!GetOptionsForAnswer(constraints, &session_options)) { | 1006 if (!GetOptionsForAnswer(constraints, &session_options)) { |
| 1002 std::string error = "CreateAnswer called with invalid constraints."; | 1007 std::string error = "CreateAnswer called with invalid constraints."; |
| 1003 LOG(LS_ERROR) << error; | 1008 LOG(LS_ERROR) << error; |
| 1004 PostCreateSessionDescriptionFailure(observer, error); | 1009 PostCreateSessionDescriptionFailure(observer, error); |
| 1005 return; | 1010 return; |
| 1006 } | 1011 } |
| 1007 | 1012 |
| 1008 session_->CreateAnswer(observer, constraints, session_options); | 1013 session_->CreateAnswer(observer, session_options); |
| 1014 } | |
| 1015 | |
| 1016 void PeerConnection::CreateAnswer(CreateSessionDescriptionObserver* observer, | |
| 1017 const RTCOfferAnswerOptions& options) { | |
| 1018 TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer"); | |
| 1019 if (!VERIFY(observer != nullptr)) { | |
| 1020 LOG(LS_ERROR) << "CreateAnswer - observer is NULL."; | |
| 1021 return; | |
| 1022 } | |
| 1023 | |
| 1024 cricket::MediaSessionOptions session_options; | |
| 1025 if (!GetOptionsForAnswer(options, &session_options)) { | |
| 1026 std::string error = "CreateAnswer called with invalid options."; | |
| 1027 LOG(LS_ERROR) << error; | |
| 1028 PostCreateSessionDescriptionFailure(observer, error); | |
| 1029 return; | |
| 1030 } | |
| 1031 | |
| 1032 session_->CreateAnswer(observer, session_options); | |
| 1009 } | 1033 } |
| 1010 | 1034 |
| 1011 void PeerConnection::SetLocalDescription( | 1035 void PeerConnection::SetLocalDescription( |
| 1012 SetSessionDescriptionObserver* observer, | 1036 SetSessionDescriptionObserver* observer, |
| 1013 SessionDescriptionInterface* desc) { | 1037 SessionDescriptionInterface* desc) { |
| 1014 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); | 1038 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); |
| 1015 if (!VERIFY(observer != nullptr)) { | 1039 if (!VERIFY(observer != nullptr)) { |
| 1016 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL."; | 1040 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL."; |
| 1017 return; | 1041 return; |
| 1018 } | 1042 } |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1545 | 1569 |
| 1546 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams | 1570 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams |
| 1547 // are not signaled in the SDP so does not go through that path and must be | 1571 // are not signaled in the SDP so does not go through that path and must be |
| 1548 // handled here. | 1572 // handled here. |
| 1549 if (session_->data_channel_type() == cricket::DCT_SCTP) { | 1573 if (session_->data_channel_type() == cricket::DCT_SCTP) { |
| 1550 session_options->data_channel_type = cricket::DCT_SCTP; | 1574 session_options->data_channel_type = cricket::DCT_SCTP; |
| 1551 } | 1575 } |
| 1552 return true; | 1576 return true; |
| 1553 } | 1577 } |
| 1554 | 1578 |
| 1579 bool PeerConnection::GetOptionsForAnswer( | |
| 1580 const RTCOfferAnswerOptions& options, | |
| 1581 cricket::MediaSessionOptions* session_options) { | |
| 1582 session_options->recv_audio = false; | |
| 1583 session_options->recv_video = false; | |
| 1584 if (!ConvertRtcOptionsForAnswer(options, session_options)) { | |
|
perkj_webrtc
2016/02/23 11:40:18
This is code duplication. Please create a helper m
hta-webrtc
2016/02/23 14:30:34
Done. We can inline it again when there's only one
| |
| 1585 return false; | |
| 1586 } | |
| 1587 | |
| 1588 AddSendStreams(session_options, senders_, rtp_data_channels_); | |
| 1589 session_options->bundle_enabled = | |
| 1590 session_options->bundle_enabled && | |
| 1591 (session_options->has_audio() || session_options->has_video() || | |
| 1592 session_options->has_data()); | |
| 1593 | |
| 1594 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams | |
| 1595 // are not signaled in the SDP so does not go through that path and must be | |
| 1596 // handled here. | |
| 1597 if (session_->data_channel_type() == cricket::DCT_SCTP) { | |
| 1598 session_options->data_channel_type = cricket::DCT_SCTP; | |
| 1599 } | |
| 1600 return true; | |
| 1601 } | |
| 1602 | |
| 1555 void PeerConnection::RemoveTracks(cricket::MediaType media_type) { | 1603 void PeerConnection::RemoveTracks(cricket::MediaType media_type) { |
| 1556 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); | 1604 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); |
| 1557 UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false, | 1605 UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false, |
| 1558 media_type, nullptr); | 1606 media_type, nullptr); |
| 1559 } | 1607 } |
| 1560 | 1608 |
| 1561 void PeerConnection::UpdateRemoteStreamsList( | 1609 void PeerConnection::UpdateRemoteStreamsList( |
| 1562 const cricket::StreamParamsVec& streams, | 1610 const cricket::StreamParamsVec& streams, |
| 1563 bool default_track_needed, | 1611 bool default_track_needed, |
| 1564 cricket::MediaType media_type, | 1612 cricket::MediaType media_type, |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2077 | 2125 |
| 2078 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { | 2126 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { |
| 2079 for (const auto& channel : sctp_data_channels_) { | 2127 for (const auto& channel : sctp_data_channels_) { |
| 2080 if (channel->id() == sid) { | 2128 if (channel->id() == sid) { |
| 2081 return channel; | 2129 return channel; |
| 2082 } | 2130 } |
| 2083 } | 2131 } |
| 2084 return nullptr; | 2132 return nullptr; |
| 2085 } | 2133 } |
| 2086 | 2134 |
| 2135 void CopyConstraintsIntoRtcConfiguration( | |
|
perkj_webrtc
2016/02/23 11:40:18
Please move this to the factory where it is used i
hta-webrtc
2016/02/23 14:30:34
The other user is webrtcsession_unittest, which do
| |
| 2136 const MediaConstraintsInterface* constraints, | |
| 2137 PeerConnectionInterface::RTCConfiguration* configuration) { | |
| 2138 // Copy info from constraints into configuration, if present. | |
| 2139 if (!constraints) { | |
| 2140 return; | |
| 2141 } | |
| 2142 | |
| 2143 bool value; | |
| 2144 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6, | |
| 2145 &value, nullptr)) { | |
| 2146 if (!value) { | |
| 2147 configuration->disable_ipv6 = true; | |
| 2148 } | |
| 2149 } | |
| 2150 // Find DSCP constraint. | |
| 2151 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableDscp, | |
| 2152 &configuration->enable_dscp, NULL)) { | |
| 2153 configuration->override_dscp = true; | |
| 2154 } | |
| 2155 // Find constraints for cpu overuse detection. | |
| 2156 if (FindConstraint(constraints, | |
| 2157 MediaConstraintsInterface::kCpuOveruseDetection, | |
| 2158 &configuration->enable_cpu_overuse_detection, NULL)) { | |
| 2159 configuration->override_cpu_overuse_detection = true; | |
| 2160 } | |
| 2161 if (FindConstraint(constraints, | |
| 2162 MediaConstraintsInterface::kEnableRtpDataChannels, &value, | |
| 2163 NULL) && | |
| 2164 value) { | |
| 2165 configuration->enable_rtp_data_channel = true; | |
| 2166 } | |
| 2167 // Find Suspend Below Min Bitrate constraint. | |
| 2168 if (FindConstraint( | |
| 2169 constraints, | |
| 2170 MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, | |
| 2171 &configuration->suspend_below_min_bitrate, NULL)) { | |
| 2172 configuration->override_suspend_below_min_bitrate = true; | |
| 2173 } | |
| 2174 if (FindConstraint(constraints, | |
| 2175 MediaConstraintsInterface::kScreencastMinBitrate, | |
| 2176 &configuration->screencast_min_bitrate, NULL)) { | |
| 2177 configuration->override_screencast_min_bitrate = true; | |
| 2178 } | |
| 2179 if (FindConstraint(constraints, | |
| 2180 MediaConstraintsInterface::kCombinedAudioVideoBwe, &value, | |
| 2181 NULL)) { | |
| 2182 configuration->override_combined_audio_video_bwe = true; | |
| 2183 configuration->combined_audio_video_bwe = value; | |
| 2184 } | |
| 2185 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2186 &value, NULL)) { | |
| 2187 configuration->override_enable_dtls_srtp = true; | |
| 2188 configuration->enable_dtls_srtp = value; | |
| 2189 } | |
| 2190 } | |
| 2191 | |
| 2087 } // namespace webrtc | 2192 } // namespace webrtc |
| OLD | NEW |