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