blob: ae81f24923d278a4e73e6622fff001f4952df279 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2012, Google Inc.
4 *
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"
47#include "webrtc/base/helpers.h"
48#include "webrtc/base/logging.h"
49#include "webrtc/base/stringencode.h"
50#include "webrtc/base/stringutils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051
52using cricket::ContentInfo;
53using cricket::ContentInfos;
54using cricket::MediaContentDescription;
55using cricket::SessionDescription;
56using cricket::TransportInfo;
57
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058namespace webrtc {
59
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060// Error messages
henrike@webrtc.org1e09a712013-07-26 19:17:59 +000061const char kBundleWithoutRtcpMux[] = "RTCP-MUX must be enabled when BUNDLE "
62 "is enabled.";
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000063const char kCreateChannelFailed[] = "Failed to create channels.";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064const char kInvalidCandidates[] = "Description contains invalid candidates.";
65const char kInvalidSdp[] = "Invalid session description.";
66const char kMlineMismatch[] =
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000067 "Offer and answer descriptions m-lines are not matching. Rejecting answer.";
68const char kPushDownTDFailed[] =
69 "Failed to push down transport description:";
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000070const char kSdpWithoutDtlsFingerprint[] =
71 "Called with SDP without DTLS fingerprint.";
72const char kSdpWithoutSdesCrypto[] =
73 "Called with SDP without SDES crypto.";
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000074const char kSdpWithoutIceUfragPwd[] =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000075 "Called with SDP without ice-ufrag and ice-pwd.";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076const char kSessionError[] = "Session error code: ";
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000077const char kSessionErrorDesc[] = "Session error description: ";
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000078const int kMaxUnsignalledRecvStreams = 20;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079
80// Compares |answer| against |offer|. Comparision is done
81// for number of m-lines in answer against offer. If matches true will be
82// returned otherwise false.
83static bool VerifyMediaDescriptions(
84 const SessionDescription* answer, const SessionDescription* offer) {
85 if (offer->contents().size() != answer->contents().size())
86 return false;
87
88 for (size_t i = 0; i < offer->contents().size(); ++i) {
89 if ((offer->contents()[i].name) != answer->contents()[i].name) {
90 return false;
91 }
wu@webrtc.org4e393072014-04-07 17:04:35 +000092 const MediaContentDescription* offer_mdesc =
93 static_cast<const MediaContentDescription*>(
94 offer->contents()[i].description);
95 const MediaContentDescription* answer_mdesc =
96 static_cast<const MediaContentDescription*>(
97 answer->contents()[i].description);
98 if (offer_mdesc->type() != answer_mdesc->type()) {
99 return false;
100 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101 }
102 return true;
103}
104
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105// Checks that each non-rejected content has SDES crypto keys or a DTLS
106// fingerprint. Mismatches, such as replying with a DTLS fingerprint to SDES
107// keys, will be caught in Transport negotiation, and backstopped by Channel's
108// |secure_required| check.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000109static bool VerifyCrypto(const SessionDescription* desc,
110 bool dtls_enabled,
111 std::string* error) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112 const ContentInfos& contents = desc->contents();
113 for (size_t index = 0; index < contents.size(); ++index) {
114 const ContentInfo* cinfo = &contents[index];
115 if (cinfo->rejected) {
116 continue;
117 }
118
119 // If the content isn't rejected, crypto must be present.
120 const MediaContentDescription* media =
121 static_cast<const MediaContentDescription*>(cinfo->description);
122 const TransportInfo* tinfo = desc->GetTransportInfoByName(cinfo->name);
123 if (!media || !tinfo) {
124 // Something is not right.
125 LOG(LS_ERROR) << kInvalidSdp;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000126 *error = kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127 return false;
128 }
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000129 if (dtls_enabled) {
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000130 if (!tinfo->description.identity_fingerprint) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000131 LOG(LS_WARNING) <<
132 "Session description must have DTLS fingerprint if DTLS enabled.";
133 *error = kSdpWithoutDtlsFingerprint;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000134 return false;
135 }
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000136 } else {
137 if (media->cryptos().empty()) {
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000138 LOG(LS_WARNING) <<
139 "Session description must have SDES when DTLS disabled.";
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000140 *error = kSdpWithoutSdesCrypto;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000141 return false;
142 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143 }
144 }
145
146 return true;
147}
148
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000149// Checks that each non-rejected content has ice-ufrag and ice-pwd set.
150static bool VerifyIceUfragPwdPresent(const SessionDescription* desc) {
151 const ContentInfos& contents = desc->contents();
152 for (size_t index = 0; index < contents.size(); ++index) {
153 const ContentInfo* cinfo = &contents[index];
154 if (cinfo->rejected) {
155 continue;
156 }
157
158 // If the content isn't rejected, ice-ufrag and ice-pwd must be present.
159 const TransportInfo* tinfo = desc->GetTransportInfoByName(cinfo->name);
160 if (!tinfo) {
161 // Something is not right.
162 LOG(LS_ERROR) << kInvalidSdp;
163 return false;
164 }
165 if (tinfo->description.ice_ufrag.empty() ||
166 tinfo->description.ice_pwd.empty()) {
167 LOG(LS_ERROR) << "Session description must have ice ufrag and pwd.";
168 return false;
169 }
170 }
171 return true;
172}
173
wu@webrtc.org91053e72013-08-10 07:18:04 +0000174// Forces |sdesc->crypto_required| to the appropriate state based on the
175// current security policy, to ensure a failure occurs if there is an error
176// in crypto negotiation.
177// Called when processing the local session description.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000178static void UpdateSessionDescriptionSecurePolicy(cricket::CryptoType type,
179 SessionDescription* sdesc) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000180 if (!sdesc) {
181 return;
182 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183
wu@webrtc.org91053e72013-08-10 07:18:04 +0000184 // Updating the |crypto_required_| in MediaContentDescription to the
185 // appropriate state based on the current security policy.
186 for (cricket::ContentInfos::iterator iter = sdesc->contents().begin();
187 iter != sdesc->contents().end(); ++iter) {
188 if (cricket::IsMediaContent(&*iter)) {
189 MediaContentDescription* mdesc =
190 static_cast<MediaContentDescription*> (iter->description);
191 if (mdesc) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000192 mdesc->set_crypto_required(type);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000193 }
194 }
195 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196}
197
198static bool GetAudioSsrcByTrackId(
199 const SessionDescription* session_description,
200 const std::string& track_id, uint32 *ssrc) {
201 const cricket::ContentInfo* audio_info =
202 cricket::GetFirstAudioContent(session_description);
203 if (!audio_info) {
204 LOG(LS_ERROR) << "Audio not used in this call";
205 return false;
206 }
207
208 const cricket::MediaContentDescription* audio_content =
209 static_cast<const cricket::MediaContentDescription*>(
210 audio_info->description);
211 cricket::StreamParams stream;
212 if (!cricket::GetStreamByIds(audio_content->streams(), "", track_id,
213 &stream)) {
214 return false;
215 }
216 *ssrc = stream.first_ssrc();
217 return true;
218}
219
220static bool GetTrackIdBySsrc(const SessionDescription* session_description,
221 uint32 ssrc, std::string* track_id) {
222 ASSERT(track_id != NULL);
223
224 cricket::StreamParams stream_out;
225 const cricket::ContentInfo* audio_info =
226 cricket::GetFirstAudioContent(session_description);
jiayl@webrtc.orge21cc9a2014-08-28 22:21:34 +0000227 if (audio_info) {
228 const cricket::MediaContentDescription* audio_content =
229 static_cast<const cricket::MediaContentDescription*>(
230 audio_info->description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231
jiayl@webrtc.orge21cc9a2014-08-28 22:21:34 +0000232 if (cricket::GetStreamBySsrc(audio_content->streams(), ssrc, &stream_out)) {
233 *track_id = stream_out.id;
234 return true;
235 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236 }
237
238 const cricket::ContentInfo* video_info =
239 cricket::GetFirstVideoContent(session_description);
jiayl@webrtc.orge21cc9a2014-08-28 22:21:34 +0000240 if (video_info) {
241 const cricket::MediaContentDescription* video_content =
242 static_cast<const cricket::MediaContentDescription*>(
243 video_info->description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244
jiayl@webrtc.orge21cc9a2014-08-28 22:21:34 +0000245 if (cricket::GetStreamBySsrc(video_content->streams(), ssrc, &stream_out)) {
246 *track_id = stream_out.id;
247 return true;
248 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 }
250 return false;
251}
252
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000253static bool BadSdp(const std::string& source,
254 const std::string& type,
255 const std::string& reason,
256 std::string* err_desc) {
257 std::ostringstream desc;
258 desc << "Failed to set " << source << " " << type << " sdp: " << reason;
259
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260 if (err_desc) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000261 *err_desc = desc.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000263 LOG(LS_ERROR) << desc.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 return false;
265}
266
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267static bool BadSdp(cricket::ContentSource source,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000268 const std::string& type,
269 const std::string& reason,
270 std::string* err_desc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 if (source == cricket::CS_LOCAL) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000272 return BadSdp("local", type, reason, err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273 } else {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000274 return BadSdp("remote", type, reason, err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275 }
276}
277
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000278static bool BadLocalSdp(const std::string& type,
279 const std::string& reason,
280 std::string* err_desc) {
281 return BadSdp(cricket::CS_LOCAL, type, reason, err_desc);
282}
283
284static bool BadRemoteSdp(const std::string& type,
285 const std::string& reason,
286 std::string* err_desc) {
287 return BadSdp(cricket::CS_REMOTE, type, reason, err_desc);
288}
289
290static bool BadOfferSdp(cricket::ContentSource source,
291 const std::string& reason,
292 std::string* err_desc) {
293 return BadSdp(source, SessionDescriptionInterface::kOffer, reason, err_desc);
294}
295
296static bool BadPranswerSdp(cricket::ContentSource source,
297 const std::string& reason,
298 std::string* err_desc) {
299 return BadSdp(source, SessionDescriptionInterface::kPrAnswer,
300 reason, err_desc);
301}
302
303static bool BadAnswerSdp(cricket::ContentSource source,
304 const std::string& reason,
305 std::string* err_desc) {
306 return BadSdp(source, SessionDescriptionInterface::kAnswer, reason, err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307}
308
309#define GET_STRING_OF_STATE(state) \
310 case cricket::BaseSession::state: \
311 result = #state; \
312 break;
313
314static std::string GetStateString(cricket::BaseSession::State state) {
315 std::string result;
316 switch (state) {
317 GET_STRING_OF_STATE(STATE_INIT)
318 GET_STRING_OF_STATE(STATE_SENTINITIATE)
319 GET_STRING_OF_STATE(STATE_RECEIVEDINITIATE)
320 GET_STRING_OF_STATE(STATE_SENTPRACCEPT)
321 GET_STRING_OF_STATE(STATE_SENTACCEPT)
322 GET_STRING_OF_STATE(STATE_RECEIVEDPRACCEPT)
323 GET_STRING_OF_STATE(STATE_RECEIVEDACCEPT)
324 GET_STRING_OF_STATE(STATE_SENTMODIFY)
325 GET_STRING_OF_STATE(STATE_RECEIVEDMODIFY)
326 GET_STRING_OF_STATE(STATE_SENTREJECT)
327 GET_STRING_OF_STATE(STATE_RECEIVEDREJECT)
328 GET_STRING_OF_STATE(STATE_SENTREDIRECT)
329 GET_STRING_OF_STATE(STATE_SENTTERMINATE)
330 GET_STRING_OF_STATE(STATE_RECEIVEDTERMINATE)
331 GET_STRING_OF_STATE(STATE_INPROGRESS)
332 GET_STRING_OF_STATE(STATE_DEINIT)
333 default:
334 ASSERT(false);
335 break;
336 }
337 return result;
338}
339
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000340#define GET_STRING_OF_ERROR_CODE(err) \
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341 case cricket::BaseSession::err: \
342 result = #err; \
343 break;
344
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000345static std::string GetErrorCodeString(cricket::BaseSession::Error err) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 std::string result;
347 switch (err) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000348 GET_STRING_OF_ERROR_CODE(ERROR_NONE)
349 GET_STRING_OF_ERROR_CODE(ERROR_TIME)
350 GET_STRING_OF_ERROR_CODE(ERROR_RESPONSE)
351 GET_STRING_OF_ERROR_CODE(ERROR_NETWORK)
352 GET_STRING_OF_ERROR_CODE(ERROR_CONTENT)
353 GET_STRING_OF_ERROR_CODE(ERROR_TRANSPORT)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 default:
355 ASSERT(false);
356 break;
357 }
358 return result;
359}
360
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000361static std::string MakeErrorString(const std::string& error,
362 const std::string& desc) {
363 std::ostringstream ret;
364 ret << error << " " << desc;
365 return ret.str();
366}
367
368static std::string MakeTdErrorString(const std::string& desc) {
369 return MakeErrorString(kPushDownTDFailed, desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370}
371
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000372// Set |option| to the highest-priority value of |key| in the optional
373// constraints if the key is found and has a valid value.
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000374template<typename T>
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000375static void SetOptionFromOptionalConstraint(
376 const MediaConstraintsInterface* constraints,
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000377 const std::string& key, cricket::Settable<T>* option) {
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000378 if (!constraints) {
379 return;
380 }
381 std::string string_value;
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000382 T value;
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000383 if (constraints->GetOptional().FindFirst(key, &string_value)) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000384 if (rtc::FromString(string_value, &value)) {
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000385 option->Set(value);
386 }
387 }
388}
389
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390// Help class used to remember if a a remote peer has requested ice restart by
391// by sending a description with new ice ufrag and password.
392class IceRestartAnswerLatch {
393 public:
394 IceRestartAnswerLatch() : ice_restart_(false) { }
395
wu@webrtc.org91053e72013-08-10 07:18:04 +0000396 // Returns true if CheckForRemoteIceRestart has been called with a new session
397 // description where ice password and ufrag has changed since last time
398 // Reset() was called.
399 bool Get() const {
400 return ice_restart_;
401 }
402
403 void Reset() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404 if (ice_restart_) {
405 ice_restart_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000406 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000407 }
408
409 void CheckForRemoteIceRestart(
410 const SessionDescriptionInterface* old_desc,
411 const SessionDescriptionInterface* new_desc) {
412 if (!old_desc || new_desc->type() != SessionDescriptionInterface::kOffer) {
413 return;
414 }
415 const SessionDescription* new_sd = new_desc->description();
416 const SessionDescription* old_sd = old_desc->description();
417 const ContentInfos& contents = new_sd->contents();
418 for (size_t index = 0; index < contents.size(); ++index) {
419 const ContentInfo* cinfo = &contents[index];
420 if (cinfo->rejected) {
421 continue;
422 }
423 // If the content isn't rejected, check if ufrag and password has
424 // changed.
425 const cricket::TransportDescription* new_transport_desc =
426 new_sd->GetTransportDescriptionByName(cinfo->name);
427 const cricket::TransportDescription* old_transport_desc =
428 old_sd->GetTransportDescriptionByName(cinfo->name);
429 if (!new_transport_desc || !old_transport_desc) {
430 // No transport description exist. This is not an ice restart.
431 continue;
432 }
jiayl@webrtc.orgdb397e52014-06-20 16:32:09 +0000433 if (cricket::IceCredentialsChanged(old_transport_desc->ice_ufrag,
434 old_transport_desc->ice_pwd,
435 new_transport_desc->ice_ufrag,
436 new_transport_desc->ice_pwd)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437 LOG(LS_INFO) << "Remote peer request ice restart.";
438 ice_restart_ = true;
439 break;
440 }
441 }
442 }
443
444 private:
445 bool ice_restart_;
446};
447
wu@webrtc.org91053e72013-08-10 07:18:04 +0000448WebRtcSession::WebRtcSession(
449 cricket::ChannelManager* channel_manager,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000450 rtc::Thread* signaling_thread,
451 rtc::Thread* worker_thread,
wu@webrtc.org91053e72013-08-10 07:18:04 +0000452 cricket::PortAllocator* port_allocator,
453 MediaStreamSignaling* mediastream_signaling)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000454 : cricket::BaseSession(signaling_thread, worker_thread, port_allocator,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000455 rtc::ToString(rtc::CreateRandomId64() &
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000456 LLONG_MAX),
457 cricket::NS_JINGLE_RTP, false),
458 // RFC 3264: The numeric value of the session id and version in the
459 // o line MUST be representable with a "64 bit signed integer".
460 // Due to this constraint session id |sid_| is max limited to LLONG_MAX.
461 channel_manager_(channel_manager),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462 mediastream_signaling_(mediastream_signaling),
463 ice_observer_(NULL),
464 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465 older_version_remote_peer_(false),
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000466 dtls_enabled_(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000467 data_channel_type_(cricket::DCT_NONE),
468 ice_restart_latch_(new IceRestartAnswerLatch) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469}
470
471WebRtcSession::~WebRtcSession() {
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000472 // Destroy video_channel_ first since it may have a pointer to the
473 // voice_channel_.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000474 if (video_channel_.get()) {
475 SignalVideoChannelDestroyed();
476 channel_manager_->DestroyVideoChannel(video_channel_.release());
477 }
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000478 if (voice_channel_.get()) {
479 SignalVoiceChannelDestroyed();
480 channel_manager_->DestroyVoiceChannel(voice_channel_.release());
481 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482 if (data_channel_.get()) {
483 SignalDataChannelDestroyed();
484 channel_manager_->DestroyDataChannel(data_channel_.release());
485 }
486 for (size_t i = 0; i < saved_candidates_.size(); ++i) {
487 delete saved_candidates_[i];
488 }
489 delete identity();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000490}
491
wu@webrtc.org91053e72013-08-10 07:18:04 +0000492bool WebRtcSession::Initialize(
wu@webrtc.org97077a32013-10-25 21:18:33 +0000493 const PeerConnectionFactoryInterface::Options& options,
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000494 const MediaConstraintsInterface* constraints,
495 DTLSIdentityServiceInterface* dtls_identity_service,
496 PeerConnectionInterface::IceTransportsType ice_transport) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000497 // TODO(perkj): Take |constraints| into consideration. Return false if not all
498 // mandatory constraints can be fulfilled. Note that |constraints|
499 // can be null.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000500 bool value;
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000501
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000502 if (options.disable_encryption) {
503 dtls_enabled_ = false;
504 } else {
505 // Enable DTLS by default if |dtls_identity_service| is valid.
506 dtls_enabled_ = (dtls_identity_service != NULL);
507 // |constraints| can override the default |dtls_enabled_| value.
508 if (FindConstraint(
509 constraints,
510 MediaConstraintsInterface::kEnableDtlsSrtp,
511 &value, NULL)) {
512 dtls_enabled_ = value;
513 }
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000514 }
515
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000516 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000517 // It takes precendence over the disable_sctp_data_channels
518 // PeerConnectionFactoryInterface::Options.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519 if (FindConstraint(
520 constraints, MediaConstraintsInterface::kEnableRtpDataChannels,
521 &value, NULL) && value) {
522 LOG(LS_INFO) << "Allowing RTP data engine.";
523 data_channel_type_ = cricket::DCT_RTP;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000524 } else {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000525 // DTLS has to be enabled to use SCTP.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000526 if (!options.disable_sctp_data_channels && dtls_enabled_) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000527 LOG(LS_INFO) << "Allowing SCTP data engine.";
528 data_channel_type_ = cricket::DCT_SCTP;
529 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000530 }
531 if (data_channel_type_ != cricket::DCT_NONE) {
532 mediastream_signaling_->SetDataChannelFactory(this);
533 }
534
wu@webrtc.orgde305012013-10-31 15:40:38 +0000535 // Find DSCP constraint.
536 if (FindConstraint(
537 constraints,
538 MediaConstraintsInterface::kEnableDscp,
539 &value, NULL)) {
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +0000540 audio_options_.dscp.Set(value);
541 video_options_.dscp.Set(value);
542 }
543
544 // Find Suspend Below Min Bitrate constraint.
545 if (FindConstraint(
546 constraints,
547 MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
548 &value,
549 NULL)) {
550 video_options_.suspend_below_min_bitrate.Set(value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000551 }
552
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000553 SetOptionFromOptionalConstraint(constraints,
554 MediaConstraintsInterface::kScreencastMinBitrate,
555 &video_options_.screencast_min_bitrate);
556
557 // Find constraints for cpu overuse detection.
558 SetOptionFromOptionalConstraint(constraints,
559 MediaConstraintsInterface::kCpuUnderuseThreshold,
560 &video_options_.cpu_underuse_threshold);
561 SetOptionFromOptionalConstraint(constraints,
562 MediaConstraintsInterface::kCpuOveruseThreshold,
563 &video_options_.cpu_overuse_threshold);
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000564 SetOptionFromOptionalConstraint(constraints,
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000565 MediaConstraintsInterface::kCpuOveruseDetection,
566 &video_options_.cpu_overuse_detection);
567 SetOptionFromOptionalConstraint(constraints,
568 MediaConstraintsInterface::kCpuOveruseEncodeUsage,
569 &video_options_.cpu_overuse_encode_usage);
570 SetOptionFromOptionalConstraint(constraints,
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000571 MediaConstraintsInterface::kCpuUnderuseEncodeRsdThreshold,
572 &video_options_.cpu_underuse_encode_rsd_threshold);
573 SetOptionFromOptionalConstraint(constraints,
574 MediaConstraintsInterface::kCpuOveruseEncodeRsdThreshold,
575 &video_options_.cpu_overuse_encode_rsd_threshold);
buildbot@webrtc.orgdb563902014-06-13 13:05:48 +0000576
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000577 // Find payload padding constraint.
578 SetOptionFromOptionalConstraint(constraints,
579 MediaConstraintsInterface::kPayloadPadding,
580 &video_options_.use_payload_padding);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000581
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000582 SetOptionFromOptionalConstraint(constraints,
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000583 MediaConstraintsInterface::kNumUnsignalledRecvStreams,
584 &video_options_.unsignalled_recv_stream_limit);
585 if (video_options_.unsignalled_recv_stream_limit.IsSet()) {
586 int stream_limit;
587 video_options_.unsignalled_recv_stream_limit.Get(&stream_limit);
588 stream_limit = rtc::_min(kMaxUnsignalledRecvStreams, stream_limit);
589 stream_limit = rtc::_max(0, stream_limit);
590 video_options_.unsignalled_recv_stream_limit.Set(stream_limit);
591 }
592
593 SetOptionFromOptionalConstraint(constraints,
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000594 MediaConstraintsInterface::kHighStartBitrate,
595 &video_options_.video_start_bitrate);
wu@webrtc.orgcfe5e9c2014-03-27 17:03:58 +0000596
597 if (FindConstraint(
598 constraints,
599 MediaConstraintsInterface::kVeryHighBitrate,
600 &value,
601 NULL)) {
602 video_options_.video_highest_bitrate.Set(
603 cricket::VideoOptions::VERY_HIGH);
604 } else if (FindConstraint(
605 constraints,
606 MediaConstraintsInterface::kHighBitrate,
607 &value,
608 NULL)) {
609 video_options_.video_highest_bitrate.Set(
610 cricket::VideoOptions::HIGH);
611 }
612
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000613 SetOptionFromOptionalConstraint(constraints,
614 MediaConstraintsInterface::kCombinedAudioVideoBwe,
615 &audio_options_.combined_audio_video_bwe);
616
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000617 const cricket::VideoCodec default_codec(
618 JsepSessionDescription::kDefaultVideoCodecId,
619 JsepSessionDescription::kDefaultVideoCodecName,
620 JsepSessionDescription::kMaxVideoCodecWidth,
621 JsepSessionDescription::kMaxVideoCodecHeight,
622 JsepSessionDescription::kDefaultVideoCodecFramerate,
623 JsepSessionDescription::kDefaultVideoCodecPreference);
624 channel_manager_->SetDefaultVideoEncoderConfig(
625 cricket::VideoEncoderConfig(default_codec));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000626
627 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
628 signaling_thread(),
629 channel_manager_,
630 mediastream_signaling_,
631 dtls_identity_service,
632 this,
633 id(),
634 data_channel_type_,
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000635 dtls_enabled_));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000636
637 webrtc_session_desc_factory_->SignalIdentityReady.connect(
638 this, &WebRtcSession::OnIdentityReady);
mallinath@webrtc.org7e809c32013-09-30 18:59:08 +0000639
wu@webrtc.org97077a32013-10-25 21:18:33 +0000640 if (options.disable_encryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000641 webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED);
mallinath@webrtc.org7e809c32013-09-30 18:59:08 +0000642 }
643
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000644 return true;
645}
646
647void WebRtcSession::Terminate() {
648 SetState(STATE_RECEIVEDTERMINATE);
649 RemoveUnusedChannelsAndTransports(NULL);
650 ASSERT(voice_channel_.get() == NULL);
651 ASSERT(video_channel_.get() == NULL);
652 ASSERT(data_channel_.get() == NULL);
653}
654
655bool WebRtcSession::StartCandidatesAllocation() {
656 // SpeculativelyConnectTransportChannels, will call ConnectChannels method
657 // from TransportProxy to start gathering ice candidates.
658 SpeculativelyConnectAllTransportChannels();
659 if (!saved_candidates_.empty()) {
660 // If there are saved candidates which arrived before local description is
661 // set, copy those to remote description.
662 CopySavedCandidates(remote_desc_.get());
663 }
664 // Push remote candidates present in remote description to transport channels.
665 UseCandidatesInSessionDescription(remote_desc_.get());
666 return true;
667}
668
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000669void WebRtcSession::SetSdesPolicy(cricket::SecurePolicy secure_policy) {
670 webrtc_session_desc_factory_->SetSdesPolicy(secure_policy);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000671}
672
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000673cricket::SecurePolicy WebRtcSession::SdesPolicy() const {
674 return webrtc_session_desc_factory_->SdesPolicy();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675}
676
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000677bool WebRtcSession::GetSslRole(rtc::SSLRole* role) {
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000678 if (local_description() == NULL || remote_description() == NULL) {
679 LOG(LS_INFO) << "Local and Remote descriptions must be applied to get "
680 << "SSL Role of the session.";
681 return false;
682 }
683
684 // TODO(mallinath) - Return role of each transport, as role may differ from
685 // one another.
686 // In current implementaion we just return the role of first transport in the
687 // transport map.
688 for (cricket::TransportMap::const_iterator iter = transport_proxies().begin();
689 iter != transport_proxies().end(); ++iter) {
690 if (iter->second->impl()) {
691 return iter->second->impl()->GetSslRole(role);
692 }
693 }
694 return false;
695}
696
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000697void WebRtcSession::CreateOffer(
698 CreateSessionDescriptionObserver* observer,
699 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
700 webrtc_session_desc_factory_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000701}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702
wu@webrtc.org91053e72013-08-10 07:18:04 +0000703void WebRtcSession::CreateAnswer(CreateSessionDescriptionObserver* observer,
704 const MediaConstraintsInterface* constraints) {
705 webrtc_session_desc_factory_->CreateAnswer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706}
707
708bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc,
709 std::string* err_desc) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000710 // Takes the ownership of |desc| regardless of the result.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000711 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000712
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000713 // Validate SDP.
714 if (!ValidateSessionDescription(desc, cricket::CS_LOCAL, err_desc)) {
715 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716 }
717
718 // Update the initiator flag if this session is the initiator.
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000719 Action action = GetAction(desc->type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000720 if (state() == STATE_INIT && action == kOffer) {
721 set_initiator(true);
722 }
723
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000724 cricket::SecurePolicy sdes_policy =
725 webrtc_session_desc_factory_->SdesPolicy();
726 cricket::CryptoType crypto_required = dtls_enabled_ ?
727 cricket::CT_DTLS : (sdes_policy == cricket::SEC_REQUIRED ?
728 cricket::CT_SDES : cricket::CT_NONE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 // Update the MediaContentDescription crypto settings as per the policy set.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000730 UpdateSessionDescriptionSecurePolicy(crypto_required, desc->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000731
732 set_local_description(desc->description()->Copy());
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000733 local_desc_.reset(desc_temp.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734
735 // Transport and Media channels will be created only when offer is set.
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000736 if (action == kOffer && !CreateChannels(local_desc_->description())) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 // TODO(mallinath) - Handle CreateChannel failure, as new local description
738 // is applied. Restore back to old description.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000739 return BadLocalSdp(desc->type(), kCreateChannelFailed, err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 }
741
742 // Remove channel and transport proxies, if MediaContentDescription is
743 // rejected.
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000744 RemoveUnusedChannelsAndTransports(local_desc_->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000746 if (!UpdateSessionState(action, cricket::CS_LOCAL, err_desc)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747 return false;
748 }
749 // Kick starting the ice candidates allocation.
750 StartCandidatesAllocation();
751
752 // Update state and SSRC of local MediaStreams and DataChannels based on the
753 // local session description.
754 mediastream_signaling_->OnLocalDescriptionChanged(local_desc_.get());
755
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000756 rtc::SSLRole role;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000757 if (data_channel_type_ == cricket::DCT_SCTP && GetSslRole(&role)) {
758 mediastream_signaling_->OnDtlsRoleReadyForSctp(role);
759 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 if (error() != cricket::BaseSession::ERROR_NONE) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000761 return BadLocalSdp(desc->type(), GetSessionErrorMsg(), err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762 }
763 return true;
764}
765
766bool WebRtcSession::SetRemoteDescription(SessionDescriptionInterface* desc,
767 std::string* err_desc) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000768 // Takes the ownership of |desc| regardless of the result.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000769 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000770
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000771 // Validate SDP.
772 if (!ValidateSessionDescription(desc, cricket::CS_REMOTE, err_desc)) {
773 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 }
775
776 // Transport and Media channels will be created only when offer is set.
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000777 Action action = GetAction(desc->type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778 if (action == kOffer && !CreateChannels(desc->description())) {
779 // TODO(mallinath) - Handle CreateChannel failure, as new local description
780 // is applied. Restore back to old description.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000781 return BadRemoteSdp(desc->type(), kCreateChannelFailed, err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782 }
783
784 // Remove channel and transport proxies, if MediaContentDescription is
785 // rejected.
786 RemoveUnusedChannelsAndTransports(desc->description());
787
788 // NOTE: Candidates allocation will be initiated only when SetLocalDescription
789 // is called.
790 set_remote_description(desc->description()->Copy());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000791 if (!UpdateSessionState(action, cricket::CS_REMOTE, err_desc)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 return false;
793 }
794
795 // Update remote MediaStreams.
796 mediastream_signaling_->OnRemoteDescriptionChanged(desc);
797 if (local_description() && !UseCandidatesInSessionDescription(desc)) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000798 return BadRemoteSdp(desc->type(), kInvalidCandidates, err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 }
800
801 // Copy all saved candidates.
802 CopySavedCandidates(desc);
803 // We retain all received candidates.
wu@webrtc.org91053e72013-08-10 07:18:04 +0000804 WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription(
805 remote_desc_.get(), desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 // Check if this new SessionDescription contains new ice ufrag and password
807 // that indicates the remote peer requests ice restart.
808 ice_restart_latch_->CheckForRemoteIceRestart(remote_desc_.get(),
809 desc);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000810 remote_desc_.reset(desc_temp.release());
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000811
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000812 rtc::SSLRole role;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000813 if (data_channel_type_ == cricket::DCT_SCTP && GetSslRole(&role)) {
814 mediastream_signaling_->OnDtlsRoleReadyForSctp(role);
815 }
816
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 if (error() != cricket::BaseSession::ERROR_NONE) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000818 return BadRemoteSdp(desc->type(), GetSessionErrorMsg(), err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 }
820 return true;
821}
822
823bool WebRtcSession::UpdateSessionState(
824 Action action, cricket::ContentSource source,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 std::string* err_desc) {
826 // If there's already a pending error then no state transition should happen.
827 // But all call-sites should be verifying this before calling us!
828 ASSERT(error() == cricket::BaseSession::ERROR_NONE);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000829 std::string td_err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830 if (action == kOffer) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000831 if (!PushdownTransportDescription(source, cricket::CA_OFFER, &td_err)) {
832 return BadOfferSdp(source, MakeTdErrorString(td_err), err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833 }
834 SetState(source == cricket::CS_LOCAL ?
835 STATE_SENTINITIATE : STATE_RECEIVEDINITIATE);
836 if (error() != cricket::BaseSession::ERROR_NONE) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000837 return BadOfferSdp(source, GetSessionErrorMsg(), err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 }
839 } else if (action == kPrAnswer) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000840 if (!PushdownTransportDescription(source, cricket::CA_PRANSWER, &td_err)) {
841 return BadPranswerSdp(source, MakeTdErrorString(td_err), err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 }
843 EnableChannels();
844 SetState(source == cricket::CS_LOCAL ?
845 STATE_SENTPRACCEPT : STATE_RECEIVEDPRACCEPT);
846 if (error() != cricket::BaseSession::ERROR_NONE) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000847 return BadPranswerSdp(source, GetSessionErrorMsg(), err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 }
849 } else if (action == kAnswer) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000850 if (!PushdownTransportDescription(source, cricket::CA_ANSWER, &td_err)) {
851 return BadAnswerSdp(source, MakeTdErrorString(td_err), err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 }
853 MaybeEnableMuxingSupport();
854 EnableChannels();
855 SetState(source == cricket::CS_LOCAL ?
856 STATE_SENTACCEPT : STATE_RECEIVEDACCEPT);
857 if (error() != cricket::BaseSession::ERROR_NONE) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000858 return BadAnswerSdp(source, GetSessionErrorMsg(), err_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 }
860 }
861 return true;
862}
863
864WebRtcSession::Action WebRtcSession::GetAction(const std::string& type) {
865 if (type == SessionDescriptionInterface::kOffer) {
866 return WebRtcSession::kOffer;
867 } else if (type == SessionDescriptionInterface::kPrAnswer) {
868 return WebRtcSession::kPrAnswer;
869 } else if (type == SessionDescriptionInterface::kAnswer) {
870 return WebRtcSession::kAnswer;
871 }
872 ASSERT(false && "unknown action type");
873 return WebRtcSession::kOffer;
874}
875
876bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) {
877 if (state() == STATE_INIT) {
878 LOG(LS_ERROR) << "ProcessIceMessage: ICE candidates can't be added "
879 << "without any offer (local or remote) "
880 << "session description.";
881 return false;
882 }
883
884 if (!candidate) {
885 LOG(LS_ERROR) << "ProcessIceMessage: Candidate is NULL";
886 return false;
887 }
888
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +0000889 bool valid = false;
890 if (!ReadyToUseRemoteCandidate(candidate, NULL, &valid)) {
891 if (valid) {
892 LOG(LS_INFO) << "ProcessIceMessage: Candidate saved";
893 saved_candidates_.push_back(
894 new JsepIceCandidate(candidate->sdp_mid(),
895 candidate->sdp_mline_index(),
896 candidate->candidate()));
buildbot@webrtc.org61c1b8e2014-04-09 06:06:38 +0000897 }
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +0000898 return valid;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 }
900
901 // Add this candidate to the remote session description.
902 if (!remote_desc_->AddCandidate(candidate)) {
903 LOG(LS_ERROR) << "ProcessIceMessage: Candidate cannot be used";
904 return false;
905 }
906
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +0000907 return UseCandidate(candidate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908}
909
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000910bool WebRtcSession::UpdateIce(PeerConnectionInterface::IceTransportsType type) {
911 return false;
912}
913
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000914bool WebRtcSession::GetLocalTrackIdBySsrc(uint32 ssrc, std::string* track_id) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 if (!BaseSession::local_description())
916 return false;
917 return webrtc::GetTrackIdBySsrc(
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000918 BaseSession::local_description(), ssrc, track_id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919}
920
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000921bool WebRtcSession::GetRemoteTrackIdBySsrc(uint32 ssrc, std::string* track_id) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 if (!BaseSession::remote_description())
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000923 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924 return webrtc::GetTrackIdBySsrc(
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000925 BaseSession::remote_description(), ssrc, track_id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926}
927
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000928std::string WebRtcSession::BadStateErrMsg(State state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 std::ostringstream desc;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000930 desc << "Called in wrong state: " << GetStateString(state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 return desc.str();
932}
933
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000934void WebRtcSession::SetAudioPlayout(uint32 ssrc, bool enable,
935 cricket::AudioRenderer* renderer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 ASSERT(signaling_thread()->IsCurrent());
937 if (!voice_channel_) {
938 LOG(LS_ERROR) << "SetAudioPlayout: No audio channel exists.";
939 return;
940 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000941 if (!voice_channel_->SetRemoteRenderer(ssrc, renderer)) {
942 // SetRenderer() can fail if the ssrc does not match any playout channel.
943 LOG(LS_ERROR) << "SetAudioPlayout: ssrc is incorrect: " << ssrc;
944 return;
945 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946 if (!voice_channel_->SetOutputScaling(ssrc, enable ? 1 : 0, enable ? 1 : 0)) {
947 // Allow that SetOutputScaling fail if |enable| is false but assert
948 // otherwise. This in the normal case when the underlying media channel has
949 // already been deleted.
950 ASSERT(enable == false);
951 }
952}
953
954void WebRtcSession::SetAudioSend(uint32 ssrc, bool enable,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000955 const cricket::AudioOptions& options,
956 cricket::AudioRenderer* renderer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 ASSERT(signaling_thread()->IsCurrent());
958 if (!voice_channel_) {
959 LOG(LS_ERROR) << "SetAudioSend: No audio channel exists.";
960 return;
961 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000962 if (!voice_channel_->SetLocalRenderer(ssrc, renderer)) {
963 // SetRenderer() can fail if the ssrc does not match any send channel.
964 LOG(LS_ERROR) << "SetAudioSend: ssrc is incorrect: " << ssrc;
965 return;
966 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 if (!voice_channel_->MuteStream(ssrc, !enable)) {
968 // Allow that MuteStream fail if |enable| is false but assert otherwise.
969 // This in the normal case when the underlying media channel has already
970 // been deleted.
971 ASSERT(enable == false);
972 return;
973 }
974 if (enable)
975 voice_channel_->SetChannelOptions(options);
976}
977
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000978void WebRtcSession::SetAudioPlayoutVolume(uint32 ssrc, double volume) {
979 ASSERT(signaling_thread()->IsCurrent());
980 ASSERT(volume >= 0 && volume <= 10);
981 if (!voice_channel_) {
982 LOG(LS_ERROR) << "SetAudioPlayoutVolume: No audio channel exists.";
983 return;
984 }
985
986 if (!voice_channel_->SetOutputScaling(ssrc, volume, volume))
987 ASSERT(false);
988}
989
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990bool WebRtcSession::SetCaptureDevice(uint32 ssrc,
991 cricket::VideoCapturer* camera) {
992 ASSERT(signaling_thread()->IsCurrent());
993
994 if (!video_channel_.get()) {
995 // |video_channel_| doesnt't exist. Probably because the remote end doesnt't
996 // support video.
997 LOG(LS_WARNING) << "Video not used in this call.";
998 return false;
999 }
1000 if (!video_channel_->SetCapturer(ssrc, camera)) {
1001 // Allow that SetCapturer fail if |camera| is NULL but assert otherwise.
1002 // This in the normal case when the underlying media channel has already
1003 // been deleted.
1004 ASSERT(camera == NULL);
1005 return false;
1006 }
1007 return true;
1008}
1009
1010void WebRtcSession::SetVideoPlayout(uint32 ssrc,
1011 bool enable,
1012 cricket::VideoRenderer* renderer) {
1013 ASSERT(signaling_thread()->IsCurrent());
1014 if (!video_channel_) {
1015 LOG(LS_WARNING) << "SetVideoPlayout: No video channel exists.";
1016 return;
1017 }
1018 if (!video_channel_->SetRenderer(ssrc, enable ? renderer : NULL)) {
1019 // Allow that SetRenderer fail if |renderer| is NULL but assert otherwise.
1020 // This in the normal case when the underlying media channel has already
1021 // been deleted.
1022 ASSERT(renderer == NULL);
1023 }
1024}
1025
1026void WebRtcSession::SetVideoSend(uint32 ssrc, bool enable,
1027 const cricket::VideoOptions* options) {
1028 ASSERT(signaling_thread()->IsCurrent());
1029 if (!video_channel_) {
1030 LOG(LS_WARNING) << "SetVideoSend: No video channel exists.";
1031 return;
1032 }
1033 if (!video_channel_->MuteStream(ssrc, !enable)) {
1034 // Allow that MuteStream fail if |enable| is false but assert otherwise.
1035 // This in the normal case when the underlying media channel has already
1036 // been deleted.
1037 ASSERT(enable == false);
1038 return;
1039 }
1040 if (enable && options)
1041 video_channel_->SetChannelOptions(*options);
1042}
1043
1044bool WebRtcSession::CanInsertDtmf(const std::string& track_id) {
1045 ASSERT(signaling_thread()->IsCurrent());
1046 if (!voice_channel_) {
1047 LOG(LS_ERROR) << "CanInsertDtmf: No audio channel exists.";
1048 return false;
1049 }
1050 uint32 send_ssrc = 0;
1051 // The Dtmf is negotiated per channel not ssrc, so we only check if the ssrc
1052 // exists.
1053 if (!GetAudioSsrcByTrackId(BaseSession::local_description(), track_id,
1054 &send_ssrc)) {
1055 LOG(LS_ERROR) << "CanInsertDtmf: Track does not exist: " << track_id;
1056 return false;
1057 }
1058 return voice_channel_->CanInsertDtmf();
1059}
1060
1061bool WebRtcSession::InsertDtmf(const std::string& track_id,
1062 int code, int duration) {
1063 ASSERT(signaling_thread()->IsCurrent());
1064 if (!voice_channel_) {
1065 LOG(LS_ERROR) << "InsertDtmf: No audio channel exists.";
1066 return false;
1067 }
1068 uint32 send_ssrc = 0;
1069 if (!VERIFY(GetAudioSsrcByTrackId(BaseSession::local_description(),
1070 track_id, &send_ssrc))) {
1071 LOG(LS_ERROR) << "InsertDtmf: Track does not exist: " << track_id;
1072 return false;
1073 }
1074 if (!voice_channel_->InsertDtmf(send_ssrc, code, duration,
1075 cricket::DF_SEND)) {
1076 LOG(LS_ERROR) << "Failed to insert DTMF to channel.";
1077 return false;
1078 }
1079 return true;
1080}
1081
1082sigslot::signal0<>* WebRtcSession::GetOnDestroyedSignal() {
1083 return &SignalVoiceChannelDestroyed;
1084}
1085
wu@webrtc.org78187522013-10-07 23:32:02 +00001086bool WebRtcSession::SendData(const cricket::SendDataParams& params,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001087 const rtc::Buffer& payload,
wu@webrtc.org78187522013-10-07 23:32:02 +00001088 cricket::SendDataResult* result) {
1089 if (!data_channel_.get()) {
1090 LOG(LS_ERROR) << "SendData called when data_channel_ is NULL.";
1091 return false;
1092 }
1093 return data_channel_->SendData(params, payload, result);
1094}
1095
1096bool WebRtcSession::ConnectDataChannel(DataChannel* webrtc_data_channel) {
1097 if (!data_channel_.get()) {
1098 LOG(LS_ERROR) << "ConnectDataChannel called when data_channel_ is NULL.";
1099 return false;
1100 }
wu@webrtc.org78187522013-10-07 23:32:02 +00001101 data_channel_->SignalReadyToSendData.connect(webrtc_data_channel,
1102 &DataChannel::OnChannelReady);
1103 data_channel_->SignalDataReceived.connect(webrtc_data_channel,
1104 &DataChannel::OnDataReceived);
wu@webrtc.org78187522013-10-07 23:32:02 +00001105 return true;
1106}
1107
1108void WebRtcSession::DisconnectDataChannel(DataChannel* webrtc_data_channel) {
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001109 if (!data_channel_.get()) {
1110 LOG(LS_ERROR) << "DisconnectDataChannel called when data_channel_ is NULL.";
1111 return;
1112 }
wu@webrtc.org78187522013-10-07 23:32:02 +00001113 data_channel_->SignalReadyToSendData.disconnect(webrtc_data_channel);
1114 data_channel_->SignalDataReceived.disconnect(webrtc_data_channel);
1115}
1116
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00001117void WebRtcSession::AddSctpDataStream(uint32 sid) {
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001118 if (!data_channel_.get()) {
1119 LOG(LS_ERROR) << "AddDataChannelStreams called when data_channel_ is NULL.";
1120 return;
1121 }
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00001122 data_channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(sid));
1123 data_channel_->AddSendStream(cricket::StreamParams::CreateLegacy(sid));
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001124}
1125
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00001126void WebRtcSession::RemoveSctpDataStream(uint32 sid) {
jiayl@webrtc.org2eaac182014-06-17 16:02:46 +00001127 mediastream_signaling_->RemoveSctpDataChannel(static_cast<int>(sid));
1128
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001129 if (!data_channel_.get()) {
1130 LOG(LS_ERROR) << "RemoveDataChannelStreams called when data_channel_ is "
1131 << "NULL.";
1132 return;
1133 }
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00001134 data_channel_->RemoveRecvStream(sid);
1135 data_channel_->RemoveSendStream(sid);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001136}
1137
wu@webrtc.org07a6fbe2013-11-04 18:41:34 +00001138bool WebRtcSession::ReadyToSendData() const {
1139 return data_channel_.get() && data_channel_->ready_to_send_data();
1140}
1141
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001142rtc::scoped_refptr<DataChannel> WebRtcSession::CreateDataChannel(
wu@webrtc.org78187522013-10-07 23:32:02 +00001143 const std::string& label,
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001144 const InternalDataChannelInit* config) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001145 if (state() == STATE_RECEIVEDTERMINATE) {
1146 return NULL;
1147 }
1148 if (data_channel_type_ == cricket::DCT_NONE) {
1149 LOG(LS_ERROR) << "CreateDataChannel: Data is not supported in this call.";
1150 return NULL;
1151 }
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001152 InternalDataChannelInit new_config =
1153 config ? (*config) : InternalDataChannelInit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001154 if (data_channel_type_ == cricket::DCT_SCTP) {
1155 if (new_config.id < 0) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001156 rtc::SSLRole role;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001157 if (GetSslRole(&role) &&
1158 !mediastream_signaling_->AllocateSctpSid(role, &new_config.id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001159 LOG(LS_ERROR) << "No id can be allocated for the SCTP data channel.";
1160 return NULL;
1161 }
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001162 } else if (!mediastream_signaling_->IsSctpSidAvailable(new_config.id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001163 LOG(LS_ERROR) << "Failed to create a SCTP data channel "
1164 << "because the id is already in use or out of range.";
1165 return NULL;
1166 }
1167 }
wu@webrtc.org91053e72013-08-10 07:18:04 +00001168
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001169 rtc::scoped_refptr<DataChannel> channel(DataChannel::Create(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001170 this, data_channel_type_, label, new_config));
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001171 if (channel && !mediastream_signaling_->AddDataChannel(channel))
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001172 return NULL;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001173
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001174 return channel;
1175}
1176
1177cricket::DataChannelType WebRtcSession::data_channel_type() const {
1178 return data_channel_type_;
1179}
1180
wu@webrtc.org91053e72013-08-10 07:18:04 +00001181bool WebRtcSession::IceRestartPending() const {
1182 return ice_restart_latch_->Get();
1183}
1184
1185void WebRtcSession::ResetIceRestartLatch() {
1186 ice_restart_latch_->Reset();
1187}
1188
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001189void WebRtcSession::OnIdentityReady(rtc::SSLIdentity* identity) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001190 SetIdentity(identity);
1191}
1192
1193bool WebRtcSession::waiting_for_identity() const {
1194 return webrtc_session_desc_factory_->waiting_for_identity();
1195}
1196
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001197void WebRtcSession::SetIceConnectionState(
1198 PeerConnectionInterface::IceConnectionState state) {
1199 if (ice_connection_state_ == state) {
1200 return;
1201 }
1202
1203 // ASSERT that the requested transition is allowed. Note that
1204 // WebRtcSession does not implement "kIceConnectionClosed" (that is handled
1205 // within PeerConnection). This switch statement should compile away when
1206 // ASSERTs are disabled.
1207 switch (ice_connection_state_) {
1208 case PeerConnectionInterface::kIceConnectionNew:
1209 ASSERT(state == PeerConnectionInterface::kIceConnectionChecking);
1210 break;
1211 case PeerConnectionInterface::kIceConnectionChecking:
1212 ASSERT(state == PeerConnectionInterface::kIceConnectionFailed ||
1213 state == PeerConnectionInterface::kIceConnectionConnected);
1214 break;
1215 case PeerConnectionInterface::kIceConnectionConnected:
1216 ASSERT(state == PeerConnectionInterface::kIceConnectionDisconnected ||
1217 state == PeerConnectionInterface::kIceConnectionChecking ||
1218 state == PeerConnectionInterface::kIceConnectionCompleted);
1219 break;
1220 case PeerConnectionInterface::kIceConnectionCompleted:
1221 ASSERT(state == PeerConnectionInterface::kIceConnectionConnected ||
1222 state == PeerConnectionInterface::kIceConnectionDisconnected);
1223 break;
1224 case PeerConnectionInterface::kIceConnectionFailed:
1225 ASSERT(state == PeerConnectionInterface::kIceConnectionNew);
1226 break;
1227 case PeerConnectionInterface::kIceConnectionDisconnected:
1228 ASSERT(state == PeerConnectionInterface::kIceConnectionChecking ||
1229 state == PeerConnectionInterface::kIceConnectionConnected ||
1230 state == PeerConnectionInterface::kIceConnectionCompleted ||
1231 state == PeerConnectionInterface::kIceConnectionFailed);
1232 break;
1233 case PeerConnectionInterface::kIceConnectionClosed:
1234 ASSERT(false);
1235 break;
1236 default:
1237 ASSERT(false);
1238 break;
1239 }
1240
1241 ice_connection_state_ = state;
1242 if (ice_observer_) {
1243 ice_observer_->OnIceConnectionChange(ice_connection_state_);
1244 }
1245}
1246
1247void WebRtcSession::OnTransportRequestSignaling(
1248 cricket::Transport* transport) {
1249 ASSERT(signaling_thread()->IsCurrent());
1250 transport->OnSignalingReady();
1251 if (ice_observer_) {
1252 ice_observer_->OnIceGatheringChange(
1253 PeerConnectionInterface::kIceGatheringGathering);
1254 }
1255}
1256
1257void WebRtcSession::OnTransportConnecting(cricket::Transport* transport) {
1258 ASSERT(signaling_thread()->IsCurrent());
1259 // start monitoring for the write state of the transport.
1260 OnTransportWritable(transport);
1261}
1262
1263void WebRtcSession::OnTransportWritable(cricket::Transport* transport) {
1264 ASSERT(signaling_thread()->IsCurrent());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265 if (transport->all_channels_writable()) {
henrike@webrtc.org05376342014-03-10 15:53:12 +00001266 SetIceConnectionState(PeerConnectionInterface::kIceConnectionConnected);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001267 } else if (transport->HasChannels()) {
1268 // If the current state is Connected or Completed, then there were writable
1269 // channels but now there are not, so the next state must be Disconnected.
1270 if (ice_connection_state_ ==
1271 PeerConnectionInterface::kIceConnectionConnected ||
1272 ice_connection_state_ ==
1273 PeerConnectionInterface::kIceConnectionCompleted) {
1274 SetIceConnectionState(
1275 PeerConnectionInterface::kIceConnectionDisconnected);
1276 }
1277 }
1278}
1279
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001280void WebRtcSession::OnTransportCompleted(cricket::Transport* transport) {
1281 ASSERT(signaling_thread()->IsCurrent());
1282 SetIceConnectionState(PeerConnectionInterface::kIceConnectionCompleted);
1283}
1284
1285void WebRtcSession::OnTransportFailed(cricket::Transport* transport) {
1286 ASSERT(signaling_thread()->IsCurrent());
1287 SetIceConnectionState(PeerConnectionInterface::kIceConnectionFailed);
1288}
1289
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290void WebRtcSession::OnTransportProxyCandidatesReady(
1291 cricket::TransportProxy* proxy, const cricket::Candidates& candidates) {
1292 ASSERT(signaling_thread()->IsCurrent());
1293 ProcessNewLocalCandidate(proxy->content_name(), candidates);
1294}
1295
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296void WebRtcSession::OnCandidatesAllocationDone() {
1297 ASSERT(signaling_thread()->IsCurrent());
1298 if (ice_observer_) {
1299 ice_observer_->OnIceGatheringChange(
1300 PeerConnectionInterface::kIceGatheringComplete);
1301 ice_observer_->OnIceComplete();
1302 }
1303}
1304
1305// Enabling voice and video channel.
1306void WebRtcSession::EnableChannels() {
1307 if (voice_channel_ && !voice_channel_->enabled())
1308 voice_channel_->Enable(true);
1309
1310 if (video_channel_ && !video_channel_->enabled())
1311 video_channel_->Enable(true);
1312
1313 if (data_channel_.get() && !data_channel_->enabled())
1314 data_channel_->Enable(true);
1315}
1316
1317void WebRtcSession::ProcessNewLocalCandidate(
1318 const std::string& content_name,
1319 const cricket::Candidates& candidates) {
1320 int sdp_mline_index;
1321 if (!GetLocalCandidateMediaIndex(content_name, &sdp_mline_index)) {
1322 LOG(LS_ERROR) << "ProcessNewLocalCandidate: content name "
1323 << content_name << " not found";
1324 return;
1325 }
1326
1327 for (cricket::Candidates::const_iterator citer = candidates.begin();
1328 citer != candidates.end(); ++citer) {
1329 // Use content_name as the candidate media id.
1330 JsepIceCandidate candidate(content_name, sdp_mline_index, *citer);
1331 if (ice_observer_) {
1332 ice_observer_->OnIceCandidate(&candidate);
1333 }
1334 if (local_desc_) {
1335 local_desc_->AddCandidate(&candidate);
1336 }
1337 }
1338}
1339
1340// Returns the media index for a local ice candidate given the content name.
1341bool WebRtcSession::GetLocalCandidateMediaIndex(const std::string& content_name,
1342 int* sdp_mline_index) {
1343 if (!BaseSession::local_description() || !sdp_mline_index)
1344 return false;
1345
1346 bool content_found = false;
1347 const ContentInfos& contents = BaseSession::local_description()->contents();
1348 for (size_t index = 0; index < contents.size(); ++index) {
1349 if (contents[index].name == content_name) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001350 *sdp_mline_index = static_cast<int>(index);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001351 content_found = true;
1352 break;
1353 }
1354 }
1355 return content_found;
1356}
1357
1358bool WebRtcSession::UseCandidatesInSessionDescription(
1359 const SessionDescriptionInterface* remote_desc) {
1360 if (!remote_desc)
1361 return true;
1362 bool ret = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00001363
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001364 for (size_t m = 0; m < remote_desc->number_of_mediasections(); ++m) {
1365 const IceCandidateCollection* candidates = remote_desc->candidates(m);
1366 for (size_t n = 0; n < candidates->count(); ++n) {
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00001367 const IceCandidateInterface* candidate = candidates->at(n);
1368 bool valid = false;
1369 if (!ReadyToUseRemoteCandidate(candidate, remote_desc, &valid)) {
1370 if (valid) {
1371 LOG(LS_INFO) << "UseCandidatesInSessionDescription: Candidate saved.";
1372 saved_candidates_.push_back(
1373 new JsepIceCandidate(candidate->sdp_mid(),
1374 candidate->sdp_mline_index(),
1375 candidate->candidate()));
1376 }
1377 continue;
1378 }
1379
1380 ret = UseCandidate(candidate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001381 if (!ret)
1382 break;
1383 }
1384 }
1385 return ret;
1386}
1387
1388bool WebRtcSession::UseCandidate(
1389 const IceCandidateInterface* candidate) {
1390
1391 size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index());
1392 size_t remote_content_size =
1393 BaseSession::remote_description()->contents().size();
1394 if (mediacontent_index >= remote_content_size) {
1395 LOG(LS_ERROR)
1396 << "UseRemoteCandidateInSession: Invalid candidate media index.";
1397 return false;
1398 }
1399
1400 cricket::ContentInfo content =
1401 BaseSession::remote_description()->contents()[mediacontent_index];
1402 std::vector<cricket::Candidate> candidates;
1403 candidates.push_back(candidate->candidate());
1404 // Invoking BaseSession method to handle remote candidates.
1405 std::string error;
1406 if (OnRemoteCandidates(content.name, candidates, &error)) {
1407 // Candidates successfully submitted for checking.
1408 if (ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew ||
1409 ice_connection_state_ ==
1410 PeerConnectionInterface::kIceConnectionDisconnected) {
1411 // If state is New, then the session has just gotten its first remote ICE
1412 // candidates, so go to Checking.
1413 // If state is Disconnected, the session is re-using old candidates or
1414 // receiving additional ones, so go to Checking.
1415 // If state is Connected, stay Connected.
1416 // TODO(bemasc): If state is Connected, and the new candidates are for a
1417 // newly added transport, then the state actually _should_ move to
1418 // checking. Add a way to distinguish that case.
1419 SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking);
1420 }
1421 // TODO(bemasc): If state is Completed, go back to Connected.
1422 } else {
fischman@webrtc.org4f2bd682014-03-28 18:13:34 +00001423 if (!error.empty()) {
1424 LOG(LS_WARNING) << error;
1425 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 }
1427 return true;
1428}
1429
1430void WebRtcSession::RemoveUnusedChannelsAndTransports(
1431 const SessionDescription* desc) {
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001432 // Destroy video_channel_ first since it may have a pointer to the
1433 // voice_channel_.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001434 const cricket::ContentInfo* video_info =
1435 cricket::GetFirstVideoContent(desc);
1436 if ((!video_info || video_info->rejected) && video_channel_) {
1437 mediastream_signaling_->OnVideoChannelClose();
1438 SignalVideoChannelDestroyed();
1439 const std::string content_name = video_channel_->content_name();
1440 channel_manager_->DestroyVideoChannel(video_channel_.release());
1441 DestroyTransportProxy(content_name);
1442 }
1443
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001444 const cricket::ContentInfo* voice_info =
1445 cricket::GetFirstAudioContent(desc);
1446 if ((!voice_info || voice_info->rejected) && voice_channel_) {
1447 mediastream_signaling_->OnAudioChannelClose();
1448 SignalVoiceChannelDestroyed();
1449 const std::string content_name = voice_channel_->content_name();
1450 channel_manager_->DestroyVoiceChannel(voice_channel_.release());
1451 DestroyTransportProxy(content_name);
1452 }
1453
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454 const cricket::ContentInfo* data_info =
1455 cricket::GetFirstDataContent(desc);
1456 if ((!data_info || data_info->rejected) && data_channel_) {
1457 mediastream_signaling_->OnDataChannelClose();
1458 SignalDataChannelDestroyed();
1459 const std::string content_name = data_channel_->content_name();
1460 channel_manager_->DestroyDataChannel(data_channel_.release());
1461 DestroyTransportProxy(content_name);
1462 }
1463}
1464
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001465// TODO(mallinath) - Add a correct error code if the channels are not creatued
1466// due to BUNDLE is enabled but rtcp-mux is disabled.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467bool WebRtcSession::CreateChannels(const SessionDescription* desc) {
1468 // Disabling the BUNDLE flag in PortAllocator if offer disabled it.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001469 bool bundle_enabled = desc->HasGroup(cricket::GROUP_TYPE_BUNDLE);
1470 if (state() == STATE_INIT && !bundle_enabled) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001471 port_allocator()->set_flags(port_allocator()->flags() &
1472 ~cricket::PORTALLOCATOR_ENABLE_BUNDLE);
1473 }
1474
1475 // Creating the media channels and transport proxies.
1476 const cricket::ContentInfo* voice = cricket::GetFirstAudioContent(desc);
1477 if (voice && !voice->rejected && !voice_channel_) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001478 if (!CreateVoiceChannel(voice)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001479 LOG(LS_ERROR) << "Failed to create voice channel.";
1480 return false;
1481 }
1482 }
1483
1484 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
1485 if (video && !video->rejected && !video_channel_) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001486 if (!CreateVideoChannel(video)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001487 LOG(LS_ERROR) << "Failed to create video channel.";
1488 return false;
1489 }
1490 }
1491
1492 const cricket::ContentInfo* data = cricket::GetFirstDataContent(desc);
1493 if (data_channel_type_ != cricket::DCT_NONE &&
1494 data && !data->rejected && !data_channel_.get()) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001495 if (!CreateDataChannel(data)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001496 LOG(LS_ERROR) << "Failed to create data channel.";
1497 return false;
1498 }
1499 }
1500
1501 return true;
1502}
1503
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001504bool WebRtcSession::CreateVoiceChannel(const cricket::ContentInfo* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001505 voice_channel_.reset(channel_manager_->CreateVoiceChannel(
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001506 this, content->name, true));
wu@webrtc.orgde305012013-10-31 15:40:38 +00001507 if (!voice_channel_.get())
1508 return false;
1509
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00001510 voice_channel_->SetChannelOptions(audio_options_);
wu@webrtc.orgde305012013-10-31 15:40:38 +00001511 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001512}
1513
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001514bool WebRtcSession::CreateVideoChannel(const cricket::ContentInfo* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001515 video_channel_.reset(channel_manager_->CreateVideoChannel(
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001516 this, content->name, true, voice_channel_.get()));
wu@webrtc.orgde305012013-10-31 15:40:38 +00001517 if (!video_channel_.get())
1518 return false;
1519
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00001520 video_channel_->SetChannelOptions(video_options_);
wu@webrtc.orgde305012013-10-31 15:40:38 +00001521 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001522}
1523
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001524bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content) {
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001525 bool sctp = (data_channel_type_ == cricket::DCT_SCTP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 data_channel_.reset(channel_manager_->CreateDataChannel(
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001527 this, content->name, !sctp, data_channel_type_));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001528 if (!data_channel_.get()) {
1529 return false;
1530 }
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001531 if (sctp) {
1532 mediastream_signaling_->OnDataTransportCreatedForSctp();
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001533 data_channel_->SignalDataReceived.connect(
1534 this, &WebRtcSession::OnDataChannelMessageReceived);
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +00001535 data_channel_->SignalStreamClosedRemotely.connect(
1536 mediastream_signaling_,
1537 &MediaStreamSignaling::OnRemoteSctpDataChannelClosed);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001538 }
wu@webrtc.org91053e72013-08-10 07:18:04 +00001539 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001540}
1541
1542void WebRtcSession::CopySavedCandidates(
1543 SessionDescriptionInterface* dest_desc) {
1544 if (!dest_desc) {
1545 ASSERT(false);
1546 return;
1547 }
1548 for (size_t i = 0; i < saved_candidates_.size(); ++i) {
1549 dest_desc->AddCandidate(saved_candidates_[i]);
1550 delete saved_candidates_[i];
1551 }
1552 saved_candidates_.clear();
1553}
1554
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001555void WebRtcSession::OnDataChannelMessageReceived(
1556 cricket::DataChannel* channel,
1557 const cricket::ReceiveDataParams& params,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001558 const rtc::Buffer& payload) {
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +00001559 ASSERT(data_channel_type_ == cricket::DCT_SCTP);
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001560 if (params.type == cricket::DMT_CONTROL &&
1561 mediastream_signaling_->IsSctpSidAvailable(params.ssrc)) {
1562 // Received CONTROL on unused sid, process as an OPEN message.
1563 mediastream_signaling_->AddDataChannelFromOpenMessage(params, payload);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 }
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001565 // otherwise ignore the message.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566}
1567
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001568// Returns false if bundle is enabled and rtcp_mux is disabled.
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001569bool WebRtcSession::ValidateBundleSettings(const SessionDescription* desc) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001570 bool bundle_enabled = desc->HasGroup(cricket::GROUP_TYPE_BUNDLE);
1571 if (!bundle_enabled)
1572 return true;
1573
1574 const cricket::ContentGroup* bundle_group =
1575 desc->GetGroupByName(cricket::GROUP_TYPE_BUNDLE);
1576 ASSERT(bundle_group != NULL);
1577
1578 const cricket::ContentInfos& contents = desc->contents();
1579 for (cricket::ContentInfos::const_iterator citer = contents.begin();
1580 citer != contents.end(); ++citer) {
1581 const cricket::ContentInfo* content = (&*citer);
1582 ASSERT(content != NULL);
1583 if (bundle_group->HasContentName(content->name) &&
1584 !content->rejected && content->type == cricket::NS_JINGLE_RTP) {
1585 if (!HasRtcpMuxEnabled(content))
1586 return false;
1587 }
1588 }
1589 // RTCP-MUX is enabled in all the contents.
1590 return true;
1591}
1592
1593bool WebRtcSession::HasRtcpMuxEnabled(
1594 const cricket::ContentInfo* content) {
1595 const cricket::MediaContentDescription* description =
1596 static_cast<cricket::MediaContentDescription*>(content->description);
1597 return description->rtcp_mux();
1598}
1599
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001600bool WebRtcSession::ValidateSessionDescription(
1601 const SessionDescriptionInterface* sdesc,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001602 cricket::ContentSource source, std::string* err_desc) {
1603 std::string type;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001604 if (error() != cricket::BaseSession::ERROR_NONE) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001605 return BadSdp(source, type, GetSessionErrorMsg(), err_desc);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001606 }
1607
1608 if (!sdesc || !sdesc->description()) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001609 return BadSdp(source, type, kInvalidSdp, err_desc);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001610 }
1611
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001612 type = sdesc->type();
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001613 Action action = GetAction(sdesc->type());
1614 if (source == cricket::CS_LOCAL) {
1615 if (!ExpectSetLocalDescription(action))
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001616 return BadLocalSdp(type, BadStateErrMsg(state()), err_desc);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001617 } else {
1618 if (!ExpectSetRemoteDescription(action))
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001619 return BadRemoteSdp(type, BadStateErrMsg(state()), err_desc);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001620 }
1621
1622 // Verify crypto settings.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00001623 std::string crypto_error;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001624 if ((webrtc_session_desc_factory_->SdesPolicy() == cricket::SEC_REQUIRED ||
1625 dtls_enabled_) &&
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00001626 !VerifyCrypto(sdesc->description(), dtls_enabled_, &crypto_error)) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001627 return BadSdp(source, type, crypto_error, err_desc);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001628 }
1629
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001630 // Verify ice-ufrag and ice-pwd.
1631 if (!VerifyIceUfragPwdPresent(sdesc->description())) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001632 return BadSdp(source, type, kSdpWithoutIceUfragPwd, err_desc);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001633 }
1634
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001635 if (!ValidateBundleSettings(sdesc->description())) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001636 return BadSdp(source, type, kBundleWithoutRtcpMux, err_desc);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001637 }
1638
1639 // Verify m-lines in Answer when compared against Offer.
1640 if (action == kAnswer) {
1641 const cricket::SessionDescription* offer_desc =
1642 (source == cricket::CS_LOCAL) ? remote_description()->description() :
1643 local_description()->description();
1644 if (!VerifyMediaDescriptions(sdesc->description(), offer_desc)) {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001645 return BadAnswerSdp(source, kMlineMismatch, err_desc);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +00001646 }
1647 }
1648
1649 return true;
1650}
1651
1652bool WebRtcSession::ExpectSetLocalDescription(Action action) {
1653 return ((action == kOffer && state() == STATE_INIT) ||
1654 // update local offer
1655 (action == kOffer && state() == STATE_SENTINITIATE) ||
1656 // update the current ongoing session.
1657 (action == kOffer && state() == STATE_RECEIVEDACCEPT) ||
1658 (action == kOffer && state() == STATE_SENTACCEPT) ||
1659 (action == kOffer && state() == STATE_INPROGRESS) ||
1660 // accept remote offer
1661 (action == kAnswer && state() == STATE_RECEIVEDINITIATE) ||
1662 (action == kAnswer && state() == STATE_SENTPRACCEPT) ||
1663 (action == kPrAnswer && state() == STATE_RECEIVEDINITIATE) ||
1664 (action == kPrAnswer && state() == STATE_SENTPRACCEPT));
1665}
1666
1667bool WebRtcSession::ExpectSetRemoteDescription(Action action) {
1668 return ((action == kOffer && state() == STATE_INIT) ||
1669 // update remote offer
1670 (action == kOffer && state() == STATE_RECEIVEDINITIATE) ||
1671 // update the current ongoing session
1672 (action == kOffer && state() == STATE_RECEIVEDACCEPT) ||
1673 (action == kOffer && state() == STATE_SENTACCEPT) ||
1674 (action == kOffer && state() == STATE_INPROGRESS) ||
1675 // accept local offer
1676 (action == kAnswer && state() == STATE_SENTINITIATE) ||
1677 (action == kAnswer && state() == STATE_RECEIVEDPRACCEPT) ||
1678 (action == kPrAnswer && state() == STATE_SENTINITIATE) ||
1679 (action == kPrAnswer && state() == STATE_RECEIVEDPRACCEPT));
1680}
1681
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001682std::string WebRtcSession::GetSessionErrorMsg() {
1683 std::ostringstream desc;
1684 desc << kSessionError << GetErrorCodeString(error()) << ". ";
1685 desc << kSessionErrorDesc << error_desc() << ".";
1686 return desc.str();
1687}
1688
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00001689// We need to check the local/remote description for the Transport instead of
1690// the session, because a new Transport added during renegotiation may have
1691// them unset while the session has them set from the previous negotiation.
1692// Not doing so may trigger the auto generation of transport description and
1693// mess up DTLS identity information, ICE credential, etc.
1694bool WebRtcSession::ReadyToUseRemoteCandidate(
1695 const IceCandidateInterface* candidate,
1696 const SessionDescriptionInterface* remote_desc,
1697 bool* valid) {
1698 *valid = true;;
1699 cricket::TransportProxy* transport_proxy = NULL;
1700
1701 const SessionDescriptionInterface* current_remote_desc =
1702 remote_desc ? remote_desc : remote_description();
1703
1704 if (!current_remote_desc)
1705 return false;
1706
1707 size_t mediacontent_index =
1708 static_cast<size_t>(candidate->sdp_mline_index());
1709 size_t remote_content_size =
1710 current_remote_desc->description()->contents().size();
1711 if (mediacontent_index >= remote_content_size) {
1712 LOG(LS_ERROR)
1713 << "ReadyToUseRemoteCandidate: Invalid candidate media index.";
1714
1715 *valid = false;
1716 return false;
1717 }
1718
1719 cricket::ContentInfo content =
1720 current_remote_desc->description()->contents()[mediacontent_index];
1721 transport_proxy = GetTransportProxy(content.name);
1722
1723 return transport_proxy && transport_proxy->local_description_set() &&
1724 transport_proxy->remote_description_set();
1725}
1726
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727} // namespace webrtc