| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } // namespace | 139 } // namespace |
| 140 | 140 |
| 141 WebrtcTransport::WebrtcTransport( | 141 WebrtcTransport::WebrtcTransport( |
| 142 rtc::Thread* worker_thread, | 142 rtc::Thread* worker_thread, |
| 143 scoped_refptr<TransportContext> transport_context, | 143 scoped_refptr<TransportContext> transport_context, |
| 144 EventHandler* event_handler) | 144 EventHandler* event_handler) |
| 145 : worker_thread_(worker_thread), | 145 : worker_thread_(worker_thread), |
| 146 transport_context_(transport_context), | 146 transport_context_(transport_context), |
| 147 event_handler_(event_handler), | 147 event_handler_(event_handler), |
| 148 handshake_hmac_(crypto::HMAC::SHA256), | 148 handshake_hmac_(crypto::HMAC::SHA256), |
| 149 outgoing_data_stream_adapter_( | |
| 150 true, | |
| 151 base::Bind(&WebrtcTransport::Close, base::Unretained(this))), | |
| 152 incoming_data_stream_adapter_( | |
| 153 false, | |
| 154 base::Bind(&WebrtcTransport::Close, base::Unretained(this))), | |
| 155 weak_factory_(this) { | 149 weak_factory_(this) { |
| 156 transport_context_->set_relay_mode(TransportContext::RelayMode::TURN); | 150 transport_context_->set_relay_mode(TransportContext::RelayMode::TURN); |
| 157 } | 151 } |
| 158 | 152 |
| 159 WebrtcTransport::~WebrtcTransport() {} | 153 WebrtcTransport::~WebrtcTransport() {} |
| 160 | 154 |
| 161 void WebrtcTransport::Start( | 155 void WebrtcTransport::Start( |
| 162 Authenticator* authenticator, | 156 Authenticator* authenticator, |
| 163 SendTransportInfoCallback send_transport_info_callback) { | 157 SendTransportInfoCallback send_transport_info_callback) { |
| 164 DCHECK(thread_checker_.CalledOnValidThread()); | 158 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 191 webrtc::FakeConstraints constraints; | 185 webrtc::FakeConstraints constraints; |
| 192 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | 186 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 193 webrtc::MediaConstraintsInterface::kValueTrue); | 187 webrtc::MediaConstraintsInterface::kValueTrue); |
| 194 | 188 |
| 195 std::unique_ptr<cricket::PortAllocator> port_allocator = | 189 std::unique_ptr<cricket::PortAllocator> port_allocator = |
| 196 transport_context_->port_allocator_factory()->CreatePortAllocator( | 190 transport_context_->port_allocator_factory()->CreatePortAllocator( |
| 197 transport_context_); | 191 transport_context_); |
| 198 peer_connection_ = peer_connection_factory_->CreatePeerConnection( | 192 peer_connection_ = peer_connection_factory_->CreatePeerConnection( |
| 199 rtc_config, &constraints, std::move(port_allocator), nullptr, this); | 193 rtc_config, &constraints, std::move(port_allocator), nullptr, this); |
| 200 | 194 |
| 201 outgoing_data_stream_adapter_.Initialize(peer_connection_); | 195 data_stream_adapter_.reset(new WebrtcDataStreamAdapter( |
| 202 incoming_data_stream_adapter_.Initialize(peer_connection_); | 196 base::Bind(&WebrtcTransport::Close, base::Unretained(this)))); |
| 197 data_stream_adapter_->Initialize(peer_connection_); |
| 203 | 198 |
| 204 event_handler_->OnWebrtcTransportConnecting(); | 199 event_handler_->OnWebrtcTransportConnecting(); |
| 205 | 200 |
| 206 if (transport_context_->role() == TransportRole::SERVER) | 201 if (transport_context_->role() == TransportRole::SERVER) |
| 207 RequestNegotiation(); | 202 RequestNegotiation(); |
| 208 } | 203 } |
| 209 | 204 |
| 210 bool WebrtcTransport::ProcessTransportInfo(XmlElement* transport_info) { | 205 bool WebrtcTransport::ProcessTransportInfo(XmlElement* transport_info) { |
| 211 DCHECK(thread_checker_.CalledOnValidThread()); | 206 DCHECK(thread_checker_.CalledOnValidThread()); |
| 212 | 207 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 | 427 |
| 433 void WebrtcTransport::OnRemoveStream( | 428 void WebrtcTransport::OnRemoveStream( |
| 434 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) { | 429 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) { |
| 435 DCHECK(thread_checker_.CalledOnValidThread()); | 430 DCHECK(thread_checker_.CalledOnValidThread()); |
| 436 event_handler_->OnWebrtcTransportMediaStreamRemoved(stream.get()); | 431 event_handler_->OnWebrtcTransportMediaStreamRemoved(stream.get()); |
| 437 } | 432 } |
| 438 | 433 |
| 439 void WebrtcTransport::OnDataChannel( | 434 void WebrtcTransport::OnDataChannel( |
| 440 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) { | 435 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) { |
| 441 DCHECK(thread_checker_.CalledOnValidThread()); | 436 DCHECK(thread_checker_.CalledOnValidThread()); |
| 442 incoming_data_stream_adapter_.OnIncomingDataChannel(data_channel); | 437 data_stream_adapter_->WrapIncomingDataChannel( |
| 438 data_channel, |
| 439 base::Bind(&EventHandler::OnWebrtcTransportIncomingDataChannel, |
| 440 base::Unretained(event_handler_), data_channel->label())); |
| 443 } | 441 } |
| 444 | 442 |
| 445 void WebrtcTransport::OnRenegotiationNeeded() { | 443 void WebrtcTransport::OnRenegotiationNeeded() { |
| 446 DCHECK(thread_checker_.CalledOnValidThread()); | 444 DCHECK(thread_checker_.CalledOnValidThread()); |
| 447 | 445 |
| 448 if (transport_context_->role() == TransportRole::SERVER) { | 446 if (transport_context_->role() == TransportRole::SERVER) { |
| 449 RequestNegotiation(); | 447 RequestNegotiation(); |
| 450 } else { | 448 } else { |
| 451 // TODO(sergeyu): Is it necessary to support renegotiation initiated by the | 449 // TODO(sergeyu): Is it necessary to support renegotiation initiated by the |
| 452 // client? | 450 // client? |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 pending_incoming_candidates_.clear(); | 564 pending_incoming_candidates_.clear(); |
| 567 } | 565 } |
| 568 } | 566 } |
| 569 | 567 |
| 570 void WebrtcTransport::Close(ErrorCode error) { | 568 void WebrtcTransport::Close(ErrorCode error) { |
| 571 DCHECK(thread_checker_.CalledOnValidThread()); | 569 DCHECK(thread_checker_.CalledOnValidThread()); |
| 572 if (!peer_connection_) | 570 if (!peer_connection_) |
| 573 return; | 571 return; |
| 574 | 572 |
| 575 weak_factory_.InvalidateWeakPtrs(); | 573 weak_factory_.InvalidateWeakPtrs(); |
| 574 |
| 575 data_stream_adapter_.reset(); |
| 576 |
| 576 peer_connection_->Close(); | 577 peer_connection_->Close(); |
| 577 peer_connection_ = nullptr; | 578 peer_connection_ = nullptr; |
| 578 peer_connection_factory_ = nullptr; | 579 peer_connection_factory_ = nullptr; |
| 579 | 580 |
| 580 if (error != OK) | 581 if (error != OK) |
| 581 event_handler_->OnWebrtcTransportError(error); | 582 event_handler_->OnWebrtcTransportError(error); |
| 582 } | 583 } |
| 583 | 584 |
| 584 } // namespace protocol | 585 } // namespace protocol |
| 585 } // namespace remoting | 586 } // namespace remoting |
| OLD | NEW |