blob: edbf6e31c19073d5e848acf978436000db654ff9 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2012, Google Inc.
4 *
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.org5b06b062014-08-15 08:38:30 +0000116 // TODO(tommi): Remove.
117 virtual void OnComplete(const std::vector<StatsReport>& reports) {}
118
119 // TODO(tommi): Make pure virtual and remove implementation.
120 virtual void OnComplete(const StatsReports& reports) {
121 std::vector<StatsReportCopyable> report_copies;
122 for (size_t i = 0; i < reports.size(); ++i)
123 report_copies.push_back(StatsReportCopyable(*reports[i]));
124 std::vector<StatsReport>* r =
125 reinterpret_cast<std::vector<StatsReport>*>(&report_copies);
126 OnComplete(*r);
127 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000128
129 protected:
130 virtual ~StatsObserver() {}
131};
132
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000133class UMAObserver : public rtc::RefCountInterface {
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000134 public:
mallinath@webrtc.orgd37bcfa2014-05-12 23:10:18 +0000135 virtual void IncrementCounter(PeerConnectionUMAMetricsCounter type) = 0;
136 virtual void AddHistogramSample(PeerConnectionUMAMetricsName type,
137 int value) = 0;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000138
139 protected:
140 virtual ~UMAObserver() {}
141};
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,
182 };
183
184 struct IceServer {
185 std::string uri;
186 std::string username;
187 std::string password;
188 };
189 typedef std::vector<IceServer> IceServers;
190
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000191 enum IceTransportsType {
192 kNone,
193 kRelay,
194 kNoHost,
195 kAll
196 };
197
198 struct RTCConfiguration {
199 IceTransportsType type;
200 IceServers servers;
201
202 RTCConfiguration() : type(kAll) {}
203 explicit RTCConfiguration(IceTransportsType type) : type(type) {}
204 };
205
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000206 struct RTCOfferAnswerOptions {
207 static const int kUndefined = -1;
208 static const int kMaxOfferToReceiveMedia = 1;
209
210 // The default value for constraint offerToReceiveX:true.
211 static const int kOfferToReceiveMediaTrue = 1;
212
213 int offer_to_receive_video;
214 int offer_to_receive_audio;
215 bool voice_activity_detection;
216 bool ice_restart;
217 bool use_rtp_mux;
218
219 RTCOfferAnswerOptions()
220 : offer_to_receive_video(kUndefined),
221 offer_to_receive_audio(kUndefined),
222 voice_activity_detection(true),
223 ice_restart(false),
224 use_rtp_mux(true) {}
225
226 RTCOfferAnswerOptions(int offer_to_receive_video,
227 int offer_to_receive_audio,
228 bool voice_activity_detection,
229 bool ice_restart,
230 bool use_rtp_mux)
231 : offer_to_receive_video(offer_to_receive_video),
232 offer_to_receive_audio(offer_to_receive_audio),
233 voice_activity_detection(voice_activity_detection),
234 ice_restart(ice_restart),
235 use_rtp_mux(use_rtp_mux) {}
236 };
237
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000238 // Used by GetStats to decide which stats to include in the stats reports.
239 // |kStatsOutputLevelStandard| includes the standard stats for Javascript API;
240 // |kStatsOutputLevelDebug| includes both the standard stats and additional
241 // stats for debugging purposes.
242 enum StatsOutputLevel {
243 kStatsOutputLevelStandard,
244 kStatsOutputLevelDebug,
245 };
246
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 // Accessor methods to active local streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000248 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 local_streams() = 0;
250
251 // Accessor methods to remote streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000252 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 remote_streams() = 0;
254
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000255 // Deprecated:
256 // TODO(perkj): Remove once its not used by Chrome.
257 virtual bool AddStream(MediaStreamInterface* stream,
258 const MediaConstraintsInterface* constraints) {
259 return AddStream(stream);
260 }
261
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262 // Add a new MediaStream to be sent on this PeerConnection.
263 // Note that a SessionDescription negotiation is needed before the
264 // remote peer can receive the stream.
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000265 virtual bool AddStream(MediaStreamInterface* stream) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000266
267 // Remove a MediaStream from this PeerConnection.
268 // Note that a SessionDescription negotiation is need before the
269 // remote peer is notified.
270 virtual void RemoveStream(MediaStreamInterface* stream) = 0;
271
272 // Returns pointer to the created DtmfSender on success.
273 // Otherwise returns NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000274 virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275 AudioTrackInterface* track) = 0;
276
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000277 virtual bool GetStats(StatsObserver* observer,
278 MediaStreamTrackInterface* track,
279 StatsOutputLevel level) = 0;
280
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000281 virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282 const std::string& label,
283 const DataChannelInit* config) = 0;
284
285 virtual const SessionDescriptionInterface* local_description() const = 0;
286 virtual const SessionDescriptionInterface* remote_description() const = 0;
287
288 // Create a new offer.
289 // The CreateSessionDescriptionObserver callback will be called when done.
290 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000291 const MediaConstraintsInterface* constraints) {}
292
293 // TODO(jiayl): remove the default impl and the old interface when chromium
294 // code is updated.
295 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
296 const RTCOfferAnswerOptions& options) {}
297
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298 // Create an answer to an offer.
299 // The CreateSessionDescriptionObserver callback will be called when done.
300 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
301 const MediaConstraintsInterface* constraints) = 0;
302 // Sets the local session description.
303 // JsepInterface takes the ownership of |desc| even if it fails.
304 // The |observer| callback will be called when done.
305 virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
306 SessionDescriptionInterface* desc) = 0;
307 // Sets the remote session description.
308 // JsepInterface takes the ownership of |desc| even if it fails.
309 // The |observer| callback will be called when done.
310 virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
311 SessionDescriptionInterface* desc) = 0;
312 // Restarts or updates the ICE Agent process of gathering local candidates
313 // and pinging remote candidates.
314 virtual bool UpdateIce(const IceServers& configuration,
315 const MediaConstraintsInterface* constraints) = 0;
316 // Provides a remote candidate to the ICE Agent.
317 // A copy of the |candidate| will be created and added to the remote
318 // description. So the caller of this method still has the ownership of the
319 // |candidate|.
320 // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will
321 // take the ownership of the |candidate|.
322 virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
323
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000324 virtual void RegisterUMAObserver(UMAObserver* observer) = 0;
325
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 // Returns the current SignalingState.
327 virtual SignalingState signaling_state() = 0;
328
329 // TODO(bemasc): Remove ice_state when callers are changed to
330 // IceConnection/GatheringState.
331 // Returns the current IceState.
332 virtual IceState ice_state() = 0;
333 virtual IceConnectionState ice_connection_state() = 0;
334 virtual IceGatheringState ice_gathering_state() = 0;
335
336 // Terminates all media and closes the transport.
337 virtual void Close() = 0;
338
339 protected:
340 // Dtor protected as objects shouldn't be deleted via this interface.
341 ~PeerConnectionInterface() {}
342};
343
344// PeerConnection callback interface. Application should implement these
345// methods.
346class PeerConnectionObserver {
347 public:
348 enum StateType {
349 kSignalingState,
350 kIceState,
351 };
352
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000353 // Deprecated.
354 // TODO(perkj): Remove once its not used by Chrome.
355 virtual void OnError() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356
357 // Triggered when the SignalingState changed.
358 virtual void OnSignalingChange(
359 PeerConnectionInterface::SignalingState new_state) {}
360
361 // Triggered when SignalingState or IceState have changed.
362 // TODO(bemasc): Remove once callers transition to OnSignalingChange.
363 virtual void OnStateChange(StateType state_changed) {}
364
365 // Triggered when media is received on a new stream from remote peer.
366 virtual void OnAddStream(MediaStreamInterface* stream) = 0;
367
368 // Triggered when a remote peer close a stream.
369 virtual void OnRemoveStream(MediaStreamInterface* stream) = 0;
370
371 // Triggered when a remote peer open a data channel.
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000372 virtual void OnDataChannel(DataChannelInterface* data_channel) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373
mallinath@webrtc.org0d92ef62014-01-22 02:21:22 +0000374 // Triggered when renegotiation is needed, for example the ICE has restarted.
fischman@webrtc.orgd7568a02014-01-13 22:04:12 +0000375 virtual void OnRenegotiationNeeded() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376
377 // Called any time the IceConnectionState changes
378 virtual void OnIceConnectionChange(
379 PeerConnectionInterface::IceConnectionState new_state) {}
380
381 // Called any time the IceGatheringState changes
382 virtual void OnIceGatheringChange(
383 PeerConnectionInterface::IceGatheringState new_state) {}
384
385 // New Ice candidate have been found.
386 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
387
388 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
389 // All Ice candidates have been found.
390 virtual void OnIceComplete() {}
391
392 protected:
393 // Dtor protected as objects shouldn't be deleted via this interface.
394 ~PeerConnectionObserver() {}
395};
396
397// Factory class used for creating cricket::PortAllocator that is used
398// for ICE negotiation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000399class PortAllocatorFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000400 public:
401 struct StunConfiguration {
402 StunConfiguration(const std::string& address, int port)
403 : server(address, port) {}
404 // STUN server address and port.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000405 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000406 };
407
408 struct TurnConfiguration {
409 TurnConfiguration(const std::string& address,
410 int port,
411 const std::string& username,
412 const std::string& password,
wu@webrtc.org91053e72013-08-10 07:18:04 +0000413 const std::string& transport_type,
414 bool secure)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415 : server(address, port),
416 username(username),
417 password(password),
wu@webrtc.org91053e72013-08-10 07:18:04 +0000418 transport_type(transport_type),
419 secure(secure) {}
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000420 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421 std::string username;
422 std::string password;
423 std::string transport_type;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000424 bool secure;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425 };
426
427 virtual cricket::PortAllocator* CreatePortAllocator(
428 const std::vector<StunConfiguration>& stun_servers,
429 const std::vector<TurnConfiguration>& turn_configurations) = 0;
430
431 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),
492 disable_sctp_data_channels(false) {
493 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000494 bool disable_encryption;
495 bool disable_sctp_data_channels;
496 };
497
498 virtual void SetOptions(const Options& options) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000499
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000500 virtual rtc::scoped_refptr<PeerConnectionInterface>
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000501 CreatePeerConnection(
502 const PeerConnectionInterface::RTCConfiguration& configuration,
503 const MediaConstraintsInterface* constraints,
504 PortAllocatorFactoryInterface* allocator_factory,
505 DTLSIdentityServiceInterface* dtls_identity_service,
506 PeerConnectionObserver* observer) = 0;
507
508 // TODO(mallinath) : Remove below versions after clients are updated
509 // to above method.
510 // In latest W3C WebRTC draft, PC constructor will take RTCConfiguration,
511 // and not IceServers. RTCConfiguration is made up of ice servers and
512 // ice transport type.
513 // http://dev.w3.org/2011/webrtc/editor/webrtc.html
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000514 inline rtc::scoped_refptr<PeerConnectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000515 CreatePeerConnection(
516 const PeerConnectionInterface::IceServers& configuration,
517 const MediaConstraintsInterface* constraints,
518 PortAllocatorFactoryInterface* allocator_factory,
519 DTLSIdentityServiceInterface* dtls_identity_service,
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000520 PeerConnectionObserver* observer) {
521 PeerConnectionInterface::RTCConfiguration rtc_config;
522 rtc_config.servers = configuration;
523 return CreatePeerConnection(rtc_config, constraints, allocator_factory,
524 dtls_identity_service, observer);
525 }
526
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000527 virtual rtc::scoped_refptr<MediaStreamInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000528 CreateLocalMediaStream(const std::string& label) = 0;
529
530 // Creates a AudioSourceInterface.
531 // |constraints| decides audio processing settings but can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000532 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533 const MediaConstraintsInterface* constraints) = 0;
534
535 // Creates a VideoSourceInterface. The new source take ownership of
536 // |capturer|. |constraints| decides video resolution and frame rate but can
537 // be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000538 virtual rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 cricket::VideoCapturer* capturer,
540 const MediaConstraintsInterface* constraints) = 0;
541
542 // Creates a new local VideoTrack. The same |source| can be used in several
543 // tracks.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000544 virtual rtc::scoped_refptr<VideoTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000545 CreateVideoTrack(const std::string& label,
546 VideoSourceInterface* source) = 0;
547
548 // Creates an new AudioTrack. At the moment |source| can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000549 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550 CreateAudioTrack(const std::string& label,
551 AudioSourceInterface* source) = 0;
552
wu@webrtc.orga9890802013-12-13 00:21:03 +0000553 // Starts AEC dump using existing file. Takes ownership of |file| and passes
554 // it on to VoiceEngine (via other objects) immediately, which will take
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000555 // the ownerhip. If the operation fails, the file will be closed.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000556 // TODO(grunell): Remove when Chromium has started to use AEC in each source.
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000557 // http://crbug.com/264611.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000558 virtual bool StartAecDump(rtc::PlatformFile file) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000559
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 protected:
561 // Dtor and ctor protected as objects shouldn't be created or deleted via
562 // this interface.
563 PeerConnectionFactoryInterface() {}
564 ~PeerConnectionFactoryInterface() {} // NOLINT
565};
566
567// Create a new instance of PeerConnectionFactoryInterface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000568rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000569CreatePeerConnectionFactory();
570
571// Create a new instance of PeerConnectionFactoryInterface.
572// Ownership of |factory|, |default_adm|, and optionally |encoder_factory| and
573// |decoder_factory| transferred to the returned factory.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000574rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575CreatePeerConnectionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000576 rtc::Thread* worker_thread,
577 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578 AudioDeviceModule* default_adm,
579 cricket::WebRtcVideoEncoderFactory* encoder_factory,
580 cricket::WebRtcVideoDecoderFactory* decoder_factory);
581
582} // namespace webrtc
583
584#endif // TALK_APP_WEBRTC_PEERCONNECTIONINTERFACE_H_