henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 30 | #include <algorithm> |
| 31 | #include <climits> |
| 32 | #include <vector> |
| 33 | |
| 34 | #include "talk/app/webrtc/jsepicecandidate.h" |
| 35 | #include "talk/app/webrtc/jsepsessiondescription.h" |
| 36 | #include "talk/app/webrtc/mediaconstraintsinterface.h" |
| 37 | #include "talk/app/webrtc/mediastreamsignaling.h" |
| 38 | #include "talk/app/webrtc/peerconnectioninterface.h" |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 39 | #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | #include "talk/base/helpers.h" |
| 41 | #include "talk/base/logging.h" |
| 42 | #include "talk/base/stringencode.h" |
| 43 | #include "talk/media/base/constants.h" |
| 44 | #include "talk/media/base/videocapturer.h" |
| 45 | #include "talk/session/media/channel.h" |
| 46 | #include "talk/session/media/channelmanager.h" |
| 47 | #include "talk/session/media/mediasession.h" |
| 48 | |
| 49 | using cricket::ContentInfo; |
| 50 | using cricket::ContentInfos; |
| 51 | using cricket::MediaContentDescription; |
| 52 | using cricket::SessionDescription; |
| 53 | using cricket::TransportInfo; |
| 54 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 55 | namespace webrtc { |
| 56 | |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 57 | const char MediaConstraintsInterface::kInternalConstraintPrefix[] = "internal"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | |
| 59 | // Supported MediaConstraints. |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 60 | // DSCP constraints. |
| 61 | const char MediaConstraintsInterface::kEnableDscp[] = "googDscp"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 62 | // DTLS-SRTP pseudo-constraints. |
| 63 | const char MediaConstraintsInterface::kEnableDtlsSrtp[] = |
| 64 | "DtlsSrtpKeyAgreement"; |
| 65 | // DataChannel pseudo constraints. |
| 66 | const char MediaConstraintsInterface::kEnableRtpDataChannels[] = |
| 67 | "RtpDataChannels"; |
| 68 | // This constraint is for internal use only, representing the Chrome command |
| 69 | // line flag. So it is prefixed with kInternalConstraintPrefix so JS values |
| 70 | // will be removed. |
| 71 | const char MediaConstraintsInterface::kEnableSctpDataChannels[] = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 72 | "deprecatedSctpDataChannels"; |
mallinath@webrtc.org | 7e809c3 | 2013-09-30 18:59:08 +0000 | [diff] [blame] | 73 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | // Error messages |
| 75 | const char kSetLocalSdpFailed[] = "SetLocalDescription failed: "; |
| 76 | const char kSetRemoteSdpFailed[] = "SetRemoteDescription failed: "; |
| 77 | const char kCreateChannelFailed[] = "Failed to create channels."; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 78 | const char kBundleWithoutRtcpMux[] = "RTCP-MUX must be enabled when BUNDLE " |
| 79 | "is enabled."; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | const char kInvalidCandidates[] = "Description contains invalid candidates."; |
| 81 | const char kInvalidSdp[] = "Invalid session description."; |
| 82 | const char kMlineMismatch[] = |
| 83 | "Offer and answer descriptions m-lines are not matching. " |
| 84 | "Rejecting answer."; |
| 85 | const char kSdpWithoutCrypto[] = "Called with a SDP without crypto enabled."; |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 86 | const char kSdpWithoutSdesAndDtlsDisabled[] = |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 87 | "Called with an SDP without SDES crypto and DTLS disabled locally."; |
| 88 | const char kSdpWithoutIceUfragPwd[] = |
| 89 | "Called with an SDP without ice-ufrag and ice-pwd."; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 90 | const char kSessionError[] = "Session error code: "; |
| 91 | const char kUpdateStateFailed[] = "Failed to update session state: "; |
| 92 | const char kPushDownOfferTDFailed[] = |
| 93 | "Failed to push down offer transport description."; |
| 94 | const char kPushDownPranswerTDFailed[] = |
| 95 | "Failed to push down pranswer transport description."; |
| 96 | const char kPushDownAnswerTDFailed[] = |
| 97 | "Failed to push down answer transport description."; |
| 98 | |
| 99 | // Compares |answer| against |offer|. Comparision is done |
| 100 | // for number of m-lines in answer against offer. If matches true will be |
| 101 | // returned otherwise false. |
| 102 | static bool VerifyMediaDescriptions( |
| 103 | const SessionDescription* answer, const SessionDescription* offer) { |
| 104 | if (offer->contents().size() != answer->contents().size()) |
| 105 | return false; |
| 106 | |
| 107 | for (size_t i = 0; i < offer->contents().size(); ++i) { |
| 108 | if ((offer->contents()[i].name) != answer->contents()[i].name) { |
| 109 | return false; |
| 110 | } |
| 111 | } |
| 112 | return true; |
| 113 | } |
| 114 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 115 | // Checks that each non-rejected content has SDES crypto keys or a DTLS |
| 116 | // fingerprint. Mismatches, such as replying with a DTLS fingerprint to SDES |
| 117 | // keys, will be caught in Transport negotiation, and backstopped by Channel's |
| 118 | // |secure_required| check. |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 119 | static bool VerifyCrypto(const SessionDescription* desc, |
| 120 | bool dtls_enabled, |
| 121 | std::string* error) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 122 | const ContentInfos& contents = desc->contents(); |
| 123 | for (size_t index = 0; index < contents.size(); ++index) { |
| 124 | const ContentInfo* cinfo = &contents[index]; |
| 125 | if (cinfo->rejected) { |
| 126 | continue; |
| 127 | } |
| 128 | |
| 129 | // If the content isn't rejected, crypto must be present. |
| 130 | const MediaContentDescription* media = |
| 131 | static_cast<const MediaContentDescription*>(cinfo->description); |
| 132 | const TransportInfo* tinfo = desc->GetTransportInfoByName(cinfo->name); |
| 133 | if (!media || !tinfo) { |
| 134 | // Something is not right. |
| 135 | LOG(LS_ERROR) << kInvalidSdp; |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 136 | *error = kInvalidSdp; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 137 | return false; |
| 138 | } |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 139 | if (media->cryptos().empty()) { |
| 140 | if (!tinfo->description.identity_fingerprint) { |
| 141 | // Crypto must be supplied. |
| 142 | LOG(LS_WARNING) << "Session description must have SDES or DTLS-SRTP."; |
| 143 | *error = kSdpWithoutCrypto; |
| 144 | return false; |
| 145 | } |
| 146 | if (!dtls_enabled) { |
| 147 | LOG(LS_WARNING) << |
| 148 | "Session description must have SDES when DTLS disabled."; |
| 149 | *error = kSdpWithoutSdesAndDtlsDisabled; |
| 150 | return false; |
| 151 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
| 155 | return true; |
| 156 | } |
| 157 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 158 | // Checks that each non-rejected content has ice-ufrag and ice-pwd set. |
| 159 | static bool VerifyIceUfragPwdPresent(const SessionDescription* desc) { |
| 160 | const ContentInfos& contents = desc->contents(); |
| 161 | for (size_t index = 0; index < contents.size(); ++index) { |
| 162 | const ContentInfo* cinfo = &contents[index]; |
| 163 | if (cinfo->rejected) { |
| 164 | continue; |
| 165 | } |
| 166 | |
| 167 | // If the content isn't rejected, ice-ufrag and ice-pwd must be present. |
| 168 | const TransportInfo* tinfo = desc->GetTransportInfoByName(cinfo->name); |
| 169 | if (!tinfo) { |
| 170 | // Something is not right. |
| 171 | LOG(LS_ERROR) << kInvalidSdp; |
| 172 | return false; |
| 173 | } |
| 174 | if (tinfo->description.ice_ufrag.empty() || |
| 175 | tinfo->description.ice_pwd.empty()) { |
| 176 | LOG(LS_ERROR) << "Session description must have ice ufrag and pwd."; |
| 177 | return false; |
| 178 | } |
| 179 | } |
| 180 | return true; |
| 181 | } |
| 182 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 183 | // Forces |sdesc->crypto_required| to the appropriate state based on the |
| 184 | // current security policy, to ensure a failure occurs if there is an error |
| 185 | // in crypto negotiation. |
| 186 | // Called when processing the local session description. |
| 187 | static void UpdateSessionDescriptionSecurePolicy( |
| 188 | cricket::SecureMediaPolicy secure_policy, |
| 189 | SessionDescription* sdesc) { |
| 190 | if (!sdesc) { |
| 191 | return; |
| 192 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 193 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 194 | // Updating the |crypto_required_| in MediaContentDescription to the |
| 195 | // appropriate state based on the current security policy. |
| 196 | for (cricket::ContentInfos::iterator iter = sdesc->contents().begin(); |
| 197 | iter != sdesc->contents().end(); ++iter) { |
| 198 | if (cricket::IsMediaContent(&*iter)) { |
| 199 | MediaContentDescription* mdesc = |
| 200 | static_cast<MediaContentDescription*> (iter->description); |
| 201 | if (mdesc) { |
| 202 | mdesc->set_crypto_required(secure_policy == cricket::SEC_REQUIRED); |
| 203 | } |
| 204 | } |
| 205 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static bool GetAudioSsrcByTrackId( |
| 209 | const SessionDescription* session_description, |
| 210 | const std::string& track_id, uint32 *ssrc) { |
| 211 | const cricket::ContentInfo* audio_info = |
| 212 | cricket::GetFirstAudioContent(session_description); |
| 213 | if (!audio_info) { |
| 214 | LOG(LS_ERROR) << "Audio not used in this call"; |
| 215 | return false; |
| 216 | } |
| 217 | |
| 218 | const cricket::MediaContentDescription* audio_content = |
| 219 | static_cast<const cricket::MediaContentDescription*>( |
| 220 | audio_info->description); |
| 221 | cricket::StreamParams stream; |
| 222 | if (!cricket::GetStreamByIds(audio_content->streams(), "", track_id, |
| 223 | &stream)) { |
| 224 | return false; |
| 225 | } |
| 226 | *ssrc = stream.first_ssrc(); |
| 227 | return true; |
| 228 | } |
| 229 | |
| 230 | static bool GetTrackIdBySsrc(const SessionDescription* session_description, |
| 231 | uint32 ssrc, std::string* track_id) { |
| 232 | ASSERT(track_id != NULL); |
| 233 | |
| 234 | cricket::StreamParams stream_out; |
| 235 | const cricket::ContentInfo* audio_info = |
| 236 | cricket::GetFirstAudioContent(session_description); |
| 237 | if (!audio_info) { |
| 238 | return false; |
| 239 | } |
| 240 | const cricket::MediaContentDescription* audio_content = |
| 241 | static_cast<const cricket::MediaContentDescription*>( |
| 242 | audio_info->description); |
| 243 | |
| 244 | if (cricket::GetStreamBySsrc(audio_content->streams(), ssrc, &stream_out)) { |
| 245 | *track_id = stream_out.id; |
| 246 | return true; |
| 247 | } |
| 248 | |
| 249 | const cricket::ContentInfo* video_info = |
| 250 | cricket::GetFirstVideoContent(session_description); |
| 251 | if (!video_info) { |
| 252 | return false; |
| 253 | } |
| 254 | const cricket::MediaContentDescription* video_content = |
| 255 | static_cast<const cricket::MediaContentDescription*>( |
| 256 | video_info->description); |
| 257 | |
| 258 | if (cricket::GetStreamBySsrc(video_content->streams(), ssrc, &stream_out)) { |
| 259 | *track_id = stream_out.id; |
| 260 | return true; |
| 261 | } |
| 262 | return false; |
| 263 | } |
| 264 | |
| 265 | static bool BadSdp(const std::string& desc, std::string* err_desc) { |
| 266 | if (err_desc) { |
| 267 | *err_desc = desc; |
| 268 | } |
| 269 | LOG(LS_ERROR) << desc; |
| 270 | return false; |
| 271 | } |
| 272 | |
| 273 | static bool BadLocalSdp(const std::string& desc, std::string* err_desc) { |
| 274 | std::string set_local_sdp_failed = kSetLocalSdpFailed; |
| 275 | set_local_sdp_failed.append(desc); |
| 276 | return BadSdp(set_local_sdp_failed, err_desc); |
| 277 | } |
| 278 | |
| 279 | static bool BadRemoteSdp(const std::string& desc, std::string* err_desc) { |
| 280 | std::string set_remote_sdp_failed = kSetRemoteSdpFailed; |
| 281 | set_remote_sdp_failed.append(desc); |
| 282 | return BadSdp(set_remote_sdp_failed, err_desc); |
| 283 | } |
| 284 | |
| 285 | static bool BadSdp(cricket::ContentSource source, |
| 286 | const std::string& desc, std::string* err_desc) { |
| 287 | if (source == cricket::CS_LOCAL) { |
| 288 | return BadLocalSdp(desc, err_desc); |
| 289 | } else { |
| 290 | return BadRemoteSdp(desc, err_desc); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | static std::string SessionErrorMsg(cricket::BaseSession::Error error) { |
| 295 | std::ostringstream desc; |
| 296 | desc << kSessionError << error; |
| 297 | return desc.str(); |
| 298 | } |
| 299 | |
| 300 | #define GET_STRING_OF_STATE(state) \ |
| 301 | case cricket::BaseSession::state: \ |
| 302 | result = #state; \ |
| 303 | break; |
| 304 | |
| 305 | static std::string GetStateString(cricket::BaseSession::State state) { |
| 306 | std::string result; |
| 307 | switch (state) { |
| 308 | GET_STRING_OF_STATE(STATE_INIT) |
| 309 | GET_STRING_OF_STATE(STATE_SENTINITIATE) |
| 310 | GET_STRING_OF_STATE(STATE_RECEIVEDINITIATE) |
| 311 | GET_STRING_OF_STATE(STATE_SENTPRACCEPT) |
| 312 | GET_STRING_OF_STATE(STATE_SENTACCEPT) |
| 313 | GET_STRING_OF_STATE(STATE_RECEIVEDPRACCEPT) |
| 314 | GET_STRING_OF_STATE(STATE_RECEIVEDACCEPT) |
| 315 | GET_STRING_OF_STATE(STATE_SENTMODIFY) |
| 316 | GET_STRING_OF_STATE(STATE_RECEIVEDMODIFY) |
| 317 | GET_STRING_OF_STATE(STATE_SENTREJECT) |
| 318 | GET_STRING_OF_STATE(STATE_RECEIVEDREJECT) |
| 319 | GET_STRING_OF_STATE(STATE_SENTREDIRECT) |
| 320 | GET_STRING_OF_STATE(STATE_SENTTERMINATE) |
| 321 | GET_STRING_OF_STATE(STATE_RECEIVEDTERMINATE) |
| 322 | GET_STRING_OF_STATE(STATE_INPROGRESS) |
| 323 | GET_STRING_OF_STATE(STATE_DEINIT) |
| 324 | default: |
| 325 | ASSERT(false); |
| 326 | break; |
| 327 | } |
| 328 | return result; |
| 329 | } |
| 330 | |
| 331 | #define GET_STRING_OF_ERROR(err) \ |
| 332 | case cricket::BaseSession::err: \ |
| 333 | result = #err; \ |
| 334 | break; |
| 335 | |
| 336 | static std::string GetErrorString(cricket::BaseSession::Error err) { |
| 337 | std::string result; |
| 338 | switch (err) { |
| 339 | GET_STRING_OF_ERROR(ERROR_NONE) |
| 340 | GET_STRING_OF_ERROR(ERROR_TIME) |
| 341 | GET_STRING_OF_ERROR(ERROR_RESPONSE) |
| 342 | GET_STRING_OF_ERROR(ERROR_NETWORK) |
| 343 | GET_STRING_OF_ERROR(ERROR_CONTENT) |
| 344 | GET_STRING_OF_ERROR(ERROR_TRANSPORT) |
| 345 | default: |
| 346 | ASSERT(false); |
| 347 | break; |
| 348 | } |
| 349 | return result; |
| 350 | } |
| 351 | |
| 352 | static bool SetSessionStateFailed(cricket::ContentSource source, |
| 353 | cricket::BaseSession::Error err, |
| 354 | std::string* err_desc) { |
| 355 | std::string set_state_err = kUpdateStateFailed; |
| 356 | set_state_err.append(GetErrorString(err)); |
| 357 | return BadSdp(source, set_state_err, err_desc); |
| 358 | } |
| 359 | |
| 360 | // Help class used to remember if a a remote peer has requested ice restart by |
| 361 | // by sending a description with new ice ufrag and password. |
| 362 | class IceRestartAnswerLatch { |
| 363 | public: |
| 364 | IceRestartAnswerLatch() : ice_restart_(false) { } |
| 365 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 366 | // Returns true if CheckForRemoteIceRestart has been called with a new session |
| 367 | // description where ice password and ufrag has changed since last time |
| 368 | // Reset() was called. |
| 369 | bool Get() const { |
| 370 | return ice_restart_; |
| 371 | } |
| 372 | |
| 373 | void Reset() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 374 | if (ice_restart_) { |
| 375 | ice_restart_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 376 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | void CheckForRemoteIceRestart( |
| 380 | const SessionDescriptionInterface* old_desc, |
| 381 | const SessionDescriptionInterface* new_desc) { |
| 382 | if (!old_desc || new_desc->type() != SessionDescriptionInterface::kOffer) { |
| 383 | return; |
| 384 | } |
| 385 | const SessionDescription* new_sd = new_desc->description(); |
| 386 | const SessionDescription* old_sd = old_desc->description(); |
| 387 | const ContentInfos& contents = new_sd->contents(); |
| 388 | for (size_t index = 0; index < contents.size(); ++index) { |
| 389 | const ContentInfo* cinfo = &contents[index]; |
| 390 | if (cinfo->rejected) { |
| 391 | continue; |
| 392 | } |
| 393 | // If the content isn't rejected, check if ufrag and password has |
| 394 | // changed. |
| 395 | const cricket::TransportDescription* new_transport_desc = |
| 396 | new_sd->GetTransportDescriptionByName(cinfo->name); |
| 397 | const cricket::TransportDescription* old_transport_desc = |
| 398 | old_sd->GetTransportDescriptionByName(cinfo->name); |
| 399 | if (!new_transport_desc || !old_transport_desc) { |
| 400 | // No transport description exist. This is not an ice restart. |
| 401 | continue; |
| 402 | } |
| 403 | if (new_transport_desc->ice_pwd != old_transport_desc->ice_pwd && |
| 404 | new_transport_desc->ice_ufrag != old_transport_desc->ice_ufrag) { |
| 405 | LOG(LS_INFO) << "Remote peer request ice restart."; |
| 406 | ice_restart_ = true; |
| 407 | break; |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | private: |
| 413 | bool ice_restart_; |
| 414 | }; |
| 415 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 416 | WebRtcSession::WebRtcSession( |
| 417 | cricket::ChannelManager* channel_manager, |
| 418 | talk_base::Thread* signaling_thread, |
| 419 | talk_base::Thread* worker_thread, |
| 420 | cricket::PortAllocator* port_allocator, |
| 421 | MediaStreamSignaling* mediastream_signaling) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 422 | : cricket::BaseSession(signaling_thread, worker_thread, port_allocator, |
| 423 | talk_base::ToString(talk_base::CreateRandomId64() & |
| 424 | LLONG_MAX), |
| 425 | cricket::NS_JINGLE_RTP, false), |
| 426 | // RFC 3264: The numeric value of the session id and version in the |
| 427 | // o line MUST be representable with a "64 bit signed integer". |
| 428 | // Due to this constraint session id |sid_| is max limited to LLONG_MAX. |
| 429 | channel_manager_(channel_manager), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 430 | mediastream_signaling_(mediastream_signaling), |
| 431 | ice_observer_(NULL), |
| 432 | ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 433 | older_version_remote_peer_(false), |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 434 | dtls_enabled_(false), |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 435 | dscp_enabled_(false), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 436 | data_channel_type_(cricket::DCT_NONE), |
| 437 | ice_restart_latch_(new IceRestartAnswerLatch) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | WebRtcSession::~WebRtcSession() { |
| 441 | if (voice_channel_.get()) { |
| 442 | SignalVoiceChannelDestroyed(); |
| 443 | channel_manager_->DestroyVoiceChannel(voice_channel_.release()); |
| 444 | } |
| 445 | if (video_channel_.get()) { |
| 446 | SignalVideoChannelDestroyed(); |
| 447 | channel_manager_->DestroyVideoChannel(video_channel_.release()); |
| 448 | } |
| 449 | if (data_channel_.get()) { |
| 450 | SignalDataChannelDestroyed(); |
| 451 | channel_manager_->DestroyDataChannel(data_channel_.release()); |
| 452 | } |
| 453 | for (size_t i = 0; i < saved_candidates_.size(); ++i) { |
| 454 | delete saved_candidates_[i]; |
| 455 | } |
| 456 | delete identity(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 457 | } |
| 458 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 459 | bool WebRtcSession::Initialize( |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 460 | const PeerConnectionFactoryInterface::Options& options, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 461 | const MediaConstraintsInterface* constraints, |
| 462 | DTLSIdentityServiceInterface* dtls_identity_service) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 463 | // TODO(perkj): Take |constraints| into consideration. Return false if not all |
| 464 | // mandatory constraints can be fulfilled. Note that |constraints| |
| 465 | // can be null. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 466 | bool value; |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 467 | |
| 468 | // Enable DTLS by default if |dtls_identity_service| is valid. |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 469 | dtls_enabled_ = (dtls_identity_service != NULL); |
| 470 | // |constraints| can override the default |dtls_enabled_| value. |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 471 | if (FindConstraint( |
| 472 | constraints, |
| 473 | MediaConstraintsInterface::kEnableDtlsSrtp, |
| 474 | &value, NULL)) { |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 475 | dtls_enabled_ = value; |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 476 | } |
| 477 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 478 | // Enable creation of RTP data channels if the kEnableRtpDataChannels is set. |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 479 | // It takes precendence over the disable_sctp_data_channels |
| 480 | // PeerConnectionFactoryInterface::Options. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 481 | if (FindConstraint( |
| 482 | constraints, MediaConstraintsInterface::kEnableRtpDataChannels, |
| 483 | &value, NULL) && value) { |
| 484 | LOG(LS_INFO) << "Allowing RTP data engine."; |
| 485 | data_channel_type_ = cricket::DCT_RTP; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 486 | } else { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 487 | // DTLS has to be enabled to use SCTP. |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 488 | if (!options.disable_sctp_data_channels && dtls_enabled_) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 489 | LOG(LS_INFO) << "Allowing SCTP data engine."; |
| 490 | data_channel_type_ = cricket::DCT_SCTP; |
| 491 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 492 | } |
| 493 | if (data_channel_type_ != cricket::DCT_NONE) { |
| 494 | mediastream_signaling_->SetDataChannelFactory(this); |
| 495 | } |
| 496 | |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 497 | // Find DSCP constraint. |
| 498 | if (FindConstraint( |
| 499 | constraints, |
| 500 | MediaConstraintsInterface::kEnableDscp, |
| 501 | &value, NULL)) { |
| 502 | dscp_enabled_ = value; |
| 503 | } |
| 504 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 505 | const cricket::VideoCodec default_codec( |
| 506 | JsepSessionDescription::kDefaultVideoCodecId, |
| 507 | JsepSessionDescription::kDefaultVideoCodecName, |
| 508 | JsepSessionDescription::kMaxVideoCodecWidth, |
| 509 | JsepSessionDescription::kMaxVideoCodecHeight, |
| 510 | JsepSessionDescription::kDefaultVideoCodecFramerate, |
| 511 | JsepSessionDescription::kDefaultVideoCodecPreference); |
| 512 | channel_manager_->SetDefaultVideoEncoderConfig( |
| 513 | cricket::VideoEncoderConfig(default_codec)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 514 | |
| 515 | webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
| 516 | signaling_thread(), |
| 517 | channel_manager_, |
| 518 | mediastream_signaling_, |
| 519 | dtls_identity_service, |
| 520 | this, |
| 521 | id(), |
| 522 | data_channel_type_, |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 523 | dtls_enabled_)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 524 | |
| 525 | webrtc_session_desc_factory_->SignalIdentityReady.connect( |
| 526 | this, &WebRtcSession::OnIdentityReady); |
mallinath@webrtc.org | 7e809c3 | 2013-09-30 18:59:08 +0000 | [diff] [blame] | 527 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 528 | if (options.disable_encryption) { |
mallinath@webrtc.org | 7e809c3 | 2013-09-30 18:59:08 +0000 | [diff] [blame] | 529 | webrtc_session_desc_factory_->set_secure(cricket::SEC_DISABLED); |
| 530 | } |
| 531 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 532 | return true; |
| 533 | } |
| 534 | |
| 535 | void WebRtcSession::Terminate() { |
| 536 | SetState(STATE_RECEIVEDTERMINATE); |
| 537 | RemoveUnusedChannelsAndTransports(NULL); |
| 538 | ASSERT(voice_channel_.get() == NULL); |
| 539 | ASSERT(video_channel_.get() == NULL); |
| 540 | ASSERT(data_channel_.get() == NULL); |
| 541 | } |
| 542 | |
| 543 | bool WebRtcSession::StartCandidatesAllocation() { |
| 544 | // SpeculativelyConnectTransportChannels, will call ConnectChannels method |
| 545 | // from TransportProxy to start gathering ice candidates. |
| 546 | SpeculativelyConnectAllTransportChannels(); |
| 547 | if (!saved_candidates_.empty()) { |
| 548 | // If there are saved candidates which arrived before local description is |
| 549 | // set, copy those to remote description. |
| 550 | CopySavedCandidates(remote_desc_.get()); |
| 551 | } |
| 552 | // Push remote candidates present in remote description to transport channels. |
| 553 | UseCandidatesInSessionDescription(remote_desc_.get()); |
| 554 | return true; |
| 555 | } |
| 556 | |
| 557 | void WebRtcSession::set_secure_policy( |
| 558 | cricket::SecureMediaPolicy secure_policy) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 559 | webrtc_session_desc_factory_->set_secure(secure_policy); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 560 | } |
| 561 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 562 | cricket::SecureMediaPolicy WebRtcSession::secure_policy() const { |
| 563 | return webrtc_session_desc_factory_->secure(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 564 | } |
| 565 | |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 566 | bool WebRtcSession::GetSslRole(talk_base::SSLRole* role) { |
| 567 | if (local_description() == NULL || remote_description() == NULL) { |
| 568 | LOG(LS_INFO) << "Local and Remote descriptions must be applied to get " |
| 569 | << "SSL Role of the session."; |
| 570 | return false; |
| 571 | } |
| 572 | |
| 573 | // TODO(mallinath) - Return role of each transport, as role may differ from |
| 574 | // one another. |
| 575 | // In current implementaion we just return the role of first transport in the |
| 576 | // transport map. |
| 577 | for (cricket::TransportMap::const_iterator iter = transport_proxies().begin(); |
| 578 | iter != transport_proxies().end(); ++iter) { |
| 579 | if (iter->second->impl()) { |
| 580 | return iter->second->impl()->GetSslRole(role); |
| 581 | } |
| 582 | } |
| 583 | return false; |
| 584 | } |
| 585 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 586 | void WebRtcSession::CreateOffer(CreateSessionDescriptionObserver* observer, |
| 587 | const MediaConstraintsInterface* constraints) { |
| 588 | webrtc_session_desc_factory_->CreateOffer(observer, constraints); |
| 589 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 590 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 591 | void WebRtcSession::CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 592 | const MediaConstraintsInterface* constraints) { |
| 593 | webrtc_session_desc_factory_->CreateAnswer(observer, constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc, |
| 597 | std::string* err_desc) { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 598 | // Takes the ownership of |desc| regardless of the result. |
| 599 | talk_base::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); |
| 600 | |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 601 | // Validate SDP. |
| 602 | if (!ValidateSessionDescription(desc, cricket::CS_LOCAL, err_desc)) { |
| 603 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | // Update the initiator flag if this session is the initiator. |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 607 | Action action = GetAction(desc->type()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 608 | if (state() == STATE_INIT && action == kOffer) { |
| 609 | set_initiator(true); |
| 610 | } |
| 611 | |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 612 | cricket::SecureMediaPolicy secure_policy = |
| 613 | webrtc_session_desc_factory_->secure(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 614 | // Update the MediaContentDescription crypto settings as per the policy set. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 615 | UpdateSessionDescriptionSecurePolicy(secure_policy, desc->description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 616 | |
| 617 | set_local_description(desc->description()->Copy()); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 618 | local_desc_.reset(desc_temp.release()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 619 | |
| 620 | // Transport and Media channels will be created only when offer is set. |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 621 | if (action == kOffer && !CreateChannels(local_desc_->description())) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 622 | // TODO(mallinath) - Handle CreateChannel failure, as new local description |
| 623 | // is applied. Restore back to old description. |
| 624 | return BadLocalSdp(kCreateChannelFailed, err_desc); |
| 625 | } |
| 626 | |
| 627 | // Remove channel and transport proxies, if MediaContentDescription is |
| 628 | // rejected. |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 629 | RemoveUnusedChannelsAndTransports(local_desc_->description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 630 | |
| 631 | if (!UpdateSessionState(action, cricket::CS_LOCAL, |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 632 | local_desc_->description(), err_desc)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 633 | return false; |
| 634 | } |
| 635 | // Kick starting the ice candidates allocation. |
| 636 | StartCandidatesAllocation(); |
| 637 | |
| 638 | // Update state and SSRC of local MediaStreams and DataChannels based on the |
| 639 | // local session description. |
| 640 | mediastream_signaling_->OnLocalDescriptionChanged(local_desc_.get()); |
| 641 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 642 | talk_base::SSLRole role; |
| 643 | if (data_channel_type_ == cricket::DCT_SCTP && GetSslRole(&role)) { |
| 644 | mediastream_signaling_->OnDtlsRoleReadyForSctp(role); |
| 645 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 646 | if (error() != cricket::BaseSession::ERROR_NONE) { |
| 647 | return BadLocalSdp(SessionErrorMsg(error()), err_desc); |
| 648 | } |
| 649 | return true; |
| 650 | } |
| 651 | |
| 652 | bool WebRtcSession::SetRemoteDescription(SessionDescriptionInterface* desc, |
| 653 | std::string* err_desc) { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 654 | // Takes the ownership of |desc| regardless of the result. |
| 655 | talk_base::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); |
| 656 | |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 657 | // Validate SDP. |
| 658 | if (!ValidateSessionDescription(desc, cricket::CS_REMOTE, err_desc)) { |
| 659 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | // Transport and Media channels will be created only when offer is set. |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 663 | Action action = GetAction(desc->type()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 664 | if (action == kOffer && !CreateChannels(desc->description())) { |
| 665 | // TODO(mallinath) - Handle CreateChannel failure, as new local description |
| 666 | // is applied. Restore back to old description. |
| 667 | return BadRemoteSdp(kCreateChannelFailed, err_desc); |
| 668 | } |
| 669 | |
| 670 | // Remove channel and transport proxies, if MediaContentDescription is |
| 671 | // rejected. |
| 672 | RemoveUnusedChannelsAndTransports(desc->description()); |
| 673 | |
| 674 | // NOTE: Candidates allocation will be initiated only when SetLocalDescription |
| 675 | // is called. |
| 676 | set_remote_description(desc->description()->Copy()); |
| 677 | if (!UpdateSessionState(action, cricket::CS_REMOTE, |
| 678 | desc->description(), err_desc)) { |
| 679 | return false; |
| 680 | } |
| 681 | |
| 682 | // Update remote MediaStreams. |
| 683 | mediastream_signaling_->OnRemoteDescriptionChanged(desc); |
| 684 | if (local_description() && !UseCandidatesInSessionDescription(desc)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 685 | return BadRemoteSdp(kInvalidCandidates, err_desc); |
| 686 | } |
| 687 | |
| 688 | // Copy all saved candidates. |
| 689 | CopySavedCandidates(desc); |
| 690 | // We retain all received candidates. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 691 | WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription( |
| 692 | remote_desc_.get(), desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 693 | // Check if this new SessionDescription contains new ice ufrag and password |
| 694 | // that indicates the remote peer requests ice restart. |
| 695 | ice_restart_latch_->CheckForRemoteIceRestart(remote_desc_.get(), |
| 696 | desc); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 697 | remote_desc_.reset(desc_temp.release()); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 698 | |
| 699 | talk_base::SSLRole role; |
| 700 | if (data_channel_type_ == cricket::DCT_SCTP && GetSslRole(&role)) { |
| 701 | mediastream_signaling_->OnDtlsRoleReadyForSctp(role); |
| 702 | } |
| 703 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 704 | if (error() != cricket::BaseSession::ERROR_NONE) { |
| 705 | return BadRemoteSdp(SessionErrorMsg(error()), err_desc); |
| 706 | } |
| 707 | return true; |
| 708 | } |
| 709 | |
| 710 | bool WebRtcSession::UpdateSessionState( |
| 711 | Action action, cricket::ContentSource source, |
| 712 | const cricket::SessionDescription* desc, |
| 713 | std::string* err_desc) { |
| 714 | // If there's already a pending error then no state transition should happen. |
| 715 | // But all call-sites should be verifying this before calling us! |
| 716 | ASSERT(error() == cricket::BaseSession::ERROR_NONE); |
| 717 | if (action == kOffer) { |
| 718 | if (!PushdownTransportDescription(source, cricket::CA_OFFER)) { |
| 719 | return BadSdp(source, kPushDownOfferTDFailed, err_desc); |
| 720 | } |
| 721 | SetState(source == cricket::CS_LOCAL ? |
| 722 | STATE_SENTINITIATE : STATE_RECEIVEDINITIATE); |
| 723 | if (error() != cricket::BaseSession::ERROR_NONE) { |
| 724 | return SetSessionStateFailed(source, error(), err_desc); |
| 725 | } |
| 726 | } else if (action == kPrAnswer) { |
| 727 | if (!PushdownTransportDescription(source, cricket::CA_PRANSWER)) { |
| 728 | return BadSdp(source, kPushDownPranswerTDFailed, err_desc); |
| 729 | } |
| 730 | EnableChannels(); |
| 731 | SetState(source == cricket::CS_LOCAL ? |
| 732 | STATE_SENTPRACCEPT : STATE_RECEIVEDPRACCEPT); |
| 733 | if (error() != cricket::BaseSession::ERROR_NONE) { |
| 734 | return SetSessionStateFailed(source, error(), err_desc); |
| 735 | } |
| 736 | } else if (action == kAnswer) { |
| 737 | if (!PushdownTransportDescription(source, cricket::CA_ANSWER)) { |
| 738 | return BadSdp(source, kPushDownAnswerTDFailed, err_desc); |
| 739 | } |
| 740 | MaybeEnableMuxingSupport(); |
| 741 | EnableChannels(); |
| 742 | SetState(source == cricket::CS_LOCAL ? |
| 743 | STATE_SENTACCEPT : STATE_RECEIVEDACCEPT); |
| 744 | if (error() != cricket::BaseSession::ERROR_NONE) { |
| 745 | return SetSessionStateFailed(source, error(), err_desc); |
| 746 | } |
| 747 | } |
| 748 | return true; |
| 749 | } |
| 750 | |
| 751 | WebRtcSession::Action WebRtcSession::GetAction(const std::string& type) { |
| 752 | if (type == SessionDescriptionInterface::kOffer) { |
| 753 | return WebRtcSession::kOffer; |
| 754 | } else if (type == SessionDescriptionInterface::kPrAnswer) { |
| 755 | return WebRtcSession::kPrAnswer; |
| 756 | } else if (type == SessionDescriptionInterface::kAnswer) { |
| 757 | return WebRtcSession::kAnswer; |
| 758 | } |
| 759 | ASSERT(false && "unknown action type"); |
| 760 | return WebRtcSession::kOffer; |
| 761 | } |
| 762 | |
| 763 | bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) { |
| 764 | if (state() == STATE_INIT) { |
| 765 | LOG(LS_ERROR) << "ProcessIceMessage: ICE candidates can't be added " |
| 766 | << "without any offer (local or remote) " |
| 767 | << "session description."; |
| 768 | return false; |
| 769 | } |
| 770 | |
| 771 | if (!candidate) { |
| 772 | LOG(LS_ERROR) << "ProcessIceMessage: Candidate is NULL"; |
| 773 | return false; |
| 774 | } |
| 775 | |
| 776 | if (!local_description() || !remote_description()) { |
| 777 | LOG(LS_INFO) << "ProcessIceMessage: Remote description not set, " |
| 778 | << "save the candidate for later use."; |
| 779 | saved_candidates_.push_back( |
| 780 | new JsepIceCandidate(candidate->sdp_mid(), candidate->sdp_mline_index(), |
| 781 | candidate->candidate())); |
| 782 | return true; |
| 783 | } |
| 784 | |
| 785 | // Add this candidate to the remote session description. |
| 786 | if (!remote_desc_->AddCandidate(candidate)) { |
| 787 | LOG(LS_ERROR) << "ProcessIceMessage: Candidate cannot be used"; |
| 788 | return false; |
| 789 | } |
| 790 | |
| 791 | return UseCandidatesInSessionDescription(remote_desc_.get()); |
| 792 | } |
| 793 | |
| 794 | bool WebRtcSession::GetTrackIdBySsrc(uint32 ssrc, std::string* id) { |
| 795 | if (GetLocalTrackId(ssrc, id)) { |
| 796 | if (GetRemoteTrackId(ssrc, id)) { |
| 797 | LOG(LS_WARNING) << "SSRC " << ssrc |
| 798 | << " exists in both local and remote descriptions"; |
| 799 | return true; // We return the remote track id. |
| 800 | } |
| 801 | return true; |
| 802 | } else { |
| 803 | return GetRemoteTrackId(ssrc, id); |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | bool WebRtcSession::GetLocalTrackId(uint32 ssrc, std::string* track_id) { |
| 808 | if (!BaseSession::local_description()) |
| 809 | return false; |
| 810 | return webrtc::GetTrackIdBySsrc( |
| 811 | BaseSession::local_description(), ssrc, track_id); |
| 812 | } |
| 813 | |
| 814 | bool WebRtcSession::GetRemoteTrackId(uint32 ssrc, std::string* track_id) { |
| 815 | if (!BaseSession::remote_description()) |
| 816 | return false; |
| 817 | return webrtc::GetTrackIdBySsrc( |
| 818 | BaseSession::remote_description(), ssrc, track_id); |
| 819 | } |
| 820 | |
| 821 | std::string WebRtcSession::BadStateErrMsg( |
| 822 | const std::string& type, State state) { |
| 823 | std::ostringstream desc; |
| 824 | desc << "Called with type in wrong state, " |
| 825 | << "type: " << type << " state: " << GetStateString(state); |
| 826 | return desc.str(); |
| 827 | } |
| 828 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 829 | void WebRtcSession::SetAudioPlayout(uint32 ssrc, bool enable, |
| 830 | cricket::AudioRenderer* renderer) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 831 | ASSERT(signaling_thread()->IsCurrent()); |
| 832 | if (!voice_channel_) { |
| 833 | LOG(LS_ERROR) << "SetAudioPlayout: No audio channel exists."; |
| 834 | return; |
| 835 | } |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 836 | if (!voice_channel_->SetRemoteRenderer(ssrc, renderer)) { |
| 837 | // SetRenderer() can fail if the ssrc does not match any playout channel. |
| 838 | LOG(LS_ERROR) << "SetAudioPlayout: ssrc is incorrect: " << ssrc; |
| 839 | return; |
| 840 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 841 | if (!voice_channel_->SetOutputScaling(ssrc, enable ? 1 : 0, enable ? 1 : 0)) { |
| 842 | // Allow that SetOutputScaling fail if |enable| is false but assert |
| 843 | // otherwise. This in the normal case when the underlying media channel has |
| 844 | // already been deleted. |
| 845 | ASSERT(enable == false); |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | void WebRtcSession::SetAudioSend(uint32 ssrc, bool enable, |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 850 | const cricket::AudioOptions& options, |
| 851 | cricket::AudioRenderer* renderer) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 852 | ASSERT(signaling_thread()->IsCurrent()); |
| 853 | if (!voice_channel_) { |
| 854 | LOG(LS_ERROR) << "SetAudioSend: No audio channel exists."; |
| 855 | return; |
| 856 | } |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 857 | if (!voice_channel_->SetLocalRenderer(ssrc, renderer)) { |
| 858 | // SetRenderer() can fail if the ssrc does not match any send channel. |
| 859 | LOG(LS_ERROR) << "SetAudioSend: ssrc is incorrect: " << ssrc; |
| 860 | return; |
| 861 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 862 | if (!voice_channel_->MuteStream(ssrc, !enable)) { |
| 863 | // Allow that MuteStream fail if |enable| is false but assert otherwise. |
| 864 | // This in the normal case when the underlying media channel has already |
| 865 | // been deleted. |
| 866 | ASSERT(enable == false); |
| 867 | return; |
| 868 | } |
| 869 | if (enable) |
| 870 | voice_channel_->SetChannelOptions(options); |
| 871 | } |
| 872 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 873 | bool WebRtcSession::SetCaptureDevice(uint32 ssrc, |
| 874 | cricket::VideoCapturer* camera) { |
| 875 | ASSERT(signaling_thread()->IsCurrent()); |
| 876 | |
| 877 | if (!video_channel_.get()) { |
| 878 | // |video_channel_| doesnt't exist. Probably because the remote end doesnt't |
| 879 | // support video. |
| 880 | LOG(LS_WARNING) << "Video not used in this call."; |
| 881 | return false; |
| 882 | } |
| 883 | if (!video_channel_->SetCapturer(ssrc, camera)) { |
| 884 | // Allow that SetCapturer fail if |camera| is NULL but assert otherwise. |
| 885 | // This in the normal case when the underlying media channel has already |
| 886 | // been deleted. |
| 887 | ASSERT(camera == NULL); |
| 888 | return false; |
| 889 | } |
| 890 | return true; |
| 891 | } |
| 892 | |
| 893 | void WebRtcSession::SetVideoPlayout(uint32 ssrc, |
| 894 | bool enable, |
| 895 | cricket::VideoRenderer* renderer) { |
| 896 | ASSERT(signaling_thread()->IsCurrent()); |
| 897 | if (!video_channel_) { |
| 898 | LOG(LS_WARNING) << "SetVideoPlayout: No video channel exists."; |
| 899 | return; |
| 900 | } |
| 901 | if (!video_channel_->SetRenderer(ssrc, enable ? renderer : NULL)) { |
| 902 | // Allow that SetRenderer fail if |renderer| is NULL but assert otherwise. |
| 903 | // This in the normal case when the underlying media channel has already |
| 904 | // been deleted. |
| 905 | ASSERT(renderer == NULL); |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | void WebRtcSession::SetVideoSend(uint32 ssrc, bool enable, |
| 910 | const cricket::VideoOptions* options) { |
| 911 | ASSERT(signaling_thread()->IsCurrent()); |
| 912 | if (!video_channel_) { |
| 913 | LOG(LS_WARNING) << "SetVideoSend: No video channel exists."; |
| 914 | return; |
| 915 | } |
| 916 | if (!video_channel_->MuteStream(ssrc, !enable)) { |
| 917 | // Allow that MuteStream fail if |enable| is false but assert otherwise. |
| 918 | // This in the normal case when the underlying media channel has already |
| 919 | // been deleted. |
| 920 | ASSERT(enable == false); |
| 921 | return; |
| 922 | } |
| 923 | if (enable && options) |
| 924 | video_channel_->SetChannelOptions(*options); |
| 925 | } |
| 926 | |
| 927 | bool WebRtcSession::CanInsertDtmf(const std::string& track_id) { |
| 928 | ASSERT(signaling_thread()->IsCurrent()); |
| 929 | if (!voice_channel_) { |
| 930 | LOG(LS_ERROR) << "CanInsertDtmf: No audio channel exists."; |
| 931 | return false; |
| 932 | } |
| 933 | uint32 send_ssrc = 0; |
| 934 | // The Dtmf is negotiated per channel not ssrc, so we only check if the ssrc |
| 935 | // exists. |
| 936 | if (!GetAudioSsrcByTrackId(BaseSession::local_description(), track_id, |
| 937 | &send_ssrc)) { |
| 938 | LOG(LS_ERROR) << "CanInsertDtmf: Track does not exist: " << track_id; |
| 939 | return false; |
| 940 | } |
| 941 | return voice_channel_->CanInsertDtmf(); |
| 942 | } |
| 943 | |
| 944 | bool WebRtcSession::InsertDtmf(const std::string& track_id, |
| 945 | int code, int duration) { |
| 946 | ASSERT(signaling_thread()->IsCurrent()); |
| 947 | if (!voice_channel_) { |
| 948 | LOG(LS_ERROR) << "InsertDtmf: No audio channel exists."; |
| 949 | return false; |
| 950 | } |
| 951 | uint32 send_ssrc = 0; |
| 952 | if (!VERIFY(GetAudioSsrcByTrackId(BaseSession::local_description(), |
| 953 | track_id, &send_ssrc))) { |
| 954 | LOG(LS_ERROR) << "InsertDtmf: Track does not exist: " << track_id; |
| 955 | return false; |
| 956 | } |
| 957 | if (!voice_channel_->InsertDtmf(send_ssrc, code, duration, |
| 958 | cricket::DF_SEND)) { |
| 959 | LOG(LS_ERROR) << "Failed to insert DTMF to channel."; |
| 960 | return false; |
| 961 | } |
| 962 | return true; |
| 963 | } |
| 964 | |
| 965 | sigslot::signal0<>* WebRtcSession::GetOnDestroyedSignal() { |
| 966 | return &SignalVoiceChannelDestroyed; |
| 967 | } |
| 968 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 969 | bool WebRtcSession::SendData(const cricket::SendDataParams& params, |
| 970 | const talk_base::Buffer& payload, |
| 971 | cricket::SendDataResult* result) { |
| 972 | if (!data_channel_.get()) { |
| 973 | LOG(LS_ERROR) << "SendData called when data_channel_ is NULL."; |
| 974 | return false; |
| 975 | } |
| 976 | return data_channel_->SendData(params, payload, result); |
| 977 | } |
| 978 | |
| 979 | bool WebRtcSession::ConnectDataChannel(DataChannel* webrtc_data_channel) { |
| 980 | if (!data_channel_.get()) { |
| 981 | LOG(LS_ERROR) << "ConnectDataChannel called when data_channel_ is NULL."; |
| 982 | return false; |
| 983 | } |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 984 | data_channel_->SignalReadyToSendData.connect(webrtc_data_channel, |
| 985 | &DataChannel::OnChannelReady); |
| 986 | data_channel_->SignalDataReceived.connect(webrtc_data_channel, |
| 987 | &DataChannel::OnDataReceived); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 988 | return true; |
| 989 | } |
| 990 | |
| 991 | void WebRtcSession::DisconnectDataChannel(DataChannel* webrtc_data_channel) { |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 992 | if (!data_channel_.get()) { |
| 993 | LOG(LS_ERROR) << "DisconnectDataChannel called when data_channel_ is NULL."; |
| 994 | return; |
| 995 | } |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 996 | data_channel_->SignalReadyToSendData.disconnect(webrtc_data_channel); |
| 997 | data_channel_->SignalDataReceived.disconnect(webrtc_data_channel); |
| 998 | } |
| 999 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1000 | void WebRtcSession::AddRtpDataStream(uint32 send_ssrc, uint32 recv_ssrc) { |
| 1001 | if (!data_channel_.get()) { |
| 1002 | LOG(LS_ERROR) << "AddDataChannelStreams called when data_channel_ is NULL."; |
| 1003 | return; |
| 1004 | } |
| 1005 | data_channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(recv_ssrc)); |
| 1006 | data_channel_->AddSendStream(cricket::StreamParams::CreateLegacy(send_ssrc)); |
| 1007 | } |
| 1008 | |
| 1009 | void WebRtcSession::AddSctpDataStream(uint32 sid) { |
| 1010 | AddRtpDataStream(sid, sid); |
| 1011 | } |
| 1012 | |
| 1013 | void WebRtcSession::RemoveRtpDataStream(uint32 send_ssrc, uint32 recv_ssrc) { |
| 1014 | if (!data_channel_.get()) { |
| 1015 | LOG(LS_ERROR) << "RemoveDataChannelStreams called when data_channel_ is " |
| 1016 | << "NULL."; |
| 1017 | return; |
| 1018 | } |
| 1019 | data_channel_->RemoveRecvStream(recv_ssrc); |
| 1020 | data_channel_->RemoveSendStream(send_ssrc); |
| 1021 | } |
| 1022 | |
| 1023 | void WebRtcSession::RemoveSctpDataStream(uint32 sid) { |
| 1024 | RemoveRtpDataStream(sid, sid); |
| 1025 | } |
| 1026 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1027 | talk_base::scoped_refptr<DataChannel> WebRtcSession::CreateDataChannel( |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 1028 | const std::string& label, |
| 1029 | const DataChannelInit* config) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1030 | if (state() == STATE_RECEIVEDTERMINATE) { |
| 1031 | return NULL; |
| 1032 | } |
| 1033 | if (data_channel_type_ == cricket::DCT_NONE) { |
| 1034 | LOG(LS_ERROR) << "CreateDataChannel: Data is not supported in this call."; |
| 1035 | return NULL; |
| 1036 | } |
| 1037 | DataChannelInit new_config = config ? (*config) : DataChannelInit(); |
| 1038 | |
| 1039 | if (data_channel_type_ == cricket::DCT_SCTP) { |
| 1040 | if (new_config.id < 0) { |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1041 | talk_base::SSLRole role; |
| 1042 | if (GetSslRole(&role) && |
| 1043 | !mediastream_signaling_->AllocateSctpSid(role, &new_config.id)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1044 | LOG(LS_ERROR) << "No id can be allocated for the SCTP data channel."; |
| 1045 | return NULL; |
| 1046 | } |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1047 | } else if (!mediastream_signaling_->IsSctpSidAvailable(new_config.id)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1048 | LOG(LS_ERROR) << "Failed to create a SCTP data channel " |
| 1049 | << "because the id is already in use or out of range."; |
| 1050 | return NULL; |
| 1051 | } |
| 1052 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1053 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1054 | talk_base::scoped_refptr<DataChannel> channel( |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 1055 | DataChannel::Create(this, data_channel_type_, label, &new_config)); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1056 | if (channel && !mediastream_signaling_->AddDataChannel(channel)) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1057 | return NULL; |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1058 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1059 | return channel; |
| 1060 | } |
| 1061 | |
| 1062 | cricket::DataChannelType WebRtcSession::data_channel_type() const { |
| 1063 | return data_channel_type_; |
| 1064 | } |
| 1065 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1066 | bool WebRtcSession::IceRestartPending() const { |
| 1067 | return ice_restart_latch_->Get(); |
| 1068 | } |
| 1069 | |
| 1070 | void WebRtcSession::ResetIceRestartLatch() { |
| 1071 | ice_restart_latch_->Reset(); |
| 1072 | } |
| 1073 | |
| 1074 | void WebRtcSession::OnIdentityReady(talk_base::SSLIdentity* identity) { |
| 1075 | SetIdentity(identity); |
| 1076 | } |
| 1077 | |
| 1078 | bool WebRtcSession::waiting_for_identity() const { |
| 1079 | return webrtc_session_desc_factory_->waiting_for_identity(); |
| 1080 | } |
| 1081 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1082 | void WebRtcSession::SetIceConnectionState( |
| 1083 | PeerConnectionInterface::IceConnectionState state) { |
| 1084 | if (ice_connection_state_ == state) { |
| 1085 | return; |
| 1086 | } |
| 1087 | |
| 1088 | // ASSERT that the requested transition is allowed. Note that |
| 1089 | // WebRtcSession does not implement "kIceConnectionClosed" (that is handled |
| 1090 | // within PeerConnection). This switch statement should compile away when |
| 1091 | // ASSERTs are disabled. |
| 1092 | switch (ice_connection_state_) { |
| 1093 | case PeerConnectionInterface::kIceConnectionNew: |
| 1094 | ASSERT(state == PeerConnectionInterface::kIceConnectionChecking); |
| 1095 | break; |
| 1096 | case PeerConnectionInterface::kIceConnectionChecking: |
| 1097 | ASSERT(state == PeerConnectionInterface::kIceConnectionFailed || |
| 1098 | state == PeerConnectionInterface::kIceConnectionConnected); |
| 1099 | break; |
| 1100 | case PeerConnectionInterface::kIceConnectionConnected: |
| 1101 | ASSERT(state == PeerConnectionInterface::kIceConnectionDisconnected || |
| 1102 | state == PeerConnectionInterface::kIceConnectionChecking || |
| 1103 | state == PeerConnectionInterface::kIceConnectionCompleted); |
| 1104 | break; |
| 1105 | case PeerConnectionInterface::kIceConnectionCompleted: |
| 1106 | ASSERT(state == PeerConnectionInterface::kIceConnectionConnected || |
| 1107 | state == PeerConnectionInterface::kIceConnectionDisconnected); |
| 1108 | break; |
| 1109 | case PeerConnectionInterface::kIceConnectionFailed: |
| 1110 | ASSERT(state == PeerConnectionInterface::kIceConnectionNew); |
| 1111 | break; |
| 1112 | case PeerConnectionInterface::kIceConnectionDisconnected: |
| 1113 | ASSERT(state == PeerConnectionInterface::kIceConnectionChecking || |
| 1114 | state == PeerConnectionInterface::kIceConnectionConnected || |
| 1115 | state == PeerConnectionInterface::kIceConnectionCompleted || |
| 1116 | state == PeerConnectionInterface::kIceConnectionFailed); |
| 1117 | break; |
| 1118 | case PeerConnectionInterface::kIceConnectionClosed: |
| 1119 | ASSERT(false); |
| 1120 | break; |
| 1121 | default: |
| 1122 | ASSERT(false); |
| 1123 | break; |
| 1124 | } |
| 1125 | |
| 1126 | ice_connection_state_ = state; |
| 1127 | if (ice_observer_) { |
| 1128 | ice_observer_->OnIceConnectionChange(ice_connection_state_); |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | void WebRtcSession::OnTransportRequestSignaling( |
| 1133 | cricket::Transport* transport) { |
| 1134 | ASSERT(signaling_thread()->IsCurrent()); |
| 1135 | transport->OnSignalingReady(); |
| 1136 | if (ice_observer_) { |
| 1137 | ice_observer_->OnIceGatheringChange( |
| 1138 | PeerConnectionInterface::kIceGatheringGathering); |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | void WebRtcSession::OnTransportConnecting(cricket::Transport* transport) { |
| 1143 | ASSERT(signaling_thread()->IsCurrent()); |
| 1144 | // start monitoring for the write state of the transport. |
| 1145 | OnTransportWritable(transport); |
| 1146 | } |
| 1147 | |
| 1148 | void WebRtcSession::OnTransportWritable(cricket::Transport* transport) { |
| 1149 | ASSERT(signaling_thread()->IsCurrent()); |
| 1150 | // TODO(bemasc): Expose more API from Transport to detect when |
| 1151 | // candidate selection starts or stops, due to success or failure. |
| 1152 | if (transport->all_channels_writable()) { |
| 1153 | if (ice_connection_state_ == |
| 1154 | PeerConnectionInterface::kIceConnectionChecking || |
| 1155 | ice_connection_state_ == |
| 1156 | PeerConnectionInterface::kIceConnectionDisconnected) { |
| 1157 | SetIceConnectionState(PeerConnectionInterface::kIceConnectionConnected); |
| 1158 | } |
| 1159 | } else if (transport->HasChannels()) { |
| 1160 | // If the current state is Connected or Completed, then there were writable |
| 1161 | // channels but now there are not, so the next state must be Disconnected. |
| 1162 | if (ice_connection_state_ == |
| 1163 | PeerConnectionInterface::kIceConnectionConnected || |
| 1164 | ice_connection_state_ == |
| 1165 | PeerConnectionInterface::kIceConnectionCompleted) { |
| 1166 | SetIceConnectionState( |
| 1167 | PeerConnectionInterface::kIceConnectionDisconnected); |
| 1168 | } |
| 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | void WebRtcSession::OnTransportProxyCandidatesReady( |
| 1173 | cricket::TransportProxy* proxy, const cricket::Candidates& candidates) { |
| 1174 | ASSERT(signaling_thread()->IsCurrent()); |
| 1175 | ProcessNewLocalCandidate(proxy->content_name(), candidates); |
| 1176 | } |
| 1177 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1178 | void WebRtcSession::OnCandidatesAllocationDone() { |
| 1179 | ASSERT(signaling_thread()->IsCurrent()); |
| 1180 | if (ice_observer_) { |
| 1181 | ice_observer_->OnIceGatheringChange( |
| 1182 | PeerConnectionInterface::kIceGatheringComplete); |
| 1183 | ice_observer_->OnIceComplete(); |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | // Enabling voice and video channel. |
| 1188 | void WebRtcSession::EnableChannels() { |
| 1189 | if (voice_channel_ && !voice_channel_->enabled()) |
| 1190 | voice_channel_->Enable(true); |
| 1191 | |
| 1192 | if (video_channel_ && !video_channel_->enabled()) |
| 1193 | video_channel_->Enable(true); |
| 1194 | |
| 1195 | if (data_channel_.get() && !data_channel_->enabled()) |
| 1196 | data_channel_->Enable(true); |
| 1197 | } |
| 1198 | |
| 1199 | void WebRtcSession::ProcessNewLocalCandidate( |
| 1200 | const std::string& content_name, |
| 1201 | const cricket::Candidates& candidates) { |
| 1202 | int sdp_mline_index; |
| 1203 | if (!GetLocalCandidateMediaIndex(content_name, &sdp_mline_index)) { |
| 1204 | LOG(LS_ERROR) << "ProcessNewLocalCandidate: content name " |
| 1205 | << content_name << " not found"; |
| 1206 | return; |
| 1207 | } |
| 1208 | |
| 1209 | for (cricket::Candidates::const_iterator citer = candidates.begin(); |
| 1210 | citer != candidates.end(); ++citer) { |
| 1211 | // Use content_name as the candidate media id. |
| 1212 | JsepIceCandidate candidate(content_name, sdp_mline_index, *citer); |
| 1213 | if (ice_observer_) { |
| 1214 | ice_observer_->OnIceCandidate(&candidate); |
| 1215 | } |
| 1216 | if (local_desc_) { |
| 1217 | local_desc_->AddCandidate(&candidate); |
| 1218 | } |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | // Returns the media index for a local ice candidate given the content name. |
| 1223 | bool WebRtcSession::GetLocalCandidateMediaIndex(const std::string& content_name, |
| 1224 | int* sdp_mline_index) { |
| 1225 | if (!BaseSession::local_description() || !sdp_mline_index) |
| 1226 | return false; |
| 1227 | |
| 1228 | bool content_found = false; |
| 1229 | const ContentInfos& contents = BaseSession::local_description()->contents(); |
| 1230 | for (size_t index = 0; index < contents.size(); ++index) { |
| 1231 | if (contents[index].name == content_name) { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1232 | *sdp_mline_index = static_cast<int>(index); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1233 | content_found = true; |
| 1234 | break; |
| 1235 | } |
| 1236 | } |
| 1237 | return content_found; |
| 1238 | } |
| 1239 | |
| 1240 | bool WebRtcSession::UseCandidatesInSessionDescription( |
| 1241 | const SessionDescriptionInterface* remote_desc) { |
| 1242 | if (!remote_desc) |
| 1243 | return true; |
| 1244 | bool ret = true; |
| 1245 | for (size_t m = 0; m < remote_desc->number_of_mediasections(); ++m) { |
| 1246 | const IceCandidateCollection* candidates = remote_desc->candidates(m); |
| 1247 | for (size_t n = 0; n < candidates->count(); ++n) { |
| 1248 | ret = UseCandidate(candidates->at(n)); |
| 1249 | if (!ret) |
| 1250 | break; |
| 1251 | } |
| 1252 | } |
| 1253 | return ret; |
| 1254 | } |
| 1255 | |
| 1256 | bool WebRtcSession::UseCandidate( |
| 1257 | const IceCandidateInterface* candidate) { |
| 1258 | |
| 1259 | size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index()); |
| 1260 | size_t remote_content_size = |
| 1261 | BaseSession::remote_description()->contents().size(); |
| 1262 | if (mediacontent_index >= remote_content_size) { |
| 1263 | LOG(LS_ERROR) |
| 1264 | << "UseRemoteCandidateInSession: Invalid candidate media index."; |
| 1265 | return false; |
| 1266 | } |
| 1267 | |
| 1268 | cricket::ContentInfo content = |
| 1269 | BaseSession::remote_description()->contents()[mediacontent_index]; |
| 1270 | std::vector<cricket::Candidate> candidates; |
| 1271 | candidates.push_back(candidate->candidate()); |
| 1272 | // Invoking BaseSession method to handle remote candidates. |
| 1273 | std::string error; |
| 1274 | if (OnRemoteCandidates(content.name, candidates, &error)) { |
| 1275 | // Candidates successfully submitted for checking. |
| 1276 | if (ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew || |
| 1277 | ice_connection_state_ == |
| 1278 | PeerConnectionInterface::kIceConnectionDisconnected) { |
| 1279 | // If state is New, then the session has just gotten its first remote ICE |
| 1280 | // candidates, so go to Checking. |
| 1281 | // If state is Disconnected, the session is re-using old candidates or |
| 1282 | // receiving additional ones, so go to Checking. |
| 1283 | // If state is Connected, stay Connected. |
| 1284 | // TODO(bemasc): If state is Connected, and the new candidates are for a |
| 1285 | // newly added transport, then the state actually _should_ move to |
| 1286 | // checking. Add a way to distinguish that case. |
| 1287 | SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking); |
| 1288 | } |
| 1289 | // TODO(bemasc): If state is Completed, go back to Connected. |
| 1290 | } else { |
| 1291 | LOG(LS_WARNING) << error; |
| 1292 | } |
| 1293 | return true; |
| 1294 | } |
| 1295 | |
| 1296 | void WebRtcSession::RemoveUnusedChannelsAndTransports( |
| 1297 | const SessionDescription* desc) { |
| 1298 | const cricket::ContentInfo* voice_info = |
| 1299 | cricket::GetFirstAudioContent(desc); |
| 1300 | if ((!voice_info || voice_info->rejected) && voice_channel_) { |
| 1301 | mediastream_signaling_->OnAudioChannelClose(); |
| 1302 | SignalVoiceChannelDestroyed(); |
| 1303 | const std::string content_name = voice_channel_->content_name(); |
| 1304 | channel_manager_->DestroyVoiceChannel(voice_channel_.release()); |
| 1305 | DestroyTransportProxy(content_name); |
| 1306 | } |
| 1307 | |
| 1308 | const cricket::ContentInfo* video_info = |
| 1309 | cricket::GetFirstVideoContent(desc); |
| 1310 | if ((!video_info || video_info->rejected) && video_channel_) { |
| 1311 | mediastream_signaling_->OnVideoChannelClose(); |
| 1312 | SignalVideoChannelDestroyed(); |
| 1313 | const std::string content_name = video_channel_->content_name(); |
| 1314 | channel_manager_->DestroyVideoChannel(video_channel_.release()); |
| 1315 | DestroyTransportProxy(content_name); |
| 1316 | } |
| 1317 | |
| 1318 | const cricket::ContentInfo* data_info = |
| 1319 | cricket::GetFirstDataContent(desc); |
| 1320 | if ((!data_info || data_info->rejected) && data_channel_) { |
| 1321 | mediastream_signaling_->OnDataChannelClose(); |
| 1322 | SignalDataChannelDestroyed(); |
| 1323 | const std::string content_name = data_channel_->content_name(); |
| 1324 | channel_manager_->DestroyDataChannel(data_channel_.release()); |
| 1325 | DestroyTransportProxy(content_name); |
| 1326 | } |
| 1327 | } |
| 1328 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1329 | // TODO(mallinath) - Add a correct error code if the channels are not creatued |
| 1330 | // due to BUNDLE is enabled but rtcp-mux is disabled. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1331 | bool WebRtcSession::CreateChannels(const SessionDescription* desc) { |
| 1332 | // Disabling the BUNDLE flag in PortAllocator if offer disabled it. |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1333 | bool bundle_enabled = desc->HasGroup(cricket::GROUP_TYPE_BUNDLE); |
| 1334 | if (state() == STATE_INIT && !bundle_enabled) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1335 | port_allocator()->set_flags(port_allocator()->flags() & |
| 1336 | ~cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
| 1337 | } |
| 1338 | |
| 1339 | // Creating the media channels and transport proxies. |
| 1340 | const cricket::ContentInfo* voice = cricket::GetFirstAudioContent(desc); |
| 1341 | if (voice && !voice->rejected && !voice_channel_) { |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1342 | if (!CreateVoiceChannel(voice)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1343 | LOG(LS_ERROR) << "Failed to create voice channel."; |
| 1344 | return false; |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc); |
| 1349 | if (video && !video->rejected && !video_channel_) { |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1350 | if (!CreateVideoChannel(video)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1351 | LOG(LS_ERROR) << "Failed to create video channel."; |
| 1352 | return false; |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | const cricket::ContentInfo* data = cricket::GetFirstDataContent(desc); |
| 1357 | if (data_channel_type_ != cricket::DCT_NONE && |
| 1358 | data && !data->rejected && !data_channel_.get()) { |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1359 | if (!CreateDataChannel(data)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1360 | LOG(LS_ERROR) << "Failed to create data channel."; |
| 1361 | return false; |
| 1362 | } |
| 1363 | } |
| 1364 | |
| 1365 | return true; |
| 1366 | } |
| 1367 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1368 | bool WebRtcSession::CreateVoiceChannel(const cricket::ContentInfo* content) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1369 | voice_channel_.reset(channel_manager_->CreateVoiceChannel( |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1370 | this, content->name, true)); |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 1371 | if (!voice_channel_.get()) |
| 1372 | return false; |
| 1373 | |
| 1374 | if (dscp_enabled_) { |
| 1375 | cricket::AudioOptions options; |
| 1376 | options.dscp.Set(true); |
| 1377 | voice_channel_->SetChannelOptions(options); |
| 1378 | } |
| 1379 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1380 | } |
| 1381 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1382 | bool WebRtcSession::CreateVideoChannel(const cricket::ContentInfo* content) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1383 | video_channel_.reset(channel_manager_->CreateVideoChannel( |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1384 | this, content->name, true, voice_channel_.get())); |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 1385 | if (!video_channel_.get()) |
| 1386 | return false; |
| 1387 | |
| 1388 | if (dscp_enabled_) { |
| 1389 | cricket::VideoOptions options; |
| 1390 | options.dscp.Set(true); |
| 1391 | video_channel_->SetChannelOptions(options); |
| 1392 | } |
| 1393 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1396 | bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content) { |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1397 | bool sctp = (data_channel_type_ == cricket::DCT_SCTP); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1398 | data_channel_.reset(channel_manager_->CreateDataChannel( |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1399 | this, content->name, !sctp, data_channel_type_)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1400 | if (!data_channel_.get()) { |
| 1401 | return false; |
| 1402 | } |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1403 | if (sctp) { |
| 1404 | mediastream_signaling_->OnDataTransportCreatedForSctp(); |
| 1405 | data_channel_->SignalNewStreamReceived.connect( |
| 1406 | this, &WebRtcSession::OnNewDataChannelReceived); |
| 1407 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1408 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | void WebRtcSession::CopySavedCandidates( |
| 1412 | SessionDescriptionInterface* dest_desc) { |
| 1413 | if (!dest_desc) { |
| 1414 | ASSERT(false); |
| 1415 | return; |
| 1416 | } |
| 1417 | for (size_t i = 0; i < saved_candidates_.size(); ++i) { |
| 1418 | dest_desc->AddCandidate(saved_candidates_[i]); |
| 1419 | delete saved_candidates_[i]; |
| 1420 | } |
| 1421 | saved_candidates_.clear(); |
| 1422 | } |
| 1423 | |
wu@webrtc.org | 1d1ffc9 | 2013-10-16 18:12:02 +0000 | [diff] [blame] | 1424 | void WebRtcSession::OnNewDataChannelReceived( |
| 1425 | const std::string& label, const DataChannelInit& init) { |
| 1426 | ASSERT(data_channel_type_ == cricket::DCT_SCTP); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1427 | if (!mediastream_signaling_->AddDataChannelFromOpenMessage( |
wu@webrtc.org | 1d1ffc9 | 2013-10-16 18:12:02 +0000 | [diff] [blame] | 1428 | label, init)) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1429 | LOG(LS_WARNING) << "Failed to create data channel from OPEN message."; |
| 1430 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1431 | } |
| 1432 | } |
| 1433 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1434 | // Returns false if bundle is enabled and rtcp_mux is disabled. |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 1435 | bool WebRtcSession::ValidateBundleSettings(const SessionDescription* desc) { |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1436 | bool bundle_enabled = desc->HasGroup(cricket::GROUP_TYPE_BUNDLE); |
| 1437 | if (!bundle_enabled) |
| 1438 | return true; |
| 1439 | |
| 1440 | const cricket::ContentGroup* bundle_group = |
| 1441 | desc->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1442 | ASSERT(bundle_group != NULL); |
| 1443 | |
| 1444 | const cricket::ContentInfos& contents = desc->contents(); |
| 1445 | for (cricket::ContentInfos::const_iterator citer = contents.begin(); |
| 1446 | citer != contents.end(); ++citer) { |
| 1447 | const cricket::ContentInfo* content = (&*citer); |
| 1448 | ASSERT(content != NULL); |
| 1449 | if (bundle_group->HasContentName(content->name) && |
| 1450 | !content->rejected && content->type == cricket::NS_JINGLE_RTP) { |
| 1451 | if (!HasRtcpMuxEnabled(content)) |
| 1452 | return false; |
| 1453 | } |
| 1454 | } |
| 1455 | // RTCP-MUX is enabled in all the contents. |
| 1456 | return true; |
| 1457 | } |
| 1458 | |
| 1459 | bool WebRtcSession::HasRtcpMuxEnabled( |
| 1460 | const cricket::ContentInfo* content) { |
| 1461 | const cricket::MediaContentDescription* description = |
| 1462 | static_cast<cricket::MediaContentDescription*>(content->description); |
| 1463 | return description->rtcp_mux(); |
| 1464 | } |
| 1465 | |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 1466 | bool WebRtcSession::ValidateSessionDescription( |
| 1467 | const SessionDescriptionInterface* sdesc, |
| 1468 | cricket::ContentSource source, std::string* error_desc) { |
| 1469 | |
| 1470 | if (error() != cricket::BaseSession::ERROR_NONE) { |
| 1471 | return BadSdp(source, SessionErrorMsg(error()), error_desc); |
| 1472 | } |
| 1473 | |
| 1474 | if (!sdesc || !sdesc->description()) { |
| 1475 | return BadSdp(source, kInvalidSdp, error_desc); |
| 1476 | } |
| 1477 | |
| 1478 | std::string type = sdesc->type(); |
| 1479 | Action action = GetAction(sdesc->type()); |
| 1480 | if (source == cricket::CS_LOCAL) { |
| 1481 | if (!ExpectSetLocalDescription(action)) |
| 1482 | return BadSdp(source, BadStateErrMsg(type, state()), error_desc); |
| 1483 | } else { |
| 1484 | if (!ExpectSetRemoteDescription(action)) |
| 1485 | return BadSdp(source, BadStateErrMsg(type, state()), error_desc); |
| 1486 | } |
| 1487 | |
| 1488 | // Verify crypto settings. |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 1489 | std::string crypto_error; |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 1490 | if (webrtc_session_desc_factory_->secure() == cricket::SEC_REQUIRED && |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 1491 | !VerifyCrypto(sdesc->description(), dtls_enabled_, &crypto_error)) { |
| 1492 | return BadSdp(source, crypto_error, error_desc); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 1493 | } |
| 1494 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1495 | // Verify ice-ufrag and ice-pwd. |
| 1496 | if (!VerifyIceUfragPwdPresent(sdesc->description())) { |
| 1497 | return BadSdp(source, kSdpWithoutIceUfragPwd, error_desc); |
| 1498 | } |
| 1499 | |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 1500 | if (!ValidateBundleSettings(sdesc->description())) { |
| 1501 | return BadSdp(source, kBundleWithoutRtcpMux, error_desc); |
| 1502 | } |
| 1503 | |
| 1504 | // Verify m-lines in Answer when compared against Offer. |
| 1505 | if (action == kAnswer) { |
| 1506 | const cricket::SessionDescription* offer_desc = |
| 1507 | (source == cricket::CS_LOCAL) ? remote_description()->description() : |
| 1508 | local_description()->description(); |
| 1509 | if (!VerifyMediaDescriptions(sdesc->description(), offer_desc)) { |
| 1510 | return BadSdp(source, kMlineMismatch, error_desc); |
| 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | return true; |
| 1515 | } |
| 1516 | |
| 1517 | bool WebRtcSession::ExpectSetLocalDescription(Action action) { |
| 1518 | return ((action == kOffer && state() == STATE_INIT) || |
| 1519 | // update local offer |
| 1520 | (action == kOffer && state() == STATE_SENTINITIATE) || |
| 1521 | // update the current ongoing session. |
| 1522 | (action == kOffer && state() == STATE_RECEIVEDACCEPT) || |
| 1523 | (action == kOffer && state() == STATE_SENTACCEPT) || |
| 1524 | (action == kOffer && state() == STATE_INPROGRESS) || |
| 1525 | // accept remote offer |
| 1526 | (action == kAnswer && state() == STATE_RECEIVEDINITIATE) || |
| 1527 | (action == kAnswer && state() == STATE_SENTPRACCEPT) || |
| 1528 | (action == kPrAnswer && state() == STATE_RECEIVEDINITIATE) || |
| 1529 | (action == kPrAnswer && state() == STATE_SENTPRACCEPT)); |
| 1530 | } |
| 1531 | |
| 1532 | bool WebRtcSession::ExpectSetRemoteDescription(Action action) { |
| 1533 | return ((action == kOffer && state() == STATE_INIT) || |
| 1534 | // update remote offer |
| 1535 | (action == kOffer && state() == STATE_RECEIVEDINITIATE) || |
| 1536 | // update the current ongoing session |
| 1537 | (action == kOffer && state() == STATE_RECEIVEDACCEPT) || |
| 1538 | (action == kOffer && state() == STATE_SENTACCEPT) || |
| 1539 | (action == kOffer && state() == STATE_INPROGRESS) || |
| 1540 | // accept local offer |
| 1541 | (action == kAnswer && state() == STATE_SENTINITIATE) || |
| 1542 | (action == kAnswer && state() == STATE_RECEIVEDPRACCEPT) || |
| 1543 | (action == kPrAnswer && state() == STATE_SENTINITIATE) || |
| 1544 | (action == kPrAnswer && state() == STATE_RECEIVEDPRACCEPT)); |
| 1545 | } |
| 1546 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1547 | } // namespace webrtc |