| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 private: | 98 private: |
| 99 ResultCallback result_callback_; | 99 ResultCallback result_callback_; |
| 100 | 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(SetSessionDescriptionObserver); | 101 DISALLOW_COPY_AND_ASSIGN(SetSessionDescriptionObserver); |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 } // namespace | 104 } // namespace |
| 105 | 105 |
| 106 WebrtcTransport::WebrtcTransport( | 106 WebrtcTransport::WebrtcTransport( |
| 107 rtc::Thread* worker_thread, | 107 rtc::Thread* worker_thread, |
| 108 scoped_refptr<TransportContext> transport_context) | 108 scoped_refptr<TransportContext> transport_context, |
| 109 : transport_context_(transport_context), | 109 EventHandler* event_handler) |
| 110 worker_thread_(worker_thread), | 110 : worker_thread_(worker_thread), |
| 111 transport_context_(transport_context), |
| 112 event_handler_(event_handler), |
| 111 weak_factory_(this) {} | 113 weak_factory_(this) {} |
| 112 | 114 |
| 113 WebrtcTransport::~WebrtcTransport() {} | 115 WebrtcTransport::~WebrtcTransport() {} |
| 114 | 116 |
| 115 void WebrtcTransport::Start(EventHandler* event_handler, | 117 void WebrtcTransport::Start( |
| 116 Authenticator* authenticator) { | 118 Authenticator* authenticator, |
| 119 SendTransportInfoCallback send_transport_info_callback) { |
| 117 DCHECK(thread_checker_.CalledOnValidThread()); | 120 DCHECK(thread_checker_.CalledOnValidThread()); |
| 121 DCHECK(send_transport_info_callback_.is_null()); |
| 118 | 122 |
| 119 event_handler_ = event_handler; | 123 send_transport_info_callback_ = std::move(send_transport_info_callback); |
| 124 |
| 120 // TODO(sergeyu): Use the |authenticator| to authenticate PeerConnection. | 125 // TODO(sergeyu): Use the |authenticator| to authenticate PeerConnection. |
| 121 | 126 |
| 122 transport_context_->CreatePortAllocator(base::Bind( | 127 transport_context_->CreatePortAllocator(base::Bind( |
| 123 &WebrtcTransport::OnPortAllocatorCreated, weak_factory_.GetWeakPtr())); | 128 &WebrtcTransport::OnPortAllocatorCreated, weak_factory_.GetWeakPtr())); |
| 124 } | 129 } |
| 125 | 130 |
| 126 void WebrtcTransport::OnPortAllocatorCreated( | 131 void WebrtcTransport::OnPortAllocatorCreated( |
| 127 scoped_ptr<cricket::PortAllocator> port_allocator) { | 132 scoped_ptr<cricket::PortAllocator> port_allocator) { |
| 128 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | 133 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
| 129 | 134 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 } | 246 } |
| 242 | 247 |
| 243 return true; | 248 return true; |
| 244 } | 249 } |
| 245 | 250 |
| 246 StreamChannelFactory* WebrtcTransport::GetStreamChannelFactory() { | 251 StreamChannelFactory* WebrtcTransport::GetStreamChannelFactory() { |
| 247 DCHECK(thread_checker_.CalledOnValidThread()); | 252 DCHECK(thread_checker_.CalledOnValidThread()); |
| 248 return &data_stream_adapter_; | 253 return &data_stream_adapter_; |
| 249 } | 254 } |
| 250 | 255 |
| 251 StreamChannelFactory* WebrtcTransport::GetMultiplexedChannelFactory() { | |
| 252 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 253 return GetStreamChannelFactory(); | |
| 254 } | |
| 255 | |
| 256 WebrtcTransport* WebrtcTransport::AsWebrtcTransport() { | |
| 257 return this; | |
| 258 } | |
| 259 | |
| 260 void WebrtcTransport::OnLocalSessionDescriptionCreated( | 256 void WebrtcTransport::OnLocalSessionDescriptionCreated( |
| 261 scoped_ptr<webrtc::SessionDescriptionInterface> description, | 257 scoped_ptr<webrtc::SessionDescriptionInterface> description, |
| 262 const std::string& error) { | 258 const std::string& error) { |
| 263 DCHECK(thread_checker_.CalledOnValidThread()); | 259 DCHECK(thread_checker_.CalledOnValidThread()); |
| 264 | 260 |
| 265 if (!peer_connection_) | 261 if (!peer_connection_) |
| 266 return; | 262 return; |
| 267 | 263 |
| 268 if (!description) { | 264 if (!description) { |
| 269 LOG(ERROR) << "PeerConnection offer creation failed: " << error; | 265 LOG(ERROR) << "PeerConnection offer creation failed: " << error; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 280 | 276 |
| 281 // Format and send the session description to the peer. | 277 // Format and send the session description to the peer. |
| 282 scoped_ptr<XmlElement> transport_info( | 278 scoped_ptr<XmlElement> transport_info( |
| 283 new XmlElement(QName(kTransportNamespace, "transport"), true)); | 279 new XmlElement(QName(kTransportNamespace, "transport"), true)); |
| 284 XmlElement* offer_tag = | 280 XmlElement* offer_tag = |
| 285 new XmlElement(QName(kTransportNamespace, "session-description")); | 281 new XmlElement(QName(kTransportNamespace, "session-description")); |
| 286 transport_info->AddElement(offer_tag); | 282 transport_info->AddElement(offer_tag); |
| 287 offer_tag->SetAttr(QName(std::string(), "type"), description->type()); | 283 offer_tag->SetAttr(QName(std::string(), "type"), description->type()); |
| 288 offer_tag->SetBodyText(description_sdp); | 284 offer_tag->SetBodyText(description_sdp); |
| 289 | 285 |
| 290 event_handler_->OnOutgoingTransportInfo(std::move(transport_info)); | 286 send_transport_info_callback_.Run(std::move(transport_info)); |
| 291 | 287 |
| 292 peer_connection_->SetLocalDescription( | 288 peer_connection_->SetLocalDescription( |
| 293 SetSessionDescriptionObserver::Create(base::Bind( | 289 SetSessionDescriptionObserver::Create(base::Bind( |
| 294 &WebrtcTransport::OnLocalDescriptionSet, weak_factory_.GetWeakPtr())), | 290 &WebrtcTransport::OnLocalDescriptionSet, weak_factory_.GetWeakPtr())), |
| 295 description.release()); | 291 description.release()); |
| 296 } | 292 } |
| 297 | 293 |
| 298 void WebrtcTransport::OnLocalDescriptionSet(bool success, | 294 void WebrtcTransport::OnLocalDescriptionSet(bool success, |
| 299 const std::string& error) { | 295 const std::string& error) { |
| 300 DCHECK(thread_checker_.CalledOnValidThread()); | 296 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 335 |
| 340 void WebrtcTransport::Close(ErrorCode error) { | 336 void WebrtcTransport::Close(ErrorCode error) { |
| 341 DCHECK(thread_checker_.CalledOnValidThread()); | 337 DCHECK(thread_checker_.CalledOnValidThread()); |
| 342 | 338 |
| 343 weak_factory_.InvalidateWeakPtrs(); | 339 weak_factory_.InvalidateWeakPtrs(); |
| 344 peer_connection_->Close(); | 340 peer_connection_->Close(); |
| 345 peer_connection_ = nullptr; | 341 peer_connection_ = nullptr; |
| 346 peer_connection_factory_ = nullptr; | 342 peer_connection_factory_ = nullptr; |
| 347 | 343 |
| 348 if (error != OK) | 344 if (error != OK) |
| 349 event_handler_->OnTransportError(error); | 345 event_handler_->OnWebrtcTransportError(error); |
| 350 } | 346 } |
| 351 | 347 |
| 352 void WebrtcTransport::OnSignalingChange( | 348 void WebrtcTransport::OnSignalingChange( |
| 353 webrtc::PeerConnectionInterface::SignalingState new_state) { | 349 webrtc::PeerConnectionInterface::SignalingState new_state) { |
| 354 DCHECK(thread_checker_.CalledOnValidThread()); | 350 DCHECK(thread_checker_.CalledOnValidThread()); |
| 355 } | 351 } |
| 356 | 352 |
| 357 void WebrtcTransport::OnAddStream(webrtc::MediaStreamInterface* stream) { | 353 void WebrtcTransport::OnAddStream(webrtc::MediaStreamInterface* stream) { |
| 358 DCHECK(thread_checker_.CalledOnValidThread()); | 354 DCHECK(thread_checker_.CalledOnValidThread()); |
| 359 LOG(ERROR) << "Stream added " << stream->label(); | 355 LOG(ERROR) << "Stream added " << stream->label(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 FROM_HERE, | 387 FROM_HERE, |
| 392 base::Bind(&WebrtcTransport::SendOffer, weak_factory_.GetWeakPtr())); | 388 base::Bind(&WebrtcTransport::SendOffer, weak_factory_.GetWeakPtr())); |
| 393 } | 389 } |
| 394 } | 390 } |
| 395 | 391 |
| 396 void WebrtcTransport::OnIceConnectionChange( | 392 void WebrtcTransport::OnIceConnectionChange( |
| 397 webrtc::PeerConnectionInterface::IceConnectionState new_state) { | 393 webrtc::PeerConnectionInterface::IceConnectionState new_state) { |
| 398 DCHECK(thread_checker_.CalledOnValidThread()); | 394 DCHECK(thread_checker_.CalledOnValidThread()); |
| 399 | 395 |
| 400 if (new_state == webrtc::PeerConnectionInterface::kIceConnectionConnected) | 396 if (new_state == webrtc::PeerConnectionInterface::kIceConnectionConnected) |
| 401 event_handler_->OnTransportConnected(); | 397 event_handler_->OnWebrtcTransportConnected(); |
| 402 } | 398 } |
| 403 | 399 |
| 404 void WebrtcTransport::OnIceGatheringChange( | 400 void WebrtcTransport::OnIceGatheringChange( |
| 405 webrtc::PeerConnectionInterface::IceGatheringState new_state) { | 401 webrtc::PeerConnectionInterface::IceGatheringState new_state) { |
| 406 DCHECK(thread_checker_.CalledOnValidThread()); | 402 DCHECK(thread_checker_.CalledOnValidThread()); |
| 407 } | 403 } |
| 408 | 404 |
| 409 void WebrtcTransport::OnIceCandidate( | 405 void WebrtcTransport::OnIceCandidate( |
| 410 const webrtc::IceCandidateInterface* candidate) { | 406 const webrtc::IceCandidateInterface* candidate) { |
| 411 DCHECK(thread_checker_.CalledOnValidThread()); | 407 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 CreateSessionDescriptionObserver::Create( | 462 CreateSessionDescriptionObserver::Create( |
| 467 base::Bind(&WebrtcTransport::OnLocalSessionDescriptionCreated, | 463 base::Bind(&WebrtcTransport::OnLocalSessionDescriptionCreated, |
| 468 weak_factory_.GetWeakPtr())), | 464 weak_factory_.GetWeakPtr())), |
| 469 &offer_config); | 465 &offer_config); |
| 470 } | 466 } |
| 471 | 467 |
| 472 void WebrtcTransport::SendTransportInfo() { | 468 void WebrtcTransport::SendTransportInfo() { |
| 473 DCHECK(thread_checker_.CalledOnValidThread()); | 469 DCHECK(thread_checker_.CalledOnValidThread()); |
| 474 DCHECK(pending_transport_info_message_); | 470 DCHECK(pending_transport_info_message_); |
| 475 | 471 |
| 476 event_handler_->OnOutgoingTransportInfo( | 472 send_transport_info_callback_.Run(std::move(pending_transport_info_message_)); |
| 477 std::move(pending_transport_info_message_)); | |
| 478 pending_transport_info_message_.reset(); | |
| 479 } | 473 } |
| 480 | 474 |
| 481 void WebrtcTransport::AddPendingCandidatesIfPossible() { | 475 void WebrtcTransport::AddPendingCandidatesIfPossible() { |
| 482 DCHECK(thread_checker_.CalledOnValidThread()); | 476 DCHECK(thread_checker_.CalledOnValidThread()); |
| 483 | 477 |
| 484 if (peer_connection_->signaling_state() == | 478 if (peer_connection_->signaling_state() == |
| 485 webrtc::PeerConnectionInterface::kStable) { | 479 webrtc::PeerConnectionInterface::kStable) { |
| 486 for (auto candidate : pending_incoming_candidates_) { | 480 for (auto candidate : pending_incoming_candidates_) { |
| 487 if (!peer_connection_->AddIceCandidate(candidate)) { | 481 if (!peer_connection_->AddIceCandidate(candidate)) { |
| 488 LOG(ERROR) << "Failed to add incoming candidate"; | 482 LOG(ERROR) << "Failed to add incoming candidate"; |
| 489 Close(INCOMPATIBLE_PROTOCOL); | 483 Close(INCOMPATIBLE_PROTOCOL); |
| 490 return; | 484 return; |
| 491 } | 485 } |
| 492 } | 486 } |
| 493 pending_incoming_candidates_.clear(); | 487 pending_incoming_candidates_.clear(); |
| 494 } | 488 } |
| 495 } | 489 } |
| 496 | 490 |
| 497 WebrtcTransportFactory::WebrtcTransportFactory( | |
| 498 rtc::Thread* worker_thread, | |
| 499 scoped_refptr<TransportContext> transport_context) | |
| 500 : worker_thread_(worker_thread), | |
| 501 transport_context_(transport_context) {} | |
| 502 | |
| 503 WebrtcTransportFactory::~WebrtcTransportFactory() {} | |
| 504 | |
| 505 scoped_ptr<Transport> WebrtcTransportFactory::CreateTransport() { | |
| 506 return make_scoped_ptr( | |
| 507 new WebrtcTransport(worker_thread_, transport_context_.get())); | |
| 508 } | |
| 509 | |
| 510 } // namespace protocol | 491 } // namespace protocol |
| 511 } // namespace remoting | 492 } // namespace remoting |
| OLD | NEW |