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

Side by Side Diff: webrtc/api/webrtcsession.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/webrtcsession.h ('k') | webrtc/api/webrtcsession_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
11 #include "webrtc/api/webrtcsession.h" 11 #include "webrtc/api/webrtcsession.h"
12 12
13 #include <limits.h> 13 #include <limits.h>
14 14
15 #include <algorithm> 15 #include <algorithm>
16 #include <set> 16 #include <set>
17 #include <utility> 17 #include <utility>
18 #include <vector> 18 #include <vector>
19 19
20 #include "webrtc/api/jsepicecandidate.h" 20 #include "webrtc/api/jsepicecandidate.h"
21 #include "webrtc/api/jsepsessiondescription.h" 21 #include "webrtc/api/jsepsessiondescription.h"
22 #include "webrtc/api/peerconnectioninterface.h" 22 #include "webrtc/api/peerconnectioninterface.h"
23 #include "webrtc/api/sctputils.h" 23 #include "webrtc/api/sctputils.h"
24 #include "webrtc/api/webrtcsessiondescriptionfactory.h" 24 #include "webrtc/api/webrtcsessiondescriptionfactory.h"
25 #include "webrtc/audio_sink.h" 25 #include "webrtc/audio_sink.h"
26 #include "webrtc/base/basictypes.h" 26 #include "webrtc/base/basictypes.h"
27 #include "webrtc/base/bind.h"
27 #include "webrtc/base/checks.h" 28 #include "webrtc/base/checks.h"
28 #include "webrtc/base/helpers.h" 29 #include "webrtc/base/helpers.h"
29 #include "webrtc/base/logging.h" 30 #include "webrtc/base/logging.h"
30 #include "webrtc/base/stringencode.h" 31 #include "webrtc/base/stringencode.h"
31 #include "webrtc/base/stringutils.h" 32 #include "webrtc/base/stringutils.h"
32 #include "webrtc/call.h" 33 #include "webrtc/call.h"
33 #include "webrtc/media/base/mediaconstants.h" 34 #include "webrtc/media/base/mediaconstants.h"
34 #include "webrtc/media/base/videocapturer.h" 35 #include "webrtc/media/base/videocapturer.h"
35 #include "webrtc/p2p/base/portallocator.h" 36 #include "webrtc/p2p/base/portallocator.h"
36 #include "webrtc/p2p/base/transportchannel.h" 37 #include "webrtc/p2p/base/transportchannel.h"
37 #include "webrtc/pc/channel.h" 38 #include "webrtc/pc/channel.h"
38 #include "webrtc/pc/channelmanager.h" 39 #include "webrtc/pc/channelmanager.h"
39 #include "webrtc/pc/mediasession.h" 40 #include "webrtc/pc/mediasession.h"
40 41
42 #ifdef HAVE_QUIC
43 #include "webrtc/p2p/quic/quictransportchannel.h"
44 #endif // HAVE_QUIC
45
41 using cricket::ContentInfo; 46 using cricket::ContentInfo;
42 using cricket::ContentInfos; 47 using cricket::ContentInfos;
43 using cricket::MediaContentDescription; 48 using cricket::MediaContentDescription;
44 using cricket::SessionDescription; 49 using cricket::SessionDescription;
45 using cricket::TransportInfo; 50 using cricket::TransportInfo;
46 51
47 using cricket::LOCAL_PORT_TYPE; 52 using cricket::LOCAL_PORT_TYPE;
48 using cricket::STUN_PORT_TYPE; 53 using cricket::STUN_PORT_TYPE;
49 using cricket::RELAY_PORT_TYPE; 54 using cricket::RELAY_PORT_TYPE;
50 using cricket::PRFLX_PORT_TYPE; 55 using cricket::PRFLX_PORT_TYPE;
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 if (rtc_configuration.enable_dtls_srtp) { 559 if (rtc_configuration.enable_dtls_srtp) {
555 dtls_enabled_ = *(rtc_configuration.enable_dtls_srtp); 560 dtls_enabled_ = *(rtc_configuration.enable_dtls_srtp);
556 } 561 }
557 } 562 }
558 563
559 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set. 564 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set.
560 // It takes precendence over the disable_sctp_data_channels 565 // It takes precendence over the disable_sctp_data_channels
561 // PeerConnectionFactoryInterface::Options. 566 // PeerConnectionFactoryInterface::Options.
562 if (rtc_configuration.enable_rtp_data_channel) { 567 if (rtc_configuration.enable_rtp_data_channel) {
563 data_channel_type_ = cricket::DCT_RTP; 568 data_channel_type_ = cricket::DCT_RTP;
564 } else { 569 }
570 #ifdef HAVE_QUIC
571 else if (rtc_configuration.enable_quic && dtls_enabled_) {
572 // Use QUIC instead of DTLS when |enable_quic| is true and encryption is
573 // enabled.
574 data_channel_type_ = cricket::DCT_QUIC;
575 transport_controller_->use_quic();
576 LOG(LS_INFO) << "Using QUIC instead of DTLS";
577 }
578 #endif // HAVE_QUIC
579 else {
565 // DTLS has to be enabled to use SCTP. 580 // DTLS has to be enabled to use SCTP.
566 if (!options.disable_sctp_data_channels && dtls_enabled_) { 581 if (!options.disable_sctp_data_channels && dtls_enabled_) {
567 data_channel_type_ = cricket::DCT_SCTP; 582 data_channel_type_ = cricket::DCT_SCTP;
568 } 583 }
569 } 584 }
570 585
571 video_options_.screencast_min_bitrate_kbps = 586 video_options_.screencast_min_bitrate_kbps =
572 rtc_configuration.screencast_min_bitrate; 587 rtc_configuration.screencast_min_bitrate;
573 audio_options_.combined_audio_video_bwe = 588 audio_options_.combined_audio_video_bwe =
574 rtc_configuration.combined_audio_video_bwe; 589 rtc_configuration.combined_audio_video_bwe;
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1741 1756
1742 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc); 1757 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
1743 if (video && !video->rejected && !video_channel_) { 1758 if (video && !video->rejected && !video_channel_) {
1744 if (!CreateVideoChannel(video)) { 1759 if (!CreateVideoChannel(video)) {
1745 LOG(LS_ERROR) << "Failed to create video channel."; 1760 LOG(LS_ERROR) << "Failed to create video channel.";
1746 return false; 1761 return false;
1747 } 1762 }
1748 } 1763 }
1749 1764
1750 const cricket::ContentInfo* data = cricket::GetFirstDataContent(desc); 1765 const cricket::ContentInfo* data = cricket::GetFirstDataContent(desc);
1751 if (data_channel_type_ != cricket::DCT_NONE && 1766 if (data_channel_type_ != cricket::DCT_NONE && data && !data->rejected &&
1752 data && !data->rejected && !data_channel_) { 1767 !data_channel_) {
1753 if (!CreateDataChannel(data)) { 1768 if (!CreateDataChannel(data)) {
1754 LOG(LS_ERROR) << "Failed to create data channel."; 1769 LOG(LS_ERROR) << "Failed to create data channel.";
1755 return false; 1770 return false;
1756 } 1771 }
1757 } 1772 }
1758 1773
1759 if (rtcp_mux_policy_ == PeerConnectionInterface::kRtcpMuxPolicyRequire) { 1774 if (rtcp_mux_policy_ == PeerConnectionInterface::kRtcpMuxPolicyRequire) {
1760 if (voice_channel()) { 1775 if (voice_channel()) {
1761 voice_channel()->ActivateRtcpMux(); 1776 voice_channel()->ActivateRtcpMux();
1762 } 1777 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 video_channel_->SignalDtlsSetupFailure.connect( 1828 video_channel_->SignalDtlsSetupFailure.connect(
1814 this, &WebRtcSession::OnDtlsSetupFailure); 1829 this, &WebRtcSession::OnDtlsSetupFailure);
1815 1830
1816 SignalVideoChannelCreated(); 1831 SignalVideoChannelCreated();
1817 video_channel_->transport_channel()->SignalSentPacket.connect( 1832 video_channel_->transport_channel()->SignalSentPacket.connect(
1818 this, &WebRtcSession::OnSentPacket_w); 1833 this, &WebRtcSession::OnSentPacket_w);
1819 return true; 1834 return true;
1820 } 1835 }
1821 1836
1822 bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content) { 1837 bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content) {
1823 bool sctp = (data_channel_type_ == cricket::DCT_SCTP); 1838 #ifdef HAVE_QUIC
1839 if (data_channel_type_ == cricket::DCT_QUIC) {
1840 // The TransportController may not have a QuicTransportChannel, so force
1841 // creation of it.
1842 LOG(LS_INFO) << "Getting or creating QuicTransportChannel";
1843 RTC_DCHECK(transport_controller_->quic());
1844 cricket::TransportChannel* transport_channel =
1845 worker_thread_->Invoke<cricket::TransportChannel*>(
1846 rtc::Bind(&cricket::TransportController::CreateTransportChannel_w,
1847 transport_controller_.get(), content->name,
1848 cricket::ICE_CANDIDATE_COMPONENT_RTP));
1849 if (!transport_channel) {
1850 return false;
1851 }
1852 quic_transport_channel_ =
1853 static_cast<cricket::QuicTransportChannel*>(transport_channel);
1854 SignalQuicTransportChannelCreated(quic_transport_channel_);
1855 return true;
1856 }
1857 #endif // HAVE_QUIC
1858 bool sctp = data_channel_type_ == cricket::DCT_SCTP;
1824 data_channel_.reset(channel_manager_->CreateDataChannel( 1859 data_channel_.reset(channel_manager_->CreateDataChannel(
1825 transport_controller_.get(), content->name, !sctp, data_channel_type_)); 1860 transport_controller_.get(), content->name, !sctp, data_channel_type_));
1826 if (!data_channel_) { 1861 if (!data_channel_) {
1827 return false; 1862 return false;
1828 } 1863 }
1829 1864
1830 if (sctp) { 1865 if (sctp) {
1831 data_channel_->SignalDataReceived.connect( 1866 data_channel_->SignalDataReceived.connect(
1832 this, &WebRtcSession::OnDataChannelMessageReceived); 1867 this, &WebRtcSession::OnDataChannelMessageReceived);
1833 } 1868 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 2022
1988 // We need to check the local/remote description for the Transport instead of 2023 // We need to check the local/remote description for the Transport instead of
1989 // the session, because a new Transport added during renegotiation may have 2024 // the session, because a new Transport added during renegotiation may have
1990 // them unset while the session has them set from the previous negotiation. 2025 // them unset while the session has them set from the previous negotiation.
1991 // Not doing so may trigger the auto generation of transport description and 2026 // Not doing so may trigger the auto generation of transport description and
1992 // mess up DTLS identity information, ICE credential, etc. 2027 // mess up DTLS identity information, ICE credential, etc.
1993 bool WebRtcSession::ReadyToUseRemoteCandidate( 2028 bool WebRtcSession::ReadyToUseRemoteCandidate(
1994 const IceCandidateInterface* candidate, 2029 const IceCandidateInterface* candidate,
1995 const SessionDescriptionInterface* remote_desc, 2030 const SessionDescriptionInterface* remote_desc,
1996 bool* valid) { 2031 bool* valid) {
1997 *valid = true;; 2032 *valid = true;
1998 2033
1999 const SessionDescriptionInterface* current_remote_desc = 2034 const SessionDescriptionInterface* current_remote_desc =
2000 remote_desc ? remote_desc : remote_desc_.get(); 2035 remote_desc ? remote_desc : remote_desc_.get();
2001 2036
2002 if (!current_remote_desc) { 2037 if (!current_remote_desc) {
2003 return false; 2038 return false;
2004 } 2039 }
2005 2040
2006 size_t mediacontent_index = 2041 size_t mediacontent_index =
2007 static_cast<size_t>(candidate->sdp_mline_index()); 2042 static_cast<size_t>(candidate->sdp_mline_index());
2008 size_t remote_content_size = 2043 size_t remote_content_size =
2009 current_remote_desc->description()->contents().size(); 2044 current_remote_desc->description()->contents().size();
2010 if (mediacontent_index >= remote_content_size) { 2045 if (mediacontent_index >= remote_content_size) {
2011 LOG(LS_ERROR) << "ReadyToUseRemoteCandidate: Invalid candidate media index " 2046 LOG(LS_ERROR) << "ReadyToUseRemoteCandidate: Invalid candidate media index "
2012 << mediacontent_index; 2047 << mediacontent_index;
2013 2048
2014 *valid = false; 2049 *valid = false;
2015 return false; 2050 return false;
2016 } 2051 }
2017 2052
2018 cricket::ContentInfo content = 2053 cricket::ContentInfo content =
2019 current_remote_desc->description()->contents()[mediacontent_index]; 2054 current_remote_desc->description()->contents()[mediacontent_index];
2020 cricket::BaseChannel* channel = GetChannel(content.name); 2055 cricket::BaseChannel* channel = GetChannel(content.name);
2021 if (!channel) { 2056 if (!channel) {
2057 #ifdef HAVE_QUIC
2058 if (data_channel_type_ == cricket::DCT_QUIC && quic_transport_channel_ &&
2059 content.name == quic_transport_channel_->transport_name()) {
2060 // QUIC data channels do not have a BaseChannel unless bundle is enabled.
2061 return transport_controller_->ReadyForRemoteCandidates(
2062 quic_transport_channel_->transport_name());
2063 }
2064 #endif // HAVE_QUIC
2022 return false; 2065 return false;
2023 } 2066 }
2024 2067
2025 return transport_controller_->ReadyForRemoteCandidates( 2068 return transport_controller_->ReadyForRemoteCandidates(
2026 channel->transport_name()); 2069 channel->transport_name());
2027 } 2070 }
2028 2071
2029 void WebRtcSession::OnTransportControllerGatheringState( 2072 void WebRtcSession::OnTransportControllerGatheringState(
2030 cricket::IceGatheringState state) { 2073 cricket::IceGatheringState state) {
2031 ASSERT(signaling_thread()->IsCurrent()); 2074 ASSERT(signaling_thread()->IsCurrent());
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 } 2198 }
2156 } 2199 }
2157 2200
2158 void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel, 2201 void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel,
2159 const rtc::SentPacket& sent_packet) { 2202 const rtc::SentPacket& sent_packet) {
2160 RTC_DCHECK(worker_thread()->IsCurrent()); 2203 RTC_DCHECK(worker_thread()->IsCurrent());
2161 media_controller_->call_w()->OnSentPacket(sent_packet); 2204 media_controller_->call_w()->OnSentPacket(sent_packet);
2162 } 2205 }
2163 2206
2164 } // namespace webrtc 2207 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/webrtcsession.h ('k') | webrtc/api/webrtcsession_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698