blob: 94d2c001e38c228d7130319d03e4e8a5c13be34e [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
11// This file contains the PeerConnection interface as defined in
12// http://dev.w3.org/2011/webrtc/editor/webrtc.html#peer-to-peer-connections.
13// Applications must use this interface to implement peerconnection.
14// PeerConnectionFactory class provides factory methods to create
15// peerconnection, mediastream and media tracks objects.
16//
17// The Following steps are needed to setup a typical call using Jsep.
18// 1. Create a PeerConnectionFactoryInterface. Check constructors for more
19// information about input parameters.
20// 2. Create a PeerConnection object. Provide a configuration string which
21// points either to stun or turn server to generate ICE candidates and provide
22// an object that implements the PeerConnectionObserver interface.
23// 3. Create local MediaStream and MediaTracks using the PeerConnectionFactory
24// and add it to PeerConnection by calling AddStream.
25// 4. Create an offer and serialize it and send it to the remote peer.
26// 5. Once an ice candidate have been found PeerConnection will call the
27// observer function OnIceCandidate. The candidates must also be serialized and
28// sent to the remote peer.
29// 6. Once an answer is received from the remote peer, call
30// SetLocalSessionDescription with the offer and SetRemoteSessionDescription
31// with the remote answer.
32// 7. Once a remote candidate is received from the remote peer, provide it to
33// the peerconnection by calling AddIceCandidate.
34
35
36// The Receiver of a call can decide to accept or reject the call.
37// This decision will be taken by the application not peerconnection.
38// If application decides to accept the call
39// 1. Create PeerConnectionFactoryInterface if it doesn't exist.
40// 2. Create a new PeerConnection.
41// 3. Provide the remote offer to the new PeerConnection object by calling
42// SetRemoteSessionDescription.
43// 4. Generate an answer to the remote offer by calling CreateAnswer and send it
44// back to the remote peer.
45// 5. Provide the local answer to the new PeerConnection by calling
46// SetLocalSessionDescription with the answer.
47// 6. Provide the remote ice candidates by calling AddIceCandidate.
48// 7. Once a candidate have been found PeerConnection will call the observer
49// function OnIceCandidate. Send these candidates to the remote peer.
50
Henrik Kjellander15583c12016-02-10 10:53:12 +010051#ifndef WEBRTC_API_PEERCONNECTIONINTERFACE_H_
52#define WEBRTC_API_PEERCONNECTIONINTERFACE_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053
kwibergd1fe2812016-04-27 06:47:29 -070054#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080056#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057#include <vector>
58
Henrik Kjellander15583c12016-02-10 10:53:12 +010059#include "webrtc/api/datachannelinterface.h"
60#include "webrtc/api/dtlsidentitystore.h"
61#include "webrtc/api/dtlsidentitystore.h"
62#include "webrtc/api/dtmfsenderinterface.h"
63#include "webrtc/api/jsep.h"
64#include "webrtc/api/mediastreaminterface.h"
65#include "webrtc/api/rtpreceiverinterface.h"
66#include "webrtc/api/rtpsenderinterface.h"
67#include "webrtc/api/statstypes.h"
68#include "webrtc/api/umametrics.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000069#include "webrtc/base/fileutils.h"
phoglund@webrtc.org006521d2015-02-12 09:23:59 +000070#include "webrtc/base/network.h"
Henrik Boström87713d02015-08-25 09:53:21 +020071#include "webrtc/base/rtccertificate.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000072#include "webrtc/base/socketaddress.h"
kjellandera96e2d72016-02-04 23:52:28 -080073#include "webrtc/base/sslstreamadapter.h"
nissec36b31b2016-04-11 23:25:29 -070074#include "webrtc/media/base/mediachannel.h"
deadbeef41b07982015-12-01 15:01:24 -080075#include "webrtc/p2p/base/portallocator.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000077namespace rtc {
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000078class SSLIdentity;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079class Thread;
80}
81
82namespace cricket {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083class WebRtcVideoDecoderFactory;
84class WebRtcVideoEncoderFactory;
85}
86
87namespace webrtc {
88class AudioDeviceModule;
89class MediaConstraintsInterface;
90
91// MediaStream container interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000092class StreamCollectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093 public:
94 // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find.
95 virtual size_t count() = 0;
96 virtual MediaStreamInterface* at(size_t index) = 0;
97 virtual MediaStreamInterface* find(const std::string& label) = 0;
98 virtual MediaStreamTrackInterface* FindAudioTrack(
99 const std::string& id) = 0;
100 virtual MediaStreamTrackInterface* FindVideoTrack(
101 const std::string& id) = 0;
102
103 protected:
104 // Dtor protected as objects shouldn't be deleted via this interface.
105 ~StreamCollectionInterface() {}
106};
107
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000108class StatsObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109 public:
tommi@webrtc.orge2e199b2014-12-15 13:22:54 +0000110 virtual void OnComplete(const StatsReports& reports) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111
112 protected:
113 virtual ~StatsObserver() {}
114};
115
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000116class MetricsObserverInterface : public rtc::RefCountInterface {
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000117 public:
Guo-wei Shieh3d564c12015-08-19 16:51:15 -0700118
119 // |type| is the type of the enum counter to be incremented. |counter|
120 // is the particular counter in that type. |counter_max| is the next sequence
121 // number after the highest counter.
122 virtual void IncrementEnumCounter(PeerConnectionEnumCounterType type,
123 int counter,
124 int counter_max) {}
125
Guo-wei Shieh456696a2015-09-30 21:48:54 -0700126 // This is used to handle sparse counters like SSL cipher suites.
127 // TODO(guoweis): Remove the implementation once the dependency's interface
128 // definition is updated.
129 virtual void IncrementSparseEnumCounter(PeerConnectionEnumCounterType type,
130 int counter) {
131 IncrementEnumCounter(type, counter, 0 /* Ignored */);
132 }
133
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000134 virtual void AddHistogramSample(PeerConnectionMetricsName type,
mallinath@webrtc.orgd37bcfa2014-05-12 23:10:18 +0000135 int value) = 0;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000136
137 protected:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000138 virtual ~MetricsObserverInterface() {}
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000139};
140
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000141typedef MetricsObserverInterface UMAObserver;
142
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000143class PeerConnectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144 public:
145 // See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions .
146 enum SignalingState {
147 kStable,
148 kHaveLocalOffer,
149 kHaveLocalPrAnswer,
150 kHaveRemoteOffer,
151 kHaveRemotePrAnswer,
152 kClosed,
153 };
154
155 // TODO(bemasc): Remove IceState when callers are changed to
156 // IceConnection/GatheringState.
157 enum IceState {
158 kIceNew,
159 kIceGathering,
160 kIceWaiting,
161 kIceChecking,
162 kIceConnected,
163 kIceCompleted,
164 kIceFailed,
165 kIceClosed,
166 };
167
168 enum IceGatheringState {
169 kIceGatheringNew,
170 kIceGatheringGathering,
171 kIceGatheringComplete
172 };
173
174 enum IceConnectionState {
175 kIceConnectionNew,
176 kIceConnectionChecking,
177 kIceConnectionConnected,
178 kIceConnectionCompleted,
179 kIceConnectionFailed,
180 kIceConnectionDisconnected,
181 kIceConnectionClosed,
Guo-wei Shieh3d564c12015-08-19 16:51:15 -0700182 kIceConnectionMax,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183 };
184
185 struct IceServer {
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200186 // TODO(jbauch): Remove uri when all code using it has switched to urls.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 std::string uri;
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200188 std::vector<std::string> urls;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 std::string username;
190 std::string password;
191 };
192 typedef std::vector<IceServer> IceServers;
193
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000194 enum IceTransportsType {
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000195 // TODO(pthatcher): Rename these kTransporTypeXXX, but update
196 // Chromium at the same time.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000197 kNone,
198 kRelay,
199 kNoHost,
200 kAll
201 };
202
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000203 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-08#section-4.1.1
204 enum BundlePolicy {
205 kBundlePolicyBalanced,
206 kBundlePolicyMaxBundle,
207 kBundlePolicyMaxCompat
208 };
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000209
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700210 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-09#section-4.1.1
211 enum RtcpMuxPolicy {
212 kRtcpMuxPolicyNegotiate,
213 kRtcpMuxPolicyRequire,
214 };
215
Jiayang Liucac1b382015-04-30 12:35:24 -0700216 enum TcpCandidatePolicy {
217 kTcpCandidatePolicyEnabled,
218 kTcpCandidatePolicyDisabled
219 };
220
honghaiz1f429e32015-09-28 07:57:34 -0700221 enum ContinualGatheringPolicy {
222 GATHER_ONCE,
223 GATHER_CONTINUALLY
224 };
225
Henrik Boström87713d02015-08-25 09:53:21 +0200226 // TODO(hbos): Change into class with private data and public getters.
nissec36b31b2016-04-11 23:25:29 -0700227 // TODO(nisse): In particular, accessing fields directly from an
228 // application is brittle, since the organization mirrors the
229 // organization of the implementation, which isn't stable. So we
230 // need getters and setters at least for fields which applications
231 // are interested in.
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000232 struct RTCConfiguration {
Niels Möller71bdda02016-03-31 12:59:59 +0200233 // This struct is subject to reorganization, both for naming
234 // consistency, and to group settings to match where they are used
235 // in the implementation. To do that, we need getter and setter
236 // methods for all settings which are of interest to applications,
237 // Chrome in particular.
238
nissec36b31b2016-04-11 23:25:29 -0700239 bool dscp() { return media_config.enable_dscp; }
240 void set_dscp(bool enable) { media_config.enable_dscp = enable; }
Niels Möller71bdda02016-03-31 12:59:59 +0200241
242 // TODO(nisse): The corresponding flag in MediaConfig and
243 // elsewhere should be renamed enable_cpu_adaptation.
nissec36b31b2016-04-11 23:25:29 -0700244 bool cpu_adaptation() {
245 return media_config.video.enable_cpu_overuse_detection;
246 }
Niels Möller71bdda02016-03-31 12:59:59 +0200247 void set_cpu_adaptation(bool enable) {
nissec36b31b2016-04-11 23:25:29 -0700248 media_config.video.enable_cpu_overuse_detection = enable;
Niels Möller71bdda02016-03-31 12:59:59 +0200249 }
250
nissec36b31b2016-04-11 23:25:29 -0700251 bool suspend_below_min_bitrate() {
252 return media_config.video.suspend_below_min_bitrate;
253 }
Niels Möller71bdda02016-03-31 12:59:59 +0200254 void set_suspend_below_min_bitrate(bool enable) {
nissec36b31b2016-04-11 23:25:29 -0700255 media_config.video.suspend_below_min_bitrate = enable;
Niels Möller71bdda02016-03-31 12:59:59 +0200256 }
257
258 // TODO(nisse): The negation in the corresponding MediaConfig
259 // attribute is inconsistent, and it should be renamed at some
260 // point.
nissec36b31b2016-04-11 23:25:29 -0700261 bool prerenderer_smoothing() {
262 return !media_config.video.disable_prerenderer_smoothing;
263 }
Niels Möller71bdda02016-03-31 12:59:59 +0200264 void set_prerenderer_smoothing(bool enable) {
nissec36b31b2016-04-11 23:25:29 -0700265 media_config.video.disable_prerenderer_smoothing = !enable;
Niels Möller71bdda02016-03-31 12:59:59 +0200266 }
267
honghaiz4edc39c2015-09-01 09:53:56 -0700268 static const int kUndefined = -1;
269 // Default maximum number of packets in the audio jitter buffer.
270 static const int kAudioJitterBufferMaxPackets = 50;
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000271 // TODO(pthatcher): Rename this ice_transport_type, but update
272 // Chromium at the same time.
deadbeefc55fb302016-05-12 12:51:38 -0700273 IceTransportsType type;
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000274 // TODO(pthatcher): Rename this ice_servers, but update Chromium
275 // at the same time.
276 IceServers servers;
deadbeefc55fb302016-05-12 12:51:38 -0700277 BundlePolicy bundle_policy;
278 RtcpMuxPolicy rtcp_mux_policy;
279 TcpCandidatePolicy tcp_candidate_policy;
280 int audio_jitter_buffer_max_packets;
281 bool audio_jitter_buffer_fast_accelerate;
282 int ice_connection_receiving_timeout; // ms
283 int ice_backup_candidate_pair_ping_interval; // ms
284 ContinualGatheringPolicy continual_gathering_policy;
Henrik Boström87713d02015-08-25 09:53:21 +0200285 std::vector<rtc::scoped_refptr<rtc::RTCCertificate>> certificates;
deadbeefc55fb302016-05-12 12:51:38 -0700286 bool prioritize_most_likely_ice_candidate_pairs;
nissec36b31b2016-04-11 23:25:29 -0700287 struct cricket::MediaConfig media_config;
htaa2a49d92016-03-04 02:51:39 -0800288 // Flags corresponding to values set by constraint flags.
289 // rtc::Optional flags can be "missing", in which case the webrtc
290 // default applies.
deadbeefc55fb302016-05-12 12:51:38 -0700291 bool disable_ipv6;
292 bool enable_rtp_data_channel;
htaa2a49d92016-03-04 02:51:39 -0800293 rtc::Optional<int> screencast_min_bitrate;
294 rtc::Optional<bool> combined_audio_video_bwe;
295 rtc::Optional<bool> enable_dtls_srtp;
deadbeefc55fb302016-05-12 12:51:38 -0700296 RTCConfiguration()
297 : type(kAll),
298 bundle_policy(kBundlePolicyBalanced),
299 rtcp_mux_policy(kRtcpMuxPolicyNegotiate),
300 tcp_candidate_policy(kTcpCandidatePolicyEnabled),
301 audio_jitter_buffer_max_packets(kAudioJitterBufferMaxPackets),
302 audio_jitter_buffer_fast_accelerate(false),
303 ice_connection_receiving_timeout(kUndefined),
304 ice_backup_candidate_pair_ping_interval(kUndefined),
305 continual_gathering_policy(GATHER_ONCE),
306 prioritize_most_likely_ice_candidate_pairs(false),
307 disable_ipv6(false),
308 enable_rtp_data_channel(false) {}
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000309 };
310
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000311 struct RTCOfferAnswerOptions {
312 static const int kUndefined = -1;
313 static const int kMaxOfferToReceiveMedia = 1;
314
315 // The default value for constraint offerToReceiveX:true.
316 static const int kOfferToReceiveMediaTrue = 1;
317
318 int offer_to_receive_video;
319 int offer_to_receive_audio;
320 bool voice_activity_detection;
321 bool ice_restart;
322 bool use_rtp_mux;
323
324 RTCOfferAnswerOptions()
325 : offer_to_receive_video(kUndefined),
326 offer_to_receive_audio(kUndefined),
327 voice_activity_detection(true),
328 ice_restart(false),
329 use_rtp_mux(true) {}
330
331 RTCOfferAnswerOptions(int offer_to_receive_video,
332 int offer_to_receive_audio,
333 bool voice_activity_detection,
334 bool ice_restart,
335 bool use_rtp_mux)
336 : offer_to_receive_video(offer_to_receive_video),
337 offer_to_receive_audio(offer_to_receive_audio),
338 voice_activity_detection(voice_activity_detection),
339 ice_restart(ice_restart),
340 use_rtp_mux(use_rtp_mux) {}
341 };
342
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000343 // Used by GetStats to decide which stats to include in the stats reports.
344 // |kStatsOutputLevelStandard| includes the standard stats for Javascript API;
345 // |kStatsOutputLevelDebug| includes both the standard stats and additional
346 // stats for debugging purposes.
347 enum StatsOutputLevel {
348 kStatsOutputLevelStandard,
349 kStatsOutputLevelDebug,
350 };
351
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 // Accessor methods to active local streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000353 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 local_streams() = 0;
355
356 // Accessor methods to remote streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000357 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 remote_streams() = 0;
359
360 // Add a new MediaStream to be sent on this PeerConnection.
361 // Note that a SessionDescription negotiation is needed before the
362 // remote peer can receive the stream.
perkj@webrtc.orgfd0efb62014-11-06 12:16:36 +0000363 virtual bool AddStream(MediaStreamInterface* stream) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364
365 // Remove a MediaStream from this PeerConnection.
366 // Note that a SessionDescription negotiation is need before the
367 // remote peer is notified.
368 virtual void RemoveStream(MediaStreamInterface* stream) = 0;
369
deadbeefe1f9d832016-01-14 15:35:42 -0800370 // TODO(deadbeef): Make the following two methods pure virtual once
371 // implemented by all subclasses of PeerConnectionInterface.
372 // Add a new MediaStreamTrack to be sent on this PeerConnection.
373 // |streams| indicates which stream labels the track should be associated
374 // with.
375 virtual rtc::scoped_refptr<RtpSenderInterface> AddTrack(
376 MediaStreamTrackInterface* track,
377 std::vector<MediaStreamInterface*> streams) {
378 return nullptr;
379 }
380
381 // Remove an RtpSender from this PeerConnection.
382 // Returns true on success.
383 virtual bool RemoveTrack(RtpSenderInterface* sender) {
384 return false;
385 }
386
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387 // Returns pointer to the created DtmfSender on success.
388 // Otherwise returns NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000389 virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390 AudioTrackInterface* track) = 0;
391
deadbeef70ab1a12015-09-28 16:53:55 -0700392 // TODO(deadbeef): Make these pure virtual once all subclasses implement them.
deadbeeffac06552015-11-25 11:26:01 -0800393 // |kind| must be "audio" or "video".
deadbeefbd7d8f72015-12-18 16:58:44 -0800394 // |stream_id| is used to populate the msid attribute; if empty, one will
395 // be generated automatically.
deadbeeffac06552015-11-25 11:26:01 -0800396 virtual rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -0800397 const std::string& kind,
398 const std::string& stream_id) {
deadbeeffac06552015-11-25 11:26:01 -0800399 return rtc::scoped_refptr<RtpSenderInterface>();
400 }
401
deadbeef70ab1a12015-09-28 16:53:55 -0700402 virtual std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
403 const {
404 return std::vector<rtc::scoped_refptr<RtpSenderInterface>>();
405 }
406
407 virtual std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
408 const {
409 return std::vector<rtc::scoped_refptr<RtpReceiverInterface>>();
410 }
411
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000412 virtual bool GetStats(StatsObserver* observer,
413 MediaStreamTrackInterface* track,
414 StatsOutputLevel level) = 0;
415
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000416 virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000417 const std::string& label,
418 const DataChannelInit* config) = 0;
419
420 virtual const SessionDescriptionInterface* local_description() const = 0;
421 virtual const SessionDescriptionInterface* remote_description() const = 0;
422
423 // Create a new offer.
424 // The CreateSessionDescriptionObserver callback will be called when done.
425 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000426 const MediaConstraintsInterface* constraints) {}
427
428 // TODO(jiayl): remove the default impl and the old interface when chromium
429 // code is updated.
430 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
431 const RTCOfferAnswerOptions& options) {}
432
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000433 // Create an answer to an offer.
434 // The CreateSessionDescriptionObserver callback will be called when done.
435 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
htaa2a49d92016-03-04 02:51:39 -0800436 const RTCOfferAnswerOptions& options) {}
437 // Deprecated - use version above.
438 // TODO(hta): Remove and remove default implementations when all callers
439 // are updated.
440 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
441 const MediaConstraintsInterface* constraints) {}
442
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443 // Sets the local session description.
444 // JsepInterface takes the ownership of |desc| even if it fails.
445 // The |observer| callback will be called when done.
446 virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
447 SessionDescriptionInterface* desc) = 0;
448 // Sets the remote session description.
449 // JsepInterface takes the ownership of |desc| even if it fails.
450 // The |observer| callback will be called when done.
451 virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
452 SessionDescriptionInterface* desc) = 0;
453 // Restarts or updates the ICE Agent process of gathering local candidates
454 // and pinging remote candidates.
deadbeefa67696b2015-09-29 11:56:26 -0700455 // TODO(deadbeef): Remove once Chrome is moved over to SetConfiguration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000456 virtual bool UpdateIce(const IceServers& configuration,
deadbeefa67696b2015-09-29 11:56:26 -0700457 const MediaConstraintsInterface* constraints) {
458 return false;
459 }
htaa2a49d92016-03-04 02:51:39 -0800460 virtual bool UpdateIce(const IceServers& configuration) { return false; }
deadbeefa67696b2015-09-29 11:56:26 -0700461 // Sets the PeerConnection's global configuration to |config|.
462 // Any changes to STUN/TURN servers or ICE candidate policy will affect the
463 // next gathering phase, and cause the next call to createOffer to generate
464 // new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies
465 // cannot be changed with this method.
466 // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of
467 // PeerConnectionInterface implement it.
468 virtual bool SetConfiguration(
469 const PeerConnectionInterface::RTCConfiguration& config) {
470 return false;
471 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000472 // Provides a remote candidate to the ICE Agent.
473 // A copy of the |candidate| will be created and added to the remote
474 // description. So the caller of this method still has the ownership of the
475 // |candidate|.
476 // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will
477 // take the ownership of the |candidate|.
478 virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
479
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700480 // Removes a group of remote candidates from the ICE agent.
481 virtual bool RemoveIceCandidates(
482 const std::vector<cricket::Candidate>& candidates) {
483 return false;
484 }
485
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000486 virtual void RegisterUMAObserver(UMAObserver* observer) = 0;
487
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000488 // Returns the current SignalingState.
489 virtual SignalingState signaling_state() = 0;
490
491 // TODO(bemasc): Remove ice_state when callers are changed to
492 // IceConnection/GatheringState.
493 // Returns the current IceState.
494 virtual IceState ice_state() = 0;
495 virtual IceConnectionState ice_connection_state() = 0;
496 virtual IceGatheringState ice_gathering_state() = 0;
497
498 // Terminates all media and closes the transport.
499 virtual void Close() = 0;
500
501 protected:
502 // Dtor protected as objects shouldn't be deleted via this interface.
503 ~PeerConnectionInterface() {}
504};
505
506// PeerConnection callback interface. Application should implement these
507// methods.
508class PeerConnectionObserver {
509 public:
510 enum StateType {
511 kSignalingState,
512 kIceState,
513 };
514
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000515 // Triggered when the SignalingState changed.
516 virtual void OnSignalingChange(
perkjdfb769d2016-02-09 03:09:43 -0800517 PeerConnectionInterface::SignalingState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000518
519 // Triggered when media is received on a new stream from remote peer.
520 virtual void OnAddStream(MediaStreamInterface* stream) = 0;
521
522 // Triggered when a remote peer close a stream.
523 virtual void OnRemoveStream(MediaStreamInterface* stream) = 0;
524
525 // Triggered when a remote peer open a data channel.
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000526 virtual void OnDataChannel(DataChannelInterface* data_channel) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000527
mallinath@webrtc.org0d92ef62014-01-22 02:21:22 +0000528 // Triggered when renegotiation is needed, for example the ICE has restarted.
fischman@webrtc.orgd7568a02014-01-13 22:04:12 +0000529 virtual void OnRenegotiationNeeded() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000530
531 // Called any time the IceConnectionState changes
532 virtual void OnIceConnectionChange(
perkjdfb769d2016-02-09 03:09:43 -0800533 PeerConnectionInterface::IceConnectionState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000534
535 // Called any time the IceGatheringState changes
536 virtual void OnIceGatheringChange(
perkjdfb769d2016-02-09 03:09:43 -0800537 PeerConnectionInterface::IceGatheringState new_state) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000538
539 // New Ice candidate have been found.
540 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
541
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700542 // Ice candidates have been removed.
543 // TODO(honghaiz): Make this a pure virtual method when all its subclasses
544 // implement it.
545 virtual void OnIceCandidatesRemoved(
546 const std::vector<cricket::Candidate>& candidates) {}
547
Peter Thatcher54360512015-07-08 11:08:35 -0700548 // Called when the ICE connection receiving status changes.
549 virtual void OnIceConnectionReceivingChange(bool receiving) {}
550
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000551 protected:
552 // Dtor protected as objects shouldn't be deleted via this interface.
553 ~PeerConnectionObserver() {}
554};
555
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556// PeerConnectionFactoryInterface is the factory interface use for creating
557// PeerConnection, MediaStream and media tracks.
558// PeerConnectionFactoryInterface will create required libjingle threads,
559// socket and network manager factory classes for networking.
560// If an application decides to provide its own threads and network
561// implementation of these classes it should use the alternate
562// CreatePeerConnectionFactory method which accepts threads as input and use the
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800563// CreatePeerConnection version that takes a PortAllocator as an
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564// argument.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000565class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000566 public:
wu@webrtc.org97077a32013-10-25 21:18:33 +0000567 class Options {
568 public:
Guo-wei Shieha7446d22016-01-11 15:27:03 -0800569 Options()
570 : disable_encryption(false),
571 disable_sctp_data_channels(false),
572 disable_network_monitor(false),
573 network_ignore_mask(rtc::kDefaultNetworkIgnoreMask),
574 ssl_max_version(rtc::SSL_PROTOCOL_DTLS_12) {}
wu@webrtc.org97077a32013-10-25 21:18:33 +0000575 bool disable_encryption;
576 bool disable_sctp_data_channels;
honghaiz023f3ef2015-10-19 09:39:32 -0700577 bool disable_network_monitor;
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000578
579 // Sets the network types to ignore. For instance, calling this with
580 // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
581 // loopback interfaces.
582 int network_ignore_mask;
Joachim Bauch04e5b492015-05-29 09:40:39 +0200583
584 // Sets the maximum supported protocol version. The highest version
585 // supported by both ends will be used for the connection, i.e. if one
586 // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used.
587 rtc::SSLProtocolVersion ssl_max_version;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000588 };
589
590 virtual void SetOptions(const Options& options) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000591
deadbeef41b07982015-12-01 15:01:24 -0800592 virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
593 const PeerConnectionInterface::RTCConfiguration& configuration,
594 const MediaConstraintsInterface* constraints,
kwibergd1fe2812016-04-27 06:47:29 -0700595 std::unique_ptr<cricket::PortAllocator> allocator,
596 std::unique_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800597 PeerConnectionObserver* observer) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000598
htaa2a49d92016-03-04 02:51:39 -0800599 virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
600 const PeerConnectionInterface::RTCConfiguration& configuration,
kwibergd1fe2812016-04-27 06:47:29 -0700601 std::unique_ptr<cricket::PortAllocator> allocator,
602 std::unique_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
htaa2a49d92016-03-04 02:51:39 -0800603 PeerConnectionObserver* observer) = 0;
604
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000605 virtual rtc::scoped_refptr<MediaStreamInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606 CreateLocalMediaStream(const std::string& label) = 0;
607
608 // Creates a AudioSourceInterface.
609 // |constraints| decides audio processing settings but can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000610 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
htaa2a49d92016-03-04 02:51:39 -0800611 const cricket::AudioOptions& options) = 0;
612 // Deprecated - use version above.
613 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000614 const MediaConstraintsInterface* constraints) = 0;
615
perkja3ede6c2016-03-08 01:27:48 +0100616 // Creates a VideoTrackSourceInterface. The new source take ownership of
htaa2a49d92016-03-04 02:51:39 -0800617 // |capturer|.
perkja3ede6c2016-03-08 01:27:48 +0100618 virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
htaa2a49d92016-03-04 02:51:39 -0800619 cricket::VideoCapturer* capturer) = 0;
620 // A video source creator that allows selection of resolution and frame rate.
621 // |constraints| decides video resolution and frame rate but can
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622 // be NULL.
htaa2a49d92016-03-04 02:51:39 -0800623 // In the NULL case, use the version above.
perkja3ede6c2016-03-08 01:27:48 +0100624 virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000625 cricket::VideoCapturer* capturer,
626 const MediaConstraintsInterface* constraints) = 0;
627
628 // Creates a new local VideoTrack. The same |source| can be used in several
629 // tracks.
perkja3ede6c2016-03-08 01:27:48 +0100630 virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
631 const std::string& label,
632 VideoTrackSourceInterface* source) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000633
634 // Creates an new AudioTrack. At the moment |source| can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000635 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000636 CreateAudioTrack(const std::string& label,
637 AudioSourceInterface* source) = 0;
638
wu@webrtc.orga9890802013-12-13 00:21:03 +0000639 // Starts AEC dump using existing file. Takes ownership of |file| and passes
640 // it on to VoiceEngine (via other objects) immediately, which will take
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000641 // the ownerhip. If the operation fails, the file will be closed.
ivocd66b44d2016-01-15 03:06:36 -0800642 // A maximum file size in bytes can be specified. When the file size limit is
643 // reached, logging is stopped automatically. If max_size_bytes is set to a
644 // value <= 0, no limit will be used, and logging will continue until the
645 // StopAecDump function is called.
646 virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000647
ivoc797ef122015-10-22 03:25:41 -0700648 // Stops logging the AEC dump.
649 virtual void StopAecDump() = 0;
650
ivoc112a3d82015-10-16 02:22:18 -0700651 // Starts RtcEventLog using existing file. Takes ownership of |file| and
652 // passes it on to VoiceEngine, which will take the ownership. If the
653 // operation fails the file will be closed. The logging will stop
654 // automatically after 10 minutes have passed, or when the StopRtcEventLog
655 // function is called.
656 // This function as well as the StopRtcEventLog don't really belong on this
657 // interface, this is a temporary solution until we move the logging object
658 // from inside voice engine to webrtc::Call, which will happen when the VoE
659 // restructuring effort is further along.
660 // TODO(ivoc): Move this into being:
661 // PeerConnection => MediaController => webrtc::Call.
662 virtual bool StartRtcEventLog(rtc::PlatformFile file) = 0;
663
664 // Stops logging the RtcEventLog.
665 virtual void StopRtcEventLog() = 0;
666
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000667 protected:
668 // Dtor and ctor protected as objects shouldn't be created or deleted via
669 // this interface.
670 PeerConnectionFactoryInterface() {}
671 ~PeerConnectionFactoryInterface() {} // NOLINT
672};
673
674// Create a new instance of PeerConnectionFactoryInterface.
Taylor Brandstettera8415fe2016-03-23 10:38:07 -0700675//
676// This method relies on the thread it's called on as the "signaling thread"
677// for the PeerConnectionFactory it creates.
678//
679// As such, if the current thread is not already running an rtc::Thread message
680// loop, an application using this method must eventually either call
681// rtc::Thread::Current()->Run(), or call
682// rtc::Thread::Current()->ProcessMessages() within the application's own
683// message loop.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000684rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000685CreatePeerConnectionFactory();
686
687// Create a new instance of PeerConnectionFactoryInterface.
Taylor Brandstettera8415fe2016-03-23 10:38:07 -0700688//
689// |worker_thread| and |signaling_thread| are the only mandatory
690// parameters.
691//
692// If non-null, ownership of |default_adm|, |encoder_factory| and
693// |decoder_factory| are transferred to the returned factory.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000694rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000695CreatePeerConnectionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000696 rtc::Thread* worker_thread,
697 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000698 AudioDeviceModule* default_adm,
699 cricket::WebRtcVideoEncoderFactory* encoder_factory,
700 cricket::WebRtcVideoDecoderFactory* decoder_factory);
701
702} // namespace webrtc
703
Henrik Kjellander15583c12016-02-10 10:53:12 +0100704#endif // WEBRTC_API_PEERCONNECTIONINTERFACE_H_