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