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

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

Issue 2089553002: Refactoring on QUIC (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Disable quic for review. Created 4 years, 6 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
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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 return true; 456 return true;
452 } 457 }
453 return false; 458 return false;
454 } 459 }
455 460
456 WebRtcSession::WebRtcSession(webrtc::MediaControllerInterface* media_controller, 461 WebRtcSession::WebRtcSession(webrtc::MediaControllerInterface* media_controller,
457 rtc::Thread* network_thread, 462 rtc::Thread* network_thread,
458 rtc::Thread* worker_thread, 463 rtc::Thread* worker_thread,
459 rtc::Thread* signaling_thread, 464 rtc::Thread* signaling_thread,
460 cricket::PortAllocator* port_allocator) 465 cricket::PortAllocator* port_allocator)
461 : worker_thread_(worker_thread), 466 : network_thread_(network_thread),
467 worker_thread_(worker_thread),
462 signaling_thread_(signaling_thread), 468 signaling_thread_(signaling_thread),
463 // RFC 3264: The numeric value of the session id and version in the 469 // RFC 3264: The numeric value of the session id and version in the
464 // o line MUST be representable with a "64 bit signed integer". 470 // o line MUST be representable with a "64 bit signed integer".
465 // Due to this constraint session id |sid_| is max limited to LLONG_MAX. 471 // Due to this constraint session id |sid_| is max limited to LLONG_MAX.
466 sid_(rtc::ToString(rtc::CreateRandomId64() & LLONG_MAX)), 472 sid_(rtc::ToString(rtc::CreateRandomId64() & LLONG_MAX)),
467 transport_controller_(new cricket::TransportController(signaling_thread, 473 transport_controller_(new cricket::TransportController(signaling_thread,
468 network_thread, 474 network_thread,
469 port_allocator)), 475 port_allocator)),
470 media_controller_(media_controller), 476 media_controller_(media_controller),
471 channel_manager_(media_controller_->channel_manager()), 477 channel_manager_(media_controller_->channel_manager()),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 if (rtc_configuration.enable_dtls_srtp) { 544 if (rtc_configuration.enable_dtls_srtp) {
539 dtls_enabled_ = *(rtc_configuration.enable_dtls_srtp); 545 dtls_enabled_ = *(rtc_configuration.enable_dtls_srtp);
540 } 546 }
541 } 547 }
542 548
543 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set. 549 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set.
544 // It takes precendence over the disable_sctp_data_channels 550 // It takes precendence over the disable_sctp_data_channels
545 // PeerConnectionFactoryInterface::Options. 551 // PeerConnectionFactoryInterface::Options.
546 if (rtc_configuration.enable_rtp_data_channel) { 552 if (rtc_configuration.enable_rtp_data_channel) {
547 data_channel_type_ = cricket::DCT_RTP; 553 data_channel_type_ = cricket::DCT_RTP;
548 } else { 554 }
555 #ifdef HAVE_QUIC
556 else if (rtc_configuration.enable_quic && dtls_enabled_) {
pthatcher1 2016/06/28 22:39:03 I don't think we need to check for dtls_enabled_.
557 // Use QUIC instead of DTLS when |enable_quic| is true and encryption is
558 // enabled.
559 data_channel_type_ = cricket::DCT_QUIC;
560 transport_controller_->use_quic();
561 LOG(LS_INFO) << "Using QUIC instead of DTLS";
pthatcher1 2016/06/28 22:39:03 We could log this if dtls_enabled_. But otherwise
562 }
563 #endif // HAVE_QUIC
564 else {
549 // DTLS has to be enabled to use SCTP. 565 // DTLS has to be enabled to use SCTP.
550 if (!options.disable_sctp_data_channels && dtls_enabled_) { 566 if (!options.disable_sctp_data_channels && dtls_enabled_) {
551 data_channel_type_ = cricket::DCT_SCTP; 567 data_channel_type_ = cricket::DCT_SCTP;
552 } 568 }
553 } 569 }
554 570
555 video_options_.screencast_min_bitrate_kbps = 571 video_options_.screencast_min_bitrate_kbps =
556 rtc_configuration.screencast_min_bitrate; 572 rtc_configuration.screencast_min_bitrate;
557 audio_options_.combined_audio_video_bwe = 573 audio_options_.combined_audio_video_bwe =
558 rtc_configuration.combined_audio_video_bwe; 574 rtc_configuration.combined_audio_video_bwe;
(...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1796 this, &WebRtcSession::OnChannelFirstPacketReceived); 1812 this, &WebRtcSession::OnChannelFirstPacketReceived);
1797 1813
1798 SignalVideoChannelCreated(); 1814 SignalVideoChannelCreated();
1799 video_channel_->SignalSentPacket.connect(this, 1815 video_channel_->SignalSentPacket.connect(this,
1800 &WebRtcSession::OnSentPacket_w); 1816 &WebRtcSession::OnSentPacket_w);
1801 return true; 1817 return true;
1802 } 1818 }
1803 1819
1804 bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content, 1820 bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content,
1805 const std::string* bundle_transport) { 1821 const std::string* bundle_transport) {
1822 #ifdef HAVE_QUIC
1823 if (data_channel_type_ == cricket::DCT_QUIC) {
1824 // The TransportController may not have a QuicTransportChannel, so force
1825 // creation of it.
1826 LOG(LS_INFO) << "Getting or creating QuicTransportChannel";
1827 RTC_DCHECK(transport_controller_->quic());
1828 cricket::TransportChannel* transport_channel =
1829 network_thread_->Invoke<cricket::TransportChannel*>(
1830 RTC_FROM_HERE,
1831 rtc::Bind(&cricket::TransportController::CreateTransportChannel_n,
1832 transport_controller_.get(), content->name,
1833 cricket::ICE_CANDIDATE_COMPONENT_RTP));
1834 if (!transport_channel) {
1835 return false;
1836 }
1837 quic_transport_channel_ =
1838 static_cast<cricket::QuicTransportChannel*>(transport_channel);
1839 SignalQuicTransportChannelCreated(quic_transport_channel_);
1840 return true;
1841 }
1842 #endif // HAVE_QUIC
Taylor Brandstetter 2016/06/29 17:50:04 I think this needs to be rethought. This design me
pthatcher1 2016/06/29 18:35:28 Yeah, we can discuss it in person. This was the d
1806 bool sctp = (data_channel_type_ == cricket::DCT_SCTP); 1843 bool sctp = (data_channel_type_ == cricket::DCT_SCTP);
1807 bool require_rtcp_mux = 1844 bool require_rtcp_mux =
1808 rtcp_mux_policy_ == PeerConnectionInterface::kRtcpMuxPolicyRequire; 1845 rtcp_mux_policy_ == PeerConnectionInterface::kRtcpMuxPolicyRequire;
1809 bool create_rtcp_transport_channel = !sctp && !require_rtcp_mux; 1846 bool create_rtcp_transport_channel = !sctp && !require_rtcp_mux;
1810 data_channel_.reset(channel_manager_->CreateDataChannel( 1847 data_channel_.reset(channel_manager_->CreateDataChannel(
1811 transport_controller_.get(), content->name, bundle_transport, 1848 transport_controller_.get(), content->name, bundle_transport,
1812 create_rtcp_transport_channel, data_channel_type_)); 1849 create_rtcp_transport_channel, data_channel_type_));
1813 if (!data_channel_) { 1850 if (!data_channel_) {
1814 return false; 1851 return false;
1815 } 1852 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1994 2031
1995 // We need to check the local/remote description for the Transport instead of 2032 // We need to check the local/remote description for the Transport instead of
1996 // the session, because a new Transport added during renegotiation may have 2033 // the session, because a new Transport added during renegotiation may have
1997 // them unset while the session has them set from the previous negotiation. 2034 // them unset while the session has them set from the previous negotiation.
1998 // Not doing so may trigger the auto generation of transport description and 2035 // Not doing so may trigger the auto generation of transport description and
1999 // mess up DTLS identity information, ICE credential, etc. 2036 // mess up DTLS identity information, ICE credential, etc.
2000 bool WebRtcSession::ReadyToUseRemoteCandidate( 2037 bool WebRtcSession::ReadyToUseRemoteCandidate(
2001 const IceCandidateInterface* candidate, 2038 const IceCandidateInterface* candidate,
2002 const SessionDescriptionInterface* remote_desc, 2039 const SessionDescriptionInterface* remote_desc,
2003 bool* valid) { 2040 bool* valid) {
2004 *valid = true;; 2041 *valid = true;
2005 2042
2006 const SessionDescriptionInterface* current_remote_desc = 2043 const SessionDescriptionInterface* current_remote_desc =
2007 remote_desc ? remote_desc : remote_desc_.get(); 2044 remote_desc ? remote_desc : remote_desc_.get();
2008 2045
2009 if (!current_remote_desc) { 2046 if (!current_remote_desc) {
2010 return false; 2047 return false;
2011 } 2048 }
2012 2049
2013 size_t mediacontent_index = 2050 size_t mediacontent_index =
2014 static_cast<size_t>(candidate->sdp_mline_index()); 2051 static_cast<size_t>(candidate->sdp_mline_index());
2015 size_t remote_content_size = 2052 size_t remote_content_size =
2016 current_remote_desc->description()->contents().size(); 2053 current_remote_desc->description()->contents().size();
2017 if (mediacontent_index >= remote_content_size) { 2054 if (mediacontent_index >= remote_content_size) {
2018 LOG(LS_ERROR) << "ReadyToUseRemoteCandidate: Invalid candidate media index " 2055 LOG(LS_ERROR) << "ReadyToUseRemoteCandidate: Invalid candidate media index "
2019 << mediacontent_index; 2056 << mediacontent_index;
2020 2057
2021 *valid = false; 2058 *valid = false;
2022 return false; 2059 return false;
2023 } 2060 }
2024 2061
2025 cricket::ContentInfo content = 2062 cricket::ContentInfo content =
2026 current_remote_desc->description()->contents()[mediacontent_index]; 2063 current_remote_desc->description()->contents()[mediacontent_index];
2027 cricket::BaseChannel* channel = GetChannel(content.name); 2064 cricket::BaseChannel* channel = GetChannel(content.name);
2028 if (!channel) { 2065 if (!channel) {
2066 #ifdef HAVE_QUIC
2067 if (data_channel_type_ == cricket::DCT_QUIC && quic_transport_channel_ &&
2068 content.name == quic_transport_channel_->transport_name()) {
2069 // QUIC data channels do not have a BaseChannel unless bundle is enabled.
2070 return transport_controller_->ReadyForRemoteCandidates(
2071 quic_transport_channel_->transport_name());
2072 }
2073 #endif // HAVE_QUIC
2029 return false; 2074 return false;
2030 } 2075 }
2031 2076
2032 return transport_controller_->ReadyForRemoteCandidates( 2077 return transport_controller_->ReadyForRemoteCandidates(
2033 channel->transport_name()); 2078 channel->transport_name());
2034 } 2079 }
2035 2080
2036 void WebRtcSession::OnTransportControllerGatheringState( 2081 void WebRtcSession::OnTransportControllerGatheringState(
2037 cricket::IceGatheringState state) { 2082 cricket::IceGatheringState state) {
2038 ASSERT(signaling_thread()->IsCurrent()); 2083 ASSERT(signaling_thread()->IsCurrent());
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2161 ssl_cipher_suite); 2206 ssl_cipher_suite);
2162 } 2207 }
2163 } 2208 }
2164 2209
2165 void WebRtcSession::OnSentPacket_w(const rtc::SentPacket& sent_packet) { 2210 void WebRtcSession::OnSentPacket_w(const rtc::SentPacket& sent_packet) {
2166 RTC_DCHECK(worker_thread()->IsCurrent()); 2211 RTC_DCHECK(worker_thread()->IsCurrent());
2167 media_controller_->call_w()->OnSentPacket(sent_packet); 2212 media_controller_->call_w()->OnSentPacket(sent_packet);
2168 } 2213 }
2169 2214
2170 } // namespace webrtc 2215 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698