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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
12 #include "net/url_request/url_request_context_getter.h" | 12 #include "net/url_request/url_request_context_getter.h" |
13 #include "remoting/host/client_session.h" | 13 #include "remoting/host/client_session.h" |
14 #include "remoting/proto/control.pb.h" | 14 #include "remoting/proto/control.pb.h" |
15 #include "remoting/protocol/chromium_port_allocator_factory.h" | 15 #include "remoting/protocol/chromium_port_allocator.h" |
16 #include "remoting/protocol/client_stub.h" | 16 #include "remoting/protocol/client_stub.h" |
17 #include "remoting/protocol/webrtc_video_capturer_adapter.h" | 17 #include "remoting/protocol/webrtc_video_capturer_adapter.h" |
18 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | 18 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
19 #include "third_party/libjingle/source/talk/app/webrtc/test/fakeconstraints.h" | 19 #include "third_party/libjingle/source/talk/app/webrtc/test/fakeconstraints.h" |
20 #include "third_party/libjingle/source/talk/app/webrtc/videosourceinterface.h" | 20 #include "third_party/libjingle/source/talk/app/webrtc/videosourceinterface.h" |
21 | 21 |
22 namespace remoting { | 22 namespace remoting { |
23 | 23 |
24 // Used as the type attribute of all Cast protocol::ExtensionMessages. | 24 // Used as the type attribute of all Cast protocol::ExtensionMessages. |
25 const char kExtensionMessageType[] = "cast_message"; | 25 const char kExtensionMessageType[] = "cast_message"; |
(...skipping 17 matching lines...) Expand all Loading... |
43 const char kWebRtcSessionDescType[] = "type"; | 43 const char kWebRtcSessionDescType[] = "type"; |
44 const char kWebRtcSessionDescSDP[] = "sdp"; | 44 const char kWebRtcSessionDescSDP[] = "sdp"; |
45 const char kWebRtcSDPMid[] = "sdpMid"; | 45 const char kWebRtcSDPMid[] = "sdpMid"; |
46 const char kWebRtcSDPMLineIndex[] = "sdpMLineIndex"; | 46 const char kWebRtcSDPMLineIndex[] = "sdpMLineIndex"; |
47 | 47 |
48 // Media labels used over the PeerConnection. | 48 // Media labels used over the PeerConnection. |
49 const char kVideoLabel[] = "cast_video_label"; | 49 const char kVideoLabel[] = "cast_video_label"; |
50 const char kStreamLabel[] = "stream_label"; | 50 const char kStreamLabel[] = "stream_label"; |
51 | 51 |
52 // Default STUN server used to construct | 52 // Default STUN server used to construct |
53 // webrtc::PeerConnectionInterface::RTCConfiguration for the PeerConnection. | 53 // ChromiumPortAllocator for the PeerConnection. |
54 const char kDefaultStunURI[] = "stun:stun.l.google.com:19302"; | 54 const char kDefaultStunHost[] = "stun.l.google.com"; |
| 55 const int kDefaultStunPort = 19302; |
55 | 56 |
56 const char kWorkerThreadName[] = "CastExtensionSessionWorkerThread"; | 57 const char kWorkerThreadName[] = "CastExtensionSessionWorkerThread"; |
57 | 58 |
58 // Interval between each call to PollPeerConnectionStats(). | 59 // Interval between each call to PollPeerConnectionStats(). |
59 const int kStatsLogIntervalSec = 10; | 60 const int kStatsLogIntervalSec = 10; |
60 | 61 |
61 // Minimum frame rate for video streaming over the PeerConnection in frames per | 62 // Minimum frame rate for video streaming over the PeerConnection in frames per |
62 // second, added as a media constraint when constructing the video source for | 63 // second, added as a media constraint when constructing the video source for |
63 // the Peer Connection. | 64 // the Peer Connection. |
64 const int kMinFramesPerSecond = 5; | 65 const int kMinFramesPerSecond = 5; |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 worker_thread_wrapper_, signaling_thread_wrapper_, nullptr, nullptr, | 475 worker_thread_wrapper_, signaling_thread_wrapper_, nullptr, nullptr, |
475 nullptr); | 476 nullptr); |
476 | 477 |
477 if (!peer_conn_factory_.get()) { | 478 if (!peer_conn_factory_.get()) { |
478 CleanupPeerConnection(); | 479 CleanupPeerConnection(); |
479 return false; | 480 return false; |
480 } | 481 } |
481 | 482 |
482 VLOG(1) << "Created PeerConnectionFactory successfully."; | 483 VLOG(1) << "Created PeerConnectionFactory successfully."; |
483 | 484 |
484 webrtc::PeerConnectionInterface::IceServers servers; | |
485 webrtc::PeerConnectionInterface::IceServer server; | |
486 server.uri = kDefaultStunURI; | |
487 servers.push_back(server); | |
488 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config; | |
489 rtc_config.servers = servers; | |
490 | |
491 // DTLS-SRTP is the preferred encryption method. If set to kValueFalse, the | 485 // DTLS-SRTP is the preferred encryption method. If set to kValueFalse, the |
492 // peer connection uses SDES. Disabling SDES as well will cause the peer | 486 // peer connection uses SDES. Disabling SDES as well will cause the peer |
493 // connection to fail to connect. | 487 // connection to fail to connect. |
494 // Note: For protection and unprotection of SRTP packets, the libjingle | 488 // Note: For protection and unprotection of SRTP packets, the libjingle |
495 // ENABLE_EXTERNAL_AUTH flag must not be set. | 489 // ENABLE_EXTERNAL_AUTH flag must not be set. |
496 webrtc::FakeConstraints constraints; | 490 webrtc::FakeConstraints constraints; |
497 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | 491 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
498 webrtc::MediaConstraintsInterface::kValueTrue); | 492 webrtc::MediaConstraintsInterface::kValueTrue); |
499 | 493 |
500 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> | 494 rtc::scoped_ptr<protocol::ChromiumPortAllocator> port_allocator( |
501 port_allocator_factory = protocol::ChromiumPortAllocatorFactory::Create( | 495 protocol::ChromiumPortAllocator::Create(url_request_context_getter_, |
502 network_settings_, url_request_context_getter_); | 496 network_settings_) |
| 497 .release()); |
| 498 std::vector<rtc::SocketAddress> stun_hosts; |
| 499 stun_hosts.push_back(rtc::SocketAddress(kDefaultStunHost, kDefaultStunPort)); |
| 500 port_allocator->SetStunHosts(stun_hosts); |
503 | 501 |
| 502 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config; |
504 peer_connection_ = peer_conn_factory_->CreatePeerConnection( | 503 peer_connection_ = peer_conn_factory_->CreatePeerConnection( |
505 rtc_config, &constraints, port_allocator_factory, nullptr, this); | 504 rtc_config, &constraints, port_allocator.Pass(), nullptr, this); |
506 | 505 |
507 if (!peer_connection_.get()) { | 506 if (!peer_connection_.get()) { |
508 CleanupPeerConnection(); | 507 CleanupPeerConnection(); |
509 return false; | 508 return false; |
510 } | 509 } |
511 | 510 |
512 VLOG(1) << "Created PeerConnection successfully."; | 511 VLOG(1) << "Created PeerConnection successfully."; |
513 | 512 |
514 create_session_desc_observer_ = | 513 create_session_desc_observer_ = |
515 CastCreateSessionDescriptionObserver::Create(this); | 514 CastCreateSessionDescriptionObserver::Create(this); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 json.SetString(kWebRtcCandidate, candidate_str); | 652 json.SetString(kWebRtcCandidate, candidate_str); |
654 std::string json_str; | 653 std::string json_str; |
655 if (!base::JSONWriter::Write(json, &json_str)) { | 654 if (!base::JSONWriter::Write(json, &json_str)) { |
656 LOG(ERROR) << "Failed to serialize candidate message."; | 655 LOG(ERROR) << "Failed to serialize candidate message."; |
657 return; | 656 return; |
658 } | 657 } |
659 SendMessageToClient(kSubjectNewCandidate, json_str); | 658 SendMessageToClient(kSubjectNewCandidate, json_str); |
660 } | 659 } |
661 | 660 |
662 } // namespace remoting | 661 } // namespace remoting |
OLD | NEW |