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 void OnSuccess() override
{
75 VLOG(1) << "Setting session description succeeded.";
77 void OnFailure(const std::string
& error
) override
{
78 LOG(ERROR
) << "Setting session description failed: " << error
;
82 CastSetSessionDescriptionObserver() {}
83 ~CastSetSessionDescriptionObserver() override
{}
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 void OnSuccess(webrtc::SessionDescriptionInterface
* desc
) override
{
99 if (cast_extension_session_
== nullptr) {
101 << "No CastExtensionSession. Creating session description succeeded.";
104 cast_extension_session_
->OnCreateSessionDescription(desc
);
106 void OnFailure(const std::string
& error
) override
{
107 if (cast_extension_session_
== nullptr) {
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 ~CastCreateSessionDescriptionObserver() override
{}
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 void OnComplete(const webrtc::StatsReports
& reports
) override
{
138 VLOG(1) << "Received " << reports
.size() << " new StatsReports.";
141 for (const auto* report
: reports
) {
142 VLOG(1) << "Report " << index
++ << ":";
143 for (const auto& v
: report
->values()) {
144 VLOG(1) << "Stat: " << v
.second
->display_name() << "="
145 << v
.second
->ToString() << ".";
151 CastStatsObserver() {}
152 ~CastStatsObserver() override
{}
154 DISALLOW_COPY_AND_ASSIGN(CastStatsObserver
);
157 // TODO(aiguha): Fix PeerConnnection-related tear down crash caused by premature
158 // destruction of cricket::CaptureManager (which occurs on releasing
159 // |peer_conn_factory_|). See crbug.com/403840.
160 CastExtensionSession::~CastExtensionSession() {
161 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
163 // Explicitly clear |create_session_desc_observer_|'s pointer to |this|,
164 // since the CastExtensionSession is destructing. Otherwise,
165 // |create_session_desc_observer_| would be left with a dangling pointer.
166 create_session_desc_observer_
->SetCastExtensionSession(nullptr);
168 CleanupPeerConnection();
172 scoped_ptr
<CastExtensionSession
> CastExtensionSession::Create(
173 scoped_refptr
<base::SingleThreadTaskRunner
> caller_task_runner
,
174 scoped_refptr
<net::URLRequestContextGetter
> url_request_context_getter
,
175 const protocol::NetworkSettings
& network_settings
,
176 ClientSessionControl
* client_session_control
,
177 protocol::ClientStub
* client_stub
) {
178 scoped_ptr
<CastExtensionSession
> cast_extension_session(
179 new CastExtensionSession(caller_task_runner
,
180 url_request_context_getter
,
182 client_session_control
,
184 if (!cast_extension_session
->WrapTasksAndSave() ||
185 !cast_extension_session
->InitializePeerConnection()) {
188 return cast_extension_session
.Pass();
191 void CastExtensionSession::OnCreateSessionDescription(
192 webrtc::SessionDescriptionInterface
* desc
) {
193 if (!caller_task_runner_
->BelongsToCurrentThread()) {
194 caller_task_runner_
->PostTask(
196 base::Bind(&CastExtensionSession::OnCreateSessionDescription
,
197 base::Unretained(this),
202 peer_connection_
->SetLocalDescription(
203 CastSetSessionDescriptionObserver::Create(), desc
);
205 base::DictionaryValue json
;
206 json
.SetString(kWebRtcSessionDescType
, desc
->type());
207 std::string subject
=
208 (desc
->type() == "offer") ? kSubjectOffer
: kSubjectAnswer
;
209 std::string desc_str
;
210 desc
->ToString(&desc_str
);
211 json
.SetString(kWebRtcSessionDescSDP
, desc_str
);
212 std::string json_str
;
213 if (!base::JSONWriter::Write(json
, &json_str
)) {
214 LOG(ERROR
) << "Failed to serialize sdp message.";
218 SendMessageToClient(subject
.c_str(), json_str
);
221 void CastExtensionSession::OnCreateSessionDescriptionFailure(
222 const std::string
& error
) {
223 VLOG(1) << "Creating Session Description failed: " << error
;
226 // TODO(aiguha): Support the case(s) where we've grabbed the capturer already,
227 // but another extension reset the video pipeline. We should remove the
228 // stream from the peer connection here, and then attempt to re-setup the
229 // peer connection in the OnRenegotiationNeeded() callback.
230 // See crbug.com/403843.
231 void CastExtensionSession::OnCreateVideoCapturer(
232 scoped_ptr
<webrtc::DesktopCapturer
>* capturer
) {
233 if (has_grabbed_capturer_
) {
234 LOG(ERROR
) << "The video pipeline was reset unexpectedly.";
235 has_grabbed_capturer_
= false;
236 peer_connection_
->RemoveStream(stream_
.release());
240 if (received_offer_
) {
241 has_grabbed_capturer_
= true;
242 if (SetupVideoStream(capturer
->Pass())) {
243 peer_connection_
->CreateAnswer(create_session_desc_observer_
, nullptr);
245 has_grabbed_capturer_
= false;
246 // Ignore the received offer, since we failed to setup a video stream.
247 received_offer_
= false;
253 bool CastExtensionSession::ModifiesVideoPipeline() const {
257 // Returns true if the |message| is a Cast ExtensionMessage, even if
258 // it was badly formed or a resulting action failed. This is done so that
259 // the host does not continue to attempt to pass |message| to other
260 // HostExtensionSessions.
261 bool CastExtensionSession::OnExtensionMessage(
262 ClientSessionControl
* client_session_control
,
263 protocol::ClientStub
* client_stub
,
264 const protocol::ExtensionMessage
& message
) {
265 if (message
.type() != kExtensionMessageType
) {
269 scoped_ptr
<base::Value
> value
= base::JSONReader::Read(message
.data());
270 base::DictionaryValue
* client_message
;
271 if (!(value
&& value
->GetAsDictionary(&client_message
))) {
272 LOG(ERROR
) << "Could not read cast extension message.";
277 if (!client_message
->GetString(kTopLevelSubject
, &subject
)) {
278 LOG(ERROR
) << "Invalid Cast Extension Message (missing subject header).";
282 if (subject
== kSubjectOffer
&& !received_offer_
) {
283 // Reset the video pipeline so we can grab the screen capturer and setup
285 if (ParseAndSetRemoteDescription(client_message
)) {
286 received_offer_
= true;
287 LOG(INFO
) << "About to ResetVideoPipeline.";
288 client_session_control_
->ResetVideoPipeline();
291 } else if (subject
== kSubjectAnswer
) {
292 ParseAndSetRemoteDescription(client_message
);
293 } else if (subject
== kSubjectNewCandidate
) {
294 ParseAndAddICECandidate(client_message
);
296 VLOG(1) << "Unexpected CastExtension Message: " << message
.data();
301 // Private methods ------------------------------------------------------------
303 CastExtensionSession::CastExtensionSession(
304 scoped_refptr
<base::SingleThreadTaskRunner
> caller_task_runner
,
305 scoped_refptr
<net::URLRequestContextGetter
> url_request_context_getter
,
306 const protocol::NetworkSettings
& network_settings
,
307 ClientSessionControl
* client_session_control
,
308 protocol::ClientStub
* client_stub
)
309 : caller_task_runner_(caller_task_runner
),
310 url_request_context_getter_(url_request_context_getter
),
311 network_settings_(network_settings
),
312 client_session_control_(client_session_control
),
313 client_stub_(client_stub
),
314 stats_observer_(CastStatsObserver::Create()),
315 received_offer_(false),
316 has_grabbed_capturer_(false),
317 signaling_thread_wrapper_(nullptr),
318 worker_thread_wrapper_(nullptr),
319 worker_thread_(kWorkerThreadName
) {
320 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
321 DCHECK(url_request_context_getter_
.get());
322 DCHECK(client_session_control_
);
323 DCHECK(client_stub_
);
325 // The worker thread is created with base::MessageLoop::TYPE_IO because
326 // the PeerConnection performs some port allocation operations on this thread
327 // that require it. See crbug.com/404013.
328 base::Thread::Options
options(base::MessageLoop::TYPE_IO
, 0);
329 worker_thread_
.StartWithOptions(options
);
330 worker_task_runner_
= worker_thread_
.task_runner();
333 bool CastExtensionSession::ParseAndSetRemoteDescription(
334 base::DictionaryValue
* message
) {
335 DCHECK(peer_connection_
.get() != nullptr);
337 base::DictionaryValue
* message_data
;
338 if (!message
->GetDictionary(kTopLevelData
, &message_data
)) {
339 LOG(ERROR
) << "Invalid Cast Extension Message (missing data).";
343 std::string webrtc_type
;
344 if (!message_data
->GetString(kWebRtcSessionDescType
, &webrtc_type
)) {
346 << "Invalid Cast Extension Message (missing webrtc type header).";
351 if (!message_data
->GetString(kWebRtcSessionDescSDP
, &sdp
)) {
352 LOG(ERROR
) << "Invalid Cast Extension Message (missing webrtc sdp header).";
356 webrtc::SdpParseError error
;
357 webrtc::SessionDescriptionInterface
* session_description(
358 webrtc::CreateSessionDescription(webrtc_type
, sdp
, &error
));
360 if (!session_description
) {
361 LOG(ERROR
) << "Invalid Cast Extension Message (could not parse sdp).";
362 VLOG(1) << "SdpParseError was: " << error
.description
;
366 peer_connection_
->SetRemoteDescription(
367 CastSetSessionDescriptionObserver::Create(), session_description
);
371 bool CastExtensionSession::ParseAndAddICECandidate(
372 base::DictionaryValue
* message
) {
373 DCHECK(peer_connection_
.get() != nullptr);
375 base::DictionaryValue
* message_data
;
376 if (!message
->GetDictionary(kTopLevelData
, &message_data
)) {
377 LOG(ERROR
) << "Invalid Cast Extension Message (missing data).";
381 std::string candidate_str
;
383 int sdp_mlineindex
= 0;
384 if (!message_data
->GetString(kWebRtcSDPMid
, &sdp_mid
) ||
385 !message_data
->GetInteger(kWebRtcSDPMLineIndex
, &sdp_mlineindex
) ||
386 !message_data
->GetString(kWebRtcCandidate
, &candidate_str
)) {
387 LOG(ERROR
) << "Invalid Cast Extension Message (could not parse).";
391 rtc::scoped_ptr
<webrtc::IceCandidateInterface
> candidate(
392 webrtc::CreateIceCandidate(sdp_mid
, sdp_mlineindex
, candidate_str
,
394 if (!candidate
.get()) {
396 << "Invalid Cast Extension Message (could not create candidate).";
400 if (!peer_connection_
->AddIceCandidate(candidate
.get())) {
401 LOG(ERROR
) << "Failed to apply received ICE Candidate to PeerConnection.";
405 VLOG(1) << "Received and Added ICE Candidate: " << candidate_str
;
410 bool CastExtensionSession::SendMessageToClient(const std::string
& subject
,
411 const std::string
& data
) {
412 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
414 if (client_stub_
== nullptr) {
415 LOG(ERROR
) << "No Client Stub. Cannot send message to client.";
419 base::DictionaryValue message_dict
;
420 message_dict
.SetString(kTopLevelSubject
, subject
);
421 message_dict
.SetString(kTopLevelData
, data
);
422 std::string message_json
;
424 if (!base::JSONWriter::Write(message_dict
, &message_json
)) {
425 LOG(ERROR
) << "Failed to serialize JSON message.";
429 protocol::ExtensionMessage message
;
430 message
.set_type(kExtensionMessageType
);
431 message
.set_data(message_json
);
432 client_stub_
->DeliverHostMessage(message
);
436 void CastExtensionSession::EnsureTaskAndSetSend(rtc::Thread
** ptr
,
437 base::WaitableEvent
* event
) {
438 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
439 jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true);
440 *ptr
= jingle_glue::JingleThreadWrapper::current();
442 if (event
!= nullptr) {
447 bool CastExtensionSession::WrapTasksAndSave() {
448 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
450 EnsureTaskAndSetSend(&signaling_thread_wrapper_
);
451 if (signaling_thread_wrapper_
== nullptr)
454 base::WaitableEvent
wrap_worker_thread_event(true, false);
455 worker_task_runner_
->PostTask(
457 base::Bind(&CastExtensionSession::EnsureTaskAndSetSend
,
458 base::Unretained(this),
459 &worker_thread_wrapper_
,
460 &wrap_worker_thread_event
));
461 wrap_worker_thread_event
.Wait();
463 return (worker_thread_wrapper_
!= nullptr);
466 bool CastExtensionSession::InitializePeerConnection() {
467 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
468 DCHECK(!peer_conn_factory_
);
469 DCHECK(!peer_connection_
);
470 DCHECK(worker_thread_wrapper_
!= nullptr);
471 DCHECK(signaling_thread_wrapper_
!= nullptr);
473 peer_conn_factory_
= webrtc::CreatePeerConnectionFactory(
474 worker_thread_wrapper_
, signaling_thread_wrapper_
, nullptr, nullptr,
477 if (!peer_conn_factory_
.get()) {
478 CleanupPeerConnection();
482 VLOG(1) << "Created PeerConnectionFactory successfully.";
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
;
491 // 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
493 // connection to fail to connect.
494 // Note: For protection and unprotection of SRTP packets, the libjingle
495 // ENABLE_EXTERNAL_AUTH flag must not be set.
496 webrtc::FakeConstraints constraints
;
497 constraints
.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp
,
498 webrtc::MediaConstraintsInterface::kValueTrue
);
500 rtc::scoped_refptr
<webrtc::PortAllocatorFactoryInterface
>
501 port_allocator_factory
= ChromiumPortAllocatorFactory::Create(
502 network_settings_
, url_request_context_getter_
);
504 peer_connection_
= peer_conn_factory_
->CreatePeerConnection(
505 rtc_config
, &constraints
, port_allocator_factory
, nullptr, this);
507 if (!peer_connection_
.get()) {
508 CleanupPeerConnection();
512 VLOG(1) << "Created PeerConnection successfully.";
514 create_session_desc_observer_
=
515 CastCreateSessionDescriptionObserver::Create(this);
517 // Send a test message to the client. Then, notify the client to start
518 // webrtc offer/answer negotiation.
519 if (!SendMessageToClient(kSubjectTest
, "Hello, client.") ||
520 !SendMessageToClient(kSubjectReady
, "Host ready to receive offers.")) {
521 LOG(ERROR
) << "Failed to send messages to client.";
528 bool CastExtensionSession::SetupVideoStream(
529 scoped_ptr
<webrtc::DesktopCapturer
> desktop_capturer
) {
530 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
531 DCHECK(desktop_capturer
);
534 VLOG(1) << "Already added MediaStream. Aborting Setup.";
538 scoped_ptr
<CastVideoCapturerAdapter
> cast_video_capturer_adapter(
539 new CastVideoCapturerAdapter(desktop_capturer
.Pass()));
541 // Set video stream constraints.
542 webrtc::FakeConstraints video_constraints
;
543 video_constraints
.AddMandatory(
544 webrtc::MediaConstraintsInterface::kMinFrameRate
, kMinFramesPerSecond
);
546 rtc::scoped_refptr
<webrtc::VideoTrackInterface
> video_track
=
547 peer_conn_factory_
->CreateVideoTrack(
549 peer_conn_factory_
->CreateVideoSource(
550 cast_video_capturer_adapter
.release(), &video_constraints
));
552 stream_
= peer_conn_factory_
->CreateLocalMediaStream(kStreamLabel
);
554 if (!stream_
->AddTrack(video_track
) ||
555 !peer_connection_
->AddStream(stream_
)) {
559 VLOG(1) << "Setup video stream successfully.";
564 void CastExtensionSession::PollPeerConnectionStats() {
565 if (!connection_active()) {
566 VLOG(1) << "Cannot poll stats while PeerConnection is inactive.";
568 rtc::scoped_refptr
<webrtc::MediaStreamTrackInterface
> video_track
=
569 stream_
->FindVideoTrack(kVideoLabel
);
570 peer_connection_
->GetStats(
571 stats_observer_
, video_track
.release(),
572 webrtc::PeerConnectionInterface::kStatsOutputLevelStandard
);
575 void CastExtensionSession::CleanupPeerConnection() {
576 peer_connection_
->Close();
577 peer_connection_
= nullptr;
579 peer_conn_factory_
= nullptr;
580 worker_thread_
.Stop();
583 bool CastExtensionSession::connection_active() const {
584 return peer_connection_
.get() != nullptr;
587 // webrtc::PeerConnectionObserver implementation -------------------------------
588 void CastExtensionSession::OnSignalingChange(
589 webrtc::PeerConnectionInterface::SignalingState new_state
) {
590 VLOG(1) << "PeerConnectionObserver: SignalingState changed to:" << new_state
;
593 void CastExtensionSession::OnStateChange(
594 webrtc::PeerConnectionObserver::StateType state_changed
) {
595 VLOG(1) << "PeerConnectionObserver: StateType changed to: " << state_changed
;
598 void CastExtensionSession::OnAddStream(webrtc::MediaStreamInterface
* stream
) {
599 VLOG(1) << "PeerConnectionObserver: stream added: " << stream
->label();
602 void CastExtensionSession::OnRemoveStream(
603 webrtc::MediaStreamInterface
* stream
) {
604 VLOG(1) << "PeerConnectionObserver: stream removed: " << stream
->label();
607 void CastExtensionSession::OnDataChannel(
608 webrtc::DataChannelInterface
* data_channel
) {
609 VLOG(1) << "PeerConnectionObserver: data channel: " << data_channel
->label();
612 void CastExtensionSession::OnRenegotiationNeeded() {
613 VLOG(1) << "PeerConnectionObserver: renegotiation needed.";
616 void CastExtensionSession::OnIceConnectionChange(
617 webrtc::PeerConnectionInterface::IceConnectionState new_state
) {
618 VLOG(1) << "PeerConnectionObserver: IceConnectionState changed to: "
621 // TODO(aiguha): Maybe start timer only if enabled by command-line flag or
622 // at a particular verbosity level.
623 if (!stats_polling_timer_
.IsRunning() &&
624 new_state
== webrtc::PeerConnectionInterface::kIceConnectionConnected
) {
625 stats_polling_timer_
.Start(
627 base::TimeDelta::FromSeconds(kStatsLogIntervalSec
),
629 &CastExtensionSession::PollPeerConnectionStats
);
633 void CastExtensionSession::OnIceGatheringChange(
634 webrtc::PeerConnectionInterface::IceGatheringState new_state
) {
635 VLOG(1) << "PeerConnectionObserver: IceGatheringState changed to: "
639 void CastExtensionSession::OnIceComplete() {
640 VLOG(1) << "PeerConnectionObserver: all ICE candidates found.";
643 void CastExtensionSession::OnIceCandidate(
644 const webrtc::IceCandidateInterface
* candidate
) {
645 std::string candidate_str
;
646 if (!candidate
->ToString(&candidate_str
)) {
647 LOG(ERROR
) << "PeerConnectionObserver: failed to serialize candidate.";
650 base::DictionaryValue json
;
651 json
.SetString(kWebRtcSDPMid
, candidate
->sdp_mid());
652 json
.SetInteger(kWebRtcSDPMLineIndex
, candidate
->sdp_mline_index());
653 json
.SetString(kWebRtcCandidate
, candidate_str
);
654 std::string json_str
;
655 if (!base::JSONWriter::Write(json
, &json_str
)) {
656 LOG(ERROR
) << "Failed to serialize candidate message.";
659 SendMessageToClient(kSubjectNewCandidate
, json_str
);
662 } // namespace remoting