blob: b1b996fc08dab9c7198ac300ecb3b3f654bd94cd [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.org28e20752013-07-10 00:45:36 +00009 */
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 Kjellander15583c12016-02-10 10:53:12 +010051#ifndef WEBRTC_API_PEERCONNECTIONINTERFACE_H_
52#define WEBRTC_API_PEERCONNECTIONINTERFACE_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053
kwibergd1fe2812016-04-27 06:47:29 -070054#include <memory>
deadbeef3edec7c2016-12-10 11:44:26 -080055#include <ostream>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080057#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058#include <vector>
59
Henrik Kjellander15583c12016-02-10 10:53:12 +010060#include "webrtc/api/datachannelinterface.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010061#include "webrtc/api/dtmfsenderinterface.h"
62#include "webrtc/api/jsep.h"
63#include "webrtc/api/mediastreaminterface.h"
ossu7bb87ee2017-01-23 04:56:25 -080064#include "webrtc/api/stats/rtcstatscollectorcallback.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010065#include "webrtc/api/rtpreceiverinterface.h"
66#include "webrtc/api/rtpsenderinterface.h"
67#include "webrtc/api/statstypes.h"
68#include "webrtc/api/umametrics.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000069#include "webrtc/base/fileutils.h"
phoglund@webrtc.org006521d2015-02-12 09:23:59 +000070#include "webrtc/base/network.h"
Henrik Boström87713d02015-08-25 09:53:21 +020071#include "webrtc/base/rtccertificate.h"
Henrik Boströmd03c23b2016-06-01 11:44:18 +020072#include "webrtc/base/rtccertificategenerator.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000073#include "webrtc/base/socketaddress.h"
kjellandera96e2d72016-02-04 23:52:28 -080074#include "webrtc/base/sslstreamadapter.h"
nissec36b31b2016-04-11 23:25:29 -070075#include "webrtc/media/base/mediachannel.h"
kwiberg1e4e8cb2017-01-31 01:48:08 -080076#include "webrtc/modules/audio_coding/codecs/audio_decoder_factory.h"
deadbeef41b07982015-12-01 15:01:24 -080077#include "webrtc/p2p/base/portallocator.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000079namespace rtc {
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000080class SSLIdentity;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081class Thread;
82}
83
84namespace cricket {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085class WebRtcVideoDecoderFactory;
86class WebRtcVideoEncoderFactory;
87}
88
89namespace webrtc {
90class AudioDeviceModule;
gyzhou95aa9642016-12-13 14:06:26 -080091class AudioMixer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092class MediaConstraintsInterface;
93
94// MediaStream container interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000095class StreamCollectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096 public:
97 // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find.
98 virtual size_t count() = 0;
99 virtual MediaStreamInterface* at(size_t index) = 0;
100 virtual MediaStreamInterface* find(const std::string& label) = 0;
101 virtual MediaStreamTrackInterface* FindAudioTrack(
102 const std::string& id) = 0;
103 virtual MediaStreamTrackInterface* FindVideoTrack(
104 const std::string& id) = 0;
105
106 protected:
107 // Dtor protected as objects shouldn't be deleted via this interface.
108 ~StreamCollectionInterface() {}
109};
110
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000111class StatsObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112 public:
nissee8abe3e2017-01-18 05:00:34 -0800113 virtual void OnComplete(const StatsReports& reports) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114
115 protected:
116 virtual ~StatsObserver() {}
117};
118
deadbeef3edec7c2016-12-10 11:44:26 -0800119// Enumeration to represent distinct classes of errors that an application
deadbeef293e9262017-01-11 12:28:30 -0800120// may wish to act upon differently. These roughly map to DOMExceptions or
121// RTCError "errorDetailEnum" values in the web API, as described in the
122// comments below.
123enum class RTCErrorType {
deadbeef3edec7c2016-12-10 11:44:26 -0800124 // No error.
125 NONE,
126 // A supplied parameter is valid, but currently unsupported.
127 // Maps to InvalidAccessError DOMException.
128 UNSUPPORTED_PARAMETER,
129 // General error indicating that a supplied parameter is invalid.
130 // Maps to InvalidAccessError or TypeError DOMException depending on context.
131 INVALID_PARAMETER,
132 // Slightly more specific than INVALID_PARAMETER; a parameter's value was
133 // outside the allowed range.
134 // Maps to RangeError DOMException.
135 INVALID_RANGE,
136 // Slightly more specific than INVALID_PARAMETER; an error occurred while
137 // parsing string input.
138 // Maps to SyntaxError DOMException.
139 SYNTAX_ERROR,
140 // The object does not support this operation in its current state.
141 // Maps to InvalidStateError DOMException.
142 INVALID_STATE,
143 // An attempt was made to modify the object in an invalid way.
144 // Maps to InvalidModificationError DOMException.
145 INVALID_MODIFICATION,
146 // An error occurred within an underlying network protocol.
147 // Maps to NetworkError DOMException.
148 NETWORK_ERROR,
149 // The operation failed due to an internal error.
150 // Maps to OperationError DOMException.
151 INTERNAL_ERROR,
152};
153
deadbeef293e9262017-01-11 12:28:30 -0800154// Roughly corresponds to RTCError in the web api. Holds an error type and
155// possibly additional information specific to that error.
156//
157// Doesn't contain anything beyond a type now, but will in the future as more
158// errors are implemented.
159class RTCError {
160 public:
161 RTCError() : type_(RTCErrorType::NONE) {}
162 explicit RTCError(RTCErrorType type) : type_(type) {}
163
164 RTCErrorType type() const { return type_; }
165 void set_type(RTCErrorType type) { type_ = type; }
166
167 private:
168 RTCErrorType type_;
169};
170
deadbeef3edec7c2016-12-10 11:44:26 -0800171// Outputs the error as a friendly string.
172// Update this method when adding a new error type.
deadbeef293e9262017-01-11 12:28:30 -0800173std::ostream& operator<<(std::ostream& stream, RTCErrorType error);
deadbeef3edec7c2016-12-10 11:44:26 -0800174
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000175class PeerConnectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000176 public:
177 // See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions .
178 enum SignalingState {
179 kStable,
180 kHaveLocalOffer,
181 kHaveLocalPrAnswer,
182 kHaveRemoteOffer,
183 kHaveRemotePrAnswer,
184 kClosed,
185 };
186
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 enum IceGatheringState {
188 kIceGatheringNew,
189 kIceGatheringGathering,
190 kIceGatheringComplete
191 };
192
193 enum IceConnectionState {
194 kIceConnectionNew,
195 kIceConnectionChecking,
196 kIceConnectionConnected,
197 kIceConnectionCompleted,
198 kIceConnectionFailed,
199 kIceConnectionDisconnected,
200 kIceConnectionClosed,
Guo-wei Shieh3d564c12015-08-19 16:51:15 -0700201 kIceConnectionMax,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000202 };
203
hnsl04833622017-01-09 08:35:45 -0800204 // TLS certificate policy.
205 enum TlsCertPolicy {
206 // For TLS based protocols, ensure the connection is secure by not
207 // circumventing certificate validation.
208 kTlsCertPolicySecure,
209 // For TLS based protocols, disregard security completely by skipping
210 // certificate validation. This is insecure and should never be used unless
211 // security is irrelevant in that particular context.
212 kTlsCertPolicyInsecureNoCheck,
213 };
214
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 struct IceServer {
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200216 // TODO(jbauch): Remove uri when all code using it has switched to urls.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 std::string uri;
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200218 std::vector<std::string> urls;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 std::string username;
220 std::string password;
hnsl04833622017-01-09 08:35:45 -0800221 TlsCertPolicy tls_cert_policy = kTlsCertPolicySecure;
222
deadbeefd1a38b52016-12-10 13:15:33 -0800223 bool operator==(const IceServer& o) const {
224 return uri == o.uri && urls == o.urls && username == o.username &&
hnsl04833622017-01-09 08:35:45 -0800225 password == o.password && tls_cert_policy == o.tls_cert_policy;
deadbeefd1a38b52016-12-10 13:15:33 -0800226 }
227 bool operator!=(const IceServer& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228 };
229 typedef std::vector<IceServer> IceServers;
230
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000231 enum IceTransportsType {
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000232 // TODO(pthatcher): Rename these kTransporTypeXXX, but update
233 // Chromium at the same time.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000234 kNone,
235 kRelay,
236 kNoHost,
237 kAll
238 };
239
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000240 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-08#section-4.1.1
241 enum BundlePolicy {
242 kBundlePolicyBalanced,
243 kBundlePolicyMaxBundle,
244 kBundlePolicyMaxCompat
245 };
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000246
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700247 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-09#section-4.1.1
248 enum RtcpMuxPolicy {
249 kRtcpMuxPolicyNegotiate,
250 kRtcpMuxPolicyRequire,
251 };
252
Jiayang Liucac1b382015-04-30 12:35:24 -0700253 enum TcpCandidatePolicy {
254 kTcpCandidatePolicyEnabled,
255 kTcpCandidatePolicyDisabled
256 };
257
honghaiz60347052016-05-31 18:29:12 -0700258 enum CandidateNetworkPolicy {
259 kCandidateNetworkPolicyAll,
260 kCandidateNetworkPolicyLowCost
261 };
262
honghaiz1f429e32015-09-28 07:57:34 -0700263 enum ContinualGatheringPolicy {
264 GATHER_ONCE,
265 GATHER_CONTINUALLY
266 };
267
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700268 enum class RTCConfigurationType {
269 // A configuration that is safer to use, despite not having the best
270 // performance. Currently this is the default configuration.
271 kSafe,
272 // An aggressive configuration that has better performance, although it
273 // may be riskier and may need extra support in the application.
274 kAggressive
275 };
276
Henrik Boström87713d02015-08-25 09:53:21 +0200277 // TODO(hbos): Change into class with private data and public getters.
nissec36b31b2016-04-11 23:25:29 -0700278 // TODO(nisse): In particular, accessing fields directly from an
279 // application is brittle, since the organization mirrors the
280 // organization of the implementation, which isn't stable. So we
281 // need getters and setters at least for fields which applications
282 // are interested in.
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000283 struct RTCConfiguration {
Niels Möller71bdda02016-03-31 12:59:59 +0200284 // This struct is subject to reorganization, both for naming
285 // consistency, and to group settings to match where they are used
286 // in the implementation. To do that, we need getter and setter
287 // methods for all settings which are of interest to applications,
288 // Chrome in particular.
289
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700290 RTCConfiguration() = default;
291 RTCConfiguration(RTCConfigurationType type) {
292 if (type == RTCConfigurationType::kAggressive) {
Honghai Zhangaecd9822016-09-02 16:58:17 -0700293 // These parameters are also defined in Java and IOS configurations,
294 // so their values may be overwritten by the Java or IOS configuration.
295 bundle_policy = kBundlePolicyMaxBundle;
296 rtcp_mux_policy = kRtcpMuxPolicyRequire;
297 ice_connection_receiving_timeout =
298 kAggressiveIceConnectionReceivingTimeout;
299
300 // These parameters are not defined in Java or IOS configuration,
301 // so their values will not be overwritten.
302 enable_ice_renomination = true;
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700303 redetermine_role_on_ice_restart = false;
304 }
Honghai Zhangbfd398c2016-08-30 22:07:42 -0700305 }
306
deadbeef293e9262017-01-11 12:28:30 -0800307 bool operator==(const RTCConfiguration& o) const;
308 bool operator!=(const RTCConfiguration& o) const;
309
nissec36b31b2016-04-11 23:25:29 -0700310 bool dscp() { return media_config.enable_dscp; }
311 void set_dscp(bool enable) { media_config.enable_dscp = enable; }
Niels Möller71bdda02016-03-31 12:59:59 +0200312
313 // TODO(nisse): The corresponding flag in MediaConfig and
314 // elsewhere should be renamed enable_cpu_adaptation.
nissec36b31b2016-04-11 23:25:29 -0700315 bool cpu_adaptation() {
316 return media_config.video.enable_cpu_overuse_detection;
317 }
Niels Möller71bdda02016-03-31 12:59:59 +0200318 void set_cpu_adaptation(bool enable) {
nissec36b31b2016-04-11 23:25:29 -0700319 media_config.video.enable_cpu_overuse_detection = enable;
Niels Möller71bdda02016-03-31 12:59:59 +0200320 }
321
nissec36b31b2016-04-11 23:25:29 -0700322 bool suspend_below_min_bitrate() {
323 return media_config.video.suspend_below_min_bitrate;
324 }
Niels Möller71bdda02016-03-31 12:59:59 +0200325 void set_suspend_below_min_bitrate(bool enable) {
nissec36b31b2016-04-11 23:25:29 -0700326 media_config.video.suspend_below_min_bitrate = enable;
Niels Möller71bdda02016-03-31 12:59:59 +0200327 }
328
329 // TODO(nisse): The negation in the corresponding MediaConfig
330 // attribute is inconsistent, and it should be renamed at some
331 // point.
nissec36b31b2016-04-11 23:25:29 -0700332 bool prerenderer_smoothing() {
333 return !media_config.video.disable_prerenderer_smoothing;
334 }
Niels Möller71bdda02016-03-31 12:59:59 +0200335 void set_prerenderer_smoothing(bool enable) {
nissec36b31b2016-04-11 23:25:29 -0700336 media_config.video.disable_prerenderer_smoothing = !enable;
Niels Möller71bdda02016-03-31 12:59:59 +0200337 }
338
honghaiz4edc39c2015-09-01 09:53:56 -0700339 static const int kUndefined = -1;
340 // Default maximum number of packets in the audio jitter buffer.
341 static const int kAudioJitterBufferMaxPackets = 50;
Honghai Zhangaecd9822016-09-02 16:58:17 -0700342 // ICE connection receiving timeout for aggressive configuration.
343 static const int kAggressiveIceConnectionReceivingTimeout = 1000;
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000344 // TODO(pthatcher): Rename this ice_transport_type, but update
345 // Chromium at the same time.
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700346 IceTransportsType type = kAll;
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000347 // TODO(pthatcher): Rename this ice_servers, but update Chromium
348 // at the same time.
349 IceServers servers;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700350 BundlePolicy bundle_policy = kBundlePolicyBalanced;
zhihuang4dfb8ce2016-11-23 10:30:12 -0800351 RtcpMuxPolicy rtcp_mux_policy = kRtcpMuxPolicyRequire;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700352 TcpCandidatePolicy tcp_candidate_policy = kTcpCandidatePolicyEnabled;
honghaiz60347052016-05-31 18:29:12 -0700353 CandidateNetworkPolicy candidate_network_policy =
354 kCandidateNetworkPolicyAll;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700355 int audio_jitter_buffer_max_packets = kAudioJitterBufferMaxPackets;
356 bool audio_jitter_buffer_fast_accelerate = false;
357 int ice_connection_receiving_timeout = kUndefined; // ms
358 int ice_backup_candidate_pair_ping_interval = kUndefined; // ms
359 ContinualGatheringPolicy continual_gathering_policy = GATHER_ONCE;
Henrik Boström87713d02015-08-25 09:53:21 +0200360 std::vector<rtc::scoped_refptr<rtc::RTCCertificate>> certificates;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700361 bool prioritize_most_likely_ice_candidate_pairs = false;
nissec36b31b2016-04-11 23:25:29 -0700362 struct cricket::MediaConfig media_config;
htaa2a49d92016-03-04 02:51:39 -0800363 // Flags corresponding to values set by constraint flags.
364 // rtc::Optional flags can be "missing", in which case the webrtc
365 // default applies.
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700366 bool disable_ipv6 = false;
367 bool enable_rtp_data_channel = false;
zhihuang9763d562016-08-05 11:14:50 -0700368 bool enable_quic = false;
htaa2a49d92016-03-04 02:51:39 -0800369 rtc::Optional<int> screencast_min_bitrate;
370 rtc::Optional<bool> combined_audio_video_bwe;
371 rtc::Optional<bool> enable_dtls_srtp;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700372 int ice_candidate_pool_size = 0;
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700373 bool prune_turn_ports = false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700374 // If set to true, this means the ICE transport should presume TURN-to-TURN
375 // candidate pairs will succeed, even before a binding response is received.
376 bool presume_writable_when_fully_relayed = false;
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700377 // If true, "renomination" will be added to the ice options in the transport
378 // description.
379 bool enable_ice_renomination = false;
Honghai Zhangbfd398c2016-08-30 22:07:42 -0700380 // If true, ICE role is redetermined when peerconnection sets a local
381 // transport description that indicates an ICE restart.
382 bool redetermine_role_on_ice_restart = true;
deadbeef293e9262017-01-11 12:28:30 -0800383 //
384 // Don't forget to update operator== if adding something.
385 //
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000386 };
387
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000388 struct RTCOfferAnswerOptions {
389 static const int kUndefined = -1;
390 static const int kMaxOfferToReceiveMedia = 1;
391
392 // The default value for constraint offerToReceiveX:true.
393 static const int kOfferToReceiveMediaTrue = 1;
394
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700395 int offer_to_receive_video = kUndefined;
396 int offer_to_receive_audio = kUndefined;
397 bool voice_activity_detection = true;
398 bool ice_restart = false;
399 bool use_rtp_mux = true;
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000400
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700401 RTCOfferAnswerOptions() = default;
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000402
403 RTCOfferAnswerOptions(int offer_to_receive_video,
404 int offer_to_receive_audio,
405 bool voice_activity_detection,
406 bool ice_restart,
407 bool use_rtp_mux)
408 : offer_to_receive_video(offer_to_receive_video),
409 offer_to_receive_audio(offer_to_receive_audio),
410 voice_activity_detection(voice_activity_detection),
411 ice_restart(ice_restart),
412 use_rtp_mux(use_rtp_mux) {}
413 };
414
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000415 // Used by GetStats to decide which stats to include in the stats reports.
416 // |kStatsOutputLevelStandard| includes the standard stats for Javascript API;
417 // |kStatsOutputLevelDebug| includes both the standard stats and additional
418 // stats for debugging purposes.
419 enum StatsOutputLevel {
420 kStatsOutputLevelStandard,
421 kStatsOutputLevelDebug,
422 };
423
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424 // Accessor methods to active local streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000425 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 local_streams() = 0;
427
428 // Accessor methods to remote streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000429 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430 remote_streams() = 0;
431
432 // Add a new MediaStream to be sent on this PeerConnection.
433 // Note that a SessionDescription negotiation is needed before the
434 // remote peer can receive the stream.
perkj@webrtc.orgfd0efb62014-11-06 12:16:36 +0000435 virtual bool AddStream(MediaStreamInterface* stream) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000436
437 // Remove a MediaStream from this PeerConnection.
438 // Note that a SessionDescription negotiation is need before the
439 // remote peer is notified.
440 virtual void RemoveStream(MediaStreamInterface* stream) = 0;
441
deadbeefe1f9d832016-01-14 15:35:42 -0800442 // TODO(deadbeef): Make the following two methods pure virtual once
443 // implemented by all subclasses of PeerConnectionInterface.
444 // Add a new MediaStreamTrack to be sent on this PeerConnection.
445 // |streams| indicates which stream labels the track should be associated
446 // with.
447 virtual rtc::scoped_refptr<RtpSenderInterface> AddTrack(
448 MediaStreamTrackInterface* track,
449 std::vector<MediaStreamInterface*> streams) {
450 return nullptr;
451 }
452
453 // Remove an RtpSender from this PeerConnection.
454 // Returns true on success.
455 virtual bool RemoveTrack(RtpSenderInterface* sender) {
456 return false;
457 }
458
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459 // Returns pointer to the created DtmfSender on success.
460 // Otherwise returns NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000461 virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462 AudioTrackInterface* track) = 0;
463
deadbeef70ab1a12015-09-28 16:53:55 -0700464 // TODO(deadbeef): Make these pure virtual once all subclasses implement them.
deadbeeffac06552015-11-25 11:26:01 -0800465 // |kind| must be "audio" or "video".
deadbeefbd7d8f72015-12-18 16:58:44 -0800466 // |stream_id| is used to populate the msid attribute; if empty, one will
467 // be generated automatically.
deadbeeffac06552015-11-25 11:26:01 -0800468 virtual rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -0800469 const std::string& kind,
470 const std::string& stream_id) {
deadbeeffac06552015-11-25 11:26:01 -0800471 return rtc::scoped_refptr<RtpSenderInterface>();
472 }
473
deadbeef70ab1a12015-09-28 16:53:55 -0700474 virtual std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
475 const {
476 return std::vector<rtc::scoped_refptr<RtpSenderInterface>>();
477 }
478
479 virtual std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
480 const {
481 return std::vector<rtc::scoped_refptr<RtpReceiverInterface>>();
482 }
483
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000484 virtual bool GetStats(StatsObserver* observer,
485 MediaStreamTrackInterface* track,
486 StatsOutputLevel level) = 0;
hbos74e1a4f2016-09-15 23:33:01 -0700487 // Gets stats using the new stats collection API, see webrtc/api/stats/. These
488 // will replace old stats collection API when the new API has matured enough.
hbose3810152016-12-13 02:35:19 -0800489 // TODO(hbos): Default implementation that does nothing only exists as to not
490 // break third party projects. As soon as they have been updated this should
491 // be changed to "= 0;".
492 virtual void GetStats(RTCStatsCollectorCallback* callback) {}
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000493
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000494 virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000495 const std::string& label,
496 const DataChannelInit* config) = 0;
497
498 virtual const SessionDescriptionInterface* local_description() const = 0;
499 virtual const SessionDescriptionInterface* remote_description() const = 0;
deadbeeffe4a8a42016-12-20 17:56:17 -0800500 // A "current" description the one currently negotiated from a complete
501 // offer/answer exchange.
502 virtual const SessionDescriptionInterface* current_local_description() const {
503 return nullptr;
504 }
505 virtual const SessionDescriptionInterface* current_remote_description()
506 const {
507 return nullptr;
508 }
509 // A "pending" description is one that's part of an incomplete offer/answer
510 // exchange (thus, either an offer or a pranswer). Once the offer/answer
511 // exchange is finished, the "pending" description will become "current".
512 virtual const SessionDescriptionInterface* pending_local_description() const {
513 return nullptr;
514 }
515 virtual const SessionDescriptionInterface* pending_remote_description()
516 const {
517 return nullptr;
518 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519
520 // Create a new offer.
521 // The CreateSessionDescriptionObserver callback will be called when done.
522 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000523 const MediaConstraintsInterface* constraints) {}
524
525 // TODO(jiayl): remove the default impl and the old interface when chromium
526 // code is updated.
527 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
528 const RTCOfferAnswerOptions& options) {}
529
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000530 // Create an answer to an offer.
531 // The CreateSessionDescriptionObserver callback will be called when done.
532 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
htaa2a49d92016-03-04 02:51:39 -0800533 const RTCOfferAnswerOptions& options) {}
534 // Deprecated - use version above.
535 // TODO(hta): Remove and remove default implementations when all callers
536 // are updated.
537 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
538 const MediaConstraintsInterface* constraints) {}
539
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000540 // Sets the local session description.
541 // JsepInterface takes the ownership of |desc| even if it fails.
542 // The |observer| callback will be called when done.
543 virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
544 SessionDescriptionInterface* desc) = 0;
545 // Sets the remote session description.
546 // JsepInterface takes the ownership of |desc| even if it fails.
547 // The |observer| callback will be called when done.
548 virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
549 SessionDescriptionInterface* desc) = 0;
550 // Restarts or updates the ICE Agent process of gathering local candidates
551 // and pinging remote candidates.
deadbeefa67696b2015-09-29 11:56:26 -0700552 // TODO(deadbeef): Remove once Chrome is moved over to SetConfiguration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553 virtual bool UpdateIce(const IceServers& configuration,
deadbeefa67696b2015-09-29 11:56:26 -0700554 const MediaConstraintsInterface* constraints) {
555 return false;
556 }
htaa2a49d92016-03-04 02:51:39 -0800557 virtual bool UpdateIce(const IceServers& configuration) { return false; }
deadbeef46c73892016-11-16 19:42:04 -0800558 // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of
559 // PeerConnectionInterface implement it.
560 virtual PeerConnectionInterface::RTCConfiguration GetConfiguration() {
561 return PeerConnectionInterface::RTCConfiguration();
562 }
deadbeef293e9262017-01-11 12:28:30 -0800563
deadbeefa67696b2015-09-29 11:56:26 -0700564 // Sets the PeerConnection's global configuration to |config|.
deadbeef293e9262017-01-11 12:28:30 -0800565 //
566 // The members of |config| that may be changed are |type|, |servers|,
567 // |ice_candidate_pool_size| and |prune_turn_ports| (though the candidate
568 // pool size can't be changed after the first call to SetLocalDescription).
569 // Note that this means the BUNDLE and RTCP-multiplexing policies cannot be
570 // changed with this method.
571 //
deadbeefa67696b2015-09-29 11:56:26 -0700572 // Any changes to STUN/TURN servers or ICE candidate policy will affect the
573 // next gathering phase, and cause the next call to createOffer to generate
deadbeef293e9262017-01-11 12:28:30 -0800574 // new ICE credentials, as described in JSEP. This also occurs when
575 // |prune_turn_ports| changes, for the same reasoning.
576 //
577 // If an error occurs, returns false and populates |error| if non-null:
578 // - INVALID_MODIFICATION if |config| contains a modified parameter other
579 // than one of the parameters listed above.
580 // - INVALID_RANGE if |ice_candidate_pool_size| is out of range.
581 // - SYNTAX_ERROR if parsing an ICE server URL failed.
582 // - INVALID_PARAMETER if a TURN server is missing |username| or |password|.
583 // - INTERNAL_ERROR if an unexpected error occurred.
584 //
deadbeefa67696b2015-09-29 11:56:26 -0700585 // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of
586 // PeerConnectionInterface implement it.
587 virtual bool SetConfiguration(
deadbeef293e9262017-01-11 12:28:30 -0800588 const PeerConnectionInterface::RTCConfiguration& config,
589 RTCError* error) {
590 return false;
591 }
592 // Version without error output param for backwards compatibility.
593 // TODO(deadbeef): Remove once chromium is updated.
594 virtual bool SetConfiguration(
deadbeef1e234612016-12-24 01:43:32 -0800595 const PeerConnectionInterface::RTCConfiguration& config) {
deadbeefa67696b2015-09-29 11:56:26 -0700596 return false;
597 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000598 // Provides a remote candidate to the ICE Agent.
599 // A copy of the |candidate| will be created and added to the remote
600 // description. So the caller of this method still has the ownership of the
601 // |candidate|.
602 // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will
603 // take the ownership of the |candidate|.
604 virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
605
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700606 // Removes a group of remote candidates from the ICE agent.
607 virtual bool RemoveIceCandidates(
608 const std::vector<cricket::Candidate>& candidates) {
609 return false;
610 }
611
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000612 virtual void RegisterUMAObserver(UMAObserver* observer) = 0;
613
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000614 // Returns the current SignalingState.
615 virtual SignalingState signaling_state() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616 virtual IceConnectionState ice_connection_state() = 0;
617 virtual IceGatheringState ice_gathering_state() = 0;
618
ivoc14d5dbe2016-07-04 07:06:55 -0700619 // Starts RtcEventLog using existing file. Takes ownership of |file| and
620 // passes it on to Call, which will take the ownership. If the
621 // operation fails the file will be closed. The logging will stop
622 // automatically after 10 minutes have passed, or when the StopRtcEventLog
623 // function is called.
624 // TODO(ivoc): Make this pure virtual when Chrome is updated.
625 virtual bool StartRtcEventLog(rtc::PlatformFile file,
626 int64_t max_size_bytes) {
627 return false;
628 }
629
630 // Stops logging the RtcEventLog.
631 // TODO(ivoc): Make this pure virtual when Chrome is updated.
632 virtual void StopRtcEventLog() {}
633
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000634 // Terminates all media and closes the transport.
635 virtual void Close() = 0;
636
637 protected:
638 // Dtor protected as objects shouldn't be deleted via this interface.
639 ~PeerConnectionInterface() {}
640};
641
642// PeerConnection callback interface. Application should implement these
643// methods.
644class PeerConnectionObserver {
645 public:
646 enum StateType {
647 kSignalingState,
648 kIceState,
649 };
650
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000651 // Triggered when the SignalingState changed.
652 virtual void OnSignalingChange(
perkjdfb769d2016-02-09 03:09:43 -0800653 PeerConnectionInterface::SignalingState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000654
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700655 // TODO(deadbeef): Once all subclasses override the scoped_refptr versions
656 // of the below three methods, make them pure virtual and remove the raw
657 // pointer version.
658
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000659 // Triggered when media is received on a new stream from remote peer.
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700660 virtual void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) {}
661 // Deprecated; please use the version that uses a scoped_refptr.
662 virtual void OnAddStream(MediaStreamInterface* stream) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000663
664 // Triggered when a remote peer close a stream.
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700665 virtual void OnRemoveStream(rtc::scoped_refptr<MediaStreamInterface> stream) {
666 }
667 // Deprecated; please use the version that uses a scoped_refptr.
668 virtual void OnRemoveStream(MediaStreamInterface* stream) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000669
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700670 // Triggered when a remote peer opens a data channel.
671 virtual void OnDataChannel(
672 rtc::scoped_refptr<DataChannelInterface> data_channel){};
673 // Deprecated; please use the version that uses a scoped_refptr.
674 virtual void OnDataChannel(DataChannelInterface* data_channel) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700676 // Triggered when renegotiation is needed. For example, an ICE restart
677 // has begun.
fischman@webrtc.orgd7568a02014-01-13 22:04:12 +0000678 virtual void OnRenegotiationNeeded() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700680 // Called any time the IceConnectionState changes.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681 virtual void OnIceConnectionChange(
perkjdfb769d2016-02-09 03:09:43 -0800682 PeerConnectionInterface::IceConnectionState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000683
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700684 // Called any time the IceGatheringState changes.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000685 virtual void OnIceGatheringChange(
perkjdfb769d2016-02-09 03:09:43 -0800686 PeerConnectionInterface::IceGatheringState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700688 // A new ICE candidate has been gathered.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000689 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
690
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700691 // Ice candidates have been removed.
692 // TODO(honghaiz): Make this a pure virtual method when all its subclasses
693 // implement it.
694 virtual void OnIceCandidatesRemoved(
695 const std::vector<cricket::Candidate>& candidates) {}
696
Peter Thatcher54360512015-07-08 11:08:35 -0700697 // Called when the ICE connection receiving status changes.
698 virtual void OnIceConnectionReceivingChange(bool receiving) {}
699
zhihuang81c3a032016-11-17 12:06:24 -0800700 // Called when a track is added to streams.
701 // TODO(zhihuang) Make this a pure virtual method when all its subclasses
702 // implement it.
703 virtual void OnAddTrack(
704 rtc::scoped_refptr<RtpReceiverInterface> receiver,
zhihuangc63b8942016-12-02 15:41:10 -0800705 const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) {}
zhihuang81c3a032016-11-17 12:06:24 -0800706
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 protected:
708 // Dtor protected as objects shouldn't be deleted via this interface.
709 ~PeerConnectionObserver() {}
710};
711
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712// PeerConnectionFactoryInterface is the factory interface use for creating
713// PeerConnection, MediaStream and media tracks.
714// PeerConnectionFactoryInterface will create required libjingle threads,
715// socket and network manager factory classes for networking.
716// If an application decides to provide its own threads and network
717// implementation of these classes it should use the alternate
718// CreatePeerConnectionFactory method which accepts threads as input and use the
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800719// CreatePeerConnection version that takes a PortAllocator as an
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000720// argument.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000721class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 public:
wu@webrtc.org97077a32013-10-25 21:18:33 +0000723 class Options {
724 public:
Guo-wei Shieha7446d22016-01-11 15:27:03 -0800725 Options()
726 : disable_encryption(false),
727 disable_sctp_data_channels(false),
728 disable_network_monitor(false),
729 network_ignore_mask(rtc::kDefaultNetworkIgnoreMask),
jbauchcb560652016-08-04 05:20:32 -0700730 ssl_max_version(rtc::SSL_PROTOCOL_DTLS_12),
731 crypto_options(rtc::CryptoOptions::NoGcm()) {}
wu@webrtc.org97077a32013-10-25 21:18:33 +0000732 bool disable_encryption;
733 bool disable_sctp_data_channels;
honghaiz023f3ef2015-10-19 09:39:32 -0700734 bool disable_network_monitor;
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000735
736 // Sets the network types to ignore. For instance, calling this with
737 // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
738 // loopback interfaces.
739 int network_ignore_mask;
Joachim Bauch04e5b492015-05-29 09:40:39 +0200740
741 // Sets the maximum supported protocol version. The highest version
742 // supported by both ends will be used for the connection, i.e. if one
743 // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used.
744 rtc::SSLProtocolVersion ssl_max_version;
jbauchcb560652016-08-04 05:20:32 -0700745
746 // Sets crypto related options, e.g. enabled cipher suites.
747 rtc::CryptoOptions crypto_options;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000748 };
749
750 virtual void SetOptions(const Options& options) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000751
deadbeef41b07982015-12-01 15:01:24 -0800752 virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
753 const PeerConnectionInterface::RTCConfiguration& configuration,
754 const MediaConstraintsInterface* constraints,
kwibergd1fe2812016-04-27 06:47:29 -0700755 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200756 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
hbosd7973cc2016-05-27 06:08:53 -0700757 PeerConnectionObserver* observer) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000758
htaa2a49d92016-03-04 02:51:39 -0800759 virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
760 const PeerConnectionInterface::RTCConfiguration& configuration,
kwibergd1fe2812016-04-27 06:47:29 -0700761 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200762 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
hbosd7973cc2016-05-27 06:08:53 -0700763 PeerConnectionObserver* observer) = 0;
htaa2a49d92016-03-04 02:51:39 -0800764
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000765 virtual rtc::scoped_refptr<MediaStreamInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766 CreateLocalMediaStream(const std::string& label) = 0;
767
768 // Creates a AudioSourceInterface.
769 // |constraints| decides audio processing settings but can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000770 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
htaa2a49d92016-03-04 02:51:39 -0800771 const cricket::AudioOptions& options) = 0;
772 // Deprecated - use version above.
deadbeeffe0fd412017-01-13 11:47:56 -0800773 // Can use CopyConstraintsIntoAudioOptions to bridge the gap.
htaa2a49d92016-03-04 02:51:39 -0800774 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775 const MediaConstraintsInterface* constraints) = 0;
776
perkja3ede6c2016-03-08 01:27:48 +0100777 // Creates a VideoTrackSourceInterface. The new source take ownership of
htaa2a49d92016-03-04 02:51:39 -0800778 // |capturer|.
perkja3ede6c2016-03-08 01:27:48 +0100779 virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
htaa2a49d92016-03-04 02:51:39 -0800780 cricket::VideoCapturer* capturer) = 0;
781 // A video source creator that allows selection of resolution and frame rate.
782 // |constraints| decides video resolution and frame rate but can
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 // be NULL.
htaa2a49d92016-03-04 02:51:39 -0800784 // In the NULL case, use the version above.
perkja3ede6c2016-03-08 01:27:48 +0100785 virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 cricket::VideoCapturer* capturer,
787 const MediaConstraintsInterface* constraints) = 0;
788
789 // Creates a new local VideoTrack. The same |source| can be used in several
790 // tracks.
perkja3ede6c2016-03-08 01:27:48 +0100791 virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
792 const std::string& label,
793 VideoTrackSourceInterface* source) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794
795 // Creates an new AudioTrack. At the moment |source| can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000796 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 CreateAudioTrack(const std::string& label,
798 AudioSourceInterface* source) = 0;
799
wu@webrtc.orga9890802013-12-13 00:21:03 +0000800 // Starts AEC dump using existing file. Takes ownership of |file| and passes
801 // it on to VoiceEngine (via other objects) immediately, which will take
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000802 // the ownerhip. If the operation fails, the file will be closed.
ivocd66b44d2016-01-15 03:06:36 -0800803 // A maximum file size in bytes can be specified. When the file size limit is
804 // reached, logging is stopped automatically. If max_size_bytes is set to a
805 // value <= 0, no limit will be used, and logging will continue until the
806 // StopAecDump function is called.
807 virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000808
ivoc797ef122015-10-22 03:25:41 -0700809 // Stops logging the AEC dump.
810 virtual void StopAecDump() = 0;
811
ivoc14d5dbe2016-07-04 07:06:55 -0700812 // This function is deprecated and will be removed when Chrome is updated to
813 // use the equivalent function on PeerConnectionInterface.
814 // TODO(ivoc) Remove after Chrome is updated.
ivocc1513ee2016-05-13 08:30:39 -0700815 virtual bool StartRtcEventLog(rtc::PlatformFile file,
816 int64_t max_size_bytes) = 0;
ivoc14d5dbe2016-07-04 07:06:55 -0700817 // This function is deprecated and will be removed when Chrome is updated to
818 // use the equivalent function on PeerConnectionInterface.
819 // TODO(ivoc) Remove after Chrome is updated.
ivoc112a3d82015-10-16 02:22:18 -0700820 virtual bool StartRtcEventLog(rtc::PlatformFile file) = 0;
821
ivoc14d5dbe2016-07-04 07:06:55 -0700822 // This function is deprecated and will be removed when Chrome is updated to
823 // use the equivalent function on PeerConnectionInterface.
824 // TODO(ivoc) Remove after Chrome is updated.
ivoc112a3d82015-10-16 02:22:18 -0700825 virtual void StopRtcEventLog() = 0;
826
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 protected:
828 // Dtor and ctor protected as objects shouldn't be created or deleted via
829 // this interface.
830 PeerConnectionFactoryInterface() {}
831 ~PeerConnectionFactoryInterface() {} // NOLINT
832};
833
kwiberg1e4e8cb2017-01-31 01:48:08 -0800834// TODO(ossu): Remove these and define a real builtin audio encoder factory
835// instead.
836class AudioEncoderFactory : public rtc::RefCountInterface {};
837inline rtc::scoped_refptr<AudioEncoderFactory>
838CreateBuiltinAudioEncoderFactory() {
839 return nullptr;
840}
841
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842// Create a new instance of PeerConnectionFactoryInterface.
Taylor Brandstettera8415fe2016-03-23 10:38:07 -0700843//
844// This method relies on the thread it's called on as the "signaling thread"
845// for the PeerConnectionFactory it creates.
846//
847// As such, if the current thread is not already running an rtc::Thread message
848// loop, an application using this method must eventually either call
849// rtc::Thread::Current()->Run(), or call
850// rtc::Thread::Current()->ProcessMessages() within the application's own
851// message loop.
kwiberg1e4e8cb2017-01-31 01:48:08 -0800852rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
853 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
854 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory);
855
856// Deprecated variant of the above.
857// TODO(kwiberg): Remove.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000858rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859CreatePeerConnectionFactory();
860
861// Create a new instance of PeerConnectionFactoryInterface.
Taylor Brandstettera8415fe2016-03-23 10:38:07 -0700862//
danilchape9021a32016-05-17 01:52:02 -0700863// |network_thread|, |worker_thread| and |signaling_thread| are
864// the only mandatory parameters.
Taylor Brandstettera8415fe2016-03-23 10:38:07 -0700865//
866// If non-null, ownership of |default_adm|, |encoder_factory| and
867// |decoder_factory| are transferred to the returned factory.
danilchape9021a32016-05-17 01:52:02 -0700868rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
869 rtc::Thread* network_thread,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000870 rtc::Thread* worker_thread,
871 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872 AudioDeviceModule* default_adm,
kwiberg1e4e8cb2017-01-31 01:48:08 -0800873 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
874 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
875 cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
876 cricket::WebRtcVideoDecoderFactory* video_decoder_factory);
877
878// Deprecated variant of the above.
879// TODO(kwiberg): Remove.
880rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
881 rtc::Thread* network_thread,
882 rtc::Thread* worker_thread,
883 rtc::Thread* signaling_thread,
884 AudioDeviceModule* default_adm,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 cricket::WebRtcVideoEncoderFactory* encoder_factory,
886 cricket::WebRtcVideoDecoderFactory* decoder_factory);
887
gyzhou95aa9642016-12-13 14:06:26 -0800888// Create a new instance of PeerConnectionFactoryInterface with external audio
889// mixer.
890//
891// If |audio_mixer| is null, an internal audio mixer will be created and used.
892rtc::scoped_refptr<PeerConnectionFactoryInterface>
893CreatePeerConnectionFactoryWithAudioMixer(
894 rtc::Thread* network_thread,
895 rtc::Thread* worker_thread,
896 rtc::Thread* signaling_thread,
897 AudioDeviceModule* default_adm,
kwiberg1e4e8cb2017-01-31 01:48:08 -0800898 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
899 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
900 cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
901 cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
902 rtc::scoped_refptr<AudioMixer> audio_mixer);
903
904// Deprecated variant of the above.
905// TODO(kwiberg): Remove.
906rtc::scoped_refptr<PeerConnectionFactoryInterface>
907CreatePeerConnectionFactoryWithAudioMixer(
908 rtc::Thread* network_thread,
909 rtc::Thread* worker_thread,
910 rtc::Thread* signaling_thread,
911 AudioDeviceModule* default_adm,
gyzhou95aa9642016-12-13 14:06:26 -0800912 cricket::WebRtcVideoEncoderFactory* encoder_factory,
913 cricket::WebRtcVideoDecoderFactory* decoder_factory,
914 rtc::scoped_refptr<AudioMixer> audio_mixer);
915
danilchape9021a32016-05-17 01:52:02 -0700916// Create a new instance of PeerConnectionFactoryInterface.
917// Same thread is used as worker and network thread.
danilchape9021a32016-05-17 01:52:02 -0700918inline rtc::scoped_refptr<PeerConnectionFactoryInterface>
919CreatePeerConnectionFactory(
920 rtc::Thread* worker_and_network_thread,
921 rtc::Thread* signaling_thread,
922 AudioDeviceModule* default_adm,
kwiberg1e4e8cb2017-01-31 01:48:08 -0800923 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
924 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
925 cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
926 cricket::WebRtcVideoDecoderFactory* video_decoder_factory) {
927 return CreatePeerConnectionFactory(
928 worker_and_network_thread, worker_and_network_thread, signaling_thread,
929 default_adm, audio_encoder_factory, audio_decoder_factory,
930 video_encoder_factory, video_decoder_factory);
931}
932
933// Deprecated variant of the above.
934// TODO(kwiberg): Remove.
935inline rtc::scoped_refptr<PeerConnectionFactoryInterface>
936CreatePeerConnectionFactory(
937 rtc::Thread* worker_and_network_thread,
938 rtc::Thread* signaling_thread,
939 AudioDeviceModule* default_adm,
danilchape9021a32016-05-17 01:52:02 -0700940 cricket::WebRtcVideoEncoderFactory* encoder_factory,
941 cricket::WebRtcVideoDecoderFactory* decoder_factory) {
942 return CreatePeerConnectionFactory(
943 worker_and_network_thread, worker_and_network_thread, signaling_thread,
944 default_adm, encoder_factory, decoder_factory);
945}
946
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947} // namespace webrtc
948
Henrik Kjellander15583c12016-02-10 10:53:12 +0100949#endif // WEBRTC_API_PEERCONNECTIONINTERFACE_H_