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