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