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