blob: 78635e4a56390953917c4b11eb3016b3dcb5f596 [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;
Jiayang Liucac1b382015-04-30 12:35:24 -0700245 RTCConfiguration()
246 : type(kAll),
247 bundle_policy(kBundlePolicyBalanced),
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700248 rtcp_mux_policy(kRtcpMuxPolicyNegotiate),
Henrik Lundin64dad832015-05-11 12:44:23 +0200249 tcp_candidate_policy(kTcpCandidatePolicyEnabled),
honghaiz4edc39c2015-09-01 09:53:56 -0700250 audio_jitter_buffer_max_packets(kAudioJitterBufferMaxPackets),
251 audio_jitter_buffer_fast_accelerate(false),
honghaiz1f429e32015-09-28 07:57:34 -0700252 ice_connection_receiving_timeout(kUndefined),
Honghai Zhang381b4212015-12-04 12:24:03 -0800253 ice_backup_candidate_pair_ping_interval(kUndefined),
qiangchen444682a2015-11-24 18:07:56 -0800254 continual_gathering_policy(GATHER_ONCE),
255 disable_prerenderer_smoothing(false) {}
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000256 };
257
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000258 struct RTCOfferAnswerOptions {
259 static const int kUndefined = -1;
260 static const int kMaxOfferToReceiveMedia = 1;
261
262 // The default value for constraint offerToReceiveX:true.
263 static const int kOfferToReceiveMediaTrue = 1;
264
265 int offer_to_receive_video;
266 int offer_to_receive_audio;
267 bool voice_activity_detection;
268 bool ice_restart;
269 bool use_rtp_mux;
270
271 RTCOfferAnswerOptions()
272 : offer_to_receive_video(kUndefined),
273 offer_to_receive_audio(kUndefined),
274 voice_activity_detection(true),
275 ice_restart(false),
276 use_rtp_mux(true) {}
277
278 RTCOfferAnswerOptions(int offer_to_receive_video,
279 int offer_to_receive_audio,
280 bool voice_activity_detection,
281 bool ice_restart,
282 bool use_rtp_mux)
283 : offer_to_receive_video(offer_to_receive_video),
284 offer_to_receive_audio(offer_to_receive_audio),
285 voice_activity_detection(voice_activity_detection),
286 ice_restart(ice_restart),
287 use_rtp_mux(use_rtp_mux) {}
288 };
289
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000290 // Used by GetStats to decide which stats to include in the stats reports.
291 // |kStatsOutputLevelStandard| includes the standard stats for Javascript API;
292 // |kStatsOutputLevelDebug| includes both the standard stats and additional
293 // stats for debugging purposes.
294 enum StatsOutputLevel {
295 kStatsOutputLevelStandard,
296 kStatsOutputLevelDebug,
297 };
298
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 // Accessor methods to active local streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000300 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301 local_streams() = 0;
302
303 // Accessor methods to remote streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000304 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 remote_streams() = 0;
306
307 // Add a new MediaStream to be sent on this PeerConnection.
308 // Note that a SessionDescription negotiation is needed before the
309 // remote peer can receive the stream.
perkj@webrtc.orgfd0efb62014-11-06 12:16:36 +0000310 virtual bool AddStream(MediaStreamInterface* stream) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311
312 // Remove a MediaStream from this PeerConnection.
313 // Note that a SessionDescription negotiation is need before the
314 // remote peer is notified.
315 virtual void RemoveStream(MediaStreamInterface* stream) = 0;
316
deadbeefe1f9d832016-01-14 15:35:42 -0800317 // TODO(deadbeef): Make the following two methods pure virtual once
318 // implemented by all subclasses of PeerConnectionInterface.
319 // Add a new MediaStreamTrack to be sent on this PeerConnection.
320 // |streams| indicates which stream labels the track should be associated
321 // with.
322 virtual rtc::scoped_refptr<RtpSenderInterface> AddTrack(
323 MediaStreamTrackInterface* track,
324 std::vector<MediaStreamInterface*> streams) {
325 return nullptr;
326 }
327
328 // Remove an RtpSender from this PeerConnection.
329 // Returns true on success.
330 virtual bool RemoveTrack(RtpSenderInterface* sender) {
331 return false;
332 }
333
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334 // Returns pointer to the created DtmfSender on success.
335 // Otherwise returns NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000336 virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337 AudioTrackInterface* track) = 0;
338
deadbeef70ab1a12015-09-28 16:53:55 -0700339 // TODO(deadbeef): Make these pure virtual once all subclasses implement them.
deadbeeffac06552015-11-25 11:26:01 -0800340 // |kind| must be "audio" or "video".
deadbeefbd7d8f72015-12-18 16:58:44 -0800341 // |stream_id| is used to populate the msid attribute; if empty, one will
342 // be generated automatically.
deadbeeffac06552015-11-25 11:26:01 -0800343 virtual rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -0800344 const std::string& kind,
345 const std::string& stream_id) {
deadbeeffac06552015-11-25 11:26:01 -0800346 return rtc::scoped_refptr<RtpSenderInterface>();
347 }
348
deadbeef70ab1a12015-09-28 16:53:55 -0700349 virtual std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
350 const {
351 return std::vector<rtc::scoped_refptr<RtpSenderInterface>>();
352 }
353
354 virtual std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
355 const {
356 return std::vector<rtc::scoped_refptr<RtpReceiverInterface>>();
357 }
358
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000359 virtual bool GetStats(StatsObserver* observer,
360 MediaStreamTrackInterface* track,
361 StatsOutputLevel level) = 0;
362
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000363 virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364 const std::string& label,
365 const DataChannelInit* config) = 0;
366
367 virtual const SessionDescriptionInterface* local_description() const = 0;
368 virtual const SessionDescriptionInterface* remote_description() const = 0;
369
370 // Create a new offer.
371 // The CreateSessionDescriptionObserver callback will be called when done.
372 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000373 const MediaConstraintsInterface* constraints) {}
374
375 // TODO(jiayl): remove the default impl and the old interface when chromium
376 // code is updated.
377 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
378 const RTCOfferAnswerOptions& options) {}
379
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 // Create an answer to an offer.
381 // The CreateSessionDescriptionObserver callback will be called when done.
382 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
383 const MediaConstraintsInterface* constraints) = 0;
384 // Sets the local session description.
385 // JsepInterface takes the ownership of |desc| even if it fails.
386 // The |observer| callback will be called when done.
387 virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
388 SessionDescriptionInterface* desc) = 0;
389 // Sets the remote session description.
390 // JsepInterface takes the ownership of |desc| even if it fails.
391 // The |observer| callback will be called when done.
392 virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
393 SessionDescriptionInterface* desc) = 0;
394 // Restarts or updates the ICE Agent process of gathering local candidates
395 // and pinging remote candidates.
deadbeefa67696b2015-09-29 11:56:26 -0700396 // TODO(deadbeef): Remove once Chrome is moved over to SetConfiguration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000397 virtual bool UpdateIce(const IceServers& configuration,
deadbeefa67696b2015-09-29 11:56:26 -0700398 const MediaConstraintsInterface* constraints) {
399 return false;
400 }
401 // Sets the PeerConnection's global configuration to |config|.
402 // Any changes to STUN/TURN servers or ICE candidate policy will affect the
403 // next gathering phase, and cause the next call to createOffer to generate
404 // new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies
405 // cannot be changed with this method.
406 // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of
407 // PeerConnectionInterface implement it.
408 virtual bool SetConfiguration(
409 const PeerConnectionInterface::RTCConfiguration& config) {
410 return false;
411 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412 // Provides a remote candidate to the ICE Agent.
413 // A copy of the |candidate| will be created and added to the remote
414 // description. So the caller of this method still has the ownership of the
415 // |candidate|.
416 // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will
417 // take the ownership of the |candidate|.
418 virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
419
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000420 virtual void RegisterUMAObserver(UMAObserver* observer) = 0;
421
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422 // Returns the current SignalingState.
423 virtual SignalingState signaling_state() = 0;
424
425 // TODO(bemasc): Remove ice_state when callers are changed to
426 // IceConnection/GatheringState.
427 // Returns the current IceState.
428 virtual IceState ice_state() = 0;
429 virtual IceConnectionState ice_connection_state() = 0;
430 virtual IceGatheringState ice_gathering_state() = 0;
431
432 // Terminates all media and closes the transport.
433 virtual void Close() = 0;
434
435 protected:
436 // Dtor protected as objects shouldn't be deleted via this interface.
437 ~PeerConnectionInterface() {}
438};
439
440// PeerConnection callback interface. Application should implement these
441// methods.
442class PeerConnectionObserver {
443 public:
444 enum StateType {
445 kSignalingState,
446 kIceState,
447 };
448
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449 // Triggered when the SignalingState changed.
450 virtual void OnSignalingChange(
perkjdfb769d2016-02-09 03:09:43 -0800451 PeerConnectionInterface::SignalingState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452
453 // Triggered when media is received on a new stream from remote peer.
454 virtual void OnAddStream(MediaStreamInterface* stream) = 0;
455
456 // Triggered when a remote peer close a stream.
457 virtual void OnRemoveStream(MediaStreamInterface* stream) = 0;
458
459 // Triggered when a remote peer open a data channel.
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000460 virtual void OnDataChannel(DataChannelInterface* data_channel) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461
mallinath@webrtc.org0d92ef62014-01-22 02:21:22 +0000462 // Triggered when renegotiation is needed, for example the ICE has restarted.
fischman@webrtc.orgd7568a02014-01-13 22:04:12 +0000463 virtual void OnRenegotiationNeeded() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000464
465 // Called any time the IceConnectionState changes
466 virtual void OnIceConnectionChange(
perkjdfb769d2016-02-09 03:09:43 -0800467 PeerConnectionInterface::IceConnectionState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468
469 // Called any time the IceGatheringState changes
470 virtual void OnIceGatheringChange(
perkjdfb769d2016-02-09 03:09:43 -0800471 PeerConnectionInterface::IceGatheringState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000472
473 // New Ice candidate have been found.
474 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
475
Peter Thatcher54360512015-07-08 11:08:35 -0700476 // Called when the ICE connection receiving status changes.
477 virtual void OnIceConnectionReceivingChange(bool receiving) {}
478
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000479 protected:
480 // Dtor protected as objects shouldn't be deleted via this interface.
481 ~PeerConnectionObserver() {}
482};
483
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484// PeerConnectionFactoryInterface is the factory interface use for creating
485// PeerConnection, MediaStream and media tracks.
486// PeerConnectionFactoryInterface will create required libjingle threads,
487// socket and network manager factory classes for networking.
488// If an application decides to provide its own threads and network
489// implementation of these classes it should use the alternate
490// CreatePeerConnectionFactory method which accepts threads as input and use the
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800491// CreatePeerConnection version that takes a PortAllocator as an
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000492// argument.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000493class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494 public:
wu@webrtc.org97077a32013-10-25 21:18:33 +0000495 class Options {
496 public:
Guo-wei Shieha7446d22016-01-11 15:27:03 -0800497 Options()
498 : disable_encryption(false),
499 disable_sctp_data_channels(false),
500 disable_network_monitor(false),
501 network_ignore_mask(rtc::kDefaultNetworkIgnoreMask),
502 ssl_max_version(rtc::SSL_PROTOCOL_DTLS_12) {}
wu@webrtc.org97077a32013-10-25 21:18:33 +0000503 bool disable_encryption;
504 bool disable_sctp_data_channels;
honghaiz023f3ef2015-10-19 09:39:32 -0700505 bool disable_network_monitor;
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000506
507 // Sets the network types to ignore. For instance, calling this with
508 // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
509 // loopback interfaces.
510 int network_ignore_mask;
Joachim Bauch04e5b492015-05-29 09:40:39 +0200511
512 // Sets the maximum supported protocol version. The highest version
513 // supported by both ends will be used for the connection, i.e. if one
514 // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used.
515 rtc::SSLProtocolVersion ssl_max_version;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000516 };
517
518 virtual void SetOptions(const Options& options) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000519
deadbeef41b07982015-12-01 15:01:24 -0800520 virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
521 const PeerConnectionInterface::RTCConfiguration& configuration,
522 const MediaConstraintsInterface* constraints,
523 rtc::scoped_ptr<cricket::PortAllocator> allocator,
524 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800525 PeerConnectionObserver* observer) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000526
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000527 virtual rtc::scoped_refptr<MediaStreamInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000528 CreateLocalMediaStream(const std::string& label) = 0;
529
530 // Creates a AudioSourceInterface.
531 // |constraints| decides audio processing settings but can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000532 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533 const MediaConstraintsInterface* constraints) = 0;
534
535 // Creates a VideoSourceInterface. The new source take ownership of
536 // |capturer|. |constraints| decides video resolution and frame rate but can
537 // be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000538 virtual rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 cricket::VideoCapturer* capturer,
540 const MediaConstraintsInterface* constraints) = 0;
541
542 // Creates a new local VideoTrack. The same |source| can be used in several
543 // tracks.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000544 virtual rtc::scoped_refptr<VideoTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000545 CreateVideoTrack(const std::string& label,
546 VideoSourceInterface* source) = 0;
547
548 // Creates an new AudioTrack. At the moment |source| can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000549 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550 CreateAudioTrack(const std::string& label,
551 AudioSourceInterface* source) = 0;
552
wu@webrtc.orga9890802013-12-13 00:21:03 +0000553 // Starts AEC dump using existing file. Takes ownership of |file| and passes
554 // it on to VoiceEngine (via other objects) immediately, which will take
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000555 // the ownerhip. If the operation fails, the file will be closed.
ivocd66b44d2016-01-15 03:06:36 -0800556 // A maximum file size in bytes can be specified. When the file size limit is
557 // reached, logging is stopped automatically. If max_size_bytes is set to a
558 // value <= 0, no limit will be used, and logging will continue until the
559 // StopAecDump function is called.
560 virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000561
ivoc797ef122015-10-22 03:25:41 -0700562 // Stops logging the AEC dump.
563 virtual void StopAecDump() = 0;
564
ivoc112a3d82015-10-16 02:22:18 -0700565 // Starts RtcEventLog using existing file. Takes ownership of |file| and
566 // passes it on to VoiceEngine, which will take the ownership. If the
567 // operation fails the file will be closed. The logging will stop
568 // automatically after 10 minutes have passed, or when the StopRtcEventLog
569 // function is called.
570 // This function as well as the StopRtcEventLog don't really belong on this
571 // interface, this is a temporary solution until we move the logging object
572 // from inside voice engine to webrtc::Call, which will happen when the VoE
573 // restructuring effort is further along.
574 // TODO(ivoc): Move this into being:
575 // PeerConnection => MediaController => webrtc::Call.
576 virtual bool StartRtcEventLog(rtc::PlatformFile file) = 0;
577
578 // Stops logging the RtcEventLog.
579 virtual void StopRtcEventLog() = 0;
580
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581 protected:
582 // Dtor and ctor protected as objects shouldn't be created or deleted via
583 // this interface.
584 PeerConnectionFactoryInterface() {}
585 ~PeerConnectionFactoryInterface() {} // NOLINT
586};
587
588// Create a new instance of PeerConnectionFactoryInterface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000589rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000590CreatePeerConnectionFactory();
591
592// Create a new instance of PeerConnectionFactoryInterface.
593// Ownership of |factory|, |default_adm|, and optionally |encoder_factory| and
594// |decoder_factory| transferred to the returned factory.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000595rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000596CreatePeerConnectionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000597 rtc::Thread* worker_thread,
598 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000599 AudioDeviceModule* default_adm,
600 cricket::WebRtcVideoEncoderFactory* encoder_factory,
601 cricket::WebRtcVideoDecoderFactory* decoder_factory);
602
603} // namespace webrtc
604
Henrik Kjellander15583c12016-02-10 10:53:12 +0100605#endif // WEBRTC_API_PEERCONNECTIONINTERFACE_H_