henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
ossu | 7bb87ee | 2017-01-23 04:56:25 -0800 | [diff] [blame] | 11 | #include "webrtc/pc/webrtcsession.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | 371243d | 2014-03-07 15:22:04 +0000 | [diff] [blame] | 13 | #include <limits.h> |
| 14 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 15 | #include <algorithm> |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 16 | #include <set> |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 17 | #include <utility> |
| 18 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 19 | |
kjellander | a69d973 | 2016-08-31 07:33:05 -0700 | [diff] [blame] | 20 | #include "webrtc/api/call/audio_sink.h" |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 21 | #include "webrtc/api/jsepicecandidate.h" |
| 22 | #include "webrtc/api/jsepsessiondescription.h" |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 23 | #include "webrtc/api/peerconnectioninterface.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 24 | #include "webrtc/base/basictypes.h" |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 25 | #include "webrtc/base/bind.h" |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 26 | #include "webrtc/base/checks.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 27 | #include "webrtc/base/helpers.h" |
| 28 | #include "webrtc/base/logging.h" |
| 29 | #include "webrtc/base/stringencode.h" |
| 30 | #include "webrtc/base/stringutils.h" |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 31 | #include "webrtc/call/call.h" |
kjellander | f475277 | 2016-03-02 05:42:30 -0800 | [diff] [blame] | 32 | #include "webrtc/media/base/mediaconstants.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 33 | #include "webrtc/media/base/videocapturer.h" |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 34 | #include "webrtc/media/sctp/sctptransportinternal.h" |
pthatcher@webrtc.org | 40b276e | 2014-12-12 02:44:30 +0000 | [diff] [blame] | 35 | #include "webrtc/p2p/base/portallocator.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 36 | #include "webrtc/pc/channel.h" |
| 37 | #include "webrtc/pc/channelmanager.h" |
| 38 | #include "webrtc/pc/mediasession.h" |
ossu | 7bb87ee | 2017-01-23 04:56:25 -0800 | [diff] [blame] | 39 | #include "webrtc/pc/sctputils.h" |
| 40 | #include "webrtc/pc/webrtcsessiondescriptionfactory.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 41 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 42 | #ifdef HAVE_QUIC |
| 43 | #include "webrtc/p2p/quic/quictransportchannel.h" |
| 44 | #endif // HAVE_QUIC |
| 45 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | using cricket::ContentInfo; |
| 47 | using cricket::ContentInfos; |
| 48 | using cricket::MediaContentDescription; |
| 49 | using cricket::SessionDescription; |
| 50 | using cricket::TransportInfo; |
| 51 | |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 52 | using cricket::LOCAL_PORT_TYPE; |
| 53 | using cricket::STUN_PORT_TYPE; |
| 54 | using cricket::RELAY_PORT_TYPE; |
| 55 | using cricket::PRFLX_PORT_TYPE; |
| 56 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 57 | namespace webrtc { |
| 58 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | // Error messages |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 60 | const char kBundleWithoutRtcpMux[] = "RTCP-MUX must be enabled when BUNDLE " |
| 61 | "is enabled."; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 62 | const char kCreateChannelFailed[] = "Failed to create channels."; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 63 | const char kInvalidCandidates[] = "Description contains invalid candidates."; |
| 64 | const char kInvalidSdp[] = "Invalid session description."; |
| 65 | const char kMlineMismatch[] = |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 66 | "Offer and answer descriptions m-lines are not matching. Rejecting answer."; |
| 67 | const char kPushDownTDFailed[] = |
| 68 | "Failed to push down transport description:"; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 69 | const char kSdpWithoutDtlsFingerprint[] = |
| 70 | "Called with SDP without DTLS fingerprint."; |
| 71 | const char kSdpWithoutSdesCrypto[] = |
| 72 | "Called with SDP without SDES crypto."; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 73 | const char kSdpWithoutIceUfragPwd[] = |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 74 | "Called with SDP without ice-ufrag and ice-pwd."; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 75 | const char kSessionError[] = "Session error code: "; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 76 | const char kSessionErrorDesc[] = "Session error description: "; |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 77 | const char kDtlsSrtpSetupFailureRtp[] = |
pthatcher@webrtc.org | 4eeef58 | 2015-03-16 19:34:23 +0000 | [diff] [blame] | 78 | "Couldn't set up DTLS-SRTP on RTP channel."; |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 79 | const char kDtlsSrtpSetupFailureRtcp[] = |
pthatcher@webrtc.org | 4eeef58 | 2015-03-16 19:34:23 +0000 | [diff] [blame] | 80 | "Couldn't set up DTLS-SRTP on RTCP channel."; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 81 | const char kEnableBundleFailed[] = "Failed to enable BUNDLE."; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 83 | IceCandidatePairType GetIceCandidatePairCounter( |
| 84 | const cricket::Candidate& local, |
| 85 | const cricket::Candidate& remote) { |
| 86 | const auto& l = local.type(); |
| 87 | const auto& r = remote.type(); |
| 88 | const auto& host = LOCAL_PORT_TYPE; |
| 89 | const auto& srflx = STUN_PORT_TYPE; |
| 90 | const auto& relay = RELAY_PORT_TYPE; |
| 91 | const auto& prflx = PRFLX_PORT_TYPE; |
Guo-wei Shieh | 3cc834a | 2015-09-04 15:52:14 -0700 | [diff] [blame] | 92 | if (l == host && r == host) { |
| 93 | bool local_private = IPIsPrivate(local.address().ipaddr()); |
| 94 | bool remote_private = IPIsPrivate(remote.address().ipaddr()); |
| 95 | if (local_private) { |
| 96 | if (remote_private) { |
| 97 | return kIceCandidatePairHostPrivateHostPrivate; |
| 98 | } else { |
| 99 | return kIceCandidatePairHostPrivateHostPublic; |
| 100 | } |
| 101 | } else { |
| 102 | if (remote_private) { |
| 103 | return kIceCandidatePairHostPublicHostPrivate; |
| 104 | } else { |
| 105 | return kIceCandidatePairHostPublicHostPublic; |
| 106 | } |
| 107 | } |
| 108 | } |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 109 | if (l == host && r == srflx) |
| 110 | return kIceCandidatePairHostSrflx; |
| 111 | if (l == host && r == relay) |
| 112 | return kIceCandidatePairHostRelay; |
| 113 | if (l == host && r == prflx) |
| 114 | return kIceCandidatePairHostPrflx; |
| 115 | if (l == srflx && r == host) |
| 116 | return kIceCandidatePairSrflxHost; |
| 117 | if (l == srflx && r == srflx) |
| 118 | return kIceCandidatePairSrflxSrflx; |
| 119 | if (l == srflx && r == relay) |
| 120 | return kIceCandidatePairSrflxRelay; |
| 121 | if (l == srflx && r == prflx) |
| 122 | return kIceCandidatePairSrflxPrflx; |
| 123 | if (l == relay && r == host) |
| 124 | return kIceCandidatePairRelayHost; |
| 125 | if (l == relay && r == srflx) |
| 126 | return kIceCandidatePairRelaySrflx; |
| 127 | if (l == relay && r == relay) |
| 128 | return kIceCandidatePairRelayRelay; |
| 129 | if (l == relay && r == prflx) |
| 130 | return kIceCandidatePairRelayPrflx; |
| 131 | if (l == prflx && r == host) |
| 132 | return kIceCandidatePairPrflxHost; |
| 133 | if (l == prflx && r == srflx) |
| 134 | return kIceCandidatePairPrflxSrflx; |
| 135 | if (l == prflx && r == relay) |
| 136 | return kIceCandidatePairPrflxRelay; |
| 137 | return kIceCandidatePairMax; |
| 138 | } |
| 139 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 140 | // Compares |answer| against |offer|. Comparision is done |
| 141 | // for number of m-lines in answer against offer. If matches true will be |
| 142 | // returned otherwise false. |
| 143 | static bool VerifyMediaDescriptions( |
| 144 | const SessionDescription* answer, const SessionDescription* offer) { |
| 145 | if (offer->contents().size() != answer->contents().size()) |
| 146 | return false; |
| 147 | |
| 148 | for (size_t i = 0; i < offer->contents().size(); ++i) { |
| 149 | if ((offer->contents()[i].name) != answer->contents()[i].name) { |
| 150 | return false; |
| 151 | } |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 152 | const MediaContentDescription* offer_mdesc = |
| 153 | static_cast<const MediaContentDescription*>( |
| 154 | offer->contents()[i].description); |
| 155 | const MediaContentDescription* answer_mdesc = |
| 156 | static_cast<const MediaContentDescription*>( |
| 157 | answer->contents()[i].description); |
| 158 | if (offer_mdesc->type() != answer_mdesc->type()) { |
| 159 | return false; |
| 160 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 161 | } |
| 162 | return true; |
| 163 | } |
| 164 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 165 | // Checks that each non-rejected content has SDES crypto keys or a DTLS |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 166 | // fingerprint, unless it's in a BUNDLE group, in which case only the |
| 167 | // BUNDLE-tag section (first media section/description in the BUNDLE group) |
| 168 | // needs a ufrag and pwd. Mismatches, such as replying with a DTLS fingerprint |
| 169 | // to SDES keys, will be caught in JsepTransport negotiation, and backstopped |
| 170 | // by Channel's |srtp_required| check. |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 171 | static bool VerifyCrypto(const SessionDescription* desc, |
| 172 | bool dtls_enabled, |
| 173 | std::string* error) { |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 174 | const cricket::ContentGroup* bundle = |
| 175 | desc->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 176 | const ContentInfos& contents = desc->contents(); |
| 177 | for (size_t index = 0; index < contents.size(); ++index) { |
| 178 | const ContentInfo* cinfo = &contents[index]; |
| 179 | if (cinfo->rejected) { |
| 180 | continue; |
| 181 | } |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 182 | if (bundle && bundle->HasContentName(cinfo->name) && |
| 183 | cinfo->name != *(bundle->FirstContentName())) { |
| 184 | // This isn't the first media section in the BUNDLE group, so it's not |
| 185 | // required to have crypto attributes, since only the crypto attributes |
| 186 | // from the first section actually get used. |
| 187 | continue; |
| 188 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 189 | |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 190 | // If the content isn't rejected or bundled into another m= section, crypto |
| 191 | // must be present. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 192 | const MediaContentDescription* media = |
| 193 | static_cast<const MediaContentDescription*>(cinfo->description); |
| 194 | const TransportInfo* tinfo = desc->GetTransportInfoByName(cinfo->name); |
| 195 | if (!media || !tinfo) { |
| 196 | // Something is not right. |
| 197 | LOG(LS_ERROR) << kInvalidSdp; |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 198 | *error = kInvalidSdp; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 199 | return false; |
| 200 | } |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 201 | if (dtls_enabled) { |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 202 | if (!tinfo->description.identity_fingerprint) { |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 203 | LOG(LS_WARNING) << |
| 204 | "Session description must have DTLS fingerprint if DTLS enabled."; |
| 205 | *error = kSdpWithoutDtlsFingerprint; |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 206 | return false; |
| 207 | } |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 208 | } else { |
| 209 | if (media->cryptos().empty()) { |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 210 | LOG(LS_WARNING) << |
| 211 | "Session description must have SDES when DTLS disabled."; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 212 | *error = kSdpWithoutSdesCrypto; |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 213 | return false; |
| 214 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
| 218 | return true; |
| 219 | } |
| 220 | |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 221 | // Checks that each non-rejected content has ice-ufrag and ice-pwd set, unless |
| 222 | // it's in a BUNDLE group, in which case only the BUNDLE-tag section (first |
| 223 | // media section/description in the BUNDLE group) needs a ufrag and pwd. |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 224 | static bool VerifyIceUfragPwdPresent(const SessionDescription* desc) { |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 225 | const cricket::ContentGroup* bundle = |
| 226 | desc->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 227 | const ContentInfos& contents = desc->contents(); |
| 228 | for (size_t index = 0; index < contents.size(); ++index) { |
| 229 | const ContentInfo* cinfo = &contents[index]; |
| 230 | if (cinfo->rejected) { |
| 231 | continue; |
| 232 | } |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 233 | if (bundle && bundle->HasContentName(cinfo->name) && |
| 234 | cinfo->name != *(bundle->FirstContentName())) { |
| 235 | // This isn't the first media section in the BUNDLE group, so it's not |
| 236 | // required to have ufrag/password, since only the ufrag/password from |
| 237 | // the first section actually get used. |
| 238 | continue; |
| 239 | } |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 240 | |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 241 | // If the content isn't rejected or bundled into another m= section, |
| 242 | // ice-ufrag and ice-pwd must be present. |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 243 | const TransportInfo* tinfo = desc->GetTransportInfoByName(cinfo->name); |
| 244 | if (!tinfo) { |
| 245 | // Something is not right. |
| 246 | LOG(LS_ERROR) << kInvalidSdp; |
| 247 | return false; |
| 248 | } |
| 249 | if (tinfo->description.ice_ufrag.empty() || |
| 250 | tinfo->description.ice_pwd.empty()) { |
| 251 | LOG(LS_ERROR) << "Session description must have ice ufrag and pwd."; |
| 252 | return false; |
| 253 | } |
| 254 | } |
| 255 | return true; |
| 256 | } |
| 257 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 258 | static bool GetTrackIdBySsrc(const SessionDescription* session_description, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 259 | uint32_t ssrc, |
| 260 | std::string* track_id) { |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 261 | RTC_DCHECK(track_id != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 262 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 263 | const cricket::ContentInfo* audio_info = |
| 264 | cricket::GetFirstAudioContent(session_description); |
jiayl@webrtc.org | e21cc9a | 2014-08-28 22:21:34 +0000 | [diff] [blame] | 265 | if (audio_info) { |
| 266 | const cricket::MediaContentDescription* audio_content = |
| 267 | static_cast<const cricket::MediaContentDescription*>( |
| 268 | audio_info->description); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 269 | |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 270 | const auto* found = |
| 271 | cricket::GetStreamBySsrc(audio_content->streams(), ssrc); |
| 272 | if (found) { |
| 273 | *track_id = found->id; |
jiayl@webrtc.org | e21cc9a | 2014-08-28 22:21:34 +0000 | [diff] [blame] | 274 | return true; |
| 275 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | const cricket::ContentInfo* video_info = |
| 279 | cricket::GetFirstVideoContent(session_description); |
jiayl@webrtc.org | e21cc9a | 2014-08-28 22:21:34 +0000 | [diff] [blame] | 280 | if (video_info) { |
| 281 | const cricket::MediaContentDescription* video_content = |
| 282 | static_cast<const cricket::MediaContentDescription*>( |
| 283 | video_info->description); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 284 | |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 285 | const auto* found = |
| 286 | cricket::GetStreamBySsrc(video_content->streams(), ssrc); |
| 287 | if (found) { |
| 288 | *track_id = found->id; |
jiayl@webrtc.org | e21cc9a | 2014-08-28 22:21:34 +0000 | [diff] [blame] | 289 | return true; |
| 290 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 291 | } |
| 292 | return false; |
| 293 | } |
| 294 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 295 | // Get the SCTP port out of a SessionDescription. |
| 296 | // Return -1 if not found. |
| 297 | static int GetSctpPort(const SessionDescription* session_description) { |
| 298 | const ContentInfo* content_info = GetFirstDataContent(session_description); |
| 299 | RTC_DCHECK(content_info); |
| 300 | if (!content_info) { |
| 301 | return -1; |
| 302 | } |
| 303 | const cricket::DataContentDescription* data = |
| 304 | static_cast<const cricket::DataContentDescription*>( |
| 305 | (content_info->description)); |
| 306 | std::string value; |
| 307 | cricket::DataCodec match_pattern(cricket::kGoogleSctpDataCodecPlType, |
| 308 | cricket::kGoogleSctpDataCodecName); |
| 309 | for (const cricket::DataCodec& codec : data->codecs()) { |
| 310 | if (!codec.Matches(match_pattern)) { |
| 311 | continue; |
| 312 | } |
| 313 | if (codec.GetParam(cricket::kCodecParamPort, &value)) { |
| 314 | return rtc::FromString<int>(value); |
| 315 | } |
| 316 | } |
| 317 | return -1; |
| 318 | } |
| 319 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 320 | static bool BadSdp(const std::string& source, |
| 321 | const std::string& type, |
| 322 | const std::string& reason, |
| 323 | std::string* err_desc) { |
| 324 | std::ostringstream desc; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 325 | desc << "Failed to set " << source; |
| 326 | if (!type.empty()) { |
| 327 | desc << " " << type; |
| 328 | } |
| 329 | desc << " sdp: " << reason; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 330 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 331 | if (err_desc) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 332 | *err_desc = desc.str(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 333 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 334 | LOG(LS_ERROR) << desc.str(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 335 | return false; |
| 336 | } |
| 337 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 338 | static bool BadSdp(cricket::ContentSource source, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 339 | const std::string& type, |
| 340 | const std::string& reason, |
| 341 | std::string* err_desc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 342 | if (source == cricket::CS_LOCAL) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 343 | return BadSdp("local", type, reason, err_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 344 | } else { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 345 | return BadSdp("remote", type, reason, err_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 349 | static bool BadLocalSdp(const std::string& type, |
| 350 | const std::string& reason, |
| 351 | std::string* err_desc) { |
| 352 | return BadSdp(cricket::CS_LOCAL, type, reason, err_desc); |
| 353 | } |
| 354 | |
| 355 | static bool BadRemoteSdp(const std::string& type, |
| 356 | const std::string& reason, |
| 357 | std::string* err_desc) { |
| 358 | return BadSdp(cricket::CS_REMOTE, type, reason, err_desc); |
| 359 | } |
| 360 | |
| 361 | static bool BadOfferSdp(cricket::ContentSource source, |
| 362 | const std::string& reason, |
| 363 | std::string* err_desc) { |
| 364 | return BadSdp(source, SessionDescriptionInterface::kOffer, reason, err_desc); |
| 365 | } |
| 366 | |
| 367 | static bool BadPranswerSdp(cricket::ContentSource source, |
| 368 | const std::string& reason, |
| 369 | std::string* err_desc) { |
| 370 | return BadSdp(source, SessionDescriptionInterface::kPrAnswer, |
| 371 | reason, err_desc); |
| 372 | } |
| 373 | |
| 374 | static bool BadAnswerSdp(cricket::ContentSource source, |
| 375 | const std::string& reason, |
| 376 | std::string* err_desc) { |
| 377 | return BadSdp(source, SessionDescriptionInterface::kAnswer, reason, err_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 378 | } |
| 379 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 380 | #define GET_STRING_OF_STATE(state) \ |
| 381 | case webrtc::WebRtcSession::state: \ |
| 382 | result = #state; \ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 383 | break; |
| 384 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 385 | static std::string GetStateString(webrtc::WebRtcSession::State state) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 386 | std::string result; |
| 387 | switch (state) { |
| 388 | GET_STRING_OF_STATE(STATE_INIT) |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 389 | GET_STRING_OF_STATE(STATE_SENTOFFER) |
| 390 | GET_STRING_OF_STATE(STATE_RECEIVEDOFFER) |
| 391 | GET_STRING_OF_STATE(STATE_SENTPRANSWER) |
| 392 | GET_STRING_OF_STATE(STATE_RECEIVEDPRANSWER) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 393 | GET_STRING_OF_STATE(STATE_INPROGRESS) |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 394 | GET_STRING_OF_STATE(STATE_CLOSED) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 395 | default: |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 396 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 397 | break; |
| 398 | } |
| 399 | return result; |
| 400 | } |
| 401 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 402 | #define GET_STRING_OF_ERROR_CODE(err) \ |
| 403 | case webrtc::WebRtcSession::err: \ |
| 404 | result = #err; \ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 405 | break; |
| 406 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 407 | static std::string GetErrorCodeString(webrtc::WebRtcSession::Error err) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 408 | std::string result; |
| 409 | switch (err) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 410 | GET_STRING_OF_ERROR_CODE(ERROR_NONE) |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 411 | GET_STRING_OF_ERROR_CODE(ERROR_CONTENT) |
| 412 | GET_STRING_OF_ERROR_CODE(ERROR_TRANSPORT) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 413 | default: |
nisse | eb4ca4e | 2017-01-12 02:24:27 -0800 | [diff] [blame] | 414 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 415 | break; |
| 416 | } |
| 417 | return result; |
| 418 | } |
| 419 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 420 | static std::string MakeErrorString(const std::string& error, |
| 421 | const std::string& desc) { |
| 422 | std::ostringstream ret; |
| 423 | ret << error << " " << desc; |
| 424 | return ret.str(); |
| 425 | } |
| 426 | |
| 427 | static std::string MakeTdErrorString(const std::string& desc) { |
| 428 | return MakeErrorString(kPushDownTDFailed, desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 429 | } |
| 430 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 431 | // Returns true if |new_desc| requests an ICE restart (i.e., new ufrag/pwd). |
| 432 | bool CheckForRemoteIceRestart(const SessionDescriptionInterface* old_desc, |
| 433 | const SessionDescriptionInterface* new_desc, |
| 434 | const std::string& content_name) { |
| 435 | if (!old_desc) { |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 436 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 437 | } |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 438 | const SessionDescription* new_sd = new_desc->description(); |
| 439 | const SessionDescription* old_sd = old_desc->description(); |
| 440 | const ContentInfo* cinfo = new_sd->GetContentByName(content_name); |
| 441 | if (!cinfo || cinfo->rejected) { |
| 442 | return false; |
| 443 | } |
| 444 | // If the content isn't rejected, check if ufrag and password has changed. |
| 445 | const cricket::TransportDescription* new_transport_desc = |
| 446 | new_sd->GetTransportDescriptionByName(content_name); |
| 447 | const cricket::TransportDescription* old_transport_desc = |
| 448 | old_sd->GetTransportDescriptionByName(content_name); |
| 449 | if (!new_transport_desc || !old_transport_desc) { |
| 450 | // No transport description exists. This is not an ICE restart. |
| 451 | return false; |
| 452 | } |
| 453 | if (cricket::IceCredentialsChanged( |
| 454 | old_transport_desc->ice_ufrag, old_transport_desc->ice_pwd, |
| 455 | new_transport_desc->ice_ufrag, new_transport_desc->ice_pwd)) { |
| 456 | LOG(LS_INFO) << "Remote peer requests ICE restart for " << content_name |
| 457 | << "."; |
| 458 | return true; |
| 459 | } |
| 460 | return false; |
| 461 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 462 | |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 463 | WebRtcSession::WebRtcSession( |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 464 | Call* call, |
| 465 | cricket::ChannelManager* channel_manager, |
| 466 | const cricket::MediaConfig& media_config, |
| 467 | RtcEventLog* event_log, |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 468 | rtc::Thread* network_thread, |
| 469 | rtc::Thread* worker_thread, |
| 470 | rtc::Thread* signaling_thread, |
| 471 | cricket::PortAllocator* port_allocator, |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 472 | std::unique_ptr<cricket::TransportController> transport_controller, |
| 473 | std::unique_ptr<cricket::SctpTransportInternalFactory> sctp_factory) |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 474 | : network_thread_(network_thread), |
| 475 | worker_thread_(worker_thread), |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 476 | signaling_thread_(signaling_thread), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 477 | // RFC 3264: The numeric value of the session id and version in the |
| 478 | // o line MUST be representable with a "64 bit signed integer". |
| 479 | // Due to this constraint session id |sid_| is max limited to LLONG_MAX. |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 480 | sid_(rtc::ToString(rtc::CreateRandomId64() & LLONG_MAX)), |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 481 | transport_controller_(std::move(transport_controller)), |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 482 | sctp_factory_(std::move(sctp_factory)), |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 483 | media_config_(media_config), |
| 484 | event_log_(event_log), |
| 485 | call_(call), |
| 486 | channel_manager_(channel_manager), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 487 | ice_observer_(NULL), |
| 488 | ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), |
Peter Thatcher | 5436051 | 2015-07-08 11:08:35 -0700 | [diff] [blame] | 489 | ice_connection_receiving_(true), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 490 | older_version_remote_peer_(false), |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 491 | dtls_enabled_(false), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 492 | data_channel_type_(cricket::DCT_NONE), |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 493 | metrics_observer_(NULL) { |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 494 | transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 495 | transport_controller_->SignalConnectionState.connect( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 496 | this, &WebRtcSession::OnTransportControllerConnectionState); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 497 | transport_controller_->SignalReceiving.connect( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 498 | this, &WebRtcSession::OnTransportControllerReceiving); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 499 | transport_controller_->SignalGatheringState.connect( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 500 | this, &WebRtcSession::OnTransportControllerGatheringState); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 501 | transport_controller_->SignalCandidatesGathered.connect( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 502 | this, &WebRtcSession::OnTransportControllerCandidatesGathered); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 503 | transport_controller_->SignalCandidatesRemoved.connect( |
| 504 | this, &WebRtcSession::OnTransportControllerCandidatesRemoved); |
zhihuang | d82eee0 | 2016-08-26 11:25:05 -0700 | [diff] [blame] | 505 | transport_controller_->SignalDtlsHandshakeError.connect( |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 506 | this, &WebRtcSession::OnTransportControllerDtlsHandshakeError); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | WebRtcSession::~WebRtcSession() { |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 510 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 511 | // Destroy video_channel_ first since it may have a pointer to the |
| 512 | // voice_channel_. |
pthatcher@webrtc.org | 4eeef58 | 2015-03-16 19:34:23 +0000 | [diff] [blame] | 513 | if (video_channel_) { |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 514 | DestroyVideoChannel(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 515 | } |
pthatcher@webrtc.org | 4eeef58 | 2015-03-16 19:34:23 +0000 | [diff] [blame] | 516 | if (voice_channel_) { |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 517 | DestroyVoiceChannel(); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 518 | } |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 519 | if (rtp_data_channel_) { |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 520 | DestroyDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 521 | } |
| 522 | if (sctp_transport_) { |
| 523 | SignalDataChannelDestroyed(); |
| 524 | network_thread_->Invoke<void>( |
| 525 | RTC_FROM_HERE, rtc::Bind(&WebRtcSession::DestroySctpTransport_n, this)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 526 | } |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 527 | #ifdef HAVE_QUIC |
| 528 | if (quic_data_transport_) { |
| 529 | quic_data_transport_.reset(); |
| 530 | } |
| 531 | #endif |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 532 | |
| 533 | LOG(LS_INFO) << "Session: " << id() << " is destroyed."; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 534 | } |
| 535 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 536 | bool WebRtcSession::Initialize( |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 537 | const PeerConnectionFactoryInterface::Options& options, |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 538 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 539 | const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { |
| 540 | bundle_policy_ = rtc_configuration.bundle_policy; |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 541 | rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 542 | transport_controller_->SetSslMaxProtocolVersion(options.ssl_max_version); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 543 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 544 | // Obtain a certificate from RTCConfiguration if any were provided (optional). |
| 545 | rtc::scoped_refptr<rtc::RTCCertificate> certificate; |
| 546 | if (!rtc_configuration.certificates.empty()) { |
| 547 | // TODO(hbos,torbjorng): Decide on certificate-selection strategy instead of |
| 548 | // just picking the first one. The decision should be made based on the DTLS |
| 549 | // handshake. The DTLS negotiations need to know about all certificates. |
| 550 | certificate = rtc_configuration.certificates[0]; |
| 551 | } |
| 552 | |
honghaiz | 1f429e3 | 2015-09-28 07:57:34 -0700 | [diff] [blame] | 553 | SetIceConfig(ParseIceConfig(rtc_configuration)); |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame] | 554 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 555 | if (options.disable_encryption) { |
| 556 | dtls_enabled_ = false; |
| 557 | } else { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 558 | // Enable DTLS by default if we have an identity store or a certificate. |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 559 | dtls_enabled_ = (cert_generator || certificate); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 560 | // |rtc_configuration| can override the default |dtls_enabled_| value. |
| 561 | if (rtc_configuration.enable_dtls_srtp) { |
| 562 | dtls_enabled_ = *(rtc_configuration.enable_dtls_srtp); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 563 | } |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 564 | } |
| 565 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 566 | // Enable creation of RTP data channels if the kEnableRtpDataChannels is set. |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 567 | // It takes precendence over the disable_sctp_data_channels |
| 568 | // PeerConnectionFactoryInterface::Options. |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 569 | if (rtc_configuration.enable_rtp_data_channel) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 570 | data_channel_type_ = cricket::DCT_RTP; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 571 | } |
| 572 | #ifdef HAVE_QUIC |
| 573 | else if (rtc_configuration.enable_quic) { |
| 574 | // Use QUIC instead of DTLS when |enable_quic| is true. |
| 575 | data_channel_type_ = cricket::DCT_QUIC; |
| 576 | transport_controller_->use_quic(); |
| 577 | if (dtls_enabled_) { |
| 578 | LOG(LS_INFO) << "Using QUIC instead of DTLS"; |
| 579 | } |
| 580 | quic_data_transport_.reset( |
| 581 | new QuicDataTransport(signaling_thread(), worker_thread(), |
| 582 | network_thread(), transport_controller_.get())); |
| 583 | } |
| 584 | #endif // HAVE_QUIC |
| 585 | else { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 586 | // DTLS has to be enabled to use SCTP. |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 587 | if (!options.disable_sctp_data_channels && dtls_enabled_) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 588 | data_channel_type_ = cricket::DCT_SCTP; |
| 589 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 590 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 591 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 592 | video_options_.screencast_min_bitrate_kbps = |
| 593 | rtc_configuration.screencast_min_bitrate; |
| 594 | audio_options_.combined_audio_video_bwe = |
| 595 | rtc_configuration.combined_audio_video_bwe; |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 596 | |
kwiberg | 102c6a6 | 2015-10-30 02:47:38 -0700 | [diff] [blame] | 597 | audio_options_.audio_jitter_buffer_max_packets = |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 598 | rtc::Optional<int>(rtc_configuration.audio_jitter_buffer_max_packets); |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 599 | |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 600 | audio_options_.audio_jitter_buffer_fast_accelerate = rtc::Optional<bool>( |
| 601 | rtc_configuration.audio_jitter_buffer_fast_accelerate); |
Henrik Lundin | 5263b3c | 2015-06-01 10:29:41 +0200 | [diff] [blame] | 602 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 603 | if (!dtls_enabled_) { |
| 604 | // Construct with DTLS disabled. |
| 605 | webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 606 | signaling_thread(), channel_manager_, this, id(), |
| 607 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface>())); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 608 | } else { |
| 609 | // Construct with DTLS enabled. |
| 610 | if (!certificate) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 611 | webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 612 | signaling_thread(), channel_manager_, this, id(), |
| 613 | std::move(cert_generator))); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 614 | } else { |
| 615 | // Use the already generated certificate. |
| 616 | webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 617 | signaling_thread(), channel_manager_, this, id(), certificate)); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 618 | } |
| 619 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 620 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 621 | webrtc_session_desc_factory_->SignalCertificateReady.connect( |
| 622 | this, &WebRtcSession::OnCertificateReady); |
mallinath@webrtc.org | 7e809c3 | 2013-09-30 18:59:08 +0000 | [diff] [blame] | 623 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 624 | if (options.disable_encryption) { |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 625 | webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED); |
mallinath@webrtc.org | 7e809c3 | 2013-09-30 18:59:08 +0000 | [diff] [blame] | 626 | } |
Guo-wei Shieh | fe3bc9d | 2015-08-20 08:48:20 -0700 | [diff] [blame] | 627 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame^] | 628 | webrtc_session_desc_factory_->set_enable_encrypted_rtp_header_extensions( |
| 629 | options.crypto_options.enable_encrypted_rtp_header_extensions); |
| 630 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 631 | return true; |
| 632 | } |
| 633 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 634 | void WebRtcSession::Close() { |
| 635 | SetState(STATE_CLOSED); |
| 636 | RemoveUnusedChannels(nullptr); |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 637 | call_ = nullptr; |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 638 | RTC_DCHECK(!voice_channel_); |
| 639 | RTC_DCHECK(!video_channel_); |
| 640 | RTC_DCHECK(!rtp_data_channel_); |
| 641 | RTC_DCHECK(!sctp_transport_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 642 | } |
| 643 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 644 | cricket::BaseChannel* WebRtcSession::GetChannel( |
| 645 | const std::string& content_name) { |
| 646 | if (voice_channel() && voice_channel()->content_name() == content_name) { |
| 647 | return voice_channel(); |
| 648 | } |
| 649 | if (video_channel() && video_channel()->content_name() == content_name) { |
| 650 | return video_channel(); |
| 651 | } |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 652 | if (rtp_data_channel() && |
| 653 | rtp_data_channel()->content_name() == content_name) { |
| 654 | return rtp_data_channel(); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 655 | } |
| 656 | return nullptr; |
| 657 | } |
| 658 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 659 | cricket::SecurePolicy WebRtcSession::SdesPolicy() const { |
| 660 | return webrtc_session_desc_factory_->SdesPolicy(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 661 | } |
| 662 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 663 | bool WebRtcSession::GetSctpSslRole(rtc::SSLRole* role) { |
| 664 | if (!local_description() || !remote_description()) { |
| 665 | LOG(LS_INFO) << "Local and Remote descriptions must be applied to get the " |
| 666 | << "SSL Role of the SCTP transport."; |
| 667 | return false; |
| 668 | } |
| 669 | if (!sctp_transport_) { |
| 670 | LOG(LS_INFO) << "Non-rejected SCTP m= section is needed to get the " |
| 671 | << "SSL Role of the SCTP transport."; |
| 672 | return false; |
| 673 | } |
| 674 | |
| 675 | return transport_controller_->GetSslRole(*sctp_transport_name_, role); |
| 676 | } |
| 677 | |
| 678 | bool WebRtcSession::GetSslRole(const std::string& content_name, |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 679 | rtc::SSLRole* role) { |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 680 | if (!local_description() || !remote_description()) { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 681 | LOG(LS_INFO) << "Local and Remote descriptions must be applied to get the " |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 682 | << "SSL Role of the session."; |
| 683 | return false; |
| 684 | } |
| 685 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 686 | return transport_controller_->GetSslRole(GetTransportName(content_name), |
| 687 | role); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 688 | } |
| 689 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 690 | void WebRtcSession::CreateOffer( |
| 691 | CreateSessionDescriptionObserver* observer, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 692 | const PeerConnectionInterface::RTCOfferAnswerOptions& options, |
| 693 | const cricket::MediaSessionOptions& session_options) { |
| 694 | webrtc_session_desc_factory_->CreateOffer(observer, options, session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 695 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 696 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 697 | void WebRtcSession::CreateAnswer( |
| 698 | CreateSessionDescriptionObserver* observer, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 699 | const cricket::MediaSessionOptions& session_options) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 700 | webrtc_session_desc_factory_->CreateAnswer(observer, session_options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc, |
| 704 | std::string* err_desc) { |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 705 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 706 | |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 707 | // Takes the ownership of |desc| regardless of the result. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 708 | std::unique_ptr<SessionDescriptionInterface> desc_temp(desc); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 709 | |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 710 | // Validate SDP. |
| 711 | if (!ValidateSessionDescription(desc, cricket::CS_LOCAL, err_desc)) { |
| 712 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 713 | } |
| 714 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 715 | // Update the initial_offerer flag if this session is the initial_offerer. |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 716 | Action action = GetAction(desc->type()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 717 | if (state() == STATE_INIT && action == kOffer) { |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 718 | initial_offerer_ = true; |
| 719 | transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 720 | } |
| 721 | |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 722 | if (action == kAnswer) { |
| 723 | current_local_description_.reset(desc_temp.release()); |
| 724 | pending_local_description_.reset(nullptr); |
| 725 | current_remote_description_.reset(pending_remote_description_.release()); |
| 726 | } else { |
| 727 | pending_local_description_.reset(desc_temp.release()); |
| 728 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 729 | |
| 730 | // Transport and Media channels will be created only when offer is set. |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 731 | if (action == kOffer && !CreateChannels(local_description()->description())) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 732 | // TODO(mallinath) - Handle CreateChannel failure, as new local description |
| 733 | // is applied. Restore back to old description. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 734 | return BadLocalSdp(desc->type(), kCreateChannelFailed, err_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 735 | } |
| 736 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 737 | // Remove unused channels if MediaContentDescription is rejected. |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 738 | RemoveUnusedChannels(local_description()->description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 739 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 740 | if (!UpdateSessionState(action, cricket::CS_LOCAL, err_desc)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 741 | return false; |
| 742 | } |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 743 | if (remote_description()) { |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 744 | // Now that we have a local description, we can push down remote candidates. |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 745 | UseCandidatesInSessionDescription(remote_description()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 746 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 747 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 748 | pending_ice_restarts_.clear(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 749 | if (error() != ERROR_NONE) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 750 | return BadLocalSdp(desc->type(), GetSessionErrorMsg(), err_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 751 | } |
| 752 | return true; |
| 753 | } |
| 754 | |
| 755 | bool WebRtcSession::SetRemoteDescription(SessionDescriptionInterface* desc, |
| 756 | std::string* err_desc) { |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 757 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 758 | |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 759 | // Takes the ownership of |desc| regardless of the result. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 760 | std::unique_ptr<SessionDescriptionInterface> desc_temp(desc); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 761 | |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 762 | // Validate SDP. |
| 763 | if (!ValidateSessionDescription(desc, cricket::CS_REMOTE, err_desc)) { |
| 764 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 765 | } |
| 766 | |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 767 | const SessionDescriptionInterface* old_remote_description = |
| 768 | remote_description(); |
| 769 | // Grab ownership of the description being replaced for the remainder of this |
| 770 | // method, since it's used below. |
| 771 | std::unique_ptr<SessionDescriptionInterface> replaced_remote_description; |
| 772 | Action action = GetAction(desc->type()); |
| 773 | if (action == kAnswer) { |
| 774 | replaced_remote_description.reset( |
| 775 | pending_remote_description_ ? pending_remote_description_.release() |
| 776 | : current_remote_description_.release()); |
| 777 | current_remote_description_.reset(desc_temp.release()); |
| 778 | pending_remote_description_.reset(nullptr); |
| 779 | current_local_description_.reset(pending_local_description_.release()); |
| 780 | } else { |
| 781 | replaced_remote_description.reset(pending_remote_description_.release()); |
| 782 | pending_remote_description_.reset(desc_temp.release()); |
| 783 | } |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 784 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 785 | // Transport and Media channels will be created only when offer is set. |
| 786 | if (action == kOffer && !CreateChannels(desc->description())) { |
| 787 | // TODO(mallinath) - Handle CreateChannel failure, as new local description |
| 788 | // is applied. Restore back to old description. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 789 | return BadRemoteSdp(desc->type(), kCreateChannelFailed, err_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 790 | } |
| 791 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 792 | // Remove unused channels if MediaContentDescription is rejected. |
| 793 | RemoveUnusedChannels(desc->description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 794 | |
| 795 | // NOTE: Candidates allocation will be initiated only when SetLocalDescription |
| 796 | // is called. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 797 | if (!UpdateSessionState(action, cricket::CS_REMOTE, err_desc)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 798 | return false; |
| 799 | } |
| 800 | |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 801 | if (local_description() && !UseCandidatesInSessionDescription(desc)) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 802 | return BadRemoteSdp(desc->type(), kInvalidCandidates, err_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 803 | } |
| 804 | |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 805 | if (old_remote_description) { |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 806 | for (const cricket::ContentInfo& content : |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 807 | old_remote_description->description()->contents()) { |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 808 | // Check if this new SessionDescription contains new ICE ufrag and |
| 809 | // password that indicates the remote peer requests an ICE restart. |
| 810 | // TODO(deadbeef): When we start storing both the current and pending |
| 811 | // remote description, this should reset pending_ice_restarts and compare |
| 812 | // against the current description. |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 813 | if (CheckForRemoteIceRestart(old_remote_description, desc, |
| 814 | content.name)) { |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 815 | if (action == kOffer) { |
| 816 | pending_ice_restarts_.insert(content.name); |
| 817 | } |
| 818 | } else { |
| 819 | // We retain all received candidates only if ICE is not restarted. |
| 820 | // When ICE is restarted, all previous candidates belong to an old |
| 821 | // generation and should not be kept. |
| 822 | // TODO(deadbeef): This goes against the W3C spec which says the remote |
| 823 | // description should only contain candidates from the last set remote |
| 824 | // description plus any candidates added since then. We should remove |
| 825 | // this once we're sure it won't break anything. |
| 826 | WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription( |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 827 | old_remote_description, content.name, desc); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 828 | } |
| 829 | } |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 830 | } |
| 831 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 832 | if (error() != ERROR_NONE) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 833 | return BadRemoteSdp(desc->type(), GetSessionErrorMsg(), err_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 834 | } |
jiayl@webrtc.org | dacdd94 | 2015-01-23 17:33:34 +0000 | [diff] [blame] | 835 | |
| 836 | // Set the the ICE connection state to connecting since the connection may |
| 837 | // become writable with peer reflexive candidates before any remote candidate |
| 838 | // is signaled. |
| 839 | // TODO(pthatcher): This is a short-term solution for crbug/446908. A real fix |
| 840 | // is to have a new signal the indicates a change in checking state from the |
| 841 | // transport and expose a new checking() member from transport that can be |
| 842 | // read to determine the current checking state. The existing SignalConnecting |
| 843 | // actually means "gathering candidates", so cannot be be used here. |
| 844 | if (desc->type() != SessionDescriptionInterface::kOffer && |
| 845 | ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew) { |
| 846 | SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking); |
| 847 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 848 | return true; |
| 849 | } |
| 850 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 851 | void WebRtcSession::LogState(State old_state, State new_state) { |
| 852 | LOG(LS_INFO) << "Session:" << id() |
| 853 | << " Old state:" << GetStateString(old_state) |
| 854 | << " New state:" << GetStateString(new_state); |
| 855 | } |
| 856 | |
| 857 | void WebRtcSession::SetState(State state) { |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 858 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 859 | if (state != state_) { |
| 860 | LogState(state_, state); |
| 861 | state_ = state; |
| 862 | SignalState(this, state_); |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | void WebRtcSession::SetError(Error error, const std::string& error_desc) { |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 867 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 868 | if (error != error_) { |
| 869 | error_ = error; |
| 870 | error_desc_ = error_desc; |
| 871 | } |
| 872 | } |
| 873 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 874 | bool WebRtcSession::UpdateSessionState( |
| 875 | Action action, cricket::ContentSource source, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 876 | std::string* err_desc) { |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 877 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 878 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 879 | // If there's already a pending error then no state transition should happen. |
| 880 | // But all call-sites should be verifying this before calling us! |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 881 | RTC_DCHECK(error() == ERROR_NONE); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 882 | std::string td_err; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 883 | if (action == kOffer) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 884 | if (!PushdownTransportDescription(source, cricket::CA_OFFER, &td_err)) { |
| 885 | return BadOfferSdp(source, MakeTdErrorString(td_err), err_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 886 | } |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 887 | SetState(source == cricket::CS_LOCAL ? STATE_SENTOFFER |
| 888 | : STATE_RECEIVEDOFFER); |
pthatcher@webrtc.org | 592470b | 2015-03-16 21:15:37 +0000 | [diff] [blame] | 889 | if (!PushdownMediaDescription(cricket::CA_OFFER, source, err_desc)) { |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 890 | SetError(ERROR_CONTENT, *err_desc); |
pthatcher@webrtc.org | 592470b | 2015-03-16 21:15:37 +0000 | [diff] [blame] | 891 | } |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 892 | if (error() != ERROR_NONE) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 893 | return BadOfferSdp(source, GetSessionErrorMsg(), err_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 894 | } |
| 895 | } else if (action == kPrAnswer) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 896 | if (!PushdownTransportDescription(source, cricket::CA_PRANSWER, &td_err)) { |
| 897 | return BadPranswerSdp(source, MakeTdErrorString(td_err), err_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 898 | } |
| 899 | EnableChannels(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 900 | SetState(source == cricket::CS_LOCAL ? STATE_SENTPRANSWER |
| 901 | : STATE_RECEIVEDPRANSWER); |
pthatcher@webrtc.org | 592470b | 2015-03-16 21:15:37 +0000 | [diff] [blame] | 902 | if (!PushdownMediaDescription(cricket::CA_PRANSWER, source, err_desc)) { |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 903 | SetError(ERROR_CONTENT, *err_desc); |
pthatcher@webrtc.org | 592470b | 2015-03-16 21:15:37 +0000 | [diff] [blame] | 904 | } |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 905 | if (error() != ERROR_NONE) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 906 | return BadPranswerSdp(source, GetSessionErrorMsg(), err_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 907 | } |
| 908 | } else if (action == kAnswer) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 909 | const cricket::ContentGroup* local_bundle = |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 910 | local_description()->description()->GetGroupByName( |
| 911 | cricket::GROUP_TYPE_BUNDLE); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 912 | const cricket::ContentGroup* remote_bundle = |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 913 | remote_description()->description()->GetGroupByName( |
| 914 | cricket::GROUP_TYPE_BUNDLE); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 915 | if (local_bundle && remote_bundle) { |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 916 | // The answerer decides the transport to bundle on. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 917 | const cricket::ContentGroup* answer_bundle = |
| 918 | (source == cricket::CS_LOCAL ? local_bundle : remote_bundle); |
| 919 | if (!EnableBundle(*answer_bundle)) { |
| 920 | LOG(LS_WARNING) << "Failed to enable BUNDLE."; |
| 921 | return BadAnswerSdp(source, kEnableBundleFailed, err_desc); |
| 922 | } |
| 923 | } |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 924 | // Only push down the transport description after enabling BUNDLE; we don't |
| 925 | // want to push down a description on a transport about to be destroyed. |
| 926 | if (!PushdownTransportDescription(source, cricket::CA_ANSWER, &td_err)) { |
| 927 | return BadAnswerSdp(source, MakeTdErrorString(td_err), err_desc); |
| 928 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 929 | EnableChannels(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 930 | SetState(STATE_INPROGRESS); |
pthatcher@webrtc.org | 592470b | 2015-03-16 21:15:37 +0000 | [diff] [blame] | 931 | if (!PushdownMediaDescription(cricket::CA_ANSWER, source, err_desc)) { |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 932 | SetError(ERROR_CONTENT, *err_desc); |
pthatcher@webrtc.org | 592470b | 2015-03-16 21:15:37 +0000 | [diff] [blame] | 933 | } |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 934 | if (error() != ERROR_NONE) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 935 | return BadAnswerSdp(source, GetSessionErrorMsg(), err_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 936 | } |
| 937 | } |
| 938 | return true; |
| 939 | } |
| 940 | |
| 941 | WebRtcSession::Action WebRtcSession::GetAction(const std::string& type) { |
| 942 | if (type == SessionDescriptionInterface::kOffer) { |
| 943 | return WebRtcSession::kOffer; |
| 944 | } else if (type == SessionDescriptionInterface::kPrAnswer) { |
| 945 | return WebRtcSession::kPrAnswer; |
| 946 | } else if (type == SessionDescriptionInterface::kAnswer) { |
| 947 | return WebRtcSession::kAnswer; |
| 948 | } |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 949 | RTC_NOTREACHED() << "unknown action type"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 950 | return WebRtcSession::kOffer; |
| 951 | } |
| 952 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 953 | bool WebRtcSession::PushdownMediaDescription( |
| 954 | cricket::ContentAction action, |
| 955 | cricket::ContentSource source, |
| 956 | std::string* err) { |
| 957 | auto set_content = [this, action, source, err](cricket::BaseChannel* ch) { |
| 958 | if (!ch) { |
| 959 | return true; |
| 960 | } else if (source == cricket::CS_LOCAL) { |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 961 | return ch->PushdownLocalDescription(local_description()->description(), |
| 962 | action, err); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 963 | } else { |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 964 | return ch->PushdownRemoteDescription(remote_description()->description(), |
| 965 | action, err); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 966 | } |
| 967 | }; |
| 968 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 969 | bool ret = (set_content(voice_channel()) && set_content(video_channel()) && |
| 970 | set_content(rtp_data_channel())); |
| 971 | // Need complete offer/answer with an SCTP m= section before starting SCTP, |
| 972 | // according to https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-19 |
| 973 | if (sctp_transport_ && local_description() && remote_description() && |
| 974 | cricket::GetFirstDataContent(local_description()->description()) && |
| 975 | cricket::GetFirstDataContent(remote_description()->description())) { |
| 976 | ret &= network_thread_->Invoke<bool>( |
| 977 | RTC_FROM_HERE, |
| 978 | rtc::Bind(&WebRtcSession::PushdownSctpParameters_n, this, source)); |
| 979 | } |
| 980 | return ret; |
| 981 | } |
| 982 | |
| 983 | bool WebRtcSession::PushdownSctpParameters_n(cricket::ContentSource source) { |
| 984 | RTC_DCHECK(network_thread_->IsCurrent()); |
| 985 | RTC_DCHECK(local_description()); |
| 986 | RTC_DCHECK(remote_description()); |
| 987 | // Apply the SCTP port (which is hidden inside a DataCodec structure...) |
| 988 | // When we support "max-message-size", that would also be pushed down here. |
| 989 | return sctp_transport_->Start( |
| 990 | GetSctpPort(local_description()->description()), |
| 991 | GetSctpPort(remote_description()->description())); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | bool WebRtcSession::PushdownTransportDescription(cricket::ContentSource source, |
| 995 | cricket::ContentAction action, |
| 996 | std::string* error_desc) { |
| 997 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
| 998 | |
| 999 | if (source == cricket::CS_LOCAL) { |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 1000 | return PushdownLocalTransportDescription(local_description()->description(), |
| 1001 | action, error_desc); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1002 | } |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 1003 | return PushdownRemoteTransportDescription(remote_description()->description(), |
| 1004 | action, error_desc); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | bool WebRtcSession::PushdownLocalTransportDescription( |
| 1008 | const SessionDescription* sdesc, |
| 1009 | cricket::ContentAction action, |
| 1010 | std::string* err) { |
| 1011 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
| 1012 | |
| 1013 | if (!sdesc) { |
| 1014 | return false; |
| 1015 | } |
| 1016 | |
| 1017 | for (const TransportInfo& tinfo : sdesc->transport_infos()) { |
| 1018 | if (!transport_controller_->SetLocalTransportDescription( |
| 1019 | tinfo.content_name, tinfo.description, action, err)) { |
| 1020 | return false; |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | return true; |
| 1025 | } |
| 1026 | |
| 1027 | bool WebRtcSession::PushdownRemoteTransportDescription( |
| 1028 | const SessionDescription* sdesc, |
| 1029 | cricket::ContentAction action, |
| 1030 | std::string* err) { |
| 1031 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
| 1032 | |
| 1033 | if (!sdesc) { |
| 1034 | return false; |
| 1035 | } |
| 1036 | |
| 1037 | for (const TransportInfo& tinfo : sdesc->transport_infos()) { |
| 1038 | if (!transport_controller_->SetRemoteTransportDescription( |
| 1039 | tinfo.content_name, tinfo.description, action, err)) { |
| 1040 | return false; |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | return true; |
| 1045 | } |
| 1046 | |
| 1047 | bool WebRtcSession::GetTransportDescription( |
| 1048 | const SessionDescription* description, |
| 1049 | const std::string& content_name, |
| 1050 | cricket::TransportDescription* tdesc) { |
| 1051 | if (!description || !tdesc) { |
| 1052 | return false; |
| 1053 | } |
| 1054 | const TransportInfo* transport_info = |
| 1055 | description->GetTransportInfoByName(content_name); |
| 1056 | if (!transport_info) { |
| 1057 | return false; |
| 1058 | } |
| 1059 | *tdesc = transport_info->description; |
| 1060 | return true; |
| 1061 | } |
| 1062 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1063 | bool WebRtcSession::EnableBundle(const cricket::ContentGroup& bundle) { |
| 1064 | const std::string* first_content_name = bundle.FirstContentName(); |
| 1065 | if (!first_content_name) { |
| 1066 | LOG(LS_WARNING) << "Tried to BUNDLE with no contents."; |
| 1067 | return false; |
| 1068 | } |
| 1069 | const std::string& transport_name = *first_content_name; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1070 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1071 | #ifdef HAVE_QUIC |
| 1072 | if (quic_data_transport_ && |
| 1073 | bundle.HasContentName(quic_data_transport_->content_name()) && |
| 1074 | quic_data_transport_->transport_name() != transport_name) { |
| 1075 | LOG(LS_ERROR) << "Unable to BUNDLE " << quic_data_transport_->content_name() |
| 1076 | << " on " << transport_name << "with QUIC."; |
| 1077 | } |
| 1078 | #endif |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1079 | auto maybe_set_transport = [this, bundle, |
| 1080 | transport_name](cricket::BaseChannel* ch) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1081 | if (!ch || !bundle.HasContentName(ch->content_name())) { |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 1082 | return true; |
| 1083 | } |
| 1084 | |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1085 | std::string old_transport_name = ch->transport_name(); |
| 1086 | if (old_transport_name == transport_name) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1087 | LOG(LS_INFO) << "BUNDLE already enabled for " << ch->content_name() |
| 1088 | << " on " << transport_name << "."; |
| 1089 | return true; |
deadbeef | 47ee2f3 | 2015-09-22 15:08:23 -0700 | [diff] [blame] | 1090 | } |
torbjorng | a81a42f | 2015-09-23 02:16:58 -0700 | [diff] [blame] | 1091 | |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1092 | cricket::DtlsTransportInternal* rtp_dtls_transport = |
| 1093 | transport_controller_->CreateDtlsTransport( |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1094 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1095 | bool need_rtcp = (ch->rtcp_dtls_transport() != nullptr); |
| 1096 | cricket::DtlsTransportInternal* rtcp_dtls_transport = nullptr; |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1097 | if (need_rtcp) { |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1098 | rtcp_dtls_transport = transport_controller_->CreateDtlsTransport_n( |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1099 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
| 1100 | } |
| 1101 | |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1102 | ch->SetTransports(rtp_dtls_transport, rtcp_dtls_transport); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1103 | LOG(LS_INFO) << "Enabled BUNDLE for " << ch->content_name() << " on " |
| 1104 | << transport_name << "."; |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1105 | transport_controller_->DestroyDtlsTransport( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 1106 | old_transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1107 | // If the channel needs rtcp, it means that the channel used to have a |
| 1108 | // rtcp transport which needs to be deleted now. |
| 1109 | if (need_rtcp) { |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1110 | transport_controller_->DestroyDtlsTransport( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 1111 | old_transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1112 | } |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 1113 | return true; |
| 1114 | }; |
| 1115 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1116 | if (!maybe_set_transport(voice_channel()) || |
| 1117 | !maybe_set_transport(video_channel()) || |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1118 | !maybe_set_transport(rtp_data_channel())) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1119 | return false; |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 1120 | } |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1121 | // For SCTP, transport creation/deletion happens here instead of in the |
| 1122 | // object itself. |
| 1123 | if (sctp_transport_) { |
| 1124 | RTC_DCHECK(sctp_transport_name_); |
| 1125 | RTC_DCHECK(sctp_content_name_); |
| 1126 | if (transport_name != *sctp_transport_name_ && |
| 1127 | bundle.HasContentName(*sctp_content_name_)) { |
| 1128 | network_thread_->Invoke<void>( |
| 1129 | RTC_FROM_HERE, rtc::Bind(&WebRtcSession::ChangeSctpTransport_n, this, |
| 1130 | transport_name)); |
| 1131 | } |
| 1132 | } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1133 | |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 1134 | return true; |
| 1135 | } |
| 1136 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1137 | bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) { |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 1138 | if (!remote_description()) { |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1139 | LOG(LS_ERROR) << "ProcessIceMessage: ICE candidates can't be added " |
| 1140 | << "without any remote session description."; |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 1141 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | if (!candidate) { |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1145 | LOG(LS_ERROR) << "ProcessIceMessage: Candidate is NULL."; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1146 | return false; |
| 1147 | } |
| 1148 | |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 1149 | bool valid = false; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1150 | bool ready = ReadyToUseRemoteCandidate(candidate, NULL, &valid); |
| 1151 | if (!valid) { |
| 1152 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | // Add this candidate to the remote session description. |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 1156 | if (!mutable_remote_description()->AddCandidate(candidate)) { |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1157 | LOG(LS_ERROR) << "ProcessIceMessage: Candidate cannot be used."; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1158 | return false; |
| 1159 | } |
| 1160 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1161 | if (ready) { |
| 1162 | return UseCandidate(candidate); |
| 1163 | } else { |
| 1164 | LOG(LS_INFO) << "ProcessIceMessage: Not ready to use candidate."; |
| 1165 | return true; |
| 1166 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1167 | } |
| 1168 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 1169 | bool WebRtcSession::RemoveRemoteIceCandidates( |
| 1170 | const std::vector<cricket::Candidate>& candidates) { |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 1171 | if (!remote_description()) { |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 1172 | LOG(LS_ERROR) << "RemoveRemoteIceCandidates: ICE candidates can't be " |
| 1173 | << "removed without any remote session description."; |
| 1174 | return false; |
| 1175 | } |
| 1176 | |
| 1177 | if (candidates.empty()) { |
| 1178 | LOG(LS_ERROR) << "RemoveRemoteIceCandidates: candidates are empty."; |
| 1179 | return false; |
| 1180 | } |
| 1181 | |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 1182 | size_t number_removed = |
| 1183 | mutable_remote_description()->RemoveCandidates(candidates); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 1184 | if (number_removed != candidates.size()) { |
| 1185 | LOG(LS_ERROR) << "RemoveRemoteIceCandidates: Failed to remove candidates. " |
| 1186 | << "Requested " << candidates.size() << " but only " |
| 1187 | << number_removed << " are removed."; |
| 1188 | } |
| 1189 | |
| 1190 | // Remove the candidates from the transport controller. |
| 1191 | std::string error; |
| 1192 | bool res = transport_controller_->RemoveRemoteCandidates(candidates, &error); |
| 1193 | if (!res && !error.empty()) { |
| 1194 | LOG(LS_ERROR) << "Error when removing remote candidates: " << error; |
| 1195 | } |
| 1196 | return true; |
| 1197 | } |
| 1198 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1199 | cricket::IceConfig WebRtcSession::ParseIceConfig( |
| 1200 | const PeerConnectionInterface::RTCConfiguration& config) const { |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 1201 | cricket::ContinualGatheringPolicy gathering_policy; |
| 1202 | // TODO(honghaiz): Add the third continual gathering policy in |
| 1203 | // PeerConnectionInterface and map it to GATHER_CONTINUALLY_AND_RECOVER. |
| 1204 | switch (config.continual_gathering_policy) { |
| 1205 | case PeerConnectionInterface::GATHER_ONCE: |
| 1206 | gathering_policy = cricket::GATHER_ONCE; |
| 1207 | break; |
| 1208 | case PeerConnectionInterface::GATHER_CONTINUALLY: |
| 1209 | gathering_policy = cricket::GATHER_CONTINUALLY; |
| 1210 | break; |
| 1211 | default: |
nisse | eb4ca4e | 2017-01-12 02:24:27 -0800 | [diff] [blame] | 1212 | RTC_NOTREACHED(); |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 1213 | gathering_policy = cricket::GATHER_ONCE; |
| 1214 | } |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1215 | cricket::IceConfig ice_config; |
Honghai Zhang | 049fbb1 | 2016-03-07 11:13:07 -0800 | [diff] [blame] | 1216 | ice_config.receiving_timeout = config.ice_connection_receiving_timeout; |
guoweis | 36f0137 | 2016-03-02 18:02:40 -0800 | [diff] [blame] | 1217 | ice_config.prioritize_most_likely_candidate_pairs = |
| 1218 | config.prioritize_most_likely_ice_candidate_pairs; |
Honghai Zhang | 381b421 | 2015-12-04 12:24:03 -0800 | [diff] [blame] | 1219 | ice_config.backup_connection_ping_interval = |
| 1220 | config.ice_backup_candidate_pair_ping_interval; |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 1221 | ice_config.continual_gathering_policy = gathering_policy; |
Taylor Brandstetter | e985111 | 2016-07-01 11:11:13 -0700 | [diff] [blame] | 1222 | ice_config.presume_writable_when_fully_relayed = |
| 1223 | config.presume_writable_when_fully_relayed; |
skvlad | 5107246 | 2017-02-02 11:50:14 -0800 | [diff] [blame] | 1224 | ice_config.ice_check_min_interval = config.ice_check_min_interval; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1225 | return ice_config; |
| 1226 | } |
| 1227 | |
| 1228 | void WebRtcSession::SetIceConfig(const cricket::IceConfig& config) { |
| 1229 | transport_controller_->SetIceConfig(config); |
| 1230 | } |
| 1231 | |
| 1232 | void WebRtcSession::MaybeStartGathering() { |
| 1233 | transport_controller_->MaybeStartGathering(); |
| 1234 | } |
| 1235 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1236 | bool WebRtcSession::GetLocalTrackIdBySsrc(uint32_t ssrc, |
| 1237 | std::string* track_id) { |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 1238 | if (!local_description()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1239 | return false; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1240 | } |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 1241 | return webrtc::GetTrackIdBySsrc(local_description()->description(), ssrc, |
| 1242 | track_id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1245 | bool WebRtcSession::GetRemoteTrackIdBySsrc(uint32_t ssrc, |
| 1246 | std::string* track_id) { |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 1247 | if (!remote_description()) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1248 | return false; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1249 | } |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 1250 | return webrtc::GetTrackIdBySsrc(remote_description()->description(), ssrc, |
| 1251 | track_id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1254 | std::string WebRtcSession::BadStateErrMsg(State state) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1255 | std::ostringstream desc; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1256 | desc << "Called in wrong state: " << GetStateString(state); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1257 | return desc.str(); |
| 1258 | } |
| 1259 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 1260 | bool WebRtcSession::SendData(const cricket::SendDataParams& params, |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 1261 | const rtc::CopyOnWriteBuffer& payload, |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 1262 | cricket::SendDataResult* result) { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1263 | if (!rtp_data_channel_ && !sctp_transport_) { |
| 1264 | LOG(LS_ERROR) << "SendData called when rtp_data_channel_ " |
| 1265 | << "and sctp_transport_ are NULL."; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 1266 | return false; |
| 1267 | } |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1268 | return rtp_data_channel_ |
| 1269 | ? rtp_data_channel_->SendData(params, payload, result) |
| 1270 | : network_thread_->Invoke<bool>( |
| 1271 | RTC_FROM_HERE, |
| 1272 | Bind(&cricket::SctpTransportInternal::SendData, |
| 1273 | sctp_transport_.get(), params, payload, result)); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | bool WebRtcSession::ConnectDataChannel(DataChannel* webrtc_data_channel) { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1277 | if (!rtp_data_channel_ && !sctp_transport_) { |
deadbeef | daf88b1 | 2016-10-05 22:29:30 -0700 | [diff] [blame] | 1278 | // Don't log an error here, because DataChannels are expected to call |
| 1279 | // ConnectDataChannel in this state. It's the only way to initially tell |
| 1280 | // whether or not the underlying transport is ready. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 1281 | return false; |
| 1282 | } |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1283 | if (rtp_data_channel_) { |
| 1284 | rtp_data_channel_->SignalReadyToSendData.connect( |
| 1285 | webrtc_data_channel, &DataChannel::OnChannelReady); |
| 1286 | rtp_data_channel_->SignalDataReceived.connect(webrtc_data_channel, |
| 1287 | &DataChannel::OnDataReceived); |
| 1288 | } else { |
| 1289 | SignalSctpReadyToSendData.connect(webrtc_data_channel, |
| 1290 | &DataChannel::OnChannelReady); |
| 1291 | SignalSctpDataReceived.connect(webrtc_data_channel, |
| 1292 | &DataChannel::OnDataReceived); |
| 1293 | SignalSctpStreamClosedRemotely.connect( |
| 1294 | webrtc_data_channel, &DataChannel::OnStreamClosedRemotely); |
| 1295 | } |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 1296 | return true; |
| 1297 | } |
| 1298 | |
| 1299 | void WebRtcSession::DisconnectDataChannel(DataChannel* webrtc_data_channel) { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1300 | if (!rtp_data_channel_ && !sctp_transport_) { |
| 1301 | LOG(LS_ERROR) << "DisconnectDataChannel called when rtp_data_channel_ and " |
| 1302 | "sctp_transport_ are NULL."; |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1303 | return; |
| 1304 | } |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1305 | if (rtp_data_channel_) { |
| 1306 | rtp_data_channel_->SignalReadyToSendData.disconnect(webrtc_data_channel); |
| 1307 | rtp_data_channel_->SignalDataReceived.disconnect(webrtc_data_channel); |
| 1308 | } else { |
| 1309 | SignalSctpReadyToSendData.disconnect(webrtc_data_channel); |
| 1310 | SignalSctpDataReceived.disconnect(webrtc_data_channel); |
| 1311 | SignalSctpStreamClosedRemotely.disconnect(webrtc_data_channel); |
| 1312 | } |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
bemasc@webrtc.org | 9b5467e | 2014-12-04 23:16:52 +0000 | [diff] [blame] | 1315 | void WebRtcSession::AddSctpDataStream(int sid) { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1316 | if (!sctp_transport_) { |
| 1317 | LOG(LS_ERROR) << "AddSctpDataStream called when sctp_transport_ is NULL."; |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1318 | return; |
| 1319 | } |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1320 | network_thread_->Invoke<void>( |
| 1321 | RTC_FROM_HERE, rtc::Bind(&cricket::SctpTransportInternal::OpenStream, |
| 1322 | sctp_transport_.get(), sid)); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
bemasc@webrtc.org | 9b5467e | 2014-12-04 23:16:52 +0000 | [diff] [blame] | 1325 | void WebRtcSession::RemoveSctpDataStream(int sid) { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1326 | if (!sctp_transport_) { |
| 1327 | LOG(LS_ERROR) << "RemoveSctpDataStream called when sctp_transport_ is " |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1328 | << "NULL."; |
| 1329 | return; |
| 1330 | } |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1331 | network_thread_->Invoke<void>( |
| 1332 | RTC_FROM_HERE, rtc::Bind(&cricket::SctpTransportInternal::ResetStream, |
| 1333 | sctp_transport_.get(), sid)); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1334 | } |
| 1335 | |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 1336 | bool WebRtcSession::ReadyToSendData() const { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1337 | return (rtp_data_channel_ && rtp_data_channel_->ready_to_send_data()) || |
| 1338 | sctp_ready_to_send_data_; |
| 1339 | } |
| 1340 | |
| 1341 | std::unique_ptr<SessionStats> WebRtcSession::GetStats_s() { |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 1342 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1343 | ChannelNamePairs channel_name_pairs; |
| 1344 | if (voice_channel()) { |
| 1345 | channel_name_pairs.voice = rtc::Optional<ChannelNamePair>(ChannelNamePair( |
| 1346 | voice_channel()->content_name(), voice_channel()->transport_name())); |
| 1347 | } |
| 1348 | if (video_channel()) { |
| 1349 | channel_name_pairs.video = rtc::Optional<ChannelNamePair>(ChannelNamePair( |
| 1350 | video_channel()->content_name(), video_channel()->transport_name())); |
| 1351 | } |
| 1352 | if (rtp_data_channel()) { |
| 1353 | channel_name_pairs.data = rtc::Optional<ChannelNamePair>( |
| 1354 | ChannelNamePair(rtp_data_channel()->content_name(), |
| 1355 | rtp_data_channel()->transport_name())); |
| 1356 | } |
| 1357 | if (sctp_transport_) { |
| 1358 | RTC_DCHECK(sctp_content_name_); |
| 1359 | RTC_DCHECK(sctp_transport_name_); |
| 1360 | channel_name_pairs.data = rtc::Optional<ChannelNamePair>( |
| 1361 | ChannelNamePair(*sctp_content_name_, *sctp_transport_name_)); |
| 1362 | } |
| 1363 | return GetStats(channel_name_pairs); |
| 1364 | } |
| 1365 | |
| 1366 | std::unique_ptr<SessionStats> WebRtcSession::GetStats( |
| 1367 | const ChannelNamePairs& channel_name_pairs) { |
| 1368 | if (network_thread()->IsCurrent()) { |
| 1369 | return GetStats_n(channel_name_pairs); |
| 1370 | } |
| 1371 | return network_thread()->Invoke<std::unique_ptr<SessionStats>>( |
| 1372 | RTC_FROM_HERE, |
| 1373 | rtc::Bind(&WebRtcSession::GetStats_n, this, channel_name_pairs)); |
| 1374 | } |
| 1375 | |
| 1376 | bool WebRtcSession::GetLocalCertificate( |
| 1377 | const std::string& transport_name, |
| 1378 | rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { |
| 1379 | return transport_controller_->GetLocalCertificate(transport_name, |
| 1380 | certificate); |
| 1381 | } |
| 1382 | |
| 1383 | std::unique_ptr<rtc::SSLCertificate> WebRtcSession::GetRemoteSSLCertificate( |
| 1384 | const std::string& transport_name) { |
| 1385 | return transport_controller_->GetRemoteSSLCertificate(transport_name); |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1388 | cricket::DataChannelType WebRtcSession::data_channel_type() const { |
| 1389 | return data_channel_type_; |
| 1390 | } |
| 1391 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 1392 | bool WebRtcSession::IceRestartPending(const std::string& content_name) const { |
| 1393 | return pending_ice_restarts_.find(content_name) != |
| 1394 | pending_ice_restarts_.end(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 1397 | void WebRtcSession::SetNeedsIceRestartFlag() { |
| 1398 | transport_controller_->SetNeedsIceRestartFlag(); |
| 1399 | } |
| 1400 | |
| 1401 | bool WebRtcSession::NeedsIceRestart(const std::string& content_name) const { |
| 1402 | return transport_controller_->NeedsIceRestart(content_name); |
| 1403 | } |
| 1404 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 1405 | void WebRtcSession::OnCertificateReady( |
| 1406 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1407 | transport_controller_->SetLocalCertificate(certificate); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1410 | void WebRtcSession::OnDtlsSrtpSetupFailure(cricket::BaseChannel*, bool rtcp) { |
| 1411 | SetError(ERROR_TRANSPORT, |
| 1412 | rtcp ? kDtlsSrtpSetupFailureRtcp : kDtlsSrtpSetupFailureRtp); |
| 1413 | } |
| 1414 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 1415 | bool WebRtcSession::waiting_for_certificate_for_testing() const { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1416 | return webrtc_session_desc_factory_->waiting_for_certificate_for_testing(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1419 | const rtc::scoped_refptr<rtc::RTCCertificate>& |
| 1420 | WebRtcSession::certificate_for_testing() { |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1421 | return transport_controller_->certificate_for_testing(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1424 | void WebRtcSession::SetIceConnectionState( |
| 1425 | PeerConnectionInterface::IceConnectionState state) { |
| 1426 | if (ice_connection_state_ == state) { |
| 1427 | return; |
| 1428 | } |
| 1429 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1430 | LOG(LS_INFO) << "Changing IceConnectionState " << ice_connection_state_ |
| 1431 | << " => " << state; |
Taylor Brandstetter | 6aefc63 | 2016-05-26 16:08:23 -0700 | [diff] [blame] | 1432 | RTC_DCHECK(ice_connection_state_ != |
| 1433 | PeerConnectionInterface::kIceConnectionClosed); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1434 | ice_connection_state_ = state; |
| 1435 | if (ice_observer_) { |
zstein | 6dfd53a | 2017-03-06 13:49:03 -0800 | [diff] [blame] | 1436 | ice_observer_->OnIceConnectionStateChange(ice_connection_state_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1437 | } |
| 1438 | } |
| 1439 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1440 | void WebRtcSession::OnTransportControllerConnectionState( |
| 1441 | cricket::IceConnectionState state) { |
| 1442 | switch (state) { |
| 1443 | case cricket::kIceConnectionConnecting: |
| 1444 | // If the current state is Connected or Completed, then there were |
| 1445 | // writable channels but now there are not, so the next state must |
| 1446 | // be Disconnected. |
| 1447 | // kIceConnectionConnecting is currently used as the default, |
| 1448 | // un-connected state by the TransportController, so its only use is |
| 1449 | // detecting disconnections. |
| 1450 | if (ice_connection_state_ == |
| 1451 | PeerConnectionInterface::kIceConnectionConnected || |
| 1452 | ice_connection_state_ == |
| 1453 | PeerConnectionInterface::kIceConnectionCompleted) { |
| 1454 | SetIceConnectionState( |
| 1455 | PeerConnectionInterface::kIceConnectionDisconnected); |
| 1456 | } |
torbjorng | a81a42f | 2015-09-23 02:16:58 -0700 | [diff] [blame] | 1457 | break; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1458 | case cricket::kIceConnectionFailed: |
| 1459 | SetIceConnectionState(PeerConnectionInterface::kIceConnectionFailed); |
| 1460 | break; |
| 1461 | case cricket::kIceConnectionConnected: |
| 1462 | LOG(LS_INFO) << "Changing to ICE connected state because " |
| 1463 | << "all transports are writable."; |
| 1464 | SetIceConnectionState(PeerConnectionInterface::kIceConnectionConnected); |
| 1465 | break; |
| 1466 | case cricket::kIceConnectionCompleted: |
| 1467 | LOG(LS_INFO) << "Changing to ICE completed state because " |
| 1468 | << "all transports are complete."; |
| 1469 | if (ice_connection_state_ != |
| 1470 | PeerConnectionInterface::kIceConnectionConnected) { |
| 1471 | // If jumping directly from "checking" to "connected", |
| 1472 | // signal "connected" first. |
| 1473 | SetIceConnectionState(PeerConnectionInterface::kIceConnectionConnected); |
| 1474 | } |
| 1475 | SetIceConnectionState(PeerConnectionInterface::kIceConnectionCompleted); |
| 1476 | if (metrics_observer_) { |
| 1477 | ReportTransportStats(); |
| 1478 | } |
| 1479 | break; |
| 1480 | default: |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 1481 | RTC_NOTREACHED(); |
torbjorng | a81a42f | 2015-09-23 02:16:58 -0700 | [diff] [blame] | 1482 | } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | void WebRtcSession::OnTransportControllerReceiving(bool receiving) { |
Peter Thatcher | 5436051 | 2015-07-08 11:08:35 -0700 | [diff] [blame] | 1486 | SetIceConnectionReceiving(receiving); |
| 1487 | } |
| 1488 | |
| 1489 | void WebRtcSession::SetIceConnectionReceiving(bool receiving) { |
| 1490 | if (ice_connection_receiving_ == receiving) { |
| 1491 | return; |
| 1492 | } |
| 1493 | ice_connection_receiving_ = receiving; |
| 1494 | if (ice_observer_) { |
| 1495 | ice_observer_->OnIceConnectionReceivingChange(receiving); |
| 1496 | } |
| 1497 | } |
| 1498 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1499 | void WebRtcSession::OnTransportControllerCandidatesGathered( |
| 1500 | const std::string& transport_name, |
| 1501 | const cricket::Candidates& candidates) { |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 1502 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1503 | int sdp_mline_index; |
| 1504 | if (!GetLocalCandidateMediaIndex(transport_name, &sdp_mline_index)) { |
| 1505 | LOG(LS_ERROR) << "OnTransportControllerCandidatesGathered: content name " |
| 1506 | << transport_name << " not found"; |
| 1507 | return; |
| 1508 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1509 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1510 | for (cricket::Candidates::const_iterator citer = candidates.begin(); |
| 1511 | citer != candidates.end(); ++citer) { |
| 1512 | // Use transport_name as the candidate media id. |
jbauch | 81bf7b0 | 2017-03-25 08:31:12 -0700 | [diff] [blame] | 1513 | std::unique_ptr<JsepIceCandidate> candidate( |
| 1514 | new JsepIceCandidate(transport_name, sdp_mline_index, *citer)); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 1515 | if (local_description()) { |
jbauch | 81bf7b0 | 2017-03-25 08:31:12 -0700 | [diff] [blame] | 1516 | mutable_local_description()->AddCandidate(candidate.get()); |
| 1517 | } |
| 1518 | if (ice_observer_) { |
| 1519 | ice_observer_->OnIceCandidate(std::move(candidate)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1520 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1521 | } |
| 1522 | } |
| 1523 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 1524 | void WebRtcSession::OnTransportControllerCandidatesRemoved( |
| 1525 | const std::vector<cricket::Candidate>& candidates) { |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 1526 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 1527 | // Sanity check. |
| 1528 | for (const cricket::Candidate& candidate : candidates) { |
| 1529 | if (candidate.transport_name().empty()) { |
| 1530 | LOG(LS_ERROR) << "OnTransportControllerCandidatesRemoved: " |
| 1531 | << "empty content name in candidate " |
| 1532 | << candidate.ToString(); |
| 1533 | return; |
| 1534 | } |
| 1535 | } |
| 1536 | |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 1537 | if (local_description()) { |
| 1538 | mutable_local_description()->RemoveCandidates(candidates); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 1539 | } |
| 1540 | if (ice_observer_) { |
| 1541 | ice_observer_->OnIceCandidatesRemoved(candidates); |
| 1542 | } |
| 1543 | } |
| 1544 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1545 | void WebRtcSession::OnTransportControllerDtlsHandshakeError( |
| 1546 | rtc::SSLHandshakeError error) { |
| 1547 | if (metrics_observer_) { |
| 1548 | metrics_observer_->IncrementEnumCounter( |
| 1549 | webrtc::kEnumCounterDtlsHandshakeError, static_cast<int>(error), |
| 1550 | static_cast<int>(rtc::SSLHandshakeError::MAX_VALUE)); |
| 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | // Enabling voice and video (and RTP data) channel. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1555 | void WebRtcSession::EnableChannels() { |
| 1556 | if (voice_channel_ && !voice_channel_->enabled()) |
| 1557 | voice_channel_->Enable(true); |
| 1558 | |
| 1559 | if (video_channel_ && !video_channel_->enabled()) |
| 1560 | video_channel_->Enable(true); |
| 1561 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1562 | if (rtp_data_channel_ && !rtp_data_channel_->enabled()) |
| 1563 | rtp_data_channel_->Enable(true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1566 | // Returns the media index for a local ice candidate given the content name. |
| 1567 | bool WebRtcSession::GetLocalCandidateMediaIndex(const std::string& content_name, |
| 1568 | int* sdp_mline_index) { |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 1569 | if (!local_description() || !sdp_mline_index) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1570 | return false; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1571 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1572 | |
| 1573 | bool content_found = false; |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 1574 | const ContentInfos& contents = local_description()->description()->contents(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1575 | for (size_t index = 0; index < contents.size(); ++index) { |
| 1576 | if (contents[index].name == content_name) { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1577 | *sdp_mline_index = static_cast<int>(index); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1578 | content_found = true; |
| 1579 | break; |
| 1580 | } |
| 1581 | } |
| 1582 | return content_found; |
| 1583 | } |
| 1584 | |
| 1585 | bool WebRtcSession::UseCandidatesInSessionDescription( |
| 1586 | const SessionDescriptionInterface* remote_desc) { |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1587 | if (!remote_desc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1588 | return true; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1589 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1590 | bool ret = true; |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 1591 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1592 | for (size_t m = 0; m < remote_desc->number_of_mediasections(); ++m) { |
| 1593 | const IceCandidateCollection* candidates = remote_desc->candidates(m); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1594 | for (size_t n = 0; n < candidates->count(); ++n) { |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 1595 | const IceCandidateInterface* candidate = candidates->at(n); |
| 1596 | bool valid = false; |
| 1597 | if (!ReadyToUseRemoteCandidate(candidate, remote_desc, &valid)) { |
| 1598 | if (valid) { |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1599 | LOG(LS_INFO) << "UseCandidatesInSessionDescription: Not ready to use " |
| 1600 | << "candidate."; |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 1601 | } |
| 1602 | continue; |
| 1603 | } |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 1604 | ret = UseCandidate(candidate); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1605 | if (!ret) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1606 | break; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1607 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1608 | } |
| 1609 | } |
| 1610 | return ret; |
| 1611 | } |
| 1612 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 1613 | bool WebRtcSession::UseCandidate(const IceCandidateInterface* candidate) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1614 | size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 1615 | size_t remote_content_size = |
| 1616 | remote_description()->description()->contents().size(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1617 | if (mediacontent_index >= remote_content_size) { |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 1618 | LOG(LS_ERROR) << "UseCandidate: Invalid candidate media index."; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1619 | return false; |
| 1620 | } |
| 1621 | |
| 1622 | cricket::ContentInfo content = |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 1623 | remote_description()->description()->contents()[mediacontent_index]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1624 | std::vector<cricket::Candidate> candidates; |
| 1625 | candidates.push_back(candidate->candidate()); |
| 1626 | // Invoking BaseSession method to handle remote candidates. |
| 1627 | std::string error; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1628 | if (transport_controller_->AddRemoteCandidates(content.name, candidates, |
| 1629 | &error)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1630 | // Candidates successfully submitted for checking. |
| 1631 | if (ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew || |
| 1632 | ice_connection_state_ == |
| 1633 | PeerConnectionInterface::kIceConnectionDisconnected) { |
| 1634 | // If state is New, then the session has just gotten its first remote ICE |
| 1635 | // candidates, so go to Checking. |
| 1636 | // If state is Disconnected, the session is re-using old candidates or |
| 1637 | // receiving additional ones, so go to Checking. |
| 1638 | // If state is Connected, stay Connected. |
| 1639 | // TODO(bemasc): If state is Connected, and the new candidates are for a |
| 1640 | // newly added transport, then the state actually _should_ move to |
| 1641 | // checking. Add a way to distinguish that case. |
| 1642 | SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking); |
| 1643 | } |
| 1644 | // TODO(bemasc): If state is Completed, go back to Connected. |
| 1645 | } else { |
fischman@webrtc.org | 4f2bd68 | 2014-03-28 18:13:34 +0000 | [diff] [blame] | 1646 | if (!error.empty()) { |
| 1647 | LOG(LS_WARNING) << error; |
| 1648 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1649 | } |
| 1650 | return true; |
| 1651 | } |
| 1652 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1653 | void WebRtcSession::RemoveUnusedChannels(const SessionDescription* desc) { |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 1654 | // Destroy video_channel_ first since it may have a pointer to the |
| 1655 | // voice_channel_. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1656 | const cricket::ContentInfo* video_info = |
| 1657 | cricket::GetFirstVideoContent(desc); |
| 1658 | if ((!video_info || video_info->rejected) && video_channel_) { |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1659 | DestroyVideoChannel(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 1662 | const cricket::ContentInfo* voice_info = |
| 1663 | cricket::GetFirstAudioContent(desc); |
| 1664 | if ((!voice_info || voice_info->rejected) && voice_channel_) { |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1665 | DestroyVoiceChannel(); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 1666 | } |
| 1667 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1668 | const cricket::ContentInfo* data_info = |
| 1669 | cricket::GetFirstDataContent(desc); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1670 | if (!data_info || data_info->rejected) { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1671 | if (rtp_data_channel_) { |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1672 | DestroyDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1673 | } |
| 1674 | if (sctp_transport_) { |
| 1675 | SignalDataChannelDestroyed(); |
| 1676 | network_thread_->Invoke<void>( |
| 1677 | RTC_FROM_HERE, |
| 1678 | rtc::Bind(&WebRtcSession::DestroySctpTransport_n, this)); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1679 | } |
| 1680 | #ifdef HAVE_QUIC |
| 1681 | // Clean up the existing QuicDataTransport and its QuicTransportChannels. |
| 1682 | if (quic_data_transport_) { |
| 1683 | quic_data_transport_.reset(); |
| 1684 | } |
| 1685 | #endif |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1686 | } |
| 1687 | } |
| 1688 | |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 1689 | // Returns the name of the transport channel when BUNDLE is enabled, or nullptr |
| 1690 | // if the channel is not part of any bundle. |
| 1691 | const std::string* WebRtcSession::GetBundleTransportName( |
| 1692 | const cricket::ContentInfo* content, |
| 1693 | const cricket::ContentGroup* bundle) { |
| 1694 | if (!bundle) { |
| 1695 | return nullptr; |
| 1696 | } |
| 1697 | const std::string* first_content_name = bundle->FirstContentName(); |
| 1698 | if (!first_content_name) { |
| 1699 | LOG(LS_WARNING) << "Tried to BUNDLE with no contents."; |
| 1700 | return nullptr; |
| 1701 | } |
| 1702 | if (!bundle->HasContentName(content->name)) { |
| 1703 | LOG(LS_WARNING) << content->name << " is not part of any bundle group"; |
| 1704 | return nullptr; |
| 1705 | } |
| 1706 | LOG(LS_INFO) << "Bundling " << content->name << " on " << *first_content_name; |
| 1707 | return first_content_name; |
| 1708 | } |
| 1709 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1710 | bool WebRtcSession::CreateChannels(const SessionDescription* desc) { |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 1711 | const cricket::ContentGroup* bundle_group = nullptr; |
| 1712 | if (bundle_policy_ == PeerConnectionInterface::kBundlePolicyMaxBundle) { |
| 1713 | bundle_group = desc->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1714 | if (!bundle_group) { |
| 1715 | LOG(LS_WARNING) << "max-bundle specified without BUNDLE specified"; |
| 1716 | return false; |
| 1717 | } |
| 1718 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1719 | // Creating the media channels and transport proxies. |
| 1720 | const cricket::ContentInfo* voice = cricket::GetFirstAudioContent(desc); |
| 1721 | if (voice && !voice->rejected && !voice_channel_) { |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 1722 | if (!CreateVoiceChannel(voice, |
| 1723 | GetBundleTransportName(voice, bundle_group))) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1724 | LOG(LS_ERROR) << "Failed to create voice channel."; |
| 1725 | return false; |
| 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc); |
| 1730 | if (video && !video->rejected && !video_channel_) { |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 1731 | if (!CreateVideoChannel(video, |
| 1732 | GetBundleTransportName(video, bundle_group))) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1733 | LOG(LS_ERROR) << "Failed to create video channel."; |
| 1734 | return false; |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | const cricket::ContentInfo* data = cricket::GetFirstDataContent(desc); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1739 | if (data_channel_type_ != cricket::DCT_NONE && data && !data->rejected && |
| 1740 | !rtp_data_channel_ && !sctp_transport_) { |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 1741 | if (!CreateDataChannel(data, GetBundleTransportName(data, bundle_group))) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1742 | LOG(LS_ERROR) << "Failed to create data channel."; |
| 1743 | return false; |
| 1744 | } |
| 1745 | } |
| 1746 | |
| 1747 | return true; |
| 1748 | } |
| 1749 | |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 1750 | bool WebRtcSession::CreateVoiceChannel(const cricket::ContentInfo* content, |
| 1751 | const std::string* bundle_transport) { |
| 1752 | bool require_rtcp_mux = |
| 1753 | rtcp_mux_policy_ == PeerConnectionInterface::kRtcpMuxPolicyRequire; |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1754 | |
| 1755 | std::string transport_name = |
| 1756 | bundle_transport ? *bundle_transport : content->name; |
| 1757 | |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1758 | cricket::DtlsTransportInternal* rtp_dtls_transport = |
| 1759 | transport_controller_->CreateDtlsTransport( |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1760 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1761 | cricket::DtlsTransportInternal* rtcp_dtls_transport = nullptr; |
deadbeef | ac22f70 | 2017-01-12 21:59:29 -0800 | [diff] [blame] | 1762 | if (!require_rtcp_mux) { |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1763 | rtcp_dtls_transport = transport_controller_->CreateDtlsTransport( |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1764 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
| 1765 | } |
| 1766 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1767 | voice_channel_.reset(channel_manager_->CreateVoiceChannel( |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 1768 | call_, media_config_, rtp_dtls_transport, rtcp_dtls_transport, |
deadbeef | 1a2183d | 2017-02-10 23:44:49 -0800 | [diff] [blame] | 1769 | transport_controller_->signaling_thread(), content->name, SrtpRequired(), |
| 1770 | audio_options_)); |
pthatcher@webrtc.org | 4eeef58 | 2015-03-16 19:34:23 +0000 | [diff] [blame] | 1771 | if (!voice_channel_) { |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1772 | transport_controller_->DestroyDtlsTransport( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 1773 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1774 | if (rtcp_dtls_transport) { |
| 1775 | transport_controller_->DestroyDtlsTransport( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 1776 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
| 1777 | } |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 1778 | return false; |
pthatcher@webrtc.org | 4eeef58 | 2015-03-16 19:34:23 +0000 | [diff] [blame] | 1779 | } |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1780 | |
deadbeef | ac22f70 | 2017-01-12 21:59:29 -0800 | [diff] [blame] | 1781 | voice_channel_->SignalRtcpMuxFullyActive.connect( |
| 1782 | this, &WebRtcSession::DestroyRtcpTransport_n); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1783 | voice_channel_->SignalDtlsSrtpSetupFailure.connect( |
| 1784 | this, &WebRtcSession::OnDtlsSrtpSetupFailure); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1785 | |
| 1786 | SignalVoiceChannelCreated(); |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 1787 | voice_channel_->SignalSentPacket.connect(this, |
| 1788 | &WebRtcSession::OnSentPacket_w); |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 1789 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1790 | } |
| 1791 | |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 1792 | bool WebRtcSession::CreateVideoChannel(const cricket::ContentInfo* content, |
| 1793 | const std::string* bundle_transport) { |
| 1794 | bool require_rtcp_mux = |
| 1795 | rtcp_mux_policy_ == PeerConnectionInterface::kRtcpMuxPolicyRequire; |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1796 | |
| 1797 | std::string transport_name = |
| 1798 | bundle_transport ? *bundle_transport : content->name; |
| 1799 | |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1800 | cricket::DtlsTransportInternal* rtp_dtls_transport = |
| 1801 | transport_controller_->CreateDtlsTransport( |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1802 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1803 | cricket::DtlsTransportInternal* rtcp_dtls_transport = nullptr; |
deadbeef | ac22f70 | 2017-01-12 21:59:29 -0800 | [diff] [blame] | 1804 | if (!require_rtcp_mux) { |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1805 | rtcp_dtls_transport = transport_controller_->CreateDtlsTransport( |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1806 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
| 1807 | } |
| 1808 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1809 | video_channel_.reset(channel_manager_->CreateVideoChannel( |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 1810 | call_, media_config_, rtp_dtls_transport, rtcp_dtls_transport, |
deadbeef | 1a2183d | 2017-02-10 23:44:49 -0800 | [diff] [blame] | 1811 | transport_controller_->signaling_thread(), content->name, SrtpRequired(), |
| 1812 | video_options_)); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1813 | |
pthatcher@webrtc.org | 4eeef58 | 2015-03-16 19:34:23 +0000 | [diff] [blame] | 1814 | if (!video_channel_) { |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1815 | transport_controller_->DestroyDtlsTransport( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 1816 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1817 | if (rtcp_dtls_transport) { |
| 1818 | transport_controller_->DestroyDtlsTransport( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 1819 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
| 1820 | } |
pthatcher@webrtc.org | 4eeef58 | 2015-03-16 19:34:23 +0000 | [diff] [blame] | 1821 | return false; |
| 1822 | } |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1823 | |
deadbeef | ac22f70 | 2017-01-12 21:59:29 -0800 | [diff] [blame] | 1824 | video_channel_->SignalRtcpMuxFullyActive.connect( |
| 1825 | this, &WebRtcSession::DestroyRtcpTransport_n); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1826 | video_channel_->SignalDtlsSrtpSetupFailure.connect( |
| 1827 | this, &WebRtcSession::OnDtlsSrtpSetupFailure); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1828 | |
| 1829 | SignalVideoChannelCreated(); |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 1830 | video_channel_->SignalSentPacket.connect(this, |
| 1831 | &WebRtcSession::OnSentPacket_w); |
pthatcher@webrtc.org | 4eeef58 | 2015-03-16 19:34:23 +0000 | [diff] [blame] | 1832 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 1835 | bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content, |
| 1836 | const std::string* bundle_transport) { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1837 | const std::string transport_name = |
| 1838 | bundle_transport ? *bundle_transport : content->name; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1839 | #ifdef HAVE_QUIC |
| 1840 | if (data_channel_type_ == cricket::DCT_QUIC) { |
| 1841 | RTC_DCHECK(transport_controller_->quic()); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1842 | quic_data_transport_->SetTransports(transport_name); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1843 | return true; |
| 1844 | } |
| 1845 | #endif // HAVE_QUIC |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1846 | bool sctp = (data_channel_type_ == cricket::DCT_SCTP); |
deadbeef | c0dad89 | 2017-01-04 20:28:21 -0800 | [diff] [blame] | 1847 | if (sctp) { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1848 | if (!sctp_factory_) { |
| 1849 | LOG(LS_ERROR) |
| 1850 | << "Trying to create SCTP transport, but didn't compile with " |
| 1851 | "SCTP support (HAVE_SCTP)"; |
| 1852 | return false; |
| 1853 | } |
| 1854 | if (!network_thread_->Invoke<bool>( |
| 1855 | RTC_FROM_HERE, rtc::Bind(&WebRtcSession::CreateSctpTransport_n, |
| 1856 | this, content->name, transport_name))) { |
| 1857 | return false; |
| 1858 | }; |
| 1859 | } else { |
| 1860 | bool require_rtcp_mux = |
| 1861 | rtcp_mux_policy_ == PeerConnectionInterface::kRtcpMuxPolicyRequire; |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1862 | |
| 1863 | std::string transport_name = |
| 1864 | bundle_transport ? *bundle_transport : content->name; |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1865 | cricket::DtlsTransportInternal* rtp_dtls_transport = |
| 1866 | transport_controller_->CreateDtlsTransport( |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1867 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1868 | cricket::DtlsTransportInternal* rtcp_dtls_transport = nullptr; |
deadbeef | ac22f70 | 2017-01-12 21:59:29 -0800 | [diff] [blame] | 1869 | if (!require_rtcp_mux) { |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1870 | rtcp_dtls_transport = transport_controller_->CreateDtlsTransport( |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1871 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
| 1872 | } |
| 1873 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1874 | rtp_data_channel_.reset(channel_manager_->CreateRtpDataChannel( |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 1875 | media_config_, rtp_dtls_transport, rtcp_dtls_transport, |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1876 | transport_controller_->signaling_thread(), content->name, |
deadbeef | 1a2183d | 2017-02-10 23:44:49 -0800 | [diff] [blame] | 1877 | SrtpRequired())); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1878 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1879 | if (!rtp_data_channel_) { |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1880 | transport_controller_->DestroyDtlsTransport( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 1881 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1882 | if (rtcp_dtls_transport) { |
| 1883 | transport_controller_->DestroyDtlsTransport( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 1884 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
| 1885 | } |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1886 | return false; |
| 1887 | } |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1888 | |
deadbeef | ac22f70 | 2017-01-12 21:59:29 -0800 | [diff] [blame] | 1889 | rtp_data_channel_->SignalRtcpMuxFullyActive.connect( |
| 1890 | this, &WebRtcSession::DestroyRtcpTransport_n); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1891 | rtp_data_channel_->SignalDtlsSrtpSetupFailure.connect( |
| 1892 | this, &WebRtcSession::OnDtlsSrtpSetupFailure); |
| 1893 | rtp_data_channel_->SignalSentPacket.connect(this, |
| 1894 | &WebRtcSession::OnSentPacket_w); |
deadbeef | c0dad89 | 2017-01-04 20:28:21 -0800 | [diff] [blame] | 1895 | } |
| 1896 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1897 | SignalDataChannelCreated(); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 1898 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1899 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1900 | } |
| 1901 | |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 1902 | Call::Stats WebRtcSession::GetCallStats() { |
| 1903 | if (!worker_thread()->IsCurrent()) { |
| 1904 | return worker_thread()->Invoke<Call::Stats>( |
| 1905 | RTC_FROM_HERE, rtc::Bind(&WebRtcSession::GetCallStats, this)); |
| 1906 | } |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 1907 | if (!call_) |
| 1908 | return Call::Stats(); |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 1909 | return call_->GetStats(); |
| 1910 | } |
| 1911 | |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 1912 | std::unique_ptr<SessionStats> WebRtcSession::GetStats_n( |
| 1913 | const ChannelNamePairs& channel_name_pairs) { |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 1914 | RTC_DCHECK(network_thread()->IsCurrent()); |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 1915 | std::unique_ptr<SessionStats> session_stats(new SessionStats()); |
| 1916 | for (const auto channel_name_pair : { &channel_name_pairs.voice, |
| 1917 | &channel_name_pairs.video, |
| 1918 | &channel_name_pairs.data }) { |
| 1919 | if (*channel_name_pair) { |
| 1920 | cricket::TransportStats transport_stats; |
| 1921 | if (!transport_controller_->GetStats((*channel_name_pair)->transport_name, |
| 1922 | &transport_stats)) { |
| 1923 | return nullptr; |
| 1924 | } |
| 1925 | session_stats->proxy_to_transport[(*channel_name_pair)->content_name] = |
| 1926 | (*channel_name_pair)->transport_name; |
| 1927 | session_stats->transport_stats[(*channel_name_pair)->transport_name] = |
| 1928 | std::move(transport_stats); |
| 1929 | } |
| 1930 | } |
| 1931 | return session_stats; |
| 1932 | } |
| 1933 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1934 | bool WebRtcSession::CreateSctpTransport_n(const std::string& content_name, |
| 1935 | const std::string& transport_name) { |
| 1936 | RTC_DCHECK(network_thread_->IsCurrent()); |
| 1937 | RTC_DCHECK(sctp_factory_); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1938 | cricket::DtlsTransportInternal* tc = |
| 1939 | transport_controller_->CreateDtlsTransport_n( |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1940 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
| 1941 | sctp_transport_ = sctp_factory_->CreateSctpTransport(tc); |
| 1942 | RTC_DCHECK(sctp_transport_); |
| 1943 | sctp_invoker_.reset(new rtc::AsyncInvoker()); |
| 1944 | sctp_transport_->SignalReadyToSendData.connect( |
| 1945 | this, &WebRtcSession::OnSctpTransportReadyToSendData_n); |
| 1946 | sctp_transport_->SignalDataReceived.connect( |
| 1947 | this, &WebRtcSession::OnSctpTransportDataReceived_n); |
| 1948 | sctp_transport_->SignalStreamClosedRemotely.connect( |
| 1949 | this, &WebRtcSession::OnSctpStreamClosedRemotely_n); |
| 1950 | sctp_transport_name_ = rtc::Optional<std::string>(transport_name); |
| 1951 | sctp_content_name_ = rtc::Optional<std::string>(content_name); |
| 1952 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1953 | } |
| 1954 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1955 | void WebRtcSession::ChangeSctpTransport_n(const std::string& transport_name) { |
| 1956 | RTC_DCHECK(network_thread_->IsCurrent()); |
| 1957 | RTC_DCHECK(sctp_transport_); |
| 1958 | RTC_DCHECK(sctp_transport_name_); |
| 1959 | std::string old_sctp_transport_name = *sctp_transport_name_; |
| 1960 | sctp_transport_name_ = rtc::Optional<std::string>(transport_name); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1961 | cricket::DtlsTransportInternal* tc = |
| 1962 | transport_controller_->CreateDtlsTransport_n( |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1963 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
| 1964 | sctp_transport_->SetTransportChannel(tc); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 1965 | transport_controller_->DestroyDtlsTransport_n( |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1966 | old_sctp_transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
| 1967 | } |
| 1968 | |
| 1969 | void WebRtcSession::DestroySctpTransport_n() { |
| 1970 | RTC_DCHECK(network_thread_->IsCurrent()); |
| 1971 | sctp_transport_.reset(nullptr); |
| 1972 | sctp_content_name_.reset(); |
| 1973 | sctp_transport_name_.reset(); |
| 1974 | sctp_invoker_.reset(nullptr); |
| 1975 | sctp_ready_to_send_data_ = false; |
| 1976 | } |
| 1977 | |
| 1978 | void WebRtcSession::OnSctpTransportReadyToSendData_n() { |
| 1979 | RTC_DCHECK(data_channel_type_ == cricket::DCT_SCTP); |
| 1980 | RTC_DCHECK(network_thread_->IsCurrent()); |
| 1981 | sctp_invoker_->AsyncInvoke<void>( |
| 1982 | RTC_FROM_HERE, signaling_thread_, |
| 1983 | rtc::Bind(&WebRtcSession::OnSctpTransportReadyToSendData_s, this, true)); |
| 1984 | } |
| 1985 | |
| 1986 | void WebRtcSession::OnSctpTransportReadyToSendData_s(bool ready) { |
| 1987 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 1988 | sctp_ready_to_send_data_ = ready; |
| 1989 | SignalSctpReadyToSendData(ready); |
| 1990 | } |
| 1991 | |
| 1992 | void WebRtcSession::OnSctpTransportDataReceived_n( |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 1993 | const cricket::ReceiveDataParams& params, |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 1994 | const rtc::CopyOnWriteBuffer& payload) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1995 | RTC_DCHECK(data_channel_type_ == cricket::DCT_SCTP); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1996 | RTC_DCHECK(network_thread_->IsCurrent()); |
| 1997 | sctp_invoker_->AsyncInvoke<void>( |
| 1998 | RTC_FROM_HERE, signaling_thread_, |
| 1999 | rtc::Bind(&WebRtcSession::OnSctpTransportDataReceived_s, this, params, |
| 2000 | payload)); |
| 2001 | } |
| 2002 | |
| 2003 | void WebRtcSession::OnSctpTransportDataReceived_s( |
| 2004 | const cricket::ReceiveDataParams& params, |
| 2005 | const rtc::CopyOnWriteBuffer& payload) { |
| 2006 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2007 | if (params.type == cricket::DMT_CONTROL && IsOpenMessage(payload)) { |
| 2008 | // Received OPEN message; parse and signal that a new data channel should |
| 2009 | // be created. |
| 2010 | std::string label; |
| 2011 | InternalDataChannelInit config; |
| 2012 | config.id = params.ssrc; |
| 2013 | if (!ParseDataChannelOpenMessage(payload, &label, &config)) { |
| 2014 | LOG(LS_WARNING) << "Failed to parse the OPEN message for sid " |
| 2015 | << params.ssrc; |
| 2016 | return; |
| 2017 | } |
| 2018 | config.open_handshake_role = InternalDataChannelInit::kAcker; |
| 2019 | SignalDataChannelOpenMessage(label, config); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2020 | } else { |
| 2021 | // Otherwise just forward the signal. |
| 2022 | SignalSctpDataReceived(params, payload); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2023 | } |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | void WebRtcSession::OnSctpStreamClosedRemotely_n(int sid) { |
| 2027 | RTC_DCHECK(data_channel_type_ == cricket::DCT_SCTP); |
| 2028 | RTC_DCHECK(network_thread_->IsCurrent()); |
| 2029 | sctp_invoker_->AsyncInvoke<void>( |
| 2030 | RTC_FROM_HERE, signaling_thread_, |
| 2031 | rtc::Bind(&sigslot::signal1<int>::operator(), |
| 2032 | &SignalSctpStreamClosedRemotely, sid)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2033 | } |
| 2034 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2035 | // Returns false if bundle is enabled and rtcp_mux is disabled. |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2036 | bool WebRtcSession::ValidateBundleSettings(const SessionDescription* desc) { |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2037 | bool bundle_enabled = desc->HasGroup(cricket::GROUP_TYPE_BUNDLE); |
| 2038 | if (!bundle_enabled) |
| 2039 | return true; |
| 2040 | |
| 2041 | const cricket::ContentGroup* bundle_group = |
| 2042 | desc->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 2043 | RTC_DCHECK(bundle_group != NULL); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2044 | |
| 2045 | const cricket::ContentInfos& contents = desc->contents(); |
| 2046 | for (cricket::ContentInfos::const_iterator citer = contents.begin(); |
| 2047 | citer != contents.end(); ++citer) { |
| 2048 | const cricket::ContentInfo* content = (&*citer); |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 2049 | RTC_DCHECK(content != NULL); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2050 | if (bundle_group->HasContentName(content->name) && |
| 2051 | !content->rejected && content->type == cricket::NS_JINGLE_RTP) { |
| 2052 | if (!HasRtcpMuxEnabled(content)) |
| 2053 | return false; |
| 2054 | } |
| 2055 | } |
| 2056 | // RTCP-MUX is enabled in all the contents. |
| 2057 | return true; |
| 2058 | } |
| 2059 | |
| 2060 | bool WebRtcSession::HasRtcpMuxEnabled( |
| 2061 | const cricket::ContentInfo* content) { |
| 2062 | const cricket::MediaContentDescription* description = |
| 2063 | static_cast<cricket::MediaContentDescription*>(content->description); |
| 2064 | return description->rtcp_mux(); |
| 2065 | } |
| 2066 | |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2067 | bool WebRtcSession::ValidateSessionDescription( |
| 2068 | const SessionDescriptionInterface* sdesc, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2069 | cricket::ContentSource source, std::string* err_desc) { |
| 2070 | std::string type; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2071 | if (error() != ERROR_NONE) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2072 | return BadSdp(source, type, GetSessionErrorMsg(), err_desc); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | if (!sdesc || !sdesc->description()) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2076 | return BadSdp(source, type, kInvalidSdp, err_desc); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2077 | } |
| 2078 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2079 | type = sdesc->type(); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2080 | Action action = GetAction(sdesc->type()); |
| 2081 | if (source == cricket::CS_LOCAL) { |
| 2082 | if (!ExpectSetLocalDescription(action)) |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2083 | return BadLocalSdp(type, BadStateErrMsg(state()), err_desc); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2084 | } else { |
| 2085 | if (!ExpectSetRemoteDescription(action)) |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2086 | return BadRemoteSdp(type, BadStateErrMsg(state()), err_desc); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | // Verify crypto settings. |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 2090 | std::string crypto_error; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 2091 | if ((webrtc_session_desc_factory_->SdesPolicy() == cricket::SEC_REQUIRED || |
| 2092 | dtls_enabled_) && |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 2093 | !VerifyCrypto(sdesc->description(), dtls_enabled_, &crypto_error)) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2094 | return BadSdp(source, type, crypto_error, err_desc); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2095 | } |
| 2096 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2097 | // Verify ice-ufrag and ice-pwd. |
| 2098 | if (!VerifyIceUfragPwdPresent(sdesc->description())) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2099 | return BadSdp(source, type, kSdpWithoutIceUfragPwd, err_desc); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2100 | } |
| 2101 | |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2102 | if (!ValidateBundleSettings(sdesc->description())) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2103 | return BadSdp(source, type, kBundleWithoutRtcpMux, err_desc); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2104 | } |
| 2105 | |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 2106 | // TODO(skvlad): When the local rtcp-mux policy is Require, reject any |
| 2107 | // m-lines that do not rtcp-mux enabled. |
| 2108 | |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2109 | // Verify m-lines in Answer when compared against Offer. |
| 2110 | if (action == kAnswer) { |
| 2111 | const cricket::SessionDescription* offer_desc = |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 2112 | (source == cricket::CS_LOCAL) ? remote_description()->description() |
| 2113 | : local_description()->description(); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2114 | if (!VerifyMediaDescriptions(sdesc->description(), offer_desc)) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2115 | return BadAnswerSdp(source, kMlineMismatch, err_desc); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2116 | } |
| 2117 | } |
| 2118 | |
| 2119 | return true; |
| 2120 | } |
| 2121 | |
| 2122 | bool WebRtcSession::ExpectSetLocalDescription(Action action) { |
| 2123 | return ((action == kOffer && state() == STATE_INIT) || |
| 2124 | // update local offer |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2125 | (action == kOffer && state() == STATE_SENTOFFER) || |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2126 | // update the current ongoing session. |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2127 | (action == kOffer && state() == STATE_INPROGRESS) || |
| 2128 | // accept remote offer |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2129 | (action == kAnswer && state() == STATE_RECEIVEDOFFER) || |
| 2130 | (action == kAnswer && state() == STATE_SENTPRANSWER) || |
| 2131 | (action == kPrAnswer && state() == STATE_RECEIVEDOFFER) || |
| 2132 | (action == kPrAnswer && state() == STATE_SENTPRANSWER)); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | bool WebRtcSession::ExpectSetRemoteDescription(Action action) { |
| 2136 | return ((action == kOffer && state() == STATE_INIT) || |
| 2137 | // update remote offer |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2138 | (action == kOffer && state() == STATE_RECEIVEDOFFER) || |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2139 | // update the current ongoing session |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2140 | (action == kOffer && state() == STATE_INPROGRESS) || |
| 2141 | // accept local offer |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2142 | (action == kAnswer && state() == STATE_SENTOFFER) || |
| 2143 | (action == kAnswer && state() == STATE_RECEIVEDPRANSWER) || |
| 2144 | (action == kPrAnswer && state() == STATE_SENTOFFER) || |
| 2145 | (action == kPrAnswer && state() == STATE_RECEIVEDPRANSWER)); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2146 | } |
| 2147 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2148 | std::string WebRtcSession::GetSessionErrorMsg() { |
| 2149 | std::ostringstream desc; |
| 2150 | desc << kSessionError << GetErrorCodeString(error()) << ". "; |
| 2151 | desc << kSessionErrorDesc << error_desc() << "."; |
| 2152 | return desc.str(); |
| 2153 | } |
| 2154 | |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2155 | // We need to check the local/remote description for the Transport instead of |
| 2156 | // the session, because a new Transport added during renegotiation may have |
| 2157 | // them unset while the session has them set from the previous negotiation. |
| 2158 | // Not doing so may trigger the auto generation of transport description and |
| 2159 | // mess up DTLS identity information, ICE credential, etc. |
| 2160 | bool WebRtcSession::ReadyToUseRemoteCandidate( |
| 2161 | const IceCandidateInterface* candidate, |
| 2162 | const SessionDescriptionInterface* remote_desc, |
| 2163 | bool* valid) { |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2164 | *valid = true; |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2165 | |
| 2166 | const SessionDescriptionInterface* current_remote_desc = |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 2167 | remote_desc ? remote_desc : remote_description(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2168 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2169 | if (!current_remote_desc) { |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2170 | return false; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2171 | } |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2172 | |
| 2173 | size_t mediacontent_index = |
| 2174 | static_cast<size_t>(candidate->sdp_mline_index()); |
| 2175 | size_t remote_content_size = |
| 2176 | current_remote_desc->description()->contents().size(); |
| 2177 | if (mediacontent_index >= remote_content_size) { |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 2178 | LOG(LS_ERROR) << "ReadyToUseRemoteCandidate: Invalid candidate media index " |
| 2179 | << mediacontent_index; |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2180 | |
| 2181 | *valid = false; |
| 2182 | return false; |
| 2183 | } |
| 2184 | |
| 2185 | cricket::ContentInfo content = |
| 2186 | current_remote_desc->description()->contents()[mediacontent_index]; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2187 | |
| 2188 | const std::string transport_name = GetTransportName(content.name); |
| 2189 | if (transport_name.empty()) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2190 | return false; |
| 2191 | } |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2192 | return transport_controller_->ReadyForRemoteCandidates(transport_name); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2193 | } |
| 2194 | |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 2195 | bool WebRtcSession::SrtpRequired() const { |
| 2196 | return dtls_enabled_ || |
| 2197 | webrtc_session_desc_factory_->SdesPolicy() == cricket::SEC_REQUIRED; |
| 2198 | } |
| 2199 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2200 | void WebRtcSession::OnTransportControllerGatheringState( |
| 2201 | cricket::IceGatheringState state) { |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 2202 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2203 | if (state == cricket::kIceGatheringGathering) { |
| 2204 | if (ice_observer_) { |
| 2205 | ice_observer_->OnIceGatheringChange( |
| 2206 | PeerConnectionInterface::kIceGatheringGathering); |
| 2207 | } |
| 2208 | } else if (state == cricket::kIceGatheringComplete) { |
| 2209 | if (ice_observer_) { |
| 2210 | ice_observer_->OnIceGatheringChange( |
| 2211 | PeerConnectionInterface::kIceGatheringComplete); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2212 | } |
| 2213 | } |
| 2214 | } |
| 2215 | |
| 2216 | void WebRtcSession::ReportTransportStats() { |
| 2217 | // Use a set so we don't report the same stats twice if two channels share |
| 2218 | // a transport. |
| 2219 | std::set<std::string> transport_names; |
| 2220 | if (voice_channel()) { |
| 2221 | transport_names.insert(voice_channel()->transport_name()); |
| 2222 | } |
| 2223 | if (video_channel()) { |
| 2224 | transport_names.insert(video_channel()->transport_name()); |
| 2225 | } |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2226 | if (rtp_data_channel()) { |
| 2227 | transport_names.insert(rtp_data_channel()->transport_name()); |
| 2228 | } |
| 2229 | if (sctp_transport_name_) { |
| 2230 | transport_names.insert(*sctp_transport_name_); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2231 | } |
| 2232 | for (const auto& name : transport_names) { |
| 2233 | cricket::TransportStats stats; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2234 | if (transport_controller_->GetStats(name, &stats)) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2235 | ReportBestConnectionState(stats); |
| 2236 | ReportNegotiatedCiphers(stats); |
| 2237 | } |
| 2238 | } |
| 2239 | } |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 2240 | // Walk through the ConnectionInfos to gather best connection usage |
| 2241 | // for IPv4 and IPv6. |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 2242 | void WebRtcSession::ReportBestConnectionState( |
| 2243 | const cricket::TransportStats& stats) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 2244 | RTC_DCHECK(metrics_observer_ != NULL); |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 2245 | for (cricket::TransportChannelStatsList::const_iterator it = |
| 2246 | stats.channel_stats.begin(); |
| 2247 | it != stats.channel_stats.end(); ++it) { |
| 2248 | for (cricket::ConnectionInfos::const_iterator it_info = |
| 2249 | it->connection_infos.begin(); |
| 2250 | it_info != it->connection_infos.end(); ++it_info) { |
| 2251 | if (!it_info->best_connection) { |
| 2252 | continue; |
| 2253 | } |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 2254 | |
| 2255 | PeerConnectionEnumCounterType type = kPeerConnectionEnumCounterMax; |
| 2256 | const cricket::Candidate& local = it_info->local_candidate; |
| 2257 | const cricket::Candidate& remote = it_info->remote_candidate; |
| 2258 | |
| 2259 | // Increment the counter for IceCandidatePairType. |
| 2260 | if (local.protocol() == cricket::TCP_PROTOCOL_NAME || |
| 2261 | (local.type() == RELAY_PORT_TYPE && |
| 2262 | local.relay_protocol() == cricket::TCP_PROTOCOL_NAME)) { |
| 2263 | type = kEnumCounterIceCandidatePairTypeTcp; |
| 2264 | } else if (local.protocol() == cricket::UDP_PROTOCOL_NAME) { |
| 2265 | type = kEnumCounterIceCandidatePairTypeUdp; |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 2266 | } else { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 2267 | RTC_CHECK(0); |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 2268 | } |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 2269 | metrics_observer_->IncrementEnumCounter( |
| 2270 | type, GetIceCandidatePairCounter(local, remote), |
| 2271 | kIceCandidatePairMax); |
| 2272 | |
| 2273 | // Increment the counter for IP type. |
| 2274 | if (local.address().family() == AF_INET) { |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 2275 | metrics_observer_->IncrementEnumCounter( |
| 2276 | kEnumCounterAddressFamily, kBestConnections_IPv4, |
| 2277 | kPeerConnectionAddressFamilyCounter_Max); |
| 2278 | |
| 2279 | } else if (local.address().family() == AF_INET6) { |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 2280 | metrics_observer_->IncrementEnumCounter( |
| 2281 | kEnumCounterAddressFamily, kBestConnections_IPv6, |
| 2282 | kPeerConnectionAddressFamilyCounter_Max); |
| 2283 | } else { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 2284 | RTC_CHECK(0); |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 2287 | return; |
| 2288 | } |
| 2289 | } |
| 2290 | } |
| 2291 | |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 2292 | void WebRtcSession::ReportNegotiatedCiphers( |
| 2293 | const cricket::TransportStats& stats) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 2294 | RTC_DCHECK(metrics_observer_ != NULL); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 2295 | if (!dtls_enabled_ || stats.channel_stats.empty()) { |
| 2296 | return; |
| 2297 | } |
| 2298 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 2299 | int srtp_crypto_suite = stats.channel_stats[0].srtp_crypto_suite; |
| 2300 | int ssl_cipher_suite = stats.channel_stats[0].ssl_cipher_suite; |
| 2301 | if (srtp_crypto_suite == rtc::SRTP_INVALID_CRYPTO_SUITE && |
| 2302 | ssl_cipher_suite == rtc::TLS_NULL_WITH_NULL_NULL) { |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 2303 | return; |
| 2304 | } |
| 2305 | |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 2306 | PeerConnectionEnumCounterType srtp_counter_type; |
| 2307 | PeerConnectionEnumCounterType ssl_counter_type; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2308 | if (stats.transport_name == cricket::CN_AUDIO) { |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 2309 | srtp_counter_type = kEnumCounterAudioSrtpCipher; |
| 2310 | ssl_counter_type = kEnumCounterAudioSslCipher; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2311 | } else if (stats.transport_name == cricket::CN_VIDEO) { |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 2312 | srtp_counter_type = kEnumCounterVideoSrtpCipher; |
| 2313 | ssl_counter_type = kEnumCounterVideoSslCipher; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2314 | } else if (stats.transport_name == cricket::CN_DATA) { |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 2315 | srtp_counter_type = kEnumCounterDataSrtpCipher; |
| 2316 | ssl_counter_type = kEnumCounterDataSslCipher; |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 2317 | } else { |
| 2318 | RTC_NOTREACHED(); |
| 2319 | return; |
| 2320 | } |
| 2321 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 2322 | if (srtp_crypto_suite != rtc::SRTP_INVALID_CRYPTO_SUITE) { |
| 2323 | metrics_observer_->IncrementSparseEnumCounter(srtp_counter_type, |
| 2324 | srtp_crypto_suite); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 2325 | } |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 2326 | if (ssl_cipher_suite != rtc::TLS_NULL_WITH_NULL_NULL) { |
| 2327 | metrics_observer_->IncrementSparseEnumCounter(ssl_counter_type, |
| 2328 | ssl_cipher_suite); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 2329 | } |
| 2330 | } |
| 2331 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 2332 | void WebRtcSession::OnSentPacket_w(const rtc::SentPacket& sent_packet) { |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 2333 | RTC_DCHECK(worker_thread()->IsCurrent()); |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 2334 | RTC_DCHECK(call_); |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 2335 | call_->OnSentPacket(sent_packet); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 2336 | } |
| 2337 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2338 | const std::string WebRtcSession::GetTransportName( |
| 2339 | const std::string& content_name) { |
| 2340 | cricket::BaseChannel* channel = GetChannel(content_name); |
| 2341 | if (!channel) { |
| 2342 | #ifdef HAVE_QUIC |
| 2343 | if (data_channel_type_ == cricket::DCT_QUIC && quic_data_transport_ && |
| 2344 | content_name == quic_data_transport_->transport_name()) { |
| 2345 | return quic_data_transport_->transport_name(); |
| 2346 | } |
| 2347 | #endif |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2348 | if (sctp_transport_) { |
| 2349 | RTC_DCHECK(sctp_content_name_); |
| 2350 | RTC_DCHECK(sctp_transport_name_); |
| 2351 | if (content_name == *sctp_content_name_) { |
| 2352 | return *sctp_transport_name_; |
| 2353 | } |
| 2354 | } |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2355 | // Return an empty string if failed to retrieve the transport name. |
| 2356 | return ""; |
| 2357 | } |
| 2358 | return channel->transport_name(); |
| 2359 | } |
zhihuang | d82eee0 | 2016-08-26 11:25:05 -0700 | [diff] [blame] | 2360 | |
deadbeef | ac22f70 | 2017-01-12 21:59:29 -0800 | [diff] [blame] | 2361 | void WebRtcSession::DestroyRtcpTransport_n(const std::string& transport_name) { |
nisse | a9dd4a1 | 2017-01-13 07:08:34 -0800 | [diff] [blame] | 2362 | RTC_DCHECK(network_thread()->IsCurrent()); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 2363 | transport_controller_->DestroyDtlsTransport_n( |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 2364 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
| 2365 | } |
| 2366 | |
| 2367 | void WebRtcSession::DestroyVideoChannel() { |
| 2368 | SignalVideoChannelDestroyed(); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 2369 | RTC_DCHECK(video_channel_->rtp_dtls_transport()); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 2370 | std::string transport_name; |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 2371 | transport_name = video_channel_->rtp_dtls_transport()->transport_name(); |
| 2372 | bool need_to_delete_rtcp = (video_channel_->rtcp_dtls_transport() != nullptr); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 2373 | channel_manager_->DestroyVideoChannel(video_channel_.release()); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 2374 | transport_controller_->DestroyDtlsTransport( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 2375 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 2376 | if (need_to_delete_rtcp) { |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 2377 | transport_controller_->DestroyDtlsTransport( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 2378 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 2379 | } |
| 2380 | } |
| 2381 | |
| 2382 | void WebRtcSession::DestroyVoiceChannel() { |
| 2383 | SignalVoiceChannelDestroyed(); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 2384 | RTC_DCHECK(voice_channel_->rtp_dtls_transport()); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 2385 | std::string transport_name; |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 2386 | transport_name = voice_channel_->rtp_dtls_transport()->transport_name(); |
| 2387 | bool need_to_delete_rtcp = (voice_channel_->rtcp_dtls_transport() != nullptr); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 2388 | channel_manager_->DestroyVoiceChannel(voice_channel_.release()); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 2389 | transport_controller_->DestroyDtlsTransport( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 2390 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 2391 | if (need_to_delete_rtcp) { |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 2392 | transport_controller_->DestroyDtlsTransport( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 2393 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 2394 | } |
| 2395 | } |
| 2396 | |
| 2397 | void WebRtcSession::DestroyDataChannel() { |
| 2398 | SignalDataChannelDestroyed(); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 2399 | RTC_DCHECK(rtp_data_channel_->rtp_dtls_transport()); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 2400 | std::string transport_name; |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 2401 | transport_name = rtp_data_channel_->rtp_dtls_transport()->transport_name(); |
| 2402 | bool need_to_delete_rtcp = |
| 2403 | (rtp_data_channel_->rtcp_dtls_transport() != nullptr); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 2404 | channel_manager_->DestroyRtpDataChannel(rtp_data_channel_.release()); |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 2405 | transport_controller_->DestroyDtlsTransport( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 2406 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 2407 | if (need_to_delete_rtcp) { |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 2408 | transport_controller_->DestroyDtlsTransport( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 2409 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 2410 | } |
| 2411 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2412 | } // namespace webrtc |