henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 11 | #include "webrtc/api/peerconnection.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 13 | #include <algorithm> |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 14 | #include <cctype> // for isdigit |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 15 | #include <utility> |
| 16 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 17 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 18 | #include "webrtc/api/audiotrack.h" |
| 19 | #include "webrtc/api/dtmfsender.h" |
| 20 | #include "webrtc/api/jsepicecandidate.h" |
| 21 | #include "webrtc/api/jsepsessiondescription.h" |
| 22 | #include "webrtc/api/mediaconstraintsinterface.h" |
| 23 | #include "webrtc/api/mediastream.h" |
| 24 | #include "webrtc/api/mediastreamobserver.h" |
| 25 | #include "webrtc/api/mediastreamproxy.h" |
| 26 | #include "webrtc/api/mediastreamtrackproxy.h" |
| 27 | #include "webrtc/api/remoteaudiosource.h" |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 28 | #include "webrtc/api/rtpreceiver.h" |
| 29 | #include "webrtc/api/rtpsender.h" |
| 30 | #include "webrtc/api/streamcollection.h" |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 31 | #include "webrtc/api/videocapturertracksource.h" |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 32 | #include "webrtc/api/videotrack.h" |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 33 | #include "webrtc/base/arraysize.h" |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 34 | #include "webrtc/base/bind.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 35 | #include "webrtc/base/logging.h" |
| 36 | #include "webrtc/base/stringencode.h" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 37 | #include "webrtc/base/stringutils.h" |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 38 | #include "webrtc/base/trace_event.h" |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 39 | #include "webrtc/call/call.h" |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 40 | #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 41 | #include "webrtc/media/sctp/sctpdataengine.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 42 | #include "webrtc/pc/channelmanager.h" |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 43 | #include "webrtc/system_wrappers/include/clock.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 44 | #include "webrtc/system_wrappers/include/field_trial.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | |
| 46 | namespace { |
| 47 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 48 | using webrtc::DataChannel; |
| 49 | using webrtc::MediaConstraintsInterface; |
| 50 | using webrtc::MediaStreamInterface; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 51 | using webrtc::PeerConnectionInterface; |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 52 | using webrtc::RtpSenderInternal; |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 53 | using webrtc::RtpSenderInterface; |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 54 | using webrtc::RtpSenderProxy; |
| 55 | using webrtc::RtpSenderProxyWithInternal; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 56 | using webrtc::StreamCollection; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 57 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 58 | static const char kDefaultStreamLabel[] = "default"; |
| 59 | static const char kDefaultAudioTrackLabel[] = "defaulta0"; |
| 60 | static const char kDefaultVideoTrackLabel[] = "defaultv0"; |
| 61 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 62 | // The min number of tokens must present in Turn host uri. |
| 63 | // e.g. user@turn.example.org |
| 64 | static const size_t kTurnHostTokensNum = 2; |
| 65 | // Number of tokens must be preset when TURN uri has transport param. |
| 66 | static const size_t kTurnTransportTokensNum = 2; |
| 67 | // The default stun port. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 68 | static const int kDefaultStunPort = 3478; |
| 69 | static const int kDefaultStunTlsPort = 5349; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 70 | static const char kTransport[] = "transport"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 71 | |
| 72 | // NOTE: Must be in the same order as the ServiceType enum. |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 73 | static const char* kValidIceServiceTypes[] = {"stun", "stuns", "turn", "turns"}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 75 | // The length of RTCP CNAMEs. |
| 76 | static const int kRtcpCnameLength = 16; |
| 77 | |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 78 | // NOTE: A loop below assumes that the first value of this enum is 0 and all |
| 79 | // other values are incremental. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | enum ServiceType { |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 81 | STUN = 0, // Indicates a STUN server. |
| 82 | STUNS, // Indicates a STUN server used with a TLS session. |
| 83 | TURN, // Indicates a TURN server |
| 84 | TURNS, // Indicates a TURN server used with a TLS session. |
| 85 | INVALID, // Unknown. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 86 | }; |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 87 | static_assert(INVALID == arraysize(kValidIceServiceTypes), |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 88 | "kValidIceServiceTypes must have as many strings as ServiceType " |
| 89 | "has values."); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 90 | |
| 91 | enum { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 92 | MSG_SET_SESSIONDESCRIPTION_SUCCESS = 0, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 93 | MSG_SET_SESSIONDESCRIPTION_FAILED, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 94 | MSG_CREATE_SESSIONDESCRIPTION_FAILED, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 95 | MSG_GETSTATS, |
deadbeef | bd29246 | 2015-12-14 18:15:29 -0800 | [diff] [blame] | 96 | MSG_FREE_DATACHANNELS, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 99 | struct SetSessionDescriptionMsg : public rtc::MessageData { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 100 | explicit SetSessionDescriptionMsg( |
| 101 | webrtc::SetSessionDescriptionObserver* observer) |
| 102 | : observer(observer) { |
| 103 | } |
| 104 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 105 | rtc::scoped_refptr<webrtc::SetSessionDescriptionObserver> observer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 106 | std::string error; |
| 107 | }; |
| 108 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 109 | struct CreateSessionDescriptionMsg : public rtc::MessageData { |
| 110 | explicit CreateSessionDescriptionMsg( |
| 111 | webrtc::CreateSessionDescriptionObserver* observer) |
| 112 | : observer(observer) {} |
| 113 | |
| 114 | rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserver> observer; |
| 115 | std::string error; |
| 116 | }; |
| 117 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 118 | struct GetStatsMsg : public rtc::MessageData { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 119 | GetStatsMsg(webrtc::StatsObserver* observer, |
| 120 | webrtc::MediaStreamTrackInterface* track) |
| 121 | : observer(observer), track(track) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 122 | } |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 123 | rtc::scoped_refptr<webrtc::StatsObserver> observer; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 124 | rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> track; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 125 | }; |
| 126 | |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 127 | // |in_str| should be of format |
| 128 | // stunURI = scheme ":" stun-host [ ":" stun-port ] |
| 129 | // scheme = "stun" / "stuns" |
| 130 | // stun-host = IP-literal / IPv4address / reg-name |
| 131 | // stun-port = *DIGIT |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 132 | // |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 133 | // draft-petithuguenin-behave-turn-uris-01 |
| 134 | // turnURI = scheme ":" turn-host [ ":" turn-port ] |
| 135 | // turn-host = username@IP-literal / IPv4address / reg-name |
| 136 | bool GetServiceTypeAndHostnameFromUri(const std::string& in_str, |
| 137 | ServiceType* service_type, |
| 138 | std::string* hostname) { |
Tommi | 77d444a | 2015-04-24 15:38:38 +0200 | [diff] [blame] | 139 | const std::string::size_type colonpos = in_str.find(':'); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 140 | if (colonpos == std::string::npos) { |
| 141 | LOG(LS_WARNING) << "Missing ':' in ICE URI: " << in_str; |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 142 | return false; |
| 143 | } |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 144 | if ((colonpos + 1) == in_str.length()) { |
| 145 | LOG(LS_WARNING) << "Empty hostname in ICE URI: " << in_str; |
| 146 | return false; |
| 147 | } |
| 148 | *service_type = INVALID; |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 149 | for (size_t i = 0; i < arraysize(kValidIceServiceTypes); ++i) { |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 150 | if (in_str.compare(0, colonpos, kValidIceServiceTypes[i]) == 0) { |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 151 | *service_type = static_cast<ServiceType>(i); |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | if (*service_type == INVALID) { |
| 156 | return false; |
| 157 | } |
| 158 | *hostname = in_str.substr(colonpos + 1, std::string::npos); |
| 159 | return true; |
| 160 | } |
| 161 | |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 162 | bool ParsePort(const std::string& in_str, int* port) { |
| 163 | // Make sure port only contains digits. FromString doesn't check this. |
| 164 | for (const char& c : in_str) { |
| 165 | if (!std::isdigit(c)) { |
| 166 | return false; |
| 167 | } |
| 168 | } |
| 169 | return rtc::FromString(in_str, port); |
| 170 | } |
| 171 | |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 172 | // This method parses IPv6 and IPv4 literal strings, along with hostnames in |
| 173 | // standard hostname:port format. |
| 174 | // Consider following formats as correct. |
| 175 | // |hostname:port|, |[IPV6 address]:port|, |IPv4 address|:port, |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 176 | // |hostname|, |[IPv6 address]|, |IPv4 address|. |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 177 | bool ParseHostnameAndPortFromString(const std::string& in_str, |
| 178 | std::string* host, |
| 179 | int* port) { |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 180 | RTC_DCHECK(host->empty()); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 181 | if (in_str.at(0) == '[') { |
| 182 | std::string::size_type closebracket = in_str.rfind(']'); |
| 183 | if (closebracket != std::string::npos) { |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 184 | std::string::size_type colonpos = in_str.find(':', closebracket); |
| 185 | if (std::string::npos != colonpos) { |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 186 | if (!ParsePort(in_str.substr(closebracket + 2, std::string::npos), |
| 187 | port)) { |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 188 | return false; |
| 189 | } |
| 190 | } |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 191 | *host = in_str.substr(1, closebracket - 1); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 192 | } else { |
| 193 | return false; |
| 194 | } |
| 195 | } else { |
| 196 | std::string::size_type colonpos = in_str.find(':'); |
| 197 | if (std::string::npos != colonpos) { |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 198 | if (!ParsePort(in_str.substr(colonpos + 1, std::string::npos), port)) { |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 199 | return false; |
| 200 | } |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 201 | *host = in_str.substr(0, colonpos); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 202 | } else { |
| 203 | *host = in_str; |
| 204 | } |
| 205 | } |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 206 | return !host->empty(); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 209 | // Adds a STUN or TURN server to the appropriate list, |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 210 | // by parsing |url| and using the username/password in |server|. |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 211 | bool ParseIceServerUrl(const PeerConnectionInterface::IceServer& server, |
| 212 | const std::string& url, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 213 | cricket::ServerAddresses* stun_servers, |
| 214 | std::vector<cricket::RelayServerConfig>* turn_servers) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 215 | // draft-nandakumar-rtcweb-stun-uri-01 |
| 216 | // stunURI = scheme ":" stun-host [ ":" stun-port ] |
| 217 | // scheme = "stun" / "stuns" |
| 218 | // stun-host = IP-literal / IPv4address / reg-name |
| 219 | // stun-port = *DIGIT |
| 220 | |
| 221 | // draft-petithuguenin-behave-turn-uris-01 |
| 222 | // turnURI = scheme ":" turn-host [ ":" turn-port ] |
| 223 | // [ "?transport=" transport ] |
| 224 | // scheme = "turn" / "turns" |
| 225 | // transport = "udp" / "tcp" / transport-ext |
| 226 | // transport-ext = 1*unreserved |
| 227 | // turn-host = IP-literal / IPv4address / reg-name |
| 228 | // turn-port = *DIGIT |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 229 | RTC_DCHECK(stun_servers != nullptr); |
| 230 | RTC_DCHECK(turn_servers != nullptr); |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 231 | std::vector<std::string> tokens; |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 232 | cricket::ProtocolType turn_transport_type = cricket::PROTO_UDP; |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 233 | RTC_DCHECK(!url.empty()); |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 234 | rtc::tokenize(url, '?', &tokens); |
| 235 | std::string uri_without_transport = tokens[0]; |
| 236 | // Let's look into transport= param, if it exists. |
| 237 | if (tokens.size() == kTurnTransportTokensNum) { // ?transport= is present. |
| 238 | std::string uri_transport_param = tokens[1]; |
| 239 | rtc::tokenize(uri_transport_param, '=', &tokens); |
| 240 | if (tokens[0] == kTransport) { |
| 241 | // As per above grammar transport param will be consist of lower case |
| 242 | // letters. |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 243 | if (!cricket::StringToProto(tokens[1].c_str(), &turn_transport_type) || |
| 244 | (turn_transport_type != cricket::PROTO_UDP && |
| 245 | turn_transport_type != cricket::PROTO_TCP)) { |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 246 | LOG(LS_WARNING) << "Transport param should always be udp or tcp."; |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 247 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 248 | } |
| 249 | } |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 250 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 251 | |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 252 | std::string hoststring; |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 253 | ServiceType service_type; |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 254 | if (!GetServiceTypeAndHostnameFromUri(uri_without_transport, |
| 255 | &service_type, |
| 256 | &hoststring)) { |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 257 | LOG(LS_WARNING) << "Invalid transport parameter in ICE URI: " << url; |
| 258 | return false; |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 259 | } |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 260 | |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 261 | // GetServiceTypeAndHostnameFromUri should never give an empty hoststring |
| 262 | RTC_DCHECK(!hoststring.empty()); |
Tommi | 77d444a | 2015-04-24 15:38:38 +0200 | [diff] [blame] | 263 | |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 264 | // Let's break hostname. |
| 265 | tokens.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 266 | rtc::tokenize_with_empty_tokens(hoststring, '@', &tokens); |
| 267 | |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 268 | std::string username(server.username); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 269 | if (tokens.size() > kTurnHostTokensNum) { |
| 270 | LOG(LS_WARNING) << "Invalid user@hostname format: " << hoststring; |
| 271 | return false; |
| 272 | } |
| 273 | if (tokens.size() == kTurnHostTokensNum) { |
| 274 | if (tokens[0].empty() || tokens[1].empty()) { |
| 275 | LOG(LS_WARNING) << "Invalid user@hostname format: " << hoststring; |
| 276 | return false; |
| 277 | } |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 278 | username.assign(rtc::s_url_decode(tokens[0])); |
| 279 | hoststring = tokens[1]; |
| 280 | } else { |
| 281 | hoststring = tokens[0]; |
| 282 | } |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 283 | |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 284 | int port = kDefaultStunPort; |
| 285 | if (service_type == TURNS) { |
| 286 | port = kDefaultStunTlsPort; |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 287 | turn_transport_type = cricket::PROTO_TCP; |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 288 | } |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 289 | |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 290 | std::string address; |
| 291 | if (!ParseHostnameAndPortFromString(hoststring, &address, &port)) { |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 292 | LOG(WARNING) << "Invalid hostname format: " << uri_without_transport; |
| 293 | return false; |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 294 | } |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 295 | |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 296 | if (port <= 0 || port > 0xffff) { |
| 297 | LOG(WARNING) << "Invalid port: " << port; |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 298 | return false; |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 299 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 300 | |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 301 | switch (service_type) { |
| 302 | case STUN: |
| 303 | case STUNS: |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 304 | stun_servers->insert(rtc::SocketAddress(address, port)); |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 305 | break; |
| 306 | case TURN: |
| 307 | case TURNS: { |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 308 | bool secure = (service_type == TURNS); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 309 | turn_servers->push_back( |
| 310 | cricket::RelayServerConfig(address, port, username, server.password, |
| 311 | turn_transport_type, secure)); |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 312 | break; |
| 313 | } |
| 314 | case INVALID: |
| 315 | default: |
| 316 | LOG(WARNING) << "Configuration not supported: " << url; |
| 317 | return false; |
| 318 | } |
| 319 | return true; |
| 320 | } |
| 321 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 322 | // Check if we can send |new_stream| on a PeerConnection. |
| 323 | bool CanAddLocalMediaStream(webrtc::StreamCollectionInterface* current_streams, |
| 324 | webrtc::MediaStreamInterface* new_stream) { |
| 325 | if (!new_stream || !current_streams) { |
| 326 | return false; |
| 327 | } |
| 328 | if (current_streams->find(new_stream->label()) != nullptr) { |
| 329 | LOG(LS_ERROR) << "MediaStream with label " << new_stream->label() |
| 330 | << " is already added."; |
| 331 | return false; |
| 332 | } |
| 333 | return true; |
| 334 | } |
| 335 | |
| 336 | bool MediaContentDirectionHasSend(cricket::MediaContentDirection dir) { |
| 337 | return dir == cricket::MD_SENDONLY || dir == cricket::MD_SENDRECV; |
| 338 | } |
| 339 | |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 340 | // If the direction is "recvonly" or "inactive", treat the description |
| 341 | // as containing no streams. |
| 342 | // See: https://code.google.com/p/webrtc/issues/detail?id=5054 |
| 343 | std::vector<cricket::StreamParams> GetActiveStreams( |
| 344 | const cricket::MediaContentDescription* desc) { |
| 345 | return MediaContentDirectionHasSend(desc->direction()) |
| 346 | ? desc->streams() |
| 347 | : std::vector<cricket::StreamParams>(); |
| 348 | } |
| 349 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 350 | bool IsValidOfferToReceiveMedia(int value) { |
| 351 | typedef PeerConnectionInterface::RTCOfferAnswerOptions Options; |
| 352 | return (value >= Options::kUndefined) && |
| 353 | (value <= Options::kMaxOfferToReceiveMedia); |
| 354 | } |
| 355 | |
| 356 | // Add the stream and RTP data channel info to |session_options|. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 357 | void AddSendStreams( |
| 358 | cricket::MediaSessionOptions* session_options, |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 359 | const std::vector<rtc::scoped_refptr< |
| 360 | RtpSenderProxyWithInternal<RtpSenderInternal>>>& senders, |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 361 | const std::map<std::string, rtc::scoped_refptr<DataChannel>>& |
| 362 | rtp_data_channels) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 363 | session_options->streams.clear(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 364 | for (const auto& sender : senders) { |
| 365 | session_options->AddSendStream(sender->media_type(), sender->id(), |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 366 | sender->internal()->stream_id()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | // Check for data channels. |
| 370 | for (const auto& kv : rtp_data_channels) { |
| 371 | const DataChannel* channel = kv.second; |
| 372 | if (channel->state() == DataChannel::kConnecting || |
| 373 | channel->state() == DataChannel::kOpen) { |
| 374 | // |streamid| and |sync_label| are both set to the DataChannel label |
| 375 | // here so they can be signaled the same way as MediaStreams and Tracks. |
| 376 | // For MediaStreams, the sync_label is the MediaStream label and the |
| 377 | // track label is the same as |streamid|. |
| 378 | const std::string& streamid = channel->label(); |
| 379 | const std::string& sync_label = channel->label(); |
| 380 | session_options->AddSendStream(cricket::MEDIA_TYPE_DATA, streamid, |
| 381 | sync_label); |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 386 | uint32_t ConvertIceTransportTypeToCandidateFilter( |
| 387 | PeerConnectionInterface::IceTransportsType type) { |
| 388 | switch (type) { |
| 389 | case PeerConnectionInterface::kNone: |
| 390 | return cricket::CF_NONE; |
| 391 | case PeerConnectionInterface::kRelay: |
| 392 | return cricket::CF_RELAY; |
| 393 | case PeerConnectionInterface::kNoHost: |
| 394 | return (cricket::CF_ALL & ~cricket::CF_HOST); |
| 395 | case PeerConnectionInterface::kAll: |
| 396 | return cricket::CF_ALL; |
| 397 | default: |
| 398 | ASSERT(false); |
| 399 | } |
| 400 | return cricket::CF_NONE; |
| 401 | } |
| 402 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 403 | // Helper method to set a voice/video channel on all applicable senders |
| 404 | // and receivers when one is created/destroyed by WebRtcSession. |
| 405 | // |
| 406 | // Used by On(Voice|Video)Channel(Created|Destroyed) |
| 407 | template <class SENDER, |
| 408 | class RECEIVER, |
| 409 | class CHANNEL, |
| 410 | class SENDERS, |
| 411 | class RECEIVERS> |
| 412 | void SetChannelOnSendersAndReceivers(CHANNEL* channel, |
| 413 | SENDERS& senders, |
| 414 | RECEIVERS& receivers, |
| 415 | cricket::MediaType media_type) { |
| 416 | for (auto& sender : senders) { |
| 417 | if (sender->media_type() == media_type) { |
| 418 | static_cast<SENDER*>(sender->internal())->SetChannel(channel); |
| 419 | } |
| 420 | } |
| 421 | for (auto& receiver : receivers) { |
| 422 | if (receiver->media_type() == media_type) { |
| 423 | if (!channel) { |
| 424 | receiver->internal()->Stop(); |
| 425 | } |
| 426 | static_cast<RECEIVER*>(receiver->internal())->SetChannel(channel); |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 431 | } // namespace |
| 432 | |
| 433 | namespace webrtc { |
| 434 | |
deadbeef | 3edec7c | 2016-12-10 11:44:26 -0800 | [diff] [blame] | 435 | static const char* const kRtcErrorNames[] = { |
| 436 | "NONE", |
| 437 | "UNSUPPORTED_PARAMETER", |
| 438 | "INVALID_PARAMETER", |
| 439 | "INVALID_RANGE", |
| 440 | "SYNTAX_ERROR", |
| 441 | "INVALID_STATE", |
| 442 | "INVALID_MODIFICATION", |
| 443 | "NETWORK_ERROR", |
| 444 | "INTERNAL_ERROR", |
| 445 | }; |
| 446 | |
| 447 | std::ostream& operator<<(std::ostream& stream, RtcError error) { |
| 448 | int index = static_cast<int>(error); |
| 449 | RTC_CHECK(index < static_cast<int>(sizeof(kRtcErrorNames) / |
| 450 | sizeof(kRtcErrorNames[0]))); |
| 451 | return stream << kRtcErrorNames[index]; |
| 452 | } |
| 453 | |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 454 | // Generate a RTCP CNAME when a PeerConnection is created. |
| 455 | std::string GenerateRtcpCname() { |
| 456 | std::string cname; |
| 457 | if (!rtc::CreateRandomString(kRtcpCnameLength, &cname)) { |
| 458 | LOG(LS_ERROR) << "Failed to generate CNAME."; |
| 459 | RTC_DCHECK(false); |
| 460 | } |
| 461 | return cname; |
| 462 | } |
| 463 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 464 | bool ExtractMediaSessionOptions( |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 465 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 466 | bool is_offer, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 467 | cricket::MediaSessionOptions* session_options) { |
| 468 | typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; |
| 469 | if (!IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_audio) || |
| 470 | !IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_video)) { |
| 471 | return false; |
| 472 | } |
| 473 | |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 474 | // If constraints don't prevent us, we always accept video. |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 475 | if (rtc_options.offer_to_receive_audio != RTCOfferAnswerOptions::kUndefined) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 476 | session_options->recv_audio = (rtc_options.offer_to_receive_audio > 0); |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 477 | } else { |
| 478 | session_options->recv_audio = true; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 479 | } |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 480 | // For offers, we only offer video if we have it or it's forced by options. |
| 481 | // For answers, we will always accept video (if offered). |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 482 | if (rtc_options.offer_to_receive_video != RTCOfferAnswerOptions::kUndefined) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 483 | session_options->recv_video = (rtc_options.offer_to_receive_video > 0); |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 484 | } else if (is_offer) { |
| 485 | session_options->recv_video = false; |
| 486 | } else { |
| 487 | session_options->recv_video = true; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | session_options->vad_enabled = rtc_options.voice_activity_detection; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 491 | session_options->bundle_enabled = rtc_options.use_rtp_mux; |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 492 | for (auto& kv : session_options->transport_options) { |
| 493 | kv.second.ice_restart = rtc_options.ice_restart; |
| 494 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 495 | |
| 496 | return true; |
| 497 | } |
| 498 | |
| 499 | bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints, |
| 500 | cricket::MediaSessionOptions* session_options) { |
| 501 | bool value = false; |
| 502 | size_t mandatory_constraints_satisfied = 0; |
| 503 | |
| 504 | // kOfferToReceiveAudio defaults to true according to spec. |
| 505 | if (!FindConstraint(constraints, |
| 506 | MediaConstraintsInterface::kOfferToReceiveAudio, &value, |
| 507 | &mandatory_constraints_satisfied) || |
| 508 | value) { |
| 509 | session_options->recv_audio = true; |
| 510 | } |
| 511 | |
| 512 | // kOfferToReceiveVideo defaults to false according to spec. But |
| 513 | // if it is an answer and video is offered, we should still accept video |
| 514 | // per default. |
| 515 | value = false; |
| 516 | if (!FindConstraint(constraints, |
| 517 | MediaConstraintsInterface::kOfferToReceiveVideo, &value, |
| 518 | &mandatory_constraints_satisfied) || |
| 519 | value) { |
| 520 | session_options->recv_video = true; |
| 521 | } |
| 522 | |
| 523 | if (FindConstraint(constraints, |
| 524 | MediaConstraintsInterface::kVoiceActivityDetection, &value, |
| 525 | &mandatory_constraints_satisfied)) { |
| 526 | session_options->vad_enabled = value; |
| 527 | } |
| 528 | |
| 529 | if (FindConstraint(constraints, MediaConstraintsInterface::kUseRtpMux, &value, |
| 530 | &mandatory_constraints_satisfied)) { |
| 531 | session_options->bundle_enabled = value; |
| 532 | } else { |
| 533 | // kUseRtpMux defaults to true according to spec. |
| 534 | session_options->bundle_enabled = true; |
| 535 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 536 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 537 | bool ice_restart = false; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 538 | if (FindConstraint(constraints, MediaConstraintsInterface::kIceRestart, |
| 539 | &value, &mandatory_constraints_satisfied)) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 540 | // kIceRestart defaults to false according to spec. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 541 | ice_restart = true; |
| 542 | } |
| 543 | for (auto& kv : session_options->transport_options) { |
| 544 | kv.second.ice_restart = ice_restart; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | if (!constraints) { |
| 548 | return true; |
| 549 | } |
| 550 | return mandatory_constraints_satisfied == constraints->GetMandatory().size(); |
| 551 | } |
| 552 | |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 553 | bool ParseIceServers(const PeerConnectionInterface::IceServers& servers, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 554 | cricket::ServerAddresses* stun_servers, |
| 555 | std::vector<cricket::RelayServerConfig>* turn_servers) { |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 556 | for (const webrtc::PeerConnectionInterface::IceServer& server : servers) { |
| 557 | if (!server.urls.empty()) { |
| 558 | for (const std::string& url : server.urls) { |
Joachim Bauch | d935f91 | 2015-05-29 22:14:21 +0200 | [diff] [blame] | 559 | if (url.empty()) { |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 560 | LOG(LS_ERROR) << "Empty uri."; |
| 561 | return false; |
Joachim Bauch | d935f91 | 2015-05-29 22:14:21 +0200 | [diff] [blame] | 562 | } |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 563 | if (!ParseIceServerUrl(server, url, stun_servers, turn_servers)) { |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 564 | return false; |
| 565 | } |
| 566 | } |
| 567 | } else if (!server.uri.empty()) { |
| 568 | // Fallback to old .uri if new .urls isn't present. |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 569 | if (!ParseIceServerUrl(server, server.uri, stun_servers, turn_servers)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 570 | return false; |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 571 | } |
| 572 | } else { |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 573 | LOG(LS_ERROR) << "Empty uri."; |
| 574 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 575 | } |
| 576 | } |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 577 | // Candidates must have unique priorities, so that connectivity checks |
| 578 | // are performed in a well-defined order. |
| 579 | int priority = static_cast<int>(turn_servers->size() - 1); |
| 580 | for (cricket::RelayServerConfig& turn_server : *turn_servers) { |
| 581 | // First in the list gets highest priority. |
| 582 | turn_server.priority = priority--; |
| 583 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 584 | return true; |
| 585 | } |
| 586 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 587 | PeerConnection::PeerConnection(PeerConnectionFactory* factory) |
| 588 | : factory_(factory), |
| 589 | observer_(NULL), |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 590 | uma_observer_(NULL), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 591 | signaling_state_(kStable), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 592 | ice_connection_state_(kIceConnectionNew), |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 593 | ice_gathering_state_(kIceGatheringNew), |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 594 | event_log_(RtcEventLog::Create(webrtc::Clock::GetRealTimeClock())), |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 595 | rtcp_cname_(GenerateRtcpCname()), |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 596 | local_streams_(StreamCollection::Create()), |
| 597 | remote_streams_(StreamCollection::Create()) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 598 | |
| 599 | PeerConnection::~PeerConnection() { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 600 | TRACE_EVENT0("webrtc", "PeerConnection::~PeerConnection"); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 601 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 602 | // Need to detach RTP senders/receivers from WebRtcSession, |
| 603 | // since it's about to be destroyed. |
| 604 | for (const auto& sender : senders_) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 605 | sender->internal()->Stop(); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 606 | } |
| 607 | for (const auto& receiver : receivers_) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 608 | receiver->internal()->Stop(); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 609 | } |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 610 | // Destroy stats_ because it depends on session_. |
| 611 | stats_.reset(nullptr); |
| 612 | // Now destroy session_ before destroying other members, |
| 613 | // because its destruction fires signals (such as VoiceChannelDestroyed) |
| 614 | // which will trigger some final actions in PeerConnection... |
| 615 | session_.reset(nullptr); |
deadbeef | 91dd567 | 2016-05-18 16:55:30 -0700 | [diff] [blame] | 616 | // port_allocator_ lives on the network thread and should be destroyed there. |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 617 | network_thread()->Invoke<void>(RTC_FROM_HERE, |
| 618 | [this] { port_allocator_.reset(nullptr); }); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | bool PeerConnection::Initialize( |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 622 | const PeerConnectionInterface::RTCConfiguration& configuration, |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 623 | std::unique_ptr<cricket::PortAllocator> allocator, |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 624 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 625 | PeerConnectionObserver* observer) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 626 | TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 627 | RTC_DCHECK(observer != nullptr); |
| 628 | if (!observer) { |
| 629 | return false; |
| 630 | } |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 631 | observer_ = observer; |
| 632 | |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 633 | port_allocator_ = std::move(allocator); |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 634 | |
deadbeef | 91dd567 | 2016-05-18 16:55:30 -0700 | [diff] [blame] | 635 | // The port allocator lives on the network thread and should be initialized |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 636 | // there. |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 637 | if (!network_thread()->Invoke<bool>( |
| 638 | RTC_FROM_HERE, rtc::Bind(&PeerConnection::InitializePortAllocator_n, |
| 639 | this, configuration))) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 640 | return false; |
| 641 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 642 | |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 643 | media_controller_.reset(factory_->CreateMediaController( |
| 644 | configuration.media_config, event_log_.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 645 | |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 646 | session_.reset(new WebRtcSession( |
| 647 | media_controller_.get(), factory_->network_thread(), |
| 648 | factory_->worker_thread(), factory_->signaling_thread(), |
| 649 | port_allocator_.get(), |
| 650 | std::unique_ptr<cricket::TransportController>( |
Honghai Zhang | bfd398c | 2016-08-30 22:07:42 -0700 | [diff] [blame] | 651 | factory_->CreateTransportController( |
| 652 | port_allocator_.get(), |
| 653 | configuration.redetermine_role_on_ice_restart)))); |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 654 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 655 | stats_.reset(new StatsCollector(this)); |
hbos | 74e1a4f | 2016-09-15 23:33:01 -0700 | [diff] [blame] | 656 | stats_collector_ = RTCStatsCollector::Create(this); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 657 | |
| 658 | // Initialize the WebRtcSession. It creates transport channels etc. |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 659 | if (!session_->Initialize(factory_->options(), std::move(cert_generator), |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 660 | configuration)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 661 | return false; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 662 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 663 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 664 | // Register PeerConnection as receiver of local ice candidates. |
| 665 | // All the callbacks will be posted to the application from PeerConnection. |
| 666 | session_->RegisterIceObserver(this); |
| 667 | session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 668 | session_->SignalVoiceChannelCreated.connect( |
| 669 | this, &PeerConnection::OnVoiceChannelCreated); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 670 | session_->SignalVoiceChannelDestroyed.connect( |
| 671 | this, &PeerConnection::OnVoiceChannelDestroyed); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 672 | session_->SignalVideoChannelCreated.connect( |
| 673 | this, &PeerConnection::OnVideoChannelCreated); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 674 | session_->SignalVideoChannelDestroyed.connect( |
| 675 | this, &PeerConnection::OnVideoChannelDestroyed); |
| 676 | session_->SignalDataChannelCreated.connect( |
| 677 | this, &PeerConnection::OnDataChannelCreated); |
| 678 | session_->SignalDataChannelDestroyed.connect( |
| 679 | this, &PeerConnection::OnDataChannelDestroyed); |
| 680 | session_->SignalDataChannelOpenMessage.connect( |
| 681 | this, &PeerConnection::OnDataChannelOpenMessage); |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 682 | |
| 683 | configuration_ = configuration; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 684 | return true; |
| 685 | } |
| 686 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 687 | rtc::scoped_refptr<StreamCollectionInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 688 | PeerConnection::local_streams() { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 689 | return local_streams_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 690 | } |
| 691 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 692 | rtc::scoped_refptr<StreamCollectionInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 693 | PeerConnection::remote_streams() { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 694 | return remote_streams_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 695 | } |
| 696 | |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 697 | bool PeerConnection::AddStream(MediaStreamInterface* local_stream) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 698 | TRACE_EVENT0("webrtc", "PeerConnection::AddStream"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 699 | if (IsClosed()) { |
| 700 | return false; |
| 701 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 702 | if (!CanAddLocalMediaStream(local_streams_, local_stream)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 703 | return false; |
| 704 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 705 | |
| 706 | local_streams_->AddStream(local_stream); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 707 | MediaStreamObserver* observer = new MediaStreamObserver(local_stream); |
| 708 | observer->SignalAudioTrackAdded.connect(this, |
| 709 | &PeerConnection::OnAudioTrackAdded); |
| 710 | observer->SignalAudioTrackRemoved.connect( |
| 711 | this, &PeerConnection::OnAudioTrackRemoved); |
| 712 | observer->SignalVideoTrackAdded.connect(this, |
| 713 | &PeerConnection::OnVideoTrackAdded); |
| 714 | observer->SignalVideoTrackRemoved.connect( |
| 715 | this, &PeerConnection::OnVideoTrackRemoved); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 716 | stream_observers_.push_back(std::unique_ptr<MediaStreamObserver>(observer)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 717 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 718 | for (const auto& track : local_stream->GetAudioTracks()) { |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 719 | OnAudioTrackAdded(track.get(), local_stream); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 720 | } |
| 721 | for (const auto& track : local_stream->GetVideoTracks()) { |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 722 | OnVideoTrackAdded(track.get(), local_stream); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 723 | } |
| 724 | |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 725 | stats_->AddStream(local_stream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 726 | observer_->OnRenegotiationNeeded(); |
| 727 | return true; |
| 728 | } |
| 729 | |
| 730 | void PeerConnection::RemoveStream(MediaStreamInterface* local_stream) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 731 | TRACE_EVENT0("webrtc", "PeerConnection::RemoveStream"); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 732 | for (const auto& track : local_stream->GetAudioTracks()) { |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 733 | OnAudioTrackRemoved(track.get(), local_stream); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 734 | } |
| 735 | for (const auto& track : local_stream->GetVideoTracks()) { |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 736 | OnVideoTrackRemoved(track.get(), local_stream); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | local_streams_->RemoveStream(local_stream); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 740 | stream_observers_.erase( |
| 741 | std::remove_if( |
| 742 | stream_observers_.begin(), stream_observers_.end(), |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 743 | [local_stream](const std::unique_ptr<MediaStreamObserver>& observer) { |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 744 | return observer->stream()->label().compare(local_stream->label()) == |
| 745 | 0; |
| 746 | }), |
| 747 | stream_observers_.end()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 748 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 749 | if (IsClosed()) { |
| 750 | return; |
| 751 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 752 | observer_->OnRenegotiationNeeded(); |
| 753 | } |
| 754 | |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 755 | rtc::scoped_refptr<RtpSenderInterface> PeerConnection::AddTrack( |
| 756 | MediaStreamTrackInterface* track, |
| 757 | std::vector<MediaStreamInterface*> streams) { |
| 758 | TRACE_EVENT0("webrtc", "PeerConnection::AddTrack"); |
| 759 | if (IsClosed()) { |
| 760 | return nullptr; |
| 761 | } |
| 762 | if (streams.size() >= 2) { |
| 763 | LOG(LS_ERROR) |
| 764 | << "Adding a track with two streams is not currently supported."; |
| 765 | return nullptr; |
| 766 | } |
| 767 | // TODO(deadbeef): Support adding a track to two different senders. |
| 768 | if (FindSenderForTrack(track) != senders_.end()) { |
| 769 | LOG(LS_ERROR) << "Sender for track " << track->id() << " already exists."; |
| 770 | return nullptr; |
| 771 | } |
| 772 | |
| 773 | // TODO(deadbeef): Support adding a track to multiple streams. |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 774 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> new_sender; |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 775 | if (track->kind() == MediaStreamTrackInterface::kAudioKind) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 776 | new_sender = RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 777 | signaling_thread(), |
| 778 | new AudioRtpSender(static_cast<AudioTrackInterface*>(track), |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 779 | session_->voice_channel(), stats_.get())); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 780 | if (!streams.empty()) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 781 | new_sender->internal()->set_stream_id(streams[0]->label()); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 782 | } |
| 783 | const TrackInfo* track_info = FindTrackInfo( |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 784 | local_audio_tracks_, new_sender->internal()->stream_id(), track->id()); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 785 | if (track_info) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 786 | new_sender->internal()->SetSsrc(track_info->ssrc); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 787 | } |
| 788 | } else if (track->kind() == MediaStreamTrackInterface::kVideoKind) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 789 | new_sender = RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 790 | signaling_thread(), |
| 791 | new VideoRtpSender(static_cast<VideoTrackInterface*>(track), |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 792 | session_->video_channel())); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 793 | if (!streams.empty()) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 794 | new_sender->internal()->set_stream_id(streams[0]->label()); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 795 | } |
| 796 | const TrackInfo* track_info = FindTrackInfo( |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 797 | local_video_tracks_, new_sender->internal()->stream_id(), track->id()); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 798 | if (track_info) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 799 | new_sender->internal()->SetSsrc(track_info->ssrc); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 800 | } |
| 801 | } else { |
| 802 | LOG(LS_ERROR) << "CreateSender called with invalid kind: " << track->kind(); |
| 803 | return rtc::scoped_refptr<RtpSenderInterface>(); |
| 804 | } |
| 805 | |
| 806 | senders_.push_back(new_sender); |
| 807 | observer_->OnRenegotiationNeeded(); |
| 808 | return new_sender; |
| 809 | } |
| 810 | |
| 811 | bool PeerConnection::RemoveTrack(RtpSenderInterface* sender) { |
| 812 | TRACE_EVENT0("webrtc", "PeerConnection::RemoveTrack"); |
| 813 | if (IsClosed()) { |
| 814 | return false; |
| 815 | } |
| 816 | |
| 817 | auto it = std::find(senders_.begin(), senders_.end(), sender); |
| 818 | if (it == senders_.end()) { |
| 819 | LOG(LS_ERROR) << "Couldn't find sender " << sender->id() << " to remove."; |
| 820 | return false; |
| 821 | } |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 822 | (*it)->internal()->Stop(); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 823 | senders_.erase(it); |
| 824 | |
| 825 | observer_->OnRenegotiationNeeded(); |
| 826 | return true; |
| 827 | } |
| 828 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 829 | rtc::scoped_refptr<DtmfSenderInterface> PeerConnection::CreateDtmfSender( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 830 | AudioTrackInterface* track) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 831 | TRACE_EVENT0("webrtc", "PeerConnection::CreateDtmfSender"); |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 832 | if (IsClosed()) { |
| 833 | return nullptr; |
| 834 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 835 | if (!track) { |
| 836 | LOG(LS_ERROR) << "CreateDtmfSender - track is NULL."; |
| 837 | return NULL; |
| 838 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 839 | if (!local_streams_->FindAudioTrack(track->id())) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 840 | LOG(LS_ERROR) << "CreateDtmfSender is called with a non local audio track."; |
| 841 | return NULL; |
| 842 | } |
| 843 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 844 | rtc::scoped_refptr<DtmfSenderInterface> sender( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 845 | DtmfSender::Create(track, signaling_thread(), session_.get())); |
| 846 | if (!sender.get()) { |
| 847 | LOG(LS_ERROR) << "CreateDtmfSender failed on DtmfSender::Create."; |
| 848 | return NULL; |
| 849 | } |
| 850 | return DtmfSenderProxy::Create(signaling_thread(), sender.get()); |
| 851 | } |
| 852 | |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 853 | rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender( |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 854 | const std::string& kind, |
| 855 | const std::string& stream_id) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 856 | TRACE_EVENT0("webrtc", "PeerConnection::CreateSender"); |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 857 | if (IsClosed()) { |
| 858 | return nullptr; |
| 859 | } |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 860 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> new_sender; |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 861 | if (kind == MediaStreamTrackInterface::kAudioKind) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 862 | new_sender = RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 863 | signaling_thread(), |
| 864 | new AudioRtpSender(session_->voice_channel(), stats_.get())); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 865 | } else if (kind == MediaStreamTrackInterface::kVideoKind) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 866 | new_sender = RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 867 | signaling_thread(), new VideoRtpSender(session_->video_channel())); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 868 | } else { |
| 869 | LOG(LS_ERROR) << "CreateSender called with invalid kind: " << kind; |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 870 | return new_sender; |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 871 | } |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 872 | if (!stream_id.empty()) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 873 | new_sender->internal()->set_stream_id(stream_id); |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 874 | } |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 875 | senders_.push_back(new_sender); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 876 | return new_sender; |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 877 | } |
| 878 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 879 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> PeerConnection::GetSenders() |
| 880 | const { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 881 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> ret; |
| 882 | for (const auto& sender : senders_) { |
| 883 | ret.push_back(sender.get()); |
| 884 | } |
| 885 | return ret; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> |
| 889 | PeerConnection::GetReceivers() const { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 890 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> ret; |
| 891 | for (const auto& receiver : receivers_) { |
| 892 | ret.push_back(receiver.get()); |
| 893 | } |
| 894 | return ret; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 895 | } |
| 896 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 897 | bool PeerConnection::GetStats(StatsObserver* observer, |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 898 | MediaStreamTrackInterface* track, |
| 899 | StatsOutputLevel level) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 900 | TRACE_EVENT0("webrtc", "PeerConnection::GetStats"); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 901 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 902 | if (!VERIFY(observer != NULL)) { |
| 903 | LOG(LS_ERROR) << "GetStats - observer is NULL."; |
| 904 | return false; |
| 905 | } |
| 906 | |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 907 | stats_->UpdateStats(level); |
zhihuang | e9e94c3 | 2016-11-04 11:38:15 -0700 | [diff] [blame] | 908 | // The StatsCollector is used to tell if a track is valid because it may |
| 909 | // remember tracks that the PeerConnection previously removed. |
| 910 | if (track && !stats_->IsValidTrack(track->id())) { |
| 911 | LOG(LS_WARNING) << "GetStats is called with an invalid track: " |
| 912 | << track->id(); |
| 913 | return false; |
| 914 | } |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 915 | signaling_thread()->Post(RTC_FROM_HERE, this, MSG_GETSTATS, |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 916 | new GetStatsMsg(observer, track)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 917 | return true; |
| 918 | } |
| 919 | |
hbos | 74e1a4f | 2016-09-15 23:33:01 -0700 | [diff] [blame] | 920 | void PeerConnection::GetStats(RTCStatsCollectorCallback* callback) { |
| 921 | RTC_DCHECK(stats_collector_); |
| 922 | stats_collector_->GetStatsReport(callback); |
| 923 | } |
| 924 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 925 | PeerConnectionInterface::SignalingState PeerConnection::signaling_state() { |
| 926 | return signaling_state_; |
| 927 | } |
| 928 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 929 | PeerConnectionInterface::IceConnectionState |
| 930 | PeerConnection::ice_connection_state() { |
| 931 | return ice_connection_state_; |
| 932 | } |
| 933 | |
| 934 | PeerConnectionInterface::IceGatheringState |
| 935 | PeerConnection::ice_gathering_state() { |
| 936 | return ice_gathering_state_; |
| 937 | } |
| 938 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 939 | rtc::scoped_refptr<DataChannelInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 940 | PeerConnection::CreateDataChannel( |
| 941 | const std::string& label, |
| 942 | const DataChannelInit* config) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 943 | TRACE_EVENT0("webrtc", "PeerConnection::CreateDataChannel"); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 944 | #ifdef HAVE_QUIC |
| 945 | if (session_->data_channel_type() == cricket::DCT_QUIC) { |
| 946 | // TODO(zhihuang): Handle case when config is NULL. |
| 947 | if (!config) { |
| 948 | LOG(LS_ERROR) << "Missing config for QUIC data channel."; |
| 949 | return nullptr; |
| 950 | } |
| 951 | // TODO(zhihuang): Allow unreliable or ordered QUIC data channels. |
| 952 | if (!config->reliable || config->ordered) { |
| 953 | LOG(LS_ERROR) << "QUIC data channel does not implement unreliable or " |
| 954 | "ordered delivery."; |
| 955 | return nullptr; |
| 956 | } |
| 957 | return session_->quic_data_transport()->CreateDataChannel(label, config); |
| 958 | } |
| 959 | #endif // HAVE_QUIC |
| 960 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 961 | bool first_datachannel = !HasDataChannels(); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 962 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 963 | std::unique_ptr<InternalDataChannelInit> internal_config; |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 964 | if (config) { |
| 965 | internal_config.reset(new InternalDataChannelInit(*config)); |
| 966 | } |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 967 | rtc::scoped_refptr<DataChannelInterface> channel( |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 968 | InternalCreateDataChannel(label, internal_config.get())); |
| 969 | if (!channel.get()) { |
| 970 | return nullptr; |
| 971 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 972 | |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 973 | // Trigger the onRenegotiationNeeded event for every new RTP DataChannel, or |
| 974 | // the first SCTP DataChannel. |
| 975 | if (session_->data_channel_type() == cricket::DCT_RTP || first_datachannel) { |
| 976 | observer_->OnRenegotiationNeeded(); |
| 977 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 978 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 979 | return DataChannelProxy::Create(signaling_thread(), channel.get()); |
| 980 | } |
| 981 | |
| 982 | void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, |
| 983 | const MediaConstraintsInterface* constraints) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 984 | TRACE_EVENT0("webrtc", "PeerConnection::CreateOffer"); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 985 | if (!VERIFY(observer != nullptr)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 986 | LOG(LS_ERROR) << "CreateOffer - observer is NULL."; |
| 987 | return; |
| 988 | } |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 989 | RTCOfferAnswerOptions options; |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 990 | |
| 991 | bool value; |
| 992 | size_t mandatory_constraints = 0; |
| 993 | |
| 994 | if (FindConstraint(constraints, |
| 995 | MediaConstraintsInterface::kOfferToReceiveAudio, |
| 996 | &value, |
| 997 | &mandatory_constraints)) { |
| 998 | options.offer_to_receive_audio = |
| 999 | value ? RTCOfferAnswerOptions::kOfferToReceiveMediaTrue : 0; |
| 1000 | } |
| 1001 | |
| 1002 | if (FindConstraint(constraints, |
| 1003 | MediaConstraintsInterface::kOfferToReceiveVideo, |
| 1004 | &value, |
| 1005 | &mandatory_constraints)) { |
| 1006 | options.offer_to_receive_video = |
| 1007 | value ? RTCOfferAnswerOptions::kOfferToReceiveMediaTrue : 0; |
| 1008 | } |
| 1009 | |
| 1010 | if (FindConstraint(constraints, |
| 1011 | MediaConstraintsInterface::kVoiceActivityDetection, |
| 1012 | &value, |
| 1013 | &mandatory_constraints)) { |
| 1014 | options.voice_activity_detection = value; |
| 1015 | } |
| 1016 | |
| 1017 | if (FindConstraint(constraints, |
| 1018 | MediaConstraintsInterface::kIceRestart, |
| 1019 | &value, |
| 1020 | &mandatory_constraints)) { |
| 1021 | options.ice_restart = value; |
| 1022 | } |
| 1023 | |
| 1024 | if (FindConstraint(constraints, |
| 1025 | MediaConstraintsInterface::kUseRtpMux, |
| 1026 | &value, |
| 1027 | &mandatory_constraints)) { |
| 1028 | options.use_rtp_mux = value; |
| 1029 | } |
| 1030 | |
| 1031 | CreateOffer(observer, options); |
| 1032 | } |
| 1033 | |
| 1034 | void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, |
| 1035 | const RTCOfferAnswerOptions& options) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 1036 | TRACE_EVENT0("webrtc", "PeerConnection::CreateOffer"); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1037 | if (!VERIFY(observer != nullptr)) { |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1038 | LOG(LS_ERROR) << "CreateOffer - observer is NULL."; |
| 1039 | return; |
| 1040 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1041 | |
| 1042 | cricket::MediaSessionOptions session_options; |
| 1043 | if (!GetOptionsForOffer(options, &session_options)) { |
| 1044 | std::string error = "CreateOffer called with invalid options."; |
| 1045 | LOG(LS_ERROR) << error; |
| 1046 | PostCreateSessionDescriptionFailure(observer, error); |
| 1047 | return; |
| 1048 | } |
| 1049 | |
| 1050 | session_->CreateOffer(observer, options, session_options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | void PeerConnection::CreateAnswer( |
| 1054 | CreateSessionDescriptionObserver* observer, |
| 1055 | const MediaConstraintsInterface* constraints) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 1056 | TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer"); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1057 | if (!VERIFY(observer != nullptr)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1058 | LOG(LS_ERROR) << "CreateAnswer - observer is NULL."; |
| 1059 | return; |
| 1060 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1061 | |
| 1062 | cricket::MediaSessionOptions session_options; |
| 1063 | if (!GetOptionsForAnswer(constraints, &session_options)) { |
| 1064 | std::string error = "CreateAnswer called with invalid constraints."; |
| 1065 | LOG(LS_ERROR) << error; |
| 1066 | PostCreateSessionDescriptionFailure(observer, error); |
| 1067 | return; |
| 1068 | } |
| 1069 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1070 | session_->CreateAnswer(observer, session_options); |
| 1071 | } |
| 1072 | |
| 1073 | void PeerConnection::CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 1074 | const RTCOfferAnswerOptions& options) { |
| 1075 | TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer"); |
| 1076 | if (!VERIFY(observer != nullptr)) { |
| 1077 | LOG(LS_ERROR) << "CreateAnswer - observer is NULL."; |
| 1078 | return; |
| 1079 | } |
| 1080 | |
| 1081 | cricket::MediaSessionOptions session_options; |
| 1082 | if (!GetOptionsForAnswer(options, &session_options)) { |
| 1083 | std::string error = "CreateAnswer called with invalid options."; |
| 1084 | LOG(LS_ERROR) << error; |
| 1085 | PostCreateSessionDescriptionFailure(observer, error); |
| 1086 | return; |
| 1087 | } |
| 1088 | |
| 1089 | session_->CreateAnswer(observer, session_options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | void PeerConnection::SetLocalDescription( |
| 1093 | SetSessionDescriptionObserver* observer, |
| 1094 | SessionDescriptionInterface* desc) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 1095 | TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 1096 | if (IsClosed()) { |
| 1097 | return; |
| 1098 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1099 | if (!VERIFY(observer != nullptr)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1100 | LOG(LS_ERROR) << "SetLocalDescription - observer is NULL."; |
| 1101 | return; |
| 1102 | } |
| 1103 | if (!desc) { |
| 1104 | PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL."); |
| 1105 | return; |
| 1106 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1107 | // Update stats here so that we have the most recent stats for tracks and |
| 1108 | // streams that might be removed by updating the session description. |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 1109 | stats_->UpdateStats(kStatsOutputLevelStandard); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1110 | std::string error; |
| 1111 | if (!session_->SetLocalDescription(desc, &error)) { |
| 1112 | PostSetSessionDescriptionFailure(observer, error); |
| 1113 | return; |
| 1114 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1115 | |
| 1116 | // If setting the description decided our SSL role, allocate any necessary |
| 1117 | // SCTP sids. |
| 1118 | rtc::SSLRole role; |
| 1119 | if (session_->data_channel_type() == cricket::DCT_SCTP && |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1120 | session_->GetSslRole(session_->data_channel(), &role)) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1121 | AllocateSctpSids(role); |
| 1122 | } |
| 1123 | |
| 1124 | // Update state and SSRC of local MediaStreams and DataChannels based on the |
| 1125 | // local session description. |
| 1126 | const cricket::ContentInfo* audio_content = |
| 1127 | GetFirstAudioContent(desc->description()); |
| 1128 | if (audio_content) { |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 1129 | if (audio_content->rejected) { |
| 1130 | RemoveTracks(cricket::MEDIA_TYPE_AUDIO); |
| 1131 | } else { |
| 1132 | const cricket::AudioContentDescription* audio_desc = |
| 1133 | static_cast<const cricket::AudioContentDescription*>( |
| 1134 | audio_content->description); |
| 1135 | UpdateLocalTracks(audio_desc->streams(), audio_desc->type()); |
| 1136 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | const cricket::ContentInfo* video_content = |
| 1140 | GetFirstVideoContent(desc->description()); |
| 1141 | if (video_content) { |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 1142 | if (video_content->rejected) { |
| 1143 | RemoveTracks(cricket::MEDIA_TYPE_VIDEO); |
| 1144 | } else { |
| 1145 | const cricket::VideoContentDescription* video_desc = |
| 1146 | static_cast<const cricket::VideoContentDescription*>( |
| 1147 | video_content->description); |
| 1148 | UpdateLocalTracks(video_desc->streams(), video_desc->type()); |
| 1149 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | const cricket::ContentInfo* data_content = |
| 1153 | GetFirstDataContent(desc->description()); |
| 1154 | if (data_content) { |
| 1155 | const cricket::DataContentDescription* data_desc = |
| 1156 | static_cast<const cricket::DataContentDescription*>( |
| 1157 | data_content->description); |
| 1158 | if (rtc::starts_with(data_desc->protocol().data(), |
| 1159 | cricket::kMediaProtocolRtpPrefix)) { |
| 1160 | UpdateLocalRtpDataChannels(data_desc->streams()); |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 1165 | signaling_thread()->Post(RTC_FROM_HERE, this, |
| 1166 | MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1167 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1168 | // MaybeStartGathering needs to be called after posting |
| 1169 | // MSG_SET_SESSIONDESCRIPTION_SUCCESS, so that we don't signal any candidates |
| 1170 | // before signaling that SetLocalDescription completed. |
| 1171 | session_->MaybeStartGathering(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | void PeerConnection::SetRemoteDescription( |
| 1175 | SetSessionDescriptionObserver* observer, |
| 1176 | SessionDescriptionInterface* desc) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 1177 | TRACE_EVENT0("webrtc", "PeerConnection::SetRemoteDescription"); |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 1178 | if (IsClosed()) { |
| 1179 | return; |
| 1180 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1181 | if (!VERIFY(observer != nullptr)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1182 | LOG(LS_ERROR) << "SetRemoteDescription - observer is NULL."; |
| 1183 | return; |
| 1184 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1185 | if (!desc) { |
| 1186 | PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL."); |
| 1187 | return; |
| 1188 | } |
| 1189 | // Update stats here so that we have the most recent stats for tracks and |
| 1190 | // streams that might be removed by updating the session description. |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 1191 | stats_->UpdateStats(kStatsOutputLevelStandard); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1192 | std::string error; |
| 1193 | if (!session_->SetRemoteDescription(desc, &error)) { |
| 1194 | PostSetSessionDescriptionFailure(observer, error); |
| 1195 | return; |
| 1196 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1197 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1198 | // If setting the description decided our SSL role, allocate any necessary |
| 1199 | // SCTP sids. |
| 1200 | rtc::SSLRole role; |
| 1201 | if (session_->data_channel_type() == cricket::DCT_SCTP && |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1202 | session_->GetSslRole(session_->data_channel(), &role)) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1203 | AllocateSctpSids(role); |
| 1204 | } |
| 1205 | |
| 1206 | const cricket::SessionDescription* remote_desc = desc->description(); |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 1207 | const cricket::ContentInfo* audio_content = GetFirstAudioContent(remote_desc); |
| 1208 | const cricket::ContentInfo* video_content = GetFirstVideoContent(remote_desc); |
| 1209 | const cricket::AudioContentDescription* audio_desc = |
| 1210 | GetFirstAudioContentDescription(remote_desc); |
| 1211 | const cricket::VideoContentDescription* video_desc = |
| 1212 | GetFirstVideoContentDescription(remote_desc); |
| 1213 | const cricket::DataContentDescription* data_desc = |
| 1214 | GetFirstDataContentDescription(remote_desc); |
| 1215 | |
| 1216 | // Check if the descriptions include streams, just in case the peer supports |
| 1217 | // MSID, but doesn't indicate so with "a=msid-semantic". |
| 1218 | if (remote_desc->msid_supported() || |
| 1219 | (audio_desc && !audio_desc->streams().empty()) || |
| 1220 | (video_desc && !video_desc->streams().empty())) { |
| 1221 | remote_peer_supports_msid_ = true; |
| 1222 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1223 | |
| 1224 | // We wait to signal new streams until we finish processing the description, |
| 1225 | // since only at that point will new streams have all their tracks. |
| 1226 | rtc::scoped_refptr<StreamCollection> new_streams(StreamCollection::Create()); |
| 1227 | |
| 1228 | // Find all audio rtp streams and create corresponding remote AudioTracks |
| 1229 | // and MediaStreams. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1230 | if (audio_content) { |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 1231 | if (audio_content->rejected) { |
| 1232 | RemoveTracks(cricket::MEDIA_TYPE_AUDIO); |
| 1233 | } else { |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 1234 | bool default_audio_track_needed = |
| 1235 | !remote_peer_supports_msid_ && |
| 1236 | MediaContentDirectionHasSend(audio_desc->direction()); |
| 1237 | UpdateRemoteStreamsList(GetActiveStreams(audio_desc), |
| 1238 | default_audio_track_needed, audio_desc->type(), |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 1239 | new_streams); |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 1240 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | // Find all video rtp streams and create corresponding remote VideoTracks |
| 1244 | // and MediaStreams. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1245 | if (video_content) { |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 1246 | if (video_content->rejected) { |
| 1247 | RemoveTracks(cricket::MEDIA_TYPE_VIDEO); |
| 1248 | } else { |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 1249 | bool default_video_track_needed = |
| 1250 | !remote_peer_supports_msid_ && |
| 1251 | MediaContentDirectionHasSend(video_desc->direction()); |
| 1252 | UpdateRemoteStreamsList(GetActiveStreams(video_desc), |
| 1253 | default_video_track_needed, video_desc->type(), |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 1254 | new_streams); |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 1255 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | // Update the DataChannels with the information from the remote peer. |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 1259 | if (data_desc) { |
| 1260 | if (rtc::starts_with(data_desc->protocol().data(), |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1261 | cricket::kMediaProtocolRtpPrefix)) { |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 1262 | UpdateRemoteRtpDataChannels(GetActiveStreams(data_desc)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1263 | } |
| 1264 | } |
| 1265 | |
| 1266 | // Iterate new_streams and notify the observer about new MediaStreams. |
| 1267 | for (size_t i = 0; i < new_streams->count(); ++i) { |
| 1268 | MediaStreamInterface* new_stream = new_streams->at(i); |
| 1269 | stats_->AddStream(new_stream); |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 1270 | // Call both the raw pointer and scoped_refptr versions of the method |
| 1271 | // for compatibility. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1272 | observer_->OnAddStream(new_stream); |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 1273 | observer_->OnAddStream( |
| 1274 | rtc::scoped_refptr<MediaStreamInterface>(new_stream)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 1277 | UpdateEndedRemoteMediaStreams(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1278 | |
| 1279 | SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 1280 | signaling_thread()->Post(RTC_FROM_HERE, this, |
| 1281 | MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); |
deadbeef | fc648b6 | 2015-10-13 16:42:33 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1284 | PeerConnectionInterface::RTCConfiguration PeerConnection::GetConfiguration() { |
| 1285 | return configuration_; |
| 1286 | } |
| 1287 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 1288 | bool PeerConnection::SetConfiguration(const RTCConfiguration& configuration) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 1289 | TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration"); |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1290 | // TODO(deadbeef): Return false and log an error if there are any unsupported |
| 1291 | // modifications. |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 1292 | if (port_allocator_) { |
deadbeef | 91dd567 | 2016-05-18 16:55:30 -0700 | [diff] [blame] | 1293 | if (!network_thread()->Invoke<bool>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 1294 | RTC_FROM_HERE, |
deadbeef | 91dd567 | 2016-05-18 16:55:30 -0700 | [diff] [blame] | 1295 | rtc::Bind(&PeerConnection::ReconfigurePortAllocator_n, this, |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 1296 | configuration))) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 1297 | return false; |
| 1298 | } |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 1299 | } |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 1300 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame^] | 1301 | // TODO(deadbeef): Shouldn't have to hop to the network thread twice... |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 1302 | session_->SetIceConfig(session_->ParseIceConfig(configuration)); |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 1303 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame^] | 1304 | // As described in JSEP, calling setConfiguration with new ICE servers or |
| 1305 | // candidate policy must set a "needs-ice-restart" bit so that the next offer |
| 1306 | // triggers an ICE restart which will pick up the changes. |
| 1307 | if (configuration.servers != configuration_.servers || |
| 1308 | configuration.type != configuration_.type) { |
| 1309 | session_->SetNeedsIceRestartFlag(); |
| 1310 | } |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1311 | configuration_ = configuration; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 1312 | return true; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1315 | bool PeerConnection::AddIceCandidate( |
| 1316 | const IceCandidateInterface* ice_candidate) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 1317 | TRACE_EVENT0("webrtc", "PeerConnection::AddIceCandidate"); |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 1318 | if (IsClosed()) { |
| 1319 | return false; |
| 1320 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1321 | return session_->ProcessIceMessage(ice_candidate); |
| 1322 | } |
| 1323 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 1324 | bool PeerConnection::RemoveIceCandidates( |
| 1325 | const std::vector<cricket::Candidate>& candidates) { |
| 1326 | TRACE_EVENT0("webrtc", "PeerConnection::RemoveIceCandidates"); |
| 1327 | return session_->RemoveRemoteIceCandidates(candidates); |
| 1328 | } |
| 1329 | |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 1330 | void PeerConnection::RegisterUMAObserver(UMAObserver* observer) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 1331 | TRACE_EVENT0("webrtc", "PeerConnection::RegisterUmaObserver"); |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 1332 | uma_observer_ = observer; |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1333 | |
| 1334 | if (session_) { |
| 1335 | session_->set_metrics_observer(uma_observer_); |
| 1336 | } |
| 1337 | |
mallinath@webrtc.org | d37bcfa | 2014-05-12 23:10:18 +0000 | [diff] [blame] | 1338 | // Send information about IPv4/IPv6 status. |
| 1339 | if (uma_observer_ && port_allocator_) { |
Honghai Zhang | d93f50c | 2016-10-05 11:47:22 -0700 | [diff] [blame] | 1340 | port_allocator_->SetMetricsObserver(uma_observer_); |
mallinath@webrtc.org | d37bcfa | 2014-05-12 23:10:18 +0000 | [diff] [blame] | 1341 | if (port_allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6) { |
Guo-wei Shieh | dfbe679 | 2015-09-03 17:12:07 -0700 | [diff] [blame] | 1342 | uma_observer_->IncrementEnumCounter( |
| 1343 | kEnumCounterAddressFamily, kPeerConnection_IPv6, |
| 1344 | kPeerConnectionAddressFamilyCounter_Max); |
mallinath@webrtc.org | b445f26 | 2014-05-23 22:19:37 +0000 | [diff] [blame] | 1345 | } else { |
Guo-wei Shieh | dfbe679 | 2015-09-03 17:12:07 -0700 | [diff] [blame] | 1346 | uma_observer_->IncrementEnumCounter( |
| 1347 | kEnumCounterAddressFamily, kPeerConnection_IPv4, |
| 1348 | kPeerConnectionAddressFamilyCounter_Max); |
mallinath@webrtc.org | d37bcfa | 2014-05-12 23:10:18 +0000 | [diff] [blame] | 1349 | } |
| 1350 | } |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 1351 | } |
| 1352 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 1353 | bool PeerConnection::StartRtcEventLog(rtc::PlatformFile file, |
| 1354 | int64_t max_size_bytes) { |
| 1355 | return factory_->worker_thread()->Invoke<bool>( |
| 1356 | RTC_FROM_HERE, rtc::Bind(&PeerConnection::StartRtcEventLog_w, this, file, |
| 1357 | max_size_bytes)); |
| 1358 | } |
| 1359 | |
| 1360 | void PeerConnection::StopRtcEventLog() { |
| 1361 | factory_->worker_thread()->Invoke<void>( |
| 1362 | RTC_FROM_HERE, rtc::Bind(&PeerConnection::StopRtcEventLog_w, this)); |
| 1363 | } |
| 1364 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1365 | const SessionDescriptionInterface* PeerConnection::local_description() const { |
| 1366 | return session_->local_description(); |
| 1367 | } |
| 1368 | |
| 1369 | const SessionDescriptionInterface* PeerConnection::remote_description() const { |
| 1370 | return session_->remote_description(); |
| 1371 | } |
| 1372 | |
| 1373 | void PeerConnection::Close() { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 1374 | TRACE_EVENT0("webrtc", "PeerConnection::Close"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1375 | // Update stats here so that we have the most recent stats for tracks and |
| 1376 | // streams before the channels are closed. |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 1377 | stats_->UpdateStats(kStatsOutputLevelStandard); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1378 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1379 | session_->Close(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1380 | } |
| 1381 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1382 | void PeerConnection::OnSessionStateChange(WebRtcSession* /*session*/, |
| 1383 | WebRtcSession::State state) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1384 | switch (state) { |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1385 | case WebRtcSession::STATE_INIT: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1386 | ChangeSignalingState(PeerConnectionInterface::kStable); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1387 | break; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1388 | case WebRtcSession::STATE_SENTOFFER: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1389 | ChangeSignalingState(PeerConnectionInterface::kHaveLocalOffer); |
| 1390 | break; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1391 | case WebRtcSession::STATE_SENTPRANSWER: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1392 | ChangeSignalingState(PeerConnectionInterface::kHaveLocalPrAnswer); |
| 1393 | break; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1394 | case WebRtcSession::STATE_RECEIVEDOFFER: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1395 | ChangeSignalingState(PeerConnectionInterface::kHaveRemoteOffer); |
| 1396 | break; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1397 | case WebRtcSession::STATE_RECEIVEDPRANSWER: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1398 | ChangeSignalingState(PeerConnectionInterface::kHaveRemotePrAnswer); |
| 1399 | break; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1400 | case WebRtcSession::STATE_INPROGRESS: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1401 | ChangeSignalingState(PeerConnectionInterface::kStable); |
| 1402 | break; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1403 | case WebRtcSession::STATE_CLOSED: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1404 | ChangeSignalingState(PeerConnectionInterface::kClosed); |
| 1405 | break; |
| 1406 | default: |
| 1407 | break; |
| 1408 | } |
| 1409 | } |
| 1410 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1411 | void PeerConnection::OnMessage(rtc::Message* msg) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1412 | switch (msg->message_id) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1413 | case MSG_SET_SESSIONDESCRIPTION_SUCCESS: { |
| 1414 | SetSessionDescriptionMsg* param = |
| 1415 | static_cast<SetSessionDescriptionMsg*>(msg->pdata); |
| 1416 | param->observer->OnSuccess(); |
| 1417 | delete param; |
| 1418 | break; |
| 1419 | } |
| 1420 | case MSG_SET_SESSIONDESCRIPTION_FAILED: { |
| 1421 | SetSessionDescriptionMsg* param = |
| 1422 | static_cast<SetSessionDescriptionMsg*>(msg->pdata); |
| 1423 | param->observer->OnFailure(param->error); |
| 1424 | delete param; |
| 1425 | break; |
| 1426 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1427 | case MSG_CREATE_SESSIONDESCRIPTION_FAILED: { |
| 1428 | CreateSessionDescriptionMsg* param = |
| 1429 | static_cast<CreateSessionDescriptionMsg*>(msg->pdata); |
| 1430 | param->observer->OnFailure(param->error); |
| 1431 | delete param; |
| 1432 | break; |
| 1433 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1434 | case MSG_GETSTATS: { |
| 1435 | GetStatsMsg* param = static_cast<GetStatsMsg*>(msg->pdata); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 1436 | StatsReports reports; |
| 1437 | stats_->GetStats(param->track, &reports); |
| 1438 | param->observer->OnComplete(reports); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1439 | delete param; |
| 1440 | break; |
| 1441 | } |
deadbeef | bd29246 | 2015-12-14 18:15:29 -0800 | [diff] [blame] | 1442 | case MSG_FREE_DATACHANNELS: { |
| 1443 | sctp_data_channels_to_free_.clear(); |
| 1444 | break; |
| 1445 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1446 | default: |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 1447 | RTC_DCHECK(false && "Not implemented"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1448 | break; |
| 1449 | } |
| 1450 | } |
| 1451 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1452 | void PeerConnection::CreateAudioReceiver(MediaStreamInterface* stream, |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 1453 | const std::string& track_id, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1454 | uint32_t ssrc) { |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 1455 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>> |
| 1456 | receiver = RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create( |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 1457 | signaling_thread(), new AudioRtpReceiver(stream, track_id, ssrc, |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 1458 | session_->voice_channel())); |
| 1459 | |
| 1460 | receivers_.push_back(receiver); |
| 1461 | std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams; |
| 1462 | streams.push_back(rtc::scoped_refptr<MediaStreamInterface>(stream)); |
| 1463 | observer_->OnAddTrack(receiver, streams); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1466 | void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream, |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame] | 1467 | const std::string& track_id, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1468 | uint32_t ssrc) { |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 1469 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>> |
| 1470 | receiver = RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create( |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 1471 | signaling_thread(), |
| 1472 | new VideoRtpReceiver(stream, track_id, factory_->worker_thread(), |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 1473 | ssrc, session_->video_channel())); |
| 1474 | receivers_.push_back(receiver); |
| 1475 | std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams; |
| 1476 | streams.push_back(rtc::scoped_refptr<MediaStreamInterface>(stream)); |
| 1477 | observer_->OnAddTrack(receiver, streams); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1478 | } |
| 1479 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 1480 | // TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote |
| 1481 | // description. |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 1482 | void PeerConnection::DestroyReceiver(const std::string& track_id) { |
| 1483 | auto it = FindReceiverForTrack(track_id); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 1484 | if (it == receivers_.end()) { |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 1485 | LOG(LS_WARNING) << "RtpReceiver for track with id " << track_id |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 1486 | << " doesn't exist."; |
| 1487 | } else { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 1488 | (*it)->internal()->Stop(); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 1489 | receivers_.erase(it); |
| 1490 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1493 | void PeerConnection::OnIceConnectionChange( |
| 1494 | PeerConnectionInterface::IceConnectionState new_state) { |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 1495 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1496 | // After transitioning to "closed", ignore any additional states from |
| 1497 | // WebRtcSession (such as "disconnected"). |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1498 | if (IsClosed()) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1499 | return; |
| 1500 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1501 | ice_connection_state_ = new_state; |
mallinath@webrtc.org | d3dc424 | 2014-03-01 00:05:52 +0000 | [diff] [blame] | 1502 | observer_->OnIceConnectionChange(ice_connection_state_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | void PeerConnection::OnIceGatheringChange( |
| 1506 | PeerConnectionInterface::IceGatheringState new_state) { |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 1507 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1508 | if (IsClosed()) { |
| 1509 | return; |
| 1510 | } |
| 1511 | ice_gathering_state_ = new_state; |
mallinath@webrtc.org | d3dc424 | 2014-03-01 00:05:52 +0000 | [diff] [blame] | 1512 | observer_->OnIceGatheringChange(ice_gathering_state_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | void PeerConnection::OnIceCandidate(const IceCandidateInterface* candidate) { |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 1516 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 1517 | if (IsClosed()) { |
| 1518 | return; |
| 1519 | } |
mallinath@webrtc.org | d3dc424 | 2014-03-01 00:05:52 +0000 | [diff] [blame] | 1520 | observer_->OnIceCandidate(candidate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1521 | } |
| 1522 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 1523 | void PeerConnection::OnIceCandidatesRemoved( |
| 1524 | const std::vector<cricket::Candidate>& candidates) { |
| 1525 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 1526 | if (IsClosed()) { |
| 1527 | return; |
| 1528 | } |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 1529 | observer_->OnIceCandidatesRemoved(candidates); |
| 1530 | } |
| 1531 | |
Peter Thatcher | 5436051 | 2015-07-08 11:08:35 -0700 | [diff] [blame] | 1532 | void PeerConnection::OnIceConnectionReceivingChange(bool receiving) { |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 1533 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 1534 | if (IsClosed()) { |
| 1535 | return; |
| 1536 | } |
Peter Thatcher | 5436051 | 2015-07-08 11:08:35 -0700 | [diff] [blame] | 1537 | observer_->OnIceConnectionReceivingChange(receiving); |
| 1538 | } |
| 1539 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1540 | void PeerConnection::ChangeSignalingState( |
| 1541 | PeerConnectionInterface::SignalingState signaling_state) { |
| 1542 | signaling_state_ = signaling_state; |
| 1543 | if (signaling_state == kClosed) { |
| 1544 | ice_connection_state_ = kIceConnectionClosed; |
| 1545 | observer_->OnIceConnectionChange(ice_connection_state_); |
| 1546 | if (ice_gathering_state_ != kIceGatheringComplete) { |
| 1547 | ice_gathering_state_ = kIceGatheringComplete; |
| 1548 | observer_->OnIceGatheringChange(ice_gathering_state_); |
| 1549 | } |
| 1550 | } |
| 1551 | observer_->OnSignalingChange(signaling_state_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1554 | void PeerConnection::OnAudioTrackAdded(AudioTrackInterface* track, |
| 1555 | MediaStreamInterface* stream) { |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 1556 | if (IsClosed()) { |
| 1557 | return; |
| 1558 | } |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1559 | auto sender = FindSenderForTrack(track); |
| 1560 | if (sender != senders_.end()) { |
| 1561 | // We already have a sender for this track, so just change the stream_id |
| 1562 | // so that it's correct in the next call to CreateOffer. |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 1563 | (*sender)->internal()->set_stream_id(stream->label()); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1564 | return; |
| 1565 | } |
| 1566 | |
| 1567 | // Normal case; we've never seen this track before. |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 1568 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> new_sender = |
| 1569 | RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 1570 | signaling_thread(), |
| 1571 | new AudioRtpSender(track, stream->label(), session_->voice_channel(), |
| 1572 | stats_.get())); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1573 | senders_.push_back(new_sender); |
| 1574 | // If the sender has already been configured in SDP, we call SetSsrc, |
| 1575 | // which will connect the sender to the underlying transport. This can |
| 1576 | // occur if a local session description that contains the ID of the sender |
| 1577 | // is set before AddStream is called. It can also occur if the local |
| 1578 | // session description is not changed and RemoveStream is called, and |
| 1579 | // later AddStream is called again with the same stream. |
| 1580 | const TrackInfo* track_info = |
| 1581 | FindTrackInfo(local_audio_tracks_, stream->label(), track->id()); |
| 1582 | if (track_info) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 1583 | new_sender->internal()->SetSsrc(track_info->ssrc); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1584 | } |
| 1585 | } |
| 1586 | |
| 1587 | // TODO(deadbeef): Don't destroy RtpSenders here; they should be kept around |
| 1588 | // indefinitely, when we have unified plan SDP. |
| 1589 | void PeerConnection::OnAudioTrackRemoved(AudioTrackInterface* track, |
| 1590 | MediaStreamInterface* stream) { |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 1591 | if (IsClosed()) { |
| 1592 | return; |
| 1593 | } |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1594 | auto sender = FindSenderForTrack(track); |
| 1595 | if (sender == senders_.end()) { |
| 1596 | LOG(LS_WARNING) << "RtpSender for track with id " << track->id() |
| 1597 | << " doesn't exist."; |
| 1598 | return; |
| 1599 | } |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 1600 | (*sender)->internal()->Stop(); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1601 | senders_.erase(sender); |
| 1602 | } |
| 1603 | |
| 1604 | void PeerConnection::OnVideoTrackAdded(VideoTrackInterface* track, |
| 1605 | MediaStreamInterface* stream) { |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 1606 | if (IsClosed()) { |
| 1607 | return; |
| 1608 | } |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1609 | auto sender = FindSenderForTrack(track); |
| 1610 | if (sender != senders_.end()) { |
| 1611 | // We already have a sender for this track, so just change the stream_id |
| 1612 | // so that it's correct in the next call to CreateOffer. |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 1613 | (*sender)->internal()->set_stream_id(stream->label()); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1614 | return; |
| 1615 | } |
| 1616 | |
| 1617 | // Normal case; we've never seen this track before. |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 1618 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> new_sender = |
| 1619 | RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 1620 | signaling_thread(), new VideoRtpSender(track, stream->label(), |
| 1621 | session_->video_channel())); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1622 | senders_.push_back(new_sender); |
| 1623 | const TrackInfo* track_info = |
| 1624 | FindTrackInfo(local_video_tracks_, stream->label(), track->id()); |
| 1625 | if (track_info) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 1626 | new_sender->internal()->SetSsrc(track_info->ssrc); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | void PeerConnection::OnVideoTrackRemoved(VideoTrackInterface* track, |
| 1631 | MediaStreamInterface* stream) { |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 1632 | if (IsClosed()) { |
| 1633 | return; |
| 1634 | } |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1635 | auto sender = FindSenderForTrack(track); |
| 1636 | if (sender == senders_.end()) { |
| 1637 | LOG(LS_WARNING) << "RtpSender for track with id " << track->id() |
| 1638 | << " doesn't exist."; |
| 1639 | return; |
| 1640 | } |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 1641 | (*sender)->internal()->Stop(); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1642 | senders_.erase(sender); |
| 1643 | } |
| 1644 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1645 | void PeerConnection::PostSetSessionDescriptionFailure( |
| 1646 | SetSessionDescriptionObserver* observer, |
| 1647 | const std::string& error) { |
| 1648 | SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); |
| 1649 | msg->error = error; |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 1650 | signaling_thread()->Post(RTC_FROM_HERE, this, |
| 1651 | MSG_SET_SESSIONDESCRIPTION_FAILED, msg); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | void PeerConnection::PostCreateSessionDescriptionFailure( |
| 1655 | CreateSessionDescriptionObserver* observer, |
| 1656 | const std::string& error) { |
| 1657 | CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); |
| 1658 | msg->error = error; |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 1659 | signaling_thread()->Post(RTC_FROM_HERE, this, |
| 1660 | MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | bool PeerConnection::GetOptionsForOffer( |
| 1664 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 1665 | cricket::MediaSessionOptions* session_options) { |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 1666 | // TODO(deadbeef): Once we have transceivers, enumerate them here instead of |
| 1667 | // ContentInfos. |
| 1668 | if (session_->local_description()) { |
| 1669 | for (const cricket::ContentInfo& content : |
| 1670 | session_->local_description()->description()->contents()) { |
| 1671 | session_options->transport_options[content.name] = |
| 1672 | cricket::TransportOptions(); |
| 1673 | } |
| 1674 | } |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1675 | session_options->enable_ice_renomination = |
| 1676 | configuration_.enable_ice_renomination; |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 1677 | |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 1678 | if (!ExtractMediaSessionOptions(rtc_options, true, session_options)) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1679 | return false; |
| 1680 | } |
| 1681 | |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 1682 | AddSendStreams(session_options, senders_, rtp_data_channels_); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1683 | // Offer to receive audio/video if the constraint is not set and there are |
| 1684 | // send streams, or we're currently receiving. |
| 1685 | if (rtc_options.offer_to_receive_audio == RTCOfferAnswerOptions::kUndefined) { |
| 1686 | session_options->recv_audio = |
| 1687 | session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO) || |
| 1688 | !remote_audio_tracks_.empty(); |
| 1689 | } |
| 1690 | if (rtc_options.offer_to_receive_video == RTCOfferAnswerOptions::kUndefined) { |
| 1691 | session_options->recv_video = |
| 1692 | session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO) || |
| 1693 | !remote_video_tracks_.empty(); |
| 1694 | } |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1695 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1696 | // Intentionally unset the data channel type for RTP data channel with the |
| 1697 | // second condition. Otherwise the RTP data channels would be successfully |
| 1698 | // negotiated by default and the unit tests in WebRtcDataBrowserTest will fail |
| 1699 | // when building with chromium. We want to leave RTP data channels broken, so |
| 1700 | // people won't try to use them. |
| 1701 | if (HasDataChannels() && session_->data_channel_type() != cricket::DCT_RTP) { |
| 1702 | session_options->data_channel_type = session_->data_channel_type(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1703 | } |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1704 | |
zhihuang | af38847 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 1705 | session_options->bundle_enabled = |
| 1706 | session_options->bundle_enabled && |
| 1707 | (session_options->has_audio() || session_options->has_video() || |
| 1708 | session_options->has_data()); |
| 1709 | |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1710 | session_options->rtcp_cname = rtcp_cname_; |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1711 | session_options->crypto_options = factory_->options().crypto_options; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1712 | return true; |
| 1713 | } |
| 1714 | |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 1715 | void PeerConnection::InitializeOptionsForAnswer( |
| 1716 | cricket::MediaSessionOptions* session_options) { |
| 1717 | session_options->recv_audio = false; |
| 1718 | session_options->recv_video = false; |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1719 | session_options->enable_ice_renomination = |
| 1720 | configuration_.enable_ice_renomination; |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1723 | void PeerConnection::FinishOptionsForAnswer( |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1724 | cricket::MediaSessionOptions* session_options) { |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 1725 | // TODO(deadbeef): Once we have transceivers, enumerate them here instead of |
| 1726 | // ContentInfos. |
| 1727 | if (session_->remote_description()) { |
| 1728 | // Initialize the transport_options map. |
| 1729 | for (const cricket::ContentInfo& content : |
| 1730 | session_->remote_description()->description()->contents()) { |
| 1731 | session_options->transport_options[content.name] = |
| 1732 | cricket::TransportOptions(); |
| 1733 | } |
| 1734 | } |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 1735 | AddSendStreams(session_options, senders_, rtp_data_channels_); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1736 | // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams |
| 1737 | // are not signaled in the SDP so does not go through that path and must be |
| 1738 | // handled here. |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1739 | // Intentionally unset the data channel type for RTP data channel. Otherwise |
| 1740 | // the RTP data channels would be successfully negotiated by default and the |
| 1741 | // unit tests in WebRtcDataBrowserTest will fail when building with chromium. |
| 1742 | // We want to leave RTP data channels broken, so people won't try to use them. |
| 1743 | if (session_->data_channel_type() != cricket::DCT_RTP) { |
| 1744 | session_options->data_channel_type = session_->data_channel_type(); |
deadbeef | 907abe4 | 2016-08-04 12:22:18 -0700 | [diff] [blame] | 1745 | } |
zhihuang | af38847 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 1746 | session_options->bundle_enabled = |
| 1747 | session_options->bundle_enabled && |
| 1748 | (session_options->has_audio() || session_options->has_video() || |
| 1749 | session_options->has_data()); |
| 1750 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1751 | session_options->crypto_options = factory_->options().crypto_options; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | bool PeerConnection::GetOptionsForAnswer( |
| 1755 | const MediaConstraintsInterface* constraints, |
| 1756 | cricket::MediaSessionOptions* session_options) { |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 1757 | InitializeOptionsForAnswer(session_options); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1758 | if (!ParseConstraintsForAnswer(constraints, session_options)) { |
| 1759 | return false; |
| 1760 | } |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1761 | session_options->rtcp_cname = rtcp_cname_; |
| 1762 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1763 | FinishOptionsForAnswer(session_options); |
| 1764 | return true; |
| 1765 | } |
| 1766 | |
| 1767 | bool PeerConnection::GetOptionsForAnswer( |
| 1768 | const RTCOfferAnswerOptions& options, |
| 1769 | cricket::MediaSessionOptions* session_options) { |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 1770 | InitializeOptionsForAnswer(session_options); |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 1771 | if (!ExtractMediaSessionOptions(options, false, session_options)) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1772 | return false; |
| 1773 | } |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1774 | session_options->rtcp_cname = rtcp_cname_; |
| 1775 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1776 | FinishOptionsForAnswer(session_options); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1777 | return true; |
| 1778 | } |
| 1779 | |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 1780 | void PeerConnection::RemoveTracks(cricket::MediaType media_type) { |
| 1781 | UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 1782 | UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false, |
| 1783 | media_type, nullptr); |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 1784 | } |
| 1785 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1786 | void PeerConnection::UpdateRemoteStreamsList( |
| 1787 | const cricket::StreamParamsVec& streams, |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 1788 | bool default_track_needed, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1789 | cricket::MediaType media_type, |
| 1790 | StreamCollection* new_streams) { |
| 1791 | TrackInfos* current_tracks = GetRemoteTracks(media_type); |
| 1792 | |
| 1793 | // Find removed tracks. I.e., tracks where the track id or ssrc don't match |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 1794 | // the new StreamParam. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1795 | auto track_it = current_tracks->begin(); |
| 1796 | while (track_it != current_tracks->end()) { |
| 1797 | const TrackInfo& info = *track_it; |
| 1798 | const cricket::StreamParams* params = |
| 1799 | cricket::GetStreamBySsrc(streams, info.ssrc); |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 1800 | bool track_exists = params && params->id == info.track_id; |
| 1801 | // If this is a default track, and we still need it, don't remove it. |
| 1802 | if ((info.stream_label == kDefaultStreamLabel && default_track_needed) || |
| 1803 | track_exists) { |
| 1804 | ++track_it; |
| 1805 | } else { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1806 | OnRemoteTrackRemoved(info.stream_label, info.track_id, media_type); |
| 1807 | track_it = current_tracks->erase(track_it); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1808 | } |
| 1809 | } |
| 1810 | |
| 1811 | // Find new and active tracks. |
| 1812 | for (const cricket::StreamParams& params : streams) { |
| 1813 | // The sync_label is the MediaStream label and the |stream.id| is the |
| 1814 | // track id. |
| 1815 | const std::string& stream_label = params.sync_label; |
| 1816 | const std::string& track_id = params.id; |
| 1817 | uint32_t ssrc = params.first_ssrc(); |
| 1818 | |
| 1819 | rtc::scoped_refptr<MediaStreamInterface> stream = |
| 1820 | remote_streams_->find(stream_label); |
| 1821 | if (!stream) { |
| 1822 | // This is a new MediaStream. Create a new remote MediaStream. |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 1823 | stream = MediaStreamProxy::Create(rtc::Thread::Current(), |
| 1824 | MediaStream::Create(stream_label)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1825 | remote_streams_->AddStream(stream); |
| 1826 | new_streams->AddStream(stream); |
| 1827 | } |
| 1828 | |
| 1829 | const TrackInfo* track_info = |
| 1830 | FindTrackInfo(*current_tracks, stream_label, track_id); |
| 1831 | if (!track_info) { |
| 1832 | current_tracks->push_back(TrackInfo(stream_label, track_id, ssrc)); |
| 1833 | OnRemoteTrackSeen(stream_label, track_id, ssrc, media_type); |
| 1834 | } |
| 1835 | } |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 1836 | |
| 1837 | // Add default track if necessary. |
| 1838 | if (default_track_needed) { |
| 1839 | rtc::scoped_refptr<MediaStreamInterface> default_stream = |
| 1840 | remote_streams_->find(kDefaultStreamLabel); |
| 1841 | if (!default_stream) { |
| 1842 | // Create the new default MediaStream. |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 1843 | default_stream = MediaStreamProxy::Create( |
| 1844 | rtc::Thread::Current(), MediaStream::Create(kDefaultStreamLabel)); |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 1845 | remote_streams_->AddStream(default_stream); |
| 1846 | new_streams->AddStream(default_stream); |
| 1847 | } |
| 1848 | std::string default_track_id = (media_type == cricket::MEDIA_TYPE_AUDIO) |
| 1849 | ? kDefaultAudioTrackLabel |
| 1850 | : kDefaultVideoTrackLabel; |
| 1851 | const TrackInfo* default_track_info = |
| 1852 | FindTrackInfo(*current_tracks, kDefaultStreamLabel, default_track_id); |
| 1853 | if (!default_track_info) { |
| 1854 | current_tracks->push_back( |
| 1855 | TrackInfo(kDefaultStreamLabel, default_track_id, 0)); |
| 1856 | OnRemoteTrackSeen(kDefaultStreamLabel, default_track_id, 0, media_type); |
| 1857 | } |
| 1858 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | void PeerConnection::OnRemoteTrackSeen(const std::string& stream_label, |
| 1862 | const std::string& track_id, |
| 1863 | uint32_t ssrc, |
| 1864 | cricket::MediaType media_type) { |
| 1865 | MediaStreamInterface* stream = remote_streams_->find(stream_label); |
| 1866 | |
| 1867 | if (media_type == cricket::MEDIA_TYPE_AUDIO) { |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 1868 | CreateAudioReceiver(stream, track_id, ssrc); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1869 | } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame] | 1870 | CreateVideoReceiver(stream, track_id, ssrc); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1871 | } else { |
| 1872 | RTC_DCHECK(false && "Invalid media type"); |
| 1873 | } |
| 1874 | } |
| 1875 | |
| 1876 | void PeerConnection::OnRemoteTrackRemoved(const std::string& stream_label, |
| 1877 | const std::string& track_id, |
| 1878 | cricket::MediaType media_type) { |
| 1879 | MediaStreamInterface* stream = remote_streams_->find(stream_label); |
| 1880 | |
| 1881 | if (media_type == cricket::MEDIA_TYPE_AUDIO) { |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 1882 | // When the MediaEngine audio channel is destroyed, the RemoteAudioSource |
| 1883 | // will be notified which will end the AudioRtpReceiver::track(). |
| 1884 | DestroyReceiver(track_id); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1885 | rtc::scoped_refptr<AudioTrackInterface> audio_track = |
| 1886 | stream->FindAudioTrack(track_id); |
| 1887 | if (audio_track) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1888 | stream->RemoveTrack(audio_track); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1889 | } |
| 1890 | } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 1891 | // Stopping or destroying a VideoRtpReceiver will end the |
| 1892 | // VideoRtpReceiver::track(). |
| 1893 | DestroyReceiver(track_id); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1894 | rtc::scoped_refptr<VideoTrackInterface> video_track = |
| 1895 | stream->FindVideoTrack(track_id); |
| 1896 | if (video_track) { |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 1897 | // There's no guarantee the track is still available, e.g. the track may |
| 1898 | // have been removed from the stream by an application. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1899 | stream->RemoveTrack(video_track); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1900 | } |
| 1901 | } else { |
| 1902 | ASSERT(false && "Invalid media type"); |
| 1903 | } |
| 1904 | } |
| 1905 | |
| 1906 | void PeerConnection::UpdateEndedRemoteMediaStreams() { |
| 1907 | std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams_to_remove; |
| 1908 | for (size_t i = 0; i < remote_streams_->count(); ++i) { |
| 1909 | MediaStreamInterface* stream = remote_streams_->at(i); |
| 1910 | if (stream->GetAudioTracks().empty() && stream->GetVideoTracks().empty()) { |
| 1911 | streams_to_remove.push_back(stream); |
| 1912 | } |
| 1913 | } |
| 1914 | |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 1915 | for (auto& stream : streams_to_remove) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1916 | remote_streams_->RemoveStream(stream); |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 1917 | // Call both the raw pointer and scoped_refptr versions of the method |
| 1918 | // for compatibility. |
| 1919 | observer_->OnRemoveStream(stream.get()); |
| 1920 | observer_->OnRemoveStream(std::move(stream)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1921 | } |
| 1922 | } |
| 1923 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1924 | void PeerConnection::UpdateLocalTracks( |
| 1925 | const std::vector<cricket::StreamParams>& streams, |
| 1926 | cricket::MediaType media_type) { |
| 1927 | TrackInfos* current_tracks = GetLocalTracks(media_type); |
| 1928 | |
| 1929 | // Find removed tracks. I.e., tracks where the track id, stream label or ssrc |
| 1930 | // don't match the new StreamParam. |
| 1931 | TrackInfos::iterator track_it = current_tracks->begin(); |
| 1932 | while (track_it != current_tracks->end()) { |
| 1933 | const TrackInfo& info = *track_it; |
| 1934 | const cricket::StreamParams* params = |
| 1935 | cricket::GetStreamBySsrc(streams, info.ssrc); |
| 1936 | if (!params || params->id != info.track_id || |
| 1937 | params->sync_label != info.stream_label) { |
| 1938 | OnLocalTrackRemoved(info.stream_label, info.track_id, info.ssrc, |
| 1939 | media_type); |
| 1940 | track_it = current_tracks->erase(track_it); |
| 1941 | } else { |
| 1942 | ++track_it; |
| 1943 | } |
| 1944 | } |
| 1945 | |
| 1946 | // Find new and active tracks. |
| 1947 | for (const cricket::StreamParams& params : streams) { |
| 1948 | // The sync_label is the MediaStream label and the |stream.id| is the |
| 1949 | // track id. |
| 1950 | const std::string& stream_label = params.sync_label; |
| 1951 | const std::string& track_id = params.id; |
| 1952 | uint32_t ssrc = params.first_ssrc(); |
| 1953 | const TrackInfo* track_info = |
| 1954 | FindTrackInfo(*current_tracks, stream_label, track_id); |
| 1955 | if (!track_info) { |
| 1956 | current_tracks->push_back(TrackInfo(stream_label, track_id, ssrc)); |
| 1957 | OnLocalTrackSeen(stream_label, track_id, params.first_ssrc(), media_type); |
| 1958 | } |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | void PeerConnection::OnLocalTrackSeen(const std::string& stream_label, |
| 1963 | const std::string& track_id, |
| 1964 | uint32_t ssrc, |
| 1965 | cricket::MediaType media_type) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 1966 | RtpSenderInternal* sender = FindSenderById(track_id); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 1967 | if (!sender) { |
| 1968 | LOG(LS_WARNING) << "An unknown RtpSender with id " << track_id |
| 1969 | << " has been configured in the local description."; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1970 | return; |
| 1971 | } |
| 1972 | |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 1973 | if (sender->media_type() != media_type) { |
| 1974 | LOG(LS_WARNING) << "An RtpSender has been configured in the local" |
| 1975 | << " description with an unexpected media type."; |
| 1976 | return; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1977 | } |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 1978 | |
| 1979 | sender->set_stream_id(stream_label); |
| 1980 | sender->SetSsrc(ssrc); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | void PeerConnection::OnLocalTrackRemoved(const std::string& stream_label, |
| 1984 | const std::string& track_id, |
| 1985 | uint32_t ssrc, |
| 1986 | cricket::MediaType media_type) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 1987 | RtpSenderInternal* sender = FindSenderById(track_id); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 1988 | if (!sender) { |
| 1989 | // This is the normal case. I.e., RemoveStream has been called and the |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1990 | // SessionDescriptions has been renegotiated. |
| 1991 | return; |
| 1992 | } |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 1993 | |
| 1994 | // A sender has been removed from the SessionDescription but it's still |
| 1995 | // associated with the PeerConnection. This only occurs if the SDP doesn't |
| 1996 | // match with the calls to CreateSender, AddStream and RemoveStream. |
| 1997 | if (sender->media_type() != media_type) { |
| 1998 | LOG(LS_WARNING) << "An RtpSender has been configured in the local" |
| 1999 | << " description with an unexpected media type."; |
| 2000 | return; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2001 | } |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 2002 | |
| 2003 | sender->SetSsrc(0); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | void PeerConnection::UpdateLocalRtpDataChannels( |
| 2007 | const cricket::StreamParamsVec& streams) { |
| 2008 | std::vector<std::string> existing_channels; |
| 2009 | |
| 2010 | // Find new and active data channels. |
| 2011 | for (const cricket::StreamParams& params : streams) { |
| 2012 | // |it->sync_label| is actually the data channel label. The reason is that |
| 2013 | // we use the same naming of data channels as we do for |
| 2014 | // MediaStreams and Tracks. |
| 2015 | // For MediaStreams, the sync_label is the MediaStream label and the |
| 2016 | // track label is the same as |streamid|. |
| 2017 | const std::string& channel_label = params.sync_label; |
| 2018 | auto data_channel_it = rtp_data_channels_.find(channel_label); |
| 2019 | if (!VERIFY(data_channel_it != rtp_data_channels_.end())) { |
| 2020 | continue; |
| 2021 | } |
| 2022 | // Set the SSRC the data channel should use for sending. |
| 2023 | data_channel_it->second->SetSendSsrc(params.first_ssrc()); |
| 2024 | existing_channels.push_back(data_channel_it->first); |
| 2025 | } |
| 2026 | |
| 2027 | UpdateClosingRtpDataChannels(existing_channels, true); |
| 2028 | } |
| 2029 | |
| 2030 | void PeerConnection::UpdateRemoteRtpDataChannels( |
| 2031 | const cricket::StreamParamsVec& streams) { |
| 2032 | std::vector<std::string> existing_channels; |
| 2033 | |
| 2034 | // Find new and active data channels. |
| 2035 | for (const cricket::StreamParams& params : streams) { |
| 2036 | // The data channel label is either the mslabel or the SSRC if the mslabel |
| 2037 | // does not exist. Ex a=ssrc:444330170 mslabel:test1. |
| 2038 | std::string label = params.sync_label.empty() |
| 2039 | ? rtc::ToString(params.first_ssrc()) |
| 2040 | : params.sync_label; |
| 2041 | auto data_channel_it = rtp_data_channels_.find(label); |
| 2042 | if (data_channel_it == rtp_data_channels_.end()) { |
| 2043 | // This is a new data channel. |
| 2044 | CreateRemoteRtpDataChannel(label, params.first_ssrc()); |
| 2045 | } else { |
| 2046 | data_channel_it->second->SetReceiveSsrc(params.first_ssrc()); |
| 2047 | } |
| 2048 | existing_channels.push_back(label); |
| 2049 | } |
| 2050 | |
| 2051 | UpdateClosingRtpDataChannels(existing_channels, false); |
| 2052 | } |
| 2053 | |
| 2054 | void PeerConnection::UpdateClosingRtpDataChannels( |
| 2055 | const std::vector<std::string>& active_channels, |
| 2056 | bool is_local_update) { |
| 2057 | auto it = rtp_data_channels_.begin(); |
| 2058 | while (it != rtp_data_channels_.end()) { |
| 2059 | DataChannel* data_channel = it->second; |
| 2060 | if (std::find(active_channels.begin(), active_channels.end(), |
| 2061 | data_channel->label()) != active_channels.end()) { |
| 2062 | ++it; |
| 2063 | continue; |
| 2064 | } |
| 2065 | |
| 2066 | if (is_local_update) { |
| 2067 | data_channel->SetSendSsrc(0); |
| 2068 | } else { |
| 2069 | data_channel->RemotePeerRequestClose(); |
| 2070 | } |
| 2071 | |
| 2072 | if (data_channel->state() == DataChannel::kClosed) { |
| 2073 | rtp_data_channels_.erase(it); |
| 2074 | it = rtp_data_channels_.begin(); |
| 2075 | } else { |
| 2076 | ++it; |
| 2077 | } |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | void PeerConnection::CreateRemoteRtpDataChannel(const std::string& label, |
| 2082 | uint32_t remote_ssrc) { |
| 2083 | rtc::scoped_refptr<DataChannel> channel( |
| 2084 | InternalCreateDataChannel(label, nullptr)); |
| 2085 | if (!channel.get()) { |
| 2086 | LOG(LS_WARNING) << "Remote peer requested a DataChannel but" |
| 2087 | << "CreateDataChannel failed."; |
| 2088 | return; |
| 2089 | } |
| 2090 | channel->SetReceiveSsrc(remote_ssrc); |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 2091 | rtc::scoped_refptr<DataChannelInterface> proxy_channel = |
| 2092 | DataChannelProxy::Create(signaling_thread(), channel); |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 2093 | // Call both the raw pointer and scoped_refptr versions of the method |
| 2094 | // for compatibility. |
| 2095 | observer_->OnDataChannel(proxy_channel.get()); |
| 2096 | observer_->OnDataChannel(std::move(proxy_channel)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | rtc::scoped_refptr<DataChannel> PeerConnection::InternalCreateDataChannel( |
| 2100 | const std::string& label, |
| 2101 | const InternalDataChannelInit* config) { |
| 2102 | if (IsClosed()) { |
| 2103 | return nullptr; |
| 2104 | } |
| 2105 | if (session_->data_channel_type() == cricket::DCT_NONE) { |
| 2106 | LOG(LS_ERROR) |
| 2107 | << "InternalCreateDataChannel: Data is not supported in this call."; |
| 2108 | return nullptr; |
| 2109 | } |
| 2110 | InternalDataChannelInit new_config = |
| 2111 | config ? (*config) : InternalDataChannelInit(); |
| 2112 | if (session_->data_channel_type() == cricket::DCT_SCTP) { |
| 2113 | if (new_config.id < 0) { |
| 2114 | rtc::SSLRole role; |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 2115 | if ((session_->GetSslRole(session_->data_channel(), &role)) && |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2116 | !sid_allocator_.AllocateSid(role, &new_config.id)) { |
| 2117 | LOG(LS_ERROR) << "No id can be allocated for the SCTP data channel."; |
| 2118 | return nullptr; |
| 2119 | } |
| 2120 | } else if (!sid_allocator_.ReserveSid(new_config.id)) { |
| 2121 | LOG(LS_ERROR) << "Failed to create a SCTP data channel " |
| 2122 | << "because the id is already in use or out of range."; |
| 2123 | return nullptr; |
| 2124 | } |
| 2125 | } |
| 2126 | |
| 2127 | rtc::scoped_refptr<DataChannel> channel(DataChannel::Create( |
| 2128 | session_.get(), session_->data_channel_type(), label, new_config)); |
| 2129 | if (!channel) { |
| 2130 | sid_allocator_.ReleaseSid(new_config.id); |
| 2131 | return nullptr; |
| 2132 | } |
| 2133 | |
| 2134 | if (channel->data_channel_type() == cricket::DCT_RTP) { |
| 2135 | if (rtp_data_channels_.find(channel->label()) != rtp_data_channels_.end()) { |
| 2136 | LOG(LS_ERROR) << "DataChannel with label " << channel->label() |
| 2137 | << " already exists."; |
| 2138 | return nullptr; |
| 2139 | } |
| 2140 | rtp_data_channels_[channel->label()] = channel; |
| 2141 | } else { |
| 2142 | RTC_DCHECK(channel->data_channel_type() == cricket::DCT_SCTP); |
| 2143 | sctp_data_channels_.push_back(channel); |
| 2144 | channel->SignalClosed.connect(this, |
| 2145 | &PeerConnection::OnSctpDataChannelClosed); |
| 2146 | } |
| 2147 | |
hbos | 82ebe02 | 2016-11-14 01:41:09 -0800 | [diff] [blame] | 2148 | SignalDataChannelCreated(channel.get()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2149 | return channel; |
| 2150 | } |
| 2151 | |
| 2152 | bool PeerConnection::HasDataChannels() const { |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2153 | #ifdef HAVE_QUIC |
| 2154 | return !rtp_data_channels_.empty() || !sctp_data_channels_.empty() || |
| 2155 | (session_->quic_data_transport() && |
| 2156 | session_->quic_data_transport()->HasDataChannels()); |
| 2157 | #else |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2158 | return !rtp_data_channels_.empty() || !sctp_data_channels_.empty(); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2159 | #endif // HAVE_QUIC |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | void PeerConnection::AllocateSctpSids(rtc::SSLRole role) { |
| 2163 | for (const auto& channel : sctp_data_channels_) { |
| 2164 | if (channel->id() < 0) { |
| 2165 | int sid; |
| 2166 | if (!sid_allocator_.AllocateSid(role, &sid)) { |
| 2167 | LOG(LS_ERROR) << "Failed to allocate SCTP sid."; |
| 2168 | continue; |
| 2169 | } |
| 2170 | channel->SetSctpSid(sid); |
| 2171 | } |
| 2172 | } |
| 2173 | } |
| 2174 | |
| 2175 | void PeerConnection::OnSctpDataChannelClosed(DataChannel* channel) { |
deadbeef | bd29246 | 2015-12-14 18:15:29 -0800 | [diff] [blame] | 2176 | RTC_DCHECK(signaling_thread()->IsCurrent()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2177 | for (auto it = sctp_data_channels_.begin(); it != sctp_data_channels_.end(); |
| 2178 | ++it) { |
| 2179 | if (it->get() == channel) { |
| 2180 | if (channel->id() >= 0) { |
| 2181 | sid_allocator_.ReleaseSid(channel->id()); |
| 2182 | } |
deadbeef | bd29246 | 2015-12-14 18:15:29 -0800 | [diff] [blame] | 2183 | // Since this method is triggered by a signal from the DataChannel, |
| 2184 | // we can't free it directly here; we need to free it asynchronously. |
| 2185 | sctp_data_channels_to_free_.push_back(*it); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2186 | sctp_data_channels_.erase(it); |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 2187 | signaling_thread()->Post(RTC_FROM_HERE, this, MSG_FREE_DATACHANNELS, |
| 2188 | nullptr); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2189 | return; |
| 2190 | } |
| 2191 | } |
| 2192 | } |
| 2193 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 2194 | void PeerConnection::OnVoiceChannelCreated() { |
| 2195 | SetChannelOnSendersAndReceivers<AudioRtpSender, AudioRtpReceiver>( |
| 2196 | session_->voice_channel(), senders_, receivers_, |
| 2197 | cricket::MEDIA_TYPE_AUDIO); |
| 2198 | } |
| 2199 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2200 | void PeerConnection::OnVoiceChannelDestroyed() { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 2201 | SetChannelOnSendersAndReceivers<AudioRtpSender, AudioRtpReceiver, |
| 2202 | cricket::VoiceChannel>( |
| 2203 | nullptr, senders_, receivers_, cricket::MEDIA_TYPE_AUDIO); |
| 2204 | } |
| 2205 | |
| 2206 | void PeerConnection::OnVideoChannelCreated() { |
| 2207 | SetChannelOnSendersAndReceivers<VideoRtpSender, VideoRtpReceiver>( |
| 2208 | session_->video_channel(), senders_, receivers_, |
| 2209 | cricket::MEDIA_TYPE_VIDEO); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | void PeerConnection::OnVideoChannelDestroyed() { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 2213 | SetChannelOnSendersAndReceivers<VideoRtpSender, VideoRtpReceiver, |
| 2214 | cricket::VideoChannel>( |
| 2215 | nullptr, senders_, receivers_, cricket::MEDIA_TYPE_VIDEO); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | void PeerConnection::OnDataChannelCreated() { |
| 2219 | for (const auto& channel : sctp_data_channels_) { |
| 2220 | channel->OnTransportChannelCreated(); |
| 2221 | } |
| 2222 | } |
| 2223 | |
| 2224 | void PeerConnection::OnDataChannelDestroyed() { |
| 2225 | // Use a temporary copy of the RTP/SCTP DataChannel list because the |
| 2226 | // DataChannel may callback to us and try to modify the list. |
| 2227 | std::map<std::string, rtc::scoped_refptr<DataChannel>> temp_rtp_dcs; |
| 2228 | temp_rtp_dcs.swap(rtp_data_channels_); |
| 2229 | for (const auto& kv : temp_rtp_dcs) { |
| 2230 | kv.second->OnTransportChannelDestroyed(); |
| 2231 | } |
| 2232 | |
| 2233 | std::vector<rtc::scoped_refptr<DataChannel>> temp_sctp_dcs; |
| 2234 | temp_sctp_dcs.swap(sctp_data_channels_); |
| 2235 | for (const auto& channel : temp_sctp_dcs) { |
| 2236 | channel->OnTransportChannelDestroyed(); |
| 2237 | } |
| 2238 | } |
| 2239 | |
| 2240 | void PeerConnection::OnDataChannelOpenMessage( |
| 2241 | const std::string& label, |
| 2242 | const InternalDataChannelInit& config) { |
| 2243 | rtc::scoped_refptr<DataChannel> channel( |
| 2244 | InternalCreateDataChannel(label, &config)); |
| 2245 | if (!channel.get()) { |
| 2246 | LOG(LS_ERROR) << "Failed to create DataChannel from the OPEN message."; |
| 2247 | return; |
| 2248 | } |
| 2249 | |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 2250 | rtc::scoped_refptr<DataChannelInterface> proxy_channel = |
| 2251 | DataChannelProxy::Create(signaling_thread(), channel); |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 2252 | // Call both the raw pointer and scoped_refptr versions of the method |
| 2253 | // for compatibility. |
| 2254 | observer_->OnDataChannel(proxy_channel.get()); |
| 2255 | observer_->OnDataChannel(std::move(proxy_channel)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2256 | } |
| 2257 | |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 2258 | RtpSenderInternal* PeerConnection::FindSenderById(const std::string& id) { |
| 2259 | auto it = std::find_if( |
| 2260 | senders_.begin(), senders_.end(), |
| 2261 | [id](const rtc::scoped_refptr< |
| 2262 | RtpSenderProxyWithInternal<RtpSenderInternal>>& sender) { |
| 2263 | return sender->id() == id; |
| 2264 | }); |
| 2265 | return it != senders_.end() ? (*it)->internal() : nullptr; |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 2266 | } |
| 2267 | |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 2268 | std::vector< |
| 2269 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>>::iterator |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 2270 | PeerConnection::FindSenderForTrack(MediaStreamTrackInterface* track) { |
| 2271 | return std::find_if( |
| 2272 | senders_.begin(), senders_.end(), |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 2273 | [track](const rtc::scoped_refptr< |
| 2274 | RtpSenderProxyWithInternal<RtpSenderInternal>>& sender) { |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 2275 | return sender->track() == track; |
| 2276 | }); |
| 2277 | } |
| 2278 | |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 2279 | std::vector<rtc::scoped_refptr< |
| 2280 | RtpReceiverProxyWithInternal<RtpReceiverInternal>>>::iterator |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 2281 | PeerConnection::FindReceiverForTrack(const std::string& track_id) { |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 2282 | return std::find_if( |
| 2283 | receivers_.begin(), receivers_.end(), |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 2284 | [track_id](const rtc::scoped_refptr< |
| 2285 | RtpReceiverProxyWithInternal<RtpReceiverInternal>>& receiver) { |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 2286 | return receiver->id() == track_id; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 2287 | }); |
| 2288 | } |
| 2289 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2290 | PeerConnection::TrackInfos* PeerConnection::GetRemoteTracks( |
| 2291 | cricket::MediaType media_type) { |
| 2292 | RTC_DCHECK(media_type == cricket::MEDIA_TYPE_AUDIO || |
| 2293 | media_type == cricket::MEDIA_TYPE_VIDEO); |
| 2294 | return (media_type == cricket::MEDIA_TYPE_AUDIO) ? &remote_audio_tracks_ |
| 2295 | : &remote_video_tracks_; |
| 2296 | } |
| 2297 | |
| 2298 | PeerConnection::TrackInfos* PeerConnection::GetLocalTracks( |
| 2299 | cricket::MediaType media_type) { |
| 2300 | RTC_DCHECK(media_type == cricket::MEDIA_TYPE_AUDIO || |
| 2301 | media_type == cricket::MEDIA_TYPE_VIDEO); |
| 2302 | return (media_type == cricket::MEDIA_TYPE_AUDIO) ? &local_audio_tracks_ |
| 2303 | : &local_video_tracks_; |
| 2304 | } |
| 2305 | |
| 2306 | const PeerConnection::TrackInfo* PeerConnection::FindTrackInfo( |
| 2307 | const PeerConnection::TrackInfos& infos, |
| 2308 | const std::string& stream_label, |
| 2309 | const std::string track_id) const { |
| 2310 | for (const TrackInfo& track_info : infos) { |
| 2311 | if (track_info.stream_label == stream_label && |
| 2312 | track_info.track_id == track_id) { |
| 2313 | return &track_info; |
| 2314 | } |
| 2315 | } |
| 2316 | return nullptr; |
| 2317 | } |
| 2318 | |
| 2319 | DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { |
| 2320 | for (const auto& channel : sctp_data_channels_) { |
| 2321 | if (channel->id() == sid) { |
| 2322 | return channel; |
| 2323 | } |
| 2324 | } |
| 2325 | return nullptr; |
| 2326 | } |
| 2327 | |
deadbeef | 91dd567 | 2016-05-18 16:55:30 -0700 | [diff] [blame] | 2328 | bool PeerConnection::InitializePortAllocator_n( |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2329 | const RTCConfiguration& configuration) { |
| 2330 | cricket::ServerAddresses stun_servers; |
| 2331 | std::vector<cricket::RelayServerConfig> turn_servers; |
| 2332 | if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { |
| 2333 | return false; |
| 2334 | } |
| 2335 | |
Taylor Brandstetter | f8e6577 | 2016-06-27 17:20:15 -0700 | [diff] [blame] | 2336 | port_allocator_->Initialize(); |
| 2337 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2338 | // To handle both internal and externally created port allocator, we will |
| 2339 | // enable BUNDLE here. |
| 2340 | int portallocator_flags = port_allocator_->flags(); |
| 2341 | portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
| 2342 | cricket::PORTALLOCATOR_ENABLE_IPV6; |
| 2343 | // If the disable-IPv6 flag was specified, we'll not override it |
| 2344 | // by experiment. |
| 2345 | if (configuration.disable_ipv6) { |
| 2346 | portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 2347 | } else if (webrtc::field_trial::FindFullName("WebRTC-IPv6Default") == |
| 2348 | "Disabled") { |
| 2349 | portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 2350 | } |
| 2351 | |
| 2352 | if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) { |
| 2353 | portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; |
| 2354 | LOG(LS_INFO) << "TCP candidates are disabled."; |
| 2355 | } |
| 2356 | |
honghaiz | 6034705 | 2016-05-31 18:29:12 -0700 | [diff] [blame] | 2357 | if (configuration.candidate_network_policy == |
| 2358 | kCandidateNetworkPolicyLowCost) { |
| 2359 | portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS; |
| 2360 | LOG(LS_INFO) << "Do not gather candidates on high-cost networks"; |
| 2361 | } |
| 2362 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2363 | port_allocator_->set_flags(portallocator_flags); |
| 2364 | // No step delay is used while allocating ports. |
| 2365 | port_allocator_->set_step_delay(cricket::kMinimumStepDelay); |
| 2366 | port_allocator_->set_candidate_filter( |
| 2367 | ConvertIceTransportTypeToCandidateFilter(configuration.type)); |
| 2368 | |
| 2369 | // Call this last since it may create pooled allocator sessions using the |
| 2370 | // properties set above. |
| 2371 | port_allocator_->SetConfiguration(stun_servers, turn_servers, |
Honghai Zhang | b9e7b4a | 2016-06-30 20:52:02 -0700 | [diff] [blame] | 2372 | configuration.ice_candidate_pool_size, |
| 2373 | configuration.prune_turn_ports); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2374 | return true; |
| 2375 | } |
| 2376 | |
deadbeef | 91dd567 | 2016-05-18 16:55:30 -0700 | [diff] [blame] | 2377 | bool PeerConnection::ReconfigurePortAllocator_n( |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2378 | const RTCConfiguration& configuration) { |
| 2379 | cricket::ServerAddresses stun_servers; |
| 2380 | std::vector<cricket::RelayServerConfig> turn_servers; |
| 2381 | if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { |
| 2382 | return false; |
| 2383 | } |
| 2384 | port_allocator_->set_candidate_filter( |
| 2385 | ConvertIceTransportTypeToCandidateFilter(configuration.type)); |
| 2386 | // Call this last since it may create pooled allocator sessions using the |
| 2387 | // candidate filter set above. |
| 2388 | port_allocator_->SetConfiguration(stun_servers, turn_servers, |
Honghai Zhang | b9e7b4a | 2016-06-30 20:52:02 -0700 | [diff] [blame] | 2389 | configuration.ice_candidate_pool_size, |
| 2390 | configuration.prune_turn_ports); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2391 | return true; |
| 2392 | } |
| 2393 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 2394 | bool PeerConnection::StartRtcEventLog_w(rtc::PlatformFile file, |
| 2395 | int64_t max_size_bytes) { |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 2396 | return event_log_->StartLogging(file, max_size_bytes); |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 2397 | } |
| 2398 | |
| 2399 | void PeerConnection::StopRtcEventLog_w() { |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 2400 | event_log_->StopLogging(); |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 2401 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2402 | } // namespace webrtc |