blob: f0a79a638c53b1f6741c5f37c503456094b7570a [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28// This file contains the PeerConnection interface as defined in
29// http://dev.w3.org/2011/webrtc/editor/webrtc.html#peer-to-peer-connections.
30// Applications must use this interface to implement peerconnection.
31// PeerConnectionFactory class provides factory methods to create
32// peerconnection, mediastream and media tracks objects.
33//
34// The Following steps are needed to setup a typical call using Jsep.
35// 1. Create a PeerConnectionFactoryInterface. Check constructors for more
36// information about input parameters.
37// 2. Create a PeerConnection object. Provide a configuration string which
38// points either to stun or turn server to generate ICE candidates and provide
39// an object that implements the PeerConnectionObserver interface.
40// 3. Create local MediaStream and MediaTracks using the PeerConnectionFactory
41// and add it to PeerConnection by calling AddStream.
42// 4. Create an offer and serialize it and send it to the remote peer.
43// 5. Once an ice candidate have been found PeerConnection will call the
44// observer function OnIceCandidate. The candidates must also be serialized and
45// sent to the remote peer.
46// 6. Once an answer is received from the remote peer, call
47// SetLocalSessionDescription with the offer and SetRemoteSessionDescription
48// with the remote answer.
49// 7. Once a remote candidate is received from the remote peer, provide it to
50// the peerconnection by calling AddIceCandidate.
51
52
53// The Receiver of a call can decide to accept or reject the call.
54// This decision will be taken by the application not peerconnection.
55// If application decides to accept the call
56// 1. Create PeerConnectionFactoryInterface if it doesn't exist.
57// 2. Create a new PeerConnection.
58// 3. Provide the remote offer to the new PeerConnection object by calling
59// SetRemoteSessionDescription.
60// 4. Generate an answer to the remote offer by calling CreateAnswer and send it
61// back to the remote peer.
62// 5. Provide the local answer to the new PeerConnection by calling
63// SetLocalSessionDescription with the answer.
64// 6. Provide the remote ice candidates by calling AddIceCandidate.
65// 7. Once a candidate have been found PeerConnection will call the observer
66// function OnIceCandidate. Send these candidates to the remote peer.
67
68#ifndef TALK_APP_WEBRTC_PEERCONNECTIONINTERFACE_H_
69#define TALK_APP_WEBRTC_PEERCONNECTIONINTERFACE_H_
70
71#include <string>
72#include <vector>
73
74#include "talk/app/webrtc/datachannelinterface.h"
Henrik Boström5b4ce332015-08-05 16:55:22 +020075#include "talk/app/webrtc/dtlsidentitystore.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076#include "talk/app/webrtc/dtmfsenderinterface.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020077#include "talk/app/webrtc/dtlsidentitystore.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078#include "talk/app/webrtc/jsep.h"
79#include "talk/app/webrtc/mediastreaminterface.h"
deadbeef70ab1a12015-09-28 16:53:55 -070080#include "talk/app/webrtc/rtpreceiverinterface.h"
81#include "talk/app/webrtc/rtpsenderinterface.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082#include "talk/app/webrtc/statstypes.h"
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +000083#include "talk/app/webrtc/umametrics.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000084#include "webrtc/base/fileutils.h"
phoglund@webrtc.org006521d2015-02-12 09:23:59 +000085#include "webrtc/base/network.h"
Henrik Boström87713d02015-08-25 09:53:21 +020086#include "webrtc/base/rtccertificate.h"
Joachim Bauch04e5b492015-05-29 09:40:39 +020087#include "webrtc/base/sslstreamadapter.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000088#include "webrtc/base/socketaddress.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000090namespace rtc {
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000091class SSLIdentity;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092class Thread;
93}
94
95namespace cricket {
96class PortAllocator;
97class WebRtcVideoDecoderFactory;
98class WebRtcVideoEncoderFactory;
99}
100
101namespace webrtc {
102class AudioDeviceModule;
103class MediaConstraintsInterface;
104
105// MediaStream container interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000106class StreamCollectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107 public:
108 // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find.
109 virtual size_t count() = 0;
110 virtual MediaStreamInterface* at(size_t index) = 0;
111 virtual MediaStreamInterface* find(const std::string& label) = 0;
112 virtual MediaStreamTrackInterface* FindAudioTrack(
113 const std::string& id) = 0;
114 virtual MediaStreamTrackInterface* FindVideoTrack(
115 const std::string& id) = 0;
116
117 protected:
118 // Dtor protected as objects shouldn't be deleted via this interface.
119 ~StreamCollectionInterface() {}
120};
121
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000122class StatsObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123 public:
tommi@webrtc.orge2e199b2014-12-15 13:22:54 +0000124 virtual void OnComplete(const StatsReports& reports) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125
126 protected:
127 virtual ~StatsObserver() {}
128};
129
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000130class MetricsObserverInterface : public rtc::RefCountInterface {
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000131 public:
Guo-wei Shieh3d564c12015-08-19 16:51:15 -0700132
133 // |type| is the type of the enum counter to be incremented. |counter|
134 // is the particular counter in that type. |counter_max| is the next sequence
135 // number after the highest counter.
136 virtual void IncrementEnumCounter(PeerConnectionEnumCounterType type,
137 int counter,
138 int counter_max) {}
139
Guo-wei Shieh456696a2015-09-30 21:48:54 -0700140 // This is used to handle sparse counters like SSL cipher suites.
141 // TODO(guoweis): Remove the implementation once the dependency's interface
142 // definition is updated.
143 virtual void IncrementSparseEnumCounter(PeerConnectionEnumCounterType type,
144 int counter) {
145 IncrementEnumCounter(type, counter, 0 /* Ignored */);
146 }
147
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000148 virtual void AddHistogramSample(PeerConnectionMetricsName type,
mallinath@webrtc.orgd37bcfa2014-05-12 23:10:18 +0000149 int value) = 0;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000150
151 protected:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000152 virtual ~MetricsObserverInterface() {}
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000153};
154
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000155typedef MetricsObserverInterface UMAObserver;
156
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000157class PeerConnectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000158 public:
159 // See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions .
160 enum SignalingState {
161 kStable,
162 kHaveLocalOffer,
163 kHaveLocalPrAnswer,
164 kHaveRemoteOffer,
165 kHaveRemotePrAnswer,
166 kClosed,
167 };
168
169 // TODO(bemasc): Remove IceState when callers are changed to
170 // IceConnection/GatheringState.
171 enum IceState {
172 kIceNew,
173 kIceGathering,
174 kIceWaiting,
175 kIceChecking,
176 kIceConnected,
177 kIceCompleted,
178 kIceFailed,
179 kIceClosed,
180 };
181
182 enum IceGatheringState {
183 kIceGatheringNew,
184 kIceGatheringGathering,
185 kIceGatheringComplete
186 };
187
188 enum IceConnectionState {
189 kIceConnectionNew,
190 kIceConnectionChecking,
191 kIceConnectionConnected,
192 kIceConnectionCompleted,
193 kIceConnectionFailed,
194 kIceConnectionDisconnected,
195 kIceConnectionClosed,
Guo-wei Shieh3d564c12015-08-19 16:51:15 -0700196 kIceConnectionMax,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000197 };
198
199 struct IceServer {
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200200 // TODO(jbauch): Remove uri when all code using it has switched to urls.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000201 std::string uri;
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200202 std::vector<std::string> urls;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 std::string username;
204 std::string password;
205 };
206 typedef std::vector<IceServer> IceServers;
207
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000208 enum IceTransportsType {
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000209 // TODO(pthatcher): Rename these kTransporTypeXXX, but update
210 // Chromium at the same time.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000211 kNone,
212 kRelay,
213 kNoHost,
214 kAll
215 };
216
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000217 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-08#section-4.1.1
218 enum BundlePolicy {
219 kBundlePolicyBalanced,
220 kBundlePolicyMaxBundle,
221 kBundlePolicyMaxCompat
222 };
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000223
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700224 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-09#section-4.1.1
225 enum RtcpMuxPolicy {
226 kRtcpMuxPolicyNegotiate,
227 kRtcpMuxPolicyRequire,
228 };
229
Jiayang Liucac1b382015-04-30 12:35:24 -0700230 enum TcpCandidatePolicy {
231 kTcpCandidatePolicyEnabled,
232 kTcpCandidatePolicyDisabled
233 };
234
honghaiz1f429e32015-09-28 07:57:34 -0700235 enum ContinualGatheringPolicy {
236 GATHER_ONCE,
237 GATHER_CONTINUALLY
238 };
239
Henrik Boström87713d02015-08-25 09:53:21 +0200240 // TODO(hbos): Change into class with private data and public getters.
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000241 struct RTCConfiguration {
honghaiz4edc39c2015-09-01 09:53:56 -0700242 static const int kUndefined = -1;
243 // Default maximum number of packets in the audio jitter buffer.
244 static const int kAudioJitterBufferMaxPackets = 50;
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000245 // TODO(pthatcher): Rename this ice_transport_type, but update
246 // Chromium at the same time.
247 IceTransportsType type;
248 // TODO(pthatcher): Rename this ice_servers, but update Chromium
249 // at the same time.
250 IceServers servers;
251 BundlePolicy bundle_policy;
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700252 RtcpMuxPolicy rtcp_mux_policy;
Jiayang Liucac1b382015-04-30 12:35:24 -0700253 TcpCandidatePolicy tcp_candidate_policy;
Henrik Lundin64dad832015-05-11 12:44:23 +0200254 int audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200255 bool audio_jitter_buffer_fast_accelerate;
honghaiz4edc39c2015-09-01 09:53:56 -0700256 int ice_connection_receiving_timeout;
honghaiz1f429e32015-09-28 07:57:34 -0700257 ContinualGatheringPolicy continual_gathering_policy;
Henrik Boström87713d02015-08-25 09:53:21 +0200258 std::vector<rtc::scoped_refptr<rtc::RTCCertificate>> certificates;
qiangchen444682a2015-11-24 18:07:56 -0800259 bool disable_prerenderer_smoothing;
Jiayang Liucac1b382015-04-30 12:35:24 -0700260 RTCConfiguration()
261 : type(kAll),
262 bundle_policy(kBundlePolicyBalanced),
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700263 rtcp_mux_policy(kRtcpMuxPolicyNegotiate),
Henrik Lundin64dad832015-05-11 12:44:23 +0200264 tcp_candidate_policy(kTcpCandidatePolicyEnabled),
honghaiz4edc39c2015-09-01 09:53:56 -0700265 audio_jitter_buffer_max_packets(kAudioJitterBufferMaxPackets),
266 audio_jitter_buffer_fast_accelerate(false),
honghaiz1f429e32015-09-28 07:57:34 -0700267 ice_connection_receiving_timeout(kUndefined),
qiangchen444682a2015-11-24 18:07:56 -0800268 continual_gathering_policy(GATHER_ONCE),
269 disable_prerenderer_smoothing(false) {}
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000270 };
271
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000272 struct RTCOfferAnswerOptions {
273 static const int kUndefined = -1;
274 static const int kMaxOfferToReceiveMedia = 1;
275
276 // The default value for constraint offerToReceiveX:true.
277 static const int kOfferToReceiveMediaTrue = 1;
278
279 int offer_to_receive_video;
280 int offer_to_receive_audio;
281 bool voice_activity_detection;
282 bool ice_restart;
283 bool use_rtp_mux;
284
285 RTCOfferAnswerOptions()
286 : offer_to_receive_video(kUndefined),
287 offer_to_receive_audio(kUndefined),
288 voice_activity_detection(true),
289 ice_restart(false),
290 use_rtp_mux(true) {}
291
292 RTCOfferAnswerOptions(int offer_to_receive_video,
293 int offer_to_receive_audio,
294 bool voice_activity_detection,
295 bool ice_restart,
296 bool use_rtp_mux)
297 : offer_to_receive_video(offer_to_receive_video),
298 offer_to_receive_audio(offer_to_receive_audio),
299 voice_activity_detection(voice_activity_detection),
300 ice_restart(ice_restart),
301 use_rtp_mux(use_rtp_mux) {}
302 };
303
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000304 // Used by GetStats to decide which stats to include in the stats reports.
305 // |kStatsOutputLevelStandard| includes the standard stats for Javascript API;
306 // |kStatsOutputLevelDebug| includes both the standard stats and additional
307 // stats for debugging purposes.
308 enum StatsOutputLevel {
309 kStatsOutputLevelStandard,
310 kStatsOutputLevelDebug,
311 };
312
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 // Accessor methods to active local streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000314 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315 local_streams() = 0;
316
317 // Accessor methods to remote streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000318 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319 remote_streams() = 0;
320
321 // Add a new MediaStream to be sent on this PeerConnection.
322 // Note that a SessionDescription negotiation is needed before the
323 // remote peer can receive the stream.
perkj@webrtc.orgfd0efb62014-11-06 12:16:36 +0000324 virtual bool AddStream(MediaStreamInterface* stream) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325
326 // Remove a MediaStream from this PeerConnection.
327 // Note that a SessionDescription negotiation is need before the
328 // remote peer is notified.
329 virtual void RemoveStream(MediaStreamInterface* stream) = 0;
330
331 // Returns pointer to the created DtmfSender on success.
332 // Otherwise returns NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000333 virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334 AudioTrackInterface* track) = 0;
335
deadbeef70ab1a12015-09-28 16:53:55 -0700336 // TODO(deadbeef): Make these pure virtual once all subclasses implement them.
deadbeeffac06552015-11-25 11:26:01 -0800337 // |kind| must be "audio" or "video".
338 virtual rtc::scoped_refptr<RtpSenderInterface> CreateSender(
339 const std::string& kind) {
340 return rtc::scoped_refptr<RtpSenderInterface>();
341 }
342
deadbeef70ab1a12015-09-28 16:53:55 -0700343 virtual std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
344 const {
345 return std::vector<rtc::scoped_refptr<RtpSenderInterface>>();
346 }
347
348 virtual std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
349 const {
350 return std::vector<rtc::scoped_refptr<RtpReceiverInterface>>();
351 }
352
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000353 virtual bool GetStats(StatsObserver* observer,
354 MediaStreamTrackInterface* track,
355 StatsOutputLevel level) = 0;
356
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000357 virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 const std::string& label,
359 const DataChannelInit* config) = 0;
360
361 virtual const SessionDescriptionInterface* local_description() const = 0;
362 virtual const SessionDescriptionInterface* remote_description() const = 0;
363
364 // Create a new offer.
365 // The CreateSessionDescriptionObserver callback will be called when done.
366 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000367 const MediaConstraintsInterface* constraints) {}
368
369 // TODO(jiayl): remove the default impl and the old interface when chromium
370 // code is updated.
371 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
372 const RTCOfferAnswerOptions& options) {}
373
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000374 // Create an answer to an offer.
375 // The CreateSessionDescriptionObserver callback will be called when done.
376 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
377 const MediaConstraintsInterface* constraints) = 0;
378 // Sets the local session description.
379 // JsepInterface takes the ownership of |desc| even if it fails.
380 // The |observer| callback will be called when done.
381 virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
382 SessionDescriptionInterface* desc) = 0;
383 // Sets the remote session description.
384 // JsepInterface takes the ownership of |desc| even if it fails.
385 // The |observer| callback will be called when done.
386 virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
387 SessionDescriptionInterface* desc) = 0;
388 // Restarts or updates the ICE Agent process of gathering local candidates
389 // and pinging remote candidates.
deadbeefa67696b2015-09-29 11:56:26 -0700390 // TODO(deadbeef): Remove once Chrome is moved over to SetConfiguration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000391 virtual bool UpdateIce(const IceServers& configuration,
deadbeefa67696b2015-09-29 11:56:26 -0700392 const MediaConstraintsInterface* constraints) {
393 return false;
394 }
395 // Sets the PeerConnection's global configuration to |config|.
396 // Any changes to STUN/TURN servers or ICE candidate policy will affect the
397 // next gathering phase, and cause the next call to createOffer to generate
398 // new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies
399 // cannot be changed with this method.
400 // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of
401 // PeerConnectionInterface implement it.
402 virtual bool SetConfiguration(
403 const PeerConnectionInterface::RTCConfiguration& config) {
404 return false;
405 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000406 // Provides a remote candidate to the ICE Agent.
407 // A copy of the |candidate| will be created and added to the remote
408 // description. So the caller of this method still has the ownership of the
409 // |candidate|.
410 // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will
411 // take the ownership of the |candidate|.
412 virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
413
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000414 virtual void RegisterUMAObserver(UMAObserver* observer) = 0;
415
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416 // Returns the current SignalingState.
417 virtual SignalingState signaling_state() = 0;
418
419 // TODO(bemasc): Remove ice_state when callers are changed to
420 // IceConnection/GatheringState.
421 // Returns the current IceState.
422 virtual IceState ice_state() = 0;
423 virtual IceConnectionState ice_connection_state() = 0;
424 virtual IceGatheringState ice_gathering_state() = 0;
425
426 // Terminates all media and closes the transport.
427 virtual void Close() = 0;
428
429 protected:
430 // Dtor protected as objects shouldn't be deleted via this interface.
431 ~PeerConnectionInterface() {}
432};
433
434// PeerConnection callback interface. Application should implement these
435// methods.
436class PeerConnectionObserver {
437 public:
438 enum StateType {
439 kSignalingState,
440 kIceState,
441 };
442
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443 // Triggered when the SignalingState changed.
444 virtual void OnSignalingChange(
445 PeerConnectionInterface::SignalingState new_state) {}
446
447 // Triggered when SignalingState or IceState have changed.
448 // TODO(bemasc): Remove once callers transition to OnSignalingChange.
449 virtual void OnStateChange(StateType state_changed) {}
450
451 // Triggered when media is received on a new stream from remote peer.
452 virtual void OnAddStream(MediaStreamInterface* stream) = 0;
453
454 // Triggered when a remote peer close a stream.
455 virtual void OnRemoveStream(MediaStreamInterface* stream) = 0;
456
457 // Triggered when a remote peer open a data channel.
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000458 virtual void OnDataChannel(DataChannelInterface* data_channel) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459
mallinath@webrtc.org0d92ef62014-01-22 02:21:22 +0000460 // Triggered when renegotiation is needed, for example the ICE has restarted.
fischman@webrtc.orgd7568a02014-01-13 22:04:12 +0000461 virtual void OnRenegotiationNeeded() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462
463 // Called any time the IceConnectionState changes
464 virtual void OnIceConnectionChange(
465 PeerConnectionInterface::IceConnectionState new_state) {}
466
467 // Called any time the IceGatheringState changes
468 virtual void OnIceGatheringChange(
469 PeerConnectionInterface::IceGatheringState new_state) {}
470
471 // New Ice candidate have been found.
472 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
473
474 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
475 // All Ice candidates have been found.
476 virtual void OnIceComplete() {}
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
486// Factory class used for creating cricket::PortAllocator that is used
487// for ICE negotiation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000488class PortAllocatorFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000489 public:
490 struct StunConfiguration {
491 StunConfiguration(const std::string& address, int port)
492 : server(address, port) {}
493 // STUN server address and port.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000494 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000495 };
496
497 struct TurnConfiguration {
498 TurnConfiguration(const std::string& address,
499 int port,
500 const std::string& username,
501 const std::string& password,
wu@webrtc.org91053e72013-08-10 07:18:04 +0000502 const std::string& transport_type,
503 bool secure)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000504 : server(address, port),
505 username(username),
506 password(password),
wu@webrtc.org91053e72013-08-10 07:18:04 +0000507 transport_type(transport_type),
508 secure(secure) {}
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000509 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000510 std::string username;
511 std::string password;
512 std::string transport_type;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000513 bool secure;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000514 };
515
516 virtual cricket::PortAllocator* CreatePortAllocator(
517 const std::vector<StunConfiguration>& stun_servers,
518 const std::vector<TurnConfiguration>& turn_configurations) = 0;
519
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000520 // TODO(phoglund): Make pure virtual when Chrome's factory implements this.
521 // After this method is called, the port allocator should consider loopback
522 // network interfaces as well.
523 virtual void SetNetworkIgnoreMask(int network_ignore_mask) {
524 }
525
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000526 protected:
527 PortAllocatorFactoryInterface() {}
528 ~PortAllocatorFactoryInterface() {}
529};
530
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000531// PeerConnectionFactoryInterface is the factory interface use for creating
532// PeerConnection, MediaStream and media tracks.
533// PeerConnectionFactoryInterface will create required libjingle threads,
534// socket and network manager factory classes for networking.
535// If an application decides to provide its own threads and network
536// implementation of these classes it should use the alternate
537// CreatePeerConnectionFactory method which accepts threads as input and use the
538// CreatePeerConnection version that takes a PortAllocatorFactoryInterface as
539// argument.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000540class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000541 public:
wu@webrtc.org97077a32013-10-25 21:18:33 +0000542 class Options {
543 public:
544 Options() :
wu@webrtc.org97077a32013-10-25 21:18:33 +0000545 disable_encryption(false),
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000546 disable_sctp_data_channels(false),
honghaiz023f3ef2015-10-19 09:39:32 -0700547 disable_network_monitor(false),
Joachim Bauch04e5b492015-05-29 09:40:39 +0200548 network_ignore_mask(rtc::kDefaultNetworkIgnoreMask),
549 ssl_max_version(rtc::SSL_PROTOCOL_DTLS_10) {
wu@webrtc.org97077a32013-10-25 21:18:33 +0000550 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000551 bool disable_encryption;
552 bool disable_sctp_data_channels;
honghaiz023f3ef2015-10-19 09:39:32 -0700553 bool disable_network_monitor;
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000554
555 // Sets the network types to ignore. For instance, calling this with
556 // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
557 // loopback interfaces.
558 int network_ignore_mask;
Joachim Bauch04e5b492015-05-29 09:40:39 +0200559
560 // Sets the maximum supported protocol version. The highest version
561 // supported by both ends will be used for the connection, i.e. if one
562 // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used.
563 rtc::SSLProtocolVersion ssl_max_version;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000564 };
565
566 virtual void SetOptions(const Options& options) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000567
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000568 virtual rtc::scoped_refptr<PeerConnectionInterface>
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000569 CreatePeerConnection(
570 const PeerConnectionInterface::RTCConfiguration& configuration,
571 const MediaConstraintsInterface* constraints,
572 PortAllocatorFactoryInterface* allocator_factory,
Henrik Boström5e56c592015-08-11 10:33:13 +0200573 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000574 PeerConnectionObserver* observer) = 0;
575
Henrik Boström5e56c592015-08-11 10:33:13 +0200576 // TODO(hbos): Remove below version after clients are updated to above method.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000577 // In latest W3C WebRTC draft, PC constructor will take RTCConfiguration,
578 // and not IceServers. RTCConfiguration is made up of ice servers and
579 // ice transport type.
580 // http://dev.w3.org/2011/webrtc/editor/webrtc.html
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000581 inline rtc::scoped_refptr<PeerConnectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582 CreatePeerConnection(
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000583 const PeerConnectionInterface::IceServers& servers,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 const MediaConstraintsInterface* constraints,
585 PortAllocatorFactoryInterface* allocator_factory,
Henrik Boström5e56c592015-08-11 10:33:13 +0200586 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000587 PeerConnectionObserver* observer) {
588 PeerConnectionInterface::RTCConfiguration rtc_config;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000589 rtc_config.servers = servers;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000590 return CreatePeerConnection(rtc_config, constraints, allocator_factory,
Henrik Boström5e56c592015-08-11 10:33:13 +0200591 dtls_identity_store.Pass(), observer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000592 }
593
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000594 virtual rtc::scoped_refptr<MediaStreamInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000595 CreateLocalMediaStream(const std::string& label) = 0;
596
597 // Creates a AudioSourceInterface.
598 // |constraints| decides audio processing settings but can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000599 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000600 const MediaConstraintsInterface* constraints) = 0;
601
602 // Creates a VideoSourceInterface. The new source take ownership of
603 // |capturer|. |constraints| decides video resolution and frame rate but can
604 // be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000605 virtual rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606 cricket::VideoCapturer* capturer,
607 const MediaConstraintsInterface* constraints) = 0;
608
609 // Creates a new local VideoTrack. The same |source| can be used in several
610 // tracks.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000611 virtual rtc::scoped_refptr<VideoTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612 CreateVideoTrack(const std::string& label,
613 VideoSourceInterface* source) = 0;
614
615 // Creates an new AudioTrack. At the moment |source| can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000616 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000617 CreateAudioTrack(const std::string& label,
618 AudioSourceInterface* source) = 0;
619
wu@webrtc.orga9890802013-12-13 00:21:03 +0000620 // Starts AEC dump using existing file. Takes ownership of |file| and passes
621 // it on to VoiceEngine (via other objects) immediately, which will take
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000622 // the ownerhip. If the operation fails, the file will be closed.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000623 // TODO(grunell): Remove when Chromium has started to use AEC in each source.
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000624 // http://crbug.com/264611.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000625 virtual bool StartAecDump(rtc::PlatformFile file) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000626
ivoc797ef122015-10-22 03:25:41 -0700627 // Stops logging the AEC dump.
628 virtual void StopAecDump() = 0;
629
ivoc112a3d82015-10-16 02:22:18 -0700630 // Starts RtcEventLog using existing file. Takes ownership of |file| and
631 // passes it on to VoiceEngine, which will take the ownership. If the
632 // operation fails the file will be closed. The logging will stop
633 // automatically after 10 minutes have passed, or when the StopRtcEventLog
634 // function is called.
635 // This function as well as the StopRtcEventLog don't really belong on this
636 // interface, this is a temporary solution until we move the logging object
637 // from inside voice engine to webrtc::Call, which will happen when the VoE
638 // restructuring effort is further along.
639 // TODO(ivoc): Move this into being:
640 // PeerConnection => MediaController => webrtc::Call.
641 virtual bool StartRtcEventLog(rtc::PlatformFile file) = 0;
642
643 // Stops logging the RtcEventLog.
644 virtual void StopRtcEventLog() = 0;
645
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000646 protected:
647 // Dtor and ctor protected as objects shouldn't be created or deleted via
648 // this interface.
649 PeerConnectionFactoryInterface() {}
650 ~PeerConnectionFactoryInterface() {} // NOLINT
651};
652
653// Create a new instance of PeerConnectionFactoryInterface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000654rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000655CreatePeerConnectionFactory();
656
657// Create a new instance of PeerConnectionFactoryInterface.
658// Ownership of |factory|, |default_adm|, and optionally |encoder_factory| and
659// |decoder_factory| transferred to the returned factory.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000660rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000661CreatePeerConnectionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000662 rtc::Thread* worker_thread,
663 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664 AudioDeviceModule* default_adm,
665 cricket::WebRtcVideoEncoderFactory* encoder_factory,
666 cricket::WebRtcVideoDecoderFactory* decoder_factory);
667
668} // namespace webrtc
669
670#endif // TALK_APP_WEBRTC_PEERCONNECTIONINTERFACE_H_