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