blob: 1fac5c73cf8078734ec9e38be54654cf8f166fc4 [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"
hbos74e1a4f2016-09-15 23:33:01 -070064#include "webrtc/api/rtcstatscollector.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"
deadbeef41b07982015-12-01 15:01:24 -080076#include "webrtc/p2p/base/portallocator.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000078namespace rtc {
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000079class SSLIdentity;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080class Thread;
81}
82
83namespace cricket {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084class WebRtcVideoDecoderFactory;
85class WebRtcVideoEncoderFactory;
86}
87
88namespace webrtc {
89class AudioDeviceModule;
gyzhou95aa9642016-12-13 14:06:26 -080090class AudioMixer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091class MediaConstraintsInterface;
92
93// MediaStream container interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000094class StreamCollectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095 public:
96 // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find.
97 virtual size_t count() = 0;
98 virtual MediaStreamInterface* at(size_t index) = 0;
99 virtual MediaStreamInterface* find(const std::string& label) = 0;
100 virtual MediaStreamTrackInterface* FindAudioTrack(
101 const std::string& id) = 0;
102 virtual MediaStreamTrackInterface* FindVideoTrack(
103 const std::string& id) = 0;
104
105 protected:
106 // Dtor protected as objects shouldn't be deleted via this interface.
107 ~StreamCollectionInterface() {}
108};
109
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000110class StatsObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111 public:
nisseb36ee8d2016-12-20 03:30:00 -0800112 // TODO(nisse, hbos): Old version, not passing ownership. Should
113 // perhaps be deprecated, but since all of this is a legacy
114 // interface anyway, probably best to leave as is until this class
115 // can be deleted.
116 virtual void OnComplete(const StatsReports& reports) {}
117 virtual void OnCompleteReports(std::unique_ptr<StatsReports> reports) {
118 OnComplete(*reports);
119 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120
121 protected:
122 virtual ~StatsObserver() {}
123};
124
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000125class MetricsObserverInterface : public rtc::RefCountInterface {
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000126 public:
Guo-wei Shieh3d564c12015-08-19 16:51:15 -0700127
128 // |type| is the type of the enum counter to be incremented. |counter|
129 // is the particular counter in that type. |counter_max| is the next sequence
130 // number after the highest counter.
131 virtual void IncrementEnumCounter(PeerConnectionEnumCounterType type,
132 int counter,
133 int counter_max) {}
134
Guo-wei Shieh456696a2015-09-30 21:48:54 -0700135 // This is used to handle sparse counters like SSL cipher suites.
136 // TODO(guoweis): Remove the implementation once the dependency's interface
137 // definition is updated.
138 virtual void IncrementSparseEnumCounter(PeerConnectionEnumCounterType type,
139 int counter) {
140 IncrementEnumCounter(type, counter, 0 /* Ignored */);
141 }
142
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000143 virtual void AddHistogramSample(PeerConnectionMetricsName type,
mallinath@webrtc.orgd37bcfa2014-05-12 23:10:18 +0000144 int value) = 0;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000145
146 protected:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000147 virtual ~MetricsObserverInterface() {}
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000148};
149
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000150typedef MetricsObserverInterface UMAObserver;
151
deadbeef3edec7c2016-12-10 11:44:26 -0800152// Enumeration to represent distinct classes of errors that an application
deadbeef7a5fa6c2016-12-24 00:47:59 -0800153// may wish to act upon differently. These roughly map to DOMExceptions or
154// RTCError "errorDetailEnum" values in the web API, as described in the
155// comments below.
156enum class RTCErrorType {
deadbeef3edec7c2016-12-10 11:44:26 -0800157 // No error.
158 NONE,
159 // A supplied parameter is valid, but currently unsupported.
160 // Maps to InvalidAccessError DOMException.
161 UNSUPPORTED_PARAMETER,
162 // General error indicating that a supplied parameter is invalid.
163 // Maps to InvalidAccessError or TypeError DOMException depending on context.
164 INVALID_PARAMETER,
165 // Slightly more specific than INVALID_PARAMETER; a parameter's value was
166 // outside the allowed range.
167 // Maps to RangeError DOMException.
168 INVALID_RANGE,
169 // Slightly more specific than INVALID_PARAMETER; an error occurred while
170 // parsing string input.
171 // Maps to SyntaxError DOMException.
172 SYNTAX_ERROR,
173 // The object does not support this operation in its current state.
174 // Maps to InvalidStateError DOMException.
175 INVALID_STATE,
176 // An attempt was made to modify the object in an invalid way.
177 // Maps to InvalidModificationError DOMException.
178 INVALID_MODIFICATION,
179 // An error occurred within an underlying network protocol.
180 // Maps to NetworkError DOMException.
181 NETWORK_ERROR,
182 // The operation failed due to an internal error.
183 // Maps to OperationError DOMException.
184 INTERNAL_ERROR,
185};
186
deadbeef7a5fa6c2016-12-24 00:47:59 -0800187// Roughly corresponds to RTCError in the web api. Holds an error type and
188// possibly additional information specific to that error.
189//
190// Doesn't contain anything beyond a type now, but will in the future as more
191// errors are implemented.
192class RTCError {
193 public:
194 RTCError() : type_(RTCErrorType::NONE) {}
195 explicit RTCError(RTCErrorType type) : type_(type) {}
196
197 RTCErrorType type() const { return type_; }
198 void set_type(RTCErrorType type) { type_ = type; }
199
200 private:
201 RTCErrorType type_;
202};
203
deadbeef3edec7c2016-12-10 11:44:26 -0800204// Outputs the error as a friendly string.
205// Update this method when adding a new error type.
deadbeef7a5fa6c2016-12-24 00:47:59 -0800206std::ostream& operator<<(std::ostream& stream, RTCErrorType error);
deadbeef3edec7c2016-12-10 11:44:26 -0800207
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000208class PeerConnectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 public:
210 // See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions .
211 enum SignalingState {
212 kStable,
213 kHaveLocalOffer,
214 kHaveLocalPrAnswer,
215 kHaveRemoteOffer,
216 kHaveRemotePrAnswer,
217 kClosed,
218 };
219
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220 enum IceGatheringState {
221 kIceGatheringNew,
222 kIceGatheringGathering,
223 kIceGatheringComplete
224 };
225
226 enum IceConnectionState {
227 kIceConnectionNew,
228 kIceConnectionChecking,
229 kIceConnectionConnected,
230 kIceConnectionCompleted,
231 kIceConnectionFailed,
232 kIceConnectionDisconnected,
233 kIceConnectionClosed,
Guo-wei Shieh3d564c12015-08-19 16:51:15 -0700234 kIceConnectionMax,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 };
236
237 struct IceServer {
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200238 // TODO(jbauch): Remove uri when all code using it has switched to urls.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239 std::string uri;
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200240 std::vector<std::string> urls;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 std::string username;
242 std::string password;
deadbeefd1a38b52016-12-10 13:15:33 -0800243 bool operator==(const IceServer& o) const {
244 return uri == o.uri && urls == o.urls && username == o.username &&
magjedd5236e22016-12-20 02:22:06 -0800245 password == o.password;
deadbeefd1a38b52016-12-10 13:15:33 -0800246 }
247 bool operator!=(const IceServer& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248 };
249 typedef std::vector<IceServer> IceServers;
250
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000251 enum IceTransportsType {
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000252 // TODO(pthatcher): Rename these kTransporTypeXXX, but update
253 // Chromium at the same time.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000254 kNone,
255 kRelay,
256 kNoHost,
257 kAll
258 };
259
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000260 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-08#section-4.1.1
261 enum BundlePolicy {
262 kBundlePolicyBalanced,
263 kBundlePolicyMaxBundle,
264 kBundlePolicyMaxCompat
265 };
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000266
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700267 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-09#section-4.1.1
268 enum RtcpMuxPolicy {
269 kRtcpMuxPolicyNegotiate,
270 kRtcpMuxPolicyRequire,
271 };
272
Jiayang Liucac1b382015-04-30 12:35:24 -0700273 enum TcpCandidatePolicy {
274 kTcpCandidatePolicyEnabled,
275 kTcpCandidatePolicyDisabled
276 };
277
honghaiz60347052016-05-31 18:29:12 -0700278 enum CandidateNetworkPolicy {
279 kCandidateNetworkPolicyAll,
280 kCandidateNetworkPolicyLowCost
281 };
282
honghaiz1f429e32015-09-28 07:57:34 -0700283 enum ContinualGatheringPolicy {
284 GATHER_ONCE,
285 GATHER_CONTINUALLY
286 };
287
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700288 enum class RTCConfigurationType {
289 // A configuration that is safer to use, despite not having the best
290 // performance. Currently this is the default configuration.
291 kSafe,
292 // An aggressive configuration that has better performance, although it
293 // may be riskier and may need extra support in the application.
294 kAggressive
295 };
296
Henrik Boström87713d02015-08-25 09:53:21 +0200297 // TODO(hbos): Change into class with private data and public getters.
nissec36b31b2016-04-11 23:25:29 -0700298 // TODO(nisse): In particular, accessing fields directly from an
299 // application is brittle, since the organization mirrors the
300 // organization of the implementation, which isn't stable. So we
301 // need getters and setters at least for fields which applications
302 // are interested in.
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000303 struct RTCConfiguration {
Niels Möller71bdda02016-03-31 12:59:59 +0200304 // This struct is subject to reorganization, both for naming
305 // consistency, and to group settings to match where they are used
306 // in the implementation. To do that, we need getter and setter
307 // methods for all settings which are of interest to applications,
308 // Chrome in particular.
309
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700310 RTCConfiguration() = default;
311 RTCConfiguration(RTCConfigurationType type) {
312 if (type == RTCConfigurationType::kAggressive) {
Honghai Zhangaecd9822016-09-02 16:58:17 -0700313 // These parameters are also defined in Java and IOS configurations,
314 // so their values may be overwritten by the Java or IOS configuration.
315 bundle_policy = kBundlePolicyMaxBundle;
316 rtcp_mux_policy = kRtcpMuxPolicyRequire;
317 ice_connection_receiving_timeout =
318 kAggressiveIceConnectionReceivingTimeout;
319
320 // These parameters are not defined in Java or IOS configuration,
321 // so their values will not be overwritten.
322 enable_ice_renomination = true;
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700323 redetermine_role_on_ice_restart = false;
324 }
Honghai Zhangbfd398c2016-08-30 22:07:42 -0700325 }
326
deadbeef7a5fa6c2016-12-24 00:47:59 -0800327 bool operator==(const RTCConfiguration& o) const;
328 bool operator!=(const RTCConfiguration& o) const;
329
nissec36b31b2016-04-11 23:25:29 -0700330 bool dscp() { return media_config.enable_dscp; }
331 void set_dscp(bool enable) { media_config.enable_dscp = enable; }
Niels Möller71bdda02016-03-31 12:59:59 +0200332
333 // TODO(nisse): The corresponding flag in MediaConfig and
334 // elsewhere should be renamed enable_cpu_adaptation.
nissec36b31b2016-04-11 23:25:29 -0700335 bool cpu_adaptation() {
336 return media_config.video.enable_cpu_overuse_detection;
337 }
Niels Möller71bdda02016-03-31 12:59:59 +0200338 void set_cpu_adaptation(bool enable) {
nissec36b31b2016-04-11 23:25:29 -0700339 media_config.video.enable_cpu_overuse_detection = enable;
Niels Möller71bdda02016-03-31 12:59:59 +0200340 }
341
nissec36b31b2016-04-11 23:25:29 -0700342 bool suspend_below_min_bitrate() {
343 return media_config.video.suspend_below_min_bitrate;
344 }
Niels Möller71bdda02016-03-31 12:59:59 +0200345 void set_suspend_below_min_bitrate(bool enable) {
nissec36b31b2016-04-11 23:25:29 -0700346 media_config.video.suspend_below_min_bitrate = enable;
Niels Möller71bdda02016-03-31 12:59:59 +0200347 }
348
349 // TODO(nisse): The negation in the corresponding MediaConfig
350 // attribute is inconsistent, and it should be renamed at some
351 // point.
nissec36b31b2016-04-11 23:25:29 -0700352 bool prerenderer_smoothing() {
353 return !media_config.video.disable_prerenderer_smoothing;
354 }
Niels Möller71bdda02016-03-31 12:59:59 +0200355 void set_prerenderer_smoothing(bool enable) {
nissec36b31b2016-04-11 23:25:29 -0700356 media_config.video.disable_prerenderer_smoothing = !enable;
Niels Möller71bdda02016-03-31 12:59:59 +0200357 }
358
honghaiz4edc39c2015-09-01 09:53:56 -0700359 static const int kUndefined = -1;
360 // Default maximum number of packets in the audio jitter buffer.
361 static const int kAudioJitterBufferMaxPackets = 50;
Honghai Zhangaecd9822016-09-02 16:58:17 -0700362 // ICE connection receiving timeout for aggressive configuration.
363 static const int kAggressiveIceConnectionReceivingTimeout = 1000;
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000364 // TODO(pthatcher): Rename this ice_transport_type, but update
365 // Chromium at the same time.
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700366 IceTransportsType type = kAll;
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000367 // TODO(pthatcher): Rename this ice_servers, but update Chromium
368 // at the same time.
369 IceServers servers;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700370 BundlePolicy bundle_policy = kBundlePolicyBalanced;
zhihuang4dfb8ce2016-11-23 10:30:12 -0800371 RtcpMuxPolicy rtcp_mux_policy = kRtcpMuxPolicyRequire;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700372 TcpCandidatePolicy tcp_candidate_policy = kTcpCandidatePolicyEnabled;
honghaiz60347052016-05-31 18:29:12 -0700373 CandidateNetworkPolicy candidate_network_policy =
374 kCandidateNetworkPolicyAll;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700375 int audio_jitter_buffer_max_packets = kAudioJitterBufferMaxPackets;
376 bool audio_jitter_buffer_fast_accelerate = false;
377 int ice_connection_receiving_timeout = kUndefined; // ms
378 int ice_backup_candidate_pair_ping_interval = kUndefined; // ms
379 ContinualGatheringPolicy continual_gathering_policy = GATHER_ONCE;
Henrik Boström87713d02015-08-25 09:53:21 +0200380 std::vector<rtc::scoped_refptr<rtc::RTCCertificate>> certificates;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700381 bool prioritize_most_likely_ice_candidate_pairs = false;
nissec36b31b2016-04-11 23:25:29 -0700382 struct cricket::MediaConfig media_config;
htaa2a49d92016-03-04 02:51:39 -0800383 // Flags corresponding to values set by constraint flags.
384 // rtc::Optional flags can be "missing", in which case the webrtc
385 // default applies.
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700386 bool disable_ipv6 = false;
387 bool enable_rtp_data_channel = false;
zhihuang9763d562016-08-05 11:14:50 -0700388 bool enable_quic = false;
htaa2a49d92016-03-04 02:51:39 -0800389 rtc::Optional<int> screencast_min_bitrate;
390 rtc::Optional<bool> combined_audio_video_bwe;
391 rtc::Optional<bool> enable_dtls_srtp;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700392 int ice_candidate_pool_size = 0;
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700393 bool prune_turn_ports = false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700394 // If set to true, this means the ICE transport should presume TURN-to-TURN
395 // candidate pairs will succeed, even before a binding response is received.
396 bool presume_writable_when_fully_relayed = false;
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700397 // If true, "renomination" will be added to the ice options in the transport
398 // description.
399 bool enable_ice_renomination = false;
Honghai Zhangbfd398c2016-08-30 22:07:42 -0700400 // If true, ICE role is redetermined when peerconnection sets a local
401 // transport description that indicates an ICE restart.
402 bool redetermine_role_on_ice_restart = true;
deadbeef7a5fa6c2016-12-24 00:47:59 -0800403 //
404 // Don't forget to update operator== if adding something.
405 //
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000406 };
407
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000408 struct RTCOfferAnswerOptions {
409 static const int kUndefined = -1;
410 static const int kMaxOfferToReceiveMedia = 1;
411
412 // The default value for constraint offerToReceiveX:true.
413 static const int kOfferToReceiveMediaTrue = 1;
414
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700415 int offer_to_receive_video = kUndefined;
416 int offer_to_receive_audio = kUndefined;
417 bool voice_activity_detection = true;
418 bool ice_restart = false;
419 bool use_rtp_mux = true;
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000420
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700421 RTCOfferAnswerOptions() = default;
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000422
423 RTCOfferAnswerOptions(int offer_to_receive_video,
424 int offer_to_receive_audio,
425 bool voice_activity_detection,
426 bool ice_restart,
427 bool use_rtp_mux)
428 : offer_to_receive_video(offer_to_receive_video),
429 offer_to_receive_audio(offer_to_receive_audio),
430 voice_activity_detection(voice_activity_detection),
431 ice_restart(ice_restart),
432 use_rtp_mux(use_rtp_mux) {}
433 };
434
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000435 // Used by GetStats to decide which stats to include in the stats reports.
436 // |kStatsOutputLevelStandard| includes the standard stats for Javascript API;
437 // |kStatsOutputLevelDebug| includes both the standard stats and additional
438 // stats for debugging purposes.
439 enum StatsOutputLevel {
440 kStatsOutputLevelStandard,
441 kStatsOutputLevelDebug,
442 };
443
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000444 // Accessor methods to active local streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000445 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446 local_streams() = 0;
447
448 // Accessor methods to remote streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000449 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450 remote_streams() = 0;
451
452 // Add a new MediaStream to be sent on this PeerConnection.
453 // Note that a SessionDescription negotiation is needed before the
454 // remote peer can receive the stream.
perkj@webrtc.orgfd0efb62014-11-06 12:16:36 +0000455 virtual bool AddStream(MediaStreamInterface* stream) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000456
457 // Remove a MediaStream from this PeerConnection.
458 // Note that a SessionDescription negotiation is need before the
459 // remote peer is notified.
460 virtual void RemoveStream(MediaStreamInterface* stream) = 0;
461
deadbeefe1f9d832016-01-14 15:35:42 -0800462 // TODO(deadbeef): Make the following two methods pure virtual once
463 // implemented by all subclasses of PeerConnectionInterface.
464 // Add a new MediaStreamTrack to be sent on this PeerConnection.
465 // |streams| indicates which stream labels the track should be associated
466 // with.
467 virtual rtc::scoped_refptr<RtpSenderInterface> AddTrack(
468 MediaStreamTrackInterface* track,
469 std::vector<MediaStreamInterface*> streams) {
470 return nullptr;
471 }
472
473 // Remove an RtpSender from this PeerConnection.
474 // Returns true on success.
475 virtual bool RemoveTrack(RtpSenderInterface* sender) {
476 return false;
477 }
478
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000479 // Returns pointer to the created DtmfSender on success.
480 // Otherwise returns NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000481 virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482 AudioTrackInterface* track) = 0;
483
deadbeef70ab1a12015-09-28 16:53:55 -0700484 // TODO(deadbeef): Make these pure virtual once all subclasses implement them.
deadbeeffac06552015-11-25 11:26:01 -0800485 // |kind| must be "audio" or "video".
deadbeefbd7d8f72015-12-18 16:58:44 -0800486 // |stream_id| is used to populate the msid attribute; if empty, one will
487 // be generated automatically.
deadbeeffac06552015-11-25 11:26:01 -0800488 virtual rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -0800489 const std::string& kind,
490 const std::string& stream_id) {
deadbeeffac06552015-11-25 11:26:01 -0800491 return rtc::scoped_refptr<RtpSenderInterface>();
492 }
493
deadbeef70ab1a12015-09-28 16:53:55 -0700494 virtual std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
495 const {
496 return std::vector<rtc::scoped_refptr<RtpSenderInterface>>();
497 }
498
499 virtual std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
500 const {
501 return std::vector<rtc::scoped_refptr<RtpReceiverInterface>>();
502 }
503
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000504 virtual bool GetStats(StatsObserver* observer,
505 MediaStreamTrackInterface* track,
506 StatsOutputLevel level) = 0;
hbos74e1a4f2016-09-15 23:33:01 -0700507 // Gets stats using the new stats collection API, see webrtc/api/stats/. These
508 // will replace old stats collection API when the new API has matured enough.
hbose3810152016-12-13 02:35:19 -0800509 // TODO(hbos): Default implementation that does nothing only exists as to not
510 // break third party projects. As soon as they have been updated this should
511 // be changed to "= 0;".
512 virtual void GetStats(RTCStatsCollectorCallback* callback) {}
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000513
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000514 virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000515 const std::string& label,
516 const DataChannelInit* config) = 0;
517
518 virtual const SessionDescriptionInterface* local_description() const = 0;
519 virtual const SessionDescriptionInterface* remote_description() const = 0;
deadbeeffe4a8a42016-12-20 17:56:17 -0800520 // A "current" description the one currently negotiated from a complete
521 // offer/answer exchange.
522 virtual const SessionDescriptionInterface* current_local_description() const {
523 return nullptr;
524 }
525 virtual const SessionDescriptionInterface* current_remote_description()
526 const {
527 return nullptr;
528 }
529 // A "pending" description is one that's part of an incomplete offer/answer
530 // exchange (thus, either an offer or a pranswer). Once the offer/answer
531 // exchange is finished, the "pending" description will become "current".
532 virtual const SessionDescriptionInterface* pending_local_description() const {
533 return nullptr;
534 }
535 virtual const SessionDescriptionInterface* pending_remote_description()
536 const {
537 return nullptr;
538 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539
540 // Create a new offer.
541 // The CreateSessionDescriptionObserver callback will be called when done.
542 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000543 const MediaConstraintsInterface* constraints) {}
544
545 // TODO(jiayl): remove the default impl and the old interface when chromium
546 // code is updated.
547 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
548 const RTCOfferAnswerOptions& options) {}
549
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550 // Create an answer to an offer.
551 // The CreateSessionDescriptionObserver callback will be called when done.
552 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
htaa2a49d92016-03-04 02:51:39 -0800553 const RTCOfferAnswerOptions& options) {}
554 // Deprecated - use version above.
555 // TODO(hta): Remove and remove default implementations when all callers
556 // are updated.
557 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
558 const MediaConstraintsInterface* constraints) {}
559
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 // Sets the local session description.
561 // JsepInterface takes the ownership of |desc| even if it fails.
562 // The |observer| callback will be called when done.
563 virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
564 SessionDescriptionInterface* desc) = 0;
565 // Sets the remote session description.
566 // JsepInterface takes the ownership of |desc| even if it fails.
567 // The |observer| callback will be called when done.
568 virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
569 SessionDescriptionInterface* desc) = 0;
570 // Restarts or updates the ICE Agent process of gathering local candidates
571 // and pinging remote candidates.
deadbeefa67696b2015-09-29 11:56:26 -0700572 // TODO(deadbeef): Remove once Chrome is moved over to SetConfiguration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000573 virtual bool UpdateIce(const IceServers& configuration,
deadbeefa67696b2015-09-29 11:56:26 -0700574 const MediaConstraintsInterface* constraints) {
575 return false;
576 }
htaa2a49d92016-03-04 02:51:39 -0800577 virtual bool UpdateIce(const IceServers& configuration) { return false; }
deadbeef46c73892016-11-16 19:42:04 -0800578 // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of
579 // PeerConnectionInterface implement it.
580 virtual PeerConnectionInterface::RTCConfiguration GetConfiguration() {
581 return PeerConnectionInterface::RTCConfiguration();
582 }
deadbeef7a5fa6c2016-12-24 00:47:59 -0800583
deadbeefa67696b2015-09-29 11:56:26 -0700584 // Sets the PeerConnection's global configuration to |config|.
deadbeef7a5fa6c2016-12-24 00:47:59 -0800585 //
586 // The members of |config| that may be changed are |type|, |servers|,
587 // |ice_candidate_pool_size| and |prune_turn_ports| (though the candidate
588 // pool size can't be changed after the first call to SetLocalDescription).
589 // Note that this means the BUNDLE and RTCP-multiplexing policies cannot be
590 // changed with this method.
591 //
deadbeefa67696b2015-09-29 11:56:26 -0700592 // Any changes to STUN/TURN servers or ICE candidate policy will affect the
593 // next gathering phase, and cause the next call to createOffer to generate
deadbeef7a5fa6c2016-12-24 00:47:59 -0800594 // new ICE credentials, as described in JSEP. This also occurs when
595 // |prune_turn_ports| changes, for the same reasoning.
596 //
597 // If an error occurs, returns false and populates |error| if non-null:
598 // - INVALID_MODIFICATION if |config| contains a modified parameter other
599 // than one of the parameters listed above.
600 // - INVALID_RANGE if |ice_candidate_pool_size| is out of range.
601 // - SYNTAX_ERROR if parsing an ICE server URL failed.
602 // - INVALID_PARAMETER if a TURN server is missing |username| or |password|.
603 // - INTERNAL_ERROR if an unexpected error occurred.
604 //
deadbeefa67696b2015-09-29 11:56:26 -0700605 // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of
606 // PeerConnectionInterface implement it.
607 virtual bool SetConfiguration(
deadbeef7a5fa6c2016-12-24 00:47:59 -0800608 const PeerConnectionInterface::RTCConfiguration& config,
609 RTCError* error = nullptr) {
deadbeefa67696b2015-09-29 11:56:26 -0700610 return false;
611 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612 // Provides a remote candidate to the ICE Agent.
613 // A copy of the |candidate| will be created and added to the remote
614 // description. So the caller of this method still has the ownership of the
615 // |candidate|.
616 // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will
617 // take the ownership of the |candidate|.
618 virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
619
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700620 // Removes a group of remote candidates from the ICE agent.
621 virtual bool RemoveIceCandidates(
622 const std::vector<cricket::Candidate>& candidates) {
623 return false;
624 }
625
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000626 virtual void RegisterUMAObserver(UMAObserver* observer) = 0;
627
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000628 // Returns the current SignalingState.
629 virtual SignalingState signaling_state() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000630 virtual IceConnectionState ice_connection_state() = 0;
631 virtual IceGatheringState ice_gathering_state() = 0;
632
ivoc14d5dbe2016-07-04 07:06:55 -0700633 // Starts RtcEventLog using existing file. Takes ownership of |file| and
634 // passes it on to Call, which will take the ownership. If the
635 // operation fails the file will be closed. The logging will stop
636 // automatically after 10 minutes have passed, or when the StopRtcEventLog
637 // function is called.
638 // TODO(ivoc): Make this pure virtual when Chrome is updated.
639 virtual bool StartRtcEventLog(rtc::PlatformFile file,
640 int64_t max_size_bytes) {
641 return false;
642 }
643
644 // Stops logging the RtcEventLog.
645 // TODO(ivoc): Make this pure virtual when Chrome is updated.
646 virtual void StopRtcEventLog() {}
647
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000648 // Terminates all media and closes the transport.
649 virtual void Close() = 0;
650
651 protected:
652 // Dtor protected as objects shouldn't be deleted via this interface.
653 ~PeerConnectionInterface() {}
654};
655
656// PeerConnection callback interface. Application should implement these
657// methods.
658class PeerConnectionObserver {
659 public:
660 enum StateType {
661 kSignalingState,
662 kIceState,
663 };
664
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000665 // Triggered when the SignalingState changed.
666 virtual void OnSignalingChange(
perkjdfb769d2016-02-09 03:09:43 -0800667 PeerConnectionInterface::SignalingState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000668
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700669 // TODO(deadbeef): Once all subclasses override the scoped_refptr versions
670 // of the below three methods, make them pure virtual and remove the raw
671 // pointer version.
672
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000673 // Triggered when media is received on a new stream from remote peer.
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700674 virtual void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) {}
675 // Deprecated; please use the version that uses a scoped_refptr.
676 virtual void OnAddStream(MediaStreamInterface* stream) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000677
678 // Triggered when a remote peer close a stream.
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700679 virtual void OnRemoveStream(rtc::scoped_refptr<MediaStreamInterface> stream) {
680 }
681 // Deprecated; please use the version that uses a scoped_refptr.
682 virtual void OnRemoveStream(MediaStreamInterface* stream) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000683
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700684 // Triggered when a remote peer opens a data channel.
685 virtual void OnDataChannel(
686 rtc::scoped_refptr<DataChannelInterface> data_channel){};
687 // Deprecated; please use the version that uses a scoped_refptr.
688 virtual void OnDataChannel(DataChannelInterface* data_channel) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000689
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700690 // Triggered when renegotiation is needed. For example, an ICE restart
691 // has begun.
fischman@webrtc.orgd7568a02014-01-13 22:04:12 +0000692 virtual void OnRenegotiationNeeded() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700694 // Called any time the IceConnectionState changes.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000695 virtual void OnIceConnectionChange(
perkjdfb769d2016-02-09 03:09:43 -0800696 PeerConnectionInterface::IceConnectionState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700698 // Called any time the IceGatheringState changes.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000699 virtual void OnIceGatheringChange(
perkjdfb769d2016-02-09 03:09:43 -0800700 PeerConnectionInterface::IceGatheringState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700702 // A new ICE candidate has been gathered.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000703 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
704
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700705 // Ice candidates have been removed.
706 // TODO(honghaiz): Make this a pure virtual method when all its subclasses
707 // implement it.
708 virtual void OnIceCandidatesRemoved(
709 const std::vector<cricket::Candidate>& candidates) {}
710
Peter Thatcher54360512015-07-08 11:08:35 -0700711 // Called when the ICE connection receiving status changes.
712 virtual void OnIceConnectionReceivingChange(bool receiving) {}
713
zhihuang81c3a032016-11-17 12:06:24 -0800714 // Called when a track is added to streams.
715 // TODO(zhihuang) Make this a pure virtual method when all its subclasses
716 // implement it.
717 virtual void OnAddTrack(
718 rtc::scoped_refptr<RtpReceiverInterface> receiver,
zhihuangc63b8942016-12-02 15:41:10 -0800719 const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) {}
zhihuang81c3a032016-11-17 12:06:24 -0800720
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 protected:
722 // Dtor protected as objects shouldn't be deleted via this interface.
723 ~PeerConnectionObserver() {}
724};
725
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726// PeerConnectionFactoryInterface is the factory interface use for creating
727// PeerConnection, MediaStream and media tracks.
728// PeerConnectionFactoryInterface will create required libjingle threads,
729// socket and network manager factory classes for networking.
730// If an application decides to provide its own threads and network
731// implementation of these classes it should use the alternate
732// CreatePeerConnectionFactory method which accepts threads as input and use the
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800733// CreatePeerConnection version that takes a PortAllocator as an
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734// argument.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000735class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 public:
wu@webrtc.org97077a32013-10-25 21:18:33 +0000737 class Options {
738 public:
Guo-wei Shieha7446d22016-01-11 15:27:03 -0800739 Options()
740 : disable_encryption(false),
741 disable_sctp_data_channels(false),
742 disable_network_monitor(false),
743 network_ignore_mask(rtc::kDefaultNetworkIgnoreMask),
jbauchcb560652016-08-04 05:20:32 -0700744 ssl_max_version(rtc::SSL_PROTOCOL_DTLS_12),
745 crypto_options(rtc::CryptoOptions::NoGcm()) {}
wu@webrtc.org97077a32013-10-25 21:18:33 +0000746 bool disable_encryption;
747 bool disable_sctp_data_channels;
honghaiz023f3ef2015-10-19 09:39:32 -0700748 bool disable_network_monitor;
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000749
750 // Sets the network types to ignore. For instance, calling this with
751 // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
752 // loopback interfaces.
753 int network_ignore_mask;
Joachim Bauch04e5b492015-05-29 09:40:39 +0200754
755 // Sets the maximum supported protocol version. The highest version
756 // supported by both ends will be used for the connection, i.e. if one
757 // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used.
758 rtc::SSLProtocolVersion ssl_max_version;
jbauchcb560652016-08-04 05:20:32 -0700759
760 // Sets crypto related options, e.g. enabled cipher suites.
761 rtc::CryptoOptions crypto_options;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000762 };
763
764 virtual void SetOptions(const Options& options) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000765
deadbeef41b07982015-12-01 15:01:24 -0800766 virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
767 const PeerConnectionInterface::RTCConfiguration& configuration,
768 const MediaConstraintsInterface* constraints,
kwibergd1fe2812016-04-27 06:47:29 -0700769 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200770 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
hbosd7973cc2016-05-27 06:08:53 -0700771 PeerConnectionObserver* observer) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000772
htaa2a49d92016-03-04 02:51:39 -0800773 virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
774 const PeerConnectionInterface::RTCConfiguration& configuration,
kwibergd1fe2812016-04-27 06:47:29 -0700775 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200776 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
hbosd7973cc2016-05-27 06:08:53 -0700777 PeerConnectionObserver* observer) = 0;
htaa2a49d92016-03-04 02:51:39 -0800778
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000779 virtual rtc::scoped_refptr<MediaStreamInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780 CreateLocalMediaStream(const std::string& label) = 0;
781
782 // Creates a AudioSourceInterface.
783 // |constraints| decides audio processing settings but can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000784 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
htaa2a49d92016-03-04 02:51:39 -0800785 const cricket::AudioOptions& options) = 0;
786 // Deprecated - use version above.
787 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 const MediaConstraintsInterface* constraints) = 0;
789
perkja3ede6c2016-03-08 01:27:48 +0100790 // Creates a VideoTrackSourceInterface. The new source take ownership of
htaa2a49d92016-03-04 02:51:39 -0800791 // |capturer|.
perkja3ede6c2016-03-08 01:27:48 +0100792 virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
htaa2a49d92016-03-04 02:51:39 -0800793 cricket::VideoCapturer* capturer) = 0;
794 // A video source creator that allows selection of resolution and frame rate.
795 // |constraints| decides video resolution and frame rate but can
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 // be NULL.
htaa2a49d92016-03-04 02:51:39 -0800797 // In the NULL case, use the version above.
perkja3ede6c2016-03-08 01:27:48 +0100798 virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 cricket::VideoCapturer* capturer,
800 const MediaConstraintsInterface* constraints) = 0;
801
802 // Creates a new local VideoTrack. The same |source| can be used in several
803 // tracks.
perkja3ede6c2016-03-08 01:27:48 +0100804 virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
805 const std::string& label,
806 VideoTrackSourceInterface* source) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807
808 // Creates an new AudioTrack. At the moment |source| can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000809 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810 CreateAudioTrack(const std::string& label,
811 AudioSourceInterface* source) = 0;
812
wu@webrtc.orga9890802013-12-13 00:21:03 +0000813 // Starts AEC dump using existing file. Takes ownership of |file| and passes
814 // it on to VoiceEngine (via other objects) immediately, which will take
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000815 // the ownerhip. If the operation fails, the file will be closed.
ivocd66b44d2016-01-15 03:06:36 -0800816 // A maximum file size in bytes can be specified. When the file size limit is
817 // reached, logging is stopped automatically. If max_size_bytes is set to a
818 // value <= 0, no limit will be used, and logging will continue until the
819 // StopAecDump function is called.
820 virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000821
ivoc797ef122015-10-22 03:25:41 -0700822 // Stops logging the AEC dump.
823 virtual void StopAecDump() = 0;
824
ivoc14d5dbe2016-07-04 07:06:55 -0700825 // This function is deprecated and will be removed when Chrome is updated to
826 // use the equivalent function on PeerConnectionInterface.
827 // TODO(ivoc) Remove after Chrome is updated.
ivocc1513ee2016-05-13 08:30:39 -0700828 virtual bool StartRtcEventLog(rtc::PlatformFile file,
829 int64_t max_size_bytes) = 0;
ivoc14d5dbe2016-07-04 07:06:55 -0700830 // This function is deprecated and will be removed when Chrome is updated to
831 // use the equivalent function on PeerConnectionInterface.
832 // TODO(ivoc) Remove after Chrome is updated.
ivoc112a3d82015-10-16 02:22:18 -0700833 virtual bool StartRtcEventLog(rtc::PlatformFile file) = 0;
834
ivoc14d5dbe2016-07-04 07:06:55 -0700835 // This function is deprecated and will be removed when Chrome is updated to
836 // use the equivalent function on PeerConnectionInterface.
837 // TODO(ivoc) Remove after Chrome is updated.
ivoc112a3d82015-10-16 02:22:18 -0700838 virtual void StopRtcEventLog() = 0;
839
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 protected:
841 // Dtor and ctor protected as objects shouldn't be created or deleted via
842 // this interface.
843 PeerConnectionFactoryInterface() {}
844 ~PeerConnectionFactoryInterface() {} // NOLINT
845};
846
847// Create a new instance of PeerConnectionFactoryInterface.
Taylor Brandstettera8415fe2016-03-23 10:38:07 -0700848//
849// This method relies on the thread it's called on as the "signaling thread"
850// for the PeerConnectionFactory it creates.
851//
852// As such, if the current thread is not already running an rtc::Thread message
853// loop, an application using this method must eventually either call
854// rtc::Thread::Current()->Run(), or call
855// rtc::Thread::Current()->ProcessMessages() within the application's own
856// message loop.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000857rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858CreatePeerConnectionFactory();
859
860// Create a new instance of PeerConnectionFactoryInterface.
Taylor Brandstettera8415fe2016-03-23 10:38:07 -0700861//
danilchape9021a32016-05-17 01:52:02 -0700862// |network_thread|, |worker_thread| and |signaling_thread| are
863// the only mandatory parameters.
Taylor Brandstettera8415fe2016-03-23 10:38:07 -0700864//
865// If non-null, ownership of |default_adm|, |encoder_factory| and
866// |decoder_factory| are transferred to the returned factory.
danilchape9021a32016-05-17 01:52:02 -0700867rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
868 rtc::Thread* network_thread,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000869 rtc::Thread* worker_thread,
870 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 AudioDeviceModule* default_adm,
872 cricket::WebRtcVideoEncoderFactory* encoder_factory,
873 cricket::WebRtcVideoDecoderFactory* decoder_factory);
874
gyzhou95aa9642016-12-13 14:06:26 -0800875// Create a new instance of PeerConnectionFactoryInterface with external audio
876// mixer.
877//
878// If |audio_mixer| is null, an internal audio mixer will be created and used.
879rtc::scoped_refptr<PeerConnectionFactoryInterface>
880CreatePeerConnectionFactoryWithAudioMixer(
881 rtc::Thread* network_thread,
882 rtc::Thread* worker_thread,
883 rtc::Thread* signaling_thread,
884 AudioDeviceModule* default_adm,
885 cricket::WebRtcVideoEncoderFactory* encoder_factory,
886 cricket::WebRtcVideoDecoderFactory* decoder_factory,
887 rtc::scoped_refptr<AudioMixer> audio_mixer);
888
danilchape9021a32016-05-17 01:52:02 -0700889// Create a new instance of PeerConnectionFactoryInterface.
890// Same thread is used as worker and network thread.
danilchape9021a32016-05-17 01:52:02 -0700891inline rtc::scoped_refptr<PeerConnectionFactoryInterface>
892CreatePeerConnectionFactory(
893 rtc::Thread* worker_and_network_thread,
894 rtc::Thread* signaling_thread,
895 AudioDeviceModule* default_adm,
896 cricket::WebRtcVideoEncoderFactory* encoder_factory,
897 cricket::WebRtcVideoDecoderFactory* decoder_factory) {
898 return CreatePeerConnectionFactory(
899 worker_and_network_thread, worker_and_network_thread, signaling_thread,
900 default_adm, encoder_factory, decoder_factory);
901}
902
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903} // namespace webrtc
904
Henrik Kjellander15583c12016-02-10 10:53:12 +0100905#endif // WEBRTC_API_PEERCONNECTIONINTERFACE_H_