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
->display_name() << "=" << v
->value
<< ".";
150 CastStatsObserver() {}
151 ~CastStatsObserver() override
{}
153 DISALLOW_COPY_AND_ASSIGN(CastStatsObserver
);
156 // TODO(aiguha): Fix PeerConnnection-related tear down crash caused by premature
157 // destruction of cricket::CaptureManager (which occurs on releasing
158 // |peer_conn_factory_|). See crbug.com/403840.
159 CastExtensionSession::~CastExtensionSession() {
160 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
162 // Explicitly clear |create_session_desc_observer_|'s pointer to |this|,
163 // since the CastExtensionSession is destructing. Otherwise,
164 // |create_session_desc_observer_| would be left with a dangling pointer.
165 create_session_desc_observer_
->SetCastExtensionSession(nullptr);
167 CleanupPeerConnection();
171 scoped_ptr
<CastExtensionSession
> CastExtensionSession::Create(
172 scoped_refptr
<base::SingleThreadTaskRunner
> caller_task_runner
,
173 scoped_refptr
<net::URLRequestContextGetter
> url_request_context_getter
,
174 const protocol::NetworkSettings
& network_settings
,
175 ClientSessionControl
* client_session_control
,
176 protocol::ClientStub
* client_stub
) {
177 scoped_ptr
<CastExtensionSession
> cast_extension_session(
178 new CastExtensionSession(caller_task_runner
,
179 url_request_context_getter
,
181 client_session_control
,
183 if (!cast_extension_session
->WrapTasksAndSave() ||
184 !cast_extension_session
->InitializePeerConnection()) {
187 return cast_extension_session
.Pass();
190 void CastExtensionSession::OnCreateSessionDescription(
191 webrtc::SessionDescriptionInterface
* desc
) {
192 if (!caller_task_runner_
->BelongsToCurrentThread()) {
193 caller_task_runner_
->PostTask(
195 base::Bind(&CastExtensionSession::OnCreateSessionDescription
,
196 base::Unretained(this),
201 peer_connection_
->SetLocalDescription(
202 CastSetSessionDescriptionObserver::Create(), desc
);
204 scoped_ptr
<base::DictionaryValue
> json(new base::DictionaryValue());
205 json
->SetString(kWebRtcSessionDescType
, desc
->type());
206 std::string subject
=
207 (desc
->type() == "offer") ? kSubjectOffer
: kSubjectAnswer
;
208 std::string desc_str
;
209 desc
->ToString(&desc_str
);
210 json
->SetString(kWebRtcSessionDescSDP
, desc_str
);
211 std::string json_str
;
212 if (!base::JSONWriter::Write(json
.get(), &json_str
)) {
213 LOG(ERROR
) << "Failed to serialize sdp message.";
217 SendMessageToClient(subject
.c_str(), json_str
);
220 void CastExtensionSession::OnCreateSessionDescriptionFailure(
221 const std::string
& error
) {
222 VLOG(1) << "Creating Session Description failed: " << error
;
225 // TODO(aiguha): Support the case(s) where we've grabbed the capturer already,
226 // but another extension reset the video pipeline. We should remove the
227 // stream from the peer connection here, and then attempt to re-setup the
228 // peer connection in the OnRenegotiationNeeded() callback.
229 // See crbug.com/403843.
230 void CastExtensionSession::OnCreateVideoCapturer(
231 scoped_ptr
<webrtc::DesktopCapturer
>* capturer
) {
232 if (has_grabbed_capturer_
) {
233 LOG(ERROR
) << "The video pipeline was reset unexpectedly.";
234 has_grabbed_capturer_
= false;
235 peer_connection_
->RemoveStream(stream_
.release());
239 if (received_offer_
) {
240 has_grabbed_capturer_
= true;
241 if (SetupVideoStream(capturer
->Pass())) {
242 peer_connection_
->CreateAnswer(create_session_desc_observer_
, nullptr);
244 has_grabbed_capturer_
= false;
245 // Ignore the received offer, since we failed to setup a video stream.
246 received_offer_
= false;
252 bool CastExtensionSession::ModifiesVideoPipeline() const {
256 // Returns true if the |message| is a Cast ExtensionMessage, even if
257 // it was badly formed or a resulting action failed. This is done so that
258 // the host does not continue to attempt to pass |message| to other
259 // HostExtensionSessions.
260 bool CastExtensionSession::OnExtensionMessage(
261 ClientSessionControl
* client_session_control
,
262 protocol::ClientStub
* client_stub
,
263 const protocol::ExtensionMessage
& message
) {
264 if (message
.type() != kExtensionMessageType
) {
268 scoped_ptr
<base::Value
> value(base::JSONReader::Read(message
.data()));
269 base::DictionaryValue
* client_message
;
270 if (!(value
&& value
->GetAsDictionary(&client_message
))) {
271 LOG(ERROR
) << "Could not read cast extension message.";
276 if (!client_message
->GetString(kTopLevelSubject
, &subject
)) {
277 LOG(ERROR
) << "Invalid Cast Extension Message (missing subject header).";
281 if (subject
== kSubjectOffer
&& !received_offer_
) {
282 // Reset the video pipeline so we can grab the screen capturer and setup
284 if (ParseAndSetRemoteDescription(client_message
)) {
285 received_offer_
= true;
286 LOG(INFO
) << "About to ResetVideoPipeline.";
287 client_session_control_
->ResetVideoPipeline();
290 } else if (subject
== kSubjectAnswer
) {
291 ParseAndSetRemoteDescription(client_message
);
292 } else if (subject
== kSubjectNewCandidate
) {
293 ParseAndAddICECandidate(client_message
);
295 VLOG(1) << "Unexpected CastExtension Message: " << message
.data();
300 // Private methods ------------------------------------------------------------
302 CastExtensionSession::CastExtensionSession(
303 scoped_refptr
<base::SingleThreadTaskRunner
> caller_task_runner
,
304 scoped_refptr
<net::URLRequestContextGetter
> url_request_context_getter
,
305 const protocol::NetworkSettings
& network_settings
,
306 ClientSessionControl
* client_session_control
,
307 protocol::ClientStub
* client_stub
)
308 : caller_task_runner_(caller_task_runner
),
309 url_request_context_getter_(url_request_context_getter
),
310 network_settings_(network_settings
),
311 client_session_control_(client_session_control
),
312 client_stub_(client_stub
),
313 stats_observer_(CastStatsObserver::Create()),
314 received_offer_(false),
315 has_grabbed_capturer_(false),
316 signaling_thread_wrapper_(nullptr),
317 worker_thread_wrapper_(nullptr),
318 worker_thread_(kWorkerThreadName
) {
319 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
320 DCHECK(url_request_context_getter_
.get());
321 DCHECK(client_session_control_
);
322 DCHECK(client_stub_
);
324 // The worker thread is created with base::MessageLoop::TYPE_IO because
325 // the PeerConnection performs some port allocation operations on this thread
326 // that require it. See crbug.com/404013.
327 base::Thread::Options
options(base::MessageLoop::TYPE_IO
, 0);
328 worker_thread_
.StartWithOptions(options
);
329 worker_task_runner_
= worker_thread_
.task_runner();
332 bool CastExtensionSession::ParseAndSetRemoteDescription(
333 base::DictionaryValue
* message
) {
334 DCHECK(peer_connection_
.get() != nullptr);
336 base::DictionaryValue
* message_data
;
337 if (!message
->GetDictionary(kTopLevelData
, &message_data
)) {
338 LOG(ERROR
) << "Invalid Cast Extension Message (missing data).";
342 std::string webrtc_type
;
343 if (!message_data
->GetString(kWebRtcSessionDescType
, &webrtc_type
)) {
345 << "Invalid Cast Extension Message (missing webrtc type header).";
350 if (!message_data
->GetString(kWebRtcSessionDescSDP
, &sdp
)) {
351 LOG(ERROR
) << "Invalid Cast Extension Message (missing webrtc sdp header).";
355 webrtc::SdpParseError error
;
356 webrtc::SessionDescriptionInterface
* session_description(
357 webrtc::CreateSessionDescription(webrtc_type
, sdp
, &error
));
359 if (!session_description
) {
360 LOG(ERROR
) << "Invalid Cast Extension Message (could not parse sdp).";
361 VLOG(1) << "SdpParseError was: " << error
.description
;
365 peer_connection_
->SetRemoteDescription(
366 CastSetSessionDescriptionObserver::Create(), session_description
);
370 bool CastExtensionSession::ParseAndAddICECandidate(
371 base::DictionaryValue
* message
) {
372 DCHECK(peer_connection_
.get() != nullptr);
374 base::DictionaryValue
* message_data
;
375 if (!message
->GetDictionary(kTopLevelData
, &message_data
)) {
376 LOG(ERROR
) << "Invalid Cast Extension Message (missing data).";
380 std::string candidate_str
;
382 int sdp_mlineindex
= 0;
383 if (!message_data
->GetString(kWebRtcSDPMid
, &sdp_mid
) ||
384 !message_data
->GetInteger(kWebRtcSDPMLineIndex
, &sdp_mlineindex
) ||
385 !message_data
->GetString(kWebRtcCandidate
, &candidate_str
)) {
386 LOG(ERROR
) << "Invalid Cast Extension Message (could not parse).";
390 rtc::scoped_ptr
<webrtc::IceCandidateInterface
> candidate(
391 webrtc::CreateIceCandidate(sdp_mid
, sdp_mlineindex
, candidate_str
));
392 if (!candidate
.get()) {
394 << "Invalid Cast Extension Message (could not create candidate).";
398 if (!peer_connection_
->AddIceCandidate(candidate
.get())) {
399 LOG(ERROR
) << "Failed to apply received ICE Candidate to PeerConnection.";
403 VLOG(1) << "Received and Added ICE Candidate: " << candidate_str
;
408 bool CastExtensionSession::SendMessageToClient(const std::string
& subject
,
409 const std::string
& data
) {
410 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
412 if (client_stub_
== nullptr) {
413 LOG(ERROR
) << "No Client Stub. Cannot send message to client.";
417 base::DictionaryValue message_dict
;
418 message_dict
.SetString(kTopLevelSubject
, subject
);
419 message_dict
.SetString(kTopLevelData
, data
);
420 std::string message_json
;
422 if (!base::JSONWriter::Write(&message_dict
, &message_json
)) {
423 LOG(ERROR
) << "Failed to serialize JSON message.";
427 protocol::ExtensionMessage message
;
428 message
.set_type(kExtensionMessageType
);
429 message
.set_data(message_json
);
430 client_stub_
->DeliverHostMessage(message
);
434 void CastExtensionSession::EnsureTaskAndSetSend(rtc::Thread
** ptr
,
435 base::WaitableEvent
* event
) {
436 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
437 jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true);
438 *ptr
= jingle_glue::JingleThreadWrapper::current();
440 if (event
!= nullptr) {
445 bool CastExtensionSession::WrapTasksAndSave() {
446 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
448 EnsureTaskAndSetSend(&signaling_thread_wrapper_
);
449 if (signaling_thread_wrapper_
== nullptr)
452 base::WaitableEvent
wrap_worker_thread_event(true, false);
453 worker_task_runner_
->PostTask(
455 base::Bind(&CastExtensionSession::EnsureTaskAndSetSend
,
456 base::Unretained(this),
457 &worker_thread_wrapper_
,
458 &wrap_worker_thread_event
));
459 wrap_worker_thread_event
.Wait();
461 return (worker_thread_wrapper_
!= nullptr);
464 bool CastExtensionSession::InitializePeerConnection() {
465 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
466 DCHECK(!peer_conn_factory_
);
467 DCHECK(!peer_connection_
);
468 DCHECK(worker_thread_wrapper_
!= nullptr);
469 DCHECK(signaling_thread_wrapper_
!= nullptr);
471 peer_conn_factory_
= webrtc::CreatePeerConnectionFactory(
472 worker_thread_wrapper_
, signaling_thread_wrapper_
, nullptr, nullptr,
475 if (!peer_conn_factory_
.get()) {
476 CleanupPeerConnection();
480 VLOG(1) << "Created PeerConnectionFactory successfully.";
482 webrtc::PeerConnectionInterface::IceServers servers
;
483 webrtc::PeerConnectionInterface::IceServer server
;
484 server
.uri
= kDefaultStunURI
;
485 servers
.push_back(server
);
486 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config
;
487 rtc_config
.servers
= servers
;
489 // DTLS-SRTP is the preferred encryption method. If set to kValueFalse, the
490 // peer connection uses SDES. Disabling SDES as well will cause the peer
491 // connection to fail to connect.
492 // Note: For protection and unprotection of SRTP packets, the libjingle
493 // ENABLE_EXTERNAL_AUTH flag must not be set.
494 webrtc::FakeConstraints constraints
;
495 constraints
.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp
,
496 webrtc::MediaConstraintsInterface::kValueTrue
);
498 rtc::scoped_refptr
<webrtc::PortAllocatorFactoryInterface
>
499 port_allocator_factory
= ChromiumPortAllocatorFactory::Create(
500 network_settings_
, url_request_context_getter_
);
502 peer_connection_
= peer_conn_factory_
->CreatePeerConnection(
503 rtc_config
, &constraints
, port_allocator_factory
, nullptr, this);
505 if (!peer_connection_
.get()) {
506 CleanupPeerConnection();
510 VLOG(1) << "Created PeerConnection successfully.";
512 create_session_desc_observer_
=
513 CastCreateSessionDescriptionObserver::Create(this);
515 // Send a test message to the client. Then, notify the client to start
516 // webrtc offer/answer negotiation.
517 if (!SendMessageToClient(kSubjectTest
, "Hello, client.") ||
518 !SendMessageToClient(kSubjectReady
, "Host ready to receive offers.")) {
519 LOG(ERROR
) << "Failed to send messages to client.";
526 bool CastExtensionSession::SetupVideoStream(
527 scoped_ptr
<webrtc::DesktopCapturer
> desktop_capturer
) {
528 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
529 DCHECK(desktop_capturer
);
532 VLOG(1) << "Already added MediaStream. Aborting Setup.";
536 scoped_ptr
<CastVideoCapturerAdapter
> cast_video_capturer_adapter(
537 new CastVideoCapturerAdapter(desktop_capturer
.Pass()));
539 // Set video stream constraints.
540 webrtc::FakeConstraints video_constraints
;
541 video_constraints
.AddMandatory(
542 webrtc::MediaConstraintsInterface::kMinFrameRate
, kMinFramesPerSecond
);
544 rtc::scoped_refptr
<webrtc::VideoTrackInterface
> video_track
=
545 peer_conn_factory_
->CreateVideoTrack(
547 peer_conn_factory_
->CreateVideoSource(
548 cast_video_capturer_adapter
.release(), &video_constraints
));
550 stream_
= peer_conn_factory_
->CreateLocalMediaStream(kStreamLabel
);
552 if (!stream_
->AddTrack(video_track
) ||
553 !peer_connection_
->AddStream(stream_
)) {
557 VLOG(1) << "Setup video stream successfully.";
562 void CastExtensionSession::PollPeerConnectionStats() {
563 if (!connection_active()) {
564 VLOG(1) << "Cannot poll stats while PeerConnection is inactive.";
566 rtc::scoped_refptr
<webrtc::MediaStreamTrackInterface
> video_track
=
567 stream_
->FindVideoTrack(kVideoLabel
);
568 peer_connection_
->GetStats(
570 video_track
.release(),
571 webrtc::PeerConnectionInterface::kStatsOutputLevelStandard
);
574 void CastExtensionSession::CleanupPeerConnection() {
575 peer_connection_
->Close();
576 peer_connection_
= nullptr;
578 peer_conn_factory_
= nullptr;
579 worker_thread_
.Stop();
582 bool CastExtensionSession::connection_active() const {
583 return peer_connection_
.get() != nullptr;
586 // webrtc::PeerConnectionObserver implementation -------------------------------
587 void CastExtensionSession::OnSignalingChange(
588 webrtc::PeerConnectionInterface::SignalingState new_state
) {
589 VLOG(1) << "PeerConnectionObserver: SignalingState changed to:" << new_state
;
592 void CastExtensionSession::OnStateChange(
593 webrtc::PeerConnectionObserver::StateType state_changed
) {
594 VLOG(1) << "PeerConnectionObserver: StateType changed to: " << state_changed
;
597 void CastExtensionSession::OnAddStream(webrtc::MediaStreamInterface
* stream
) {
598 VLOG(1) << "PeerConnectionObserver: stream added: " << stream
->label();
601 void CastExtensionSession::OnRemoveStream(
602 webrtc::MediaStreamInterface
* stream
) {
603 VLOG(1) << "PeerConnectionObserver: stream removed: " << stream
->label();
606 void CastExtensionSession::OnDataChannel(
607 webrtc::DataChannelInterface
* data_channel
) {
608 VLOG(1) << "PeerConnectionObserver: data channel: " << data_channel
->label();
611 void CastExtensionSession::OnRenegotiationNeeded() {
612 VLOG(1) << "PeerConnectionObserver: renegotiation needed.";
615 void CastExtensionSession::OnIceConnectionChange(
616 webrtc::PeerConnectionInterface::IceConnectionState new_state
) {
617 VLOG(1) << "PeerConnectionObserver: IceConnectionState changed to: "
620 // TODO(aiguha): Maybe start timer only if enabled by command-line flag or
621 // at a particular verbosity level.
622 if (!stats_polling_timer_
.IsRunning() &&
623 new_state
== webrtc::PeerConnectionInterface::kIceConnectionConnected
) {
624 stats_polling_timer_
.Start(
626 base::TimeDelta::FromSeconds(kStatsLogIntervalSec
),
628 &CastExtensionSession::PollPeerConnectionStats
);
632 void CastExtensionSession::OnIceGatheringChange(
633 webrtc::PeerConnectionInterface::IceGatheringState new_state
) {
634 VLOG(1) << "PeerConnectionObserver: IceGatheringState changed to: "
638 void CastExtensionSession::OnIceComplete() {
639 VLOG(1) << "PeerConnectionObserver: all ICE candidates found.";
642 void CastExtensionSession::OnIceCandidate(
643 const webrtc::IceCandidateInterface
* candidate
) {
644 std::string candidate_str
;
645 if (!candidate
->ToString(&candidate_str
)) {
646 LOG(ERROR
) << "PeerConnectionObserver: failed to serialize candidate.";
649 scoped_ptr
<base::DictionaryValue
> json(new base::DictionaryValue());
650 json
->SetString(kWebRtcSDPMid
, candidate
->sdp_mid());
651 json
->SetInteger(kWebRtcSDPMLineIndex
, candidate
->sdp_mline_index());
652 json
->SetString(kWebRtcCandidate
, candidate_str
);
653 std::string json_str
;
654 if (!base::JSONWriter::Write(json
.get(), &json_str
)) {
655 LOG(ERROR
) << "Failed to serialize candidate message.";
658 SendMessageToClient(kSubjectNewCandidate
, json_str
);
661 } // namespace remoting