Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: remoting/protocol/webrtc_transport.cc

Issue 1521883006: Add TransportContext class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "jingle/glue/thread_wrapper.h" 12 #include "jingle/glue/thread_wrapper.h"
13 #include "remoting/protocol/transport_context.h"
13 #include "third_party/libjingle/source/talk/app/webrtc/test/fakeconstraints.h" 14 #include "third_party/libjingle/source/talk/app/webrtc/test/fakeconstraints.h"
14 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" 15 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
15 #include "third_party/webrtc/modules/audio_device/include/fake_audio_device.h" 16 #include "third_party/webrtc/modules/audio_device/include/fake_audio_device.h"
16 17
17 using buzz::QName; 18 using buzz::QName;
18 using buzz::XmlElement; 19 using buzz::XmlElement;
19 20
20 namespace remoting { 21 namespace remoting {
21 namespace protocol { 22 namespace protocol {
22 23
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 private: 95 private:
95 ResultCallback result_callback_; 96 ResultCallback result_callback_;
96 97
97 DISALLOW_COPY_AND_ASSIGN(SetSessionDescriptionObserver); 98 DISALLOW_COPY_AND_ASSIGN(SetSessionDescriptionObserver);
98 }; 99 };
99 100
100 } // namespace 101 } // namespace
101 102
102 WebrtcTransport::WebrtcTransport( 103 WebrtcTransport::WebrtcTransport(
103 rtc::Thread* worker_thread, 104 rtc::Thread* worker_thread,
104 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> 105 scoped_refptr<TransportContext> transport_context)
105 port_allocator_factory, 106 : transport_context_(transport_context),
106 TransportRole role)
107 : port_allocator_factory_(port_allocator_factory),
108 role_(role),
109 worker_thread_(worker_thread), 107 worker_thread_(worker_thread),
110 weak_factory_(this) {} 108 weak_factory_(this) {}
111 109
112 WebrtcTransport::~WebrtcTransport() {} 110 WebrtcTransport::~WebrtcTransport() {}
113 111
114 void WebrtcTransport::Start(EventHandler* event_handler, 112 void WebrtcTransport::Start(EventHandler* event_handler,
115 Authenticator* authenticator) { 113 Authenticator* authenticator) {
116 DCHECK(thread_checker_.CalledOnValidThread()); 114 DCHECK(thread_checker_.CalledOnValidThread());
117 115
118 event_handler_ = event_handler; 116 event_handler_ = event_handler;
117 // TODO(sergeyu): Use the |authenticator| to authenticate PeerConnection.
119 118
120 // TODO(sergeyu): Use the |authenticator| to authenticate PeerConnection. 119 transport_context_->CreatePortAllocator(base::Bind(
120 &WebrtcTransport::OnPortAllocatorCreated, weak_factory_.GetWeakPtr()));
121 }
122
123 void WebrtcTransport::OnPortAllocatorCreated(
124 scoped_ptr<cricket::PortAllocator> port_allocator) {
121 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); 125 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
122 126
123 // TODO(sergeyu): Investigate if it's possible to avoid Send(). 127 // TODO(sergeyu): Investigate if it's possible to avoid Send().
124 jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true); 128 jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true);
125 129
126 fake_audio_device_module_.reset(new webrtc::FakeAudioDeviceModule()); 130 fake_audio_device_module_.reset(new webrtc::FakeAudioDeviceModule());
127 131
128 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( 132 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
129 worker_thread_, rtc::Thread::Current(), 133 worker_thread_, rtc::Thread::Current(),
130 fake_audio_device_module_.get(), nullptr, nullptr); 134 fake_audio_device_module_.get(), nullptr, nullptr);
131 135
132 webrtc::PeerConnectionInterface::IceServer stun_server; 136 webrtc::PeerConnectionInterface::IceServer stun_server;
133 stun_server.urls.push_back("stun:stun.l.google.com:19302"); 137 stun_server.urls.push_back("stun:stun.l.google.com:19302");
134 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config; 138 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config;
135 rtc_config.servers.push_back(stun_server); 139 rtc_config.servers.push_back(stun_server);
136 140
137 webrtc::FakeConstraints constraints; 141 webrtc::FakeConstraints constraints;
138 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, 142 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
139 webrtc::MediaConstraintsInterface::kValueTrue); 143 webrtc::MediaConstraintsInterface::kValueTrue);
140 144
141 peer_connection_ = peer_connection_factory_->CreatePeerConnection( 145 peer_connection_ = peer_connection_factory_->CreatePeerConnection(
142 rtc_config, &constraints, port_allocator_factory_, nullptr, this); 146 rtc_config, &constraints,
147 rtc::scoped_ptr<cricket::PortAllocator>(port_allocator.release()),
148 nullptr, this);
143 149
144 data_stream_adapter_.Initialize(peer_connection_, 150 data_stream_adapter_.Initialize(
145 role_ == TransportRole::SERVER); 151 peer_connection_, transport_context_->role() == TransportRole::SERVER);
146 152
147 if (role_ == TransportRole::SERVER) 153 if (transport_context_->role() == TransportRole::SERVER)
148 RequestNegotiation(); 154 RequestNegotiation();
149 } 155 }
150 156
151 bool WebrtcTransport::ProcessTransportInfo(XmlElement* transport_info) { 157 bool WebrtcTransport::ProcessTransportInfo(XmlElement* transport_info) {
152 DCHECK(thread_checker_.CalledOnValidThread()); 158 DCHECK(thread_checker_.CalledOnValidThread());
153 159
154 if (transport_info->Name() != QName(kTransportNamespace, "transport")) 160 if (transport_info->Name() != QName(kTransportNamespace, "transport"))
155 return false; 161 return false;
156 162
157 if (!peer_connection_) 163 if (!peer_connection_)
158 return false; 164 return false;
159 165
160 XmlElement* session_description = transport_info->FirstNamed( 166 XmlElement* session_description = transport_info->FirstNamed(
161 QName(kTransportNamespace, "session-description")); 167 QName(kTransportNamespace, "session-description"));
162 if (session_description) { 168 if (session_description) {
163 webrtc::PeerConnectionInterface::SignalingState expected_state = 169 webrtc::PeerConnectionInterface::SignalingState expected_state =
164 role_ == TransportRole::CLIENT 170 transport_context_->role() == TransportRole::CLIENT
165 ? webrtc::PeerConnectionInterface::kStable 171 ? webrtc::PeerConnectionInterface::kStable
166 : webrtc::PeerConnectionInterface::kHaveLocalOffer; 172 : webrtc::PeerConnectionInterface::kHaveLocalOffer;
167 if (peer_connection_->signaling_state() != expected_state) { 173 if (peer_connection_->signaling_state() != expected_state) {
168 LOG(ERROR) << "Received unexpected WebRTC session_description. "; 174 LOG(ERROR) << "Received unexpected WebRTC session_description. ";
169 return false; 175 return false;
170 } 176 }
171 177
172 std::string type = session_description->Attr(QName(std::string(), "type")); 178 std::string type = session_description->Attr(QName(std::string(), "type"));
173 std::string sdp = session_description->BodyText(); 179 std::string sdp = session_description->BodyText();
174 if (type.empty() || sdp.empty()) { 180 if (type.empty() || sdp.empty()) {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 363
358 void WebrtcTransport::OnDataChannel( 364 void WebrtcTransport::OnDataChannel(
359 webrtc::DataChannelInterface* data_channel) { 365 webrtc::DataChannelInterface* data_channel) {
360 DCHECK(thread_checker_.CalledOnValidThread()); 366 DCHECK(thread_checker_.CalledOnValidThread());
361 data_stream_adapter_.OnIncomingDataChannel(data_channel); 367 data_stream_adapter_.OnIncomingDataChannel(data_channel);
362 } 368 }
363 369
364 void WebrtcTransport::OnRenegotiationNeeded() { 370 void WebrtcTransport::OnRenegotiationNeeded() {
365 DCHECK(thread_checker_.CalledOnValidThread()); 371 DCHECK(thread_checker_.CalledOnValidThread());
366 372
367 if (role_ == TransportRole::SERVER) { 373 if (transport_context_->role() == TransportRole::SERVER) {
368 RequestNegotiation(); 374 RequestNegotiation();
369 } else { 375 } else {
370 // TODO(sergeyu): Is it necessary to support renegotiation initiated by the 376 // TODO(sergeyu): Is it necessary to support renegotiation initiated by the
371 // client? 377 // client?
372 NOTIMPLEMENTED(); 378 NOTIMPLEMENTED();
373 } 379 }
374 } 380 }
375 381
376 void WebrtcTransport::RequestNegotiation() { 382 void WebrtcTransport::RequestNegotiation() {
377 DCHECK(role_ == TransportRole::SERVER); 383 DCHECK(transport_context_->role() == TransportRole::SERVER);
378 384
379 if (!negotiation_pending_) { 385 if (!negotiation_pending_) {
380 negotiation_pending_ = true; 386 negotiation_pending_ = true;
381 base::ThreadTaskRunnerHandle::Get()->PostTask( 387 base::ThreadTaskRunnerHandle::Get()->PostTask(
382 FROM_HERE, 388 FROM_HERE,
383 base::Bind(&WebrtcTransport::SendOffer, weak_factory_.GetWeakPtr())); 389 base::Bind(&WebrtcTransport::SendOffer, weak_factory_.GetWeakPtr()));
384 } 390 }
385 } 391 }
386 392
387 void WebrtcTransport::OnIceConnectionChange( 393 void WebrtcTransport::OnIceConnectionChange(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 438
433 // Delay sending the new candidates in case we get more candidates 439 // Delay sending the new candidates in case we get more candidates
434 // that we can send in one message. 440 // that we can send in one message.
435 transport_info_timer_.Start( 441 transport_info_timer_.Start(
436 FROM_HERE, base::TimeDelta::FromMilliseconds(kTransportInfoSendDelayMs), 442 FROM_HERE, base::TimeDelta::FromMilliseconds(kTransportInfoSendDelayMs),
437 this, &WebrtcTransport::SendTransportInfo); 443 this, &WebrtcTransport::SendTransportInfo);
438 } 444 }
439 } 445 }
440 446
441 void WebrtcTransport::SendOffer() { 447 void WebrtcTransport::SendOffer() {
442 DCHECK(role_ == TransportRole::SERVER); 448 DCHECK(transport_context_->role() == TransportRole::SERVER);
443 449
444 DCHECK(negotiation_pending_); 450 DCHECK(negotiation_pending_);
445 negotiation_pending_ = false; 451 negotiation_pending_ = false;
446 452
447 webrtc::FakeConstraints offer_config; 453 webrtc::FakeConstraints offer_config;
448 offer_config.AddMandatory( 454 offer_config.AddMandatory(
449 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, 455 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo,
450 webrtc::MediaConstraintsInterface::kValueTrue); 456 webrtc::MediaConstraintsInterface::kValueTrue);
451 offer_config.AddMandatory( 457 offer_config.AddMandatory(
452 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, 458 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio,
(...skipping 27 matching lines...) Expand all
480 Close(INCOMPATIBLE_PROTOCOL); 486 Close(INCOMPATIBLE_PROTOCOL);
481 return; 487 return;
482 } 488 }
483 } 489 }
484 pending_incoming_candidates_.clear(); 490 pending_incoming_candidates_.clear();
485 } 491 }
486 } 492 }
487 493
488 WebrtcTransportFactory::WebrtcTransportFactory( 494 WebrtcTransportFactory::WebrtcTransportFactory(
489 rtc::Thread* worker_thread, 495 rtc::Thread* worker_thread,
490 SignalStrategy* signal_strategy, 496 scoped_refptr<TransportContext> transport_context)
491 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface>
492 port_allocator_factory,
493 TransportRole role)
494 : worker_thread_(worker_thread), 497 : worker_thread_(worker_thread),
495 signal_strategy_(signal_strategy), 498 transport_context_(transport_context) {}
496 port_allocator_factory_(port_allocator_factory),
497 role_(role) {}
498 499
499 WebrtcTransportFactory::~WebrtcTransportFactory() {} 500 WebrtcTransportFactory::~WebrtcTransportFactory() {}
500 501
501 scoped_ptr<Transport> WebrtcTransportFactory::CreateTransport() { 502 scoped_ptr<Transport> WebrtcTransportFactory::CreateTransport() {
502 return make_scoped_ptr( 503 return make_scoped_ptr(
503 new WebrtcTransport(worker_thread_, port_allocator_factory_, role_)); 504 new WebrtcTransport(worker_thread_, transport_context_.get()));
504 } 505 }
505 506
506 } // namespace protocol 507 } // namespace protocol
507 } // namespace remoting 508 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698