blob: 946b1253c99bfca3ce1bd508a0973f6f437e83d6 [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"
77#include "talk/app/webrtc/jsep.h"
78#include "talk/app/webrtc/mediastreaminterface.h"
79#include "talk/app/webrtc/statstypes.h"
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +000080#include "talk/app/webrtc/umametrics.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000081#include "webrtc/base/fileutils.h"
phoglund@webrtc.org006521d2015-02-12 09:23:59 +000082#include "webrtc/base/network.h"
Joachim Bauch04e5b492015-05-29 09:40:39 +020083#include "webrtc/base/sslstreamadapter.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000084#include "webrtc/base/socketaddress.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000086namespace rtc {
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000087class SSLIdentity;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088class Thread;
89}
90
91namespace cricket {
92class PortAllocator;
93class WebRtcVideoDecoderFactory;
94class WebRtcVideoEncoderFactory;
95}
96
97namespace webrtc {
98class AudioDeviceModule;
99class MediaConstraintsInterface;
100
101// MediaStream container interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000102class StreamCollectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103 public:
104 // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find.
105 virtual size_t count() = 0;
106 virtual MediaStreamInterface* at(size_t index) = 0;
107 virtual MediaStreamInterface* find(const std::string& label) = 0;
108 virtual MediaStreamTrackInterface* FindAudioTrack(
109 const std::string& id) = 0;
110 virtual MediaStreamTrackInterface* FindVideoTrack(
111 const std::string& id) = 0;
112
113 protected:
114 // Dtor protected as objects shouldn't be deleted via this interface.
115 ~StreamCollectionInterface() {}
116};
117
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000118class StatsObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119 public:
tommi@webrtc.orge2e199b2014-12-15 13:22:54 +0000120 virtual void OnComplete(const StatsReports& reports) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121
122 protected:
123 virtual ~StatsObserver() {}
124};
125
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000126class MetricsObserverInterface : public rtc::RefCountInterface {
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000127 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000128 virtual void IncrementCounter(PeerConnectionMetricsCounter type) = 0;
129 virtual void AddHistogramSample(PeerConnectionMetricsName type,
mallinath@webrtc.orgd37bcfa2014-05-12 23:10:18 +0000130 int value) = 0;
jbauchac8869e2015-07-03 01:36:14 -0700131 // TODO(jbauch): Make method abstract when it is implemented by Chromium.
132 virtual void AddHistogramSample(PeerConnectionMetricsName type,
133 const std::string& value) {}
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000134
135 protected:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000136 virtual ~MetricsObserverInterface() {}
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000137};
138
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000139typedef MetricsObserverInterface UMAObserver;
140
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000141class PeerConnectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142 public:
143 // See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions .
144 enum SignalingState {
145 kStable,
146 kHaveLocalOffer,
147 kHaveLocalPrAnswer,
148 kHaveRemoteOffer,
149 kHaveRemotePrAnswer,
150 kClosed,
151 };
152
153 // TODO(bemasc): Remove IceState when callers are changed to
154 // IceConnection/GatheringState.
155 enum IceState {
156 kIceNew,
157 kIceGathering,
158 kIceWaiting,
159 kIceChecking,
160 kIceConnected,
161 kIceCompleted,
162 kIceFailed,
163 kIceClosed,
164 };
165
166 enum IceGatheringState {
167 kIceGatheringNew,
168 kIceGatheringGathering,
169 kIceGatheringComplete
170 };
171
172 enum IceConnectionState {
173 kIceConnectionNew,
174 kIceConnectionChecking,
175 kIceConnectionConnected,
176 kIceConnectionCompleted,
177 kIceConnectionFailed,
178 kIceConnectionDisconnected,
179 kIceConnectionClosed,
180 };
181
182 struct IceServer {
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200183 // TODO(jbauch): Remove uri when all code using it has switched to urls.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 std::string uri;
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200185 std::vector<std::string> urls;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 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 {
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000192 // TODO(pthatcher): Rename these kTransporTypeXXX, but update
193 // Chromium at the same time.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000194 kNone,
195 kRelay,
196 kNoHost,
197 kAll
198 };
199
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000200 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-08#section-4.1.1
201 enum BundlePolicy {
202 kBundlePolicyBalanced,
203 kBundlePolicyMaxBundle,
204 kBundlePolicyMaxCompat
205 };
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000206
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700207 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-09#section-4.1.1
208 enum RtcpMuxPolicy {
209 kRtcpMuxPolicyNegotiate,
210 kRtcpMuxPolicyRequire,
211 };
212
Jiayang Liucac1b382015-04-30 12:35:24 -0700213 enum TcpCandidatePolicy {
214 kTcpCandidatePolicyEnabled,
215 kTcpCandidatePolicyDisabled
216 };
217
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000218 struct RTCConfiguration {
219 // TODO(pthatcher): Rename this ice_transport_type, but update
220 // Chromium at the same time.
221 IceTransportsType type;
222 // TODO(pthatcher): Rename this ice_servers, but update Chromium
223 // at the same time.
224 IceServers servers;
225 BundlePolicy bundle_policy;
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700226 RtcpMuxPolicy rtcp_mux_policy;
Jiayang Liucac1b382015-04-30 12:35:24 -0700227 TcpCandidatePolicy tcp_candidate_policy;
Henrik Lundin64dad832015-05-11 12:44:23 +0200228 int audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200229 bool audio_jitter_buffer_fast_accelerate;
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000230
Jiayang Liucac1b382015-04-30 12:35:24 -0700231 RTCConfiguration()
232 : type(kAll),
233 bundle_policy(kBundlePolicyBalanced),
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700234 rtcp_mux_policy(kRtcpMuxPolicyNegotiate),
Henrik Lundin64dad832015-05-11 12:44:23 +0200235 tcp_candidate_policy(kTcpCandidatePolicyEnabled),
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200236 audio_jitter_buffer_max_packets(50),
237 audio_jitter_buffer_fast_accelerate(false) {}
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000238 };
239
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000240 struct RTCOfferAnswerOptions {
241 static const int kUndefined = -1;
242 static const int kMaxOfferToReceiveMedia = 1;
243
244 // The default value for constraint offerToReceiveX:true.
245 static const int kOfferToReceiveMediaTrue = 1;
246
247 int offer_to_receive_video;
248 int offer_to_receive_audio;
249 bool voice_activity_detection;
250 bool ice_restart;
251 bool use_rtp_mux;
252
253 RTCOfferAnswerOptions()
254 : offer_to_receive_video(kUndefined),
255 offer_to_receive_audio(kUndefined),
256 voice_activity_detection(true),
257 ice_restart(false),
258 use_rtp_mux(true) {}
259
260 RTCOfferAnswerOptions(int offer_to_receive_video,
261 int offer_to_receive_audio,
262 bool voice_activity_detection,
263 bool ice_restart,
264 bool use_rtp_mux)
265 : offer_to_receive_video(offer_to_receive_video),
266 offer_to_receive_audio(offer_to_receive_audio),
267 voice_activity_detection(voice_activity_detection),
268 ice_restart(ice_restart),
269 use_rtp_mux(use_rtp_mux) {}
270 };
271
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000272 // Used by GetStats to decide which stats to include in the stats reports.
273 // |kStatsOutputLevelStandard| includes the standard stats for Javascript API;
274 // |kStatsOutputLevelDebug| includes both the standard stats and additional
275 // stats for debugging purposes.
276 enum StatsOutputLevel {
277 kStatsOutputLevelStandard,
278 kStatsOutputLevelDebug,
279 };
280
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281 // Accessor methods to active local streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000282 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283 local_streams() = 0;
284
285 // Accessor methods to remote streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000286 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000287 remote_streams() = 0;
288
289 // Add a new MediaStream to be sent on this PeerConnection.
290 // Note that a SessionDescription negotiation is needed before the
291 // remote peer can receive the stream.
perkj@webrtc.orgfd0efb62014-11-06 12:16:36 +0000292 virtual bool AddStream(MediaStreamInterface* stream) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293
294 // Remove a MediaStream from this PeerConnection.
295 // Note that a SessionDescription negotiation is need before the
296 // remote peer is notified.
297 virtual void RemoveStream(MediaStreamInterface* stream) = 0;
298
299 // Returns pointer to the created DtmfSender on success.
300 // Otherwise returns NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000301 virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 AudioTrackInterface* track) = 0;
303
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000304 virtual bool GetStats(StatsObserver* observer,
305 MediaStreamTrackInterface* track,
306 StatsOutputLevel level) = 0;
307
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000308 virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 const std::string& label,
310 const DataChannelInit* config) = 0;
311
312 virtual const SessionDescriptionInterface* local_description() const = 0;
313 virtual const SessionDescriptionInterface* remote_description() const = 0;
314
315 // Create a new offer.
316 // The CreateSessionDescriptionObserver callback will be called when done.
317 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000318 const MediaConstraintsInterface* constraints) {}
319
320 // TODO(jiayl): remove the default impl and the old interface when chromium
321 // code is updated.
322 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
323 const RTCOfferAnswerOptions& options) {}
324
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 // Create an answer to an offer.
326 // The CreateSessionDescriptionObserver callback will be called when done.
327 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
328 const MediaConstraintsInterface* constraints) = 0;
329 // Sets the local session description.
330 // JsepInterface takes the ownership of |desc| even if it fails.
331 // The |observer| callback will be called when done.
332 virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
333 SessionDescriptionInterface* desc) = 0;
334 // Sets the remote session description.
335 // JsepInterface takes the ownership of |desc| even if it fails.
336 // The |observer| callback will be called when done.
337 virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
338 SessionDescriptionInterface* desc) = 0;
honghaiz90099622015-07-13 12:19:33 -0700339 // Sets the ICE connection receiving timeout value in milliseconds.
honghaiza03cd3f2015-07-13 17:08:08 -0700340 virtual void SetIceConnectionReceivingTimeout(int timeout_ms) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341 // Restarts or updates the ICE Agent process of gathering local candidates
342 // and pinging remote candidates.
343 virtual bool UpdateIce(const IceServers& configuration,
344 const MediaConstraintsInterface* constraints) = 0;
345 // Provides a remote candidate to the ICE Agent.
346 // A copy of the |candidate| will be created and added to the remote
347 // description. So the caller of this method still has the ownership of the
348 // |candidate|.
349 // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will
350 // take the ownership of the |candidate|.
351 virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
352
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000353 virtual void RegisterUMAObserver(UMAObserver* observer) = 0;
354
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 // Returns the current SignalingState.
356 virtual SignalingState signaling_state() = 0;
357
358 // TODO(bemasc): Remove ice_state when callers are changed to
359 // IceConnection/GatheringState.
360 // Returns the current IceState.
361 virtual IceState ice_state() = 0;
362 virtual IceConnectionState ice_connection_state() = 0;
363 virtual IceGatheringState ice_gathering_state() = 0;
364
365 // Terminates all media and closes the transport.
366 virtual void Close() = 0;
367
368 protected:
369 // Dtor protected as objects shouldn't be deleted via this interface.
370 ~PeerConnectionInterface() {}
371};
372
373// PeerConnection callback interface. Application should implement these
374// methods.
375class PeerConnectionObserver {
376 public:
377 enum StateType {
378 kSignalingState,
379 kIceState,
380 };
381
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000382 // Triggered when the SignalingState changed.
383 virtual void OnSignalingChange(
384 PeerConnectionInterface::SignalingState new_state) {}
385
386 // Triggered when SignalingState or IceState have changed.
387 // TODO(bemasc): Remove once callers transition to OnSignalingChange.
388 virtual void OnStateChange(StateType state_changed) {}
389
390 // Triggered when media is received on a new stream from remote peer.
391 virtual void OnAddStream(MediaStreamInterface* stream) = 0;
392
393 // Triggered when a remote peer close a stream.
394 virtual void OnRemoveStream(MediaStreamInterface* stream) = 0;
395
396 // Triggered when a remote peer open a data channel.
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000397 virtual void OnDataChannel(DataChannelInterface* data_channel) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000398
mallinath@webrtc.org0d92ef62014-01-22 02:21:22 +0000399 // Triggered when renegotiation is needed, for example the ICE has restarted.
fischman@webrtc.orgd7568a02014-01-13 22:04:12 +0000400 virtual void OnRenegotiationNeeded() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000401
402 // Called any time the IceConnectionState changes
403 virtual void OnIceConnectionChange(
404 PeerConnectionInterface::IceConnectionState new_state) {}
405
406 // Called any time the IceGatheringState changes
407 virtual void OnIceGatheringChange(
408 PeerConnectionInterface::IceGatheringState new_state) {}
409
410 // New Ice candidate have been found.
411 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
412
413 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
414 // All Ice candidates have been found.
415 virtual void OnIceComplete() {}
416
Peter Thatcher54360512015-07-08 11:08:35 -0700417 // Called when the ICE connection receiving status changes.
418 virtual void OnIceConnectionReceivingChange(bool receiving) {}
419
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000420 protected:
421 // Dtor protected as objects shouldn't be deleted via this interface.
422 ~PeerConnectionObserver() {}
423};
424
425// Factory class used for creating cricket::PortAllocator that is used
426// for ICE negotiation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000427class PortAllocatorFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000428 public:
429 struct StunConfiguration {
430 StunConfiguration(const std::string& address, int port)
431 : server(address, port) {}
432 // STUN server address and port.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000433 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434 };
435
436 struct TurnConfiguration {
437 TurnConfiguration(const std::string& address,
438 int port,
439 const std::string& username,
440 const std::string& password,
wu@webrtc.org91053e72013-08-10 07:18:04 +0000441 const std::string& transport_type,
442 bool secure)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443 : server(address, port),
444 username(username),
445 password(password),
wu@webrtc.org91053e72013-08-10 07:18:04 +0000446 transport_type(transport_type),
447 secure(secure) {}
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000448 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449 std::string username;
450 std::string password;
451 std::string transport_type;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000452 bool secure;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453 };
454
455 virtual cricket::PortAllocator* CreatePortAllocator(
456 const std::vector<StunConfiguration>& stun_servers,
457 const std::vector<TurnConfiguration>& turn_configurations) = 0;
458
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000459 // TODO(phoglund): Make pure virtual when Chrome's factory implements this.
460 // After this method is called, the port allocator should consider loopback
461 // network interfaces as well.
462 virtual void SetNetworkIgnoreMask(int network_ignore_mask) {
463 }
464
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465 protected:
466 PortAllocatorFactoryInterface() {}
467 ~PortAllocatorFactoryInterface() {}
468};
469
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000470class DTLSIdentityServiceInterface {
471 public:
472 // Asynchronously request a DTLS identity, including a self-signed certificate
473 // and the private key used to sign the certificate, from the identity store
474 // for the given identity name.
475 // DTLSIdentityRequestObserver::OnSuccess will be called with the identity if
476 // the request succeeded; DTLSIdentityRequestObserver::OnFailure will be
477 // called with an error code if the request failed.
478 //
479 // Only one request can be made at a time. If a second request is called
480 // before the first one completes, RequestIdentity will abort and return
481 // false.
482 //
483 // |identity_name| is an internal name selected by the client to identify an
484 // identity within an origin. E.g. an web site may cache the certificates used
485 // to communicate with differnent peers under different identity names.
486 //
487 // |common_name| is the common name used to generate the certificate. If the
488 // certificate already exists in the store, |common_name| is ignored.
489 //
490 // |observer| is the object to receive success or failure callbacks.
491 //
492 // Returns true if either OnFailure or OnSuccess will be called.
493 virtual bool RequestIdentity(
494 const std::string& identity_name,
495 const std::string& common_name,
496 DTLSIdentityRequestObserver* observer) = 0;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000497
498 virtual ~DTLSIdentityServiceInterface() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499};
500
501// PeerConnectionFactoryInterface is the factory interface use for creating
502// PeerConnection, MediaStream and media tracks.
503// PeerConnectionFactoryInterface will create required libjingle threads,
504// socket and network manager factory classes for networking.
505// If an application decides to provide its own threads and network
506// implementation of these classes it should use the alternate
507// CreatePeerConnectionFactory method which accepts threads as input and use the
508// CreatePeerConnection version that takes a PortAllocatorFactoryInterface as
509// argument.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000510class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000511 public:
wu@webrtc.org97077a32013-10-25 21:18:33 +0000512 class Options {
513 public:
514 Options() :
wu@webrtc.org97077a32013-10-25 21:18:33 +0000515 disable_encryption(false),
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000516 disable_sctp_data_channels(false),
Joachim Bauch04e5b492015-05-29 09:40:39 +0200517 network_ignore_mask(rtc::kDefaultNetworkIgnoreMask),
518 ssl_max_version(rtc::SSL_PROTOCOL_DTLS_10) {
wu@webrtc.org97077a32013-10-25 21:18:33 +0000519 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000520 bool disable_encryption;
521 bool disable_sctp_data_channels;
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000522
523 // Sets the network types to ignore. For instance, calling this with
524 // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
525 // loopback interfaces.
526 int network_ignore_mask;
Joachim Bauch04e5b492015-05-29 09:40:39 +0200527
528 // Sets the maximum supported protocol version. The highest version
529 // supported by both ends will be used for the connection, i.e. if one
530 // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used.
531 rtc::SSLProtocolVersion ssl_max_version;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000532 };
533
534 virtual void SetOptions(const Options& options) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000535
Henrik Boström5b4ce332015-08-05 16:55:22 +0200536 // TODO(hbos): Temporary CreatePeerConnection function while we transition
537 // from DTLSIdentityServiceInterface to DtlsIdentityStoreInterface.
538 rtc::scoped_refptr<PeerConnectionInterface>
539 CreatePeerConnection(
540 const PeerConnectionInterface::RTCConfiguration& configuration,
541 const MediaConstraintsInterface* constraints,
542 PortAllocatorFactoryInterface* allocator_factory,
543 DTLSIdentityServiceInterface* dtls_identity_service,
544 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
545 PeerConnectionObserver* observer) {
546 return CreatePeerConnection(configuration, constraints, allocator_factory,
547 dtls_identity_service, observer);
548 }
549
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +0000550 // This method takes the ownership of |dtls_identity_service|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000551 virtual rtc::scoped_refptr<PeerConnectionInterface>
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000552 CreatePeerConnection(
553 const PeerConnectionInterface::RTCConfiguration& configuration,
554 const MediaConstraintsInterface* constraints,
555 PortAllocatorFactoryInterface* allocator_factory,
556 DTLSIdentityServiceInterface* dtls_identity_service,
557 PeerConnectionObserver* observer) = 0;
558
559 // TODO(mallinath) : Remove below versions after clients are updated
560 // to above method.
561 // In latest W3C WebRTC draft, PC constructor will take RTCConfiguration,
562 // and not IceServers. RTCConfiguration is made up of ice servers and
563 // ice transport type.
564 // http://dev.w3.org/2011/webrtc/editor/webrtc.html
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000565 inline rtc::scoped_refptr<PeerConnectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000566 CreatePeerConnection(
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000567 const PeerConnectionInterface::IceServers& servers,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568 const MediaConstraintsInterface* constraints,
569 PortAllocatorFactoryInterface* allocator_factory,
570 DTLSIdentityServiceInterface* dtls_identity_service,
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000571 PeerConnectionObserver* observer) {
572 PeerConnectionInterface::RTCConfiguration rtc_config;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000573 rtc_config.servers = servers;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000574 return CreatePeerConnection(rtc_config, constraints, allocator_factory,
575 dtls_identity_service, observer);
576 }
577
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000578 virtual rtc::scoped_refptr<MediaStreamInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000579 CreateLocalMediaStream(const std::string& label) = 0;
580
581 // Creates a AudioSourceInterface.
582 // |constraints| decides audio processing settings but can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000583 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 const MediaConstraintsInterface* constraints) = 0;
585
586 // Creates a VideoSourceInterface. The new source take ownership of
587 // |capturer|. |constraints| decides video resolution and frame rate but can
588 // be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000589 virtual rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000590 cricket::VideoCapturer* capturer,
591 const MediaConstraintsInterface* constraints) = 0;
592
593 // Creates a new local VideoTrack. The same |source| can be used in several
594 // tracks.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000595 virtual rtc::scoped_refptr<VideoTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000596 CreateVideoTrack(const std::string& label,
597 VideoSourceInterface* source) = 0;
598
599 // Creates an new AudioTrack. At the moment |source| can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000600 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000601 CreateAudioTrack(const std::string& label,
602 AudioSourceInterface* source) = 0;
603
wu@webrtc.orga9890802013-12-13 00:21:03 +0000604 // Starts AEC dump using existing file. Takes ownership of |file| and passes
605 // it on to VoiceEngine (via other objects) immediately, which will take
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000606 // the ownerhip. If the operation fails, the file will be closed.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000607 // TODO(grunell): Remove when Chromium has started to use AEC in each source.
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000608 // http://crbug.com/264611.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000609 virtual bool StartAecDump(rtc::PlatformFile file) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000610
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000611 protected:
612 // Dtor and ctor protected as objects shouldn't be created or deleted via
613 // this interface.
614 PeerConnectionFactoryInterface() {}
615 ~PeerConnectionFactoryInterface() {} // NOLINT
616};
617
618// Create a new instance of PeerConnectionFactoryInterface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000619rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000620CreatePeerConnectionFactory();
621
622// Create a new instance of PeerConnectionFactoryInterface.
623// Ownership of |factory|, |default_adm|, and optionally |encoder_factory| and
624// |decoder_factory| transferred to the returned factory.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000625rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626CreatePeerConnectionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000627 rtc::Thread* worker_thread,
628 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000629 AudioDeviceModule* default_adm,
630 cricket::WebRtcVideoEncoderFactory* encoder_factory,
631 cricket::WebRtcVideoDecoderFactory* decoder_factory);
632
633} // namespace webrtc
634
635#endif // TALK_APP_WEBRTC_PEERCONNECTIONINTERFACE_H_