OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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) { | |
557 // Use QUIC instead of DTLS when |enable_quic| is true. | |
558 data_channel_type_ = cricket::DCT_QUIC; | |
559 transport_controller_->use_quic(); | |
560 if (dtls_enabled_) { | |
561 LOG(LS_INFO) << "Using QUIC instead of DTLS"; | |
562 } | |
563 quic_data_transport_.reset( | |
564 new QuicDataTransport(signaling_thread(), worker_thread(), | |
565 network_thread(), transport_controller_.get())); | |
566 } | |
567 #endif // HAVE_QUIC | |
568 else { | |
549 // DTLS has to be enabled to use SCTP. | 569 // DTLS has to be enabled to use SCTP. |
550 if (!options.disable_sctp_data_channels && dtls_enabled_) { | 570 if (!options.disable_sctp_data_channels && dtls_enabled_) { |
551 data_channel_type_ = cricket::DCT_SCTP; | 571 data_channel_type_ = cricket::DCT_SCTP; |
552 } | 572 } |
553 } | 573 } |
554 | 574 |
555 video_options_.screencast_min_bitrate_kbps = | 575 video_options_.screencast_min_bitrate_kbps = |
556 rtc_configuration.screencast_min_bitrate; | 576 rtc_configuration.screencast_min_bitrate; |
557 audio_options_.combined_audio_video_bwe = | 577 audio_options_.combined_audio_video_bwe = |
558 rtc_configuration.combined_audio_video_bwe; | 578 rtc_configuration.combined_audio_video_bwe; |
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1652 this, &WebRtcSession::OnDtlsSetupFailure); | 1672 this, &WebRtcSession::OnDtlsSetupFailure); |
1653 | 1673 |
1654 SignalVideoChannelCreated(); | 1674 SignalVideoChannelCreated(); |
1655 video_channel_->SignalSentPacket.connect(this, | 1675 video_channel_->SignalSentPacket.connect(this, |
1656 &WebRtcSession::OnSentPacket_w); | 1676 &WebRtcSession::OnSentPacket_w); |
1657 return true; | 1677 return true; |
1658 } | 1678 } |
1659 | 1679 |
1660 bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content, | 1680 bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content, |
1661 const std::string* bundle_transport) { | 1681 const std::string* bundle_transport) { |
1682 #ifdef HAVE_QUIC | |
1683 if (data_channel_type_ == cricket::DCT_QUIC) { | |
1684 // The TransportController may not have a QuicTransportChannel, so force | |
1685 // creation of it. | |
1686 LOG(LS_INFO) << "Getting or creating QuicTransportChannel"; | |
1687 RTC_DCHECK(transport_controller_->quic()); | |
1688 cricket::TransportChannel* transport_channel = | |
1689 network_thread_->Invoke<cricket::TransportChannel*>( | |
1690 RTC_FROM_HERE, | |
1691 rtc::Bind(&cricket::TransportController::CreateTransportChannel_n, | |
1692 transport_controller_.get(), content->name, | |
1693 cricket::ICE_CANDIDATE_COMPONENT_RTP)); | |
1694 if (!transport_channel) { | |
1695 return false; | |
1696 } | |
1697 quic_transport_channel_ = | |
1698 static_cast<cricket::QuicTransportChannel*>(transport_channel); | |
1699 quic_data_transport_->SetTransportChannel(quic_transport_channel_); | |
1700 quic_data_transport_->set_transport_name(content->name); | |
1701 quic_data_transport_->set_content_name(content->name); | |
1702 return true; | |
pthatcher1
2016/07/22 17:57:57
I don't understand why we create the quic_transpor
Zhi Huang
2016/07/25 23:40:36
Yes, we don't need quic_transport_channel_ here an
| |
1703 } | |
1704 #endif // HAVE_QUIC | |
Taylor Brandstetter
2016/07/21 23:39:57
Ok, so when using QUIC, the QuicTransportChannel a
| |
1662 bool sctp = (data_channel_type_ == cricket::DCT_SCTP); | 1705 bool sctp = (data_channel_type_ == cricket::DCT_SCTP); |
1663 bool require_rtcp_mux = | 1706 bool require_rtcp_mux = |
1664 rtcp_mux_policy_ == PeerConnectionInterface::kRtcpMuxPolicyRequire; | 1707 rtcp_mux_policy_ == PeerConnectionInterface::kRtcpMuxPolicyRequire; |
1665 bool create_rtcp_transport_channel = !sctp && !require_rtcp_mux; | 1708 bool create_rtcp_transport_channel = !sctp && !require_rtcp_mux; |
1666 data_channel_.reset(channel_manager_->CreateDataChannel( | 1709 data_channel_.reset(channel_manager_->CreateDataChannel( |
1667 transport_controller_.get(), content->name, bundle_transport, | 1710 transport_controller_.get(), content->name, bundle_transport, |
1668 create_rtcp_transport_channel, data_channel_type_)); | 1711 create_rtcp_transport_channel, data_channel_type_)); |
1669 if (!data_channel_) { | 1712 if (!data_channel_) { |
1670 return false; | 1713 return false; |
1671 } | 1714 } |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1835 | 1878 |
1836 // We need to check the local/remote description for the Transport instead of | 1879 // We need to check the local/remote description for the Transport instead of |
1837 // the session, because a new Transport added during renegotiation may have | 1880 // the session, because a new Transport added during renegotiation may have |
1838 // them unset while the session has them set from the previous negotiation. | 1881 // them unset while the session has them set from the previous negotiation. |
1839 // Not doing so may trigger the auto generation of transport description and | 1882 // Not doing so may trigger the auto generation of transport description and |
1840 // mess up DTLS identity information, ICE credential, etc. | 1883 // mess up DTLS identity information, ICE credential, etc. |
1841 bool WebRtcSession::ReadyToUseRemoteCandidate( | 1884 bool WebRtcSession::ReadyToUseRemoteCandidate( |
1842 const IceCandidateInterface* candidate, | 1885 const IceCandidateInterface* candidate, |
1843 const SessionDescriptionInterface* remote_desc, | 1886 const SessionDescriptionInterface* remote_desc, |
1844 bool* valid) { | 1887 bool* valid) { |
1845 *valid = true;; | 1888 *valid = true; |
1846 | 1889 |
1847 const SessionDescriptionInterface* current_remote_desc = | 1890 const SessionDescriptionInterface* current_remote_desc = |
1848 remote_desc ? remote_desc : remote_desc_.get(); | 1891 remote_desc ? remote_desc : remote_desc_.get(); |
1849 | 1892 |
1850 if (!current_remote_desc) { | 1893 if (!current_remote_desc) { |
1851 return false; | 1894 return false; |
1852 } | 1895 } |
1853 | 1896 |
1854 size_t mediacontent_index = | 1897 size_t mediacontent_index = |
1855 static_cast<size_t>(candidate->sdp_mline_index()); | 1898 static_cast<size_t>(candidate->sdp_mline_index()); |
1856 size_t remote_content_size = | 1899 size_t remote_content_size = |
1857 current_remote_desc->description()->contents().size(); | 1900 current_remote_desc->description()->contents().size(); |
1858 if (mediacontent_index >= remote_content_size) { | 1901 if (mediacontent_index >= remote_content_size) { |
1859 LOG(LS_ERROR) << "ReadyToUseRemoteCandidate: Invalid candidate media index " | 1902 LOG(LS_ERROR) << "ReadyToUseRemoteCandidate: Invalid candidate media index " |
1860 << mediacontent_index; | 1903 << mediacontent_index; |
1861 | 1904 |
1862 *valid = false; | 1905 *valid = false; |
1863 return false; | 1906 return false; |
1864 } | 1907 } |
1865 | 1908 |
1866 cricket::ContentInfo content = | 1909 cricket::ContentInfo content = |
1867 current_remote_desc->description()->contents()[mediacontent_index]; | 1910 current_remote_desc->description()->contents()[mediacontent_index]; |
1868 cricket::BaseChannel* channel = GetChannel(content.name); | 1911 cricket::BaseChannel* channel = GetChannel(content.name); |
pthatcher1
2016/07/22 17:57:57
I think we should add a method called GetTransport
Zhi Huang
2016/07/25 23:40:36
Done.
| |
1869 if (!channel) { | 1912 if (!channel) { |
1913 #ifdef HAVE_QUIC | |
1914 if (data_channel_type_ == cricket::DCT_QUIC && quic_transport_channel_ && | |
1915 content.name == quic_transport_channel_->transport_name()) { | |
1916 // QUIC data channels do not have a BaseChannel unless bundle is enabled. | |
1917 return transport_controller_->ReadyForRemoteCandidates( | |
1918 quic_transport_channel_->transport_name()); | |
pthatcher1
2016/07/22 17:57:57
Why get it from the quic_transport_channel_ instea
Zhi Huang
2016/07/25 23:40:36
Done.
| |
1919 } | |
1920 #endif // HAVE_QUIC | |
1870 return false; | 1921 return false; |
1871 } | 1922 } |
1872 | 1923 |
1873 return transport_controller_->ReadyForRemoteCandidates( | 1924 return transport_controller_->ReadyForRemoteCandidates( |
1874 channel->transport_name()); | 1925 channel->transport_name()); |
1875 } | 1926 } |
1876 | 1927 |
1877 void WebRtcSession::OnTransportControllerGatheringState( | 1928 void WebRtcSession::OnTransportControllerGatheringState( |
1878 cricket::IceGatheringState state) { | 1929 cricket::IceGatheringState state) { |
1879 ASSERT(signaling_thread()->IsCurrent()); | 1930 ASSERT(signaling_thread()->IsCurrent()); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2001 metrics_observer_->IncrementSparseEnumCounter(ssl_counter_type, | 2052 metrics_observer_->IncrementSparseEnumCounter(ssl_counter_type, |
2002 ssl_cipher_suite); | 2053 ssl_cipher_suite); |
2003 } | 2054 } |
2004 } | 2055 } |
2005 | 2056 |
2006 void WebRtcSession::OnSentPacket_w(const rtc::SentPacket& sent_packet) { | 2057 void WebRtcSession::OnSentPacket_w(const rtc::SentPacket& sent_packet) { |
2007 RTC_DCHECK(worker_thread()->IsCurrent()); | 2058 RTC_DCHECK(worker_thread()->IsCurrent()); |
2008 media_controller_->call_w()->OnSentPacket(sent_packet); | 2059 media_controller_->call_w()->OnSentPacket(sent_packet); |
2009 } | 2060 } |
2010 | 2061 |
2011 } // namespace webrtc | 2062 } // namespace webrtc |
Taylor Brandstetter
2016/07/21 23:39:57
We still need to clean up the QuicDataTransport at
pthatcher1
2016/07/22 17:57:57
Agreed, but I would say we should just destroy the
| |
OLD | NEW |