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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 | 445 |
446 session_options->vad_enabled = rtc_options.voice_activity_detection; | 446 session_options->vad_enabled = rtc_options.voice_activity_detection; |
447 session_options->bundle_enabled = rtc_options.use_rtp_mux; | 447 session_options->bundle_enabled = rtc_options.use_rtp_mux; |
448 for (auto& kv : session_options->transport_options) { | 448 for (auto& kv : session_options->transport_options) { |
449 kv.second.ice_restart = rtc_options.ice_restart; | 449 kv.second.ice_restart = rtc_options.ice_restart; |
450 } | 450 } |
451 | 451 |
452 return true; | 452 return true; |
453 } | 453 } |
454 | 454 |
455 bool ConvertRtcOptionsForAnswer( | |
456 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, | |
457 cricket::MediaSessionOptions* session_options) { | |
458 // TODO(hta): Figure out if there's a difference | |
nisse-webrtc
2016/02/26 08:53:45
Will you figure it out before landing?
hta-webrtc
2016/02/29 11:09:48
Yes, I've decided that there is no difference we c
| |
459 return ConvertRtcOptionsForOffer(rtc_options, session_options); | |
460 } | |
461 | |
455 bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints, | 462 bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints, |
456 cricket::MediaSessionOptions* session_options) { | 463 cricket::MediaSessionOptions* session_options) { |
457 bool value = false; | 464 bool value = false; |
458 size_t mandatory_constraints_satisfied = 0; | 465 size_t mandatory_constraints_satisfied = 0; |
459 | 466 |
460 // kOfferToReceiveAudio defaults to true according to spec. | 467 // kOfferToReceiveAudio defaults to true according to spec. |
461 if (!FindConstraint(constraints, | 468 if (!FindConstraint(constraints, |
462 MediaConstraintsInterface::kOfferToReceiveAudio, &value, | 469 MediaConstraintsInterface::kOfferToReceiveAudio, &value, |
463 &mandatory_constraints_satisfied) || | 470 &mandatory_constraints_satisfied) || |
464 value) { | 471 value) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 // since it's about to be destroyed. | 565 // since it's about to be destroyed. |
559 for (const auto& sender : senders_) { | 566 for (const auto& sender : senders_) { |
560 sender->Stop(); | 567 sender->Stop(); |
561 } | 568 } |
562 for (const auto& receiver : receivers_) { | 569 for (const auto& receiver : receivers_) { |
563 receiver->Stop(); | 570 receiver->Stop(); |
564 } | 571 } |
565 } | 572 } |
566 | 573 |
567 bool PeerConnection::Initialize( | 574 bool PeerConnection::Initialize( |
575 const cricket::MediaConfig& media_config, | |
568 const PeerConnectionInterface::RTCConfiguration& configuration, | 576 const PeerConnectionInterface::RTCConfiguration& configuration, |
569 const MediaConstraintsInterface* constraints, | |
570 rtc::scoped_ptr<cricket::PortAllocator> allocator, | 577 rtc::scoped_ptr<cricket::PortAllocator> allocator, |
571 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | 578 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
572 PeerConnectionObserver* observer) { | 579 PeerConnectionObserver* observer) { |
573 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); | 580 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); |
574 RTC_DCHECK(observer != nullptr); | 581 RTC_DCHECK(observer != nullptr); |
575 if (!observer) { | 582 if (!observer) { |
576 return false; | 583 return false; |
577 } | 584 } |
578 observer_ = observer; | 585 observer_ = observer; |
579 | 586 |
580 port_allocator_ = std::move(allocator); | 587 port_allocator_ = std::move(allocator); |
581 | 588 |
582 cricket::ServerAddresses stun_servers; | 589 cricket::ServerAddresses stun_servers; |
583 std::vector<cricket::RelayServerConfig> turn_servers; | 590 std::vector<cricket::RelayServerConfig> turn_servers; |
584 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { | 591 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { |
585 return false; | 592 return false; |
586 } | 593 } |
587 port_allocator_->SetIceServers(stun_servers, turn_servers); | 594 port_allocator_->SetIceServers(stun_servers, turn_servers); |
588 | 595 |
589 // To handle both internal and externally created port allocator, we will | 596 // To handle both internal and externally created port allocator, we will |
590 // enable BUNDLE here. | 597 // enable BUNDLE here. |
591 int portallocator_flags = port_allocator_->flags(); | 598 int portallocator_flags = port_allocator_->flags(); |
592 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 599 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
593 cricket::PORTALLOCATOR_ENABLE_IPV6; | 600 cricket::PORTALLOCATOR_ENABLE_IPV6; |
594 bool value; | 601 // If the disable-IPv6 flag was specified, we'll not override it |
595 // If IPv6 flag was specified, we'll not override it by experiment. | 602 // by experiment. |
596 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6, | 603 if (configuration.disable_ipv6) { |
597 &value, nullptr)) { | 604 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); |
598 if (!value) { | |
599 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); | |
600 } | |
601 } else if (webrtc::field_trial::FindFullName("WebRTC-IPv6Default") == | 605 } else if (webrtc::field_trial::FindFullName("WebRTC-IPv6Default") == |
602 "Disabled") { | 606 "Disabled") { |
603 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); | 607 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); |
604 } | 608 } |
605 | 609 |
606 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) { | 610 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) { |
607 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; | 611 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; |
608 LOG(LS_INFO) << "TCP candidates are disabled."; | 612 LOG(LS_INFO) << "TCP candidates are disabled."; |
609 } | 613 } |
610 | 614 |
611 port_allocator_->set_flags(portallocator_flags); | 615 port_allocator_->set_flags(portallocator_flags); |
612 // No step delay is used while allocating ports. | 616 // No step delay is used while allocating ports. |
613 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); | 617 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); |
614 | 618 |
615 // We rely on default values when constraints aren't found. | |
616 cricket::MediaConfig media_config; | |
617 | |
618 media_config.disable_prerenderer_smoothing = | |
619 configuration.disable_prerenderer_smoothing; | |
620 | |
621 // Find DSCP constraint. | |
622 FindConstraint(constraints, MediaConstraintsInterface::kEnableDscp, | |
623 &media_config.enable_dscp, NULL); | |
624 // Find constraints for cpu overuse detection. | |
625 FindConstraint(constraints, MediaConstraintsInterface::kCpuOveruseDetection, | |
626 &media_config.enable_cpu_overuse_detection, NULL); | |
627 | |
628 media_controller_.reset(factory_->CreateMediaController(media_config)); | 619 media_controller_.reset(factory_->CreateMediaController(media_config)); |
629 | 620 |
630 remote_stream_factory_.reset(new RemoteMediaStreamFactory( | 621 remote_stream_factory_.reset(new RemoteMediaStreamFactory( |
631 factory_->signaling_thread(), media_controller_->channel_manager())); | 622 factory_->signaling_thread(), media_controller_->channel_manager())); |
632 | 623 |
633 session_.reset( | 624 session_.reset( |
634 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), | 625 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), |
635 factory_->worker_thread(), port_allocator_.get())); | 626 factory_->worker_thread(), port_allocator_.get())); |
636 stats_.reset(new StatsCollector(this)); | 627 stats_.reset(new StatsCollector(this)); |
637 | 628 |
638 // Initialize the WebRtcSession. It creates transport channels etc. | 629 // Initialize the WebRtcSession. It creates transport channels etc. |
639 if (!session_->Initialize(factory_->options(), constraints, | 630 if (!session_->Initialize(factory_->options(), std::move(dtls_identity_store), |
640 std::move(dtls_identity_store), configuration)) { | 631 configuration)) { |
641 return false; | 632 return false; |
642 } | 633 } |
643 | 634 |
644 // Register PeerConnection as receiver of local ice candidates. | 635 // Register PeerConnection as receiver of local ice candidates. |
645 // All the callbacks will be posted to the application from PeerConnection. | 636 // All the callbacks will be posted to the application from PeerConnection. |
646 session_->RegisterIceObserver(this); | 637 session_->RegisterIceObserver(this); |
647 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); | 638 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); |
648 session_->SignalVoiceChannelDestroyed.connect( | 639 session_->SignalVoiceChannelDestroyed.connect( |
649 this, &PeerConnection::OnVoiceChannelDestroyed); | 640 this, &PeerConnection::OnVoiceChannelDestroyed); |
650 session_->SignalVideoChannelDestroyed.connect( | 641 session_->SignalVideoChannelDestroyed.connect( |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
994 } | 985 } |
995 | 986 |
996 cricket::MediaSessionOptions session_options; | 987 cricket::MediaSessionOptions session_options; |
997 if (!GetOptionsForAnswer(constraints, &session_options)) { | 988 if (!GetOptionsForAnswer(constraints, &session_options)) { |
998 std::string error = "CreateAnswer called with invalid constraints."; | 989 std::string error = "CreateAnswer called with invalid constraints."; |
999 LOG(LS_ERROR) << error; | 990 LOG(LS_ERROR) << error; |
1000 PostCreateSessionDescriptionFailure(observer, error); | 991 PostCreateSessionDescriptionFailure(observer, error); |
1001 return; | 992 return; |
1002 } | 993 } |
1003 | 994 |
1004 session_->CreateAnswer(observer, constraints, session_options); | 995 session_->CreateAnswer(observer, session_options); |
996 } | |
997 | |
998 void PeerConnection::CreateAnswer(CreateSessionDescriptionObserver* observer, | |
999 const RTCOfferAnswerOptions& options) { | |
1000 TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer"); | |
1001 if (!VERIFY(observer != nullptr)) { | |
1002 LOG(LS_ERROR) << "CreateAnswer - observer is NULL."; | |
1003 return; | |
1004 } | |
1005 | |
1006 cricket::MediaSessionOptions session_options; | |
1007 if (!GetOptionsForAnswer(options, &session_options)) { | |
1008 std::string error = "CreateAnswer called with invalid options."; | |
1009 LOG(LS_ERROR) << error; | |
1010 PostCreateSessionDescriptionFailure(observer, error); | |
1011 return; | |
1012 } | |
1013 | |
1014 session_->CreateAnswer(observer, session_options); | |
1005 } | 1015 } |
1006 | 1016 |
1007 void PeerConnection::SetLocalDescription( | 1017 void PeerConnection::SetLocalDescription( |
1008 SetSessionDescriptionObserver* observer, | 1018 SetSessionDescriptionObserver* observer, |
1009 SessionDescriptionInterface* desc) { | 1019 SessionDescriptionInterface* desc) { |
1010 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); | 1020 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); |
1011 if (!VERIFY(observer != nullptr)) { | 1021 if (!VERIFY(observer != nullptr)) { |
1012 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL."; | 1022 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL."; |
1013 return; | 1023 return; |
1014 } | 1024 } |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1526 session_options->bundle_enabled && | 1536 session_options->bundle_enabled && |
1527 (session_options->has_audio() || session_options->has_video() || | 1537 (session_options->has_audio() || session_options->has_video() || |
1528 session_options->has_data()); | 1538 session_options->has_data()); |
1529 | 1539 |
1530 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) { | 1540 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) { |
1531 session_options->data_channel_type = cricket::DCT_SCTP; | 1541 session_options->data_channel_type = cricket::DCT_SCTP; |
1532 } | 1542 } |
1533 return true; | 1543 return true; |
1534 } | 1544 } |
1535 | 1545 |
1536 bool PeerConnection::GetOptionsForAnswer( | 1546 void PeerConnection::FinishOptionsForAnswer( |
1537 const MediaConstraintsInterface* constraints, | |
1538 cricket::MediaSessionOptions* session_options) { | 1547 cricket::MediaSessionOptions* session_options) { |
1539 session_options->recv_audio = false; | |
1540 session_options->recv_video = false; | |
1541 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of | 1548 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of |
1542 // ContentInfos. | 1549 // ContentInfos. |
1543 if (session_->remote_description()) { | 1550 if (session_->remote_description()) { |
1544 // Initialize the transport_options map. | 1551 // Initialize the transport_options map. |
1545 for (const cricket::ContentInfo& content : | 1552 for (const cricket::ContentInfo& content : |
1546 session_->remote_description()->description()->contents()) { | 1553 session_->remote_description()->description()->contents()) { |
1547 session_options->transport_options[content.name] = | 1554 session_options->transport_options[content.name] = |
1548 cricket::TransportOptions(); | 1555 cricket::TransportOptions(); |
1549 } | 1556 } |
1550 } | 1557 } |
1551 if (!ParseConstraintsForAnswer(constraints, session_options)) { | |
1552 return false; | |
1553 } | |
1554 | |
1555 AddSendStreams(session_options, senders_, rtp_data_channels_); | 1558 AddSendStreams(session_options, senders_, rtp_data_channels_); |
1556 session_options->bundle_enabled = | 1559 session_options->bundle_enabled = |
1557 session_options->bundle_enabled && | 1560 session_options->bundle_enabled && |
1558 (session_options->has_audio() || session_options->has_video() || | 1561 (session_options->has_audio() || session_options->has_video() || |
1559 session_options->has_data()); | 1562 session_options->has_data()); |
1560 | 1563 |
1561 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams | 1564 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams |
1562 // are not signaled in the SDP so does not go through that path and must be | 1565 // are not signaled in the SDP so does not go through that path and must be |
1563 // handled here. | 1566 // handled here. |
1564 if (session_->data_channel_type() == cricket::DCT_SCTP) { | 1567 if (session_->data_channel_type() == cricket::DCT_SCTP) { |
1565 session_options->data_channel_type = cricket::DCT_SCTP; | 1568 session_options->data_channel_type = cricket::DCT_SCTP; |
1566 } | 1569 } |
1570 } | |
1571 | |
1572 bool PeerConnection::GetOptionsForAnswer( | |
1573 const MediaConstraintsInterface* constraints, | |
1574 cricket::MediaSessionOptions* session_options) { | |
1575 session_options->recv_audio = false; | |
1576 session_options->recv_video = false; | |
1577 if (!ParseConstraintsForAnswer(constraints, session_options)) { | |
1578 return false; | |
1579 } | |
1580 FinishOptionsForAnswer(session_options); | |
1567 return true; | 1581 return true; |
1568 } | 1582 } |
1569 | 1583 |
1584 bool PeerConnection::GetOptionsForAnswer( | |
1585 const RTCOfferAnswerOptions& options, | |
1586 cricket::MediaSessionOptions* session_options) { | |
1587 session_options->recv_audio = false; | |
1588 session_options->recv_video = false; | |
1589 if (!ConvertRtcOptionsForAnswer(options, session_options)) { | |
1590 return false; | |
1591 } | |
1592 FinishOptionsForAnswer(session_options); | |
1593 return true; | |
1594 } | |
1595 | |
1570 void PeerConnection::RemoveTracks(cricket::MediaType media_type) { | 1596 void PeerConnection::RemoveTracks(cricket::MediaType media_type) { |
1571 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); | 1597 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); |
1572 UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false, | 1598 UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false, |
1573 media_type, nullptr); | 1599 media_type, nullptr); |
1574 } | 1600 } |
1575 | 1601 |
1576 void PeerConnection::UpdateRemoteStreamsList( | 1602 void PeerConnection::UpdateRemoteStreamsList( |
1577 const cricket::StreamParamsVec& streams, | 1603 const cricket::StreamParamsVec& streams, |
1578 bool default_track_needed, | 1604 bool default_track_needed, |
1579 cricket::MediaType media_type, | 1605 cricket::MediaType media_type, |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2092 | 2118 |
2093 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { | 2119 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { |
2094 for (const auto& channel : sctp_data_channels_) { | 2120 for (const auto& channel : sctp_data_channels_) { |
2095 if (channel->id() == sid) { | 2121 if (channel->id() == sid) { |
2096 return channel; | 2122 return channel; |
2097 } | 2123 } |
2098 } | 2124 } |
2099 return nullptr; | 2125 return nullptr; |
2100 } | 2126 } |
2101 | 2127 |
2128 void CopyConstraintsIntoRtcConfiguration( | |
2129 const MediaConstraintsInterface* constraints, | |
2130 PeerConnectionInterface::RTCConfiguration* configuration) { | |
2131 // Copy info from constraints into configuration, if present. | |
2132 if (!constraints) { | |
2133 return; | |
2134 } | |
2135 | |
2136 bool value; | |
2137 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6, | |
2138 &value, nullptr)) { | |
2139 if (!value) { | |
2140 configuration->disable_ipv6 = true; | |
2141 } | |
2142 } | |
2143 configuration->enable_dscp = ConstraintToOptionalBool( | |
nisse-webrtc
2016/02/25 15:25:54
I like this version better. Have you considered in
hta-webrtc
2016/02/25 16:06:07
But then the logic for deciding what was the defau
| |
2144 constraints, MediaConstraintsInterface::kEnableDscp); | |
2145 configuration->cpu_overuse_detection = ConstraintToOptionalBool( | |
2146 constraints, MediaConstraintsInterface::kCpuOveruseDetection); | |
2147 if (FindConstraint(constraints, | |
2148 MediaConstraintsInterface::kEnableRtpDataChannels, &value, | |
2149 NULL) && | |
2150 value) { | |
2151 configuration->enable_rtp_data_channel = true; | |
2152 } | |
2153 // Find Suspend Below Min Bitrate constraint. | |
2154 configuration->suspend_below_min_bitrate = ConstraintToOptionalBool( | |
2155 constraints, | |
2156 MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate); | |
2157 configuration->screencast_min_bitrate = ConstraintToOptionalInt( | |
2158 constraints, MediaConstraintsInterface::kScreencastMinBitrate); | |
2159 configuration->combined_audio_video_bwe = ConstraintToOptionalBool( | |
2160 constraints, MediaConstraintsInterface::kCombinedAudioVideoBwe); | |
2161 configuration->enable_dtls_srtp = ConstraintToOptionalBool( | |
2162 constraints, MediaConstraintsInterface::kEnableDtlsSrtp); | |
2163 } | |
2164 | |
2102 } // namespace webrtc | 2165 } // namespace webrtc |
OLD | NEW |