blob: 838ad93af1920689240a6b7cae7eadb42fca27b1 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "talk/app/webrtc/webrtcsession.h"
29
pbos@webrtc.org371243d2014-03-07 15:22:04 +000030#include <limits.h>
31
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032#include <algorithm>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033#include <vector>
34
35#include "talk/app/webrtc/jsepicecandidate.h"
36#include "talk/app/webrtc/jsepsessiondescription.h"
37#include "talk/app/webrtc/mediaconstraintsinterface.h"
38#include "talk/app/webrtc/mediastreamsignaling.h"
39#include "talk/app/webrtc/peerconnectioninterface.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000040#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000041#include "talk/media/base/constants.h"
42#include "talk/media/base/videocapturer.h"
43#include "talk/session/media/channel.h"
44#include "talk/session/media/channelmanager.h"
45#include "talk/session/media/mediasession.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000046#include "webrtc/base/basictypes.h"
jbauchac8869e2015-07-03 01:36:14 -070047#include "webrtc/base/checks.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000048#include "webrtc/base/helpers.h"
49#include "webrtc/base/logging.h"
50#include "webrtc/base/stringencode.h"
51#include "webrtc/base/stringutils.h"
pthatcher@webrtc.org40b276e2014-12-12 02:44:30 +000052#include "webrtc/p2p/base/portallocator.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053
54using cricket::ContentInfo;
55using cricket::ContentInfos;
56using cricket::MediaContentDescription;
57using cricket::SessionDescription;
58using cricket::TransportInfo;
59
Guo-wei Shieh3d564c12015-08-19 16:51:15 -070060using cricket::LOCAL_PORT_TYPE;
61using cricket::STUN_PORT_TYPE;
62using cricket::RELAY_PORT_TYPE;
63using cricket::PRFLX_PORT_TYPE;
64
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065namespace webrtc {
66
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067// Error messages
henrike@webrtc.org1e09a712013-07-26 19:17:59 +000068const char kBundleWithoutRtcpMux[] = "RTCP-MUX must be enabled when BUNDLE "
69 "is enabled.";
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000070const char kCreateChannelFailed[] = "Failed to create channels.";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071const char kInvalidCandidates[] = "Description contains invalid candidates.";
72const char kInvalidSdp[] = "Invalid session description.";
73const char kMlineMismatch[] =
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000074 "Offer and answer descriptions m-lines are not matching. Rejecting answer.";
75const char kPushDownTDFailed[] =
76 "Failed to push down transport description:";
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000077const char kSdpWithoutDtlsFingerprint[] =
78 "Called with SDP without DTLS fingerprint.";
79const char kSdpWithoutSdesCrypto[] =
80 "Called with SDP without SDES crypto.";
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000081const char kSdpWithoutIceUfragPwd[] =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000082 "Called with SDP without ice-ufrag and ice-pwd.";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083const char kSessionError[] = "Session error code: ";
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000084const char kSessionErrorDesc[] = "Session error description: ";
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +000085const char kDtlsSetupFailureRtp[] =
86 "Couldn't set up DTLS-SRTP on RTP channel.";
87const char kDtlsSetupFailureRtcp[] =
88 "Couldn't set up DTLS-SRTP on RTCP channel.";
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000089const int kMaxUnsignalledRecvStreams = 20;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090
Guo-wei Shieh3d564c12015-08-19 16:51:15 -070091IceCandidatePairType GetIceCandidatePairCounter(
92 const cricket::Candidate& local,
93 const cricket::Candidate& remote) {
94 const auto& l = local.type();
95 const auto& r = remote.type();
96 const auto& host = LOCAL_PORT_TYPE;
97 const auto& srflx = STUN_PORT_TYPE;
98 const auto& relay = RELAY_PORT_TYPE;
99 const auto& prflx = PRFLX_PORT_TYPE;
100 if (l == host && r == host)
101 return kIceCandidatePairHostHost;
102 if (l == host && r == srflx)
103 return kIceCandidatePairHostSrflx;
104 if (l == host && r == relay)
105 return kIceCandidatePairHostRelay;
106 if (l == host && r == prflx)
107 return kIceCandidatePairHostPrflx;
108 if (l == srflx && r == host)
109 return kIceCandidatePairSrflxHost;
110 if (l == srflx && r == srflx)
111 return kIceCandidatePairSrflxSrflx;
112 if (l == srflx && r == relay)
113 return kIceCandidatePairSrflxRelay;
114 if (l == srflx && r == prflx)
115 return kIceCandidatePairSrflxPrflx;
116 if (l == relay && r == host)
117 return kIceCandidatePairRelayHost;
118 if (l == relay && r == srflx)
119 return kIceCandidatePairRelaySrflx;
120 if (l == relay && r == relay)
121 return kIceCandidatePairRelayRelay;
122 if (l == relay && r == prflx)
123 return kIceCandidatePairRelayPrflx;
124 if (l == prflx && r == host)
125 return kIceCandidatePairPrflxHost;
126 if (l == prflx && r == srflx)
127 return kIceCandidatePairPrflxSrflx;
128 if (l == prflx && r == relay)
129 return kIceCandidatePairPrflxRelay;
130 return kIceCandidatePairMax;
131}
132
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133// Compares |answer| against |offer|. Comparision is done
134// for number of m-lines in answer against offer. If matches true will be
135// returned otherwise false.
136static bool VerifyMediaDescriptions(
137 const SessionDescription* answer, const SessionDescription* offer) {
138 if (offer->contents().size() != answer->contents().size())
139 return false;
140
141 for (size_t i = 0; i < offer->contents().size(); ++i) {
142 if ((offer->contents()[i].name) != answer->contents()[i].name) {
143 return false;
144 }
wu@webrtc.org4e393072014-04-07 17:04:35 +0000145 const MediaContentDescription* offer_mdesc =
146 static_cast<const MediaContentDescription*>(
147 offer->contents()[i].description);
148 const MediaContentDescription* answer_mdesc =
149 static_cast<const MediaContentDescription*>(
150 answer->contents()[i].description);
151 if (offer_mdesc->type() != answer_mdesc->type()) {
152 return false;
153 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154 }
155 return true;
156}
157
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000158// Checks that each non-rejected content has SDES crypto keys or a DTLS
159// fingerprint. Mismatches, such as replying with a DTLS fingerprint to SDES
160// keys, will be caught in Transport negotiation, and backstopped by Channel's
161// |secure_required| check.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000162static bool VerifyCrypto(const SessionDescription* desc,
163 bool dtls_enabled,
164 std::string* error) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 const ContentInfos& contents = desc->contents();
166 for (size_t index = 0; index < contents.size(); ++index) {
167 const ContentInfo* cinfo = &contents[index];
168 if (cinfo->rejected) {
169 continue;
170 }
171
172 // If the content isn't rejected, crypto must be present.
173 const MediaContentDescription* media =
174 static_cast<const MediaContentDescription*>(cinfo->description);
175 const TransportInfo* tinfo = desc->GetTransportInfoByName(cinfo->name);
176 if (!media || !tinfo) {
177 // Something is not right.
178 LOG(LS_ERROR) << kInvalidSdp;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000179 *error = kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180 return false;
181 }
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000182 if (dtls_enabled) {
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000183 if (!tinfo->description.identity_fingerprint) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000184 LOG(LS_WARNING) <<
185 "Session description must have DTLS fingerprint if DTLS enabled.";
186 *error = kSdpWithoutDtlsFingerprint;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000187 return false;
188 }
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000189 } else {
190 if (media->cryptos().empty()) {
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000191 LOG(LS_WARNING) <<
192 "Session description must have SDES when DTLS disabled.";
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000193 *error = kSdpWithoutSdesCrypto;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000194 return false;
195 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 }
197 }
198
199 return true;
200}
201
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000202// Checks that each non-rejected content has ice-ufrag and ice-pwd set.
203static bool VerifyIceUfragPwdPresent(const SessionDescription* desc) {
204 const ContentInfos& contents = desc->contents();
205 for (size_t index = 0; index < contents.size(); ++index) {
206 const ContentInfo* cinfo = &contents[index];
207 if (cinfo->rejected) {
208 continue;
209 }
210
211 // If the content isn't rejected, ice-ufrag and ice-pwd must be present.
212 const TransportInfo* tinfo = desc->GetTransportInfoByName(cinfo->name);
213 if (!tinfo) {
214 // Something is not right.
215 LOG(LS_ERROR) << kInvalidSdp;
216 return false;
217 }
218 if (tinfo->description.ice_ufrag.empty() ||
219 tinfo->description.ice_pwd.empty()) {
220 LOG(LS_ERROR) << "Session description must have ice ufrag and pwd.";
221 return false;
222 }
223 }
224 return true;
225}
226
wu@webrtc.org91053e72013-08-10 07:18:04 +0000227// Forces |sdesc->crypto_required| to the appropriate state based on the
228// current security policy, to ensure a failure occurs if there is an error
229// in crypto negotiation.
230// Called when processing the local session description.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000231static void UpdateSessionDescriptionSecurePolicy(cricket::CryptoType type,
232 SessionDescription* sdesc) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000233 if (!sdesc) {
234 return;
235 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236
wu@webrtc.org91053e72013-08-10 07:18:04 +0000237 // Updating the |crypto_required_| in MediaContentDescription to the
238 // appropriate state based on the current security policy.
239 for (cricket::ContentInfos::iterator iter = sdesc->contents().begin();
240 iter != sdesc->contents().end(); ++iter) {
241 if (cricket::IsMediaContent(&*iter)) {
242 MediaContentDescription* mdesc =
243 static_cast<MediaContentDescription*> (iter->description);
244 if (mdesc) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000245 mdesc->set_crypto_required(type);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000246 }
247 }
248 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249}
250
251static bool GetAudioSsrcByTrackId(
252 const SessionDescription* session_description,
253 const std::string& track_id, uint32 *ssrc) {
254 const cricket::ContentInfo* audio_info =
255 cricket::GetFirstAudioContent(session_description);
256 if (!audio_info) {
257 LOG(LS_ERROR) << "Audio not used in this call";
258 return false;
259 }
260
261 const cricket::MediaContentDescription* audio_content =
262 static_cast<const cricket::MediaContentDescription*>(
263 audio_info->description);
tommi@webrtc.org586f2ed2015-01-22 23:00:41 +0000264 const cricket::StreamParams* stream =
265 cricket::GetStreamByIds(audio_content->streams(), "", track_id);
266 if (!stream) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267 return false;
268 }
tommi@webrtc.org586f2ed2015-01-22 23:00:41 +0000269
270 *ssrc = stream->first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 return true;
272}
273
274static bool GetTrackIdBySsrc(const SessionDescription* session_description,
275 uint32 ssrc, std::string* track_id) {
276 ASSERT(track_id != NULL);
277
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000278 const cricket::ContentInfo* audio_info =
279 cricket::GetFirstAudioContent(session_description);
jiayl@webrtc.orge21cc9a2014-08-28 22:21:34 +0000280 if (audio_info) {
281 const cricket::MediaContentDescription* audio_content =
282 static_cast<const cricket::MediaContentDescription*>(
283 audio_info->description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284
tommi@webrtc.org586f2ed2015-01-22 23:00:41 +0000285 const auto* found =
286 cricket::GetStreamBySsrc(audio_content->streams(), ssrc);
287 if (found) {
288 *track_id = found->id;
jiayl@webrtc.orge21cc9a2014-08-28 22:21:34 +0000289 return true;
290 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000291 }
292
293 const cricket::ContentInfo* video_info =
294 cricket::GetFirstVideoContent(session_description);
jiayl@webrtc.orge21cc9a2014-08-28 22:21:34 +0000295 if (video_info) {
296 const cricket::MediaContentDescription* video_content =
297 static_cast<const cricket::MediaContentDescription*>(
298 video_info->description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299
tommi@webrtc.org586f2ed2015-01-22 23:00:41 +0000300 const auto* found =
301 cricket::GetStreamBySsrc(video_content->streams(), ssrc);
302 if (found) {
303 *track_id = found->id;
jiayl@webrtc.orge21cc9a2014-08-28 22:21:34 +0000304 return true;
305 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306 }
307 return false;
308}
309
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000310static bool BadSdp(const std::string& source,
311 const std::string& type,
312 const std::string& reason,
313 std::string* err_desc) {
314 std::ostringstream desc;
315 desc << "Failed to set " << source << " " << type << " sdp: " << reason;
316
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 if (err_desc) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000318 *err_desc = desc.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000320 LOG(LS_ERROR) << desc.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321 return false;
322}
323
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324static bool BadSdp(cricket::ContentSource source,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000325 const std::string& type,
326 const std::string& reason,
327 std::string* err_desc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328 if (source == cricket::CS_LOCAL) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000329 return BadSdp("local", type, reason, err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 } else {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000331 return BadSdp("remote", type, reason, err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 }
333}
334
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000335static bool BadLocalSdp(const std::string& type,
336 const std::string& reason,
337 std::string* err_desc) {
338 return BadSdp(cricket::CS_LOCAL, type, reason, err_desc);
339}
340
341static bool BadRemoteSdp(const std::string& type,
342 const std::string& reason,
343 std::string* err_desc) {
344 return BadSdp(cricket::CS_REMOTE, type, reason, err_desc);
345}
346
347static bool BadOfferSdp(cricket::ContentSource source,
348 const std::string& reason,
349 std::string* err_desc) {
350 return BadSdp(source, SessionDescriptionInterface::kOffer, reason, err_desc);
351}
352
353static bool BadPranswerSdp(cricket::ContentSource source,
354 const std::string& reason,
355 std::string* err_desc) {
356 return BadSdp(source, SessionDescriptionInterface::kPrAnswer,
357 reason, err_desc);
358}
359
360static bool BadAnswerSdp(cricket::ContentSource source,
361 const std::string& reason,
362 std::string* err_desc) {
363 return BadSdp(source, SessionDescriptionInterface::kAnswer, reason, err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364}
365
366#define GET_STRING_OF_STATE(state) \
367 case cricket::BaseSession::state: \
368 result = #state; \
369 break;
370
371static std::string GetStateString(cricket::BaseSession::State state) {
372 std::string result;
373 switch (state) {
374 GET_STRING_OF_STATE(STATE_INIT)
375 GET_STRING_OF_STATE(STATE_SENTINITIATE)
376 GET_STRING_OF_STATE(STATE_RECEIVEDINITIATE)
377 GET_STRING_OF_STATE(STATE_SENTPRACCEPT)
378 GET_STRING_OF_STATE(STATE_SENTACCEPT)
379 GET_STRING_OF_STATE(STATE_RECEIVEDPRACCEPT)
380 GET_STRING_OF_STATE(STATE_RECEIVEDACCEPT)
381 GET_STRING_OF_STATE(STATE_SENTMODIFY)
382 GET_STRING_OF_STATE(STATE_RECEIVEDMODIFY)
383 GET_STRING_OF_STATE(STATE_SENTREJECT)
384 GET_STRING_OF_STATE(STATE_RECEIVEDREJECT)
385 GET_STRING_OF_STATE(STATE_SENTREDIRECT)
386 GET_STRING_OF_STATE(STATE_SENTTERMINATE)
387 GET_STRING_OF_STATE(STATE_RECEIVEDTERMINATE)
388 GET_STRING_OF_STATE(STATE_INPROGRESS)
389 GET_STRING_OF_STATE(STATE_DEINIT)
390 default:
391 ASSERT(false);
392 break;
393 }
394 return result;
395}
396
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000397#define GET_STRING_OF_ERROR_CODE(err) \
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000398 case cricket::BaseSession::err: \
399 result = #err; \
400 break;
401
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000402static std::string GetErrorCodeString(cricket::BaseSession::Error err) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403 std::string result;
404 switch (err) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000405 GET_STRING_OF_ERROR_CODE(ERROR_NONE)
406 GET_STRING_OF_ERROR_CODE(ERROR_TIME)
407 GET_STRING_OF_ERROR_CODE(ERROR_RESPONSE)
408 GET_STRING_OF_ERROR_CODE(ERROR_NETWORK)
409 GET_STRING_OF_ERROR_CODE(ERROR_CONTENT)
410 GET_STRING_OF_ERROR_CODE(ERROR_TRANSPORT)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411 default:
412 ASSERT(false);
413 break;
414 }
415 return result;
416}
417
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000418static std::string MakeErrorString(const std::string& error,
419 const std::string& desc) {
420 std::ostringstream ret;
421 ret << error << " " << desc;
422 return ret.str();
423}
424
425static std::string MakeTdErrorString(const std::string& desc) {
426 return MakeErrorString(kPushDownTDFailed, desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000427}
428
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000429// Set |option| to the highest-priority value of |key| in the optional
430// constraints if the key is found and has a valid value.
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000431template<typename T>
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000432static void SetOptionFromOptionalConstraint(
433 const MediaConstraintsInterface* constraints,
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000434 const std::string& key, cricket::Settable<T>* option) {
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000435 if (!constraints) {
436 return;
437 }
438 std::string string_value;
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000439 T value;
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000440 if (constraints->GetOptional().FindFirst(key, &string_value)) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000441 if (rtc::FromString(string_value, &value)) {
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000442 option->Set(value);
443 }
444 }
445}
446
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000447uint32 ConvertIceTransportTypeToCandidateFilter(
448 PeerConnectionInterface::IceTransportsType type) {
449 switch (type) {
450 case PeerConnectionInterface::kNone:
451 return cricket::CF_NONE;
452 case PeerConnectionInterface::kRelay:
453 return cricket::CF_RELAY;
454 case PeerConnectionInterface::kNoHost:
455 return (cricket::CF_ALL & ~cricket::CF_HOST);
456 case PeerConnectionInterface::kAll:
457 return cricket::CF_ALL;
458 default: ASSERT(false);
459 }
460 return cricket::CF_NONE;
461}
462
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463// Help class used to remember if a a remote peer has requested ice restart by
464// by sending a description with new ice ufrag and password.
465class IceRestartAnswerLatch {
466 public:
467 IceRestartAnswerLatch() : ice_restart_(false) { }
468
wu@webrtc.org91053e72013-08-10 07:18:04 +0000469 // Returns true if CheckForRemoteIceRestart has been called with a new session
470 // description where ice password and ufrag has changed since last time
471 // Reset() was called.
472 bool Get() const {
473 return ice_restart_;
474 }
475
476 void Reset() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000477 if (ice_restart_) {
478 ice_restart_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000479 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480 }
481
honghaiz503726c2015-07-31 12:37:38 -0700482 bool CheckForRemoteIceRestart(const SessionDescriptionInterface* old_desc,
483 const SessionDescriptionInterface* new_desc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484 if (!old_desc || new_desc->type() != SessionDescriptionInterface::kOffer) {
honghaiz503726c2015-07-31 12:37:38 -0700485 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000486 }
487 const SessionDescription* new_sd = new_desc->description();
488 const SessionDescription* old_sd = old_desc->description();
489 const ContentInfos& contents = new_sd->contents();
490 for (size_t index = 0; index < contents.size(); ++index) {
491 const ContentInfo* cinfo = &contents[index];
492 if (cinfo->rejected) {
493 continue;
494 }
495 // If the content isn't rejected, check if ufrag and password has
496 // changed.
497 const cricket::TransportDescription* new_transport_desc =
498 new_sd->GetTransportDescriptionByName(cinfo->name);
499 const cricket::TransportDescription* old_transport_desc =
500 old_sd->GetTransportDescriptionByName(cinfo->name);
501 if (!new_transport_desc || !old_transport_desc) {
502 // No transport description exist. This is not an ice restart.
503 continue;
504 }
jiayl@webrtc.orgdb397e52014-06-20 16:32:09 +0000505 if (cricket::IceCredentialsChanged(old_transport_desc->ice_ufrag,
506 old_transport_desc->ice_pwd,
507 new_transport_desc->ice_ufrag,
508 new_transport_desc->ice_pwd)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000509 LOG(LS_INFO) << "Remote peer request ice restart.";
510 ice_restart_ = true;
honghaiz503726c2015-07-31 12:37:38 -0700511 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000512 }
513 }
honghaiz503726c2015-07-31 12:37:38 -0700514 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000515 }
516
517 private:
518 bool ice_restart_;
519};
520
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000521WebRtcSession::WebRtcSession(
522 cricket::ChannelManager* channel_manager,
523 rtc::Thread* signaling_thread,
524 rtc::Thread* worker_thread,
525 cricket::PortAllocator* port_allocator,
526 MediaStreamSignaling* mediastream_signaling)
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000527 : cricket::BaseSession(signaling_thread,
528 worker_thread,
529 port_allocator,
530 rtc::ToString(rtc::CreateRandomId64() & LLONG_MAX),
531 cricket::NS_JINGLE_RTP,
532 false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533 // RFC 3264: The numeric value of the session id and version in the
534 // o line MUST be representable with a "64 bit signed integer".
535 // Due to this constraint session id |sid_| is max limited to LLONG_MAX.
536 channel_manager_(channel_manager),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537 mediastream_signaling_(mediastream_signaling),
538 ice_observer_(NULL),
539 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
Peter Thatcher54360512015-07-08 11:08:35 -0700540 ice_connection_receiving_(true),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000541 older_version_remote_peer_(false),
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000542 dtls_enabled_(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000543 data_channel_type_(cricket::DCT_NONE),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000544 ice_restart_latch_(new IceRestartAnswerLatch),
545 metrics_observer_(NULL) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546}
547
548WebRtcSession::~WebRtcSession() {
tommi0f620f42015-07-09 03:25:02 -0700549 ASSERT(signaling_thread()->IsCurrent());
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000550 // Destroy video_channel_ first since it may have a pointer to the
551 // voice_channel_.
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +0000552 if (video_channel_) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553 SignalVideoChannelDestroyed();
554 channel_manager_->DestroyVideoChannel(video_channel_.release());
555 }
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +0000556 if (voice_channel_) {
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000557 SignalVoiceChannelDestroyed();
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200558 channel_manager_->DestroyVoiceChannel(voice_channel_.release(), nullptr);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000559 }
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +0000560 if (data_channel_) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 SignalDataChannelDestroyed();
562 channel_manager_->DestroyDataChannel(data_channel_.release());
563 }
564 for (size_t i = 0; i < saved_candidates_.size(); ++i) {
565 delete saved_candidates_[i];
566 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000567}
568
wu@webrtc.org91053e72013-08-10 07:18:04 +0000569bool WebRtcSession::Initialize(
wu@webrtc.org97077a32013-10-25 21:18:33 +0000570 const PeerConnectionFactoryInterface::Options& options,
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000571 const MediaConstraintsInterface* constraints,
Henrik Boström5e56c592015-08-11 10:33:13 +0200572 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200573 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
574 bundle_policy_ = rtc_configuration.bundle_policy;
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700575 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy;
Joachim Bauch04e5b492015-05-29 09:40:39 +0200576 SetSslMaxProtocolVersion(options.ssl_max_version);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000577
Henrik Boström87713d02015-08-25 09:53:21 +0200578 // Obtain a certificate from RTCConfiguration if any were provided (optional).
579 rtc::scoped_refptr<rtc::RTCCertificate> certificate;
580 if (!rtc_configuration.certificates.empty()) {
581 // TODO(hbos,torbjorng): Decide on certificate-selection strategy instead of
582 // just picking the first one. The decision should be made based on the DTLS
583 // handshake. The DTLS negotiations need to know about all certificates.
584 certificate = rtc_configuration.certificates[0];
585 }
586
honghaiz4edc39c2015-09-01 09:53:56 -0700587 SetIceConnectionReceivingTimeout(
588 rtc_configuration.ice_connection_receiving_timeout);
589
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000590 // TODO(perkj): Take |constraints| into consideration. Return false if not all
591 // mandatory constraints can be fulfilled. Note that |constraints|
592 // can be null.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 bool value;
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000594
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000595 if (options.disable_encryption) {
596 dtls_enabled_ = false;
597 } else {
Henrik Boström87713d02015-08-25 09:53:21 +0200598 // Enable DTLS by default if we have an identity store or a certificate.
599 dtls_enabled_ = (dtls_identity_store || certificate);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000600 // |constraints| can override the default |dtls_enabled_| value.
601 if (FindConstraint(
602 constraints,
603 MediaConstraintsInterface::kEnableDtlsSrtp,
Henrik Boström87713d02015-08-25 09:53:21 +0200604 &value, nullptr)) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000605 dtls_enabled_ = value;
606 }
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000607 }
608
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000609 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000610 // It takes precendence over the disable_sctp_data_channels
611 // PeerConnectionFactoryInterface::Options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612 if (FindConstraint(
613 constraints, MediaConstraintsInterface::kEnableRtpDataChannels,
614 &value, NULL) && value) {
615 LOG(LS_INFO) << "Allowing RTP data engine.";
616 data_channel_type_ = cricket::DCT_RTP;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000617 } else {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000618 // DTLS has to be enabled to use SCTP.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000619 if (!options.disable_sctp_data_channels && dtls_enabled_) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000620 LOG(LS_INFO) << "Allowing SCTP data engine.";
621 data_channel_type_ = cricket::DCT_SCTP;
622 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000623 }
624 if (data_channel_type_ != cricket::DCT_NONE) {
625 mediastream_signaling_->SetDataChannelFactory(this);
626 }
627
wu@webrtc.orgde305012013-10-31 15:40:38 +0000628 // Find DSCP constraint.
629 if (FindConstraint(
630 constraints,
631 MediaConstraintsInterface::kEnableDscp,
632 &value, NULL)) {
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +0000633 audio_options_.dscp.Set(value);
634 video_options_.dscp.Set(value);
635 }
636
637 // Find Suspend Below Min Bitrate constraint.
638 if (FindConstraint(
639 constraints,
640 MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
641 &value,
642 NULL)) {
643 video_options_.suspend_below_min_bitrate.Set(value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000644 }
645
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000646 SetOptionFromOptionalConstraint(constraints,
647 MediaConstraintsInterface::kScreencastMinBitrate,
648 &video_options_.screencast_min_bitrate);
649
650 // Find constraints for cpu overuse detection.
651 SetOptionFromOptionalConstraint(constraints,
652 MediaConstraintsInterface::kCpuUnderuseThreshold,
653 &video_options_.cpu_underuse_threshold);
654 SetOptionFromOptionalConstraint(constraints,
655 MediaConstraintsInterface::kCpuOveruseThreshold,
656 &video_options_.cpu_overuse_threshold);
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000657 SetOptionFromOptionalConstraint(constraints,
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000658 MediaConstraintsInterface::kCpuOveruseDetection,
659 &video_options_.cpu_overuse_detection);
660 SetOptionFromOptionalConstraint(constraints,
661 MediaConstraintsInterface::kCpuOveruseEncodeUsage,
662 &video_options_.cpu_overuse_encode_usage);
663 SetOptionFromOptionalConstraint(constraints,
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000664 MediaConstraintsInterface::kCpuUnderuseEncodeRsdThreshold,
665 &video_options_.cpu_underuse_encode_rsd_threshold);
666 SetOptionFromOptionalConstraint(constraints,
667 MediaConstraintsInterface::kCpuOveruseEncodeRsdThreshold,
668 &video_options_.cpu_overuse_encode_rsd_threshold);
buildbot@webrtc.orgdb563902014-06-13 13:05:48 +0000669
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000670 SetOptionFromOptionalConstraint(constraints,
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000671 MediaConstraintsInterface::kNumUnsignalledRecvStreams,
672 &video_options_.unsignalled_recv_stream_limit);
673 if (video_options_.unsignalled_recv_stream_limit.IsSet()) {
674 int stream_limit;
675 video_options_.unsignalled_recv_stream_limit.Get(&stream_limit);
andresp@webrtc.orgff689be2015-02-12 11:54:26 +0000676 stream_limit = std::min(kMaxUnsignalledRecvStreams, stream_limit);
677 stream_limit = std::max(0, stream_limit);
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000678 video_options_.unsignalled_recv_stream_limit.Set(stream_limit);
679 }
680
681 SetOptionFromOptionalConstraint(constraints,
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000682 MediaConstraintsInterface::kHighStartBitrate,
683 &video_options_.video_start_bitrate);
wu@webrtc.orgcfe5e9c2014-03-27 17:03:58 +0000684
685 if (FindConstraint(
686 constraints,
687 MediaConstraintsInterface::kVeryHighBitrate,
688 &value,
689 NULL)) {
690 video_options_.video_highest_bitrate.Set(
691 cricket::VideoOptions::VERY_HIGH);
692 } else if (FindConstraint(
693 constraints,
694 MediaConstraintsInterface::kHighBitrate,
695 &value,
696 NULL)) {
697 video_options_.video_highest_bitrate.Set(
698 cricket::VideoOptions::HIGH);
699 }
700
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000701 SetOptionFromOptionalConstraint(constraints,
702 MediaConstraintsInterface::kCombinedAudioVideoBwe,
703 &audio_options_.combined_audio_video_bwe);
704
Henrik Lundin64dad832015-05-11 12:44:23 +0200705 audio_options_.audio_jitter_buffer_max_packets.Set(
706 rtc_configuration.audio_jitter_buffer_max_packets);
707
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200708 audio_options_.audio_jitter_buffer_fast_accelerate.Set(
709 rtc_configuration.audio_jitter_buffer_fast_accelerate);
710
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711 const cricket::VideoCodec default_codec(
712 JsepSessionDescription::kDefaultVideoCodecId,
713 JsepSessionDescription::kDefaultVideoCodecName,
714 JsepSessionDescription::kMaxVideoCodecWidth,
715 JsepSessionDescription::kMaxVideoCodecHeight,
716 JsepSessionDescription::kDefaultVideoCodecFramerate,
717 JsepSessionDescription::kDefaultVideoCodecPreference);
718 channel_manager_->SetDefaultVideoEncoderConfig(
719 cricket::VideoEncoderConfig(default_codec));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000720
Henrik Boström87713d02015-08-25 09:53:21 +0200721 if (!dtls_enabled_) {
722 // Construct with DTLS disabled.
723 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
724 signaling_thread(),
725 channel_manager_,
726 mediastream_signaling_,
727 this,
728 id(),
729 data_channel_type_));
730 } else {
731 // Construct with DTLS enabled.
732 if (!certificate) {
733 // Use the |dtls_identity_store| to generate a certificate.
734 DCHECK(dtls_identity_store);
735 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
736 signaling_thread(),
737 channel_manager_,
738 mediastream_signaling_,
739 dtls_identity_store.Pass(),
740 this,
741 id(),
742 data_channel_type_));
743 } else {
744 // Use the already generated certificate.
745 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
746 signaling_thread(),
747 channel_manager_,
748 mediastream_signaling_,
749 certificate,
750 this,
751 id(),
752 data_channel_type_));
753 }
754 }
wu@webrtc.org91053e72013-08-10 07:18:04 +0000755
Henrik Boströmd8281982015-08-27 10:12:24 +0200756 webrtc_session_desc_factory_->SignalCertificateReady.connect(
757 this, &WebRtcSession::OnCertificateReady);
mallinath@webrtc.org7e809c32013-09-30 18:59:08 +0000758
wu@webrtc.org97077a32013-10-25 21:18:33 +0000759 if (options.disable_encryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000760 webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED);
mallinath@webrtc.org7e809c32013-09-30 18:59:08 +0000761 }
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000762 port_allocator()->set_candidate_filter(
Henrik Lundin64dad832015-05-11 12:44:23 +0200763 ConvertIceTransportTypeToCandidateFilter(rtc_configuration.type));
Guo-wei Shiehfe3bc9d2015-08-20 08:48:20 -0700764
765 if (rtc_configuration.enable_localhost_ice_candidate) {
766 port_allocator()->set_flags(
767 port_allocator()->flags() |
768 cricket::PORTALLOCATOR_ENABLE_LOCALHOST_CANDIDATE);
769 }
770
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771 return true;
772}
773
774void WebRtcSession::Terminate() {
775 SetState(STATE_RECEIVEDTERMINATE);
776 RemoveUnusedChannelsAndTransports(NULL);
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +0000777 ASSERT(!voice_channel_);
778 ASSERT(!video_channel_);
779 ASSERT(!data_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780}
781
782bool WebRtcSession::StartCandidatesAllocation() {
783 // SpeculativelyConnectTransportChannels, will call ConnectChannels method
784 // from TransportProxy to start gathering ice candidates.
785 SpeculativelyConnectAllTransportChannels();
786 if (!saved_candidates_.empty()) {
787 // If there are saved candidates which arrived before local description is
788 // set, copy those to remote description.
789 CopySavedCandidates(remote_desc_.get());
790 }
791 // Push remote candidates present in remote description to transport channels.
792 UseCandidatesInSessionDescription(remote_desc_.get());
793 return true;
794}
795
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000796void WebRtcSession::SetSdesPolicy(cricket::SecurePolicy secure_policy) {
797 webrtc_session_desc_factory_->SetSdesPolicy(secure_policy);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798}
799
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000800cricket::SecurePolicy WebRtcSession::SdesPolicy() const {
801 return webrtc_session_desc_factory_->SdesPolicy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802}
803
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000804bool WebRtcSession::GetSslRole(rtc::SSLRole* role) {
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000805 if (local_description() == NULL || remote_description() == NULL) {
806 LOG(LS_INFO) << "Local and Remote descriptions must be applied to get "
807 << "SSL Role of the session.";
808 return false;
809 }
810
811 // TODO(mallinath) - Return role of each transport, as role may differ from
812 // one another.
813 // In current implementaion we just return the role of first transport in the
814 // transport map.
815 for (cricket::TransportMap::const_iterator iter = transport_proxies().begin();
816 iter != transport_proxies().end(); ++iter) {
817 if (iter->second->impl()) {
818 return iter->second->impl()->GetSslRole(role);
819 }
820 }
821 return false;
822}
823
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000824void WebRtcSession::CreateOffer(
825 CreateSessionDescriptionObserver* observer,
826 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
827 webrtc_session_desc_factory_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000828}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829
wu@webrtc.org91053e72013-08-10 07:18:04 +0000830void WebRtcSession::CreateAnswer(CreateSessionDescriptionObserver* observer,
831 const MediaConstraintsInterface* constraints) {
832 webrtc_session_desc_factory_->CreateAnswer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833}
834
835bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc,
836 std::string* err_desc) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000837 // Takes the ownership of |desc| regardless of the result.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000838 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000839
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000840 // Validate SDP.
841 if (!ValidateSessionDescription(desc, cricket::CS_LOCAL, err_desc)) {
842 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 }
844
845 // Update the initiator flag if this session is the initiator.
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000846 Action action = GetAction(desc->type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 if (state() == STATE_INIT && action == kOffer) {
848 set_initiator(true);
849 }
850
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000851 cricket::SecurePolicy sdes_policy =
852 webrtc_session_desc_factory_->SdesPolicy();
853 cricket::CryptoType crypto_required = dtls_enabled_ ?
854 cricket::CT_DTLS : (sdes_policy == cricket::SEC_REQUIRED ?
855 cricket::CT_SDES : cricket::CT_NONE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 // Update the MediaContentDescription crypto settings as per the policy set.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000857 UpdateSessionDescriptionSecurePolicy(crypto_required, desc->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858
859 set_local_description(desc->description()->Copy());
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000860 local_desc_.reset(desc_temp.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861
862 // Transport and Media channels will be created only when offer is set.
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000863 if (action == kOffer && !CreateChannels(local_desc_->description())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 // TODO(mallinath) - Handle CreateChannel failure, as new local description
865 // is applied. Restore back to old description.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000866 return BadLocalSdp(desc->type(), kCreateChannelFailed, err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 }
868
869 // Remove channel and transport proxies, if MediaContentDescription is
870 // rejected.
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000871 RemoveUnusedChannelsAndTransports(local_desc_->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000873 if (!UpdateSessionState(action, cricket::CS_LOCAL, err_desc)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 return false;
875 }
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000876
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 // Kick starting the ice candidates allocation.
878 StartCandidatesAllocation();
879
880 // Update state and SSRC of local MediaStreams and DataChannels based on the
881 // local session description.
882 mediastream_signaling_->OnLocalDescriptionChanged(local_desc_.get());
883
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000884 rtc::SSLRole role;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000885 if (data_channel_type_ == cricket::DCT_SCTP && GetSslRole(&role)) {
886 mediastream_signaling_->OnDtlsRoleReadyForSctp(role);
887 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 if (error() != cricket::BaseSession::ERROR_NONE) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000889 return BadLocalSdp(desc->type(), GetSessionErrorMsg(), err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 }
891 return true;
892}
893
894bool WebRtcSession::SetRemoteDescription(SessionDescriptionInterface* desc,
895 std::string* err_desc) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000896 // Takes the ownership of |desc| regardless of the result.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000897 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000898
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000899 // Validate SDP.
900 if (!ValidateSessionDescription(desc, cricket::CS_REMOTE, err_desc)) {
901 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 }
903
904 // Transport and Media channels will be created only when offer is set.
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000905 Action action = GetAction(desc->type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 if (action == kOffer && !CreateChannels(desc->description())) {
907 // TODO(mallinath) - Handle CreateChannel failure, as new local description
908 // is applied. Restore back to old description.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000909 return BadRemoteSdp(desc->type(), kCreateChannelFailed, err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 }
911
912 // Remove channel and transport proxies, if MediaContentDescription is
913 // rejected.
914 RemoveUnusedChannelsAndTransports(desc->description());
915
916 // NOTE: Candidates allocation will be initiated only when SetLocalDescription
917 // is called.
918 set_remote_description(desc->description()->Copy());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000919 if (!UpdateSessionState(action, cricket::CS_REMOTE, err_desc)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 return false;
921 }
922
923 // Update remote MediaStreams.
924 mediastream_signaling_->OnRemoteDescriptionChanged(desc);
925 if (local_description() && !UseCandidatesInSessionDescription(desc)) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000926 return BadRemoteSdp(desc->type(), kInvalidCandidates, err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 }
928
929 // Copy all saved candidates.
930 CopySavedCandidates(desc);
honghaiz503726c2015-07-31 12:37:38 -0700931
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000932 // Check if this new SessionDescription contains new ice ufrag and password
933 // that indicates the remote peer requests ice restart.
honghaiz503726c2015-07-31 12:37:38 -0700934 bool ice_restart =
935 ice_restart_latch_->CheckForRemoteIceRestart(remote_desc_.get(), desc);
936 // We retain all received candidates only if ICE is not restarted.
937 // When ICE is restarted, all previous candidates belong to an old generation
938 // and should not be kept.
939 if (!ice_restart) {
940 WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription(
941 remote_desc_.get(), desc);
942 }
943
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000944 remote_desc_.reset(desc_temp.release());
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000945
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000946 rtc::SSLRole role;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000947 if (data_channel_type_ == cricket::DCT_SCTP && GetSslRole(&role)) {
948 mediastream_signaling_->OnDtlsRoleReadyForSctp(role);
949 }
950
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 if (error() != cricket::BaseSession::ERROR_NONE) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000952 return BadRemoteSdp(desc->type(), GetSessionErrorMsg(), err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 }
jiayl@webrtc.orgdacdd942015-01-23 17:33:34 +0000954
955 // Set the the ICE connection state to connecting since the connection may
956 // become writable with peer reflexive candidates before any remote candidate
957 // is signaled.
958 // TODO(pthatcher): This is a short-term solution for crbug/446908. A real fix
959 // is to have a new signal the indicates a change in checking state from the
960 // transport and expose a new checking() member from transport that can be
961 // read to determine the current checking state. The existing SignalConnecting
962 // actually means "gathering candidates", so cannot be be used here.
963 if (desc->type() != SessionDescriptionInterface::kOffer &&
964 ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew) {
965 SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking);
966 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 return true;
968}
969
970bool WebRtcSession::UpdateSessionState(
971 Action action, cricket::ContentSource source,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 std::string* err_desc) {
973 // If there's already a pending error then no state transition should happen.
974 // But all call-sites should be verifying this before calling us!
975 ASSERT(error() == cricket::BaseSession::ERROR_NONE);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000976 std::string td_err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977 if (action == kOffer) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000978 if (!PushdownTransportDescription(source, cricket::CA_OFFER, &td_err)) {
979 return BadOfferSdp(source, MakeTdErrorString(td_err), err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 }
981 SetState(source == cricket::CS_LOCAL ?
982 STATE_SENTINITIATE : STATE_RECEIVEDINITIATE);
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +0000983 if (!PushdownMediaDescription(cricket::CA_OFFER, source, err_desc)) {
984 SetError(BaseSession::ERROR_CONTENT, *err_desc);
985 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 if (error() != cricket::BaseSession::ERROR_NONE) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000987 return BadOfferSdp(source, GetSessionErrorMsg(), err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988 }
989 } else if (action == kPrAnswer) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000990 if (!PushdownTransportDescription(source, cricket::CA_PRANSWER, &td_err)) {
991 return BadPranswerSdp(source, MakeTdErrorString(td_err), err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992 }
993 EnableChannels();
994 SetState(source == cricket::CS_LOCAL ?
995 STATE_SENTPRACCEPT : STATE_RECEIVEDPRACCEPT);
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +0000996 if (!PushdownMediaDescription(cricket::CA_PRANSWER, source, err_desc)) {
997 SetError(BaseSession::ERROR_CONTENT, *err_desc);
998 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 if (error() != cricket::BaseSession::ERROR_NONE) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001000 return BadPranswerSdp(source, GetSessionErrorMsg(), err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001 }
1002 } else if (action == kAnswer) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001003 if (!PushdownTransportDescription(source, cricket::CA_ANSWER, &td_err)) {
1004 return BadAnswerSdp(source, MakeTdErrorString(td_err), err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 }
1006 MaybeEnableMuxingSupport();
1007 EnableChannels();
1008 SetState(source == cricket::CS_LOCAL ?
1009 STATE_SENTACCEPT : STATE_RECEIVEDACCEPT);
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +00001010 if (!PushdownMediaDescription(cricket::CA_ANSWER, source, err_desc)) {
1011 SetError(BaseSession::ERROR_CONTENT, *err_desc);
1012 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001013 if (error() != cricket::BaseSession::ERROR_NONE) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001014 return BadAnswerSdp(source, GetSessionErrorMsg(), err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015 }
1016 }
1017 return true;
1018}
1019
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +00001020bool WebRtcSession::PushdownMediaDescription(
1021 cricket::ContentAction action,
1022 cricket::ContentSource source,
1023 std::string* err) {
1024 auto set_content = [this, action, source, err](cricket::BaseChannel* ch) {
1025 if (!ch) {
1026 return true;
1027 } else if (source == cricket::CS_LOCAL) {
1028 return ch->PushdownLocalDescription(
1029 base_local_description(), action, err);
1030 } else {
1031 return ch->PushdownRemoteDescription(
1032 base_remote_description(), action, err);
1033 }
1034 };
1035
1036 return (set_content(voice_channel()) &&
1037 set_content(video_channel()) &&
1038 set_content(data_channel()));
1039}
1040
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001041WebRtcSession::Action WebRtcSession::GetAction(const std::string& type) {
1042 if (type == SessionDescriptionInterface::kOffer) {
1043 return WebRtcSession::kOffer;
1044 } else if (type == SessionDescriptionInterface::kPrAnswer) {
1045 return WebRtcSession::kPrAnswer;
1046 } else if (type == SessionDescriptionInterface::kAnswer) {
1047 return WebRtcSession::kAnswer;
1048 }
1049 ASSERT(false && "unknown action type");
1050 return WebRtcSession::kOffer;
1051}
1052
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +00001053bool WebRtcSession::GetTransportStats(cricket::SessionStats* stats) {
1054 ASSERT(signaling_thread()->IsCurrent());
1055
1056 const auto get_transport_stats = [stats](const std::string& content_name,
1057 cricket::Transport* transport) {
1058 const std::string& transport_id = transport->content_name();
1059 stats->proxy_to_transport[content_name] = transport_id;
1060 if (stats->transport_stats.find(transport_id)
1061 != stats->transport_stats.end()) {
1062 // Transport stats already done for this transport.
1063 return true;
1064 }
1065
1066 cricket::TransportStats tstats;
1067 if (!transport->GetStats(&tstats)) {
1068 return false;
1069 }
1070
1071 stats->transport_stats[transport_id] = tstats;
1072 return true;
1073 };
1074
1075 for (const auto& kv : transport_proxies()) {
1076 cricket::Transport* transport = kv.second->impl();
1077 if (transport && !get_transport_stats(kv.first, transport)) {
1078 return false;
1079 }
1080 }
1081 return true;
1082}
1083
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) {
1085 if (state() == STATE_INIT) {
1086 LOG(LS_ERROR) << "ProcessIceMessage: ICE candidates can't be added "
1087 << "without any offer (local or remote) "
1088 << "session description.";
1089 return false;
1090 }
1091
1092 if (!candidate) {
1093 LOG(LS_ERROR) << "ProcessIceMessage: Candidate is NULL";
1094 return false;
1095 }
1096
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00001097 bool valid = false;
1098 if (!ReadyToUseRemoteCandidate(candidate, NULL, &valid)) {
1099 if (valid) {
1100 LOG(LS_INFO) << "ProcessIceMessage: Candidate saved";
1101 saved_candidates_.push_back(
1102 new JsepIceCandidate(candidate->sdp_mid(),
1103 candidate->sdp_mline_index(),
1104 candidate->candidate()));
buildbot@webrtc.org61c1b8e2014-04-09 06:06:38 +00001105 }
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00001106 return valid;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001107 }
1108
1109 // Add this candidate to the remote session description.
1110 if (!remote_desc_->AddCandidate(candidate)) {
1111 LOG(LS_ERROR) << "ProcessIceMessage: Candidate cannot be used";
1112 return false;
1113 }
1114
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001115 return UseCandidate(candidate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001116}
1117
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001118bool WebRtcSession::SetIceTransports(
1119 PeerConnectionInterface::IceTransportsType type) {
1120 return port_allocator()->set_candidate_filter(
1121 ConvertIceTransportTypeToCandidateFilter(type));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001122}
1123
xians@webrtc.org4cb01282014-06-12 14:57:05 +00001124bool WebRtcSession::GetLocalTrackIdBySsrc(uint32 ssrc, std::string* track_id) {
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +00001125 if (!base_local_description())
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001126 return false;
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +00001127 return webrtc::GetTrackIdBySsrc(base_local_description(), ssrc, track_id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001128}
1129
xians@webrtc.org4cb01282014-06-12 14:57:05 +00001130bool WebRtcSession::GetRemoteTrackIdBySsrc(uint32 ssrc, std::string* track_id) {
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +00001131 if (!base_remote_description())
xians@webrtc.org4cb01282014-06-12 14:57:05 +00001132 return false;
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +00001133 return webrtc::GetTrackIdBySsrc(base_remote_description(), ssrc, track_id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001134}
1135
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001136std::string WebRtcSession::BadStateErrMsg(State state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001137 std::ostringstream desc;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001138 desc << "Called in wrong state: " << GetStateString(state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001139 return desc.str();
1140}
1141
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001142void WebRtcSession::SetAudioPlayout(uint32 ssrc, bool enable,
1143 cricket::AudioRenderer* renderer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001144 ASSERT(signaling_thread()->IsCurrent());
1145 if (!voice_channel_) {
1146 LOG(LS_ERROR) << "SetAudioPlayout: No audio channel exists.";
1147 return;
1148 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001149 if (!voice_channel_->SetRemoteRenderer(ssrc, renderer)) {
1150 // SetRenderer() can fail if the ssrc does not match any playout channel.
1151 LOG(LS_ERROR) << "SetAudioPlayout: ssrc is incorrect: " << ssrc;
1152 return;
1153 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001154 if (!voice_channel_->SetOutputScaling(ssrc, enable ? 1 : 0, enable ? 1 : 0)) {
1155 // Allow that SetOutputScaling fail if |enable| is false but assert
1156 // otherwise. This in the normal case when the underlying media channel has
1157 // already been deleted.
1158 ASSERT(enable == false);
1159 }
1160}
1161
1162void WebRtcSession::SetAudioSend(uint32 ssrc, bool enable,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001163 const cricket::AudioOptions& options,
1164 cricket::AudioRenderer* renderer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001165 ASSERT(signaling_thread()->IsCurrent());
1166 if (!voice_channel_) {
1167 LOG(LS_ERROR) << "SetAudioSend: No audio channel exists.";
1168 return;
1169 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001170 if (!voice_channel_->SetLocalRenderer(ssrc, renderer)) {
1171 // SetRenderer() can fail if the ssrc does not match any send channel.
1172 LOG(LS_ERROR) << "SetAudioSend: ssrc is incorrect: " << ssrc;
1173 return;
1174 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001175 if (!voice_channel_->MuteStream(ssrc, !enable)) {
1176 // Allow that MuteStream fail if |enable| is false but assert otherwise.
1177 // This in the normal case when the underlying media channel has already
1178 // been deleted.
1179 ASSERT(enable == false);
1180 return;
1181 }
1182 if (enable)
1183 voice_channel_->SetChannelOptions(options);
1184}
1185
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001186void WebRtcSession::SetAudioPlayoutVolume(uint32 ssrc, double volume) {
1187 ASSERT(signaling_thread()->IsCurrent());
1188 ASSERT(volume >= 0 && volume <= 10);
1189 if (!voice_channel_) {
1190 LOG(LS_ERROR) << "SetAudioPlayoutVolume: No audio channel exists.";
1191 return;
1192 }
1193
1194 if (!voice_channel_->SetOutputScaling(ssrc, volume, volume))
1195 ASSERT(false);
1196}
1197
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001198bool WebRtcSession::SetCaptureDevice(uint32 ssrc,
1199 cricket::VideoCapturer* camera) {
1200 ASSERT(signaling_thread()->IsCurrent());
1201
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001202 if (!video_channel_) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001203 // |video_channel_| doesnt't exist. Probably because the remote end doesnt't
1204 // support video.
1205 LOG(LS_WARNING) << "Video not used in this call.";
1206 return false;
1207 }
1208 if (!video_channel_->SetCapturer(ssrc, camera)) {
1209 // Allow that SetCapturer fail if |camera| is NULL but assert otherwise.
1210 // This in the normal case when the underlying media channel has already
1211 // been deleted.
1212 ASSERT(camera == NULL);
1213 return false;
1214 }
1215 return true;
1216}
1217
1218void WebRtcSession::SetVideoPlayout(uint32 ssrc,
1219 bool enable,
1220 cricket::VideoRenderer* renderer) {
1221 ASSERT(signaling_thread()->IsCurrent());
1222 if (!video_channel_) {
1223 LOG(LS_WARNING) << "SetVideoPlayout: No video channel exists.";
1224 return;
1225 }
1226 if (!video_channel_->SetRenderer(ssrc, enable ? renderer : NULL)) {
1227 // Allow that SetRenderer fail if |renderer| is NULL but assert otherwise.
1228 // This in the normal case when the underlying media channel has already
1229 // been deleted.
1230 ASSERT(renderer == NULL);
1231 }
1232}
1233
1234void WebRtcSession::SetVideoSend(uint32 ssrc, bool enable,
1235 const cricket::VideoOptions* options) {
1236 ASSERT(signaling_thread()->IsCurrent());
1237 if (!video_channel_) {
1238 LOG(LS_WARNING) << "SetVideoSend: No video channel exists.";
1239 return;
1240 }
1241 if (!video_channel_->MuteStream(ssrc, !enable)) {
1242 // Allow that MuteStream fail if |enable| is false but assert otherwise.
1243 // This in the normal case when the underlying media channel has already
1244 // been deleted.
1245 ASSERT(enable == false);
1246 return;
1247 }
1248 if (enable && options)
1249 video_channel_->SetChannelOptions(*options);
1250}
1251
1252bool WebRtcSession::CanInsertDtmf(const std::string& track_id) {
1253 ASSERT(signaling_thread()->IsCurrent());
1254 if (!voice_channel_) {
1255 LOG(LS_ERROR) << "CanInsertDtmf: No audio channel exists.";
1256 return false;
1257 }
1258 uint32 send_ssrc = 0;
1259 // The Dtmf is negotiated per channel not ssrc, so we only check if the ssrc
1260 // exists.
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +00001261 if (!GetAudioSsrcByTrackId(base_local_description(), track_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001262 &send_ssrc)) {
1263 LOG(LS_ERROR) << "CanInsertDtmf: Track does not exist: " << track_id;
1264 return false;
1265 }
1266 return voice_channel_->CanInsertDtmf();
1267}
1268
1269bool WebRtcSession::InsertDtmf(const std::string& track_id,
1270 int code, int duration) {
1271 ASSERT(signaling_thread()->IsCurrent());
1272 if (!voice_channel_) {
1273 LOG(LS_ERROR) << "InsertDtmf: No audio channel exists.";
1274 return false;
1275 }
1276 uint32 send_ssrc = 0;
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +00001277 if (!VERIFY(GetAudioSsrcByTrackId(base_local_description(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278 track_id, &send_ssrc))) {
1279 LOG(LS_ERROR) << "InsertDtmf: Track does not exist: " << track_id;
1280 return false;
1281 }
1282 if (!voice_channel_->InsertDtmf(send_ssrc, code, duration,
1283 cricket::DF_SEND)) {
1284 LOG(LS_ERROR) << "Failed to insert DTMF to channel.";
1285 return false;
1286 }
1287 return true;
1288}
1289
1290sigslot::signal0<>* WebRtcSession::GetOnDestroyedSignal() {
1291 return &SignalVoiceChannelDestroyed;
1292}
1293
wu@webrtc.org78187522013-10-07 23:32:02 +00001294bool WebRtcSession::SendData(const cricket::SendDataParams& params,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001295 const rtc::Buffer& payload,
wu@webrtc.org78187522013-10-07 23:32:02 +00001296 cricket::SendDataResult* result) {
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001297 if (!data_channel_) {
wu@webrtc.org78187522013-10-07 23:32:02 +00001298 LOG(LS_ERROR) << "SendData called when data_channel_ is NULL.";
1299 return false;
1300 }
1301 return data_channel_->SendData(params, payload, result);
1302}
1303
1304bool WebRtcSession::ConnectDataChannel(DataChannel* webrtc_data_channel) {
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001305 if (!data_channel_) {
wu@webrtc.org78187522013-10-07 23:32:02 +00001306 LOG(LS_ERROR) << "ConnectDataChannel called when data_channel_ is NULL.";
1307 return false;
1308 }
wu@webrtc.org78187522013-10-07 23:32:02 +00001309 data_channel_->SignalReadyToSendData.connect(webrtc_data_channel,
1310 &DataChannel::OnChannelReady);
1311 data_channel_->SignalDataReceived.connect(webrtc_data_channel,
1312 &DataChannel::OnDataReceived);
wu@webrtc.org78187522013-10-07 23:32:02 +00001313 return true;
1314}
1315
1316void WebRtcSession::DisconnectDataChannel(DataChannel* webrtc_data_channel) {
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001317 if (!data_channel_) {
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001318 LOG(LS_ERROR) << "DisconnectDataChannel called when data_channel_ is NULL.";
1319 return;
1320 }
wu@webrtc.org78187522013-10-07 23:32:02 +00001321 data_channel_->SignalReadyToSendData.disconnect(webrtc_data_channel);
1322 data_channel_->SignalDataReceived.disconnect(webrtc_data_channel);
1323}
1324
bemasc@webrtc.org9b5467e2014-12-04 23:16:52 +00001325void WebRtcSession::AddSctpDataStream(int sid) {
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001326 if (!data_channel_) {
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001327 LOG(LS_ERROR) << "AddDataChannelStreams called when data_channel_ is NULL.";
1328 return;
1329 }
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00001330 data_channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(sid));
1331 data_channel_->AddSendStream(cricket::StreamParams::CreateLegacy(sid));
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001332}
1333
bemasc@webrtc.org9b5467e2014-12-04 23:16:52 +00001334void WebRtcSession::RemoveSctpDataStream(int sid) {
1335 mediastream_signaling_->RemoveSctpDataChannel(sid);
jiayl@webrtc.org2eaac182014-06-17 16:02:46 +00001336
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001337 if (!data_channel_) {
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001338 LOG(LS_ERROR) << "RemoveDataChannelStreams called when data_channel_ is "
1339 << "NULL.";
1340 return;
1341 }
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00001342 data_channel_->RemoveRecvStream(sid);
1343 data_channel_->RemoveSendStream(sid);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001344}
1345
wu@webrtc.org07a6fbe2013-11-04 18:41:34 +00001346bool WebRtcSession::ReadyToSendData() const {
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001347 return data_channel_ && data_channel_->ready_to_send_data();
wu@webrtc.org07a6fbe2013-11-04 18:41:34 +00001348}
1349
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001350rtc::scoped_refptr<DataChannel> WebRtcSession::CreateDataChannel(
wu@webrtc.org78187522013-10-07 23:32:02 +00001351 const std::string& label,
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001352 const InternalDataChannelInit* config) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001353 if (state() == STATE_RECEIVEDTERMINATE) {
1354 return NULL;
1355 }
1356 if (data_channel_type_ == cricket::DCT_NONE) {
1357 LOG(LS_ERROR) << "CreateDataChannel: Data is not supported in this call.";
1358 return NULL;
1359 }
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001360 InternalDataChannelInit new_config =
1361 config ? (*config) : InternalDataChannelInit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 if (data_channel_type_ == cricket::DCT_SCTP) {
1363 if (new_config.id < 0) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001364 rtc::SSLRole role;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001365 if (GetSslRole(&role) &&
1366 !mediastream_signaling_->AllocateSctpSid(role, &new_config.id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001367 LOG(LS_ERROR) << "No id can be allocated for the SCTP data channel.";
1368 return NULL;
1369 }
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001370 } else if (!mediastream_signaling_->IsSctpSidAvailable(new_config.id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001371 LOG(LS_ERROR) << "Failed to create a SCTP data channel "
1372 << "because the id is already in use or out of range.";
1373 return NULL;
1374 }
1375 }
wu@webrtc.org91053e72013-08-10 07:18:04 +00001376
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001377 rtc::scoped_refptr<DataChannel> channel(DataChannel::Create(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001378 this, data_channel_type_, label, new_config));
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001379 if (channel && !mediastream_signaling_->AddDataChannel(channel))
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001380 return NULL;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001381
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001382 return channel;
1383}
1384
1385cricket::DataChannelType WebRtcSession::data_channel_type() const {
1386 return data_channel_type_;
1387}
1388
wu@webrtc.org91053e72013-08-10 07:18:04 +00001389bool WebRtcSession::IceRestartPending() const {
1390 return ice_restart_latch_->Get();
1391}
1392
1393void WebRtcSession::ResetIceRestartLatch() {
1394 ice_restart_latch_->Reset();
1395}
1396
Henrik Boströmd8281982015-08-27 10:12:24 +02001397void WebRtcSession::OnCertificateReady(
1398 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) {
1399 SetCertificate(certificate);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001400}
1401
Henrik Boströmd8281982015-08-27 10:12:24 +02001402bool WebRtcSession::waiting_for_certificate_for_testing() const {
Henrik Boström87713d02015-08-25 09:53:21 +02001403 return webrtc_session_desc_factory_->waiting_for_certificate_for_testing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001404}
1405
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001406void WebRtcSession::SetIceConnectionState(
1407 PeerConnectionInterface::IceConnectionState state) {
1408 if (ice_connection_state_ == state) {
1409 return;
1410 }
1411
1412 // ASSERT that the requested transition is allowed. Note that
1413 // WebRtcSession does not implement "kIceConnectionClosed" (that is handled
1414 // within PeerConnection). This switch statement should compile away when
1415 // ASSERTs are disabled.
1416 switch (ice_connection_state_) {
1417 case PeerConnectionInterface::kIceConnectionNew:
1418 ASSERT(state == PeerConnectionInterface::kIceConnectionChecking);
1419 break;
1420 case PeerConnectionInterface::kIceConnectionChecking:
1421 ASSERT(state == PeerConnectionInterface::kIceConnectionFailed ||
1422 state == PeerConnectionInterface::kIceConnectionConnected);
1423 break;
1424 case PeerConnectionInterface::kIceConnectionConnected:
1425 ASSERT(state == PeerConnectionInterface::kIceConnectionDisconnected ||
1426 state == PeerConnectionInterface::kIceConnectionChecking ||
1427 state == PeerConnectionInterface::kIceConnectionCompleted);
1428 break;
1429 case PeerConnectionInterface::kIceConnectionCompleted:
1430 ASSERT(state == PeerConnectionInterface::kIceConnectionConnected ||
1431 state == PeerConnectionInterface::kIceConnectionDisconnected);
1432 break;
1433 case PeerConnectionInterface::kIceConnectionFailed:
1434 ASSERT(state == PeerConnectionInterface::kIceConnectionNew);
1435 break;
1436 case PeerConnectionInterface::kIceConnectionDisconnected:
1437 ASSERT(state == PeerConnectionInterface::kIceConnectionChecking ||
1438 state == PeerConnectionInterface::kIceConnectionConnected ||
1439 state == PeerConnectionInterface::kIceConnectionCompleted ||
1440 state == PeerConnectionInterface::kIceConnectionFailed);
1441 break;
1442 case PeerConnectionInterface::kIceConnectionClosed:
1443 ASSERT(false);
1444 break;
1445 default:
1446 ASSERT(false);
1447 break;
1448 }
1449
1450 ice_connection_state_ = state;
1451 if (ice_observer_) {
1452 ice_observer_->OnIceConnectionChange(ice_connection_state_);
1453 }
1454}
1455
1456void WebRtcSession::OnTransportRequestSignaling(
1457 cricket::Transport* transport) {
1458 ASSERT(signaling_thread()->IsCurrent());
1459 transport->OnSignalingReady();
1460 if (ice_observer_) {
1461 ice_observer_->OnIceGatheringChange(
1462 PeerConnectionInterface::kIceGatheringGathering);
1463 }
1464}
1465
1466void WebRtcSession::OnTransportConnecting(cricket::Transport* transport) {
1467 ASSERT(signaling_thread()->IsCurrent());
1468 // start monitoring for the write state of the transport.
1469 OnTransportWritable(transport);
1470}
1471
1472void WebRtcSession::OnTransportWritable(cricket::Transport* transport) {
1473 ASSERT(signaling_thread()->IsCurrent());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474 if (transport->all_channels_writable()) {
henrike@webrtc.org05376342014-03-10 15:53:12 +00001475 SetIceConnectionState(PeerConnectionInterface::kIceConnectionConnected);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001476 } else if (transport->HasChannels()) {
1477 // If the current state is Connected or Completed, then there were writable
1478 // channels but now there are not, so the next state must be Disconnected.
1479 if (ice_connection_state_ ==
1480 PeerConnectionInterface::kIceConnectionConnected ||
1481 ice_connection_state_ ==
1482 PeerConnectionInterface::kIceConnectionCompleted) {
1483 SetIceConnectionState(
1484 PeerConnectionInterface::kIceConnectionDisconnected);
1485 }
1486 }
1487}
1488
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001489void WebRtcSession::OnTransportCompleted(cricket::Transport* transport) {
1490 ASSERT(signaling_thread()->IsCurrent());
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001491 PeerConnectionInterface::IceConnectionState old_state = ice_connection_state_;
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001492 SetIceConnectionState(PeerConnectionInterface::kIceConnectionCompleted);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001493 // Only report once when Ice connection is completed.
1494 if (old_state != PeerConnectionInterface::kIceConnectionCompleted) {
jbauchac8869e2015-07-03 01:36:14 -07001495 cricket::TransportStats stats;
1496 if (metrics_observer_ && transport->GetStats(&stats)) {
1497 ReportBestConnectionState(stats);
1498 ReportNegotiatedCiphers(stats);
1499 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001500 }
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001501}
1502
1503void WebRtcSession::OnTransportFailed(cricket::Transport* transport) {
1504 ASSERT(signaling_thread()->IsCurrent());
1505 SetIceConnectionState(PeerConnectionInterface::kIceConnectionFailed);
1506}
1507
Peter Thatcher54360512015-07-08 11:08:35 -07001508void WebRtcSession::OnTransportReceiving(cricket::Transport* transport) {
1509 ASSERT(signaling_thread()->IsCurrent());
1510 // The ice connection is considered receiving if at least one transport is
1511 // receiving on any channels.
1512 bool receiving = false;
1513 for (const auto& kv : transport_proxies()) {
1514 cricket::Transport* transport = kv.second->impl();
1515 if (transport && transport->any_channel_receiving()) {
1516 receiving = true;
1517 break;
1518 }
1519 }
1520 SetIceConnectionReceiving(receiving);
1521}
1522
1523void WebRtcSession::SetIceConnectionReceiving(bool receiving) {
1524 if (ice_connection_receiving_ == receiving) {
1525 return;
1526 }
1527 ice_connection_receiving_ = receiving;
1528 if (ice_observer_) {
1529 ice_observer_->OnIceConnectionReceivingChange(receiving);
1530 }
1531}
1532
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001533void WebRtcSession::OnTransportProxyCandidatesReady(
1534 cricket::TransportProxy* proxy, const cricket::Candidates& candidates) {
1535 ASSERT(signaling_thread()->IsCurrent());
1536 ProcessNewLocalCandidate(proxy->content_name(), candidates);
1537}
1538
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001539void WebRtcSession::OnCandidatesAllocationDone() {
1540 ASSERT(signaling_thread()->IsCurrent());
1541 if (ice_observer_) {
1542 ice_observer_->OnIceGatheringChange(
1543 PeerConnectionInterface::kIceGatheringComplete);
1544 ice_observer_->OnIceComplete();
1545 }
1546}
1547
1548// Enabling voice and video channel.
1549void WebRtcSession::EnableChannels() {
1550 if (voice_channel_ && !voice_channel_->enabled())
1551 voice_channel_->Enable(true);
1552
1553 if (video_channel_ && !video_channel_->enabled())
1554 video_channel_->Enable(true);
1555
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001556 if (data_channel_ && !data_channel_->enabled())
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001557 data_channel_->Enable(true);
1558}
1559
1560void WebRtcSession::ProcessNewLocalCandidate(
1561 const std::string& content_name,
1562 const cricket::Candidates& candidates) {
1563 int sdp_mline_index;
1564 if (!GetLocalCandidateMediaIndex(content_name, &sdp_mline_index)) {
1565 LOG(LS_ERROR) << "ProcessNewLocalCandidate: content name "
1566 << content_name << " not found";
1567 return;
1568 }
1569
1570 for (cricket::Candidates::const_iterator citer = candidates.begin();
1571 citer != candidates.end(); ++citer) {
1572 // Use content_name as the candidate media id.
1573 JsepIceCandidate candidate(content_name, sdp_mline_index, *citer);
1574 if (ice_observer_) {
1575 ice_observer_->OnIceCandidate(&candidate);
1576 }
1577 if (local_desc_) {
1578 local_desc_->AddCandidate(&candidate);
1579 }
1580 }
1581}
1582
1583// Returns the media index for a local ice candidate given the content name.
1584bool WebRtcSession::GetLocalCandidateMediaIndex(const std::string& content_name,
1585 int* sdp_mline_index) {
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +00001586 if (!base_local_description() || !sdp_mline_index)
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587 return false;
1588
1589 bool content_found = false;
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +00001590 const ContentInfos& contents = base_local_description()->contents();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591 for (size_t index = 0; index < contents.size(); ++index) {
1592 if (contents[index].name == content_name) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001593 *sdp_mline_index = static_cast<int>(index);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594 content_found = true;
1595 break;
1596 }
1597 }
1598 return content_found;
1599}
1600
1601bool WebRtcSession::UseCandidatesInSessionDescription(
1602 const SessionDescriptionInterface* remote_desc) {
1603 if (!remote_desc)
1604 return true;
1605 bool ret = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00001606
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 for (size_t m = 0; m < remote_desc->number_of_mediasections(); ++m) {
1608 const IceCandidateCollection* candidates = remote_desc->candidates(m);
1609 for (size_t n = 0; n < candidates->count(); ++n) {
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00001610 const IceCandidateInterface* candidate = candidates->at(n);
1611 bool valid = false;
1612 if (!ReadyToUseRemoteCandidate(candidate, remote_desc, &valid)) {
1613 if (valid) {
1614 LOG(LS_INFO) << "UseCandidatesInSessionDescription: Candidate saved.";
1615 saved_candidates_.push_back(
1616 new JsepIceCandidate(candidate->sdp_mid(),
1617 candidate->sdp_mline_index(),
1618 candidate->candidate()));
1619 }
1620 continue;
1621 }
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00001622 ret = UseCandidate(candidate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623 if (!ret)
1624 break;
1625 }
1626 }
1627 return ret;
1628}
1629
1630bool WebRtcSession::UseCandidate(
1631 const IceCandidateInterface* candidate) {
1632
1633 size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index());
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +00001634 size_t remote_content_size = base_remote_description()->contents().size();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 if (mediacontent_index >= remote_content_size) {
1636 LOG(LS_ERROR)
1637 << "UseRemoteCandidateInSession: Invalid candidate media index.";
1638 return false;
1639 }
1640
1641 cricket::ContentInfo content =
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +00001642 base_remote_description()->contents()[mediacontent_index];
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643 std::vector<cricket::Candidate> candidates;
1644 candidates.push_back(candidate->candidate());
1645 // Invoking BaseSession method to handle remote candidates.
1646 std::string error;
1647 if (OnRemoteCandidates(content.name, candidates, &error)) {
1648 // Candidates successfully submitted for checking.
1649 if (ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew ||
1650 ice_connection_state_ ==
1651 PeerConnectionInterface::kIceConnectionDisconnected) {
1652 // If state is New, then the session has just gotten its first remote ICE
1653 // candidates, so go to Checking.
1654 // If state is Disconnected, the session is re-using old candidates or
1655 // receiving additional ones, so go to Checking.
1656 // If state is Connected, stay Connected.
1657 // TODO(bemasc): If state is Connected, and the new candidates are for a
1658 // newly added transport, then the state actually _should_ move to
1659 // checking. Add a way to distinguish that case.
1660 SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking);
1661 }
1662 // TODO(bemasc): If state is Completed, go back to Connected.
1663 } else {
fischman@webrtc.org4f2bd682014-03-28 18:13:34 +00001664 if (!error.empty()) {
1665 LOG(LS_WARNING) << error;
1666 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 }
1668 return true;
1669}
1670
1671void WebRtcSession::RemoveUnusedChannelsAndTransports(
1672 const SessionDescription* desc) {
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001673 // Destroy video_channel_ first since it may have a pointer to the
1674 // voice_channel_.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675 const cricket::ContentInfo* video_info =
1676 cricket::GetFirstVideoContent(desc);
1677 if ((!video_info || video_info->rejected) && video_channel_) {
1678 mediastream_signaling_->OnVideoChannelClose();
1679 SignalVideoChannelDestroyed();
1680 const std::string content_name = video_channel_->content_name();
1681 channel_manager_->DestroyVideoChannel(video_channel_.release());
bjornv@webrtc.org520a69e2015-02-04 12:45:44 +00001682 DestroyTransportProxy(content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001683 }
1684
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001685 const cricket::ContentInfo* voice_info =
1686 cricket::GetFirstAudioContent(desc);
1687 if ((!voice_info || voice_info->rejected) && voice_channel_) {
1688 mediastream_signaling_->OnAudioChannelClose();
1689 SignalVoiceChannelDestroyed();
1690 const std::string content_name = voice_channel_->content_name();
Fredrik Solenberg4b60c732015-05-07 14:07:48 +02001691 channel_manager_->DestroyVoiceChannel(voice_channel_.release(),
1692 video_channel_.get());
bjornv@webrtc.org520a69e2015-02-04 12:45:44 +00001693 DestroyTransportProxy(content_name);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001694 }
1695
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 const cricket::ContentInfo* data_info =
1697 cricket::GetFirstDataContent(desc);
1698 if ((!data_info || data_info->rejected) && data_channel_) {
1699 mediastream_signaling_->OnDataChannelClose();
1700 SignalDataChannelDestroyed();
1701 const std::string content_name = data_channel_->content_name();
1702 channel_manager_->DestroyDataChannel(data_channel_.release());
bjornv@webrtc.org520a69e2015-02-04 12:45:44 +00001703 DestroyTransportProxy(content_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 }
1705}
1706
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001707// TODO(mallinath) - Add a correct error code if the channels are not creatued
1708// due to BUNDLE is enabled but rtcp-mux is disabled.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001709bool WebRtcSession::CreateChannels(const SessionDescription* desc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710 // Creating the media channels and transport proxies.
1711 const cricket::ContentInfo* voice = cricket::GetFirstAudioContent(desc);
1712 if (voice && !voice->rejected && !voice_channel_) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001713 if (!CreateVoiceChannel(voice)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714 LOG(LS_ERROR) << "Failed to create voice channel.";
1715 return false;
1716 }
1717 }
1718
1719 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
1720 if (video && !video->rejected && !video_channel_) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001721 if (!CreateVideoChannel(video)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722 LOG(LS_ERROR) << "Failed to create video channel.";
1723 return false;
1724 }
1725 }
1726
1727 const cricket::ContentInfo* data = cricket::GetFirstDataContent(desc);
1728 if (data_channel_type_ != cricket::DCT_NONE &&
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001729 data && !data->rejected && !data_channel_) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001730 if (!CreateDataChannel(data)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731 LOG(LS_ERROR) << "Failed to create data channel.";
1732 return false;
1733 }
1734 }
1735
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001736 if (rtcp_mux_policy_ == PeerConnectionInterface::kRtcpMuxPolicyRequire) {
1737 if (voice_channel()) {
1738 voice_channel()->ActivateRtcpMux();
1739 }
1740 if (video_channel()) {
1741 video_channel()->ActivateRtcpMux();
1742 }
1743 if (data_channel()) {
1744 data_channel()->ActivateRtcpMux();
1745 }
1746 }
1747
Donald Curtis0e209b02015-03-24 09:29:54 -07001748 // Enable bundle before when kMaxBundle policy is in effect.
1749 if (bundle_policy_ == PeerConnectionInterface::kBundlePolicyMaxBundle) {
Peter Thatcher4eddf182015-04-30 10:55:59 -07001750 const cricket::ContentGroup* bundle_group = desc->GetGroupByName(
1751 cricket::GROUP_TYPE_BUNDLE);
1752 if (!bundle_group) {
Donald Curtis0e209b02015-03-24 09:29:54 -07001753 LOG(LS_WARNING) << "max-bundle specified without BUNDLE specified";
1754 return false;
1755 }
Peter Thatcher4eddf182015-04-30 10:55:59 -07001756 if (!BaseSession::BundleContentGroup(bundle_group)) {
Donald Curtis0e209b02015-03-24 09:29:54 -07001757 LOG(LS_WARNING) << "max-bundle failed to enable bundling.";
1758 return false;
1759 }
1760 }
1761
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762 return true;
1763}
1764
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001765bool WebRtcSession::CreateVoiceChannel(const cricket::ContentInfo* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 voice_channel_.reset(channel_manager_->CreateVoiceChannel(
Jelena Marusicc28a8962015-05-29 15:05:44 +02001767 this, content->name, true, audio_options_));
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001768 if (!voice_channel_) {
wu@webrtc.orgde305012013-10-31 15:40:38 +00001769 return false;
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001770 }
wu@webrtc.orgde305012013-10-31 15:40:38 +00001771
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001772 voice_channel_->SignalDtlsSetupFailure.connect(
1773 this, &WebRtcSession::OnDtlsSetupFailure);
wu@webrtc.orgde305012013-10-31 15:40:38 +00001774 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775}
1776
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001777bool WebRtcSession::CreateVideoChannel(const cricket::ContentInfo* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 video_channel_.reset(channel_manager_->CreateVideoChannel(
buildbot@webrtc.org1ecbe452014-10-14 20:29:28 +00001779 this, content->name, true, video_options_, voice_channel_.get()));
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001780 if (!video_channel_) {
1781 return false;
1782 }
1783
1784 video_channel_->SignalDtlsSetupFailure.connect(
1785 this, &WebRtcSession::OnDtlsSetupFailure);
1786 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787}
1788
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001789bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content) {
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001790 bool sctp = (data_channel_type_ == cricket::DCT_SCTP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791 data_channel_.reset(channel_manager_->CreateDataChannel(
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001792 this, content->name, !sctp, data_channel_type_));
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001793 if (!data_channel_) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001794 return false;
1795 }
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001796
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001797 if (sctp) {
1798 mediastream_signaling_->OnDataTransportCreatedForSctp();
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001799 data_channel_->SignalDataReceived.connect(
1800 this, &WebRtcSession::OnDataChannelMessageReceived);
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +00001801 data_channel_->SignalStreamClosedRemotely.connect(
1802 mediastream_signaling_,
1803 &MediaStreamSignaling::OnRemoteSctpDataChannelClosed);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001804 }
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001805
1806 data_channel_->SignalDtlsSetupFailure.connect(
1807 this, &WebRtcSession::OnDtlsSetupFailure);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001808 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809}
1810
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +00001811void WebRtcSession::OnDtlsSetupFailure(cricket::BaseChannel*, bool rtcp) {
1812 SetError(BaseSession::ERROR_TRANSPORT, rtcp ? kDtlsSetupFailureRtcp :
1813 kDtlsSetupFailureRtp);
1814}
1815
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816void WebRtcSession::CopySavedCandidates(
1817 SessionDescriptionInterface* dest_desc) {
1818 if (!dest_desc) {
1819 ASSERT(false);
1820 return;
1821 }
1822 for (size_t i = 0; i < saved_candidates_.size(); ++i) {
1823 dest_desc->AddCandidate(saved_candidates_[i]);
1824 delete saved_candidates_[i];
1825 }
1826 saved_candidates_.clear();
1827}
1828
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001829void WebRtcSession::OnDataChannelMessageReceived(
1830 cricket::DataChannel* channel,
1831 const cricket::ReceiveDataParams& params,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001832 const rtc::Buffer& payload) {
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +00001833 ASSERT(data_channel_type_ == cricket::DCT_SCTP);
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001834 if (params.type == cricket::DMT_CONTROL &&
1835 mediastream_signaling_->IsSctpSidAvailable(params.ssrc)) {
1836 // Received CONTROL on unused sid, process as an OPEN message.
1837 mediastream_signaling_->AddDataChannelFromOpenMessage(params, payload);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001838 }
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001839 // otherwise ignore the message.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001840}
1841
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001842// Returns false if bundle is enabled and rtcp_mux is disabled.
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001843bool WebRtcSession::ValidateBundleSettings(const SessionDescription* desc) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001844 bool bundle_enabled = desc->HasGroup(cricket::GROUP_TYPE_BUNDLE);
1845 if (!bundle_enabled)
1846 return true;
1847
1848 const cricket::ContentGroup* bundle_group =
1849 desc->GetGroupByName(cricket::GROUP_TYPE_BUNDLE);
1850 ASSERT(bundle_group != NULL);
1851
1852 const cricket::ContentInfos& contents = desc->contents();
1853 for (cricket::ContentInfos::const_iterator citer = contents.begin();
1854 citer != contents.end(); ++citer) {
1855 const cricket::ContentInfo* content = (&*citer);
1856 ASSERT(content != NULL);
1857 if (bundle_group->HasContentName(content->name) &&
1858 !content->rejected && content->type == cricket::NS_JINGLE_RTP) {
1859 if (!HasRtcpMuxEnabled(content))
1860 return false;
1861 }
1862 }
1863 // RTCP-MUX is enabled in all the contents.
1864 return true;
1865}
1866
1867bool WebRtcSession::HasRtcpMuxEnabled(
1868 const cricket::ContentInfo* content) {
1869 const cricket::MediaContentDescription* description =
1870 static_cast<cricket::MediaContentDescription*>(content->description);
1871 return description->rtcp_mux();
1872}
1873
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001874bool WebRtcSession::ValidateSessionDescription(
1875 const SessionDescriptionInterface* sdesc,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001876 cricket::ContentSource source, std::string* err_desc) {
1877 std::string type;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001878 if (error() != cricket::BaseSession::ERROR_NONE) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001879 return BadSdp(source, type, GetSessionErrorMsg(), err_desc);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001880 }
1881
1882 if (!sdesc || !sdesc->description()) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001883 return BadSdp(source, type, kInvalidSdp, err_desc);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001884 }
1885
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001886 type = sdesc->type();
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001887 Action action = GetAction(sdesc->type());
1888 if (source == cricket::CS_LOCAL) {
1889 if (!ExpectSetLocalDescription(action))
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001890 return BadLocalSdp(type, BadStateErrMsg(state()), err_desc);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001891 } else {
1892 if (!ExpectSetRemoteDescription(action))
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001893 return BadRemoteSdp(type, BadStateErrMsg(state()), err_desc);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001894 }
1895
1896 // Verify crypto settings.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00001897 std::string crypto_error;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001898 if ((webrtc_session_desc_factory_->SdesPolicy() == cricket::SEC_REQUIRED ||
1899 dtls_enabled_) &&
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00001900 !VerifyCrypto(sdesc->description(), dtls_enabled_, &crypto_error)) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001901 return BadSdp(source, type, crypto_error, err_desc);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001902 }
1903
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001904 // Verify ice-ufrag and ice-pwd.
1905 if (!VerifyIceUfragPwdPresent(sdesc->description())) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001906 return BadSdp(source, type, kSdpWithoutIceUfragPwd, err_desc);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001907 }
1908
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001909 if (!ValidateBundleSettings(sdesc->description())) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001910 return BadSdp(source, type, kBundleWithoutRtcpMux, err_desc);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001911 }
1912
1913 // Verify m-lines in Answer when compared against Offer.
1914 if (action == kAnswer) {
1915 const cricket::SessionDescription* offer_desc =
1916 (source == cricket::CS_LOCAL) ? remote_description()->description() :
1917 local_description()->description();
1918 if (!VerifyMediaDescriptions(sdesc->description(), offer_desc)) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001919 return BadAnswerSdp(source, kMlineMismatch, err_desc);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001920 }
1921 }
1922
1923 return true;
1924}
1925
1926bool WebRtcSession::ExpectSetLocalDescription(Action action) {
1927 return ((action == kOffer && state() == STATE_INIT) ||
1928 // update local offer
1929 (action == kOffer && state() == STATE_SENTINITIATE) ||
1930 // update the current ongoing session.
1931 (action == kOffer && state() == STATE_RECEIVEDACCEPT) ||
1932 (action == kOffer && state() == STATE_SENTACCEPT) ||
1933 (action == kOffer && state() == STATE_INPROGRESS) ||
1934 // accept remote offer
1935 (action == kAnswer && state() == STATE_RECEIVEDINITIATE) ||
1936 (action == kAnswer && state() == STATE_SENTPRACCEPT) ||
1937 (action == kPrAnswer && state() == STATE_RECEIVEDINITIATE) ||
1938 (action == kPrAnswer && state() == STATE_SENTPRACCEPT));
1939}
1940
1941bool WebRtcSession::ExpectSetRemoteDescription(Action action) {
1942 return ((action == kOffer && state() == STATE_INIT) ||
1943 // update remote offer
1944 (action == kOffer && state() == STATE_RECEIVEDINITIATE) ||
1945 // update the current ongoing session
1946 (action == kOffer && state() == STATE_RECEIVEDACCEPT) ||
1947 (action == kOffer && state() == STATE_SENTACCEPT) ||
1948 (action == kOffer && state() == STATE_INPROGRESS) ||
1949 // accept local offer
1950 (action == kAnswer && state() == STATE_SENTINITIATE) ||
1951 (action == kAnswer && state() == STATE_RECEIVEDPRACCEPT) ||
1952 (action == kPrAnswer && state() == STATE_SENTINITIATE) ||
1953 (action == kPrAnswer && state() == STATE_RECEIVEDPRACCEPT));
1954}
1955
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001956std::string WebRtcSession::GetSessionErrorMsg() {
1957 std::ostringstream desc;
1958 desc << kSessionError << GetErrorCodeString(error()) << ". ";
1959 desc << kSessionErrorDesc << error_desc() << ".";
1960 return desc.str();
1961}
1962
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00001963// We need to check the local/remote description for the Transport instead of
1964// the session, because a new Transport added during renegotiation may have
1965// them unset while the session has them set from the previous negotiation.
1966// Not doing so may trigger the auto generation of transport description and
1967// mess up DTLS identity information, ICE credential, etc.
1968bool WebRtcSession::ReadyToUseRemoteCandidate(
1969 const IceCandidateInterface* candidate,
1970 const SessionDescriptionInterface* remote_desc,
1971 bool* valid) {
1972 *valid = true;;
1973 cricket::TransportProxy* transport_proxy = NULL;
1974
1975 const SessionDescriptionInterface* current_remote_desc =
1976 remote_desc ? remote_desc : remote_description();
1977
1978 if (!current_remote_desc)
1979 return false;
1980
1981 size_t mediacontent_index =
1982 static_cast<size_t>(candidate->sdp_mline_index());
1983 size_t remote_content_size =
1984 current_remote_desc->description()->contents().size();
1985 if (mediacontent_index >= remote_content_size) {
1986 LOG(LS_ERROR)
1987 << "ReadyToUseRemoteCandidate: Invalid candidate media index.";
1988
1989 *valid = false;
1990 return false;
1991 }
1992
1993 cricket::ContentInfo content =
1994 current_remote_desc->description()->contents()[mediacontent_index];
1995 transport_proxy = GetTransportProxy(content.name);
1996
1997 return transport_proxy && transport_proxy->local_description_set() &&
1998 transport_proxy->remote_description_set();
1999}
2000
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00002001// Walk through the ConnectionInfos to gather best connection usage
2002// for IPv4 and IPv6.
jbauchac8869e2015-07-03 01:36:14 -07002003void WebRtcSession::ReportBestConnectionState(
2004 const cricket::TransportStats& stats) {
2005 DCHECK(metrics_observer_ != NULL);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00002006 for (cricket::TransportChannelStatsList::const_iterator it =
2007 stats.channel_stats.begin();
2008 it != stats.channel_stats.end(); ++it) {
2009 for (cricket::ConnectionInfos::const_iterator it_info =
2010 it->connection_infos.begin();
2011 it_info != it->connection_infos.end(); ++it_info) {
2012 if (!it_info->best_connection) {
2013 continue;
2014 }
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07002015
2016 PeerConnectionEnumCounterType type = kPeerConnectionEnumCounterMax;
2017 const cricket::Candidate& local = it_info->local_candidate;
2018 const cricket::Candidate& remote = it_info->remote_candidate;
2019
2020 // Increment the counter for IceCandidatePairType.
2021 if (local.protocol() == cricket::TCP_PROTOCOL_NAME ||
2022 (local.type() == RELAY_PORT_TYPE &&
2023 local.relay_protocol() == cricket::TCP_PROTOCOL_NAME)) {
2024 type = kEnumCounterIceCandidatePairTypeTcp;
2025 } else if (local.protocol() == cricket::UDP_PROTOCOL_NAME) {
2026 type = kEnumCounterIceCandidatePairTypeUdp;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00002027 } else {
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07002028 CHECK(0);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00002029 }
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07002030 metrics_observer_->IncrementEnumCounter(
2031 type, GetIceCandidatePairCounter(local, remote),
2032 kIceCandidatePairMax);
2033
2034 // Increment the counter for IP type.
2035 if (local.address().family() == AF_INET) {
2036 // TODO(guoweis): Remove this next line once IncrementEnumCounter
2037 // implemented for PeerConnectionMetrics.
2038 metrics_observer_->IncrementCounter(kBestConnections_IPv4);
2039
2040 metrics_observer_->IncrementEnumCounter(
2041 kEnumCounterAddressFamily, kBestConnections_IPv4,
2042 kPeerConnectionAddressFamilyCounter_Max);
2043
2044 } else if (local.address().family() == AF_INET6) {
2045 // TODO(guoweis): Remove this next line.
2046 metrics_observer_->IncrementCounter(kBestConnections_IPv6);
2047
2048 metrics_observer_->IncrementEnumCounter(
2049 kEnumCounterAddressFamily, kBestConnections_IPv6,
2050 kPeerConnectionAddressFamilyCounter_Max);
2051 } else {
2052 CHECK(0);
2053 }
2054
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00002055 return;
2056 }
2057 }
2058}
2059
jbauchac8869e2015-07-03 01:36:14 -07002060void WebRtcSession::ReportNegotiatedCiphers(
2061 const cricket::TransportStats& stats) {
2062 DCHECK(metrics_observer_ != NULL);
2063 if (!dtls_enabled_ || stats.channel_stats.empty()) {
2064 return;
2065 }
2066
2067 const std::string& srtp_cipher = stats.channel_stats[0].srtp_cipher;
2068 const std::string& ssl_cipher = stats.channel_stats[0].ssl_cipher;
2069 if (srtp_cipher.empty() && ssl_cipher.empty()) {
2070 return;
2071 }
2072
2073 PeerConnectionMetricsName srtp_name;
2074 PeerConnectionMetricsName ssl_name;
2075 if (stats.content_name == cricket::CN_AUDIO) {
2076 srtp_name = kAudioSrtpCipher;
2077 ssl_name = kAudioSslCipher;
2078 } else if (stats.content_name == cricket::CN_VIDEO) {
2079 srtp_name = kVideoSrtpCipher;
2080 ssl_name = kVideoSslCipher;
2081 } else if (stats.content_name == cricket::CN_DATA) {
2082 srtp_name = kDataSrtpCipher;
2083 ssl_name = kDataSslCipher;
2084 } else {
2085 RTC_NOTREACHED();
2086 return;
2087 }
2088
2089 if (!srtp_cipher.empty()) {
2090 metrics_observer_->AddHistogramSample(srtp_name, srtp_cipher);
2091 }
2092 if (!ssl_cipher.empty()) {
2093 metrics_observer_->AddHistogramSample(ssl_name, ssl_cipher);
2094 }
2095}
2096
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097} // namespace webrtc