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

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

Issue 1844803002: Modify PeerConnection for end-to-end QuicDataChannel usage (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Sync to upstream after landing QUIC data channel and QUIC transport CLs Created 4 years, 7 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/peerconnection_unittest.cc » ('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 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; 563 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP;
564 LOG(LS_INFO) << "TCP candidates are disabled."; 564 LOG(LS_INFO) << "TCP candidates are disabled.";
565 } 565 }
566 566
567 port_allocator_->set_flags(portallocator_flags); 567 port_allocator_->set_flags(portallocator_flags);
568 // No step delay is used while allocating ports. 568 // No step delay is used while allocating ports.
569 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); 569 port_allocator_->set_step_delay(cricket::kMinimumStepDelay);
570 570
571 media_controller_.reset( 571 media_controller_.reset(
572 factory_->CreateMediaController(configuration.media_config)); 572 factory_->CreateMediaController(configuration.media_config));
573 573 #ifdef HAVE_QUIC
574 if (configuration.enable_quic) {
575 quic_data_transport_.reset(new QuicDataTransport(
576 factory_->signaling_thread(), factory_->worker_thread()));
577 }
578 #endif // HAVE_QUIC
574 session_.reset( 579 session_.reset(
575 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), 580 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(),
576 factory_->worker_thread(), port_allocator_.get())); 581 factory_->worker_thread(), port_allocator_.get()));
577 stats_.reset(new StatsCollector(this)); 582 stats_.reset(new StatsCollector(this));
578 583
579 // Initialize the WebRtcSession. It creates transport channels etc. 584 // Initialize the WebRtcSession. It creates transport channels etc.
580 if (!session_->Initialize(factory_->options(), std::move(dtls_identity_store), 585 if (!session_->Initialize(factory_->options(), std::move(dtls_identity_store),
581 configuration)) { 586 configuration)) {
582 return false; 587 return false;
583 } 588 }
584 589
585 // Register PeerConnection as receiver of local ice candidates. 590 // Register PeerConnection as receiver of local ice candidates.
586 // All the callbacks will be posted to the application from PeerConnection. 591 // All the callbacks will be posted to the application from PeerConnection.
587 session_->RegisterIceObserver(this); 592 session_->RegisterIceObserver(this);
588 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); 593 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange);
589 session_->SignalVoiceChannelDestroyed.connect( 594 session_->SignalVoiceChannelDestroyed.connect(
590 this, &PeerConnection::OnVoiceChannelDestroyed); 595 this, &PeerConnection::OnVoiceChannelDestroyed);
591 session_->SignalVideoChannelDestroyed.connect( 596 session_->SignalVideoChannelDestroyed.connect(
592 this, &PeerConnection::OnVideoChannelDestroyed); 597 this, &PeerConnection::OnVideoChannelDestroyed);
593 session_->SignalDataChannelCreated.connect( 598 session_->SignalDataChannelCreated.connect(
594 this, &PeerConnection::OnDataChannelCreated); 599 this, &PeerConnection::OnDataChannelCreated);
595 session_->SignalDataChannelDestroyed.connect( 600 session_->SignalDataChannelDestroyed.connect(
596 this, &PeerConnection::OnDataChannelDestroyed); 601 this, &PeerConnection::OnDataChannelDestroyed);
597 session_->SignalDataChannelOpenMessage.connect( 602 session_->SignalDataChannelOpenMessage.connect(
598 this, &PeerConnection::OnDataChannelOpenMessage); 603 this, &PeerConnection::OnDataChannelOpenMessage);
604 #ifdef HAVE_QUIC
605 session_->SignalQuicTransportChannelCreated.connect(
606 this, &PeerConnection::OnQuicTransportChannelCreated);
607 #endif // HAVE_QUIC
599 return true; 608 return true;
600 } 609 }
601 610
602 rtc::scoped_refptr<StreamCollectionInterface> 611 rtc::scoped_refptr<StreamCollectionInterface>
603 PeerConnection::local_streams() { 612 PeerConnection::local_streams() {
604 return local_streams_; 613 return local_streams_;
605 } 614 }
606 615
607 rtc::scoped_refptr<StreamCollectionInterface> 616 rtc::scoped_refptr<StreamCollectionInterface>
608 PeerConnection::remote_streams() { 617 PeerConnection::remote_streams() {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 PeerConnectionInterface::IceGatheringState 835 PeerConnectionInterface::IceGatheringState
827 PeerConnection::ice_gathering_state() { 836 PeerConnection::ice_gathering_state() {
828 return ice_gathering_state_; 837 return ice_gathering_state_;
829 } 838 }
830 839
831 rtc::scoped_refptr<DataChannelInterface> 840 rtc::scoped_refptr<DataChannelInterface>
832 PeerConnection::CreateDataChannel( 841 PeerConnection::CreateDataChannel(
833 const std::string& label, 842 const std::string& label,
834 const DataChannelInit* config) { 843 const DataChannelInit* config) {
835 TRACE_EVENT0("webrtc", "PeerConnection::CreateDataChannel"); 844 TRACE_EVENT0("webrtc", "PeerConnection::CreateDataChannel");
845 #ifdef HAVE_QUIC
846 if (session_->data_channel_type() == cricket::DCT_QUIC) {
847 // TODO(mikescarlett): Handle case when config is NULL.
848 if (!config) {
849 LOG(LS_ERROR) << "Missing config for QUIC data channel.";
850 return nullptr;
851 }
852 // TODO(mikescarlett): Allow unreliable or ordered QUIC data channels.
853 if (!config->reliable || config->ordered) {
854 LOG(LS_ERROR) << "QUIC data channel does not implement unreliable or "
855 "ordered delivery.";
856 return nullptr;
857 }
858 return quic_data_transport_->CreateDataChannel(label, config);
859 }
860 #endif // HAVE_QUIC
861
836 bool first_datachannel = !HasDataChannels(); 862 bool first_datachannel = !HasDataChannels();
837 863
838 std::unique_ptr<InternalDataChannelInit> internal_config; 864 std::unique_ptr<InternalDataChannelInit> internal_config;
839 if (config) { 865 if (config) {
840 internal_config.reset(new InternalDataChannelInit(*config)); 866 internal_config.reset(new InternalDataChannelInit(*config));
841 } 867 }
842 rtc::scoped_refptr<DataChannelInterface> channel( 868 rtc::scoped_refptr<DataChannelInterface> channel(
843 InternalCreateDataChannel(label, internal_config.get())); 869 InternalCreateDataChannel(label, internal_config.get()));
844 if (!channel.get()) { 870 if (!channel.get()) {
845 return nullptr; 871 return nullptr;
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 if (rtc_options.offer_to_receive_video == RTCOfferAnswerOptions::kUndefined) { 1519 if (rtc_options.offer_to_receive_video == RTCOfferAnswerOptions::kUndefined) {
1494 session_options->recv_video = 1520 session_options->recv_video =
1495 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO) || 1521 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO) ||
1496 !remote_video_tracks_.empty(); 1522 !remote_video_tracks_.empty();
1497 } 1523 }
1498 session_options->bundle_enabled = 1524 session_options->bundle_enabled =
1499 session_options->bundle_enabled && 1525 session_options->bundle_enabled &&
1500 (session_options->has_audio() || session_options->has_video() || 1526 (session_options->has_audio() || session_options->has_video() ||
1501 session_options->has_data()); 1527 session_options->has_data());
1502 1528
1503 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) { 1529 if (HasDataChannels()) {
1504 session_options->data_channel_type = cricket::DCT_SCTP; 1530 session_options->data_channel_type = session_->data_channel_type();
1505 } 1531 }
1506 return true; 1532 return true;
1507 } 1533 }
1508 1534
1509 void PeerConnection::FinishOptionsForAnswer( 1535 void PeerConnection::FinishOptionsForAnswer(
1510 cricket::MediaSessionOptions* session_options) { 1536 cricket::MediaSessionOptions* session_options) {
1511 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of 1537 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of
1512 // ContentInfos. 1538 // ContentInfos.
1513 if (session_->remote_description()) { 1539 if (session_->remote_description()) {
1514 // Initialize the transport_options map. 1540 // Initialize the transport_options map.
1515 for (const cricket::ContentInfo& content : 1541 for (const cricket::ContentInfo& content :
1516 session_->remote_description()->description()->contents()) { 1542 session_->remote_description()->description()->contents()) {
1517 session_options->transport_options[content.name] = 1543 session_options->transport_options[content.name] =
1518 cricket::TransportOptions(); 1544 cricket::TransportOptions();
1519 } 1545 }
1520 } 1546 }
1521 AddSendStreams(session_options, senders_, rtp_data_channels_); 1547 AddSendStreams(session_options, senders_, rtp_data_channels_);
1522 session_options->bundle_enabled = 1548 session_options->bundle_enabled =
1523 session_options->bundle_enabled && 1549 session_options->bundle_enabled &&
1524 (session_options->has_audio() || session_options->has_video() || 1550 (session_options->has_audio() || session_options->has_video() ||
1525 session_options->has_data()); 1551 session_options->has_data());
1526 1552
1527 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams 1553 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams
1528 // are not signaled in the SDP so does not go through that path and must be 1554 // are not signaled in the SDP so does not go through that path and must be
1529 // handled here. 1555 // handled here.
1530 if (session_->data_channel_type() == cricket::DCT_SCTP) { 1556 session_options->data_channel_type = session_->data_channel_type();
1531 session_options->data_channel_type = cricket::DCT_SCTP;
1532 }
1533 } 1557 }
1534 1558
1535 bool PeerConnection::GetOptionsForAnswer( 1559 bool PeerConnection::GetOptionsForAnswer(
1536 const MediaConstraintsInterface* constraints, 1560 const MediaConstraintsInterface* constraints,
1537 cricket::MediaSessionOptions* session_options) { 1561 cricket::MediaSessionOptions* session_options) {
1538 session_options->recv_audio = false; 1562 session_options->recv_audio = false;
1539 session_options->recv_video = false; 1563 session_options->recv_video = false;
1540 if (!ParseConstraintsForAnswer(constraints, session_options)) { 1564 if (!ParseConstraintsForAnswer(constraints, session_options)) {
1541 return false; 1565 return false;
1542 } 1566 }
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 RTC_DCHECK(channel->data_channel_type() == cricket::DCT_SCTP); 1938 RTC_DCHECK(channel->data_channel_type() == cricket::DCT_SCTP);
1915 sctp_data_channels_.push_back(channel); 1939 sctp_data_channels_.push_back(channel);
1916 channel->SignalClosed.connect(this, 1940 channel->SignalClosed.connect(this,
1917 &PeerConnection::OnSctpDataChannelClosed); 1941 &PeerConnection::OnSctpDataChannelClosed);
1918 } 1942 }
1919 1943
1920 return channel; 1944 return channel;
1921 } 1945 }
1922 1946
1923 bool PeerConnection::HasDataChannels() const { 1947 bool PeerConnection::HasDataChannels() const {
1948 #ifdef HAVE_QUIC
1949 return !rtp_data_channels_.empty() || !sctp_data_channels_.empty() ||
1950 quic_data_transport_->HasDataChannels();
1951 #else
1924 return !rtp_data_channels_.empty() || !sctp_data_channels_.empty(); 1952 return !rtp_data_channels_.empty() || !sctp_data_channels_.empty();
1953 #endif // HAVE_QUIC
1925 } 1954 }
1926 1955
1927 void PeerConnection::AllocateSctpSids(rtc::SSLRole role) { 1956 void PeerConnection::AllocateSctpSids(rtc::SSLRole role) {
1928 for (const auto& channel : sctp_data_channels_) { 1957 for (const auto& channel : sctp_data_channels_) {
1929 if (channel->id() < 0) { 1958 if (channel->id() < 0) {
1930 int sid; 1959 int sid;
1931 if (!sid_allocator_.AllocateSid(role, &sid)) { 1960 if (!sid_allocator_.AllocateSid(role, &sid)) {
1932 LOG(LS_ERROR) << "Failed to allocate SCTP sid."; 1961 LOG(LS_ERROR) << "Failed to allocate SCTP sid.";
1933 continue; 1962 continue;
1934 } 1963 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 2086
2058 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { 2087 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const {
2059 for (const auto& channel : sctp_data_channels_) { 2088 for (const auto& channel : sctp_data_channels_) {
2060 if (channel->id() == sid) { 2089 if (channel->id() == sid) {
2061 return channel; 2090 return channel;
2062 } 2091 }
2063 } 2092 }
2064 return nullptr; 2093 return nullptr;
2065 } 2094 }
2066 2095
2096 #ifdef HAVE_QUIC
2097 void PeerConnection::OnQuicTransportChannelCreated(
2098 cricket::QuicTransportChannel* channel) {
2099 RTC_DCHECK(signaling_thread()->IsCurrent());
2100 quic_data_transport_->SetTransportChannel(channel);
2101 }
2102 #endif // HAVE_QUIC
2103
2067 } // namespace webrtc 2104 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/peerconnection.h ('k') | webrtc/api/peerconnection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698