blob: e616122996e128c00a93a7ae66a371c498904120 [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;
Jiayang Liucac1b382015-04-30 12:35:24 -0700246 RTCConfiguration()
247 : type(kAll),
248 bundle_policy(kBundlePolicyBalanced),
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700249 rtcp_mux_policy(kRtcpMuxPolicyNegotiate),
Henrik Lundin64dad832015-05-11 12:44:23 +0200250 tcp_candidate_policy(kTcpCandidatePolicyEnabled),
honghaiz4edc39c2015-09-01 09:53:56 -0700251 audio_jitter_buffer_max_packets(kAudioJitterBufferMaxPackets),
252 audio_jitter_buffer_fast_accelerate(false),
honghaiz1f429e32015-09-28 07:57:34 -0700253 ice_connection_receiving_timeout(kUndefined),
Honghai Zhang381b4212015-12-04 12:24:03 -0800254 ice_backup_candidate_pair_ping_interval(kUndefined),
qiangchen444682a2015-11-24 18:07:56 -0800255 continual_gathering_policy(GATHER_ONCE),
guoweis36f01372016-03-02 18:02:40 -0800256 disable_prerenderer_smoothing(false),
257 prioritize_most_likely_ice_candidate_pairs(false) {}
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000258 };
259
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000260 struct RTCOfferAnswerOptions {
261 static const int kUndefined = -1;
262 static const int kMaxOfferToReceiveMedia = 1;
263
264 // The default value for constraint offerToReceiveX:true.
265 static const int kOfferToReceiveMediaTrue = 1;
266
267 int offer_to_receive_video;
268 int offer_to_receive_audio;
269 bool voice_activity_detection;
270 bool ice_restart;
271 bool use_rtp_mux;
272
273 RTCOfferAnswerOptions()
274 : offer_to_receive_video(kUndefined),
275 offer_to_receive_audio(kUndefined),
276 voice_activity_detection(true),
277 ice_restart(false),
278 use_rtp_mux(true) {}
279
280 RTCOfferAnswerOptions(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 : offer_to_receive_video(offer_to_receive_video),
286 offer_to_receive_audio(offer_to_receive_audio),
287 voice_activity_detection(voice_activity_detection),
288 ice_restart(ice_restart),
289 use_rtp_mux(use_rtp_mux) {}
290 };
291
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000292 // Used by GetStats to decide which stats to include in the stats reports.
293 // |kStatsOutputLevelStandard| includes the standard stats for Javascript API;
294 // |kStatsOutputLevelDebug| includes both the standard stats and additional
295 // stats for debugging purposes.
296 enum StatsOutputLevel {
297 kStatsOutputLevelStandard,
298 kStatsOutputLevelDebug,
299 };
300
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301 // Accessor methods to active local streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000302 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303 local_streams() = 0;
304
305 // Accessor methods to remote streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000306 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307 remote_streams() = 0;
308
309 // Add a new MediaStream to be sent on this PeerConnection.
310 // Note that a SessionDescription negotiation is needed before the
311 // remote peer can receive the stream.
perkj@webrtc.orgfd0efb62014-11-06 12:16:36 +0000312 virtual bool AddStream(MediaStreamInterface* stream) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313
314 // Remove a MediaStream from this PeerConnection.
315 // Note that a SessionDescription negotiation is need before the
316 // remote peer is notified.
317 virtual void RemoveStream(MediaStreamInterface* stream) = 0;
318
deadbeefe1f9d832016-01-14 15:35:42 -0800319 // TODO(deadbeef): Make the following two methods pure virtual once
320 // implemented by all subclasses of PeerConnectionInterface.
321 // Add a new MediaStreamTrack to be sent on this PeerConnection.
322 // |streams| indicates which stream labels the track should be associated
323 // with.
324 virtual rtc::scoped_refptr<RtpSenderInterface> AddTrack(
325 MediaStreamTrackInterface* track,
326 std::vector<MediaStreamInterface*> streams) {
327 return nullptr;
328 }
329
330 // Remove an RtpSender from this PeerConnection.
331 // Returns true on success.
332 virtual bool RemoveTrack(RtpSenderInterface* sender) {
333 return false;
334 }
335
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000336 // Returns pointer to the created DtmfSender on success.
337 // Otherwise returns NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000338 virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339 AudioTrackInterface* track) = 0;
340
deadbeef70ab1a12015-09-28 16:53:55 -0700341 // TODO(deadbeef): Make these pure virtual once all subclasses implement them.
deadbeeffac06552015-11-25 11:26:01 -0800342 // |kind| must be "audio" or "video".
deadbeefbd7d8f72015-12-18 16:58:44 -0800343 // |stream_id| is used to populate the msid attribute; if empty, one will
344 // be generated automatically.
deadbeeffac06552015-11-25 11:26:01 -0800345 virtual rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -0800346 const std::string& kind,
347 const std::string& stream_id) {
deadbeeffac06552015-11-25 11:26:01 -0800348 return rtc::scoped_refptr<RtpSenderInterface>();
349 }
350
deadbeef70ab1a12015-09-28 16:53:55 -0700351 virtual std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
352 const {
353 return std::vector<rtc::scoped_refptr<RtpSenderInterface>>();
354 }
355
356 virtual std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
357 const {
358 return std::vector<rtc::scoped_refptr<RtpReceiverInterface>>();
359 }
360
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000361 virtual bool GetStats(StatsObserver* observer,
362 MediaStreamTrackInterface* track,
363 StatsOutputLevel level) = 0;
364
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000365 virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 const std::string& label,
367 const DataChannelInit* config) = 0;
368
369 virtual const SessionDescriptionInterface* local_description() const = 0;
370 virtual const SessionDescriptionInterface* remote_description() const = 0;
371
372 // Create a new offer.
373 // The CreateSessionDescriptionObserver callback will be called when done.
374 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000375 const MediaConstraintsInterface* constraints) {}
376
377 // TODO(jiayl): remove the default impl and the old interface when chromium
378 // code is updated.
379 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
380 const RTCOfferAnswerOptions& options) {}
381
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000382 // Create an answer to an offer.
383 // The CreateSessionDescriptionObserver callback will be called when done.
384 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
385 const MediaConstraintsInterface* constraints) = 0;
386 // Sets the local session description.
387 // JsepInterface takes the ownership of |desc| even if it fails.
388 // The |observer| callback will be called when done.
389 virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
390 SessionDescriptionInterface* desc) = 0;
391 // Sets the remote session description.
392 // JsepInterface takes the ownership of |desc| even if it fails.
393 // The |observer| callback will be called when done.
394 virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
395 SessionDescriptionInterface* desc) = 0;
396 // Restarts or updates the ICE Agent process of gathering local candidates
397 // and pinging remote candidates.
deadbeefa67696b2015-09-29 11:56:26 -0700398 // TODO(deadbeef): Remove once Chrome is moved over to SetConfiguration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000399 virtual bool UpdateIce(const IceServers& configuration,
deadbeefa67696b2015-09-29 11:56:26 -0700400 const MediaConstraintsInterface* constraints) {
401 return false;
402 }
403 // Sets the PeerConnection's global configuration to |config|.
404 // Any changes to STUN/TURN servers or ICE candidate policy will affect the
405 // next gathering phase, and cause the next call to createOffer to generate
406 // new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies
407 // cannot be changed with this method.
408 // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of
409 // PeerConnectionInterface implement it.
410 virtual bool SetConfiguration(
411 const PeerConnectionInterface::RTCConfiguration& config) {
412 return false;
413 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414 // Provides a remote candidate to the ICE Agent.
415 // A copy of the |candidate| will be created and added to the remote
416 // description. So the caller of this method still has the ownership of the
417 // |candidate|.
418 // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will
419 // take the ownership of the |candidate|.
420 virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
421
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000422 virtual void RegisterUMAObserver(UMAObserver* observer) = 0;
423
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424 // Returns the current SignalingState.
425 virtual SignalingState signaling_state() = 0;
426
427 // TODO(bemasc): Remove ice_state when callers are changed to
428 // IceConnection/GatheringState.
429 // Returns the current IceState.
430 virtual IceState ice_state() = 0;
431 virtual IceConnectionState ice_connection_state() = 0;
432 virtual IceGatheringState ice_gathering_state() = 0;
433
434 // Terminates all media and closes the transport.
435 virtual void Close() = 0;
436
437 protected:
438 // Dtor protected as objects shouldn't be deleted via this interface.
439 ~PeerConnectionInterface() {}
440};
441
442// PeerConnection callback interface. Application should implement these
443// methods.
444class PeerConnectionObserver {
445 public:
446 enum StateType {
447 kSignalingState,
448 kIceState,
449 };
450
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451 // Triggered when the SignalingState changed.
452 virtual void OnSignalingChange(
perkjdfb769d2016-02-09 03:09:43 -0800453 PeerConnectionInterface::SignalingState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000454
455 // Triggered when media is received on a new stream from remote peer.
456 virtual void OnAddStream(MediaStreamInterface* stream) = 0;
457
458 // Triggered when a remote peer close a stream.
459 virtual void OnRemoveStream(MediaStreamInterface* stream) = 0;
460
461 // Triggered when a remote peer open a data channel.
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000462 virtual void OnDataChannel(DataChannelInterface* data_channel) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463
mallinath@webrtc.org0d92ef62014-01-22 02:21:22 +0000464 // Triggered when renegotiation is needed, for example the ICE has restarted.
fischman@webrtc.orgd7568a02014-01-13 22:04:12 +0000465 virtual void OnRenegotiationNeeded() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000466
467 // Called any time the IceConnectionState changes
468 virtual void OnIceConnectionChange(
perkjdfb769d2016-02-09 03:09:43 -0800469 PeerConnectionInterface::IceConnectionState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000470
471 // Called any time the IceGatheringState changes
472 virtual void OnIceGatheringChange(
perkjdfb769d2016-02-09 03:09:43 -0800473 PeerConnectionInterface::IceGatheringState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000474
475 // New Ice candidate have been found.
476 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
477
Peter Thatcher54360512015-07-08 11:08:35 -0700478 // Called when the ICE connection receiving status changes.
479 virtual void OnIceConnectionReceivingChange(bool receiving) {}
480
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000481 protected:
482 // Dtor protected as objects shouldn't be deleted via this interface.
483 ~PeerConnectionObserver() {}
484};
485
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000486// PeerConnectionFactoryInterface is the factory interface use for creating
487// PeerConnection, MediaStream and media tracks.
488// PeerConnectionFactoryInterface will create required libjingle threads,
489// socket and network manager factory classes for networking.
490// If an application decides to provide its own threads and network
491// implementation of these classes it should use the alternate
492// CreatePeerConnectionFactory method which accepts threads as input and use the
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800493// CreatePeerConnection version that takes a PortAllocator as an
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494// argument.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000495class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000496 public:
wu@webrtc.org97077a32013-10-25 21:18:33 +0000497 class Options {
498 public:
Guo-wei Shieha7446d22016-01-11 15:27:03 -0800499 Options()
500 : disable_encryption(false),
501 disable_sctp_data_channels(false),
502 disable_network_monitor(false),
503 network_ignore_mask(rtc::kDefaultNetworkIgnoreMask),
504 ssl_max_version(rtc::SSL_PROTOCOL_DTLS_12) {}
wu@webrtc.org97077a32013-10-25 21:18:33 +0000505 bool disable_encryption;
506 bool disable_sctp_data_channels;
honghaiz023f3ef2015-10-19 09:39:32 -0700507 bool disable_network_monitor;
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000508
509 // Sets the network types to ignore. For instance, calling this with
510 // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
511 // loopback interfaces.
512 int network_ignore_mask;
Joachim Bauch04e5b492015-05-29 09:40:39 +0200513
514 // Sets the maximum supported protocol version. The highest version
515 // supported by both ends will be used for the connection, i.e. if one
516 // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used.
517 rtc::SSLProtocolVersion ssl_max_version;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000518 };
519
520 virtual void SetOptions(const Options& options) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000521
deadbeef41b07982015-12-01 15:01:24 -0800522 virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
523 const PeerConnectionInterface::RTCConfiguration& configuration,
524 const MediaConstraintsInterface* constraints,
525 rtc::scoped_ptr<cricket::PortAllocator> allocator,
526 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800527 PeerConnectionObserver* observer) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000528
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000529 virtual rtc::scoped_refptr<MediaStreamInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000530 CreateLocalMediaStream(const std::string& label) = 0;
531
532 // Creates a AudioSourceInterface.
533 // |constraints| decides audio processing settings but can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000534 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000535 const MediaConstraintsInterface* constraints) = 0;
536
537 // Creates a VideoSourceInterface. The new source take ownership of
538 // |capturer|. |constraints| decides video resolution and frame rate but can
539 // be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000540 virtual rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000541 cricket::VideoCapturer* capturer,
542 const MediaConstraintsInterface* constraints) = 0;
543
544 // Creates a new local VideoTrack. The same |source| can be used in several
545 // tracks.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000546 virtual rtc::scoped_refptr<VideoTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000547 CreateVideoTrack(const std::string& label,
548 VideoSourceInterface* source) = 0;
549
550 // Creates an new AudioTrack. At the moment |source| can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000551 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000552 CreateAudioTrack(const std::string& label,
553 AudioSourceInterface* source) = 0;
554
wu@webrtc.orga9890802013-12-13 00:21:03 +0000555 // Starts AEC dump using existing file. Takes ownership of |file| and passes
556 // it on to VoiceEngine (via other objects) immediately, which will take
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000557 // the ownerhip. If the operation fails, the file will be closed.
ivocd66b44d2016-01-15 03:06:36 -0800558 // A maximum file size in bytes can be specified. When the file size limit is
559 // reached, logging is stopped automatically. If max_size_bytes is set to a
560 // value <= 0, no limit will be used, and logging will continue until the
561 // StopAecDump function is called.
562 virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000563
ivoc797ef122015-10-22 03:25:41 -0700564 // Stops logging the AEC dump.
565 virtual void StopAecDump() = 0;
566
ivoc112a3d82015-10-16 02:22:18 -0700567 // Starts RtcEventLog using existing file. Takes ownership of |file| and
568 // passes it on to VoiceEngine, which will take the ownership. If the
569 // operation fails the file will be closed. The logging will stop
570 // automatically after 10 minutes have passed, or when the StopRtcEventLog
571 // function is called.
572 // This function as well as the StopRtcEventLog don't really belong on this
573 // interface, this is a temporary solution until we move the logging object
574 // from inside voice engine to webrtc::Call, which will happen when the VoE
575 // restructuring effort is further along.
576 // TODO(ivoc): Move this into being:
577 // PeerConnection => MediaController => webrtc::Call.
578 virtual bool StartRtcEventLog(rtc::PlatformFile file) = 0;
579
580 // Stops logging the RtcEventLog.
581 virtual void StopRtcEventLog() = 0;
582
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583 protected:
584 // Dtor and ctor protected as objects shouldn't be created or deleted via
585 // this interface.
586 PeerConnectionFactoryInterface() {}
587 ~PeerConnectionFactoryInterface() {} // NOLINT
588};
589
590// Create a new instance of PeerConnectionFactoryInterface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000591rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592CreatePeerConnectionFactory();
593
594// Create a new instance of PeerConnectionFactoryInterface.
595// Ownership of |factory|, |default_adm|, and optionally |encoder_factory| and
596// |decoder_factory| transferred to the returned factory.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000597rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000598CreatePeerConnectionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000599 rtc::Thread* worker_thread,
600 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000601 AudioDeviceModule* default_adm,
602 cricket::WebRtcVideoEncoderFactory* encoder_factory,
603 cricket::WebRtcVideoDecoderFactory* decoder_factory);
604
605} // namespace webrtc
606
Henrik Kjellander15583c12016-02-10 10:53:12 +0100607#endif // WEBRTC_API_PEERCONNECTIONINTERFACE_H_