| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/protocol/webrtc_transport.h" | 5 #include "remoting/protocol/webrtc_transport.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 event_handler_(event_handler), | 147 event_handler_(event_handler), |
| 148 handshake_hmac_(crypto::HMAC::SHA256), | 148 handshake_hmac_(crypto::HMAC::SHA256), |
| 149 weak_factory_(this) { | 149 weak_factory_(this) { |
| 150 transport_context_->set_relay_mode(TransportContext::RelayMode::TURN); | 150 transport_context_->set_relay_mode(TransportContext::RelayMode::TURN); |
| 151 } | 151 } |
| 152 | 152 |
| 153 WebrtcTransport::~WebrtcTransport() {} | 153 WebrtcTransport::~WebrtcTransport() {} |
| 154 | 154 |
| 155 std::unique_ptr<MessagePipe> WebrtcTransport::CreateOutgoingChannel( | 155 std::unique_ptr<MessagePipe> WebrtcTransport::CreateOutgoingChannel( |
| 156 const std::string& name) { | 156 const std::string& name) { |
| 157 return data_stream_adapter_->CreateOutgoingChannel(name); | 157 webrtc::DataChannelInit config; |
| 158 config.reliable = true; |
| 159 return base::WrapUnique(new WebrtcDataStreamAdapter( |
| 160 peer_connection_->CreateDataChannel(name, &config))); |
| 158 } | 161 } |
| 159 | 162 |
| 160 void WebrtcTransport::Start( | 163 void WebrtcTransport::Start( |
| 161 Authenticator* authenticator, | 164 Authenticator* authenticator, |
| 162 SendTransportInfoCallback send_transport_info_callback) { | 165 SendTransportInfoCallback send_transport_info_callback) { |
| 163 DCHECK(thread_checker_.CalledOnValidThread()); | 166 DCHECK(thread_checker_.CalledOnValidThread()); |
| 164 DCHECK(send_transport_info_callback_.is_null()); | 167 DCHECK(send_transport_info_callback_.is_null()); |
| 165 | 168 |
| 166 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | 169 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
| 167 | 170 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 190 webrtc::FakeConstraints constraints; | 193 webrtc::FakeConstraints constraints; |
| 191 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | 194 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 192 webrtc::MediaConstraintsInterface::kValueTrue); | 195 webrtc::MediaConstraintsInterface::kValueTrue); |
| 193 | 196 |
| 194 std::unique_ptr<cricket::PortAllocator> port_allocator = | 197 std::unique_ptr<cricket::PortAllocator> port_allocator = |
| 195 transport_context_->port_allocator_factory()->CreatePortAllocator( | 198 transport_context_->port_allocator_factory()->CreatePortAllocator( |
| 196 transport_context_); | 199 transport_context_); |
| 197 peer_connection_ = peer_connection_factory_->CreatePeerConnection( | 200 peer_connection_ = peer_connection_factory_->CreatePeerConnection( |
| 198 rtc_config, &constraints, std::move(port_allocator), nullptr, this); | 201 rtc_config, &constraints, std::move(port_allocator), nullptr, this); |
| 199 | 202 |
| 200 data_stream_adapter_.reset(new WebrtcDataStreamAdapter(peer_connection_)); | |
| 201 | |
| 202 event_handler_->OnWebrtcTransportConnecting(); | 203 event_handler_->OnWebrtcTransportConnecting(); |
| 203 | 204 |
| 204 if (transport_context_->role() == TransportRole::SERVER) | 205 if (transport_context_->role() == TransportRole::SERVER) |
| 205 RequestNegotiation(); | 206 RequestNegotiation(); |
| 206 } | 207 } |
| 207 | 208 |
| 208 bool WebrtcTransport::ProcessTransportInfo(XmlElement* transport_info) { | 209 bool WebrtcTransport::ProcessTransportInfo(XmlElement* transport_info) { |
| 209 DCHECK(thread_checker_.CalledOnValidThread()); | 210 DCHECK(thread_checker_.CalledOnValidThread()); |
| 210 | 211 |
| 211 if (transport_info->Name() != QName(kTransportNamespace, "transport")) | 212 if (transport_info->Name() != QName(kTransportNamespace, "transport")) |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) { | 433 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) { |
| 433 DCHECK(thread_checker_.CalledOnValidThread()); | 434 DCHECK(thread_checker_.CalledOnValidThread()); |
| 434 event_handler_->OnWebrtcTransportMediaStreamRemoved(stream.get()); | 435 event_handler_->OnWebrtcTransportMediaStreamRemoved(stream.get()); |
| 435 } | 436 } |
| 436 | 437 |
| 437 void WebrtcTransport::OnDataChannel( | 438 void WebrtcTransport::OnDataChannel( |
| 438 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) { | 439 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) { |
| 439 DCHECK(thread_checker_.CalledOnValidThread()); | 440 DCHECK(thread_checker_.CalledOnValidThread()); |
| 440 event_handler_->OnWebrtcTransportIncomingDataChannel( | 441 event_handler_->OnWebrtcTransportIncomingDataChannel( |
| 441 data_channel->label(), | 442 data_channel->label(), |
| 442 data_stream_adapter_->WrapIncomingDataChannel(data_channel)); | 443 base::WrapUnique(new WebrtcDataStreamAdapter(data_channel))); |
| 443 } | 444 } |
| 444 | 445 |
| 445 void WebrtcTransport::OnRenegotiationNeeded() { | 446 void WebrtcTransport::OnRenegotiationNeeded() { |
| 446 DCHECK(thread_checker_.CalledOnValidThread()); | 447 DCHECK(thread_checker_.CalledOnValidThread()); |
| 447 | 448 |
| 448 if (transport_context_->role() == TransportRole::SERVER) { | 449 if (transport_context_->role() == TransportRole::SERVER) { |
| 449 RequestNegotiation(); | 450 RequestNegotiation(); |
| 450 } else { | 451 } else { |
| 451 // TODO(sergeyu): Is it necessary to support renegotiation initiated by the | 452 // TODO(sergeyu): Is it necessary to support renegotiation initiated by the |
| 452 // client? | 453 // client? |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 } | 568 } |
| 568 } | 569 } |
| 569 | 570 |
| 570 void WebrtcTransport::Close(ErrorCode error) { | 571 void WebrtcTransport::Close(ErrorCode error) { |
| 571 DCHECK(thread_checker_.CalledOnValidThread()); | 572 DCHECK(thread_checker_.CalledOnValidThread()); |
| 572 if (!peer_connection_) | 573 if (!peer_connection_) |
| 573 return; | 574 return; |
| 574 | 575 |
| 575 weak_factory_.InvalidateWeakPtrs(); | 576 weak_factory_.InvalidateWeakPtrs(); |
| 576 | 577 |
| 577 data_stream_adapter_.reset(); | |
| 578 | |
| 579 peer_connection_->Close(); | 578 peer_connection_->Close(); |
| 580 peer_connection_ = nullptr; | 579 peer_connection_ = nullptr; |
| 581 peer_connection_factory_ = nullptr; | 580 peer_connection_factory_ = nullptr; |
| 582 | 581 |
| 583 if (error != OK) | 582 if (error != OK) |
| 584 event_handler_->OnWebrtcTransportError(error); | 583 event_handler_->OnWebrtcTransportError(error); |
| 585 } | 584 } |
| 586 | 585 |
| 587 } // namespace protocol | 586 } // namespace protocol |
| 588 } // namespace remoting | 587 } // namespace remoting |
| OLD | NEW |