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
3 // found in the LICENSE file.
5 #include "remoting/host/cast_extension_session.h"
8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h"
10 #include "base/logging.h"
11 #include "base/synchronization/waitable_event.h"
12 #include "net/url_request/url_request_context_getter.h"
13 #include "remoting/host/cast_video_capturer_adapter.h"
14 #include "remoting/host/chromium_port_allocator_factory.h"
15 #include "remoting/host/client_session.h"
16 #include "remoting/proto/control.pb.h"
17 #include "remoting/protocol/client_stub.h"
18 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
19 #include "third_party/libjingle/source/talk/app/webrtc/test/fakeconstraints.h"
20 #include "third_party/libjingle/source/talk/app/webrtc/videosourceinterface.h"
24 // Used as the type attribute of all Cast protocol::ExtensionMessages.
25 const char kExtensionMessageType
[] = "cast_message";
27 // Top-level keys used in all extension messages between host and client.
28 // Must keep synced with webapp.
29 const char kTopLevelData
[] = "chromoting_data";
30 const char kTopLevelSubject
[] = "subject";
32 // Keys used to describe the subject of a cast extension message. WebRTC-related
33 // message subjects are prepended with "webrtc_".
34 // Must keep synced with webapp.
35 const char kSubjectReady
[] = "ready";
36 const char kSubjectTest
[] = "test";
37 const char kSubjectNewCandidate
[] = "webrtc_candidate";
38 const char kSubjectOffer
[] = "webrtc_offer";
39 const char kSubjectAnswer
[] = "webrtc_answer";
41 // WebRTC headers used inside messages with subject = "webrtc_*".
42 const char kWebRtcCandidate
[] = "candidate";
43 const char kWebRtcSessionDescType
[] = "type";
44 const char kWebRtcSessionDescSDP
[] = "sdp";
45 const char kWebRtcSDPMid
[] = "sdpMid";
46 const char kWebRtcSDPMLineIndex
[] = "sdpMLineIndex";
48 // Media labels used over the PeerConnection.
49 const char kVideoLabel
[] = "cast_video_label";
50 const char kStreamLabel
[] = "stream_label";
52 // Default STUN server used to construct
53 // webrtc::PeerConnectionInterface::RTCConfiguration for the PeerConnection.
54 const char kDefaultStunURI
[] = "stun:stun.l.google.com:19302";
56 const char kWorkerThreadName
[] = "CastExtensionSessionWorkerThread";
58 // Interval between each call to PollPeerConnectionStats().
59 const int kStatsLogIntervalSec
= 10;
61 // 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 // the Peer Connection.
64 const int kMinFramesPerSecond
= 5;
66 // A webrtc::SetSessionDescriptionObserver implementation used to receive the
67 // results of setting local and remote descriptions of the PeerConnection.
68 class CastSetSessionDescriptionObserver
69 : public webrtc::SetSessionDescriptionObserver
{
71 static CastSetSessionDescriptionObserver
* Create() {
72 return new rtc::RefCountedObject
<CastSetSessionDescriptionObserver
>();
74 virtual void OnSuccess() override
{
75 VLOG(1) << "Setting session description succeeded.";
77 virtual void OnFailure(const std::string
& error
) override
{
78 LOG(ERROR
) << "Setting session description failed: " << error
;
82 CastSetSessionDescriptionObserver() {}
83 virtual ~CastSetSessionDescriptionObserver() {}
85 DISALLOW_COPY_AND_ASSIGN(CastSetSessionDescriptionObserver
);
88 // A webrtc::CreateSessionDescriptionObserver implementation used to receive the
89 // results of creating descriptions for this end of the PeerConnection.
90 class CastCreateSessionDescriptionObserver
91 : public webrtc::CreateSessionDescriptionObserver
{
93 static CastCreateSessionDescriptionObserver
* Create(
94 CastExtensionSession
* session
) {
95 return new rtc::RefCountedObject
<CastCreateSessionDescriptionObserver
>(
98 virtual void OnSuccess(webrtc::SessionDescriptionInterface
* desc
) override
{
99 if (cast_extension_session_
== NULL
) {
101 << "No CastExtensionSession. Creating session description succeeded.";
104 cast_extension_session_
->OnCreateSessionDescription(desc
);
106 virtual void OnFailure(const std::string
& error
) override
{
107 if (cast_extension_session_
== NULL
) {
109 << "No CastExtensionSession. Creating session description failed.";
112 cast_extension_session_
->OnCreateSessionDescriptionFailure(error
);
114 void SetCastExtensionSession(CastExtensionSession
* cast_extension_session
) {
115 cast_extension_session_
= cast_extension_session
;
119 explicit CastCreateSessionDescriptionObserver(CastExtensionSession
* session
)
120 : cast_extension_session_(session
) {}
121 virtual ~CastCreateSessionDescriptionObserver() {}
124 CastExtensionSession
* cast_extension_session_
;
126 DISALLOW_COPY_AND_ASSIGN(CastCreateSessionDescriptionObserver
);
129 // A webrtc::StatsObserver implementation used to receive statistics about the
130 // current PeerConnection.
131 class CastStatsObserver
: public webrtc::StatsObserver
{
133 static CastStatsObserver
* Create() {
134 return new rtc::RefCountedObject
<CastStatsObserver
>();
137 virtual void OnComplete(
138 const std::vector
<webrtc::StatsReport
>& reports
) override
{
139 typedef webrtc::StatsReport::Values::iterator ValuesIterator
;
141 VLOG(1) << "Received " << reports
.size() << " new StatsReports.";
144 std::vector
<webrtc::StatsReport
>::const_iterator it
;
145 for (it
= reports
.begin(), index
= 0; it
!= reports
.end(); ++it
, ++index
) {
146 webrtc::StatsReport::Values v
= it
->values
;
147 VLOG(1) << "Report " << index
<< ":";
148 for (ValuesIterator vIt
= v
.begin(); vIt
!= v
.end(); ++vIt
) {
149 VLOG(1) << "Stat: " << vIt
->name
<< "=" << vIt
->value
<< ".";
155 CastStatsObserver() {}
156 virtual ~CastStatsObserver() {}
158 DISALLOW_COPY_AND_ASSIGN(CastStatsObserver
);
161 // TODO(aiguha): Fix PeerConnnection-related tear down crash caused by premature
162 // destruction of cricket::CaptureManager (which occurs on releasing
163 // |peer_conn_factory_|). See crbug.com/403840.
164 CastExtensionSession::~CastExtensionSession() {
165 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
167 // Explicitly clear |create_session_desc_observer_|'s pointer to |this|,
168 // since the CastExtensionSession is destructing. Otherwise,
169 // |create_session_desc_observer_| would be left with a dangling pointer.
170 create_session_desc_observer_
->SetCastExtensionSession(NULL
);
172 CleanupPeerConnection();
176 scoped_ptr
<CastExtensionSession
> CastExtensionSession::Create(
177 scoped_refptr
<base::SingleThreadTaskRunner
> caller_task_runner
,
178 scoped_refptr
<net::URLRequestContextGetter
> url_request_context_getter
,
179 const protocol::NetworkSettings
& network_settings
,
180 ClientSessionControl
* client_session_control
,
181 protocol::ClientStub
* client_stub
) {
182 scoped_ptr
<CastExtensionSession
> cast_extension_session(
183 new CastExtensionSession(caller_task_runner
,
184 url_request_context_getter
,
186 client_session_control
,
188 if (!cast_extension_session
->WrapTasksAndSave() ||
189 !cast_extension_session
->InitializePeerConnection()) {
192 return cast_extension_session
.Pass();
195 void CastExtensionSession::OnCreateSessionDescription(
196 webrtc::SessionDescriptionInterface
* desc
) {
197 if (!caller_task_runner_
->BelongsToCurrentThread()) {
198 caller_task_runner_
->PostTask(
200 base::Bind(&CastExtensionSession::OnCreateSessionDescription
,
201 base::Unretained(this),
206 peer_connection_
->SetLocalDescription(
207 CastSetSessionDescriptionObserver::Create(), desc
);
209 scoped_ptr
<base::DictionaryValue
> json(new base::DictionaryValue());
210 json
->SetString(kWebRtcSessionDescType
, desc
->type());
211 std::string subject
=
212 (desc
->type() == "offer") ? kSubjectOffer
: kSubjectAnswer
;
213 std::string desc_str
;
214 desc
->ToString(&desc_str
);
215 json
->SetString(kWebRtcSessionDescSDP
, desc_str
);
216 std::string json_str
;
217 if (!base::JSONWriter::Write(json
.get(), &json_str
)) {
218 LOG(ERROR
) << "Failed to serialize sdp message.";
222 SendMessageToClient(subject
.c_str(), json_str
);
225 void CastExtensionSession::OnCreateSessionDescriptionFailure(
226 const std::string
& error
) {
227 VLOG(1) << "Creating Session Description failed: " << error
;
230 // TODO(aiguha): Support the case(s) where we've grabbed the capturer already,
231 // but another extension reset the video pipeline. We should remove the
232 // stream from the peer connection here, and then attempt to re-setup the
233 // peer connection in the OnRenegotiationNeeded() callback.
234 // See crbug.com/403843.
235 void CastExtensionSession::OnCreateVideoCapturer(
236 scoped_ptr
<webrtc::DesktopCapturer
>* capturer
) {
237 if (has_grabbed_capturer_
) {
238 LOG(ERROR
) << "The video pipeline was reset unexpectedly.";
239 has_grabbed_capturer_
= false;
240 peer_connection_
->RemoveStream(stream_
.release());
244 if (received_offer_
) {
245 has_grabbed_capturer_
= true;
246 if (SetupVideoStream(capturer
->Pass())) {
247 peer_connection_
->CreateAnswer(create_session_desc_observer_
, NULL
);
249 has_grabbed_capturer_
= false;
250 // Ignore the received offer, since we failed to setup a video stream.
251 received_offer_
= false;
257 bool CastExtensionSession::ModifiesVideoPipeline() const {
261 // Returns true if the |message| is a Cast ExtensionMessage, even if
262 // it was badly formed or a resulting action failed. This is done so that
263 // the host does not continue to attempt to pass |message| to other
264 // HostExtensionSessions.
265 bool CastExtensionSession::OnExtensionMessage(
266 ClientSessionControl
* client_session_control
,
267 protocol::ClientStub
* client_stub
,
268 const protocol::ExtensionMessage
& message
) {
269 if (message
.type() != kExtensionMessageType
) {
273 scoped_ptr
<base::Value
> value(base::JSONReader::Read(message
.data()));
274 base::DictionaryValue
* client_message
;
275 if (!(value
&& value
->GetAsDictionary(&client_message
))) {
276 LOG(ERROR
) << "Could not read cast extension message.";
281 if (!client_message
->GetString(kTopLevelSubject
, &subject
)) {
282 LOG(ERROR
) << "Invalid Cast Extension Message (missing subject header).";
286 if (subject
== kSubjectOffer
&& !received_offer_
) {
287 // Reset the video pipeline so we can grab the screen capturer and setup
289 if (ParseAndSetRemoteDescription(client_message
)) {
290 received_offer_
= true;
291 LOG(INFO
) << "About to ResetVideoPipeline.";
292 client_session_control_
->ResetVideoPipeline();
295 } else if (subject
== kSubjectAnswer
) {
296 ParseAndSetRemoteDescription(client_message
);
297 } else if (subject
== kSubjectNewCandidate
) {
298 ParseAndAddICECandidate(client_message
);
300 VLOG(1) << "Unexpected CastExtension Message: " << message
.data();
305 // Private methods ------------------------------------------------------------
307 CastExtensionSession::CastExtensionSession(
308 scoped_refptr
<base::SingleThreadTaskRunner
> caller_task_runner
,
309 scoped_refptr
<net::URLRequestContextGetter
> url_request_context_getter
,
310 const protocol::NetworkSettings
& network_settings
,
311 ClientSessionControl
* client_session_control
,
312 protocol::ClientStub
* client_stub
)
313 : caller_task_runner_(caller_task_runner
),
314 url_request_context_getter_(url_request_context_getter
),
315 network_settings_(network_settings
),
316 client_session_control_(client_session_control
),
317 client_stub_(client_stub
),
318 stats_observer_(CastStatsObserver::Create()),
319 received_offer_(false),
320 has_grabbed_capturer_(false),
321 signaling_thread_wrapper_(NULL
),
322 worker_thread_wrapper_(NULL
),
323 worker_thread_(kWorkerThreadName
) {
324 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
325 DCHECK(url_request_context_getter_
.get());
326 DCHECK(client_session_control_
);
327 DCHECK(client_stub_
);
329 // The worker thread is created with base::MessageLoop::TYPE_IO because
330 // the PeerConnection performs some port allocation operations on this thread
331 // that require it. See crbug.com/404013.
332 base::Thread::Options
options(base::MessageLoop::TYPE_IO
, 0);
333 worker_thread_
.StartWithOptions(options
);
334 worker_task_runner_
= worker_thread_
.task_runner();
337 bool CastExtensionSession::ParseAndSetRemoteDescription(
338 base::DictionaryValue
* message
) {
339 DCHECK(peer_connection_
.get() != NULL
);
341 base::DictionaryValue
* message_data
;
342 if (!message
->GetDictionary(kTopLevelData
, &message_data
)) {
343 LOG(ERROR
) << "Invalid Cast Extension Message (missing data).";
347 std::string webrtc_type
;
348 if (!message_data
->GetString(kWebRtcSessionDescType
, &webrtc_type
)) {
350 << "Invalid Cast Extension Message (missing webrtc type header).";
355 if (!message_data
->GetString(kWebRtcSessionDescSDP
, &sdp
)) {
356 LOG(ERROR
) << "Invalid Cast Extension Message (missing webrtc sdp header).";
360 webrtc::SdpParseError error
;
361 webrtc::SessionDescriptionInterface
* session_description(
362 webrtc::CreateSessionDescription(webrtc_type
, sdp
, &error
));
364 if (!session_description
) {
365 LOG(ERROR
) << "Invalid Cast Extension Message (could not parse sdp).";
366 VLOG(1) << "SdpParseError was: " << error
.description
;
370 peer_connection_
->SetRemoteDescription(
371 CastSetSessionDescriptionObserver::Create(), session_description
);
375 bool CastExtensionSession::ParseAndAddICECandidate(
376 base::DictionaryValue
* message
) {
377 DCHECK(peer_connection_
.get() != NULL
);
379 base::DictionaryValue
* message_data
;
380 if (!message
->GetDictionary(kTopLevelData
, &message_data
)) {
381 LOG(ERROR
) << "Invalid Cast Extension Message (missing data).";
385 std::string candidate_str
;
387 int sdp_mlineindex
= 0;
388 if (!message_data
->GetString(kWebRtcSDPMid
, &sdp_mid
) ||
389 !message_data
->GetInteger(kWebRtcSDPMLineIndex
, &sdp_mlineindex
) ||
390 !message_data
->GetString(kWebRtcCandidate
, &candidate_str
)) {
391 LOG(ERROR
) << "Invalid Cast Extension Message (could not parse).";
395 rtc::scoped_ptr
<webrtc::IceCandidateInterface
> candidate(
396 webrtc::CreateIceCandidate(sdp_mid
, sdp_mlineindex
, candidate_str
));
397 if (!candidate
.get()) {
399 << "Invalid Cast Extension Message (could not create candidate).";
403 if (!peer_connection_
->AddIceCandidate(candidate
.get())) {
404 LOG(ERROR
) << "Failed to apply received ICE Candidate to PeerConnection.";
408 VLOG(1) << "Received and Added ICE Candidate: " << candidate_str
;
413 bool CastExtensionSession::SendMessageToClient(const std::string
& subject
,
414 const std::string
& data
) {
415 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
417 if (client_stub_
== NULL
) {
418 LOG(ERROR
) << "No Client Stub. Cannot send message to client.";
422 base::DictionaryValue message_dict
;
423 message_dict
.SetString(kTopLevelSubject
, subject
);
424 message_dict
.SetString(kTopLevelData
, data
);
425 std::string message_json
;
427 if (!base::JSONWriter::Write(&message_dict
, &message_json
)) {
428 LOG(ERROR
) << "Failed to serialize JSON message.";
432 protocol::ExtensionMessage message
;
433 message
.set_type(kExtensionMessageType
);
434 message
.set_data(message_json
);
435 client_stub_
->DeliverHostMessage(message
);
439 void CastExtensionSession::EnsureTaskAndSetSend(rtc::Thread
** ptr
,
440 base::WaitableEvent
* event
) {
441 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
442 jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true);
443 *ptr
= jingle_glue::JingleThreadWrapper::current();
450 bool CastExtensionSession::WrapTasksAndSave() {
451 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
453 EnsureTaskAndSetSend(&signaling_thread_wrapper_
);
454 if (signaling_thread_wrapper_
== NULL
)
457 base::WaitableEvent
wrap_worker_thread_event(true, false);
458 worker_task_runner_
->PostTask(
460 base::Bind(&CastExtensionSession::EnsureTaskAndSetSend
,
461 base::Unretained(this),
462 &worker_thread_wrapper_
,
463 &wrap_worker_thread_event
));
464 wrap_worker_thread_event
.Wait();
466 return (worker_thread_wrapper_
!= NULL
);
469 bool CastExtensionSession::InitializePeerConnection() {
470 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
471 DCHECK(!peer_conn_factory_
);
472 DCHECK(!peer_connection_
);
473 DCHECK(worker_thread_wrapper_
!= NULL
);
474 DCHECK(signaling_thread_wrapper_
!= NULL
);
476 peer_conn_factory_
= webrtc::CreatePeerConnectionFactory(
477 worker_thread_wrapper_
, signaling_thread_wrapper_
, NULL
, NULL
, NULL
);
479 if (!peer_conn_factory_
.get()) {
480 CleanupPeerConnection();
484 VLOG(1) << "Created PeerConnectionFactory successfully.";
486 webrtc::PeerConnectionInterface::IceServers servers
;
487 webrtc::PeerConnectionInterface::IceServer server
;
488 server
.uri
= kDefaultStunURI
;
489 servers
.push_back(server
);
490 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config
;
491 rtc_config
.servers
= servers
;
493 // DTLS-SRTP is the preferred encryption method. If set to kValueFalse, the
494 // peer connection uses SDES. Disabling SDES as well will cause the peer
495 // connection to fail to connect.
496 // Note: For protection and unprotection of SRTP packets, the libjingle
497 // ENABLE_EXTERNAL_AUTH flag must not be set.
498 webrtc::FakeConstraints constraints
;
499 constraints
.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp
,
500 webrtc::MediaConstraintsInterface::kValueTrue
);
502 rtc::scoped_refptr
<webrtc::PortAllocatorFactoryInterface
>
503 port_allocator_factory
= ChromiumPortAllocatorFactory::Create(
504 network_settings_
, url_request_context_getter_
);
506 peer_connection_
= peer_conn_factory_
->CreatePeerConnection(
507 rtc_config
, &constraints
, port_allocator_factory
, NULL
, this);
509 if (!peer_connection_
.get()) {
510 CleanupPeerConnection();
514 VLOG(1) << "Created PeerConnection successfully.";
516 create_session_desc_observer_
=
517 CastCreateSessionDescriptionObserver::Create(this);
519 // Send a test message to the client. Then, notify the client to start
520 // webrtc offer/answer negotiation.
521 if (!SendMessageToClient(kSubjectTest
, "Hello, client.") ||
522 !SendMessageToClient(kSubjectReady
, "Host ready to receive offers.")) {
523 LOG(ERROR
) << "Failed to send messages to client.";
530 bool CastExtensionSession::SetupVideoStream(
531 scoped_ptr
<webrtc::DesktopCapturer
> desktop_capturer
) {
532 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
533 DCHECK(desktop_capturer
);
536 VLOG(1) << "Already added MediaStream. Aborting Setup.";
540 scoped_ptr
<CastVideoCapturerAdapter
> cast_video_capturer_adapter(
541 new CastVideoCapturerAdapter(desktop_capturer
.Pass()));
543 // Set video stream constraints.
544 webrtc::FakeConstraints video_constraints
;
545 video_constraints
.AddMandatory(
546 webrtc::MediaConstraintsInterface::kMinFrameRate
, kMinFramesPerSecond
);
548 rtc::scoped_refptr
<webrtc::VideoTrackInterface
> video_track
=
549 peer_conn_factory_
->CreateVideoTrack(
551 peer_conn_factory_
->CreateVideoSource(
552 cast_video_capturer_adapter
.release(), &video_constraints
));
554 stream_
= peer_conn_factory_
->CreateLocalMediaStream(kStreamLabel
);
556 if (!stream_
->AddTrack(video_track
) ||
557 !peer_connection_
->AddStream(stream_
, NULL
)) {
561 VLOG(1) << "Setup video stream successfully.";
566 void CastExtensionSession::PollPeerConnectionStats() {
567 if (!connection_active()) {
568 VLOG(1) << "Cannot poll stats while PeerConnection is inactive.";
570 rtc::scoped_refptr
<webrtc::MediaStreamTrackInterface
> video_track
=
571 stream_
->FindVideoTrack(kVideoLabel
);
572 peer_connection_
->GetStats(
574 video_track
.release(),
575 webrtc::PeerConnectionInterface::kStatsOutputLevelStandard
);
578 void CastExtensionSession::CleanupPeerConnection() {
579 peer_connection_
->Close();
580 peer_connection_
= NULL
;
582 peer_conn_factory_
= NULL
;
583 worker_thread_
.Stop();
586 bool CastExtensionSession::connection_active() const {
587 return peer_connection_
.get() != NULL
;
590 // webrtc::PeerConnectionObserver implementation -------------------------------
592 void CastExtensionSession::OnError() {
593 VLOG(1) << "PeerConnectionObserver: an error occurred.";
596 void CastExtensionSession::OnSignalingChange(
597 webrtc::PeerConnectionInterface::SignalingState new_state
) {
598 VLOG(1) << "PeerConnectionObserver: SignalingState changed to:" << new_state
;
601 void CastExtensionSession::OnStateChange(
602 webrtc::PeerConnectionObserver::StateType state_changed
) {
603 VLOG(1) << "PeerConnectionObserver: StateType changed to: " << state_changed
;
606 void CastExtensionSession::OnAddStream(webrtc::MediaStreamInterface
* stream
) {
607 VLOG(1) << "PeerConnectionObserver: stream added: " << stream
->label();
610 void CastExtensionSession::OnRemoveStream(
611 webrtc::MediaStreamInterface
* stream
) {
612 VLOG(1) << "PeerConnectionObserver: stream removed: " << stream
->label();
615 void CastExtensionSession::OnDataChannel(
616 webrtc::DataChannelInterface
* data_channel
) {
617 VLOG(1) << "PeerConnectionObserver: data channel: " << data_channel
->label();
620 void CastExtensionSession::OnRenegotiationNeeded() {
621 VLOG(1) << "PeerConnectionObserver: renegotiation needed.";
624 void CastExtensionSession::OnIceConnectionChange(
625 webrtc::PeerConnectionInterface::IceConnectionState new_state
) {
626 VLOG(1) << "PeerConnectionObserver: IceConnectionState changed to: "
629 // TODO(aiguha): Maybe start timer only if enabled by command-line flag or
630 // at a particular verbosity level.
631 if (!stats_polling_timer_
.IsRunning() &&
632 new_state
== webrtc::PeerConnectionInterface::kIceConnectionConnected
) {
633 stats_polling_timer_
.Start(
635 base::TimeDelta::FromSeconds(kStatsLogIntervalSec
),
637 &CastExtensionSession::PollPeerConnectionStats
);
641 void CastExtensionSession::OnIceGatheringChange(
642 webrtc::PeerConnectionInterface::IceGatheringState new_state
) {
643 VLOG(1) << "PeerConnectionObserver: IceGatheringState changed to: "
647 void CastExtensionSession::OnIceComplete() {
648 VLOG(1) << "PeerConnectionObserver: all ICE candidates found.";
651 void CastExtensionSession::OnIceCandidate(
652 const webrtc::IceCandidateInterface
* candidate
) {
653 std::string candidate_str
;
654 if (!candidate
->ToString(&candidate_str
)) {
655 LOG(ERROR
) << "PeerConnectionObserver: failed to serialize candidate.";
658 scoped_ptr
<base::DictionaryValue
> json(new base::DictionaryValue());
659 json
->SetString(kWebRtcSDPMid
, candidate
->sdp_mid());
660 json
->SetInteger(kWebRtcSDPMLineIndex
, candidate
->sdp_mline_index());
661 json
->SetString(kWebRtcCandidate
, candidate_str
);
662 std::string json_str
;
663 if (!base::JSONWriter::Write(json
.get(), &json_str
)) {
664 LOG(ERROR
) << "Failed to serialize candidate message.";
667 SendMessageToClient(kSubjectNewCandidate
, json_str
);
670 } // namespace remoting