blob: f6c8cbaf00bd0d93b2b7c60cd13506928b9a9de5 [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
54#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080055#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056#include <vector>
57
Henrik Kjellander15583c12016-02-10 10:53:12 +010058#include "webrtc/api/datachannelinterface.h"
59#include "webrtc/api/dtlsidentitystore.h"
60#include "webrtc/api/dtlsidentitystore.h"
61#include "webrtc/api/dtmfsenderinterface.h"
62#include "webrtc/api/jsep.h"
63#include "webrtc/api/mediastreaminterface.h"
64#include "webrtc/api/rtpreceiverinterface.h"
65#include "webrtc/api/rtpsenderinterface.h"
66#include "webrtc/api/statstypes.h"
67#include "webrtc/api/umametrics.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000068#include "webrtc/base/fileutils.h"
phoglund@webrtc.org006521d2015-02-12 09:23:59 +000069#include "webrtc/base/network.h"
Henrik Boström87713d02015-08-25 09:53:21 +020070#include "webrtc/base/rtccertificate.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000071#include "webrtc/base/socketaddress.h"
kjellandera96e2d72016-02-04 23:52:28 -080072#include "webrtc/base/sslstreamadapter.h"
deadbeef41b07982015-12-01 15:01:24 -080073#include "webrtc/p2p/base/portallocator.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000075namespace rtc {
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000076class SSLIdentity;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077class Thread;
78}
79
80namespace cricket {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081class WebRtcVideoDecoderFactory;
82class WebRtcVideoEncoderFactory;
83}
84
85namespace webrtc {
86class AudioDeviceModule;
87class MediaConstraintsInterface;
88
89// MediaStream container interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000090class StreamCollectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091 public:
92 // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find.
93 virtual size_t count() = 0;
94 virtual MediaStreamInterface* at(size_t index) = 0;
95 virtual MediaStreamInterface* find(const std::string& label) = 0;
96 virtual MediaStreamTrackInterface* FindAudioTrack(
97 const std::string& id) = 0;
98 virtual MediaStreamTrackInterface* FindVideoTrack(
99 const std::string& id) = 0;
100
101 protected:
102 // Dtor protected as objects shouldn't be deleted via this interface.
103 ~StreamCollectionInterface() {}
104};
105
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000106class StatsObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107 public:
tommi@webrtc.orge2e199b2014-12-15 13:22:54 +0000108 virtual void OnComplete(const StatsReports& reports) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109
110 protected:
111 virtual ~StatsObserver() {}
112};
113
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000114class MetricsObserverInterface : public rtc::RefCountInterface {
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000115 public:
Guo-wei Shieh3d564c12015-08-19 16:51:15 -0700116
117 // |type| is the type of the enum counter to be incremented. |counter|
118 // is the particular counter in that type. |counter_max| is the next sequence
119 // number after the highest counter.
120 virtual void IncrementEnumCounter(PeerConnectionEnumCounterType type,
121 int counter,
122 int counter_max) {}
123
Guo-wei Shieh456696a2015-09-30 21:48:54 -0700124 // This is used to handle sparse counters like SSL cipher suites.
125 // TODO(guoweis): Remove the implementation once the dependency's interface
126 // definition is updated.
127 virtual void IncrementSparseEnumCounter(PeerConnectionEnumCounterType type,
128 int counter) {
129 IncrementEnumCounter(type, counter, 0 /* Ignored */);
130 }
131
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000132 virtual void AddHistogramSample(PeerConnectionMetricsName type,
mallinath@webrtc.orgd37bcfa2014-05-12 23:10:18 +0000133 int value) = 0;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000134
135 protected:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000136 virtual ~MetricsObserverInterface() {}
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000137};
138
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000139typedef MetricsObserverInterface UMAObserver;
140
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000141class PeerConnectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142 public:
143 // See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions .
144 enum SignalingState {
145 kStable,
146 kHaveLocalOffer,
147 kHaveLocalPrAnswer,
148 kHaveRemoteOffer,
149 kHaveRemotePrAnswer,
150 kClosed,
151 };
152
153 // TODO(bemasc): Remove IceState when callers are changed to
154 // IceConnection/GatheringState.
155 enum IceState {
156 kIceNew,
157 kIceGathering,
158 kIceWaiting,
159 kIceChecking,
160 kIceConnected,
161 kIceCompleted,
162 kIceFailed,
163 kIceClosed,
164 };
165
166 enum IceGatheringState {
167 kIceGatheringNew,
168 kIceGatheringGathering,
169 kIceGatheringComplete
170 };
171
172 enum IceConnectionState {
173 kIceConnectionNew,
174 kIceConnectionChecking,
175 kIceConnectionConnected,
176 kIceConnectionCompleted,
177 kIceConnectionFailed,
178 kIceConnectionDisconnected,
179 kIceConnectionClosed,
Guo-wei Shieh3d564c12015-08-19 16:51:15 -0700180 kIceConnectionMax,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 };
182
183 struct IceServer {
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200184 // TODO(jbauch): Remove uri when all code using it has switched to urls.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 std::string uri;
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200186 std::vector<std::string> urls;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 std::string username;
188 std::string password;
189 };
190 typedef std::vector<IceServer> IceServers;
191
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000192 enum IceTransportsType {
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000193 // TODO(pthatcher): Rename these kTransporTypeXXX, but update
194 // Chromium at the same time.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000195 kNone,
196 kRelay,
197 kNoHost,
198 kAll
199 };
200
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000201 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-08#section-4.1.1
202 enum BundlePolicy {
203 kBundlePolicyBalanced,
204 kBundlePolicyMaxBundle,
205 kBundlePolicyMaxCompat
206 };
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000207
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700208 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-09#section-4.1.1
209 enum RtcpMuxPolicy {
210 kRtcpMuxPolicyNegotiate,
211 kRtcpMuxPolicyRequire,
212 };
213
Jiayang Liucac1b382015-04-30 12:35:24 -0700214 enum TcpCandidatePolicy {
215 kTcpCandidatePolicyEnabled,
216 kTcpCandidatePolicyDisabled
217 };
218
honghaiz1f429e32015-09-28 07:57:34 -0700219 enum ContinualGatheringPolicy {
220 GATHER_ONCE,
221 GATHER_CONTINUALLY
222 };
223
Henrik Boström87713d02015-08-25 09:53:21 +0200224 // TODO(hbos): Change into class with private data and public getters.
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000225 struct RTCConfiguration {
honghaiz4edc39c2015-09-01 09:53:56 -0700226 static const int kUndefined = -1;
227 // Default maximum number of packets in the audio jitter buffer.
228 static const int kAudioJitterBufferMaxPackets = 50;
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000229 // TODO(pthatcher): Rename this ice_transport_type, but update
230 // Chromium at the same time.
231 IceTransportsType type;
232 // TODO(pthatcher): Rename this ice_servers, but update Chromium
233 // at the same time.
234 IceServers servers;
235 BundlePolicy bundle_policy;
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700236 RtcpMuxPolicy rtcp_mux_policy;
Jiayang Liucac1b382015-04-30 12:35:24 -0700237 TcpCandidatePolicy tcp_candidate_policy;
Henrik Lundin64dad832015-05-11 12:44:23 +0200238 int audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200239 bool audio_jitter_buffer_fast_accelerate;
Honghai Zhang381b4212015-12-04 12:24:03 -0800240 int ice_connection_receiving_timeout; // ms
241 int ice_backup_candidate_pair_ping_interval; // ms
honghaiz1f429e32015-09-28 07:57:34 -0700242 ContinualGatheringPolicy continual_gathering_policy;
Henrik Boström87713d02015-08-25 09:53:21 +0200243 std::vector<rtc::scoped_refptr<rtc::RTCCertificate>> certificates;
qiangchen444682a2015-11-24 18:07:56 -0800244 bool disable_prerenderer_smoothing;
guoweis36f01372016-03-02 18:02:40 -0800245 bool prioritize_most_likely_ice_candidate_pairs;
htaa2a49d92016-03-04 02:51:39 -0800246 // Flags corresponding to values set by constraint flags.
247 // rtc::Optional flags can be "missing", in which case the webrtc
248 // default applies.
249 bool disable_ipv6;
250 rtc::Optional<bool> enable_dscp;
251 bool enable_rtp_data_channel;
252 rtc::Optional<bool> cpu_overuse_detection;
253 rtc::Optional<bool> suspend_below_min_bitrate;
254 rtc::Optional<int> screencast_min_bitrate;
255 rtc::Optional<bool> combined_audio_video_bwe;
256 rtc::Optional<bool> enable_dtls_srtp;
Jiayang Liucac1b382015-04-30 12:35:24 -0700257 RTCConfiguration()
258 : type(kAll),
259 bundle_policy(kBundlePolicyBalanced),
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700260 rtcp_mux_policy(kRtcpMuxPolicyNegotiate),
Henrik Lundin64dad832015-05-11 12:44:23 +0200261 tcp_candidate_policy(kTcpCandidatePolicyEnabled),
honghaiz4edc39c2015-09-01 09:53:56 -0700262 audio_jitter_buffer_max_packets(kAudioJitterBufferMaxPackets),
263 audio_jitter_buffer_fast_accelerate(false),
honghaiz1f429e32015-09-28 07:57:34 -0700264 ice_connection_receiving_timeout(kUndefined),
Honghai Zhang381b4212015-12-04 12:24:03 -0800265 ice_backup_candidate_pair_ping_interval(kUndefined),
qiangchen444682a2015-11-24 18:07:56 -0800266 continual_gathering_policy(GATHER_ONCE),
guoweis36f01372016-03-02 18:02:40 -0800267 disable_prerenderer_smoothing(false),
htaa2a49d92016-03-04 02:51:39 -0800268 prioritize_most_likely_ice_candidate_pairs(false),
269 disable_ipv6(false),
270 enable_rtp_data_channel(false) {}
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000271 };
272
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000273 struct RTCOfferAnswerOptions {
274 static const int kUndefined = -1;
275 static const int kMaxOfferToReceiveMedia = 1;
276
277 // The default value for constraint offerToReceiveX:true.
278 static const int kOfferToReceiveMediaTrue = 1;
279
280 int offer_to_receive_video;
281 int offer_to_receive_audio;
282 bool voice_activity_detection;
283 bool ice_restart;
284 bool use_rtp_mux;
285
286 RTCOfferAnswerOptions()
287 : offer_to_receive_video(kUndefined),
288 offer_to_receive_audio(kUndefined),
289 voice_activity_detection(true),
290 ice_restart(false),
291 use_rtp_mux(true) {}
292
293 RTCOfferAnswerOptions(int offer_to_receive_video,
294 int offer_to_receive_audio,
295 bool voice_activity_detection,
296 bool ice_restart,
297 bool use_rtp_mux)
298 : offer_to_receive_video(offer_to_receive_video),
299 offer_to_receive_audio(offer_to_receive_audio),
300 voice_activity_detection(voice_activity_detection),
301 ice_restart(ice_restart),
302 use_rtp_mux(use_rtp_mux) {}
303 };
304
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000305 // Used by GetStats to decide which stats to include in the stats reports.
306 // |kStatsOutputLevelStandard| includes the standard stats for Javascript API;
307 // |kStatsOutputLevelDebug| includes both the standard stats and additional
308 // stats for debugging purposes.
309 enum StatsOutputLevel {
310 kStatsOutputLevelStandard,
311 kStatsOutputLevelDebug,
312 };
313
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000314 // Accessor methods to active local streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000315 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 local_streams() = 0;
317
318 // Accessor methods to remote streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000319 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320 remote_streams() = 0;
321
322 // Add a new MediaStream to be sent on this PeerConnection.
323 // Note that a SessionDescription negotiation is needed before the
324 // remote peer can receive the stream.
perkj@webrtc.orgfd0efb62014-11-06 12:16:36 +0000325 virtual bool AddStream(MediaStreamInterface* stream) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326
327 // Remove a MediaStream from this PeerConnection.
328 // Note that a SessionDescription negotiation is need before the
329 // remote peer is notified.
330 virtual void RemoveStream(MediaStreamInterface* stream) = 0;
331
deadbeefe1f9d832016-01-14 15:35:42 -0800332 // TODO(deadbeef): Make the following two methods pure virtual once
333 // implemented by all subclasses of PeerConnectionInterface.
334 // Add a new MediaStreamTrack to be sent on this PeerConnection.
335 // |streams| indicates which stream labels the track should be associated
336 // with.
337 virtual rtc::scoped_refptr<RtpSenderInterface> AddTrack(
338 MediaStreamTrackInterface* track,
339 std::vector<MediaStreamInterface*> streams) {
340 return nullptr;
341 }
342
343 // Remove an RtpSender from this PeerConnection.
344 // Returns true on success.
345 virtual bool RemoveTrack(RtpSenderInterface* sender) {
346 return false;
347 }
348
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 // Returns pointer to the created DtmfSender on success.
350 // Otherwise returns NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000351 virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 AudioTrackInterface* track) = 0;
353
deadbeef70ab1a12015-09-28 16:53:55 -0700354 // TODO(deadbeef): Make these pure virtual once all subclasses implement them.
deadbeeffac06552015-11-25 11:26:01 -0800355 // |kind| must be "audio" or "video".
deadbeefbd7d8f72015-12-18 16:58:44 -0800356 // |stream_id| is used to populate the msid attribute; if empty, one will
357 // be generated automatically.
deadbeeffac06552015-11-25 11:26:01 -0800358 virtual rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -0800359 const std::string& kind,
360 const std::string& stream_id) {
deadbeeffac06552015-11-25 11:26:01 -0800361 return rtc::scoped_refptr<RtpSenderInterface>();
362 }
363
deadbeef70ab1a12015-09-28 16:53:55 -0700364 virtual std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
365 const {
366 return std::vector<rtc::scoped_refptr<RtpSenderInterface>>();
367 }
368
369 virtual std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
370 const {
371 return std::vector<rtc::scoped_refptr<RtpReceiverInterface>>();
372 }
373
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000374 virtual bool GetStats(StatsObserver* observer,
375 MediaStreamTrackInterface* track,
376 StatsOutputLevel level) = 0;
377
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000378 virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 const std::string& label,
380 const DataChannelInit* config) = 0;
381
382 virtual const SessionDescriptionInterface* local_description() const = 0;
383 virtual const SessionDescriptionInterface* remote_description() const = 0;
384
385 // Create a new offer.
386 // The CreateSessionDescriptionObserver callback will be called when done.
387 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000388 const MediaConstraintsInterface* constraints) {}
389
390 // TODO(jiayl): remove the default impl and the old interface when chromium
391 // code is updated.
392 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
393 const RTCOfferAnswerOptions& options) {}
394
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000395 // Create an answer to an offer.
396 // The CreateSessionDescriptionObserver callback will be called when done.
397 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
htaa2a49d92016-03-04 02:51:39 -0800398 const RTCOfferAnswerOptions& options) {}
399 // Deprecated - use version above.
400 // TODO(hta): Remove and remove default implementations when all callers
401 // are updated.
402 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
403 const MediaConstraintsInterface* constraints) {}
404
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405 // Sets the local session description.
406 // JsepInterface takes the ownership of |desc| even if it fails.
407 // The |observer| callback will be called when done.
408 virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
409 SessionDescriptionInterface* desc) = 0;
410 // Sets the remote session description.
411 // JsepInterface takes the ownership of |desc| even if it fails.
412 // The |observer| callback will be called when done.
413 virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
414 SessionDescriptionInterface* desc) = 0;
415 // Restarts or updates the ICE Agent process of gathering local candidates
416 // and pinging remote candidates.
deadbeefa67696b2015-09-29 11:56:26 -0700417 // TODO(deadbeef): Remove once Chrome is moved over to SetConfiguration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418 virtual bool UpdateIce(const IceServers& configuration,
deadbeefa67696b2015-09-29 11:56:26 -0700419 const MediaConstraintsInterface* constraints) {
420 return false;
421 }
htaa2a49d92016-03-04 02:51:39 -0800422 virtual bool UpdateIce(const IceServers& configuration) { return false; }
deadbeefa67696b2015-09-29 11:56:26 -0700423 // Sets the PeerConnection's global configuration to |config|.
424 // Any changes to STUN/TURN servers or ICE candidate policy will affect the
425 // next gathering phase, and cause the next call to createOffer to generate
426 // new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies
427 // cannot be changed with this method.
428 // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of
429 // PeerConnectionInterface implement it.
430 virtual bool SetConfiguration(
431 const PeerConnectionInterface::RTCConfiguration& config) {
432 return false;
433 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434 // Provides a remote candidate to the ICE Agent.
435 // A copy of the |candidate| will be created and added to the remote
436 // description. So the caller of this method still has the ownership of the
437 // |candidate|.
438 // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will
439 // take the ownership of the |candidate|.
440 virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
441
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000442 virtual void RegisterUMAObserver(UMAObserver* observer) = 0;
443
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000444 // Returns the current SignalingState.
445 virtual SignalingState signaling_state() = 0;
446
447 // TODO(bemasc): Remove ice_state when callers are changed to
448 // IceConnection/GatheringState.
449 // Returns the current IceState.
450 virtual IceState ice_state() = 0;
451 virtual IceConnectionState ice_connection_state() = 0;
452 virtual IceGatheringState ice_gathering_state() = 0;
453
454 // Terminates all media and closes the transport.
455 virtual void Close() = 0;
456
457 protected:
458 // Dtor protected as objects shouldn't be deleted via this interface.
459 ~PeerConnectionInterface() {}
460};
461
462// PeerConnection callback interface. Application should implement these
463// methods.
464class PeerConnectionObserver {
465 public:
466 enum StateType {
467 kSignalingState,
468 kIceState,
469 };
470
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000471 // Triggered when the SignalingState changed.
472 virtual void OnSignalingChange(
perkjdfb769d2016-02-09 03:09:43 -0800473 PeerConnectionInterface::SignalingState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000474
475 // Triggered when media is received on a new stream from remote peer.
476 virtual void OnAddStream(MediaStreamInterface* stream) = 0;
477
478 // Triggered when a remote peer close a stream.
479 virtual void OnRemoveStream(MediaStreamInterface* stream) = 0;
480
481 // Triggered when a remote peer open a data channel.
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000482 virtual void OnDataChannel(DataChannelInterface* data_channel) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483
mallinath@webrtc.org0d92ef62014-01-22 02:21:22 +0000484 // Triggered when renegotiation is needed, for example the ICE has restarted.
fischman@webrtc.orgd7568a02014-01-13 22:04:12 +0000485 virtual void OnRenegotiationNeeded() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000486
487 // Called any time the IceConnectionState changes
488 virtual void OnIceConnectionChange(
perkjdfb769d2016-02-09 03:09:43 -0800489 PeerConnectionInterface::IceConnectionState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000490
491 // Called any time the IceGatheringState changes
492 virtual void OnIceGatheringChange(
perkjdfb769d2016-02-09 03:09:43 -0800493 PeerConnectionInterface::IceGatheringState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494
495 // New Ice candidate have been found.
496 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
497
Peter Thatcher54360512015-07-08 11:08:35 -0700498 // Called when the ICE connection receiving status changes.
499 virtual void OnIceConnectionReceivingChange(bool receiving) {}
500
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000501 protected:
502 // Dtor protected as objects shouldn't be deleted via this interface.
503 ~PeerConnectionObserver() {}
504};
505
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000506// PeerConnectionFactoryInterface is the factory interface use for creating
507// PeerConnection, MediaStream and media tracks.
508// PeerConnectionFactoryInterface will create required libjingle threads,
509// socket and network manager factory classes for networking.
510// If an application decides to provide its own threads and network
511// implementation of these classes it should use the alternate
512// CreatePeerConnectionFactory method which accepts threads as input and use the
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800513// CreatePeerConnection version that takes a PortAllocator as an
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000514// argument.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000515class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000516 public:
wu@webrtc.org97077a32013-10-25 21:18:33 +0000517 class Options {
518 public:
Guo-wei Shieha7446d22016-01-11 15:27:03 -0800519 Options()
520 : disable_encryption(false),
521 disable_sctp_data_channels(false),
522 disable_network_monitor(false),
523 network_ignore_mask(rtc::kDefaultNetworkIgnoreMask),
524 ssl_max_version(rtc::SSL_PROTOCOL_DTLS_12) {}
wu@webrtc.org97077a32013-10-25 21:18:33 +0000525 bool disable_encryption;
526 bool disable_sctp_data_channels;
honghaiz023f3ef2015-10-19 09:39:32 -0700527 bool disable_network_monitor;
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000528
529 // Sets the network types to ignore. For instance, calling this with
530 // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
531 // loopback interfaces.
532 int network_ignore_mask;
Joachim Bauch04e5b492015-05-29 09:40:39 +0200533
534 // Sets the maximum supported protocol version. The highest version
535 // supported by both ends will be used for the connection, i.e. if one
536 // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used.
537 rtc::SSLProtocolVersion ssl_max_version;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000538 };
539
540 virtual void SetOptions(const Options& options) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000541
deadbeef41b07982015-12-01 15:01:24 -0800542 virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
543 const PeerConnectionInterface::RTCConfiguration& configuration,
544 const MediaConstraintsInterface* constraints,
545 rtc::scoped_ptr<cricket::PortAllocator> allocator,
546 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800547 PeerConnectionObserver* observer) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000548
htaa2a49d92016-03-04 02:51:39 -0800549 virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
550 const PeerConnectionInterface::RTCConfiguration& configuration,
551 rtc::scoped_ptr<cricket::PortAllocator> allocator,
552 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
553 PeerConnectionObserver* observer) = 0;
554
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000555 virtual rtc::scoped_refptr<MediaStreamInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 CreateLocalMediaStream(const std::string& label) = 0;
557
558 // Creates a AudioSourceInterface.
559 // |constraints| decides audio processing settings but can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000560 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
htaa2a49d92016-03-04 02:51:39 -0800561 const cricket::AudioOptions& options) = 0;
562 // Deprecated - use version above.
563 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564 const MediaConstraintsInterface* constraints) = 0;
565
perkja3ede6c2016-03-08 01:27:48 +0100566 // Creates a VideoTrackSourceInterface. The new source take ownership of
htaa2a49d92016-03-04 02:51:39 -0800567 // |capturer|.
perkja3ede6c2016-03-08 01:27:48 +0100568 virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
htaa2a49d92016-03-04 02:51:39 -0800569 cricket::VideoCapturer* capturer) = 0;
570 // A video source creator that allows selection of resolution and frame rate.
571 // |constraints| decides video resolution and frame rate but can
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 // be NULL.
htaa2a49d92016-03-04 02:51:39 -0800573 // In the NULL case, use the version above.
perkja3ede6c2016-03-08 01:27:48 +0100574 virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 cricket::VideoCapturer* capturer,
576 const MediaConstraintsInterface* constraints) = 0;
577
578 // Creates a new local VideoTrack. The same |source| can be used in several
579 // tracks.
perkja3ede6c2016-03-08 01:27:48 +0100580 virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
581 const std::string& label,
582 VideoTrackSourceInterface* source) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583
584 // Creates an new AudioTrack. At the moment |source| can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000585 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000586 CreateAudioTrack(const std::string& label,
587 AudioSourceInterface* source) = 0;
588
wu@webrtc.orga9890802013-12-13 00:21:03 +0000589 // Starts AEC dump using existing file. Takes ownership of |file| and passes
590 // it on to VoiceEngine (via other objects) immediately, which will take
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000591 // the ownerhip. If the operation fails, the file will be closed.
ivocd66b44d2016-01-15 03:06:36 -0800592 // A maximum file size in bytes can be specified. When the file size limit is
593 // reached, logging is stopped automatically. If max_size_bytes is set to a
594 // value <= 0, no limit will be used, and logging will continue until the
595 // StopAecDump function is called.
596 virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000597
ivoc797ef122015-10-22 03:25:41 -0700598 // Stops logging the AEC dump.
599 virtual void StopAecDump() = 0;
600
ivoc112a3d82015-10-16 02:22:18 -0700601 // Starts RtcEventLog using existing file. Takes ownership of |file| and
602 // passes it on to VoiceEngine, which will take the ownership. If the
603 // operation fails the file will be closed. The logging will stop
604 // automatically after 10 minutes have passed, or when the StopRtcEventLog
605 // function is called.
606 // This function as well as the StopRtcEventLog don't really belong on this
607 // interface, this is a temporary solution until we move the logging object
608 // from inside voice engine to webrtc::Call, which will happen when the VoE
609 // restructuring effort is further along.
610 // TODO(ivoc): Move this into being:
611 // PeerConnection => MediaController => webrtc::Call.
612 virtual bool StartRtcEventLog(rtc::PlatformFile file) = 0;
613
614 // Stops logging the RtcEventLog.
615 virtual void StopRtcEventLog() = 0;
616
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000617 protected:
618 // Dtor and ctor protected as objects shouldn't be created or deleted via
619 // this interface.
620 PeerConnectionFactoryInterface() {}
621 ~PeerConnectionFactoryInterface() {} // NOLINT
622};
623
624// Create a new instance of PeerConnectionFactoryInterface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000625rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626CreatePeerConnectionFactory();
627
628// Create a new instance of PeerConnectionFactoryInterface.
629// Ownership of |factory|, |default_adm|, and optionally |encoder_factory| and
630// |decoder_factory| transferred to the returned factory.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000631rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632CreatePeerConnectionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000633 rtc::Thread* worker_thread,
634 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000635 AudioDeviceModule* default_adm,
636 cricket::WebRtcVideoEncoderFactory* encoder_factory,
637 cricket::WebRtcVideoDecoderFactory* decoder_factory);
638
639} // namespace webrtc
640
Henrik Kjellander15583c12016-02-10 10:53:12 +0100641#endif // WEBRTC_API_PEERCONNECTIONINTERFACE_H_