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