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