| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/host/cast_extension_session.h" | 5 #include "remoting/host/cast_extension_session.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 15 #include "net/url_request/url_request_context_getter.h" | 15 #include "base/thread_task_runner_handle.h" |
| 16 #include "remoting/host/client_session.h" | 16 #include "remoting/host/client_session.h" |
| 17 #include "remoting/proto/control.pb.h" | 17 #include "remoting/proto/control.pb.h" |
| 18 #include "remoting/protocol/chromium_port_allocator.h" | |
| 19 #include "remoting/protocol/client_stub.h" | 18 #include "remoting/protocol/client_stub.h" |
| 19 #include "remoting/protocol/port_allocator_factory.h" |
| 20 #include "remoting/protocol/transport_context.h" |
| 20 #include "remoting/protocol/webrtc_video_capturer_adapter.h" | 21 #include "remoting/protocol/webrtc_video_capturer_adapter.h" |
| 21 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | 22 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
| 22 #include "third_party/libjingle/source/talk/app/webrtc/test/fakeconstraints.h" | 23 #include "third_party/libjingle/source/talk/app/webrtc/test/fakeconstraints.h" |
| 23 #include "third_party/libjingle/source/talk/app/webrtc/videosourceinterface.h" | 24 #include "third_party/libjingle/source/talk/app/webrtc/videosourceinterface.h" |
| 24 | 25 |
| 25 namespace remoting { | 26 namespace remoting { |
| 26 | 27 |
| 27 // Used as the type attribute of all Cast protocol::ExtensionMessages. | 28 // Used as the type attribute of all Cast protocol::ExtensionMessages. |
| 28 const char kExtensionMessageType[] = "cast_message"; | 29 const char kExtensionMessageType[] = "cast_message"; |
| 29 | 30 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // Explicitly clear |create_session_desc_observer_|'s pointer to |this|, | 163 // Explicitly clear |create_session_desc_observer_|'s pointer to |this|, |
| 163 // since the CastExtensionSession is destructing. Otherwise, | 164 // since the CastExtensionSession is destructing. Otherwise, |
| 164 // |create_session_desc_observer_| would be left with a dangling pointer. | 165 // |create_session_desc_observer_| would be left with a dangling pointer. |
| 165 create_session_desc_observer_->SetCastExtensionSession(nullptr); | 166 create_session_desc_observer_->SetCastExtensionSession(nullptr); |
| 166 | 167 |
| 167 CleanupPeerConnection(); | 168 CleanupPeerConnection(); |
| 168 } | 169 } |
| 169 | 170 |
| 170 // static | 171 // static |
| 171 scoped_ptr<CastExtensionSession> CastExtensionSession::Create( | 172 scoped_ptr<CastExtensionSession> CastExtensionSession::Create( |
| 172 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 173 scoped_refptr<protocol::TransportContext> transport_context, |
| 173 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, | |
| 174 const protocol::NetworkSettings& network_settings, | |
| 175 ClientSessionControl* client_session_control, | 174 ClientSessionControl* client_session_control, |
| 176 protocol::ClientStub* client_stub) { | 175 protocol::ClientStub* client_stub) { |
| 177 scoped_ptr<CastExtensionSession> cast_extension_session( | 176 scoped_ptr<CastExtensionSession> cast_extension_session( |
| 178 new CastExtensionSession(caller_task_runner, | 177 new CastExtensionSession(transport_context, |
| 179 url_request_context_getter, | 178 client_session_control, client_stub)); |
| 180 network_settings, | |
| 181 client_session_control, | |
| 182 client_stub)); | |
| 183 if (!cast_extension_session->WrapTasksAndSave() || | 179 if (!cast_extension_session->WrapTasksAndSave() || |
| 184 !cast_extension_session->InitializePeerConnection()) { | 180 !cast_extension_session->InitializePeerConnection()) { |
| 185 return nullptr; | 181 return nullptr; |
| 186 } | 182 } |
| 187 return cast_extension_session; | 183 return cast_extension_session; |
| 188 } | 184 } |
| 189 | 185 |
| 190 void CastExtensionSession::OnCreateSessionDescription( | 186 void CastExtensionSession::OnCreateSessionDescription( |
| 191 webrtc::SessionDescriptionInterface* desc) { | 187 webrtc::SessionDescriptionInterface* desc) { |
| 192 if (!caller_task_runner_->BelongsToCurrentThread()) { | 188 if (!caller_task_runner_->BelongsToCurrentThread()) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 ParseAndAddICECandidate(client_message); | 289 ParseAndAddICECandidate(client_message); |
| 294 } else { | 290 } else { |
| 295 VLOG(1) << "Unexpected CastExtension Message: " << message.data(); | 291 VLOG(1) << "Unexpected CastExtension Message: " << message.data(); |
| 296 } | 292 } |
| 297 return true; | 293 return true; |
| 298 } | 294 } |
| 299 | 295 |
| 300 // Private methods ------------------------------------------------------------ | 296 // Private methods ------------------------------------------------------------ |
| 301 | 297 |
| 302 CastExtensionSession::CastExtensionSession( | 298 CastExtensionSession::CastExtensionSession( |
| 303 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 299 scoped_refptr<protocol::TransportContext> transport_context, |
| 304 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, | |
| 305 const protocol::NetworkSettings& network_settings, | |
| 306 ClientSessionControl* client_session_control, | 300 ClientSessionControl* client_session_control, |
| 307 protocol::ClientStub* client_stub) | 301 protocol::ClientStub* client_stub) |
| 308 : caller_task_runner_(caller_task_runner), | 302 : caller_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 309 url_request_context_getter_(url_request_context_getter), | 303 transport_context_(transport_context), |
| 310 network_settings_(network_settings), | |
| 311 client_session_control_(client_session_control), | 304 client_session_control_(client_session_control), |
| 312 client_stub_(client_stub), | 305 client_stub_(client_stub), |
| 313 stats_observer_(CastStatsObserver::Create()), | 306 stats_observer_(CastStatsObserver::Create()), |
| 314 received_offer_(false), | 307 received_offer_(false), |
| 315 has_grabbed_capturer_(false), | 308 has_grabbed_capturer_(false), |
| 316 signaling_thread_wrapper_(nullptr), | 309 signaling_thread_wrapper_(nullptr), |
| 317 worker_thread_wrapper_(nullptr), | 310 worker_thread_wrapper_(nullptr), |
| 318 worker_thread_(kWorkerThreadName) { | 311 worker_thread_(kWorkerThreadName) { |
| 319 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 312 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 320 DCHECK(url_request_context_getter_.get()); | |
| 321 DCHECK(client_session_control_); | 313 DCHECK(client_session_control_); |
| 322 DCHECK(client_stub_); | 314 DCHECK(client_stub_); |
| 323 | 315 |
| 324 // The worker thread is created with base::MessageLoop::TYPE_IO because | 316 // The worker thread is created with base::MessageLoop::TYPE_IO because |
| 325 // the PeerConnection performs some port allocation operations on this thread | 317 // the PeerConnection performs some port allocation operations on this thread |
| 326 // that require it. See crbug.com/404013. | 318 // that require it. See crbug.com/404013. |
| 327 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); | 319 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); |
| 328 worker_thread_.StartWithOptions(options); | 320 worker_thread_.StartWithOptions(options); |
| 329 worker_task_runner_ = worker_thread_.task_runner(); | 321 worker_task_runner_ = worker_thread_.task_runner(); |
| 330 } | 322 } |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 // DTLS-SRTP is the preferred encryption method. If set to kValueFalse, the | 475 // DTLS-SRTP is the preferred encryption method. If set to kValueFalse, the |
| 484 // peer connection uses SDES. Disabling SDES as well will cause the peer | 476 // peer connection uses SDES. Disabling SDES as well will cause the peer |
| 485 // connection to fail to connect. | 477 // connection to fail to connect. |
| 486 // Note: For protection and unprotection of SRTP packets, the libjingle | 478 // Note: For protection and unprotection of SRTP packets, the libjingle |
| 487 // ENABLE_EXTERNAL_AUTH flag must not be set. | 479 // ENABLE_EXTERNAL_AUTH flag must not be set. |
| 488 webrtc::FakeConstraints constraints; | 480 webrtc::FakeConstraints constraints; |
| 489 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | 481 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 490 webrtc::MediaConstraintsInterface::kValueTrue); | 482 webrtc::MediaConstraintsInterface::kValueTrue); |
| 491 | 483 |
| 492 scoped_ptr<cricket::PortAllocator> port_allocator = | 484 scoped_ptr<cricket::PortAllocator> port_allocator = |
| 493 protocol::ChromiumPortAllocator::Create(url_request_context_getter_); | 485 transport_context_->port_allocator_factory()->CreatePortAllocator( |
| 486 transport_context_); |
| 494 | 487 |
| 495 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config; | 488 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config; |
| 496 peer_connection_ = peer_conn_factory_->CreatePeerConnection( | 489 peer_connection_ = peer_conn_factory_->CreatePeerConnection( |
| 497 rtc_config, &constraints, | 490 rtc_config, &constraints, |
| 498 rtc::scoped_ptr<cricket::PortAllocator>(port_allocator.release()), | 491 rtc::scoped_ptr<cricket::PortAllocator>(port_allocator.release()), |
| 499 nullptr, this); | 492 nullptr, this); |
| 500 | 493 |
| 501 if (!peer_connection_.get()) { | 494 if (!peer_connection_.get()) { |
| 502 CleanupPeerConnection(); | 495 CleanupPeerConnection(); |
| 503 return false; | 496 return false; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 json.SetString(kWebRtcCandidate, candidate_str); | 640 json.SetString(kWebRtcCandidate, candidate_str); |
| 648 std::string json_str; | 641 std::string json_str; |
| 649 if (!base::JSONWriter::Write(json, &json_str)) { | 642 if (!base::JSONWriter::Write(json, &json_str)) { |
| 650 LOG(ERROR) << "Failed to serialize candidate message."; | 643 LOG(ERROR) << "Failed to serialize candidate message."; |
| 651 return; | 644 return; |
| 652 } | 645 } |
| 653 SendMessageToClient(kSubjectNewCandidate, json_str); | 646 SendMessageToClient(kSubjectNewCandidate, json_str); |
| 654 } | 647 } |
| 655 | 648 |
| 656 } // namespace remoting | 649 } // namespace remoting |
| OLD | NEW |