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