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 |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 // The port allocator lives on the network thread and should be initialized | 584 // The port allocator lives on the network thread and should be initialized |
585 // there. | 585 // there. |
586 if (!network_thread()->Invoke<bool>( | 586 if (!network_thread()->Invoke<bool>( |
587 RTC_FROM_HERE, rtc::Bind(&PeerConnection::InitializePortAllocator_n, | 587 RTC_FROM_HERE, rtc::Bind(&PeerConnection::InitializePortAllocator_n, |
588 this, configuration))) { | 588 this, configuration))) { |
589 return false; | 589 return false; |
590 } | 590 } |
591 | 591 |
592 media_controller_.reset( | 592 media_controller_.reset( |
593 factory_->CreateMediaController(configuration.media_config)); | 593 factory_->CreateMediaController(configuration.media_config)); |
594 | 594 #ifdef HAVE_QUIC |
| 595 if (configuration.enable_quic) { |
| 596 quic_data_transport_.reset(new QuicDataTransport( |
| 597 factory_->signaling_thread(), factory_->worker_thread(), |
| 598 factory_->network_thread())); |
| 599 } |
| 600 #endif // HAVE_QUIC |
595 session_.reset( | 601 session_.reset( |
596 new WebRtcSession(media_controller_.get(), factory_->network_thread(), | 602 new WebRtcSession(media_controller_.get(), factory_->network_thread(), |
597 factory_->worker_thread(), factory_->signaling_thread(), | 603 factory_->worker_thread(), factory_->signaling_thread(), |
598 port_allocator_.get())); | 604 port_allocator_.get())); |
599 stats_.reset(new StatsCollector(this)); | 605 stats_.reset(new StatsCollector(this)); |
600 | 606 |
601 // Initialize the WebRtcSession. It creates transport channels etc. | 607 // Initialize the WebRtcSession. It creates transport channels etc. |
602 if (!session_->Initialize(factory_->options(), std::move(cert_generator), | 608 if (!session_->Initialize(factory_->options(), std::move(cert_generator), |
603 configuration)) { | 609 configuration)) { |
604 return false; | 610 return false; |
605 } | 611 } |
606 | 612 |
607 // Register PeerConnection as receiver of local ice candidates. | 613 // Register PeerConnection as receiver of local ice candidates. |
608 // All the callbacks will be posted to the application from PeerConnection. | 614 // All the callbacks will be posted to the application from PeerConnection. |
609 session_->RegisterIceObserver(this); | 615 session_->RegisterIceObserver(this); |
610 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); | 616 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); |
611 session_->SignalVoiceChannelDestroyed.connect( | 617 session_->SignalVoiceChannelDestroyed.connect( |
612 this, &PeerConnection::OnVoiceChannelDestroyed); | 618 this, &PeerConnection::OnVoiceChannelDestroyed); |
613 session_->SignalVideoChannelDestroyed.connect( | 619 session_->SignalVideoChannelDestroyed.connect( |
614 this, &PeerConnection::OnVideoChannelDestroyed); | 620 this, &PeerConnection::OnVideoChannelDestroyed); |
615 session_->SignalDataChannelCreated.connect( | 621 session_->SignalDataChannelCreated.connect( |
616 this, &PeerConnection::OnDataChannelCreated); | 622 this, &PeerConnection::OnDataChannelCreated); |
617 session_->SignalDataChannelDestroyed.connect( | 623 session_->SignalDataChannelDestroyed.connect( |
618 this, &PeerConnection::OnDataChannelDestroyed); | 624 this, &PeerConnection::OnDataChannelDestroyed); |
619 session_->SignalDataChannelOpenMessage.connect( | 625 session_->SignalDataChannelOpenMessage.connect( |
620 this, &PeerConnection::OnDataChannelOpenMessage); | 626 this, &PeerConnection::OnDataChannelOpenMessage); |
| 627 #ifdef HAVE_QUIC |
| 628 session_->SignalQuicTransportChannelCreated.connect( |
| 629 this, &PeerConnection::OnQuicTransportChannelCreated); |
| 630 #endif // HAVE_QUIC |
621 return true; | 631 return true; |
622 } | 632 } |
623 | 633 |
624 rtc::scoped_refptr<StreamCollectionInterface> | 634 rtc::scoped_refptr<StreamCollectionInterface> |
625 PeerConnection::local_streams() { | 635 PeerConnection::local_streams() { |
626 return local_streams_; | 636 return local_streams_; |
627 } | 637 } |
628 | 638 |
629 rtc::scoped_refptr<StreamCollectionInterface> | 639 rtc::scoped_refptr<StreamCollectionInterface> |
630 PeerConnection::remote_streams() { | 640 PeerConnection::remote_streams() { |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 PeerConnectionInterface::IceGatheringState | 866 PeerConnectionInterface::IceGatheringState |
857 PeerConnection::ice_gathering_state() { | 867 PeerConnection::ice_gathering_state() { |
858 return ice_gathering_state_; | 868 return ice_gathering_state_; |
859 } | 869 } |
860 | 870 |
861 rtc::scoped_refptr<DataChannelInterface> | 871 rtc::scoped_refptr<DataChannelInterface> |
862 PeerConnection::CreateDataChannel( | 872 PeerConnection::CreateDataChannel( |
863 const std::string& label, | 873 const std::string& label, |
864 const DataChannelInit* config) { | 874 const DataChannelInit* config) { |
865 TRACE_EVENT0("webrtc", "PeerConnection::CreateDataChannel"); | 875 TRACE_EVENT0("webrtc", "PeerConnection::CreateDataChannel"); |
| 876 #ifdef HAVE_QUIC |
| 877 if (session_->data_channel_type() == cricket::DCT_QUIC) { |
| 878 // TODO(mikescarlett): Handle case when config is NULL. |
| 879 if (!config) { |
| 880 LOG(LS_ERROR) << "Missing config for QUIC data channel."; |
| 881 return nullptr; |
| 882 } |
| 883 // TODO(mikescarlett): Allow unreliable or ordered QUIC data channels. |
| 884 if (!config->reliable || config->ordered) { |
| 885 LOG(LS_ERROR) << "QUIC data channel does not implement unreliable or " |
| 886 "ordered delivery."; |
| 887 return nullptr; |
| 888 } |
| 889 return quic_data_transport_->CreateDataChannel(label, config); |
| 890 } |
| 891 #endif // HAVE_QUIC |
| 892 |
866 bool first_datachannel = !HasDataChannels(); | 893 bool first_datachannel = !HasDataChannels(); |
867 | 894 |
868 std::unique_ptr<InternalDataChannelInit> internal_config; | 895 std::unique_ptr<InternalDataChannelInit> internal_config; |
869 if (config) { | 896 if (config) { |
870 internal_config.reset(new InternalDataChannelInit(*config)); | 897 internal_config.reset(new InternalDataChannelInit(*config)); |
871 } | 898 } |
872 rtc::scoped_refptr<DataChannelInterface> channel( | 899 rtc::scoped_refptr<DataChannelInterface> channel( |
873 InternalCreateDataChannel(label, internal_config.get())); | 900 InternalCreateDataChannel(label, internal_config.get())); |
874 if (!channel.get()) { | 901 if (!channel.get()) { |
875 return nullptr; | 902 return nullptr; |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1537 if (rtc_options.offer_to_receive_video == RTCOfferAnswerOptions::kUndefined) { | 1564 if (rtc_options.offer_to_receive_video == RTCOfferAnswerOptions::kUndefined) { |
1538 session_options->recv_video = | 1565 session_options->recv_video = |
1539 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO) || | 1566 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO) || |
1540 !remote_video_tracks_.empty(); | 1567 !remote_video_tracks_.empty(); |
1541 } | 1568 } |
1542 session_options->bundle_enabled = | 1569 session_options->bundle_enabled = |
1543 session_options->bundle_enabled && | 1570 session_options->bundle_enabled && |
1544 (session_options->has_audio() || session_options->has_video() || | 1571 (session_options->has_audio() || session_options->has_video() || |
1545 session_options->has_data()); | 1572 session_options->has_data()); |
1546 | 1573 |
1547 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) { | 1574 if (HasDataChannels()) { |
1548 session_options->data_channel_type = cricket::DCT_SCTP; | 1575 session_options->data_channel_type = session_->data_channel_type(); |
1549 } | 1576 } |
1550 | 1577 |
1551 session_options->rtcp_cname = rtcp_cname_; | 1578 session_options->rtcp_cname = rtcp_cname_; |
1552 return true; | 1579 return true; |
1553 } | 1580 } |
1554 | 1581 |
1555 void PeerConnection::FinishOptionsForAnswer( | 1582 void PeerConnection::FinishOptionsForAnswer( |
1556 cricket::MediaSessionOptions* session_options) { | 1583 cricket::MediaSessionOptions* session_options) { |
1557 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of | 1584 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of |
1558 // ContentInfos. | 1585 // ContentInfos. |
1559 if (session_->remote_description()) { | 1586 if (session_->remote_description()) { |
1560 // Initialize the transport_options map. | 1587 // Initialize the transport_options map. |
1561 for (const cricket::ContentInfo& content : | 1588 for (const cricket::ContentInfo& content : |
1562 session_->remote_description()->description()->contents()) { | 1589 session_->remote_description()->description()->contents()) { |
1563 session_options->transport_options[content.name] = | 1590 session_options->transport_options[content.name] = |
1564 cricket::TransportOptions(); | 1591 cricket::TransportOptions(); |
1565 } | 1592 } |
1566 } | 1593 } |
1567 AddSendStreams(session_options, senders_, rtp_data_channels_); | 1594 AddSendStreams(session_options, senders_, rtp_data_channels_); |
1568 session_options->bundle_enabled = | 1595 session_options->bundle_enabled = |
1569 session_options->bundle_enabled && | 1596 session_options->bundle_enabled && |
1570 (session_options->has_audio() || session_options->has_video() || | 1597 (session_options->has_audio() || session_options->has_video() || |
1571 session_options->has_data()); | 1598 session_options->has_data()); |
1572 | 1599 |
1573 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams | 1600 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams |
1574 // are not signaled in the SDP so does not go through that path and must be | 1601 // are not signaled in the SDP so does not go through that path and must be |
1575 // handled here. | 1602 // handled here. |
1576 if (session_->data_channel_type() == cricket::DCT_SCTP) { | 1603 session_options->data_channel_type = session_->data_channel_type(); |
1577 session_options->data_channel_type = cricket::DCT_SCTP; | |
1578 } | |
1579 } | 1604 } |
1580 | 1605 |
1581 bool PeerConnection::GetOptionsForAnswer( | 1606 bool PeerConnection::GetOptionsForAnswer( |
1582 const MediaConstraintsInterface* constraints, | 1607 const MediaConstraintsInterface* constraints, |
1583 cricket::MediaSessionOptions* session_options) { | 1608 cricket::MediaSessionOptions* session_options) { |
1584 session_options->recv_audio = false; | 1609 session_options->recv_audio = false; |
1585 session_options->recv_video = false; | 1610 session_options->recv_video = false; |
1586 if (!ParseConstraintsForAnswer(constraints, session_options)) { | 1611 if (!ParseConstraintsForAnswer(constraints, session_options)) { |
1587 return false; | 1612 return false; |
1588 } | 1613 } |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1971 RTC_DCHECK(channel->data_channel_type() == cricket::DCT_SCTP); | 1996 RTC_DCHECK(channel->data_channel_type() == cricket::DCT_SCTP); |
1972 sctp_data_channels_.push_back(channel); | 1997 sctp_data_channels_.push_back(channel); |
1973 channel->SignalClosed.connect(this, | 1998 channel->SignalClosed.connect(this, |
1974 &PeerConnection::OnSctpDataChannelClosed); | 1999 &PeerConnection::OnSctpDataChannelClosed); |
1975 } | 2000 } |
1976 | 2001 |
1977 return channel; | 2002 return channel; |
1978 } | 2003 } |
1979 | 2004 |
1980 bool PeerConnection::HasDataChannels() const { | 2005 bool PeerConnection::HasDataChannels() const { |
| 2006 #ifdef HAVE_QUIC |
| 2007 return !rtp_data_channels_.empty() || !sctp_data_channels_.empty() || |
| 2008 (quic_data_transport_ && quic_data_transport_->HasDataChannels()); |
| 2009 #else |
1981 return !rtp_data_channels_.empty() || !sctp_data_channels_.empty(); | 2010 return !rtp_data_channels_.empty() || !sctp_data_channels_.empty(); |
| 2011 #endif // HAVE_QUIC |
1982 } | 2012 } |
1983 | 2013 |
1984 void PeerConnection::AllocateSctpSids(rtc::SSLRole role) { | 2014 void PeerConnection::AllocateSctpSids(rtc::SSLRole role) { |
1985 for (const auto& channel : sctp_data_channels_) { | 2015 for (const auto& channel : sctp_data_channels_) { |
1986 if (channel->id() < 0) { | 2016 if (channel->id() < 0) { |
1987 int sid; | 2017 int sid; |
1988 if (!sid_allocator_.AllocateSid(role, &sid)) { | 2018 if (!sid_allocator_.AllocateSid(role, &sid)) { |
1989 LOG(LS_ERROR) << "Failed to allocate SCTP sid."; | 2019 LOG(LS_ERROR) << "Failed to allocate SCTP sid."; |
1990 continue; | 2020 continue; |
1991 } | 2021 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2186 } | 2216 } |
2187 port_allocator_->set_candidate_filter( | 2217 port_allocator_->set_candidate_filter( |
2188 ConvertIceTransportTypeToCandidateFilter(configuration.type)); | 2218 ConvertIceTransportTypeToCandidateFilter(configuration.type)); |
2189 // Call this last since it may create pooled allocator sessions using the | 2219 // Call this last since it may create pooled allocator sessions using the |
2190 // candidate filter set above. | 2220 // candidate filter set above. |
2191 port_allocator_->SetConfiguration(stun_servers, turn_servers, | 2221 port_allocator_->SetConfiguration(stun_servers, turn_servers, |
2192 configuration.ice_candidate_pool_size); | 2222 configuration.ice_candidate_pool_size); |
2193 return true; | 2223 return true; |
2194 } | 2224 } |
2195 | 2225 |
| 2226 #ifdef HAVE_QUIC |
| 2227 void PeerConnection::OnQuicTransportChannelCreated( |
| 2228 cricket::QuicTransportChannel* channel) { |
| 2229 RTC_DCHECK(signaling_thread()->IsCurrent()); |
| 2230 quic_data_transport_->SetTransportChannel(channel); |
| 2231 } |
| 2232 #endif // HAVE_QUIC |
| 2233 |
2196 } // namespace webrtc | 2234 } // namespace webrtc |
OLD | NEW |