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