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