blob: 739730ad0037afd49a7899af0c7e6bb99ce65e88 [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"
36
wu@webrtc.org364f2042013-11-20 21:49:41 +000037using cricket::MediaSessionOptions;
38
wu@webrtc.org91053e72013-08-10 07:18:04 +000039namespace webrtc {
wu@webrtc.org91053e72013-08-10 07:18:04 +000040namespace {
wu@webrtc.org91053e72013-08-10 07:18:04 +000041static const char kFailedDueToIdentityFailed[] =
42 " failed because DTLS identity request failed";
tommi0f620f42015-07-09 03:25:02 -070043static const char kFailedDueToSessionShutdown[] =
44 " failed because the session was shut down";
wu@webrtc.org91053e72013-08-10 07:18:04 +000045
wu@webrtc.org91053e72013-08-10 07:18:04 +000046static const uint64 kInitSessionVersion = 2;
47
wu@webrtc.org364f2042013-11-20 21:49:41 +000048static bool CompareStream(const MediaSessionOptions::Stream& stream1,
49 const MediaSessionOptions::Stream& stream2) {
50 return stream1.id < stream2.id;
wu@webrtc.org91053e72013-08-10 07:18:04 +000051}
52
wu@webrtc.org364f2042013-11-20 21:49:41 +000053static bool SameId(const MediaSessionOptions::Stream& stream1,
54 const MediaSessionOptions::Stream& stream2) {
55 return stream1.id == stream2.id;
wu@webrtc.org91053e72013-08-10 07:18:04 +000056}
57
58// Checks if each Stream within the |streams| has unique id.
wu@webrtc.org364f2042013-11-20 21:49:41 +000059static bool ValidStreams(const MediaSessionOptions::Streams& streams) {
60 MediaSessionOptions::Streams sorted_streams = streams;
wu@webrtc.org91053e72013-08-10 07:18:04 +000061 std::sort(sorted_streams.begin(), sorted_streams.end(), CompareStream);
wu@webrtc.org364f2042013-11-20 21:49:41 +000062 MediaSessionOptions::Streams::iterator it =
wu@webrtc.org91053e72013-08-10 07:18:04 +000063 std::adjacent_find(sorted_streams.begin(), sorted_streams.end(),
64 SameId);
wu@webrtc.org364f2042013-11-20 21:49:41 +000065 return it == sorted_streams.end();
wu@webrtc.org91053e72013-08-10 07:18:04 +000066}
67
68enum {
69 MSG_CREATE_SESSIONDESCRIPTION_SUCCESS,
70 MSG_CREATE_SESSIONDESCRIPTION_FAILED,
71 MSG_GENERATE_IDENTITY,
72};
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
105void WebRtcIdentityRequestObserver::OnSuccessWithIdentityObj(
106 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,
133 DTLSIdentityServiceInterface* dtls_identity_service,
134 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),
146 identity_service_(dtls_identity_service),
147 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
wu@webrtc.org364f2042013-11-20 21:49:41 +0000155 if (!dtls_enabled) {
156 return;
157 }
wu@webrtc.org91053e72013-08-10 07:18:04 +0000158
wu@webrtc.org364f2042013-11-20 21:49:41 +0000159 if (identity_service_.get()) {
160 identity_request_observer_ =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000161 new rtc::RefCountedObject<WebRtcIdentityRequestObserver>();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000162
wu@webrtc.org364f2042013-11-20 21:49:41 +0000163 identity_request_observer_->SignalRequestFailed.connect(
164 this, &WebRtcSessionDescriptionFactory::OnIdentityRequestFailed);
165 identity_request_observer_->SignalIdentityReady.connect(
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +0000166 this, &WebRtcSessionDescriptionFactory::SetIdentity);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000167
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +0000168 if (identity_service_->RequestIdentity(
169 DtlsIdentityStore::kIdentityName,
170 DtlsIdentityStore::kIdentityName,
171 identity_request_observer_)) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000172 LOG(LS_VERBOSE) << "DTLS-SRTP enabled; sent DTLS identity request.";
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000173 identity_request_state_ = IDENTITY_WAITING;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000174 } else {
175 LOG(LS_ERROR) << "Failed to send DTLS identity request.";
176 identity_request_state_ = IDENTITY_FAILED;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000177 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000178 } else {
179 identity_request_state_ = IDENTITY_WAITING;
180 // Do not generate the identity in the constructor since the caller has
181 // not got a chance to connect to SignalIdentityReady.
182 signaling_thread_->Post(this, MSG_GENERATE_IDENTITY, NULL);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000183 }
184}
185
186WebRtcSessionDescriptionFactory::~WebRtcSessionDescriptionFactory() {
tommi0f620f42015-07-09 03:25:02 -0700187 ASSERT(signaling_thread_->IsCurrent());
188
189 // Fail any requests that were asked for before identity generation completed.
190 FailPendingRequests(kFailedDueToSessionShutdown);
191
192 // Process all pending notifications in the message queue. If we don't do
193 // this, requests will linger and not know they succeeded or failed.
194 rtc::MessageList list;
195 signaling_thread_->Clear(this, rtc::MQID_ANY, &list);
196 for (auto& msg : list)
197 OnMessage(&msg);
198
wu@webrtc.org91053e72013-08-10 07:18:04 +0000199 transport_desc_factory_.set_identity(NULL);
200}
201
202void WebRtcSessionDescriptionFactory::CreateOffer(
203 CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000204 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
205 cricket::MediaSessionOptions session_options;
206
wu@webrtc.org91053e72013-08-10 07:18:04 +0000207 std::string error = "CreateOffer";
208 if (identity_request_state_ == IDENTITY_FAILED) {
209 error += kFailedDueToIdentityFailed;
210 LOG(LS_ERROR) << error;
211 PostCreateSessionDescriptionFailed(observer, error);
212 return;
213 }
214
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000215 if (!mediastream_signaling_->GetOptionsForOffer(options,
216 &session_options)) {
217 error += " called with invalid options.";
wu@webrtc.org91053e72013-08-10 07:18:04 +0000218 LOG(LS_ERROR) << error;
219 PostCreateSessionDescriptionFailed(observer, error);
220 return;
221 }
222
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000223 if (!ValidStreams(session_options.streams)) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000224 error += " called with invalid media streams.";
225 LOG(LS_ERROR) << error;
226 PostCreateSessionDescriptionFailed(observer, error);
227 return;
228 }
229
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000230 if (data_channel_type_ == cricket::DCT_SCTP &&
231 mediastream_signaling_->HasDataChannels()) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000232 session_options.data_channel_type = cricket::DCT_SCTP;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000233 }
234
235 CreateSessionDescriptionRequest request(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000236 CreateSessionDescriptionRequest::kOffer, observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000237 if (identity_request_state_ == IDENTITY_WAITING) {
238 create_session_description_requests_.push(request);
239 } else {
240 ASSERT(identity_request_state_ == IDENTITY_SUCCEEDED ||
241 identity_request_state_ == IDENTITY_NOT_NEEDED);
242 InternalCreateOffer(request);
243 }
244}
245
246void WebRtcSessionDescriptionFactory::CreateAnswer(
247 CreateSessionDescriptionObserver* observer,
248 const MediaConstraintsInterface* constraints) {
249 std::string error = "CreateAnswer";
250 if (identity_request_state_ == IDENTITY_FAILED) {
251 error += kFailedDueToIdentityFailed;
252 LOG(LS_ERROR) << error;
253 PostCreateSessionDescriptionFailed(observer, error);
254 return;
255 }
256 if (!session_->remote_description()) {
257 error += " can't be called before SetRemoteDescription.";
258 LOG(LS_ERROR) << error;
259 PostCreateSessionDescriptionFailed(observer, error);
260 return;
261 }
262 if (session_->remote_description()->type() !=
263 JsepSessionDescription::kOffer) {
264 error += " failed because remote_description is not an offer.";
265 LOG(LS_ERROR) << error;
266 PostCreateSessionDescriptionFailed(observer, error);
267 return;
268 }
269
270 cricket::MediaSessionOptions options;
271 if (!mediastream_signaling_->GetOptionsForAnswer(constraints, &options)) {
272 error += " called with invalid constraints.";
273 LOG(LS_ERROR) << error;
274 PostCreateSessionDescriptionFailed(observer, error);
275 return;
276 }
277 if (!ValidStreams(options.streams)) {
278 error += " called with invalid media streams.";
279 LOG(LS_ERROR) << error;
280 PostCreateSessionDescriptionFailed(observer, error);
281 return;
282 }
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000283 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams
284 // are not signaled in the SDP so does not go through that path and must be
285 // handled here.
286 if (data_channel_type_ == cricket::DCT_SCTP) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000287 options.data_channel_type = cricket::DCT_SCTP;
288 }
289
290 CreateSessionDescriptionRequest request(
291 CreateSessionDescriptionRequest::kAnswer, observer, options);
292 if (identity_request_state_ == IDENTITY_WAITING) {
293 create_session_description_requests_.push(request);
294 } else {
295 ASSERT(identity_request_state_ == IDENTITY_SUCCEEDED ||
296 identity_request_state_ == IDENTITY_NOT_NEEDED);
297 InternalCreateAnswer(request);
298 }
299}
300
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000301void WebRtcSessionDescriptionFactory::SetSdesPolicy(
302 cricket::SecurePolicy secure_policy) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000303 session_desc_factory_.set_secure(secure_policy);
304}
305
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000306cricket::SecurePolicy WebRtcSessionDescriptionFactory::SdesPolicy() const {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000307 return session_desc_factory_.secure();
308}
309
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000310void WebRtcSessionDescriptionFactory::OnMessage(rtc::Message* msg) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000311 switch (msg->message_id) {
312 case MSG_CREATE_SESSIONDESCRIPTION_SUCCESS: {
313 CreateSessionDescriptionMsg* param =
314 static_cast<CreateSessionDescriptionMsg*>(msg->pdata);
315 param->observer->OnSuccess(param->description.release());
316 delete param;
317 break;
318 }
319 case MSG_CREATE_SESSIONDESCRIPTION_FAILED: {
320 CreateSessionDescriptionMsg* param =
321 static_cast<CreateSessionDescriptionMsg*>(msg->pdata);
322 param->observer->OnFailure(param->error);
323 delete param;
324 break;
325 }
326 case MSG_GENERATE_IDENTITY: {
327 LOG(LS_INFO) << "Generating identity.";
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +0000328 SetIdentity(rtc::SSLIdentity::Generate(DtlsIdentityStore::kIdentityName));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000329 break;
330 }
331 default:
332 ASSERT(false);
333 break;
334 }
335}
336
337void WebRtcSessionDescriptionFactory::InternalCreateOffer(
338 CreateSessionDescriptionRequest request) {
339 cricket::SessionDescription* desc(
340 session_desc_factory_.CreateOffer(
341 request.options,
342 static_cast<cricket::BaseSession*>(session_)->local_description()));
343 // RFC 3264
344 // When issuing an offer that modifies the session,
345 // the "o=" line of the new SDP MUST be identical to that in the
346 // previous SDP, except that the version in the origin field MUST
347 // increment by one from the previous SDP.
348
349 // Just increase the version number by one each time when a new offer
350 // is created regardless if it's identical to the previous one or not.
351 // The |session_version_| is a uint64, the wrap around should not happen.
352 ASSERT(session_version_ + 1 > session_version_);
353 JsepSessionDescription* offer(new JsepSessionDescription(
354 JsepSessionDescription::kOffer));
355 if (!offer->Initialize(desc, session_id_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000356 rtc::ToString(session_version_++))) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000357 delete offer;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000358 PostCreateSessionDescriptionFailed(request.observer,
359 "Failed to initialize the offer.");
wu@webrtc.org91053e72013-08-10 07:18:04 +0000360 return;
361 }
362 if (session_->local_description() &&
363 !request.options.transport_options.ice_restart) {
364 // Include all local ice candidates in the SessionDescription unless
365 // the an ice restart has been requested.
366 CopyCandidatesFromSessionDescription(session_->local_description(), offer);
367 }
368 PostCreateSessionDescriptionSucceeded(request.observer, offer);
369}
370
371void WebRtcSessionDescriptionFactory::InternalCreateAnswer(
372 CreateSessionDescriptionRequest request) {
373 // According to http://tools.ietf.org/html/rfc5245#section-9.2.1.1
374 // an answer should also contain new ice ufrag and password if an offer has
375 // been received with new ufrag and password.
376 request.options.transport_options.ice_restart = session_->IceRestartPending();
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000377 // We should pass current ssl role to the transport description factory, if
378 // there is already an existing ongoing session.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000379 rtc::SSLRole ssl_role;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000380 if (session_->GetSslRole(&ssl_role)) {
381 request.options.transport_options.prefer_passive_role =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000382 (rtc::SSL_SERVER == ssl_role);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000383 }
wu@webrtc.org91053e72013-08-10 07:18:04 +0000384
385 cricket::SessionDescription* desc(session_desc_factory_.CreateAnswer(
386 static_cast<cricket::BaseSession*>(session_)->remote_description(),
387 request.options,
388 static_cast<cricket::BaseSession*>(session_)->local_description()));
389 // RFC 3264
390 // If the answer is different from the offer in any way (different IP
391 // addresses, ports, etc.), the origin line MUST be different in the answer.
392 // In that case, the version number in the "o=" line of the answer is
393 // unrelated to the version number in the o line of the offer.
394 // Get a new version number by increasing the |session_version_answer_|.
395 // The |session_version_| is a uint64, the wrap around should not happen.
396 ASSERT(session_version_ + 1 > session_version_);
397 JsepSessionDescription* answer(new JsepSessionDescription(
398 JsepSessionDescription::kAnswer));
399 if (!answer->Initialize(desc, session_id_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000400 rtc::ToString(session_version_++))) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000401 delete answer;
402 PostCreateSessionDescriptionFailed(request.observer,
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000403 "Failed to initialize the answer.");
wu@webrtc.org91053e72013-08-10 07:18:04 +0000404 return;
405 }
406 if (session_->local_description() &&
407 !request.options.transport_options.ice_restart) {
408 // Include all local ice candidates in the SessionDescription unless
409 // the remote peer has requested an ice restart.
410 CopyCandidatesFromSessionDescription(session_->local_description(), answer);
411 }
412 session_->ResetIceRestartLatch();
413 PostCreateSessionDescriptionSucceeded(request.observer, answer);
414}
415
tommi0f620f42015-07-09 03:25:02 -0700416void WebRtcSessionDescriptionFactory::FailPendingRequests(
417 const std::string& reason) {
418 ASSERT(signaling_thread_->IsCurrent());
419 while (!create_session_description_requests_.empty()) {
420 const CreateSessionDescriptionRequest& request =
421 create_session_description_requests_.front();
422 PostCreateSessionDescriptionFailed(request.observer,
423 ((request.type == CreateSessionDescriptionRequest::kOffer) ?
424 "CreateOffer" : "CreateAnswer") + reason);
425 create_session_description_requests_.pop();
426 }
427}
428
wu@webrtc.org91053e72013-08-10 07:18:04 +0000429void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionFailed(
430 CreateSessionDescriptionObserver* observer, const std::string& error) {
431 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer);
432 msg->error = error;
433 signaling_thread_->Post(this, MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000434 LOG(LS_ERROR) << "Create SDP failed: " << error;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000435}
436
437void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionSucceeded(
438 CreateSessionDescriptionObserver* observer,
439 SessionDescriptionInterface* description) {
440 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer);
441 msg->description.reset(description);
442 signaling_thread_->Post(this, MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, msg);
443}
444
445void WebRtcSessionDescriptionFactory::OnIdentityRequestFailed(int error) {
446 ASSERT(signaling_thread_->IsCurrent());
447
448 LOG(LS_ERROR) << "Async identity request failed: error = " << error;
449 identity_request_state_ = IDENTITY_FAILED;
450
tommi0f620f42015-07-09 03:25:02 -0700451 FailPendingRequests(kFailedDueToIdentityFailed);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000452}
453
wu@webrtc.org91053e72013-08-10 07:18:04 +0000454void WebRtcSessionDescriptionFactory::SetIdentity(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000455 rtc::SSLIdentity* identity) {
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +0000456 LOG(LS_VERBOSE) << "Setting new identity";
457
wu@webrtc.org91053e72013-08-10 07:18:04 +0000458 identity_request_state_ = IDENTITY_SUCCEEDED;
459 SignalIdentityReady(identity);
460
461 transport_desc_factory_.set_identity(identity);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000462 transport_desc_factory_.set_secure(cricket::SEC_ENABLED);
463
464 while (!create_session_description_requests_.empty()) {
465 if (create_session_description_requests_.front().type ==
466 CreateSessionDescriptionRequest::kOffer) {
467 InternalCreateOffer(create_session_description_requests_.front());
468 } else {
469 InternalCreateAnswer(create_session_description_requests_.front());
470 }
471 create_session_description_requests_.pop();
472 }
473}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000474} // namespace webrtc