blob: 391255ff24f3d305883ad98649b832fd710a6cda [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"
75#include "talk/app/webrtc/dtmfsenderinterface.h"
76#include "talk/app/webrtc/jsep.h"
77#include "talk/app/webrtc/mediastreaminterface.h"
78#include "talk/app/webrtc/statstypes.h"
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +000079#include "talk/app/webrtc/umametrics.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000080#include "webrtc/base/fileutils.h"
phoglund@webrtc.org006521d2015-02-12 09:23:59 +000081#include "webrtc/base/network.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000082#include "webrtc/base/socketaddress.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000084namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085class Thread;
86}
87
88namespace cricket {
89class PortAllocator;
90class WebRtcVideoDecoderFactory;
91class WebRtcVideoEncoderFactory;
92}
93
94namespace webrtc {
95class AudioDeviceModule;
96class MediaConstraintsInterface;
97
98// MediaStream container interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000099class StreamCollectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100 public:
101 // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find.
102 virtual size_t count() = 0;
103 virtual MediaStreamInterface* at(size_t index) = 0;
104 virtual MediaStreamInterface* find(const std::string& label) = 0;
105 virtual MediaStreamTrackInterface* FindAudioTrack(
106 const std::string& id) = 0;
107 virtual MediaStreamTrackInterface* FindVideoTrack(
108 const std::string& id) = 0;
109
110 protected:
111 // Dtor protected as objects shouldn't be deleted via this interface.
112 ~StreamCollectionInterface() {}
113};
114
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000115class StatsObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116 public:
tommi@webrtc.orge2e199b2014-12-15 13:22:54 +0000117 virtual void OnComplete(const StatsReports& reports) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118
119 protected:
120 virtual ~StatsObserver() {}
121};
122
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000123class MetricsObserverInterface : public rtc::RefCountInterface {
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000124 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000125 virtual void IncrementCounter(PeerConnectionMetricsCounter type) = 0;
126 virtual void AddHistogramSample(PeerConnectionMetricsName type,
mallinath@webrtc.orgd37bcfa2014-05-12 23:10:18 +0000127 int value) = 0;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000128
129 protected:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000130 virtual ~MetricsObserverInterface() {}
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000131};
132
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000133typedef MetricsObserverInterface UMAObserver;
134
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000135class PeerConnectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136 public:
137 // See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions .
138 enum SignalingState {
139 kStable,
140 kHaveLocalOffer,
141 kHaveLocalPrAnswer,
142 kHaveRemoteOffer,
143 kHaveRemotePrAnswer,
144 kClosed,
145 };
146
147 // TODO(bemasc): Remove IceState when callers are changed to
148 // IceConnection/GatheringState.
149 enum IceState {
150 kIceNew,
151 kIceGathering,
152 kIceWaiting,
153 kIceChecking,
154 kIceConnected,
155 kIceCompleted,
156 kIceFailed,
157 kIceClosed,
158 };
159
160 enum IceGatheringState {
161 kIceGatheringNew,
162 kIceGatheringGathering,
163 kIceGatheringComplete
164 };
165
166 enum IceConnectionState {
167 kIceConnectionNew,
168 kIceConnectionChecking,
169 kIceConnectionConnected,
170 kIceConnectionCompleted,
171 kIceConnectionFailed,
172 kIceConnectionDisconnected,
173 kIceConnectionClosed,
174 };
175
176 struct IceServer {
177 std::string uri;
178 std::string username;
179 std::string password;
180 };
181 typedef std::vector<IceServer> IceServers;
182
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000183 enum IceTransportsType {
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000184 // TODO(pthatcher): Rename these kTransporTypeXXX, but update
185 // Chromium at the same time.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000186 kNone,
187 kRelay,
188 kNoHost,
189 kAll
190 };
191
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000192 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-08#section-4.1.1
193 enum BundlePolicy {
194 kBundlePolicyBalanced,
195 kBundlePolicyMaxBundle,
196 kBundlePolicyMaxCompat
197 };
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000198
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000199 struct RTCConfiguration {
200 // TODO(pthatcher): Rename this ice_transport_type, but update
201 // Chromium at the same time.
202 IceTransportsType type;
203 // TODO(pthatcher): Rename this ice_servers, but update Chromium
204 // at the same time.
205 IceServers servers;
206 BundlePolicy bundle_policy;
207
208 RTCConfiguration() : type(kAll), bundle_policy(kBundlePolicyBalanced) {}
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000209 };
210
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000211 struct RTCOfferAnswerOptions {
212 static const int kUndefined = -1;
213 static const int kMaxOfferToReceiveMedia = 1;
214
215 // The default value for constraint offerToReceiveX:true.
216 static const int kOfferToReceiveMediaTrue = 1;
217
218 int offer_to_receive_video;
219 int offer_to_receive_audio;
220 bool voice_activity_detection;
221 bool ice_restart;
222 bool use_rtp_mux;
223
224 RTCOfferAnswerOptions()
225 : offer_to_receive_video(kUndefined),
226 offer_to_receive_audio(kUndefined),
227 voice_activity_detection(true),
228 ice_restart(false),
229 use_rtp_mux(true) {}
230
231 RTCOfferAnswerOptions(int offer_to_receive_video,
232 int offer_to_receive_audio,
233 bool voice_activity_detection,
234 bool ice_restart,
235 bool use_rtp_mux)
236 : offer_to_receive_video(offer_to_receive_video),
237 offer_to_receive_audio(offer_to_receive_audio),
238 voice_activity_detection(voice_activity_detection),
239 ice_restart(ice_restart),
240 use_rtp_mux(use_rtp_mux) {}
241 };
242
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000243 // Used by GetStats to decide which stats to include in the stats reports.
244 // |kStatsOutputLevelStandard| includes the standard stats for Javascript API;
245 // |kStatsOutputLevelDebug| includes both the standard stats and additional
246 // stats for debugging purposes.
247 enum StatsOutputLevel {
248 kStatsOutputLevelStandard,
249 kStatsOutputLevelDebug,
250 };
251
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 // Accessor methods to active local streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000253 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254 local_streams() = 0;
255
256 // Accessor methods to remote streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000257 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 remote_streams() = 0;
259
260 // Add a new MediaStream to be sent on this PeerConnection.
261 // Note that a SessionDescription negotiation is needed before the
262 // remote peer can receive the stream.
perkj@webrtc.orgfd0efb62014-11-06 12:16:36 +0000263 virtual bool AddStream(MediaStreamInterface* stream) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264
265 // Remove a MediaStream from this PeerConnection.
266 // Note that a SessionDescription negotiation is need before the
267 // remote peer is notified.
268 virtual void RemoveStream(MediaStreamInterface* stream) = 0;
269
270 // Returns pointer to the created DtmfSender on success.
271 // Otherwise returns NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000272 virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273 AudioTrackInterface* track) = 0;
274
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000275 virtual bool GetStats(StatsObserver* observer,
276 MediaStreamTrackInterface* track,
277 StatsOutputLevel level) = 0;
278
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000279 virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280 const std::string& label,
281 const DataChannelInit* config) = 0;
282
283 virtual const SessionDescriptionInterface* local_description() const = 0;
284 virtual const SessionDescriptionInterface* remote_description() const = 0;
285
286 // Create a new offer.
287 // The CreateSessionDescriptionObserver callback will be called when done.
288 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000289 const MediaConstraintsInterface* constraints) {}
290
291 // TODO(jiayl): remove the default impl and the old interface when chromium
292 // code is updated.
293 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
294 const RTCOfferAnswerOptions& options) {}
295
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000296 // Create an answer to an offer.
297 // The CreateSessionDescriptionObserver callback will be called when done.
298 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
299 const MediaConstraintsInterface* constraints) = 0;
300 // Sets the local session description.
301 // JsepInterface takes the ownership of |desc| even if it fails.
302 // The |observer| callback will be called when done.
303 virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
304 SessionDescriptionInterface* desc) = 0;
305 // Sets the remote session description.
306 // JsepInterface takes the ownership of |desc| even if it fails.
307 // The |observer| callback will be called when done.
308 virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
309 SessionDescriptionInterface* desc) = 0;
310 // Restarts or updates the ICE Agent process of gathering local candidates
311 // and pinging remote candidates.
312 virtual bool UpdateIce(const IceServers& configuration,
313 const MediaConstraintsInterface* constraints) = 0;
314 // Provides a remote candidate to the ICE Agent.
315 // A copy of the |candidate| will be created and added to the remote
316 // description. So the caller of this method still has the ownership of the
317 // |candidate|.
318 // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will
319 // take the ownership of the |candidate|.
320 virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
321
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000322 virtual void RegisterUMAObserver(UMAObserver* observer) = 0;
323
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 // Returns the current SignalingState.
325 virtual SignalingState signaling_state() = 0;
326
327 // TODO(bemasc): Remove ice_state when callers are changed to
328 // IceConnection/GatheringState.
329 // Returns the current IceState.
330 virtual IceState ice_state() = 0;
331 virtual IceConnectionState ice_connection_state() = 0;
332 virtual IceGatheringState ice_gathering_state() = 0;
333
334 // Terminates all media and closes the transport.
335 virtual void Close() = 0;
336
337 protected:
338 // Dtor protected as objects shouldn't be deleted via this interface.
339 ~PeerConnectionInterface() {}
340};
341
342// PeerConnection callback interface. Application should implement these
343// methods.
344class PeerConnectionObserver {
345 public:
346 enum StateType {
347 kSignalingState,
348 kIceState,
349 };
350
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 // Triggered when the SignalingState changed.
352 virtual void OnSignalingChange(
353 PeerConnectionInterface::SignalingState new_state) {}
354
355 // Triggered when SignalingState or IceState have changed.
356 // TODO(bemasc): Remove once callers transition to OnSignalingChange.
357 virtual void OnStateChange(StateType state_changed) {}
358
359 // Triggered when media is received on a new stream from remote peer.
360 virtual void OnAddStream(MediaStreamInterface* stream) = 0;
361
362 // Triggered when a remote peer close a stream.
363 virtual void OnRemoveStream(MediaStreamInterface* stream) = 0;
364
365 // Triggered when a remote peer open a data channel.
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000366 virtual void OnDataChannel(DataChannelInterface* data_channel) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367
mallinath@webrtc.org0d92ef62014-01-22 02:21:22 +0000368 // Triggered when renegotiation is needed, for example the ICE has restarted.
fischman@webrtc.orgd7568a02014-01-13 22:04:12 +0000369 virtual void OnRenegotiationNeeded() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370
371 // Called any time the IceConnectionState changes
372 virtual void OnIceConnectionChange(
373 PeerConnectionInterface::IceConnectionState new_state) {}
374
375 // Called any time the IceGatheringState changes
376 virtual void OnIceGatheringChange(
377 PeerConnectionInterface::IceGatheringState new_state) {}
378
379 // New Ice candidate have been found.
380 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
381
382 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
383 // All Ice candidates have been found.
384 virtual void OnIceComplete() {}
385
386 protected:
387 // Dtor protected as objects shouldn't be deleted via this interface.
388 ~PeerConnectionObserver() {}
389};
390
391// Factory class used for creating cricket::PortAllocator that is used
392// for ICE negotiation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000393class PortAllocatorFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394 public:
395 struct StunConfiguration {
396 StunConfiguration(const std::string& address, int port)
397 : server(address, port) {}
398 // STUN server address and port.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000399 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000400 };
401
402 struct TurnConfiguration {
403 TurnConfiguration(const std::string& address,
404 int port,
405 const std::string& username,
406 const std::string& password,
wu@webrtc.org91053e72013-08-10 07:18:04 +0000407 const std::string& transport_type,
408 bool secure)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000409 : server(address, port),
410 username(username),
411 password(password),
wu@webrtc.org91053e72013-08-10 07:18:04 +0000412 transport_type(transport_type),
413 secure(secure) {}
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000414 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415 std::string username;
416 std::string password;
417 std::string transport_type;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000418 bool secure;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419 };
420
421 virtual cricket::PortAllocator* CreatePortAllocator(
422 const std::vector<StunConfiguration>& stun_servers,
423 const std::vector<TurnConfiguration>& turn_configurations) = 0;
424
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000425 // TODO(phoglund): Make pure virtual when Chrome's factory implements this.
426 // After this method is called, the port allocator should consider loopback
427 // network interfaces as well.
428 virtual void SetNetworkIgnoreMask(int network_ignore_mask) {
429 }
430
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431 protected:
432 PortAllocatorFactoryInterface() {}
433 ~PortAllocatorFactoryInterface() {}
434};
435
436// Used to receive callbacks of DTLS identity requests.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000437class DTLSIdentityRequestObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000438 public:
439 virtual void OnFailure(int error) = 0;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000440 virtual void OnSuccess(const std::string& der_cert,
441 const std::string& der_private_key) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000442 protected:
443 virtual ~DTLSIdentityRequestObserver() {}
444};
445
446class DTLSIdentityServiceInterface {
447 public:
448 // Asynchronously request a DTLS identity, including a self-signed certificate
449 // and the private key used to sign the certificate, from the identity store
450 // for the given identity name.
451 // DTLSIdentityRequestObserver::OnSuccess will be called with the identity if
452 // the request succeeded; DTLSIdentityRequestObserver::OnFailure will be
453 // called with an error code if the request failed.
454 //
455 // Only one request can be made at a time. If a second request is called
456 // before the first one completes, RequestIdentity will abort and return
457 // false.
458 //
459 // |identity_name| is an internal name selected by the client to identify an
460 // identity within an origin. E.g. an web site may cache the certificates used
461 // to communicate with differnent peers under different identity names.
462 //
463 // |common_name| is the common name used to generate the certificate. If the
464 // certificate already exists in the store, |common_name| is ignored.
465 //
466 // |observer| is the object to receive success or failure callbacks.
467 //
468 // Returns true if either OnFailure or OnSuccess will be called.
469 virtual bool RequestIdentity(
470 const std::string& identity_name,
471 const std::string& common_name,
472 DTLSIdentityRequestObserver* observer) = 0;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000473
474 virtual ~DTLSIdentityServiceInterface() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475};
476
477// PeerConnectionFactoryInterface is the factory interface use for creating
478// PeerConnection, MediaStream and media tracks.
479// PeerConnectionFactoryInterface will create required libjingle threads,
480// socket and network manager factory classes for networking.
481// If an application decides to provide its own threads and network
482// implementation of these classes it should use the alternate
483// CreatePeerConnectionFactory method which accepts threads as input and use the
484// CreatePeerConnection version that takes a PortAllocatorFactoryInterface as
485// argument.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000486class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000487 public:
wu@webrtc.org97077a32013-10-25 21:18:33 +0000488 class Options {
489 public:
490 Options() :
wu@webrtc.org97077a32013-10-25 21:18:33 +0000491 disable_encryption(false),
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000492 disable_sctp_data_channels(false),
493 network_ignore_mask(rtc::kDefaultNetworkIgnoreMask) {
wu@webrtc.org97077a32013-10-25 21:18:33 +0000494 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000495 bool disable_encryption;
496 bool disable_sctp_data_channels;
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000497
498 // Sets the network types to ignore. For instance, calling this with
499 // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
500 // loopback interfaces.
501 int network_ignore_mask;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000502 };
503
504 virtual void SetOptions(const Options& options) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000505
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000506 virtual rtc::scoped_refptr<PeerConnectionInterface>
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000507 CreatePeerConnection(
508 const PeerConnectionInterface::RTCConfiguration& configuration,
509 const MediaConstraintsInterface* constraints,
510 PortAllocatorFactoryInterface* allocator_factory,
511 DTLSIdentityServiceInterface* dtls_identity_service,
512 PeerConnectionObserver* observer) = 0;
513
514 // TODO(mallinath) : Remove below versions after clients are updated
515 // to above method.
516 // In latest W3C WebRTC draft, PC constructor will take RTCConfiguration,
517 // and not IceServers. RTCConfiguration is made up of ice servers and
518 // ice transport type.
519 // http://dev.w3.org/2011/webrtc/editor/webrtc.html
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000520 inline rtc::scoped_refptr<PeerConnectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521 CreatePeerConnection(
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000522 const PeerConnectionInterface::IceServers& servers,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000523 const MediaConstraintsInterface* constraints,
524 PortAllocatorFactoryInterface* allocator_factory,
525 DTLSIdentityServiceInterface* dtls_identity_service,
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000526 PeerConnectionObserver* observer) {
527 PeerConnectionInterface::RTCConfiguration rtc_config;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000528 rtc_config.servers = servers;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000529 return CreatePeerConnection(rtc_config, constraints, allocator_factory,
530 dtls_identity_service, observer);
531 }
532
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000533 virtual rtc::scoped_refptr<MediaStreamInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000534 CreateLocalMediaStream(const std::string& label) = 0;
535
536 // Creates a AudioSourceInterface.
537 // |constraints| decides audio processing settings but can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000538 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 const MediaConstraintsInterface* constraints) = 0;
540
541 // Creates a VideoSourceInterface. The new source take ownership of
542 // |capturer|. |constraints| decides video resolution and frame rate but can
543 // be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000544 virtual rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000545 cricket::VideoCapturer* capturer,
546 const MediaConstraintsInterface* constraints) = 0;
547
548 // Creates a new local VideoTrack. The same |source| can be used in several
549 // tracks.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000550 virtual rtc::scoped_refptr<VideoTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000551 CreateVideoTrack(const std::string& label,
552 VideoSourceInterface* source) = 0;
553
554 // Creates an new AudioTrack. At the moment |source| can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000555 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 CreateAudioTrack(const std::string& label,
557 AudioSourceInterface* source) = 0;
558
wu@webrtc.orga9890802013-12-13 00:21:03 +0000559 // Starts AEC dump using existing file. Takes ownership of |file| and passes
560 // it on to VoiceEngine (via other objects) immediately, which will take
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000561 // the ownerhip. If the operation fails, the file will be closed.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000562 // TODO(grunell): Remove when Chromium has started to use AEC in each source.
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000563 // http://crbug.com/264611.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000564 virtual bool StartAecDump(rtc::PlatformFile file) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000565
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000566 protected:
567 // Dtor and ctor protected as objects shouldn't be created or deleted via
568 // this interface.
569 PeerConnectionFactoryInterface() {}
570 ~PeerConnectionFactoryInterface() {} // NOLINT
571};
572
573// Create a new instance of PeerConnectionFactoryInterface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000574rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575CreatePeerConnectionFactory();
576
577// Create a new instance of PeerConnectionFactoryInterface.
578// Ownership of |factory|, |default_adm|, and optionally |encoder_factory| and
579// |decoder_factory| transferred to the returned factory.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000580rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581CreatePeerConnectionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000582 rtc::Thread* worker_thread,
583 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 AudioDeviceModule* default_adm,
585 cricket::WebRtcVideoEncoderFactory* encoder_factory,
586 cricket::WebRtcVideoDecoderFactory* decoder_factory);
587
588} // namespace webrtc
589
590#endif // TALK_APP_WEBRTC_PEERCONNECTIONINTERFACE_H_