blob: 734c2d09d3915db1adbc9e93d5d6218c7ecef62f [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"
Henrik Boström5e56c592015-08-11 10:33:13 +020077#include "talk/app/webrtc/dtlsidentitystore.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078#include "talk/app/webrtc/jsep.h"
79#include "talk/app/webrtc/mediastreaminterface.h"
deadbeef70ab1a12015-09-28 16:53:55 -070080#include "talk/app/webrtc/rtpreceiverinterface.h"
81#include "talk/app/webrtc/rtpsenderinterface.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082#include "talk/app/webrtc/statstypes.h"
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +000083#include "talk/app/webrtc/umametrics.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000084#include "webrtc/base/fileutils.h"
phoglund@webrtc.org006521d2015-02-12 09:23:59 +000085#include "webrtc/base/network.h"
Henrik Boström87713d02015-08-25 09:53:21 +020086#include "webrtc/base/rtccertificate.h"
Joachim Bauch04e5b492015-05-29 09:40:39 +020087#include "webrtc/base/sslstreamadapter.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000088#include "webrtc/base/socketaddress.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000090namespace rtc {
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000091class SSLIdentity;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092class Thread;
93}
94
95namespace cricket {
96class PortAllocator;
97class WebRtcVideoDecoderFactory;
98class WebRtcVideoEncoderFactory;
99}
100
101namespace webrtc {
102class AudioDeviceModule;
103class MediaConstraintsInterface;
104
105// MediaStream container interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000106class StreamCollectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107 public:
108 // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find.
109 virtual size_t count() = 0;
110 virtual MediaStreamInterface* at(size_t index) = 0;
111 virtual MediaStreamInterface* find(const std::string& label) = 0;
112 virtual MediaStreamTrackInterface* FindAudioTrack(
113 const std::string& id) = 0;
114 virtual MediaStreamTrackInterface* FindVideoTrack(
115 const std::string& id) = 0;
116
117 protected:
118 // Dtor protected as objects shouldn't be deleted via this interface.
119 ~StreamCollectionInterface() {}
120};
121
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000122class StatsObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123 public:
tommi@webrtc.orge2e199b2014-12-15 13:22:54 +0000124 virtual void OnComplete(const StatsReports& reports) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125
126 protected:
127 virtual ~StatsObserver() {}
128};
129
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000130class MetricsObserverInterface : public rtc::RefCountInterface {
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000131 public:
Guo-wei Shieh3d564c12015-08-19 16:51:15 -0700132
133 // |type| is the type of the enum counter to be incremented. |counter|
134 // is the particular counter in that type. |counter_max| is the next sequence
135 // number after the highest counter.
136 virtual void IncrementEnumCounter(PeerConnectionEnumCounterType type,
137 int counter,
138 int counter_max) {}
139
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000140 virtual void AddHistogramSample(PeerConnectionMetricsName type,
mallinath@webrtc.orgd37bcfa2014-05-12 23:10:18 +0000141 int value) = 0;
jbauchac8869e2015-07-03 01:36:14 -0700142 // TODO(jbauch): Make method abstract when it is implemented by Chromium.
143 virtual void AddHistogramSample(PeerConnectionMetricsName type,
144 const std::string& value) {}
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000145
146 protected:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000147 virtual ~MetricsObserverInterface() {}
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000148};
149
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000150typedef MetricsObserverInterface UMAObserver;
151
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000152class PeerConnectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153 public:
154 // See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions .
155 enum SignalingState {
156 kStable,
157 kHaveLocalOffer,
158 kHaveLocalPrAnswer,
159 kHaveRemoteOffer,
160 kHaveRemotePrAnswer,
161 kClosed,
162 };
163
164 // TODO(bemasc): Remove IceState when callers are changed to
165 // IceConnection/GatheringState.
166 enum IceState {
167 kIceNew,
168 kIceGathering,
169 kIceWaiting,
170 kIceChecking,
171 kIceConnected,
172 kIceCompleted,
173 kIceFailed,
174 kIceClosed,
175 };
176
177 enum IceGatheringState {
178 kIceGatheringNew,
179 kIceGatheringGathering,
180 kIceGatheringComplete
181 };
182
183 enum IceConnectionState {
184 kIceConnectionNew,
185 kIceConnectionChecking,
186 kIceConnectionConnected,
187 kIceConnectionCompleted,
188 kIceConnectionFailed,
189 kIceConnectionDisconnected,
190 kIceConnectionClosed,
Guo-wei Shieh3d564c12015-08-19 16:51:15 -0700191 kIceConnectionMax,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 };
193
194 struct IceServer {
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200195 // TODO(jbauch): Remove uri when all code using it has switched to urls.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 std::string uri;
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200197 std::vector<std::string> urls;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 std::string username;
199 std::string password;
200 };
201 typedef std::vector<IceServer> IceServers;
202
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000203 enum IceTransportsType {
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000204 // TODO(pthatcher): Rename these kTransporTypeXXX, but update
205 // Chromium at the same time.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000206 kNone,
207 kRelay,
208 kNoHost,
209 kAll
210 };
211
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000212 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-08#section-4.1.1
213 enum BundlePolicy {
214 kBundlePolicyBalanced,
215 kBundlePolicyMaxBundle,
216 kBundlePolicyMaxCompat
217 };
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000218
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700219 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-09#section-4.1.1
220 enum RtcpMuxPolicy {
221 kRtcpMuxPolicyNegotiate,
222 kRtcpMuxPolicyRequire,
223 };
224
Jiayang Liucac1b382015-04-30 12:35:24 -0700225 enum TcpCandidatePolicy {
226 kTcpCandidatePolicyEnabled,
227 kTcpCandidatePolicyDisabled
228 };
229
honghaiz1f429e32015-09-28 07:57:34 -0700230 enum ContinualGatheringPolicy {
231 GATHER_ONCE,
232 GATHER_CONTINUALLY
233 };
234
Henrik Boström87713d02015-08-25 09:53:21 +0200235 // TODO(hbos): Change into class with private data and public getters.
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000236 struct RTCConfiguration {
honghaiz4edc39c2015-09-01 09:53:56 -0700237 static const int kUndefined = -1;
238 // Default maximum number of packets in the audio jitter buffer.
239 static const int kAudioJitterBufferMaxPackets = 50;
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000240 // TODO(pthatcher): Rename this ice_transport_type, but update
241 // Chromium at the same time.
242 IceTransportsType type;
243 // TODO(pthatcher): Rename this ice_servers, but update Chromium
244 // at the same time.
245 IceServers servers;
Guo-wei Shiehfe3bc9d2015-08-20 08:48:20 -0700246 // A localhost candidate is signaled whenever a candidate with the any
247 // address is allocated.
248 bool enable_localhost_ice_candidate;
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000249 BundlePolicy bundle_policy;
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700250 RtcpMuxPolicy rtcp_mux_policy;
Jiayang Liucac1b382015-04-30 12:35:24 -0700251 TcpCandidatePolicy tcp_candidate_policy;
Henrik Lundin64dad832015-05-11 12:44:23 +0200252 int audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200253 bool audio_jitter_buffer_fast_accelerate;
honghaiz4edc39c2015-09-01 09:53:56 -0700254 int ice_connection_receiving_timeout;
honghaiz1f429e32015-09-28 07:57:34 -0700255 ContinualGatheringPolicy continual_gathering_policy;
Henrik Boström87713d02015-08-25 09:53:21 +0200256 std::vector<rtc::scoped_refptr<rtc::RTCCertificate>> certificates;
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000257
Jiayang Liucac1b382015-04-30 12:35:24 -0700258 RTCConfiguration()
259 : type(kAll),
Guo-wei Shiehfe3bc9d2015-08-20 08:48:20 -0700260 enable_localhost_ice_candidate(false),
Jiayang Liucac1b382015-04-30 12:35:24 -0700261 bundle_policy(kBundlePolicyBalanced),
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700262 rtcp_mux_policy(kRtcpMuxPolicyNegotiate),
Henrik Lundin64dad832015-05-11 12:44:23 +0200263 tcp_candidate_policy(kTcpCandidatePolicyEnabled),
honghaiz4edc39c2015-09-01 09:53:56 -0700264 audio_jitter_buffer_max_packets(kAudioJitterBufferMaxPackets),
265 audio_jitter_buffer_fast_accelerate(false),
honghaiz1f429e32015-09-28 07:57:34 -0700266 ice_connection_receiving_timeout(kUndefined),
267 continual_gathering_policy(GATHER_ONCE) {}
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000268 };
269
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000270 struct RTCOfferAnswerOptions {
271 static const int kUndefined = -1;
272 static const int kMaxOfferToReceiveMedia = 1;
273
274 // The default value for constraint offerToReceiveX:true.
275 static const int kOfferToReceiveMediaTrue = 1;
276
277 int offer_to_receive_video;
278 int offer_to_receive_audio;
279 bool voice_activity_detection;
280 bool ice_restart;
281 bool use_rtp_mux;
282
283 RTCOfferAnswerOptions()
284 : offer_to_receive_video(kUndefined),
285 offer_to_receive_audio(kUndefined),
286 voice_activity_detection(true),
287 ice_restart(false),
288 use_rtp_mux(true) {}
289
290 RTCOfferAnswerOptions(int offer_to_receive_video,
291 int offer_to_receive_audio,
292 bool voice_activity_detection,
293 bool ice_restart,
294 bool use_rtp_mux)
295 : offer_to_receive_video(offer_to_receive_video),
296 offer_to_receive_audio(offer_to_receive_audio),
297 voice_activity_detection(voice_activity_detection),
298 ice_restart(ice_restart),
299 use_rtp_mux(use_rtp_mux) {}
300 };
301
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000302 // Used by GetStats to decide which stats to include in the stats reports.
303 // |kStatsOutputLevelStandard| includes the standard stats for Javascript API;
304 // |kStatsOutputLevelDebug| includes both the standard stats and additional
305 // stats for debugging purposes.
306 enum StatsOutputLevel {
307 kStatsOutputLevelStandard,
308 kStatsOutputLevelDebug,
309 };
310
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 // Accessor methods to active local streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000312 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 local_streams() = 0;
314
315 // Accessor methods to remote streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000316 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 remote_streams() = 0;
318
319 // Add a new MediaStream to be sent on this PeerConnection.
320 // Note that a SessionDescription negotiation is needed before the
321 // remote peer can receive the stream.
perkj@webrtc.orgfd0efb62014-11-06 12:16:36 +0000322 virtual bool AddStream(MediaStreamInterface* stream) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323
324 // Remove a MediaStream from this PeerConnection.
325 // Note that a SessionDescription negotiation is need before the
326 // remote peer is notified.
327 virtual void RemoveStream(MediaStreamInterface* stream) = 0;
328
329 // Returns pointer to the created DtmfSender on success.
330 // Otherwise returns NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000331 virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 AudioTrackInterface* track) = 0;
333
deadbeef70ab1a12015-09-28 16:53:55 -0700334 // TODO(deadbeef): Make these pure virtual once all subclasses implement them.
335 virtual std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
336 const {
337 return std::vector<rtc::scoped_refptr<RtpSenderInterface>>();
338 }
339
340 virtual std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
341 const {
342 return std::vector<rtc::scoped_refptr<RtpReceiverInterface>>();
343 }
344
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000345 virtual bool GetStats(StatsObserver* observer,
346 MediaStreamTrackInterface* track,
347 StatsOutputLevel level) = 0;
348
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000349 virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 const std::string& label,
351 const DataChannelInit* config) = 0;
352
353 virtual const SessionDescriptionInterface* local_description() const = 0;
354 virtual const SessionDescriptionInterface* remote_description() const = 0;
355
356 // Create a new offer.
357 // The CreateSessionDescriptionObserver callback will be called when done.
358 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000359 const MediaConstraintsInterface* constraints) {}
360
361 // TODO(jiayl): remove the default impl and the old interface when chromium
362 // code is updated.
363 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
364 const RTCOfferAnswerOptions& options) {}
365
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 // Create an answer to an offer.
367 // The CreateSessionDescriptionObserver callback will be called when done.
368 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
369 const MediaConstraintsInterface* constraints) = 0;
370 // Sets the local session description.
371 // JsepInterface takes the ownership of |desc| even if it fails.
372 // The |observer| callback will be called when done.
373 virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
374 SessionDescriptionInterface* desc) = 0;
375 // Sets the remote session description.
376 // JsepInterface takes the ownership of |desc| even if it fails.
377 // The |observer| callback will be called when done.
378 virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
379 SessionDescriptionInterface* desc) = 0;
380 // Restarts or updates the ICE Agent process of gathering local candidates
381 // and pinging remote candidates.
382 virtual bool UpdateIce(const IceServers& configuration,
383 const MediaConstraintsInterface* constraints) = 0;
384 // Provides a remote candidate to the ICE Agent.
385 // A copy of the |candidate| will be created and added to the remote
386 // description. So the caller of this method still has the ownership of the
387 // |candidate|.
388 // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will
389 // take the ownership of the |candidate|.
390 virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
391
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000392 virtual void RegisterUMAObserver(UMAObserver* observer) = 0;
393
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394 // Returns the current SignalingState.
395 virtual SignalingState signaling_state() = 0;
396
397 // TODO(bemasc): Remove ice_state when callers are changed to
398 // IceConnection/GatheringState.
399 // Returns the current IceState.
400 virtual IceState ice_state() = 0;
401 virtual IceConnectionState ice_connection_state() = 0;
402 virtual IceGatheringState ice_gathering_state() = 0;
403
404 // Terminates all media and closes the transport.
405 virtual void Close() = 0;
406
407 protected:
408 // Dtor protected as objects shouldn't be deleted via this interface.
409 ~PeerConnectionInterface() {}
410};
411
412// PeerConnection callback interface. Application should implement these
413// methods.
414class PeerConnectionObserver {
415 public:
416 enum StateType {
417 kSignalingState,
418 kIceState,
419 };
420
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421 // Triggered when the SignalingState changed.
422 virtual void OnSignalingChange(
423 PeerConnectionInterface::SignalingState new_state) {}
424
425 // Triggered when SignalingState or IceState have changed.
426 // TODO(bemasc): Remove once callers transition to OnSignalingChange.
427 virtual void OnStateChange(StateType state_changed) {}
428
429 // Triggered when media is received on a new stream from remote peer.
430 virtual void OnAddStream(MediaStreamInterface* stream) = 0;
431
432 // Triggered when a remote peer close a stream.
433 virtual void OnRemoveStream(MediaStreamInterface* stream) = 0;
434
435 // Triggered when a remote peer open a data channel.
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000436 virtual void OnDataChannel(DataChannelInterface* data_channel) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437
mallinath@webrtc.org0d92ef62014-01-22 02:21:22 +0000438 // Triggered when renegotiation is needed, for example the ICE has restarted.
fischman@webrtc.orgd7568a02014-01-13 22:04:12 +0000439 virtual void OnRenegotiationNeeded() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440
441 // Called any time the IceConnectionState changes
442 virtual void OnIceConnectionChange(
443 PeerConnectionInterface::IceConnectionState new_state) {}
444
445 // Called any time the IceGatheringState changes
446 virtual void OnIceGatheringChange(
447 PeerConnectionInterface::IceGatheringState new_state) {}
448
449 // New Ice candidate have been found.
450 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
451
452 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
453 // All Ice candidates have been found.
454 virtual void OnIceComplete() {}
455
Peter Thatcher54360512015-07-08 11:08:35 -0700456 // Called when the ICE connection receiving status changes.
457 virtual void OnIceConnectionReceivingChange(bool receiving) {}
458
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459 protected:
460 // Dtor protected as objects shouldn't be deleted via this interface.
461 ~PeerConnectionObserver() {}
462};
463
464// Factory class used for creating cricket::PortAllocator that is used
465// for ICE negotiation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000466class PortAllocatorFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000467 public:
468 struct StunConfiguration {
469 StunConfiguration(const std::string& address, int port)
470 : server(address, port) {}
471 // STUN server address and port.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000472 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000473 };
474
475 struct TurnConfiguration {
476 TurnConfiguration(const std::string& address,
477 int port,
478 const std::string& username,
479 const std::string& password,
wu@webrtc.org91053e72013-08-10 07:18:04 +0000480 const std::string& transport_type,
481 bool secure)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482 : server(address, port),
483 username(username),
484 password(password),
wu@webrtc.org91053e72013-08-10 07:18:04 +0000485 transport_type(transport_type),
486 secure(secure) {}
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000487 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000488 std::string username;
489 std::string password;
490 std::string transport_type;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000491 bool secure;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000492 };
493
494 virtual cricket::PortAllocator* CreatePortAllocator(
495 const std::vector<StunConfiguration>& stun_servers,
496 const std::vector<TurnConfiguration>& turn_configurations) = 0;
497
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000498 // TODO(phoglund): Make pure virtual when Chrome's factory implements this.
499 // After this method is called, the port allocator should consider loopback
500 // network interfaces as well.
501 virtual void SetNetworkIgnoreMask(int network_ignore_mask) {
502 }
503
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000504 protected:
505 PortAllocatorFactoryInterface() {}
506 ~PortAllocatorFactoryInterface() {}
507};
508
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000509// PeerConnectionFactoryInterface is the factory interface use for creating
510// PeerConnection, MediaStream and media tracks.
511// PeerConnectionFactoryInterface will create required libjingle threads,
512// socket and network manager factory classes for networking.
513// If an application decides to provide its own threads and network
514// implementation of these classes it should use the alternate
515// CreatePeerConnectionFactory method which accepts threads as input and use the
516// CreatePeerConnection version that takes a PortAllocatorFactoryInterface as
517// argument.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000518class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519 public:
wu@webrtc.org97077a32013-10-25 21:18:33 +0000520 class Options {
521 public:
522 Options() :
wu@webrtc.org97077a32013-10-25 21:18:33 +0000523 disable_encryption(false),
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000524 disable_sctp_data_channels(false),
Joachim Bauch04e5b492015-05-29 09:40:39 +0200525 network_ignore_mask(rtc::kDefaultNetworkIgnoreMask),
526 ssl_max_version(rtc::SSL_PROTOCOL_DTLS_10) {
wu@webrtc.org97077a32013-10-25 21:18:33 +0000527 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000528 bool disable_encryption;
529 bool disable_sctp_data_channels;
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000530
531 // Sets the network types to ignore. For instance, calling this with
532 // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
533 // loopback interfaces.
534 int network_ignore_mask;
Joachim Bauch04e5b492015-05-29 09:40:39 +0200535
536 // Sets the maximum supported protocol version. The highest version
537 // supported by both ends will be used for the connection, i.e. if one
538 // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used.
539 rtc::SSLProtocolVersion ssl_max_version;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000540 };
541
542 virtual void SetOptions(const Options& options) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000543
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000544 virtual rtc::scoped_refptr<PeerConnectionInterface>
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000545 CreatePeerConnection(
546 const PeerConnectionInterface::RTCConfiguration& configuration,
547 const MediaConstraintsInterface* constraints,
548 PortAllocatorFactoryInterface* allocator_factory,
Henrik Boström5e56c592015-08-11 10:33:13 +0200549 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000550 PeerConnectionObserver* observer) = 0;
551
Henrik Boström5e56c592015-08-11 10:33:13 +0200552 // TODO(hbos): Remove below version after clients are updated to above method.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000553 // In latest W3C WebRTC draft, PC constructor will take RTCConfiguration,
554 // and not IceServers. RTCConfiguration is made up of ice servers and
555 // ice transport type.
556 // http://dev.w3.org/2011/webrtc/editor/webrtc.html
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000557 inline rtc::scoped_refptr<PeerConnectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000558 CreatePeerConnection(
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000559 const PeerConnectionInterface::IceServers& servers,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 const MediaConstraintsInterface* constraints,
561 PortAllocatorFactoryInterface* allocator_factory,
Henrik Boström5e56c592015-08-11 10:33:13 +0200562 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000563 PeerConnectionObserver* observer) {
564 PeerConnectionInterface::RTCConfiguration rtc_config;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000565 rtc_config.servers = servers;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000566 return CreatePeerConnection(rtc_config, constraints, allocator_factory,
Henrik Boström5e56c592015-08-11 10:33:13 +0200567 dtls_identity_store.Pass(), observer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000568 }
569
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000570 virtual rtc::scoped_refptr<MediaStreamInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 CreateLocalMediaStream(const std::string& label) = 0;
572
573 // Creates a AudioSourceInterface.
574 // |constraints| decides audio processing settings but can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000575 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576 const MediaConstraintsInterface* constraints) = 0;
577
578 // Creates a VideoSourceInterface. The new source take ownership of
579 // |capturer|. |constraints| decides video resolution and frame rate but can
580 // be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000581 virtual rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582 cricket::VideoCapturer* capturer,
583 const MediaConstraintsInterface* constraints) = 0;
584
585 // Creates a new local VideoTrack. The same |source| can be used in several
586 // tracks.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000587 virtual rtc::scoped_refptr<VideoTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000588 CreateVideoTrack(const std::string& label,
589 VideoSourceInterface* source) = 0;
590
591 // Creates an new AudioTrack. At the moment |source| can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000592 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 CreateAudioTrack(const std::string& label,
594 AudioSourceInterface* source) = 0;
595
wu@webrtc.orga9890802013-12-13 00:21:03 +0000596 // Starts AEC dump using existing file. Takes ownership of |file| and passes
597 // it on to VoiceEngine (via other objects) immediately, which will take
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000598 // the ownerhip. If the operation fails, the file will be closed.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000599 // TODO(grunell): Remove when Chromium has started to use AEC in each source.
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000600 // http://crbug.com/264611.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000601 virtual bool StartAecDump(rtc::PlatformFile file) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000602
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603 protected:
604 // Dtor and ctor protected as objects shouldn't be created or deleted via
605 // this interface.
606 PeerConnectionFactoryInterface() {}
607 ~PeerConnectionFactoryInterface() {} // NOLINT
608};
609
610// Create a new instance of PeerConnectionFactoryInterface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000611rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612CreatePeerConnectionFactory();
613
614// Create a new instance of PeerConnectionFactoryInterface.
615// Ownership of |factory|, |default_adm|, and optionally |encoder_factory| and
616// |decoder_factory| transferred to the returned factory.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000617rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618CreatePeerConnectionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000619 rtc::Thread* worker_thread,
620 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000621 AudioDeviceModule* default_adm,
622 cricket::WebRtcVideoEncoderFactory* encoder_factory,
623 cricket::WebRtcVideoDecoderFactory* decoder_factory);
624
625} // namespace webrtc
626
627#endif // TALK_APP_WEBRTC_PEERCONNECTIONINTERFACE_H_