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

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

Issue 1717583002: Non-constraint interfaces for all constrainable interfaces (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase result (no intentional change) Created 4 years, 9 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
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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(
568 const PeerConnectionInterface::RTCConfiguration& configuration, 575 const PeerConnectionInterface::RTCConfiguration& configuration,
569 const MediaConstraintsInterface* constraints,
570 rtc::scoped_ptr<cricket::PortAllocator> allocator, 576 rtc::scoped_ptr<cricket::PortAllocator> allocator,
571 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, 577 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
572 PeerConnectionObserver* observer) { 578 PeerConnectionObserver* observer) {
573 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); 579 TRACE_EVENT0("webrtc", "PeerConnection::Initialize");
574 RTC_DCHECK(observer != nullptr); 580 RTC_DCHECK(observer != nullptr);
575 if (!observer) { 581 if (!observer) {
576 return false; 582 return false;
577 } 583 }
578 observer_ = observer; 584 observer_ = observer;
579 585
580 port_allocator_ = std::move(allocator); 586 port_allocator_ = std::move(allocator);
581 587
582 cricket::ServerAddresses stun_servers; 588 cricket::ServerAddresses stun_servers;
583 std::vector<cricket::RelayServerConfig> turn_servers; 589 std::vector<cricket::RelayServerConfig> turn_servers;
584 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { 590 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) {
585 return false; 591 return false;
586 } 592 }
587 port_allocator_->SetIceServers(stun_servers, turn_servers); 593 port_allocator_->SetIceServers(stun_servers, turn_servers);
588 594
589 // To handle both internal and externally created port allocator, we will 595 // To handle both internal and externally created port allocator, we will
590 // enable BUNDLE here. 596 // enable BUNDLE here.
591 int portallocator_flags = port_allocator_->flags(); 597 int portallocator_flags = port_allocator_->flags();
592 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 598 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
593 cricket::PORTALLOCATOR_ENABLE_IPV6; 599 cricket::PORTALLOCATOR_ENABLE_IPV6;
594 bool value;
595 // If IPv6 flag was specified, we'll not override it by experiment. 600 // If IPv6 flag was specified, we'll not override it by experiment.
596 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6, 601 if (configuration.disable_ipv6) {
597 &value, nullptr)) { 602 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") == 603 } else if (webrtc::field_trial::FindFullName("WebRTC-IPv6Default") ==
602 "Disabled") { 604 "Disabled") {
603 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); 605 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6);
604 } 606 }
605 607
606 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) { 608 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) {
607 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; 609 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP;
608 LOG(LS_INFO) << "TCP candidates are disabled."; 610 LOG(LS_INFO) << "TCP candidates are disabled.";
609 } 611 }
610 612
611 port_allocator_->set_flags(portallocator_flags); 613 port_allocator_->set_flags(portallocator_flags);
612 // No step delay is used while allocating ports. 614 // No step delay is used while allocating ports.
613 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); 615 port_allocator_->set_step_delay(cricket::kMinimumStepDelay);
614 616
615 // We rely on default values when constraints aren't found. 617 // We rely on default values when constraints aren't found.
616 cricket::MediaConfig media_config; 618 cricket::MediaConfig media_config;
617 619
618 media_config.disable_prerenderer_smoothing = 620 media_config.disable_prerenderer_smoothing =
619 configuration.disable_prerenderer_smoothing; 621 configuration.disable_prerenderer_smoothing;
620 622
621 // Find DSCP constraint. 623 // Find DSCP constraint.
622 FindConstraint(constraints, MediaConstraintsInterface::kEnableDscp, 624 if (configuration.enable_dscp) {
623 &media_config.enable_dscp, NULL); 625 media_config.enable_dscp = *(configuration.enable_dscp);
nisse-webrtc 2016/02/25 08:26:51 I agree this use of rtc::Optional makes some sense
hta-webrtc 2016/02/25 14:32:42 I was misremembering (it is the IPv6 that is contr
626 }
624 // Find constraints for cpu overuse detection. 627 // Find constraints for cpu overuse detection.
625 FindConstraint(constraints, MediaConstraintsInterface::kCpuOveruseDetection, 628 if (configuration.cpu_overuse_detection) {
626 &media_config.enable_cpu_overuse_detection, NULL); 629 media_config.enable_cpu_overuse_detection =
630 *(configuration.cpu_overuse_detection);
631 }
627 632
628 media_controller_.reset(factory_->CreateMediaController(media_config)); 633 media_controller_.reset(factory_->CreateMediaController(media_config));
629 634
630 remote_stream_factory_.reset(new RemoteMediaStreamFactory( 635 remote_stream_factory_.reset(new RemoteMediaStreamFactory(
631 factory_->signaling_thread(), media_controller_->channel_manager())); 636 factory_->signaling_thread(), media_controller_->channel_manager()));
632 637
633 session_.reset( 638 session_.reset(
634 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), 639 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(),
635 factory_->worker_thread(), port_allocator_.get())); 640 factory_->worker_thread(), port_allocator_.get()));
636 stats_.reset(new StatsCollector(this)); 641 stats_.reset(new StatsCollector(this));
637 642
638 // Initialize the WebRtcSession. It creates transport channels etc. 643 // Initialize the WebRtcSession. It creates transport channels etc.
639 if (!session_->Initialize(factory_->options(), constraints, 644 if (!session_->Initialize(factory_->options(), std::move(dtls_identity_store),
640 std::move(dtls_identity_store), configuration)) { 645 configuration)) {
641 return false; 646 return false;
642 } 647 }
643 648
644 // Register PeerConnection as receiver of local ice candidates. 649 // Register PeerConnection as receiver of local ice candidates.
645 // All the callbacks will be posted to the application from PeerConnection. 650 // All the callbacks will be posted to the application from PeerConnection.
646 session_->RegisterIceObserver(this); 651 session_->RegisterIceObserver(this);
647 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); 652 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange);
648 session_->SignalVoiceChannelDestroyed.connect( 653 session_->SignalVoiceChannelDestroyed.connect(
649 this, &PeerConnection::OnVoiceChannelDestroyed); 654 this, &PeerConnection::OnVoiceChannelDestroyed);
650 session_->SignalVideoChannelDestroyed.connect( 655 session_->SignalVideoChannelDestroyed.connect(
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 } 999 }
995 1000
996 cricket::MediaSessionOptions session_options; 1001 cricket::MediaSessionOptions session_options;
997 if (!GetOptionsForAnswer(constraints, &session_options)) { 1002 if (!GetOptionsForAnswer(constraints, &session_options)) {
998 std::string error = "CreateAnswer called with invalid constraints."; 1003 std::string error = "CreateAnswer called with invalid constraints.";
999 LOG(LS_ERROR) << error; 1004 LOG(LS_ERROR) << error;
1000 PostCreateSessionDescriptionFailure(observer, error); 1005 PostCreateSessionDescriptionFailure(observer, error);
1001 return; 1006 return;
1002 } 1007 }
1003 1008
1004 session_->CreateAnswer(observer, constraints, session_options); 1009 session_->CreateAnswer(observer, session_options);
1010 }
1011
1012 void PeerConnection::CreateAnswer(CreateSessionDescriptionObserver* observer,
1013 const RTCOfferAnswerOptions& options) {
1014 TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer");
1015 if (!VERIFY(observer != nullptr)) {
1016 LOG(LS_ERROR) << "CreateAnswer - observer is NULL.";
1017 return;
1018 }
1019
1020 cricket::MediaSessionOptions session_options;
1021 if (!GetOptionsForAnswer(options, &session_options)) {
1022 std::string error = "CreateAnswer called with invalid options.";
1023 LOG(LS_ERROR) << error;
1024 PostCreateSessionDescriptionFailure(observer, error);
1025 return;
1026 }
1027
1028 session_->CreateAnswer(observer, session_options);
1005 } 1029 }
1006 1030
1007 void PeerConnection::SetLocalDescription( 1031 void PeerConnection::SetLocalDescription(
1008 SetSessionDescriptionObserver* observer, 1032 SetSessionDescriptionObserver* observer,
1009 SessionDescriptionInterface* desc) { 1033 SessionDescriptionInterface* desc) {
1010 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); 1034 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription");
1011 if (!VERIFY(observer != nullptr)) { 1035 if (!VERIFY(observer != nullptr)) {
1012 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL."; 1036 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL.";
1013 return; 1037 return;
1014 } 1038 }
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 session_options->bundle_enabled && 1550 session_options->bundle_enabled &&
1527 (session_options->has_audio() || session_options->has_video() || 1551 (session_options->has_audio() || session_options->has_video() ||
1528 session_options->has_data()); 1552 session_options->has_data());
1529 1553
1530 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) { 1554 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) {
1531 session_options->data_channel_type = cricket::DCT_SCTP; 1555 session_options->data_channel_type = cricket::DCT_SCTP;
1532 } 1556 }
1533 return true; 1557 return true;
1534 } 1558 }
1535 1559
1536 bool PeerConnection::GetOptionsForAnswer( 1560 void PeerConnection::FinishOptionsForAnswer(
1537 const MediaConstraintsInterface* constraints,
1538 cricket::MediaSessionOptions* session_options) { 1561 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 1562 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of
1542 // ContentInfos. 1563 // ContentInfos.
1543 if (session_->remote_description()) { 1564 if (session_->remote_description()) {
1544 // Initialize the transport_options map. 1565 // Initialize the transport_options map.
1545 for (const cricket::ContentInfo& content : 1566 for (const cricket::ContentInfo& content :
1546 session_->remote_description()->description()->contents()) { 1567 session_->remote_description()->description()->contents()) {
1547 session_options->transport_options[content.name] = 1568 session_options->transport_options[content.name] =
1548 cricket::TransportOptions(); 1569 cricket::TransportOptions();
1549 } 1570 }
1550 } 1571 }
1551 if (!ParseConstraintsForAnswer(constraints, session_options)) {
1552 return false;
1553 }
1554
1555 AddSendStreams(session_options, senders_, rtp_data_channels_); 1572 AddSendStreams(session_options, senders_, rtp_data_channels_);
1556 session_options->bundle_enabled = 1573 session_options->bundle_enabled =
1557 session_options->bundle_enabled && 1574 session_options->bundle_enabled &&
1558 (session_options->has_audio() || session_options->has_video() || 1575 (session_options->has_audio() || session_options->has_video() ||
1559 session_options->has_data()); 1576 session_options->has_data());
1560 1577
1561 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams 1578 // 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 1579 // are not signaled in the SDP so does not go through that path and must be
1563 // handled here. 1580 // handled here.
1564 if (session_->data_channel_type() == cricket::DCT_SCTP) { 1581 if (session_->data_channel_type() == cricket::DCT_SCTP) {
1565 session_options->data_channel_type = cricket::DCT_SCTP; 1582 session_options->data_channel_type = cricket::DCT_SCTP;
1566 } 1583 }
1584 }
1585
1586 bool PeerConnection::GetOptionsForAnswer(
1587 const MediaConstraintsInterface* constraints,
1588 cricket::MediaSessionOptions* session_options) {
1589 session_options->recv_audio = false;
1590 session_options->recv_video = false;
1591 if (!ParseConstraintsForAnswer(constraints, session_options)) {
1592 return false;
1593 }
1594 FinishOptionsForAnswer(session_options);
1567 return true; 1595 return true;
1568 } 1596 }
1569 1597
1598 bool PeerConnection::GetOptionsForAnswer(
1599 const RTCOfferAnswerOptions& options,
1600 cricket::MediaSessionOptions* session_options) {
1601 session_options->recv_audio = false;
1602 session_options->recv_video = false;
1603 if (!ConvertRtcOptionsForAnswer(options, session_options)) {
1604 return false;
1605 }
1606 FinishOptionsForAnswer(session_options);
1607 return true;
1608 }
1609
1570 void PeerConnection::RemoveTracks(cricket::MediaType media_type) { 1610 void PeerConnection::RemoveTracks(cricket::MediaType media_type) {
1571 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); 1611 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type);
1572 UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false, 1612 UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false,
1573 media_type, nullptr); 1613 media_type, nullptr);
1574 } 1614 }
1575 1615
1576 void PeerConnection::UpdateRemoteStreamsList( 1616 void PeerConnection::UpdateRemoteStreamsList(
1577 const cricket::StreamParamsVec& streams, 1617 const cricket::StreamParamsVec& streams,
1578 bool default_track_needed, 1618 bool default_track_needed,
1579 cricket::MediaType media_type, 1619 cricket::MediaType media_type,
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
2092 2132
2093 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { 2133 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const {
2094 for (const auto& channel : sctp_data_channels_) { 2134 for (const auto& channel : sctp_data_channels_) {
2095 if (channel->id() == sid) { 2135 if (channel->id() == sid) {
2096 return channel; 2136 return channel;
2097 } 2137 }
2098 } 2138 }
2099 return nullptr; 2139 return nullptr;
2100 } 2140 }
2101 2141
2142 void CopyConstraintsIntoRtcConfiguration(
2143 const MediaConstraintsInterface* constraints,
2144 PeerConnectionInterface::RTCConfiguration* configuration) {
2145 // Copy info from constraints into configuration, if present.
2146 if (!constraints) {
2147 return;
2148 }
2149
2150 bool value;
2151 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6,
2152 &value, nullptr)) {
2153 if (!value) {
2154 configuration->disable_ipv6 = true;
2155 }
2156 }
2157 configuration->enable_dscp = ConstraintToOptionalBool(
2158 constraints, MediaConstraintsInterface::kEnableDscp);
2159 configuration->cpu_overuse_detection = ConstraintToOptionalBool(
2160 constraints, MediaConstraintsInterface::kCpuOveruseDetection);
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 configuration->suspend_below_min_bitrate = ConstraintToOptionalBool(
2169 constraints,
2170 MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate);
2171 configuration->screencast_min_bitrate = ConstraintToOptionalInt(
2172 constraints, MediaConstraintsInterface::kScreencastMinBitrate);
2173 configuration->combined_audio_video_bwe = ConstraintToOptionalBool(
2174 constraints, MediaConstraintsInterface::kCombinedAudioVideoBwe);
2175 configuration->enable_dtls_srtp = ConstraintToOptionalBool(
2176 constraints, MediaConstraintsInterface::kEnableDtlsSrtp);
2177 }
2178
2102 } // namespace webrtc 2179 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698