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