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.h" | 15 #include "remoting/protocol/chromium_port_allocator_factory.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 // ChromiumPortAllocator for the PeerConnection. | 53 // webrtc::PeerConnectionInterface::RTCConfiguration for the PeerConnection. |
54 const char kDefaultStunHost[] = "stun.l.google.com"; | 54 const char kDefaultStunURI[] = "stun:stun.l.google.com:19302"; |
55 const int kDefaultStunPort = 19302; | |
56 | 55 |
57 const char kWorkerThreadName[] = "CastExtensionSessionWorkerThread"; | 56 const char kWorkerThreadName[] = "CastExtensionSessionWorkerThread"; |
58 | 57 |
59 // Interval between each call to PollPeerConnectionStats(). | 58 // Interval between each call to PollPeerConnectionStats(). |
60 const int kStatsLogIntervalSec = 10; | 59 const int kStatsLogIntervalSec = 10; |
61 | 60 |
62 // Minimum frame rate for video streaming over the PeerConnection in frames per | 61 // Minimum frame rate for video streaming over the PeerConnection in frames per |
63 // second, added as a media constraint when constructing the video source for | 62 // second, added as a media constraint when constructing the video source for |
64 // the Peer Connection. | 63 // the Peer Connection. |
65 const int kMinFramesPerSecond = 5; | 64 const int kMinFramesPerSecond = 5; |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 worker_thread_wrapper_, signaling_thread_wrapper_, nullptr, nullptr, | 474 worker_thread_wrapper_, signaling_thread_wrapper_, nullptr, nullptr, |
476 nullptr); | 475 nullptr); |
477 | 476 |
478 if (!peer_conn_factory_.get()) { | 477 if (!peer_conn_factory_.get()) { |
479 CleanupPeerConnection(); | 478 CleanupPeerConnection(); |
480 return false; | 479 return false; |
481 } | 480 } |
482 | 481 |
483 VLOG(1) << "Created PeerConnectionFactory successfully."; | 482 VLOG(1) << "Created PeerConnectionFactory successfully."; |
484 | 483 |
| 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 |
485 // DTLS-SRTP is the preferred encryption method. If set to kValueFalse, the | 491 // DTLS-SRTP is the preferred encryption method. If set to kValueFalse, the |
486 // peer connection uses SDES. Disabling SDES as well will cause the peer | 492 // peer connection uses SDES. Disabling SDES as well will cause the peer |
487 // connection to fail to connect. | 493 // connection to fail to connect. |
488 // Note: For protection and unprotection of SRTP packets, the libjingle | 494 // Note: For protection and unprotection of SRTP packets, the libjingle |
489 // ENABLE_EXTERNAL_AUTH flag must not be set. | 495 // ENABLE_EXTERNAL_AUTH flag must not be set. |
490 webrtc::FakeConstraints constraints; | 496 webrtc::FakeConstraints constraints; |
491 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | 497 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
492 webrtc::MediaConstraintsInterface::kValueTrue); | 498 webrtc::MediaConstraintsInterface::kValueTrue); |
493 | 499 |
494 rtc::scoped_ptr<protocol::ChromiumPortAllocator> port_allocator( | 500 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> |
495 protocol::ChromiumPortAllocator::Create(url_request_context_getter_, | 501 port_allocator_factory = protocol::ChromiumPortAllocatorFactory::Create( |
496 network_settings_) | 502 network_settings_, url_request_context_getter_); |
497 .release()); | |
498 std::vector<rtc::SocketAddress> stun_hosts; | |
499 stun_hosts.push_back(rtc::SocketAddress(kDefaultStunHost, kDefaultStunPort)); | |
500 port_allocator->SetStunHosts(stun_hosts); | |
501 | 503 |
502 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config; | |
503 peer_connection_ = peer_conn_factory_->CreatePeerConnection( | 504 peer_connection_ = peer_conn_factory_->CreatePeerConnection( |
504 rtc_config, &constraints, port_allocator.Pass(), nullptr, this); | 505 rtc_config, &constraints, port_allocator_factory, nullptr, this); |
505 | 506 |
506 if (!peer_connection_.get()) { | 507 if (!peer_connection_.get()) { |
507 CleanupPeerConnection(); | 508 CleanupPeerConnection(); |
508 return false; | 509 return false; |
509 } | 510 } |
510 | 511 |
511 VLOG(1) << "Created PeerConnection successfully."; | 512 VLOG(1) << "Created PeerConnection successfully."; |
512 | 513 |
513 create_session_desc_observer_ = | 514 create_session_desc_observer_ = |
514 CastCreateSessionDescriptionObserver::Create(this); | 515 CastCreateSessionDescriptionObserver::Create(this); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 json.SetString(kWebRtcCandidate, candidate_str); | 653 json.SetString(kWebRtcCandidate, candidate_str); |
653 std::string json_str; | 654 std::string json_str; |
654 if (!base::JSONWriter::Write(json, &json_str)) { | 655 if (!base::JSONWriter::Write(json, &json_str)) { |
655 LOG(ERROR) << "Failed to serialize candidate message."; | 656 LOG(ERROR) << "Failed to serialize candidate message."; |
656 return; | 657 return; |
657 } | 658 } |
658 SendMessageToClient(kSubjectNewCandidate, json_str); | 659 SendMessageToClient(kSubjectNewCandidate, json_str); |
659 } | 660 } |
660 | 661 |
661 } // namespace remoting | 662 } // namespace remoting |
OLD | NEW |