blob: 2f33b415481291a4e8f9d396db4d61e88ac21268 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:133 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:364 *
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 14:55:2275#include "talk/app/webrtc/dtlsidentitystore.h"
henrike@webrtc.org28e20752013-07-10 00:45:3676#include "talk/app/webrtc/dtmfsenderinterface.h"
Henrik Boström5e56c592015-08-11 08:33:1377#include "talk/app/webrtc/dtlsidentitystore.h"
henrike@webrtc.org28e20752013-07-10 00:45:3678#include "talk/app/webrtc/jsep.h"
79#include "talk/app/webrtc/mediastreaminterface.h"
80#include "talk/app/webrtc/statstypes.h"
buildbot@webrtc.org1567b8c2014-05-08 19:54:1681#include "talk/app/webrtc/umametrics.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5282#include "webrtc/base/fileutils.h"
phoglund@webrtc.org006521d2015-02-12 09:23:5983#include "webrtc/base/network.h"
Henrik Boström87713d02015-08-25 07:53:2184#include "webrtc/base/rtccertificate.h"
Joachim Bauch04e5b492015-05-29 07:40:3985#include "webrtc/base/sslstreamadapter.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5286#include "webrtc/base/socketaddress.h"
henrike@webrtc.org28e20752013-07-10 00:45:3687
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5288namespace rtc {
jiayl@webrtc.org61e00b02015-03-04 22:17:3889class SSLIdentity;
henrike@webrtc.org28e20752013-07-10 00:45:3690class Thread;
91}
92
93namespace cricket {
94class PortAllocator;
95class WebRtcVideoDecoderFactory;
96class WebRtcVideoEncoderFactory;
97}
98
99namespace webrtc {
100class AudioDeviceModule;
101class MediaConstraintsInterface;
102
103// MediaStream container interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52104class StreamCollectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36105 public:
106 // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find.
107 virtual size_t count() = 0;
108 virtual MediaStreamInterface* at(size_t index) = 0;
109 virtual MediaStreamInterface* find(const std::string& label) = 0;
110 virtual MediaStreamTrackInterface* FindAudioTrack(
111 const std::string& id) = 0;
112 virtual MediaStreamTrackInterface* FindVideoTrack(
113 const std::string& id) = 0;
114
115 protected:
116 // Dtor protected as objects shouldn't be deleted via this interface.
117 ~StreamCollectionInterface() {}
118};
119
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52120class StatsObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36121 public:
tommi@webrtc.orge2e199b2014-12-15 13:22:54122 virtual void OnComplete(const StatsReports& reports) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36123
124 protected:
125 virtual ~StatsObserver() {}
126};
127
guoweis@webrtc.org7169afd2014-12-04 17:59:29128class MetricsObserverInterface : public rtc::RefCountInterface {
buildbot@webrtc.org1567b8c2014-05-08 19:54:16129 public:
Guo-wei Shieh3d564c12015-08-19 23:51:15130
131 // |type| is the type of the enum counter to be incremented. |counter|
132 // is the particular counter in that type. |counter_max| is the next sequence
133 // number after the highest counter.
134 virtual void IncrementEnumCounter(PeerConnectionEnumCounterType type,
135 int counter,
136 int counter_max) {}
137
guoweis@webrtc.org7169afd2014-12-04 17:59:29138 virtual void AddHistogramSample(PeerConnectionMetricsName type,
mallinath@webrtc.orgd37bcfa2014-05-12 23:10:18139 int value) = 0;
jbauchac8869e2015-07-03 08:36:14140 // TODO(jbauch): Make method abstract when it is implemented by Chromium.
141 virtual void AddHistogramSample(PeerConnectionMetricsName type,
142 const std::string& value) {}
buildbot@webrtc.org1567b8c2014-05-08 19:54:16143
144 protected:
guoweis@webrtc.org7169afd2014-12-04 17:59:29145 virtual ~MetricsObserverInterface() {}
buildbot@webrtc.org1567b8c2014-05-08 19:54:16146};
147
guoweis@webrtc.org7169afd2014-12-04 17:59:29148typedef MetricsObserverInterface UMAObserver;
149
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52150class PeerConnectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36151 public:
152 // See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions .
153 enum SignalingState {
154 kStable,
155 kHaveLocalOffer,
156 kHaveLocalPrAnswer,
157 kHaveRemoteOffer,
158 kHaveRemotePrAnswer,
159 kClosed,
160 };
161
162 // TODO(bemasc): Remove IceState when callers are changed to
163 // IceConnection/GatheringState.
164 enum IceState {
165 kIceNew,
166 kIceGathering,
167 kIceWaiting,
168 kIceChecking,
169 kIceConnected,
170 kIceCompleted,
171 kIceFailed,
172 kIceClosed,
173 };
174
175 enum IceGatheringState {
176 kIceGatheringNew,
177 kIceGatheringGathering,
178 kIceGatheringComplete
179 };
180
181 enum IceConnectionState {
182 kIceConnectionNew,
183 kIceConnectionChecking,
184 kIceConnectionConnected,
185 kIceConnectionCompleted,
186 kIceConnectionFailed,
187 kIceConnectionDisconnected,
188 kIceConnectionClosed,
Guo-wei Shieh3d564c12015-08-19 23:51:15189 kIceConnectionMax,
henrike@webrtc.org28e20752013-07-10 00:45:36190 };
191
192 struct IceServer {
Joachim Bauch7c4e7452015-05-28 21:06:30193 // TODO(jbauch): Remove uri when all code using it has switched to urls.
henrike@webrtc.org28e20752013-07-10 00:45:36194 std::string uri;
Joachim Bauch7c4e7452015-05-28 21:06:30195 std::vector<std::string> urls;
henrike@webrtc.org28e20752013-07-10 00:45:36196 std::string username;
197 std::string password;
198 };
199 typedef std::vector<IceServer> IceServers;
200
buildbot@webrtc.org41451d42014-05-03 05:39:45201 enum IceTransportsType {
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06202 // TODO(pthatcher): Rename these kTransporTypeXXX, but update
203 // Chromium at the same time.
buildbot@webrtc.org41451d42014-05-03 05:39:45204 kNone,
205 kRelay,
206 kNoHost,
207 kAll
208 };
209
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06210 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-08#section-4.1.1
211 enum BundlePolicy {
212 kBundlePolicyBalanced,
213 kBundlePolicyMaxBundle,
214 kBundlePolicyMaxCompat
215 };
buildbot@webrtc.org41451d42014-05-03 05:39:45216
Peter Thatcheraf55ccc2015-05-21 14:48:41217 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-09#section-4.1.1
218 enum RtcpMuxPolicy {
219 kRtcpMuxPolicyNegotiate,
220 kRtcpMuxPolicyRequire,
221 };
222
Jiayang Liucac1b382015-04-30 19:35:24223 enum TcpCandidatePolicy {
224 kTcpCandidatePolicyEnabled,
225 kTcpCandidatePolicyDisabled
226 };
227
honghaiz1f429e32015-09-28 14:57:34228 enum ContinualGatheringPolicy {
229 GATHER_ONCE,
230 GATHER_CONTINUALLY
231 };
232
Henrik Boström87713d02015-08-25 07:53:21233 // TODO(hbos): Change into class with private data and public getters.
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06234 struct RTCConfiguration {
honghaiz4edc39c2015-09-01 16:53:56235 static const int kUndefined = -1;
236 // Default maximum number of packets in the audio jitter buffer.
237 static const int kAudioJitterBufferMaxPackets = 50;
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06238 // TODO(pthatcher): Rename this ice_transport_type, but update
239 // Chromium at the same time.
240 IceTransportsType type;
241 // TODO(pthatcher): Rename this ice_servers, but update Chromium
242 // at the same time.
243 IceServers servers;
Guo-wei Shiehfe3bc9d2015-08-20 15:48:20244 // A localhost candidate is signaled whenever a candidate with the any
245 // address is allocated.
246 bool enable_localhost_ice_candidate;
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06247 BundlePolicy bundle_policy;
Peter Thatcheraf55ccc2015-05-21 14:48:41248 RtcpMuxPolicy rtcp_mux_policy;
Jiayang Liucac1b382015-04-30 19:35:24249 TcpCandidatePolicy tcp_candidate_policy;
Henrik Lundin64dad832015-05-11 10:44:23250 int audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 08:29:41251 bool audio_jitter_buffer_fast_accelerate;
honghaiz4edc39c2015-09-01 16:53:56252 int ice_connection_receiving_timeout;
honghaiz1f429e32015-09-28 14:57:34253 ContinualGatheringPolicy continual_gathering_policy;
Henrik Boström87713d02015-08-25 07:53:21254 std::vector<rtc::scoped_refptr<rtc::RTCCertificate>> certificates;
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06255
Jiayang Liucac1b382015-04-30 19:35:24256 RTCConfiguration()
257 : type(kAll),
Guo-wei Shiehfe3bc9d2015-08-20 15:48:20258 enable_localhost_ice_candidate(false),
Jiayang Liucac1b382015-04-30 19:35:24259 bundle_policy(kBundlePolicyBalanced),
Peter Thatcheraf55ccc2015-05-21 14:48:41260 rtcp_mux_policy(kRtcpMuxPolicyNegotiate),
Henrik Lundin64dad832015-05-11 10:44:23261 tcp_candidate_policy(kTcpCandidatePolicyEnabled),
honghaiz4edc39c2015-09-01 16:53:56262 audio_jitter_buffer_max_packets(kAudioJitterBufferMaxPackets),
263 audio_jitter_buffer_fast_accelerate(false),
honghaiz1f429e32015-09-28 14:57:34264 ice_connection_receiving_timeout(kUndefined),
265 continual_gathering_policy(GATHER_ONCE) {}
buildbot@webrtc.org41451d42014-05-03 05:39:45266 };
267
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16268 struct RTCOfferAnswerOptions {
269 static const int kUndefined = -1;
270 static const int kMaxOfferToReceiveMedia = 1;
271
272 // The default value for constraint offerToReceiveX:true.
273 static const int kOfferToReceiveMediaTrue = 1;
274
275 int offer_to_receive_video;
276 int offer_to_receive_audio;
277 bool voice_activity_detection;
278 bool ice_restart;
279 bool use_rtp_mux;
280
281 RTCOfferAnswerOptions()
282 : offer_to_receive_video(kUndefined),
283 offer_to_receive_audio(kUndefined),
284 voice_activity_detection(true),
285 ice_restart(false),
286 use_rtp_mux(true) {}
287
288 RTCOfferAnswerOptions(int offer_to_receive_video,
289 int offer_to_receive_audio,
290 bool voice_activity_detection,
291 bool ice_restart,
292 bool use_rtp_mux)
293 : offer_to_receive_video(offer_to_receive_video),
294 offer_to_receive_audio(offer_to_receive_audio),
295 voice_activity_detection(voice_activity_detection),
296 ice_restart(ice_restart),
297 use_rtp_mux(use_rtp_mux) {}
298 };
299
wu@webrtc.orgb9a088b2014-02-13 23:18:49300 // Used by GetStats to decide which stats to include in the stats reports.
301 // |kStatsOutputLevelStandard| includes the standard stats for Javascript API;
302 // |kStatsOutputLevelDebug| includes both the standard stats and additional
303 // stats for debugging purposes.
304 enum StatsOutputLevel {
305 kStatsOutputLevelStandard,
306 kStatsOutputLevelDebug,
307 };
308
henrike@webrtc.org28e20752013-07-10 00:45:36309 // Accessor methods to active local streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52310 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36311 local_streams() = 0;
312
313 // Accessor methods to remote streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52314 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36315 remote_streams() = 0;
316
317 // Add a new MediaStream to be sent on this PeerConnection.
318 // Note that a SessionDescription negotiation is needed before the
319 // remote peer can receive the stream.
perkj@webrtc.orgfd0efb62014-11-06 12:16:36320 virtual bool AddStream(MediaStreamInterface* stream) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36321
322 // Remove a MediaStream from this PeerConnection.
323 // Note that a SessionDescription negotiation is need before the
324 // remote peer is notified.
325 virtual void RemoveStream(MediaStreamInterface* stream) = 0;
326
327 // Returns pointer to the created DtmfSender on success.
328 // Otherwise returns NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52329 virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
henrike@webrtc.org28e20752013-07-10 00:45:36330 AudioTrackInterface* track) = 0;
331
wu@webrtc.orgb9a088b2014-02-13 23:18:49332 virtual bool GetStats(StatsObserver* observer,
333 MediaStreamTrackInterface* track,
334 StatsOutputLevel level) = 0;
335
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52336 virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36337 const std::string& label,
338 const DataChannelInit* config) = 0;
339
340 virtual const SessionDescriptionInterface* local_description() const = 0;
341 virtual const SessionDescriptionInterface* remote_description() const = 0;
342
343 // Create a new offer.
344 // The CreateSessionDescriptionObserver callback will be called when done.
345 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16346 const MediaConstraintsInterface* constraints) {}
347
348 // TODO(jiayl): remove the default impl and the old interface when chromium
349 // code is updated.
350 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
351 const RTCOfferAnswerOptions& options) {}
352
henrike@webrtc.org28e20752013-07-10 00:45:36353 // Create an answer to an offer.
354 // The CreateSessionDescriptionObserver callback will be called when done.
355 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
356 const MediaConstraintsInterface* constraints) = 0;
357 // Sets the local session description.
358 // JsepInterface takes the ownership of |desc| even if it fails.
359 // The |observer| callback will be called when done.
360 virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
361 SessionDescriptionInterface* desc) = 0;
362 // Sets the remote session description.
363 // JsepInterface takes the ownership of |desc| even if it fails.
364 // The |observer| callback will be called when done.
365 virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
366 SessionDescriptionInterface* desc) = 0;
367 // Restarts or updates the ICE Agent process of gathering local candidates
368 // and pinging remote candidates.
369 virtual bool UpdateIce(const IceServers& configuration,
370 const MediaConstraintsInterface* constraints) = 0;
371 // Provides a remote candidate to the ICE Agent.
372 // A copy of the |candidate| will be created and added to the remote
373 // description. So the caller of this method still has the ownership of the
374 // |candidate|.
375 // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will
376 // take the ownership of the |candidate|.
377 virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
378
buildbot@webrtc.org1567b8c2014-05-08 19:54:16379 virtual void RegisterUMAObserver(UMAObserver* observer) = 0;
380
henrike@webrtc.org28e20752013-07-10 00:45:36381 // Returns the current SignalingState.
382 virtual SignalingState signaling_state() = 0;
383
384 // TODO(bemasc): Remove ice_state when callers are changed to
385 // IceConnection/GatheringState.
386 // Returns the current IceState.
387 virtual IceState ice_state() = 0;
388 virtual IceConnectionState ice_connection_state() = 0;
389 virtual IceGatheringState ice_gathering_state() = 0;
390
391 // Terminates all media and closes the transport.
392 virtual void Close() = 0;
393
394 protected:
395 // Dtor protected as objects shouldn't be deleted via this interface.
396 ~PeerConnectionInterface() {}
397};
398
399// PeerConnection callback interface. Application should implement these
400// methods.
401class PeerConnectionObserver {
402 public:
403 enum StateType {
404 kSignalingState,
405 kIceState,
406 };
407
henrike@webrtc.org28e20752013-07-10 00:45:36408 // Triggered when the SignalingState changed.
409 virtual void OnSignalingChange(
410 PeerConnectionInterface::SignalingState new_state) {}
411
412 // Triggered when SignalingState or IceState have changed.
413 // TODO(bemasc): Remove once callers transition to OnSignalingChange.
414 virtual void OnStateChange(StateType state_changed) {}
415
416 // Triggered when media is received on a new stream from remote peer.
417 virtual void OnAddStream(MediaStreamInterface* stream) = 0;
418
419 // Triggered when a remote peer close a stream.
420 virtual void OnRemoveStream(MediaStreamInterface* stream) = 0;
421
422 // Triggered when a remote peer open a data channel.
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29423 virtual void OnDataChannel(DataChannelInterface* data_channel) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36424
mallinath@webrtc.org0d92ef62014-01-22 02:21:22425 // Triggered when renegotiation is needed, for example the ICE has restarted.
fischman@webrtc.orgd7568a02014-01-13 22:04:12426 virtual void OnRenegotiationNeeded() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36427
428 // Called any time the IceConnectionState changes
429 virtual void OnIceConnectionChange(
430 PeerConnectionInterface::IceConnectionState new_state) {}
431
432 // Called any time the IceGatheringState changes
433 virtual void OnIceGatheringChange(
434 PeerConnectionInterface::IceGatheringState new_state) {}
435
436 // New Ice candidate have been found.
437 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
438
439 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
440 // All Ice candidates have been found.
441 virtual void OnIceComplete() {}
442
Peter Thatcher54360512015-07-08 18:08:35443 // Called when the ICE connection receiving status changes.
444 virtual void OnIceConnectionReceivingChange(bool receiving) {}
445
henrike@webrtc.org28e20752013-07-10 00:45:36446 protected:
447 // Dtor protected as objects shouldn't be deleted via this interface.
448 ~PeerConnectionObserver() {}
449};
450
451// Factory class used for creating cricket::PortAllocator that is used
452// for ICE negotiation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52453class PortAllocatorFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36454 public:
455 struct StunConfiguration {
456 StunConfiguration(const std::string& address, int port)
457 : server(address, port) {}
458 // STUN server address and port.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52459 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36460 };
461
462 struct TurnConfiguration {
463 TurnConfiguration(const std::string& address,
464 int port,
465 const std::string& username,
466 const std::string& password,
wu@webrtc.org91053e72013-08-10 07:18:04467 const std::string& transport_type,
468 bool secure)
henrike@webrtc.org28e20752013-07-10 00:45:36469 : server(address, port),
470 username(username),
471 password(password),
wu@webrtc.org91053e72013-08-10 07:18:04472 transport_type(transport_type),
473 secure(secure) {}
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52474 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36475 std::string username;
476 std::string password;
477 std::string transport_type;
wu@webrtc.org91053e72013-08-10 07:18:04478 bool secure;
henrike@webrtc.org28e20752013-07-10 00:45:36479 };
480
481 virtual cricket::PortAllocator* CreatePortAllocator(
482 const std::vector<StunConfiguration>& stun_servers,
483 const std::vector<TurnConfiguration>& turn_configurations) = 0;
484
phoglund@webrtc.org006521d2015-02-12 09:23:59485 // TODO(phoglund): Make pure virtual when Chrome's factory implements this.
486 // After this method is called, the port allocator should consider loopback
487 // network interfaces as well.
488 virtual void SetNetworkIgnoreMask(int network_ignore_mask) {
489 }
490
henrike@webrtc.org28e20752013-07-10 00:45:36491 protected:
492 PortAllocatorFactoryInterface() {}
493 ~PortAllocatorFactoryInterface() {}
494};
495
henrike@webrtc.org28e20752013-07-10 00:45:36496// PeerConnectionFactoryInterface is the factory interface use for creating
497// PeerConnection, MediaStream and media tracks.
498// PeerConnectionFactoryInterface will create required libjingle threads,
499// socket and network manager factory classes for networking.
500// If an application decides to provide its own threads and network
501// implementation of these classes it should use the alternate
502// CreatePeerConnectionFactory method which accepts threads as input and use the
503// CreatePeerConnection version that takes a PortAllocatorFactoryInterface as
504// argument.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52505class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36506 public:
wu@webrtc.org97077a32013-10-25 21:18:33507 class Options {
508 public:
509 Options() :
wu@webrtc.org97077a32013-10-25 21:18:33510 disable_encryption(false),
phoglund@webrtc.org006521d2015-02-12 09:23:59511 disable_sctp_data_channels(false),
Joachim Bauch04e5b492015-05-29 07:40:39512 network_ignore_mask(rtc::kDefaultNetworkIgnoreMask),
513 ssl_max_version(rtc::SSL_PROTOCOL_DTLS_10) {
wu@webrtc.org97077a32013-10-25 21:18:33514 }
wu@webrtc.org97077a32013-10-25 21:18:33515 bool disable_encryption;
516 bool disable_sctp_data_channels;
phoglund@webrtc.org006521d2015-02-12 09:23:59517
518 // Sets the network types to ignore. For instance, calling this with
519 // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
520 // loopback interfaces.
521 int network_ignore_mask;
Joachim Bauch04e5b492015-05-29 07:40:39522
523 // Sets the maximum supported protocol version. The highest version
524 // supported by both ends will be used for the connection, i.e. if one
525 // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used.
526 rtc::SSLProtocolVersion ssl_max_version;
wu@webrtc.org97077a32013-10-25 21:18:33527 };
528
529 virtual void SetOptions(const Options& options) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45530
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52531 virtual rtc::scoped_refptr<PeerConnectionInterface>
buildbot@webrtc.org41451d42014-05-03 05:39:45532 CreatePeerConnection(
533 const PeerConnectionInterface::RTCConfiguration& configuration,
534 const MediaConstraintsInterface* constraints,
535 PortAllocatorFactoryInterface* allocator_factory,
Henrik Boström5e56c592015-08-11 08:33:13536 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
buildbot@webrtc.org41451d42014-05-03 05:39:45537 PeerConnectionObserver* observer) = 0;
538
Henrik Boström5e56c592015-08-11 08:33:13539 // TODO(hbos): Remove below version after clients are updated to above method.
buildbot@webrtc.org41451d42014-05-03 05:39:45540 // In latest W3C WebRTC draft, PC constructor will take RTCConfiguration,
541 // and not IceServers. RTCConfiguration is made up of ice servers and
542 // ice transport type.
543 // http://dev.w3.org/2011/webrtc/editor/webrtc.html
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52544 inline rtc::scoped_refptr<PeerConnectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36545 CreatePeerConnection(
pthatcher@webrtc.org877ac762015-02-04 22:03:09546 const PeerConnectionInterface::IceServers& servers,
henrike@webrtc.org28e20752013-07-10 00:45:36547 const MediaConstraintsInterface* constraints,
548 PortAllocatorFactoryInterface* allocator_factory,
Henrik Boström5e56c592015-08-11 08:33:13549 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
buildbot@webrtc.org41451d42014-05-03 05:39:45550 PeerConnectionObserver* observer) {
551 PeerConnectionInterface::RTCConfiguration rtc_config;
pthatcher@webrtc.org877ac762015-02-04 22:03:09552 rtc_config.servers = servers;
buildbot@webrtc.org41451d42014-05-03 05:39:45553 return CreatePeerConnection(rtc_config, constraints, allocator_factory,
Henrik Boström5e56c592015-08-11 08:33:13554 dtls_identity_store.Pass(), observer);
buildbot@webrtc.org41451d42014-05-03 05:39:45555 }
556
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52557 virtual rtc::scoped_refptr<MediaStreamInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36558 CreateLocalMediaStream(const std::string& label) = 0;
559
560 // Creates a AudioSourceInterface.
561 // |constraints| decides audio processing settings but can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52562 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
henrike@webrtc.org28e20752013-07-10 00:45:36563 const MediaConstraintsInterface* constraints) = 0;
564
565 // Creates a VideoSourceInterface. The new source take ownership of
566 // |capturer|. |constraints| decides video resolution and frame rate but can
567 // be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52568 virtual rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource(
henrike@webrtc.org28e20752013-07-10 00:45:36569 cricket::VideoCapturer* capturer,
570 const MediaConstraintsInterface* constraints) = 0;
571
572 // Creates a new local VideoTrack. The same |source| can be used in several
573 // tracks.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52574 virtual rtc::scoped_refptr<VideoTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36575 CreateVideoTrack(const std::string& label,
576 VideoSourceInterface* source) = 0;
577
578 // Creates an new AudioTrack. At the moment |source| can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52579 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36580 CreateAudioTrack(const std::string& label,
581 AudioSourceInterface* source) = 0;
582
wu@webrtc.orga9890802013-12-13 00:21:03583 // Starts AEC dump using existing file. Takes ownership of |file| and passes
584 // it on to VoiceEngine (via other objects) immediately, which will take
wu@webrtc.orga8910d22014-01-23 22:12:45585 // the ownerhip. If the operation fails, the file will be closed.
wu@webrtc.orga9890802013-12-13 00:21:03586 // TODO(grunell): Remove when Chromium has started to use AEC in each source.
wu@webrtc.orga8910d22014-01-23 22:12:45587 // http://crbug.com/264611.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52588 virtual bool StartAecDump(rtc::PlatformFile file) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03589
henrike@webrtc.org28e20752013-07-10 00:45:36590 protected:
591 // Dtor and ctor protected as objects shouldn't be created or deleted via
592 // this interface.
593 PeerConnectionFactoryInterface() {}
594 ~PeerConnectionFactoryInterface() {} // NOLINT
595};
596
597// Create a new instance of PeerConnectionFactoryInterface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52598rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36599CreatePeerConnectionFactory();
600
601// Create a new instance of PeerConnectionFactoryInterface.
602// Ownership of |factory|, |default_adm|, and optionally |encoder_factory| and
603// |decoder_factory| transferred to the returned factory.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52604rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36605CreatePeerConnectionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52606 rtc::Thread* worker_thread,
607 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36608 AudioDeviceModule* default_adm,
609 cricket::WebRtcVideoEncoderFactory* encoder_factory,
610 cricket::WebRtcVideoDecoderFactory* decoder_factory);
611
612} // namespace webrtc
613
614#endif // TALK_APP_WEBRTC_PEERCONNECTIONINTERFACE_H_