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 | |
| 11 | // This file contains the PeerConnection interface as defined in |
| 12 | // http://dev.w3.org/2011/webrtc/editor/webrtc.html#peer-to-peer-connections. |
| 13 | // Applications must use this interface to implement peerconnection. |
| 14 | // PeerConnectionFactory class provides factory methods to create |
| 15 | // peerconnection, mediastream and media tracks objects. |
| 16 | // |
| 17 | // The Following steps are needed to setup a typical call using Jsep. |
| 18 | // 1. Create a PeerConnectionFactoryInterface. Check constructors for more |
| 19 | // information about input parameters. |
| 20 | // 2. Create a PeerConnection object. Provide a configuration string which |
| 21 | // points either to stun or turn server to generate ICE candidates and provide |
| 22 | // an object that implements the PeerConnectionObserver interface. |
| 23 | // 3. Create local MediaStream and MediaTracks using the PeerConnectionFactory |
| 24 | // and add it to PeerConnection by calling AddStream. |
| 25 | // 4. Create an offer and serialize it and send it to the remote peer. |
| 26 | // 5. Once an ice candidate have been found PeerConnection will call the |
| 27 | // observer function OnIceCandidate. The candidates must also be serialized and |
| 28 | // sent to the remote peer. |
| 29 | // 6. Once an answer is received from the remote peer, call |
| 30 | // SetLocalSessionDescription with the offer and SetRemoteSessionDescription |
| 31 | // with the remote answer. |
| 32 | // 7. Once a remote candidate is received from the remote peer, provide it to |
| 33 | // the peerconnection by calling AddIceCandidate. |
| 34 | |
| 35 | |
| 36 | // The Receiver of a call can decide to accept or reject the call. |
| 37 | // This decision will be taken by the application not peerconnection. |
| 38 | // If application decides to accept the call |
| 39 | // 1. Create PeerConnectionFactoryInterface if it doesn't exist. |
| 40 | // 2. Create a new PeerConnection. |
| 41 | // 3. Provide the remote offer to the new PeerConnection object by calling |
| 42 | // SetRemoteSessionDescription. |
| 43 | // 4. Generate an answer to the remote offer by calling CreateAnswer and send it |
| 44 | // back to the remote peer. |
| 45 | // 5. Provide the local answer to the new PeerConnection by calling |
| 46 | // SetLocalSessionDescription with the answer. |
| 47 | // 6. Provide the remote ice candidates by calling AddIceCandidate. |
| 48 | // 7. Once a candidate have been found PeerConnection will call the observer |
| 49 | // function OnIceCandidate. Send these candidates to the remote peer. |
| 50 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 51 | #ifndef WEBRTC_API_PEERCONNECTIONINTERFACE_H_ |
| 52 | #define WEBRTC_API_PEERCONNECTIONINTERFACE_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 53 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 54 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 55 | #include <string> |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 56 | #include <utility> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 57 | #include <vector> |
| 58 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 59 | #include "webrtc/api/datachannelinterface.h" |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 60 | #include "webrtc/api/dtmfsenderinterface.h" |
| 61 | #include "webrtc/api/jsep.h" |
| 62 | #include "webrtc/api/mediastreaminterface.h" |
hbos | 74e1a4f | 2016-09-15 23:33:01 -0700 | [diff] [blame] | 63 | #include "webrtc/api/rtcstatscollector.h" |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 64 | #include "webrtc/api/rtpreceiverinterface.h" |
| 65 | #include "webrtc/api/rtpsenderinterface.h" |
| 66 | #include "webrtc/api/statstypes.h" |
| 67 | #include "webrtc/api/umametrics.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 68 | #include "webrtc/base/fileutils.h" |
phoglund@webrtc.org | 006521d | 2015-02-12 09:23:59 +0000 | [diff] [blame] | 69 | #include "webrtc/base/network.h" |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 70 | #include "webrtc/base/rtccertificate.h" |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 71 | #include "webrtc/base/rtccertificategenerator.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 72 | #include "webrtc/base/socketaddress.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 73 | #include "webrtc/base/sslstreamadapter.h" |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 74 | #include "webrtc/media/base/mediachannel.h" |
deadbeef | 41b0798 | 2015-12-01 15:01:24 -0800 | [diff] [blame] | 75 | #include "webrtc/p2p/base/portallocator.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 77 | namespace rtc { |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 +0000 | [diff] [blame] | 78 | class SSLIdentity; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 79 | class Thread; |
| 80 | } |
| 81 | |
| 82 | namespace cricket { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | class WebRtcVideoDecoderFactory; |
| 84 | class WebRtcVideoEncoderFactory; |
| 85 | } |
| 86 | |
| 87 | namespace webrtc { |
| 88 | class AudioDeviceModule; |
| 89 | class MediaConstraintsInterface; |
| 90 | |
| 91 | // MediaStream container interface. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 92 | class StreamCollectionInterface : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 93 | public: |
| 94 | // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find. |
| 95 | virtual size_t count() = 0; |
| 96 | virtual MediaStreamInterface* at(size_t index) = 0; |
| 97 | virtual MediaStreamInterface* find(const std::string& label) = 0; |
| 98 | virtual MediaStreamTrackInterface* FindAudioTrack( |
| 99 | const std::string& id) = 0; |
| 100 | virtual MediaStreamTrackInterface* FindVideoTrack( |
| 101 | const std::string& id) = 0; |
| 102 | |
| 103 | protected: |
| 104 | // Dtor protected as objects shouldn't be deleted via this interface. |
| 105 | ~StreamCollectionInterface() {} |
| 106 | }; |
| 107 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 108 | class StatsObserver : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 109 | public: |
tommi@webrtc.org | e2e199b | 2014-12-15 13:22:54 +0000 | [diff] [blame] | 110 | virtual void OnComplete(const StatsReports& reports) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 111 | |
| 112 | protected: |
| 113 | virtual ~StatsObserver() {} |
| 114 | }; |
| 115 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 116 | class MetricsObserverInterface : public rtc::RefCountInterface { |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 117 | public: |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 118 | |
| 119 | // |type| is the type of the enum counter to be incremented. |counter| |
| 120 | // is the particular counter in that type. |counter_max| is the next sequence |
| 121 | // number after the highest counter. |
| 122 | virtual void IncrementEnumCounter(PeerConnectionEnumCounterType type, |
| 123 | int counter, |
| 124 | int counter_max) {} |
| 125 | |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 126 | // This is used to handle sparse counters like SSL cipher suites. |
| 127 | // TODO(guoweis): Remove the implementation once the dependency's interface |
| 128 | // definition is updated. |
| 129 | virtual void IncrementSparseEnumCounter(PeerConnectionEnumCounterType type, |
| 130 | int counter) { |
| 131 | IncrementEnumCounter(type, counter, 0 /* Ignored */); |
| 132 | } |
| 133 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 134 | virtual void AddHistogramSample(PeerConnectionMetricsName type, |
mallinath@webrtc.org | d37bcfa | 2014-05-12 23:10:18 +0000 | [diff] [blame] | 135 | int value) = 0; |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 136 | |
| 137 | protected: |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 138 | virtual ~MetricsObserverInterface() {} |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 141 | typedef MetricsObserverInterface UMAObserver; |
| 142 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 143 | class PeerConnectionInterface : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 144 | public: |
| 145 | // See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions . |
| 146 | enum SignalingState { |
| 147 | kStable, |
| 148 | kHaveLocalOffer, |
| 149 | kHaveLocalPrAnswer, |
| 150 | kHaveRemoteOffer, |
| 151 | kHaveRemotePrAnswer, |
| 152 | kClosed, |
| 153 | }; |
| 154 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 155 | enum IceGatheringState { |
| 156 | kIceGatheringNew, |
| 157 | kIceGatheringGathering, |
| 158 | kIceGatheringComplete |
| 159 | }; |
| 160 | |
| 161 | enum IceConnectionState { |
| 162 | kIceConnectionNew, |
| 163 | kIceConnectionChecking, |
| 164 | kIceConnectionConnected, |
| 165 | kIceConnectionCompleted, |
| 166 | kIceConnectionFailed, |
| 167 | kIceConnectionDisconnected, |
| 168 | kIceConnectionClosed, |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 169 | kIceConnectionMax, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | struct IceServer { |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 173 | // TODO(jbauch): Remove uri when all code using it has switched to urls. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 174 | std::string uri; |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 175 | std::vector<std::string> urls; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 176 | std::string username; |
| 177 | std::string password; |
| 178 | }; |
| 179 | typedef std::vector<IceServer> IceServers; |
| 180 | |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 181 | enum IceTransportsType { |
pthatcher@webrtc.org | fd630a5 | 2015-01-14 23:19:06 +0000 | [diff] [blame] | 182 | // TODO(pthatcher): Rename these kTransporTypeXXX, but update |
| 183 | // Chromium at the same time. |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 184 | kNone, |
| 185 | kRelay, |
| 186 | kNoHost, |
| 187 | kAll |
| 188 | }; |
| 189 | |
pthatcher@webrtc.org | fd630a5 | 2015-01-14 23:19:06 +0000 | [diff] [blame] | 190 | // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-08#section-4.1.1 |
| 191 | enum BundlePolicy { |
| 192 | kBundlePolicyBalanced, |
| 193 | kBundlePolicyMaxBundle, |
| 194 | kBundlePolicyMaxCompat |
| 195 | }; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 196 | |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 197 | // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-09#section-4.1.1 |
| 198 | enum RtcpMuxPolicy { |
| 199 | kRtcpMuxPolicyNegotiate, |
| 200 | kRtcpMuxPolicyRequire, |
| 201 | }; |
| 202 | |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 203 | enum TcpCandidatePolicy { |
| 204 | kTcpCandidatePolicyEnabled, |
| 205 | kTcpCandidatePolicyDisabled |
| 206 | }; |
| 207 | |
honghaiz | 6034705 | 2016-05-31 18:29:12 -0700 | [diff] [blame] | 208 | enum CandidateNetworkPolicy { |
| 209 | kCandidateNetworkPolicyAll, |
| 210 | kCandidateNetworkPolicyLowCost |
| 211 | }; |
| 212 | |
honghaiz | 1f429e3 | 2015-09-28 07:57:34 -0700 | [diff] [blame] | 213 | enum ContinualGatheringPolicy { |
| 214 | GATHER_ONCE, |
| 215 | GATHER_CONTINUALLY |
| 216 | }; |
| 217 | |
Honghai Zhang | f7ddc06 | 2016-09-01 15:34:01 -0700 | [diff] [blame] | 218 | enum class RTCConfigurationType { |
| 219 | // A configuration that is safer to use, despite not having the best |
| 220 | // performance. Currently this is the default configuration. |
| 221 | kSafe, |
| 222 | // An aggressive configuration that has better performance, although it |
| 223 | // may be riskier and may need extra support in the application. |
| 224 | kAggressive |
| 225 | }; |
| 226 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 227 | // TODO(hbos): Change into class with private data and public getters. |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 228 | // TODO(nisse): In particular, accessing fields directly from an |
| 229 | // application is brittle, since the organization mirrors the |
| 230 | // organization of the implementation, which isn't stable. So we |
| 231 | // need getters and setters at least for fields which applications |
| 232 | // are interested in. |
pthatcher@webrtc.org | fd630a5 | 2015-01-14 23:19:06 +0000 | [diff] [blame] | 233 | struct RTCConfiguration { |
Niels Möller | 71bdda0 | 2016-03-31 12:59:59 +0200 | [diff] [blame] | 234 | // This struct is subject to reorganization, both for naming |
| 235 | // consistency, and to group settings to match where they are used |
| 236 | // in the implementation. To do that, we need getter and setter |
| 237 | // methods for all settings which are of interest to applications, |
| 238 | // Chrome in particular. |
| 239 | |
Honghai Zhang | f7ddc06 | 2016-09-01 15:34:01 -0700 | [diff] [blame] | 240 | RTCConfiguration() = default; |
| 241 | RTCConfiguration(RTCConfigurationType type) { |
| 242 | if (type == RTCConfigurationType::kAggressive) { |
Honghai Zhang | aecd982 | 2016-09-02 16:58:17 -0700 | [diff] [blame] | 243 | // These parameters are also defined in Java and IOS configurations, |
| 244 | // so their values may be overwritten by the Java or IOS configuration. |
| 245 | bundle_policy = kBundlePolicyMaxBundle; |
| 246 | rtcp_mux_policy = kRtcpMuxPolicyRequire; |
| 247 | ice_connection_receiving_timeout = |
| 248 | kAggressiveIceConnectionReceivingTimeout; |
| 249 | |
| 250 | // These parameters are not defined in Java or IOS configuration, |
| 251 | // so their values will not be overwritten. |
| 252 | enable_ice_renomination = true; |
Honghai Zhang | f7ddc06 | 2016-09-01 15:34:01 -0700 | [diff] [blame] | 253 | redetermine_role_on_ice_restart = false; |
| 254 | } |
Honghai Zhang | bfd398c | 2016-08-30 22:07:42 -0700 | [diff] [blame] | 255 | } |
| 256 | |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 257 | bool dscp() { return media_config.enable_dscp; } |
| 258 | void set_dscp(bool enable) { media_config.enable_dscp = enable; } |
Niels Möller | 71bdda0 | 2016-03-31 12:59:59 +0200 | [diff] [blame] | 259 | |
| 260 | // TODO(nisse): The corresponding flag in MediaConfig and |
| 261 | // elsewhere should be renamed enable_cpu_adaptation. |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 262 | bool cpu_adaptation() { |
| 263 | return media_config.video.enable_cpu_overuse_detection; |
| 264 | } |
Niels Möller | 71bdda0 | 2016-03-31 12:59:59 +0200 | [diff] [blame] | 265 | void set_cpu_adaptation(bool enable) { |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 266 | media_config.video.enable_cpu_overuse_detection = enable; |
Niels Möller | 71bdda0 | 2016-03-31 12:59:59 +0200 | [diff] [blame] | 267 | } |
| 268 | |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 269 | bool suspend_below_min_bitrate() { |
| 270 | return media_config.video.suspend_below_min_bitrate; |
| 271 | } |
Niels Möller | 71bdda0 | 2016-03-31 12:59:59 +0200 | [diff] [blame] | 272 | void set_suspend_below_min_bitrate(bool enable) { |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 273 | media_config.video.suspend_below_min_bitrate = enable; |
Niels Möller | 71bdda0 | 2016-03-31 12:59:59 +0200 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | // TODO(nisse): The negation in the corresponding MediaConfig |
| 277 | // attribute is inconsistent, and it should be renamed at some |
| 278 | // point. |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 279 | bool prerenderer_smoothing() { |
| 280 | return !media_config.video.disable_prerenderer_smoothing; |
| 281 | } |
Niels Möller | 71bdda0 | 2016-03-31 12:59:59 +0200 | [diff] [blame] | 282 | void set_prerenderer_smoothing(bool enable) { |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 283 | media_config.video.disable_prerenderer_smoothing = !enable; |
Niels Möller | 71bdda0 | 2016-03-31 12:59:59 +0200 | [diff] [blame] | 284 | } |
| 285 | |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame] | 286 | static const int kUndefined = -1; |
| 287 | // Default maximum number of packets in the audio jitter buffer. |
| 288 | static const int kAudioJitterBufferMaxPackets = 50; |
Honghai Zhang | aecd982 | 2016-09-02 16:58:17 -0700 | [diff] [blame] | 289 | // ICE connection receiving timeout for aggressive configuration. |
| 290 | static const int kAggressiveIceConnectionReceivingTimeout = 1000; |
pthatcher@webrtc.org | fd630a5 | 2015-01-14 23:19:06 +0000 | [diff] [blame] | 291 | // TODO(pthatcher): Rename this ice_transport_type, but update |
| 292 | // Chromium at the same time. |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 293 | IceTransportsType type = kAll; |
pthatcher@webrtc.org | fd630a5 | 2015-01-14 23:19:06 +0000 | [diff] [blame] | 294 | // TODO(pthatcher): Rename this ice_servers, but update Chromium |
| 295 | // at the same time. |
| 296 | IceServers servers; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 297 | BundlePolicy bundle_policy = kBundlePolicyBalanced; |
| 298 | RtcpMuxPolicy rtcp_mux_policy = kRtcpMuxPolicyNegotiate; |
| 299 | TcpCandidatePolicy tcp_candidate_policy = kTcpCandidatePolicyEnabled; |
honghaiz | 6034705 | 2016-05-31 18:29:12 -0700 | [diff] [blame] | 300 | CandidateNetworkPolicy candidate_network_policy = |
| 301 | kCandidateNetworkPolicyAll; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 302 | int audio_jitter_buffer_max_packets = kAudioJitterBufferMaxPackets; |
| 303 | bool audio_jitter_buffer_fast_accelerate = false; |
| 304 | int ice_connection_receiving_timeout = kUndefined; // ms |
| 305 | int ice_backup_candidate_pair_ping_interval = kUndefined; // ms |
| 306 | ContinualGatheringPolicy continual_gathering_policy = GATHER_ONCE; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 307 | std::vector<rtc::scoped_refptr<rtc::RTCCertificate>> certificates; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 308 | bool prioritize_most_likely_ice_candidate_pairs = false; |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 309 | struct cricket::MediaConfig media_config; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 310 | // Flags corresponding to values set by constraint flags. |
| 311 | // rtc::Optional flags can be "missing", in which case the webrtc |
| 312 | // default applies. |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 313 | bool disable_ipv6 = false; |
| 314 | bool enable_rtp_data_channel = false; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 315 | bool enable_quic = false; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 316 | rtc::Optional<int> screencast_min_bitrate; |
| 317 | rtc::Optional<bool> combined_audio_video_bwe; |
| 318 | rtc::Optional<bool> enable_dtls_srtp; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 319 | int ice_candidate_pool_size = 0; |
Honghai Zhang | b9e7b4a | 2016-06-30 20:52:02 -0700 | [diff] [blame] | 320 | bool prune_turn_ports = false; |
Taylor Brandstetter | e985111 | 2016-07-01 11:11:13 -0700 | [diff] [blame] | 321 | // If set to true, this means the ICE transport should presume TURN-to-TURN |
| 322 | // candidate pairs will succeed, even before a binding response is received. |
| 323 | bool presume_writable_when_fully_relayed = false; |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 324 | // If true, "renomination" will be added to the ice options in the transport |
| 325 | // description. |
| 326 | bool enable_ice_renomination = false; |
Honghai Zhang | bfd398c | 2016-08-30 22:07:42 -0700 | [diff] [blame] | 327 | // If true, ICE role is redetermined when peerconnection sets a local |
| 328 | // transport description that indicates an ICE restart. |
| 329 | bool redetermine_role_on_ice_restart = true; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 330 | }; |
| 331 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 332 | struct RTCOfferAnswerOptions { |
| 333 | static const int kUndefined = -1; |
| 334 | static const int kMaxOfferToReceiveMedia = 1; |
| 335 | |
| 336 | // The default value for constraint offerToReceiveX:true. |
| 337 | static const int kOfferToReceiveMediaTrue = 1; |
| 338 | |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 339 | int offer_to_receive_video = kUndefined; |
| 340 | int offer_to_receive_audio = kUndefined; |
| 341 | bool voice_activity_detection = true; |
| 342 | bool ice_restart = false; |
| 343 | bool use_rtp_mux = true; |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 344 | |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 345 | RTCOfferAnswerOptions() = default; |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 346 | |
| 347 | RTCOfferAnswerOptions(int offer_to_receive_video, |
| 348 | int offer_to_receive_audio, |
| 349 | bool voice_activity_detection, |
| 350 | bool ice_restart, |
| 351 | bool use_rtp_mux) |
| 352 | : offer_to_receive_video(offer_to_receive_video), |
| 353 | offer_to_receive_audio(offer_to_receive_audio), |
| 354 | voice_activity_detection(voice_activity_detection), |
| 355 | ice_restart(ice_restart), |
| 356 | use_rtp_mux(use_rtp_mux) {} |
| 357 | }; |
| 358 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 359 | // Used by GetStats to decide which stats to include in the stats reports. |
| 360 | // |kStatsOutputLevelStandard| includes the standard stats for Javascript API; |
| 361 | // |kStatsOutputLevelDebug| includes both the standard stats and additional |
| 362 | // stats for debugging purposes. |
| 363 | enum StatsOutputLevel { |
| 364 | kStatsOutputLevelStandard, |
| 365 | kStatsOutputLevelDebug, |
| 366 | }; |
| 367 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 368 | // Accessor methods to active local streams. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 369 | virtual rtc::scoped_refptr<StreamCollectionInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 370 | local_streams() = 0; |
| 371 | |
| 372 | // Accessor methods to remote streams. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 373 | virtual rtc::scoped_refptr<StreamCollectionInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 374 | remote_streams() = 0; |
| 375 | |
| 376 | // Add a new MediaStream to be sent on this PeerConnection. |
| 377 | // Note that a SessionDescription negotiation is needed before the |
| 378 | // remote peer can receive the stream. |
perkj@webrtc.org | fd0efb6 | 2014-11-06 12:16:36 +0000 | [diff] [blame] | 379 | virtual bool AddStream(MediaStreamInterface* stream) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 380 | |
| 381 | // Remove a MediaStream from this PeerConnection. |
| 382 | // Note that a SessionDescription negotiation is need before the |
| 383 | // remote peer is notified. |
| 384 | virtual void RemoveStream(MediaStreamInterface* stream) = 0; |
| 385 | |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 386 | // TODO(deadbeef): Make the following two methods pure virtual once |
| 387 | // implemented by all subclasses of PeerConnectionInterface. |
| 388 | // Add a new MediaStreamTrack to be sent on this PeerConnection. |
| 389 | // |streams| indicates which stream labels the track should be associated |
| 390 | // with. |
| 391 | virtual rtc::scoped_refptr<RtpSenderInterface> AddTrack( |
| 392 | MediaStreamTrackInterface* track, |
| 393 | std::vector<MediaStreamInterface*> streams) { |
| 394 | return nullptr; |
| 395 | } |
| 396 | |
| 397 | // Remove an RtpSender from this PeerConnection. |
| 398 | // Returns true on success. |
| 399 | virtual bool RemoveTrack(RtpSenderInterface* sender) { |
| 400 | return false; |
| 401 | } |
| 402 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 403 | // Returns pointer to the created DtmfSender on success. |
| 404 | // Otherwise returns NULL. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 405 | virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 406 | AudioTrackInterface* track) = 0; |
| 407 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 408 | // TODO(deadbeef): Make these pure virtual once all subclasses implement them. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 409 | // |kind| must be "audio" or "video". |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 410 | // |stream_id| is used to populate the msid attribute; if empty, one will |
| 411 | // be generated automatically. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 412 | virtual rtc::scoped_refptr<RtpSenderInterface> CreateSender( |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 413 | const std::string& kind, |
| 414 | const std::string& stream_id) { |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 415 | return rtc::scoped_refptr<RtpSenderInterface>(); |
| 416 | } |
| 417 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 418 | virtual std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders() |
| 419 | const { |
| 420 | return std::vector<rtc::scoped_refptr<RtpSenderInterface>>(); |
| 421 | } |
| 422 | |
| 423 | virtual std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers() |
| 424 | const { |
| 425 | return std::vector<rtc::scoped_refptr<RtpReceiverInterface>>(); |
| 426 | } |
| 427 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 428 | virtual bool GetStats(StatsObserver* observer, |
| 429 | MediaStreamTrackInterface* track, |
| 430 | StatsOutputLevel level) = 0; |
hbos | 74e1a4f | 2016-09-15 23:33:01 -0700 | [diff] [blame] | 431 | // Gets stats using the new stats collection API, see webrtc/api/stats/. These |
| 432 | // will replace old stats collection API when the new API has matured enough. |
| 433 | // TODO(hbos): Default implementation that does nothing only exists as to not |
| 434 | // break third party projects. As soon as they have been updated this should |
| 435 | // be changed to "= 0;". |
| 436 | virtual void GetStats(RTCStatsCollectorCallback* callback) {} |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 437 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 438 | virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 439 | const std::string& label, |
| 440 | const DataChannelInit* config) = 0; |
| 441 | |
| 442 | virtual const SessionDescriptionInterface* local_description() const = 0; |
| 443 | virtual const SessionDescriptionInterface* remote_description() const = 0; |
| 444 | |
| 445 | // Create a new offer. |
| 446 | // The CreateSessionDescriptionObserver callback will be called when done. |
| 447 | virtual void CreateOffer(CreateSessionDescriptionObserver* observer, |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 448 | const MediaConstraintsInterface* constraints) {} |
| 449 | |
| 450 | // TODO(jiayl): remove the default impl and the old interface when chromium |
| 451 | // code is updated. |
| 452 | virtual void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 453 | const RTCOfferAnswerOptions& options) {} |
| 454 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 455 | // Create an answer to an offer. |
| 456 | // The CreateSessionDescriptionObserver callback will be called when done. |
| 457 | virtual void CreateAnswer(CreateSessionDescriptionObserver* observer, |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 458 | const RTCOfferAnswerOptions& options) {} |
| 459 | // Deprecated - use version above. |
| 460 | // TODO(hta): Remove and remove default implementations when all callers |
| 461 | // are updated. |
| 462 | virtual void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 463 | const MediaConstraintsInterface* constraints) {} |
| 464 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 465 | // Sets the local session description. |
| 466 | // JsepInterface takes the ownership of |desc| even if it fails. |
| 467 | // The |observer| callback will be called when done. |
| 468 | virtual void SetLocalDescription(SetSessionDescriptionObserver* observer, |
| 469 | SessionDescriptionInterface* desc) = 0; |
| 470 | // Sets the remote session description. |
| 471 | // JsepInterface takes the ownership of |desc| even if it fails. |
| 472 | // The |observer| callback will be called when done. |
| 473 | virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer, |
| 474 | SessionDescriptionInterface* desc) = 0; |
| 475 | // Restarts or updates the ICE Agent process of gathering local candidates |
| 476 | // and pinging remote candidates. |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 477 | // TODO(deadbeef): Remove once Chrome is moved over to SetConfiguration. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 478 | virtual bool UpdateIce(const IceServers& configuration, |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 479 | const MediaConstraintsInterface* constraints) { |
| 480 | return false; |
| 481 | } |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 482 | virtual bool UpdateIce(const IceServers& configuration) { return false; } |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame^] | 483 | // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of |
| 484 | // PeerConnectionInterface implement it. |
| 485 | virtual PeerConnectionInterface::RTCConfiguration GetConfiguration() { |
| 486 | return PeerConnectionInterface::RTCConfiguration(); |
| 487 | } |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 488 | // Sets the PeerConnection's global configuration to |config|. |
| 489 | // Any changes to STUN/TURN servers or ICE candidate policy will affect the |
| 490 | // next gathering phase, and cause the next call to createOffer to generate |
| 491 | // new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies |
| 492 | // cannot be changed with this method. |
| 493 | // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of |
| 494 | // PeerConnectionInterface implement it. |
| 495 | virtual bool SetConfiguration( |
| 496 | const PeerConnectionInterface::RTCConfiguration& config) { |
| 497 | return false; |
| 498 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 499 | // Provides a remote candidate to the ICE Agent. |
| 500 | // A copy of the |candidate| will be created and added to the remote |
| 501 | // description. So the caller of this method still has the ownership of the |
| 502 | // |candidate|. |
| 503 | // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will |
| 504 | // take the ownership of the |candidate|. |
| 505 | virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0; |
| 506 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 507 | // Removes a group of remote candidates from the ICE agent. |
| 508 | virtual bool RemoveIceCandidates( |
| 509 | const std::vector<cricket::Candidate>& candidates) { |
| 510 | return false; |
| 511 | } |
| 512 | |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 513 | virtual void RegisterUMAObserver(UMAObserver* observer) = 0; |
| 514 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 515 | // Returns the current SignalingState. |
| 516 | virtual SignalingState signaling_state() = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 517 | virtual IceConnectionState ice_connection_state() = 0; |
| 518 | virtual IceGatheringState ice_gathering_state() = 0; |
| 519 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 520 | // Starts RtcEventLog using existing file. Takes ownership of |file| and |
| 521 | // passes it on to Call, which will take the ownership. If the |
| 522 | // operation fails the file will be closed. The logging will stop |
| 523 | // automatically after 10 minutes have passed, or when the StopRtcEventLog |
| 524 | // function is called. |
| 525 | // TODO(ivoc): Make this pure virtual when Chrome is updated. |
| 526 | virtual bool StartRtcEventLog(rtc::PlatformFile file, |
| 527 | int64_t max_size_bytes) { |
| 528 | return false; |
| 529 | } |
| 530 | |
| 531 | // Stops logging the RtcEventLog. |
| 532 | // TODO(ivoc): Make this pure virtual when Chrome is updated. |
| 533 | virtual void StopRtcEventLog() {} |
| 534 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 535 | // Terminates all media and closes the transport. |
| 536 | virtual void Close() = 0; |
| 537 | |
| 538 | protected: |
| 539 | // Dtor protected as objects shouldn't be deleted via this interface. |
| 540 | ~PeerConnectionInterface() {} |
| 541 | }; |
| 542 | |
| 543 | // PeerConnection callback interface. Application should implement these |
| 544 | // methods. |
| 545 | class PeerConnectionObserver { |
| 546 | public: |
| 547 | enum StateType { |
| 548 | kSignalingState, |
| 549 | kIceState, |
| 550 | }; |
| 551 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 552 | // Triggered when the SignalingState changed. |
| 553 | virtual void OnSignalingChange( |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 554 | PeerConnectionInterface::SignalingState new_state) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 555 | |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 556 | // TODO(deadbeef): Once all subclasses override the scoped_refptr versions |
| 557 | // of the below three methods, make them pure virtual and remove the raw |
| 558 | // pointer version. |
| 559 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 560 | // Triggered when media is received on a new stream from remote peer. |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 561 | virtual void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) {} |
| 562 | // Deprecated; please use the version that uses a scoped_refptr. |
| 563 | virtual void OnAddStream(MediaStreamInterface* stream) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 564 | |
| 565 | // Triggered when a remote peer close a stream. |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 566 | virtual void OnRemoveStream(rtc::scoped_refptr<MediaStreamInterface> stream) { |
| 567 | } |
| 568 | // Deprecated; please use the version that uses a scoped_refptr. |
| 569 | virtual void OnRemoveStream(MediaStreamInterface* stream) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 570 | |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 571 | // Triggered when a remote peer opens a data channel. |
| 572 | virtual void OnDataChannel( |
| 573 | rtc::scoped_refptr<DataChannelInterface> data_channel){}; |
| 574 | // Deprecated; please use the version that uses a scoped_refptr. |
| 575 | virtual void OnDataChannel(DataChannelInterface* data_channel) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 576 | |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 577 | // Triggered when renegotiation is needed. For example, an ICE restart |
| 578 | // has begun. |
fischman@webrtc.org | d7568a0 | 2014-01-13 22:04:12 +0000 | [diff] [blame] | 579 | virtual void OnRenegotiationNeeded() = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 580 | |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 581 | // Called any time the IceConnectionState changes. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 582 | virtual void OnIceConnectionChange( |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 583 | PeerConnectionInterface::IceConnectionState new_state) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 584 | |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 585 | // Called any time the IceGatheringState changes. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 586 | virtual void OnIceGatheringChange( |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 587 | PeerConnectionInterface::IceGatheringState new_state) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 588 | |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 589 | // A new ICE candidate has been gathered. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 590 | virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0; |
| 591 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 592 | // Ice candidates have been removed. |
| 593 | // TODO(honghaiz): Make this a pure virtual method when all its subclasses |
| 594 | // implement it. |
| 595 | virtual void OnIceCandidatesRemoved( |
| 596 | const std::vector<cricket::Candidate>& candidates) {} |
| 597 | |
Peter Thatcher | 5436051 | 2015-07-08 11:08:35 -0700 | [diff] [blame] | 598 | // Called when the ICE connection receiving status changes. |
| 599 | virtual void OnIceConnectionReceivingChange(bool receiving) {} |
| 600 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 601 | protected: |
| 602 | // Dtor protected as objects shouldn't be deleted via this interface. |
| 603 | ~PeerConnectionObserver() {} |
| 604 | }; |
| 605 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 606 | // PeerConnectionFactoryInterface is the factory interface use for creating |
| 607 | // PeerConnection, MediaStream and media tracks. |
| 608 | // PeerConnectionFactoryInterface will create required libjingle threads, |
| 609 | // socket and network manager factory classes for networking. |
| 610 | // If an application decides to provide its own threads and network |
| 611 | // implementation of these classes it should use the alternate |
| 612 | // CreatePeerConnectionFactory method which accepts threads as input and use the |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 613 | // CreatePeerConnection version that takes a PortAllocator as an |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 614 | // argument. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 615 | class PeerConnectionFactoryInterface : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 616 | public: |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 617 | class Options { |
| 618 | public: |
Guo-wei Shieh | a7446d2 | 2016-01-11 15:27:03 -0800 | [diff] [blame] | 619 | Options() |
| 620 | : disable_encryption(false), |
| 621 | disable_sctp_data_channels(false), |
| 622 | disable_network_monitor(false), |
| 623 | network_ignore_mask(rtc::kDefaultNetworkIgnoreMask), |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 624 | ssl_max_version(rtc::SSL_PROTOCOL_DTLS_12), |
| 625 | crypto_options(rtc::CryptoOptions::NoGcm()) {} |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 626 | bool disable_encryption; |
| 627 | bool disable_sctp_data_channels; |
honghaiz | 023f3ef | 2015-10-19 09:39:32 -0700 | [diff] [blame] | 628 | bool disable_network_monitor; |
phoglund@webrtc.org | 006521d | 2015-02-12 09:23:59 +0000 | [diff] [blame] | 629 | |
| 630 | // Sets the network types to ignore. For instance, calling this with |
| 631 | // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and |
| 632 | // loopback interfaces. |
| 633 | int network_ignore_mask; |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 634 | |
| 635 | // Sets the maximum supported protocol version. The highest version |
| 636 | // supported by both ends will be used for the connection, i.e. if one |
| 637 | // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used. |
| 638 | rtc::SSLProtocolVersion ssl_max_version; |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 639 | |
| 640 | // Sets crypto related options, e.g. enabled cipher suites. |
| 641 | rtc::CryptoOptions crypto_options; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 642 | }; |
| 643 | |
| 644 | virtual void SetOptions(const Options& options) = 0; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 645 | |
deadbeef | 41b0798 | 2015-12-01 15:01:24 -0800 | [diff] [blame] | 646 | virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection( |
| 647 | const PeerConnectionInterface::RTCConfiguration& configuration, |
| 648 | const MediaConstraintsInterface* constraints, |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 649 | std::unique_ptr<cricket::PortAllocator> allocator, |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 650 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
hbos | d7973cc | 2016-05-27 06:08:53 -0700 | [diff] [blame] | 651 | PeerConnectionObserver* observer) = 0; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 652 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 653 | virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection( |
| 654 | const PeerConnectionInterface::RTCConfiguration& configuration, |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 655 | std::unique_ptr<cricket::PortAllocator> allocator, |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 656 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
hbos | d7973cc | 2016-05-27 06:08:53 -0700 | [diff] [blame] | 657 | PeerConnectionObserver* observer) = 0; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 658 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 659 | virtual rtc::scoped_refptr<MediaStreamInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 660 | CreateLocalMediaStream(const std::string& label) = 0; |
| 661 | |
| 662 | // Creates a AudioSourceInterface. |
| 663 | // |constraints| decides audio processing settings but can be NULL. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 664 | virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 665 | const cricket::AudioOptions& options) = 0; |
| 666 | // Deprecated - use version above. |
| 667 | virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 668 | const MediaConstraintsInterface* constraints) = 0; |
| 669 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 670 | // Creates a VideoTrackSourceInterface. The new source take ownership of |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 671 | // |capturer|. |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 672 | virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 673 | cricket::VideoCapturer* capturer) = 0; |
| 674 | // A video source creator that allows selection of resolution and frame rate. |
| 675 | // |constraints| decides video resolution and frame rate but can |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 676 | // be NULL. |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 677 | // In the NULL case, use the version above. |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 678 | virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 679 | cricket::VideoCapturer* capturer, |
| 680 | const MediaConstraintsInterface* constraints) = 0; |
| 681 | |
| 682 | // Creates a new local VideoTrack. The same |source| can be used in several |
| 683 | // tracks. |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 684 | virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack( |
| 685 | const std::string& label, |
| 686 | VideoTrackSourceInterface* source) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 687 | |
| 688 | // Creates an new AudioTrack. At the moment |source| can be NULL. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 689 | virtual rtc::scoped_refptr<AudioTrackInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 690 | CreateAudioTrack(const std::string& label, |
| 691 | AudioSourceInterface* source) = 0; |
| 692 | |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 693 | // Starts AEC dump using existing file. Takes ownership of |file| and passes |
| 694 | // it on to VoiceEngine (via other objects) immediately, which will take |
wu@webrtc.org | a8910d2 | 2014-01-23 22:12:45 +0000 | [diff] [blame] | 695 | // the ownerhip. If the operation fails, the file will be closed. |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 696 | // A maximum file size in bytes can be specified. When the file size limit is |
| 697 | // reached, logging is stopped automatically. If max_size_bytes is set to a |
| 698 | // value <= 0, no limit will be used, and logging will continue until the |
| 699 | // StopAecDump function is called. |
| 700 | virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) = 0; |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 701 | |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 702 | // Stops logging the AEC dump. |
| 703 | virtual void StopAecDump() = 0; |
| 704 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 705 | // This function is deprecated and will be removed when Chrome is updated to |
| 706 | // use the equivalent function on PeerConnectionInterface. |
| 707 | // TODO(ivoc) Remove after Chrome is updated. |
ivoc | c1513ee | 2016-05-13 08:30:39 -0700 | [diff] [blame] | 708 | virtual bool StartRtcEventLog(rtc::PlatformFile file, |
| 709 | int64_t max_size_bytes) = 0; |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 710 | // This function is deprecated and will be removed when Chrome is updated to |
| 711 | // use the equivalent function on PeerConnectionInterface. |
| 712 | // TODO(ivoc) Remove after Chrome is updated. |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 713 | virtual bool StartRtcEventLog(rtc::PlatformFile file) = 0; |
| 714 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 715 | // This function is deprecated and will be removed when Chrome is updated to |
| 716 | // use the equivalent function on PeerConnectionInterface. |
| 717 | // TODO(ivoc) Remove after Chrome is updated. |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 718 | virtual void StopRtcEventLog() = 0; |
| 719 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 720 | protected: |
| 721 | // Dtor and ctor protected as objects shouldn't be created or deleted via |
| 722 | // this interface. |
| 723 | PeerConnectionFactoryInterface() {} |
| 724 | ~PeerConnectionFactoryInterface() {} // NOLINT |
| 725 | }; |
| 726 | |
| 727 | // Create a new instance of PeerConnectionFactoryInterface. |
Taylor Brandstetter | a8415fe | 2016-03-23 10:38:07 -0700 | [diff] [blame] | 728 | // |
| 729 | // This method relies on the thread it's called on as the "signaling thread" |
| 730 | // for the PeerConnectionFactory it creates. |
| 731 | // |
| 732 | // As such, if the current thread is not already running an rtc::Thread message |
| 733 | // loop, an application using this method must eventually either call |
| 734 | // rtc::Thread::Current()->Run(), or call |
| 735 | // rtc::Thread::Current()->ProcessMessages() within the application's own |
| 736 | // message loop. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 737 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 738 | CreatePeerConnectionFactory(); |
| 739 | |
| 740 | // Create a new instance of PeerConnectionFactoryInterface. |
Taylor Brandstetter | a8415fe | 2016-03-23 10:38:07 -0700 | [diff] [blame] | 741 | // |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 742 | // |network_thread|, |worker_thread| and |signaling_thread| are |
| 743 | // the only mandatory parameters. |
Taylor Brandstetter | a8415fe | 2016-03-23 10:38:07 -0700 | [diff] [blame] | 744 | // |
| 745 | // If non-null, ownership of |default_adm|, |encoder_factory| and |
| 746 | // |decoder_factory| are transferred to the returned factory. |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 747 | rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory( |
| 748 | rtc::Thread* network_thread, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 749 | rtc::Thread* worker_thread, |
| 750 | rtc::Thread* signaling_thread, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 751 | AudioDeviceModule* default_adm, |
| 752 | cricket::WebRtcVideoEncoderFactory* encoder_factory, |
| 753 | cricket::WebRtcVideoDecoderFactory* decoder_factory); |
| 754 | |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 755 | // Create a new instance of PeerConnectionFactoryInterface. |
| 756 | // Same thread is used as worker and network thread. |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 757 | inline rtc::scoped_refptr<PeerConnectionFactoryInterface> |
| 758 | CreatePeerConnectionFactory( |
| 759 | rtc::Thread* worker_and_network_thread, |
| 760 | rtc::Thread* signaling_thread, |
| 761 | AudioDeviceModule* default_adm, |
| 762 | cricket::WebRtcVideoEncoderFactory* encoder_factory, |
| 763 | cricket::WebRtcVideoDecoderFactory* decoder_factory) { |
| 764 | return CreatePeerConnectionFactory( |
| 765 | worker_and_network_thread, worker_and_network_thread, signaling_thread, |
| 766 | default_adm, encoder_factory, decoder_factory); |
| 767 | } |
| 768 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 769 | } // namespace webrtc |
| 770 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 771 | #endif // WEBRTC_API_PEERCONNECTIONINTERFACE_H_ |