blob: 6c6981ce5a9987e12f185cc4b351bb105d438bbf [file] [log] [blame]
wu@webrtc.org91053e72013-08-10 07:18:04 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2013 Google Inc.
wu@webrtc.org91053e72013-08-10 07:18:04 +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/webrtcsessiondescriptionfactory.h"
29
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000030#include "talk/app/webrtc/dtlsidentitystore.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000031#include "talk/app/webrtc/jsep.h"
32#include "talk/app/webrtc/jsepsessiondescription.h"
33#include "talk/app/webrtc/mediaconstraintsinterface.h"
34#include "talk/app/webrtc/mediastreamsignaling.h"
35#include "talk/app/webrtc/webrtcsession.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020036#include "webrtc/base/sslidentity.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000037
wu@webrtc.org364f2042013-11-20 21:49:41 +000038using cricket::MediaSessionOptions;
39
wu@webrtc.org91053e72013-08-10 07:18:04 +000040namespace webrtc {
wu@webrtc.org91053e72013-08-10 07:18:04 +000041namespace {
wu@webrtc.org91053e72013-08-10 07:18:04 +000042static const char kFailedDueToIdentityFailed[] =
43 " failed because DTLS identity request failed";
tommi0f620f42015-07-09 03:25:02 -070044static const char kFailedDueToSessionShutdown[] =
45 " failed because the session was shut down";
wu@webrtc.org91053e72013-08-10 07:18:04 +000046
wu@webrtc.org91053e72013-08-10 07:18:04 +000047static const uint64 kInitSessionVersion = 2;
48
wu@webrtc.org364f2042013-11-20 21:49:41 +000049static bool CompareStream(const MediaSessionOptions::Stream& stream1,
50 const MediaSessionOptions::Stream& stream2) {
51 return stream1.id < stream2.id;
wu@webrtc.org91053e72013-08-10 07:18:04 +000052}
53
wu@webrtc.org364f2042013-11-20 21:49:41 +000054static bool SameId(const MediaSessionOptions::Stream& stream1,
55 const MediaSessionOptions::Stream& stream2) {
56 return stream1.id == stream2.id;
wu@webrtc.org91053e72013-08-10 07:18:04 +000057}
58
59// Checks if each Stream within the |streams| has unique id.
wu@webrtc.org364f2042013-11-20 21:49:41 +000060static bool ValidStreams(const MediaSessionOptions::Streams& streams) {
61 MediaSessionOptions::Streams sorted_streams = streams;
wu@webrtc.org91053e72013-08-10 07:18:04 +000062 std::sort(sorted_streams.begin(), sorted_streams.end(), CompareStream);
wu@webrtc.org364f2042013-11-20 21:49:41 +000063 MediaSessionOptions::Streams::iterator it =
wu@webrtc.org91053e72013-08-10 07:18:04 +000064 std::adjacent_find(sorted_streams.begin(), sorted_streams.end(),
65 SameId);
wu@webrtc.org364f2042013-11-20 21:49:41 +000066 return it == sorted_streams.end();
wu@webrtc.org91053e72013-08-10 07:18:04 +000067}
68
69enum {
70 MSG_CREATE_SESSIONDESCRIPTION_SUCCESS,
Henrik Boström5e56c592015-08-11 10:33:13 +020071 MSG_CREATE_SESSIONDESCRIPTION_FAILED
wu@webrtc.org91053e72013-08-10 07:18:04 +000072};
73
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000074struct CreateSessionDescriptionMsg : public rtc::MessageData {
wu@webrtc.org91053e72013-08-10 07:18:04 +000075 explicit CreateSessionDescriptionMsg(
76 webrtc::CreateSessionDescriptionObserver* observer)
77 : observer(observer) {
78 }
79
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000080 rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserver> observer;
wu@webrtc.org91053e72013-08-10 07:18:04 +000081 std::string error;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000082 rtc::scoped_ptr<webrtc::SessionDescriptionInterface> description;
wu@webrtc.org91053e72013-08-10 07:18:04 +000083};
wu@webrtc.org91053e72013-08-10 07:18:04 +000084} // namespace
85
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000086void WebRtcIdentityRequestObserver::OnFailure(int error) {
87 SignalRequestFailed(error);
88}
89
90void WebRtcIdentityRequestObserver::OnSuccess(
91 const std::string& der_cert, const std::string& der_private_key) {
92 std::string pem_cert = rtc::SSLIdentity::DerToPem(
93 rtc::kPemTypeCertificate,
94 reinterpret_cast<const unsigned char*>(der_cert.data()),
95 der_cert.length());
96 std::string pem_key = rtc::SSLIdentity::DerToPem(
97 rtc::kPemTypeRsaPrivateKey,
98 reinterpret_cast<const unsigned char*>(der_private_key.data()),
99 der_private_key.length());
100 rtc::SSLIdentity* identity =
101 rtc::SSLIdentity::FromPEMStrings(pem_key, pem_cert);
102 SignalIdentityReady(identity);
103}
104
Henrik Boström5e56c592015-08-11 10:33:13 +0200105void WebRtcIdentityRequestObserver::OnSuccess(
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +0000106 rtc::scoped_ptr<rtc::SSLIdentity> identity) {
107 SignalIdentityReady(identity.release());
108}
109
wu@webrtc.org91053e72013-08-10 07:18:04 +0000110// static
111void WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription(
112 const SessionDescriptionInterface* source_desc,
113 SessionDescriptionInterface* dest_desc) {
114 if (!source_desc)
115 return;
116 for (size_t m = 0; m < source_desc->number_of_mediasections() &&
117 m < dest_desc->number_of_mediasections(); ++m) {
118 const IceCandidateCollection* source_candidates =
119 source_desc->candidates(m);
120 const IceCandidateCollection* dest_candidates = dest_desc->candidates(m);
121 for (size_t n = 0; n < source_candidates->count(); ++n) {
122 const IceCandidateInterface* new_candidate = source_candidates->at(n);
123 if (!dest_candidates->HasCandidate(new_candidate))
124 dest_desc->AddCandidate(source_candidates->at(n));
125 }
126 }
127}
128
129WebRtcSessionDescriptionFactory::WebRtcSessionDescriptionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000130 rtc::Thread* signaling_thread,
wu@webrtc.org91053e72013-08-10 07:18:04 +0000131 cricket::ChannelManager* channel_manager,
132 MediaStreamSignaling* mediastream_signaling,
Henrik Boström5e56c592015-08-11 10:33:13 +0200133 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
wu@webrtc.org91053e72013-08-10 07:18:04 +0000134 WebRtcSession* session,
135 const std::string& session_id,
136 cricket::DataChannelType dct,
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000137 bool dtls_enabled)
wu@webrtc.org91053e72013-08-10 07:18:04 +0000138 : signaling_thread_(signaling_thread),
139 mediastream_signaling_(mediastream_signaling),
140 session_desc_factory_(channel_manager, &transport_desc_factory_),
141 // RFC 4566 suggested a Network Time Protocol (NTP) format timestamp
142 // as the session id and session version. To simplify, it should be fine
143 // to just use a random number as session id and start version from
144 // |kInitSessionVersion|.
145 session_version_(kInitSessionVersion),
Henrik Boström5e56c592015-08-11 10:33:13 +0200146 dtls_identity_store_(dtls_identity_store.Pass()),
wu@webrtc.org91053e72013-08-10 07:18:04 +0000147 session_(session),
148 session_id_(session_id),
149 data_channel_type_(dct),
150 identity_request_state_(IDENTITY_NOT_NEEDED) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000151 session_desc_factory_.set_add_legacy_streams(false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000152 // SRTP-SDES is disabled if DTLS is on.
153 SetSdesPolicy(dtls_enabled ? cricket::SEC_DISABLED : cricket::SEC_REQUIRED);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000154
Henrik Boström5e56c592015-08-11 10:33:13 +0200155 // If |dtls_enabled| we must have a |dtls_identity_store_|.
156 DCHECK(!dtls_enabled || dtls_identity_store_);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000157
Henrik Boström5e56c592015-08-11 10:33:13 +0200158 if (dtls_enabled && dtls_identity_store_) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000159 identity_request_observer_ =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000160 new rtc::RefCountedObject<WebRtcIdentityRequestObserver>();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000161
wu@webrtc.org364f2042013-11-20 21:49:41 +0000162 identity_request_observer_->SignalRequestFailed.connect(
163 this, &WebRtcSessionDescriptionFactory::OnIdentityRequestFailed);
164 identity_request_observer_->SignalIdentityReady.connect(
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +0000165 this, &WebRtcSessionDescriptionFactory::SetIdentity);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000166
Henrik Boström5e56c592015-08-11 10:33:13 +0200167 LOG(LS_VERBOSE) << "DTLS-SRTP enabled; sending DTLS identity request.";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000168 identity_request_state_ = IDENTITY_WAITING;
Henrik Boström5e56c592015-08-11 10:33:13 +0200169 dtls_identity_store_->RequestIdentity(rtc::KT_DEFAULT,
170 identity_request_observer_);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000171 }
172}
173
174WebRtcSessionDescriptionFactory::~WebRtcSessionDescriptionFactory() {
tommi0f620f42015-07-09 03:25:02 -0700175 ASSERT(signaling_thread_->IsCurrent());
176
177 // Fail any requests that were asked for before identity generation completed.
178 FailPendingRequests(kFailedDueToSessionShutdown);
179
180 // Process all pending notifications in the message queue. If we don't do
181 // this, requests will linger and not know they succeeded or failed.
182 rtc::MessageList list;
183 signaling_thread_->Clear(this, rtc::MQID_ANY, &list);
184 for (auto& msg : list)
185 OnMessage(&msg);
186
wu@webrtc.org91053e72013-08-10 07:18:04 +0000187 transport_desc_factory_.set_identity(NULL);
188}
189
190void WebRtcSessionDescriptionFactory::CreateOffer(
191 CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000192 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
193 cricket::MediaSessionOptions session_options;
194
wu@webrtc.org91053e72013-08-10 07:18:04 +0000195 std::string error = "CreateOffer";
196 if (identity_request_state_ == IDENTITY_FAILED) {
197 error += kFailedDueToIdentityFailed;
198 LOG(LS_ERROR) << error;
199 PostCreateSessionDescriptionFailed(observer, error);
200 return;
201 }
202
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000203 if (!mediastream_signaling_->GetOptionsForOffer(options,
204 &session_options)) {
205 error += " called with invalid options.";
wu@webrtc.org91053e72013-08-10 07:18:04 +0000206 LOG(LS_ERROR) << error;
207 PostCreateSessionDescriptionFailed(observer, error);
208 return;
209 }
210
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000211 if (!ValidStreams(session_options.streams)) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000212 error += " called with invalid media streams.";
213 LOG(LS_ERROR) << error;
214 PostCreateSessionDescriptionFailed(observer, error);
215 return;
216 }
217
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000218 if (data_channel_type_ == cricket::DCT_SCTP &&
219 mediastream_signaling_->HasDataChannels()) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000220 session_options.data_channel_type = cricket::DCT_SCTP;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000221 }
222
223 CreateSessionDescriptionRequest request(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000224 CreateSessionDescriptionRequest::kOffer, observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000225 if (identity_request_state_ == IDENTITY_WAITING) {
226 create_session_description_requests_.push(request);
227 } else {
228 ASSERT(identity_request_state_ == IDENTITY_SUCCEEDED ||
229 identity_request_state_ == IDENTITY_NOT_NEEDED);
230 InternalCreateOffer(request);
231 }
232}
233
234void WebRtcSessionDescriptionFactory::CreateAnswer(
235 CreateSessionDescriptionObserver* observer,
236 const MediaConstraintsInterface* constraints) {
237 std::string error = "CreateAnswer";
238 if (identity_request_state_ == IDENTITY_FAILED) {
239 error += kFailedDueToIdentityFailed;
240 LOG(LS_ERROR) << error;
241 PostCreateSessionDescriptionFailed(observer, error);
242 return;
243 }
244 if (!session_->remote_description()) {
245 error += " can't be called before SetRemoteDescription.";
246 LOG(LS_ERROR) << error;
247 PostCreateSessionDescriptionFailed(observer, error);
248 return;
249 }
250 if (session_->remote_description()->type() !=
251 JsepSessionDescription::kOffer) {
252 error += " failed because remote_description is not an offer.";
253 LOG(LS_ERROR) << error;
254 PostCreateSessionDescriptionFailed(observer, error);
255 return;
256 }
257
258 cricket::MediaSessionOptions options;
259 if (!mediastream_signaling_->GetOptionsForAnswer(constraints, &options)) {
260 error += " called with invalid constraints.";
261 LOG(LS_ERROR) << error;
262 PostCreateSessionDescriptionFailed(observer, error);
263 return;
264 }
265 if (!ValidStreams(options.streams)) {
266 error += " called with invalid media streams.";
267 LOG(LS_ERROR) << error;
268 PostCreateSessionDescriptionFailed(observer, error);
269 return;
270 }
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000271 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams
272 // are not signaled in the SDP so does not go through that path and must be
273 // handled here.
274 if (data_channel_type_ == cricket::DCT_SCTP) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000275 options.data_channel_type = cricket::DCT_SCTP;
276 }
277
278 CreateSessionDescriptionRequest request(
279 CreateSessionDescriptionRequest::kAnswer, observer, options);
280 if (identity_request_state_ == IDENTITY_WAITING) {
281 create_session_description_requests_.push(request);
282 } else {
283 ASSERT(identity_request_state_ == IDENTITY_SUCCEEDED ||
284 identity_request_state_ == IDENTITY_NOT_NEEDED);
285 InternalCreateAnswer(request);
286 }
287}
288
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000289void WebRtcSessionDescriptionFactory::SetSdesPolicy(
290 cricket::SecurePolicy secure_policy) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000291 session_desc_factory_.set_secure(secure_policy);
292}
293
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000294cricket::SecurePolicy WebRtcSessionDescriptionFactory::SdesPolicy() const {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000295 return session_desc_factory_.secure();
296}
297
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000298void WebRtcSessionDescriptionFactory::OnMessage(rtc::Message* msg) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000299 switch (msg->message_id) {
300 case MSG_CREATE_SESSIONDESCRIPTION_SUCCESS: {
301 CreateSessionDescriptionMsg* param =
302 static_cast<CreateSessionDescriptionMsg*>(msg->pdata);
303 param->observer->OnSuccess(param->description.release());
304 delete param;
305 break;
306 }
307 case MSG_CREATE_SESSIONDESCRIPTION_FAILED: {
308 CreateSessionDescriptionMsg* param =
309 static_cast<CreateSessionDescriptionMsg*>(msg->pdata);
310 param->observer->OnFailure(param->error);
311 delete param;
312 break;
313 }
wu@webrtc.org91053e72013-08-10 07:18:04 +0000314 default:
315 ASSERT(false);
316 break;
317 }
318}
319
320void WebRtcSessionDescriptionFactory::InternalCreateOffer(
321 CreateSessionDescriptionRequest request) {
322 cricket::SessionDescription* desc(
323 session_desc_factory_.CreateOffer(
324 request.options,
325 static_cast<cricket::BaseSession*>(session_)->local_description()));
326 // RFC 3264
327 // When issuing an offer that modifies the session,
328 // the "o=" line of the new SDP MUST be identical to that in the
329 // previous SDP, except that the version in the origin field MUST
330 // increment by one from the previous SDP.
331
332 // Just increase the version number by one each time when a new offer
333 // is created regardless if it's identical to the previous one or not.
334 // The |session_version_| is a uint64, the wrap around should not happen.
335 ASSERT(session_version_ + 1 > session_version_);
336 JsepSessionDescription* offer(new JsepSessionDescription(
337 JsepSessionDescription::kOffer));
338 if (!offer->Initialize(desc, session_id_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000339 rtc::ToString(session_version_++))) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000340 delete offer;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000341 PostCreateSessionDescriptionFailed(request.observer,
342 "Failed to initialize the offer.");
wu@webrtc.org91053e72013-08-10 07:18:04 +0000343 return;
344 }
345 if (session_->local_description() &&
346 !request.options.transport_options.ice_restart) {
347 // Include all local ice candidates in the SessionDescription unless
348 // the an ice restart has been requested.
349 CopyCandidatesFromSessionDescription(session_->local_description(), offer);
350 }
351 PostCreateSessionDescriptionSucceeded(request.observer, offer);
352}
353
354void WebRtcSessionDescriptionFactory::InternalCreateAnswer(
355 CreateSessionDescriptionRequest request) {
356 // According to http://tools.ietf.org/html/rfc5245#section-9.2.1.1
357 // an answer should also contain new ice ufrag and password if an offer has
358 // been received with new ufrag and password.
359 request.options.transport_options.ice_restart = session_->IceRestartPending();
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000360 // We should pass current ssl role to the transport description factory, if
361 // there is already an existing ongoing session.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000362 rtc::SSLRole ssl_role;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000363 if (session_->GetSslRole(&ssl_role)) {
364 request.options.transport_options.prefer_passive_role =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000365 (rtc::SSL_SERVER == ssl_role);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000366 }
wu@webrtc.org91053e72013-08-10 07:18:04 +0000367
368 cricket::SessionDescription* desc(session_desc_factory_.CreateAnswer(
369 static_cast<cricket::BaseSession*>(session_)->remote_description(),
370 request.options,
371 static_cast<cricket::BaseSession*>(session_)->local_description()));
372 // RFC 3264
373 // If the answer is different from the offer in any way (different IP
374 // addresses, ports, etc.), the origin line MUST be different in the answer.
375 // In that case, the version number in the "o=" line of the answer is
376 // unrelated to the version number in the o line of the offer.
377 // Get a new version number by increasing the |session_version_answer_|.
378 // The |session_version_| is a uint64, the wrap around should not happen.
379 ASSERT(session_version_ + 1 > session_version_);
380 JsepSessionDescription* answer(new JsepSessionDescription(
381 JsepSessionDescription::kAnswer));
382 if (!answer->Initialize(desc, session_id_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000383 rtc::ToString(session_version_++))) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000384 delete answer;
385 PostCreateSessionDescriptionFailed(request.observer,
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000386 "Failed to initialize the answer.");
wu@webrtc.org91053e72013-08-10 07:18:04 +0000387 return;
388 }
389 if (session_->local_description() &&
390 !request.options.transport_options.ice_restart) {
391 // Include all local ice candidates in the SessionDescription unless
392 // the remote peer has requested an ice restart.
393 CopyCandidatesFromSessionDescription(session_->local_description(), answer);
394 }
395 session_->ResetIceRestartLatch();
396 PostCreateSessionDescriptionSucceeded(request.observer, answer);
397}
398
tommi0f620f42015-07-09 03:25:02 -0700399void WebRtcSessionDescriptionFactory::FailPendingRequests(
400 const std::string& reason) {
401 ASSERT(signaling_thread_->IsCurrent());
402 while (!create_session_description_requests_.empty()) {
403 const CreateSessionDescriptionRequest& request =
404 create_session_description_requests_.front();
405 PostCreateSessionDescriptionFailed(request.observer,
406 ((request.type == CreateSessionDescriptionRequest::kOffer) ?
407 "CreateOffer" : "CreateAnswer") + reason);
408 create_session_description_requests_.pop();
409 }
410}
411
wu@webrtc.org91053e72013-08-10 07:18:04 +0000412void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionFailed(
413 CreateSessionDescriptionObserver* observer, const std::string& error) {
414 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer);
415 msg->error = error;
416 signaling_thread_->Post(this, MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000417 LOG(LS_ERROR) << "Create SDP failed: " << error;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000418}
419
420void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionSucceeded(
421 CreateSessionDescriptionObserver* observer,
422 SessionDescriptionInterface* description) {
423 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer);
424 msg->description.reset(description);
425 signaling_thread_->Post(this, MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, msg);
426}
427
428void WebRtcSessionDescriptionFactory::OnIdentityRequestFailed(int error) {
429 ASSERT(signaling_thread_->IsCurrent());
430
431 LOG(LS_ERROR) << "Async identity request failed: error = " << error;
432 identity_request_state_ = IDENTITY_FAILED;
433
tommi0f620f42015-07-09 03:25:02 -0700434 FailPendingRequests(kFailedDueToIdentityFailed);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000435}
436
wu@webrtc.org91053e72013-08-10 07:18:04 +0000437void WebRtcSessionDescriptionFactory::SetIdentity(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000438 rtc::SSLIdentity* identity) {
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +0000439 LOG(LS_VERBOSE) << "Setting new identity";
440
wu@webrtc.org91053e72013-08-10 07:18:04 +0000441 identity_request_state_ = IDENTITY_SUCCEEDED;
442 SignalIdentityReady(identity);
443
444 transport_desc_factory_.set_identity(identity);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000445 transport_desc_factory_.set_secure(cricket::SEC_ENABLED);
446
447 while (!create_session_description_requests_.empty()) {
448 if (create_session_description_requests_.front().type ==
449 CreateSessionDescriptionRequest::kOffer) {
450 InternalCreateOffer(create_session_description_requests_.front());
451 } else {
452 InternalCreateAnswer(create_session_description_requests_.front());
453 }
454 create_session_description_requests_.pop();
455 }
456}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000457} // namespace webrtc