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

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: Review comments 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
« no previous file with comments | « webrtc/api/peerconnection.h ('k') | webrtc/api/peerconnectionfactory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 if (stream->AddTrack(track)) { 420 if (stream->AddTrack(track)) {
421 return track; 421 return track;
422 } 422 }
423 return nullptr; 423 return nullptr;
424 } 424 }
425 425
426 rtc::Thread* signaling_thread_; 426 rtc::Thread* signaling_thread_;
427 rtc::Thread* worker_thread_; 427 rtc::Thread* worker_thread_;
428 }; 428 };
429 429
430 bool ConvertRtcOptionsForOffer( 430 bool ExtractMediaSessionOptions(
431 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, 431 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
432 cricket::MediaSessionOptions* session_options) { 432 cricket::MediaSessionOptions* session_options) {
433 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; 433 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
434 if (!IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_audio) || 434 if (!IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_audio) ||
435 !IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_video)) { 435 !IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_video)) {
436 return false; 436 return false;
437 } 437 }
438 438
439 if (rtc_options.offer_to_receive_audio != RTCOfferAnswerOptions::kUndefined) { 439 if (rtc_options.offer_to_receive_audio != RTCOfferAnswerOptions::kUndefined) {
440 session_options->recv_audio = (rtc_options.offer_to_receive_audio > 0); 440 session_options->recv_audio = (rtc_options.offer_to_receive_audio > 0);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 // since it's about to be destroyed. 558 // since it's about to be destroyed.
559 for (const auto& sender : senders_) { 559 for (const auto& sender : senders_) {
560 sender->Stop(); 560 sender->Stop();
561 } 561 }
562 for (const auto& receiver : receivers_) { 562 for (const auto& receiver : receivers_) {
563 receiver->Stop(); 563 receiver->Stop();
564 } 564 }
565 } 565 }
566 566
567 bool PeerConnection::Initialize( 567 bool PeerConnection::Initialize(
568 const cricket::MediaConfig& media_config,
568 const PeerConnectionInterface::RTCConfiguration& configuration, 569 const PeerConnectionInterface::RTCConfiguration& configuration,
569 const MediaConstraintsInterface* constraints,
570 rtc::scoped_ptr<cricket::PortAllocator> allocator, 570 rtc::scoped_ptr<cricket::PortAllocator> allocator,
571 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, 571 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
572 PeerConnectionObserver* observer) { 572 PeerConnectionObserver* observer) {
573 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); 573 TRACE_EVENT0("webrtc", "PeerConnection::Initialize");
574 RTC_DCHECK(observer != nullptr); 574 RTC_DCHECK(observer != nullptr);
575 if (!observer) { 575 if (!observer) {
576 return false; 576 return false;
577 } 577 }
578 observer_ = observer; 578 observer_ = observer;
579 579
580 port_allocator_ = std::move(allocator); 580 port_allocator_ = std::move(allocator);
581 581
582 cricket::ServerAddresses stun_servers; 582 cricket::ServerAddresses stun_servers;
583 std::vector<cricket::RelayServerConfig> turn_servers; 583 std::vector<cricket::RelayServerConfig> turn_servers;
584 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { 584 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) {
585 return false; 585 return false;
586 } 586 }
587 port_allocator_->SetIceServers(stun_servers, turn_servers); 587 port_allocator_->SetIceServers(stun_servers, turn_servers);
588 588
589 // To handle both internal and externally created port allocator, we will 589 // To handle both internal and externally created port allocator, we will
590 // enable BUNDLE here. 590 // enable BUNDLE here.
591 int portallocator_flags = port_allocator_->flags(); 591 int portallocator_flags = port_allocator_->flags();
592 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 592 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
593 cricket::PORTALLOCATOR_ENABLE_IPV6; 593 cricket::PORTALLOCATOR_ENABLE_IPV6;
594 bool value; 594 // 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. 595 // by experiment.
596 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6, 596 if (configuration.disable_ipv6) {
597 &value, nullptr)) { 597 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") == 598 } else if (webrtc::field_trial::FindFullName("WebRTC-IPv6Default") ==
602 "Disabled") { 599 "Disabled") {
603 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); 600 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6);
604 } 601 }
605 602
606 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) { 603 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) {
607 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; 604 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP;
608 LOG(LS_INFO) << "TCP candidates are disabled."; 605 LOG(LS_INFO) << "TCP candidates are disabled.";
609 } 606 }
610 607
611 port_allocator_->set_flags(portallocator_flags); 608 port_allocator_->set_flags(portallocator_flags);
612 // No step delay is used while allocating ports. 609 // No step delay is used while allocating ports.
613 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); 610 port_allocator_->set_step_delay(cricket::kMinimumStepDelay);
614 611
615 // We rely on default values when constraints aren't found.
616 cricket::MediaConfig media_config;
617
618 media_config.video.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 constraint for cpu overuse detection.
625 FindConstraint(constraints, MediaConstraintsInterface::kCpuOveruseDetection,
626 &media_config.video.enable_cpu_overuse_detection, NULL);
627
628 // Find Suspend Below Min Bitrate constraint.
629 FindConstraint(constraints,
630 MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
631 &media_config.video.suspend_below_min_bitrate, NULL);
632
633 media_controller_.reset(factory_->CreateMediaController(media_config)); 612 media_controller_.reset(factory_->CreateMediaController(media_config));
634 613
635 remote_stream_factory_.reset(new RemoteMediaStreamFactory( 614 remote_stream_factory_.reset(new RemoteMediaStreamFactory(
636 factory_->signaling_thread(), factory_->worker_thread())); 615 factory_->signaling_thread(), factory_->worker_thread()));
637 616
638 session_.reset( 617 session_.reset(
639 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), 618 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(),
640 factory_->worker_thread(), port_allocator_.get())); 619 factory_->worker_thread(), port_allocator_.get()));
641 stats_.reset(new StatsCollector(this)); 620 stats_.reset(new StatsCollector(this));
642 621
643 // Initialize the WebRtcSession. It creates transport channels etc. 622 // Initialize the WebRtcSession. It creates transport channels etc.
644 if (!session_->Initialize(factory_->options(), constraints, 623 if (!session_->Initialize(factory_->options(), std::move(dtls_identity_store),
645 std::move(dtls_identity_store), configuration)) { 624 configuration)) {
646 return false; 625 return false;
647 } 626 }
648 627
649 // Register PeerConnection as receiver of local ice candidates. 628 // Register PeerConnection as receiver of local ice candidates.
650 // All the callbacks will be posted to the application from PeerConnection. 629 // All the callbacks will be posted to the application from PeerConnection.
651 session_->RegisterIceObserver(this); 630 session_->RegisterIceObserver(this);
652 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); 631 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange);
653 session_->SignalVoiceChannelDestroyed.connect( 632 session_->SignalVoiceChannelDestroyed.connect(
654 this, &PeerConnection::OnVoiceChannelDestroyed); 633 this, &PeerConnection::OnVoiceChannelDestroyed);
655 session_->SignalVideoChannelDestroyed.connect( 634 session_->SignalVideoChannelDestroyed.connect(
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 } 978 }
1000 979
1001 cricket::MediaSessionOptions session_options; 980 cricket::MediaSessionOptions session_options;
1002 if (!GetOptionsForAnswer(constraints, &session_options)) { 981 if (!GetOptionsForAnswer(constraints, &session_options)) {
1003 std::string error = "CreateAnswer called with invalid constraints."; 982 std::string error = "CreateAnswer called with invalid constraints.";
1004 LOG(LS_ERROR) << error; 983 LOG(LS_ERROR) << error;
1005 PostCreateSessionDescriptionFailure(observer, error); 984 PostCreateSessionDescriptionFailure(observer, error);
1006 return; 985 return;
1007 } 986 }
1008 987
1009 session_->CreateAnswer(observer, constraints, session_options); 988 session_->CreateAnswer(observer, session_options);
989 }
990
991 void PeerConnection::CreateAnswer(CreateSessionDescriptionObserver* observer,
992 const RTCOfferAnswerOptions& options) {
993 TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer");
994 if (!VERIFY(observer != nullptr)) {
995 LOG(LS_ERROR) << "CreateAnswer - observer is NULL.";
996 return;
997 }
998
999 cricket::MediaSessionOptions session_options;
1000 if (!GetOptionsForAnswer(options, &session_options)) {
1001 std::string error = "CreateAnswer called with invalid options.";
1002 LOG(LS_ERROR) << error;
1003 PostCreateSessionDescriptionFailure(observer, error);
1004 return;
1005 }
1006
1007 session_->CreateAnswer(observer, session_options);
1010 } 1008 }
1011 1009
1012 void PeerConnection::SetLocalDescription( 1010 void PeerConnection::SetLocalDescription(
1013 SetSessionDescriptionObserver* observer, 1011 SetSessionDescriptionObserver* observer,
1014 SessionDescriptionInterface* desc) { 1012 SessionDescriptionInterface* desc) {
1015 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); 1013 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription");
1016 if (!VERIFY(observer != nullptr)) { 1014 if (!VERIFY(observer != nullptr)) {
1017 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL."; 1015 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL.";
1018 return; 1016 return;
1019 } 1017 }
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 cricket::MediaSessionOptions* session_options) { 1501 cricket::MediaSessionOptions* session_options) {
1504 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of 1502 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of
1505 // ContentInfos. 1503 // ContentInfos.
1506 if (session_->local_description()) { 1504 if (session_->local_description()) {
1507 for (const cricket::ContentInfo& content : 1505 for (const cricket::ContentInfo& content :
1508 session_->local_description()->description()->contents()) { 1506 session_->local_description()->description()->contents()) {
1509 session_options->transport_options[content.name] = 1507 session_options->transport_options[content.name] =
1510 cricket::TransportOptions(); 1508 cricket::TransportOptions();
1511 } 1509 }
1512 } 1510 }
1513 if (!ConvertRtcOptionsForOffer(rtc_options, session_options)) { 1511 if (!ExtractMediaSessionOptions(rtc_options, session_options)) {
1514 return false; 1512 return false;
1515 } 1513 }
1516 1514
1517 AddSendStreams(session_options, senders_, rtp_data_channels_); 1515 AddSendStreams(session_options, senders_, rtp_data_channels_);
1518 // Offer to receive audio/video if the constraint is not set and there are 1516 // Offer to receive audio/video if the constraint is not set and there are
1519 // send streams, or we're currently receiving. 1517 // send streams, or we're currently receiving.
1520 if (rtc_options.offer_to_receive_audio == RTCOfferAnswerOptions::kUndefined) { 1518 if (rtc_options.offer_to_receive_audio == RTCOfferAnswerOptions::kUndefined) {
1521 session_options->recv_audio = 1519 session_options->recv_audio =
1522 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO) || 1520 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO) ||
1523 !remote_audio_tracks_.empty(); 1521 !remote_audio_tracks_.empty();
1524 } 1522 }
1525 if (rtc_options.offer_to_receive_video == RTCOfferAnswerOptions::kUndefined) { 1523 if (rtc_options.offer_to_receive_video == RTCOfferAnswerOptions::kUndefined) {
1526 session_options->recv_video = 1524 session_options->recv_video =
1527 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO) || 1525 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO) ||
1528 !remote_video_tracks_.empty(); 1526 !remote_video_tracks_.empty();
1529 } 1527 }
1530 session_options->bundle_enabled = 1528 session_options->bundle_enabled =
1531 session_options->bundle_enabled && 1529 session_options->bundle_enabled &&
1532 (session_options->has_audio() || session_options->has_video() || 1530 (session_options->has_audio() || session_options->has_video() ||
1533 session_options->has_data()); 1531 session_options->has_data());
1534 1532
1535 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) { 1533 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) {
1536 session_options->data_channel_type = cricket::DCT_SCTP; 1534 session_options->data_channel_type = cricket::DCT_SCTP;
1537 } 1535 }
1538 return true; 1536 return true;
1539 } 1537 }
1540 1538
1541 bool PeerConnection::GetOptionsForAnswer( 1539 void PeerConnection::FinishOptionsForAnswer(
1542 const MediaConstraintsInterface* constraints,
1543 cricket::MediaSessionOptions* session_options) { 1540 cricket::MediaSessionOptions* session_options) {
1544 session_options->recv_audio = false;
1545 session_options->recv_video = false;
1546 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of 1541 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of
1547 // ContentInfos. 1542 // ContentInfos.
1548 if (session_->remote_description()) { 1543 if (session_->remote_description()) {
1549 // Initialize the transport_options map. 1544 // Initialize the transport_options map.
1550 for (const cricket::ContentInfo& content : 1545 for (const cricket::ContentInfo& content :
1551 session_->remote_description()->description()->contents()) { 1546 session_->remote_description()->description()->contents()) {
1552 session_options->transport_options[content.name] = 1547 session_options->transport_options[content.name] =
1553 cricket::TransportOptions(); 1548 cricket::TransportOptions();
1554 } 1549 }
1555 } 1550 }
1556 if (!ParseConstraintsForAnswer(constraints, session_options)) {
1557 return false;
1558 }
1559
1560 AddSendStreams(session_options, senders_, rtp_data_channels_); 1551 AddSendStreams(session_options, senders_, rtp_data_channels_);
1561 session_options->bundle_enabled = 1552 session_options->bundle_enabled =
1562 session_options->bundle_enabled && 1553 session_options->bundle_enabled &&
1563 (session_options->has_audio() || session_options->has_video() || 1554 (session_options->has_audio() || session_options->has_video() ||
1564 session_options->has_data()); 1555 session_options->has_data());
1565 1556
1566 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams 1557 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams
1567 // are not signaled in the SDP so does not go through that path and must be 1558 // are not signaled in the SDP so does not go through that path and must be
1568 // handled here. 1559 // handled here.
1569 if (session_->data_channel_type() == cricket::DCT_SCTP) { 1560 if (session_->data_channel_type() == cricket::DCT_SCTP) {
1570 session_options->data_channel_type = cricket::DCT_SCTP; 1561 session_options->data_channel_type = cricket::DCT_SCTP;
1571 } 1562 }
1563 }
1564
1565 bool PeerConnection::GetOptionsForAnswer(
1566 const MediaConstraintsInterface* constraints,
1567 cricket::MediaSessionOptions* session_options) {
1568 session_options->recv_audio = false;
1569 session_options->recv_video = false;
1570 if (!ParseConstraintsForAnswer(constraints, session_options)) {
1571 return false;
1572 }
1573 FinishOptionsForAnswer(session_options);
1572 return true; 1574 return true;
1573 } 1575 }
1574 1576
1577 bool PeerConnection::GetOptionsForAnswer(
1578 const RTCOfferAnswerOptions& options,
1579 cricket::MediaSessionOptions* session_options) {
1580 session_options->recv_audio = false;
1581 session_options->recv_video = false;
1582 if (!ExtractMediaSessionOptions(options, session_options)) {
1583 return false;
1584 }
1585 FinishOptionsForAnswer(session_options);
1586 return true;
1587 }
1588
1575 void PeerConnection::RemoveTracks(cricket::MediaType media_type) { 1589 void PeerConnection::RemoveTracks(cricket::MediaType media_type) {
1576 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); 1590 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type);
1577 UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false, 1591 UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false,
1578 media_type, nullptr); 1592 media_type, nullptr);
1579 } 1593 }
1580 1594
1581 void PeerConnection::UpdateRemoteStreamsList( 1595 void PeerConnection::UpdateRemoteStreamsList(
1582 const cricket::StreamParamsVec& streams, 1596 const cricket::StreamParamsVec& streams,
1583 bool default_track_needed, 1597 bool default_track_needed,
1584 cricket::MediaType media_type, 1598 cricket::MediaType media_type,
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
2098 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { 2112 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const {
2099 for (const auto& channel : sctp_data_channels_) { 2113 for (const auto& channel : sctp_data_channels_) {
2100 if (channel->id() == sid) { 2114 if (channel->id() == sid) {
2101 return channel; 2115 return channel;
2102 } 2116 }
2103 } 2117 }
2104 return nullptr; 2118 return nullptr;
2105 } 2119 }
2106 2120
2107 } // namespace webrtc 2121 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/peerconnection.h ('k') | webrtc/api/peerconnectionfactory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698