blob: 35ba705b88c24cb3ddef5c6c6d08e701a1e07de4 [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"
81#include "webrtc/base/socketaddress.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000083namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084class Thread;
85}
86
87namespace cricket {
88class PortAllocator;
89class WebRtcVideoDecoderFactory;
90class WebRtcVideoEncoderFactory;
91}
92
93namespace webrtc {
94class AudioDeviceModule;
95class MediaConstraintsInterface;
96
97// MediaStream container interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000098class StreamCollectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099 public:
100 // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find.
101 virtual size_t count() = 0;
102 virtual MediaStreamInterface* at(size_t index) = 0;
103 virtual MediaStreamInterface* find(const std::string& label) = 0;
104 virtual MediaStreamTrackInterface* FindAudioTrack(
105 const std::string& id) = 0;
106 virtual MediaStreamTrackInterface* FindVideoTrack(
107 const std::string& id) = 0;
108
109 protected:
110 // Dtor protected as objects shouldn't be deleted via this interface.
111 ~StreamCollectionInterface() {}
112};
113
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000114class StatsObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115 public:
tommi@webrtc.orge2e199b2014-12-15 13:22:54 +0000116 virtual void OnComplete(const StatsReports& reports) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117
118 protected:
119 virtual ~StatsObserver() {}
120};
121
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000122class MetricsObserverInterface : public rtc::RefCountInterface {
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000123 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000124 virtual void IncrementCounter(PeerConnectionMetricsCounter type) = 0;
125 virtual void AddHistogramSample(PeerConnectionMetricsName type,
mallinath@webrtc.orgd37bcfa2014-05-12 23:10:18 +0000126 int value) = 0;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000127
128 protected:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000129 virtual ~MetricsObserverInterface() {}
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000130};
131
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000132typedef MetricsObserverInterface UMAObserver;
133
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000134class PeerConnectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135 public:
136 // See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions .
137 enum SignalingState {
138 kStable,
139 kHaveLocalOffer,
140 kHaveLocalPrAnswer,
141 kHaveRemoteOffer,
142 kHaveRemotePrAnswer,
143 kClosed,
144 };
145
146 // TODO(bemasc): Remove IceState when callers are changed to
147 // IceConnection/GatheringState.
148 enum IceState {
149 kIceNew,
150 kIceGathering,
151 kIceWaiting,
152 kIceChecking,
153 kIceConnected,
154 kIceCompleted,
155 kIceFailed,
156 kIceClosed,
157 };
158
159 enum IceGatheringState {
160 kIceGatheringNew,
161 kIceGatheringGathering,
162 kIceGatheringComplete
163 };
164
165 enum IceConnectionState {
166 kIceConnectionNew,
167 kIceConnectionChecking,
168 kIceConnectionConnected,
169 kIceConnectionCompleted,
170 kIceConnectionFailed,
171 kIceConnectionDisconnected,
172 kIceConnectionClosed,
173 };
174
175 struct IceServer {
176 std::string uri;
177 std::string username;
178 std::string password;
179 };
180 typedef std::vector<IceServer> IceServers;
181
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000182 enum IceTransportsType {
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000183 // TODO(pthatcher): Rename these kTransporTypeXXX, but update
184 // Chromium at the same time.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000185 kNone,
186 kRelay,
187 kNoHost,
188 kAll
189 };
190
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000191 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-08#section-4.1.1
192 enum BundlePolicy {
193 kBundlePolicyBalanced,
194 kBundlePolicyMaxBundle,
195 kBundlePolicyMaxCompat
196 };
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000197
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000198 struct RTCConfiguration {
199 // TODO(pthatcher): Rename this ice_transport_type, but update
200 // Chromium at the same time.
201 IceTransportsType type;
202 // TODO(pthatcher): Rename this ice_servers, but update Chromium
203 // at the same time.
204 IceServers servers;
205 BundlePolicy bundle_policy;
206
207 RTCConfiguration() : type(kAll), bundle_policy(kBundlePolicyBalanced) {}
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000208 };
209
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000210 struct RTCOfferAnswerOptions {
211 static const int kUndefined = -1;
212 static const int kMaxOfferToReceiveMedia = 1;
213
214 // The default value for constraint offerToReceiveX:true.
215 static const int kOfferToReceiveMediaTrue = 1;
216
217 int offer_to_receive_video;
218 int offer_to_receive_audio;
219 bool voice_activity_detection;
220 bool ice_restart;
221 bool use_rtp_mux;
222
223 RTCOfferAnswerOptions()
224 : offer_to_receive_video(kUndefined),
225 offer_to_receive_audio(kUndefined),
226 voice_activity_detection(true),
227 ice_restart(false),
228 use_rtp_mux(true) {}
229
230 RTCOfferAnswerOptions(int offer_to_receive_video,
231 int offer_to_receive_audio,
232 bool voice_activity_detection,
233 bool ice_restart,
234 bool use_rtp_mux)
235 : offer_to_receive_video(offer_to_receive_video),
236 offer_to_receive_audio(offer_to_receive_audio),
237 voice_activity_detection(voice_activity_detection),
238 ice_restart(ice_restart),
239 use_rtp_mux(use_rtp_mux) {}
240 };
241
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000242 // Used by GetStats to decide which stats to include in the stats reports.
243 // |kStatsOutputLevelStandard| includes the standard stats for Javascript API;
244 // |kStatsOutputLevelDebug| includes both the standard stats and additional
245 // stats for debugging purposes.
246 enum StatsOutputLevel {
247 kStatsOutputLevelStandard,
248 kStatsOutputLevelDebug,
249 };
250
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251 // Accessor methods to active local streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000252 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 local_streams() = 0;
254
255 // Accessor methods to remote streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000256 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 remote_streams() = 0;
258
259 // Add a new MediaStream to be sent on this PeerConnection.
260 // Note that a SessionDescription negotiation is needed before the
261 // remote peer can receive the stream.
perkj@webrtc.orgfd0efb62014-11-06 12:16:36 +0000262 virtual bool AddStream(MediaStreamInterface* stream) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263
264 // Remove a MediaStream from this PeerConnection.
265 // Note that a SessionDescription negotiation is need before the
266 // remote peer is notified.
267 virtual void RemoveStream(MediaStreamInterface* stream) = 0;
268
269 // Returns pointer to the created DtmfSender on success.
270 // Otherwise returns NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000271 virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 AudioTrackInterface* track) = 0;
273
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000274 virtual bool GetStats(StatsObserver* observer,
275 MediaStreamTrackInterface* track,
276 StatsOutputLevel level) = 0;
277
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000278 virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279 const std::string& label,
280 const DataChannelInit* config) = 0;
281
282 virtual const SessionDescriptionInterface* local_description() const = 0;
283 virtual const SessionDescriptionInterface* remote_description() const = 0;
284
285 // Create a new offer.
286 // The CreateSessionDescriptionObserver callback will be called when done.
287 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000288 const MediaConstraintsInterface* constraints) {}
289
290 // TODO(jiayl): remove the default impl and the old interface when chromium
291 // code is updated.
292 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
293 const RTCOfferAnswerOptions& options) {}
294
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295 // Create an answer to an offer.
296 // The CreateSessionDescriptionObserver callback will be called when done.
297 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
298 const MediaConstraintsInterface* constraints) = 0;
299 // Sets the local session description.
300 // JsepInterface takes the ownership of |desc| even if it fails.
301 // The |observer| callback will be called when done.
302 virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
303 SessionDescriptionInterface* desc) = 0;
304 // Sets the remote session description.
305 // JsepInterface takes the ownership of |desc| even if it fails.
306 // The |observer| callback will be called when done.
307 virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
308 SessionDescriptionInterface* desc) = 0;
309 // Restarts or updates the ICE Agent process of gathering local candidates
310 // and pinging remote candidates.
311 virtual bool UpdateIce(const IceServers& configuration,
312 const MediaConstraintsInterface* constraints) = 0;
313 // Provides a remote candidate to the ICE Agent.
314 // A copy of the |candidate| will be created and added to the remote
315 // description. So the caller of this method still has the ownership of the
316 // |candidate|.
317 // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will
318 // take the ownership of the |candidate|.
319 virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
320
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000321 virtual void RegisterUMAObserver(UMAObserver* observer) = 0;
322
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323 // Returns the current SignalingState.
324 virtual SignalingState signaling_state() = 0;
325
326 // TODO(bemasc): Remove ice_state when callers are changed to
327 // IceConnection/GatheringState.
328 // Returns the current IceState.
329 virtual IceState ice_state() = 0;
330 virtual IceConnectionState ice_connection_state() = 0;
331 virtual IceGatheringState ice_gathering_state() = 0;
332
333 // Terminates all media and closes the transport.
334 virtual void Close() = 0;
335
336 protected:
337 // Dtor protected as objects shouldn't be deleted via this interface.
338 ~PeerConnectionInterface() {}
339};
340
341// PeerConnection callback interface. Application should implement these
342// methods.
343class PeerConnectionObserver {
344 public:
345 enum StateType {
346 kSignalingState,
347 kIceState,
348 };
349
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 // Triggered when the SignalingState changed.
351 virtual void OnSignalingChange(
352 PeerConnectionInterface::SignalingState new_state) {}
353
354 // Triggered when SignalingState or IceState have changed.
355 // TODO(bemasc): Remove once callers transition to OnSignalingChange.
356 virtual void OnStateChange(StateType state_changed) {}
357
358 // Triggered when media is received on a new stream from remote peer.
359 virtual void OnAddStream(MediaStreamInterface* stream) = 0;
360
361 // Triggered when a remote peer close a stream.
362 virtual void OnRemoveStream(MediaStreamInterface* stream) = 0;
363
364 // Triggered when a remote peer open a data channel.
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000365 virtual void OnDataChannel(DataChannelInterface* data_channel) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366
mallinath@webrtc.org0d92ef62014-01-22 02:21:22 +0000367 // Triggered when renegotiation is needed, for example the ICE has restarted.
fischman@webrtc.orgd7568a02014-01-13 22:04:12 +0000368 virtual void OnRenegotiationNeeded() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369
370 // Called any time the IceConnectionState changes
371 virtual void OnIceConnectionChange(
372 PeerConnectionInterface::IceConnectionState new_state) {}
373
374 // Called any time the IceGatheringState changes
375 virtual void OnIceGatheringChange(
376 PeerConnectionInterface::IceGatheringState new_state) {}
377
378 // New Ice candidate have been found.
379 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
380
381 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
382 // All Ice candidates have been found.
383 virtual void OnIceComplete() {}
384
385 protected:
386 // Dtor protected as objects shouldn't be deleted via this interface.
387 ~PeerConnectionObserver() {}
388};
389
390// Factory class used for creating cricket::PortAllocator that is used
391// for ICE negotiation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000392class PortAllocatorFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000393 public:
394 struct StunConfiguration {
395 StunConfiguration(const std::string& address, int port)
396 : server(address, port) {}
397 // STUN server address and port.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000398 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000399 };
400
401 struct TurnConfiguration {
402 TurnConfiguration(const std::string& address,
403 int port,
404 const std::string& username,
405 const std::string& password,
wu@webrtc.org91053e72013-08-10 07:18:04 +0000406 const std::string& transport_type,
407 bool secure)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000408 : server(address, port),
409 username(username),
410 password(password),
wu@webrtc.org91053e72013-08-10 07:18:04 +0000411 transport_type(transport_type),
412 secure(secure) {}
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000413 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414 std::string username;
415 std::string password;
416 std::string transport_type;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000417 bool secure;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418 };
419
420 virtual cricket::PortAllocator* CreatePortAllocator(
421 const std::vector<StunConfiguration>& stun_servers,
422 const std::vector<TurnConfiguration>& turn_configurations) = 0;
423
424 protected:
425 PortAllocatorFactoryInterface() {}
426 ~PortAllocatorFactoryInterface() {}
427};
428
429// Used to receive callbacks of DTLS identity requests.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000430class DTLSIdentityRequestObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431 public:
432 virtual void OnFailure(int error) = 0;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000433 virtual void OnSuccess(const std::string& der_cert,
434 const std::string& der_private_key) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000435 protected:
436 virtual ~DTLSIdentityRequestObserver() {}
437};
438
439class DTLSIdentityServiceInterface {
440 public:
441 // Asynchronously request a DTLS identity, including a self-signed certificate
442 // and the private key used to sign the certificate, from the identity store
443 // for the given identity name.
444 // DTLSIdentityRequestObserver::OnSuccess will be called with the identity if
445 // the request succeeded; DTLSIdentityRequestObserver::OnFailure will be
446 // called with an error code if the request failed.
447 //
448 // Only one request can be made at a time. If a second request is called
449 // before the first one completes, RequestIdentity will abort and return
450 // false.
451 //
452 // |identity_name| is an internal name selected by the client to identify an
453 // identity within an origin. E.g. an web site may cache the certificates used
454 // to communicate with differnent peers under different identity names.
455 //
456 // |common_name| is the common name used to generate the certificate. If the
457 // certificate already exists in the store, |common_name| is ignored.
458 //
459 // |observer| is the object to receive success or failure callbacks.
460 //
461 // Returns true if either OnFailure or OnSuccess will be called.
462 virtual bool RequestIdentity(
463 const std::string& identity_name,
464 const std::string& common_name,
465 DTLSIdentityRequestObserver* observer) = 0;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000466
467 virtual ~DTLSIdentityServiceInterface() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468};
469
470// PeerConnectionFactoryInterface is the factory interface use for creating
471// PeerConnection, MediaStream and media tracks.
472// PeerConnectionFactoryInterface will create required libjingle threads,
473// socket and network manager factory classes for networking.
474// If an application decides to provide its own threads and network
475// implementation of these classes it should use the alternate
476// CreatePeerConnectionFactory method which accepts threads as input and use the
477// CreatePeerConnection version that takes a PortAllocatorFactoryInterface as
478// argument.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000479class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480 public:
wu@webrtc.org97077a32013-10-25 21:18:33 +0000481 class Options {
482 public:
483 Options() :
wu@webrtc.org97077a32013-10-25 21:18:33 +0000484 disable_encryption(false),
485 disable_sctp_data_channels(false) {
486 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000487 bool disable_encryption;
488 bool disable_sctp_data_channels;
489 };
490
491 virtual void SetOptions(const Options& options) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000492
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000493 virtual rtc::scoped_refptr<PeerConnectionInterface>
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000494 CreatePeerConnection(
495 const PeerConnectionInterface::RTCConfiguration& configuration,
496 const MediaConstraintsInterface* constraints,
497 PortAllocatorFactoryInterface* allocator_factory,
498 DTLSIdentityServiceInterface* dtls_identity_service,
499 PeerConnectionObserver* observer) = 0;
500
501 // TODO(mallinath) : Remove below versions after clients are updated
502 // to above method.
503 // In latest W3C WebRTC draft, PC constructor will take RTCConfiguration,
504 // and not IceServers. RTCConfiguration is made up of ice servers and
505 // ice transport type.
506 // http://dev.w3.org/2011/webrtc/editor/webrtc.html
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000507 inline rtc::scoped_refptr<PeerConnectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000508 CreatePeerConnection(
509 const PeerConnectionInterface::IceServers& configuration,
510 const MediaConstraintsInterface* constraints,
511 PortAllocatorFactoryInterface* allocator_factory,
512 DTLSIdentityServiceInterface* dtls_identity_service,
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000513 PeerConnectionObserver* observer) {
514 PeerConnectionInterface::RTCConfiguration rtc_config;
515 rtc_config.servers = configuration;
516 return CreatePeerConnection(rtc_config, constraints, allocator_factory,
517 dtls_identity_service, observer);
518 }
519
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000520 virtual rtc::scoped_refptr<MediaStreamInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521 CreateLocalMediaStream(const std::string& label) = 0;
522
523 // Creates a AudioSourceInterface.
524 // |constraints| decides audio processing settings but can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000525 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000526 const MediaConstraintsInterface* constraints) = 0;
527
528 // Creates a VideoSourceInterface. The new source take ownership of
529 // |capturer|. |constraints| decides video resolution and frame rate but can
530 // be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000531 virtual rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000532 cricket::VideoCapturer* capturer,
533 const MediaConstraintsInterface* constraints) = 0;
534
535 // Creates a new local VideoTrack. The same |source| can be used in several
536 // tracks.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000537 virtual rtc::scoped_refptr<VideoTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000538 CreateVideoTrack(const std::string& label,
539 VideoSourceInterface* source) = 0;
540
541 // Creates an new AudioTrack. At the moment |source| can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000542 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000543 CreateAudioTrack(const std::string& label,
544 AudioSourceInterface* source) = 0;
545
wu@webrtc.orga9890802013-12-13 00:21:03 +0000546 // Starts AEC dump using existing file. Takes ownership of |file| and passes
547 // it on to VoiceEngine (via other objects) immediately, which will take
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000548 // the ownerhip. If the operation fails, the file will be closed.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000549 // TODO(grunell): Remove when Chromium has started to use AEC in each source.
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000550 // http://crbug.com/264611.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000551 virtual bool StartAecDump(rtc::PlatformFile file) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000552
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553 protected:
554 // Dtor and ctor protected as objects shouldn't be created or deleted via
555 // this interface.
556 PeerConnectionFactoryInterface() {}
557 ~PeerConnectionFactoryInterface() {} // NOLINT
558};
559
560// Create a new instance of PeerConnectionFactoryInterface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000561rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000562CreatePeerConnectionFactory();
563
564// Create a new instance of PeerConnectionFactoryInterface.
565// Ownership of |factory|, |default_adm|, and optionally |encoder_factory| and
566// |decoder_factory| transferred to the returned factory.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000567rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568CreatePeerConnectionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000569 rtc::Thread* worker_thread,
570 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 AudioDeviceModule* default_adm,
572 cricket::WebRtcVideoEncoderFactory* encoder_factory,
573 cricket::WebRtcVideoDecoderFactory* decoder_factory);
574
575} // namespace webrtc
576
577#endif // TALK_APP_WEBRTC_PEERCONNECTIONINTERFACE_H_