blob: f301bafdff54f672f3f3da501d8965b934e78405 [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;
guoweis27dc29b2015-09-30 19:23:09 -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.
deadbeefa67696b2015-09-29 11:56:26 -0700382 // TODO(deadbeef): Remove once Chrome is moved over to SetConfiguration.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383 virtual bool UpdateIce(const IceServers& configuration,
deadbeefa67696b2015-09-29 11:56:26 -0700384 const MediaConstraintsInterface* constraints) {
385 return false;
386 }
387 // Sets the PeerConnection's global configuration to |config|.
388 // Any changes to STUN/TURN servers or ICE candidate policy will affect the
389 // next gathering phase, and cause the next call to createOffer to generate
390 // new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies
391 // cannot be changed with this method.
392 // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of
393 // PeerConnectionInterface implement it.
394 virtual bool SetConfiguration(
395 const PeerConnectionInterface::RTCConfiguration& config) {
396 return false;
397 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000398 // Provides a remote candidate to the ICE Agent.
399 // A copy of the |candidate| will be created and added to the remote
400 // description. So the caller of this method still has the ownership of the
401 // |candidate|.
402 // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will
403 // take the ownership of the |candidate|.
404 virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
405
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000406 virtual void RegisterUMAObserver(UMAObserver* observer) = 0;
407
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000408 // Returns the current SignalingState.
409 virtual SignalingState signaling_state() = 0;
410
411 // TODO(bemasc): Remove ice_state when callers are changed to
412 // IceConnection/GatheringState.
413 // Returns the current IceState.
414 virtual IceState ice_state() = 0;
415 virtual IceConnectionState ice_connection_state() = 0;
416 virtual IceGatheringState ice_gathering_state() = 0;
417
418 // Terminates all media and closes the transport.
419 virtual void Close() = 0;
420
421 protected:
422 // Dtor protected as objects shouldn't be deleted via this interface.
423 ~PeerConnectionInterface() {}
424};
425
426// PeerConnection callback interface. Application should implement these
427// methods.
428class PeerConnectionObserver {
429 public:
430 enum StateType {
431 kSignalingState,
432 kIceState,
433 };
434
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000435 // Triggered when the SignalingState changed.
436 virtual void OnSignalingChange(
437 PeerConnectionInterface::SignalingState new_state) {}
438
439 // Triggered when SignalingState or IceState have changed.
440 // TODO(bemasc): Remove once callers transition to OnSignalingChange.
441 virtual void OnStateChange(StateType state_changed) {}
442
443 // Triggered when media is received on a new stream from remote peer.
444 virtual void OnAddStream(MediaStreamInterface* stream) = 0;
445
446 // Triggered when a remote peer close a stream.
447 virtual void OnRemoveStream(MediaStreamInterface* stream) = 0;
448
449 // Triggered when a remote peer open a data channel.
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000450 virtual void OnDataChannel(DataChannelInterface* data_channel) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451
mallinath@webrtc.org0d92ef62014-01-22 02:21:22 +0000452 // Triggered when renegotiation is needed, for example the ICE has restarted.
fischman@webrtc.orgd7568a02014-01-13 22:04:12 +0000453 virtual void OnRenegotiationNeeded() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000454
455 // Called any time the IceConnectionState changes
456 virtual void OnIceConnectionChange(
457 PeerConnectionInterface::IceConnectionState new_state) {}
458
459 // Called any time the IceGatheringState changes
460 virtual void OnIceGatheringChange(
461 PeerConnectionInterface::IceGatheringState new_state) {}
462
463 // New Ice candidate have been found.
464 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
465
466 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
467 // All Ice candidates have been found.
468 virtual void OnIceComplete() {}
469
Peter Thatcher54360512015-07-08 11:08:35 -0700470 // Called when the ICE connection receiving status changes.
471 virtual void OnIceConnectionReceivingChange(bool receiving) {}
472
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000473 protected:
474 // Dtor protected as objects shouldn't be deleted via this interface.
475 ~PeerConnectionObserver() {}
476};
477
478// Factory class used for creating cricket::PortAllocator that is used
479// for ICE negotiation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000480class PortAllocatorFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000481 public:
482 struct StunConfiguration {
483 StunConfiguration(const std::string& address, int port)
484 : server(address, port) {}
485 // STUN server address and port.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000486 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000487 };
488
489 struct TurnConfiguration {
490 TurnConfiguration(const std::string& address,
491 int port,
492 const std::string& username,
493 const std::string& password,
wu@webrtc.org91053e72013-08-10 07:18:04 +0000494 const std::string& transport_type,
495 bool secure)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000496 : server(address, port),
497 username(username),
498 password(password),
wu@webrtc.org91053e72013-08-10 07:18:04 +0000499 transport_type(transport_type),
500 secure(secure) {}
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000501 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502 std::string username;
503 std::string password;
504 std::string transport_type;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000505 bool secure;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000506 };
507
508 virtual cricket::PortAllocator* CreatePortAllocator(
509 const std::vector<StunConfiguration>& stun_servers,
510 const std::vector<TurnConfiguration>& turn_configurations) = 0;
511
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000512 // TODO(phoglund): Make pure virtual when Chrome's factory implements this.
513 // After this method is called, the port allocator should consider loopback
514 // network interfaces as well.
515 virtual void SetNetworkIgnoreMask(int network_ignore_mask) {
516 }
517
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000518 protected:
519 PortAllocatorFactoryInterface() {}
520 ~PortAllocatorFactoryInterface() {}
521};
522
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000523// PeerConnectionFactoryInterface is the factory interface use for creating
524// PeerConnection, MediaStream and media tracks.
525// PeerConnectionFactoryInterface will create required libjingle threads,
526// socket and network manager factory classes for networking.
527// If an application decides to provide its own threads and network
528// implementation of these classes it should use the alternate
529// CreatePeerConnectionFactory method which accepts threads as input and use the
530// CreatePeerConnection version that takes a PortAllocatorFactoryInterface as
531// argument.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000532class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533 public:
wu@webrtc.org97077a32013-10-25 21:18:33 +0000534 class Options {
535 public:
536 Options() :
wu@webrtc.org97077a32013-10-25 21:18:33 +0000537 disable_encryption(false),
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000538 disable_sctp_data_channels(false),
Joachim Bauch04e5b492015-05-29 09:40:39 +0200539 network_ignore_mask(rtc::kDefaultNetworkIgnoreMask),
540 ssl_max_version(rtc::SSL_PROTOCOL_DTLS_10) {
wu@webrtc.org97077a32013-10-25 21:18:33 +0000541 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000542 bool disable_encryption;
543 bool disable_sctp_data_channels;
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000544
545 // Sets the network types to ignore. For instance, calling this with
546 // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
547 // loopback interfaces.
548 int network_ignore_mask;
Joachim Bauch04e5b492015-05-29 09:40:39 +0200549
550 // Sets the maximum supported protocol version. The highest version
551 // supported by both ends will be used for the connection, i.e. if one
552 // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used.
553 rtc::SSLProtocolVersion ssl_max_version;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000554 };
555
556 virtual void SetOptions(const Options& options) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000557
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000558 virtual rtc::scoped_refptr<PeerConnectionInterface>
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000559 CreatePeerConnection(
560 const PeerConnectionInterface::RTCConfiguration& configuration,
561 const MediaConstraintsInterface* constraints,
562 PortAllocatorFactoryInterface* allocator_factory,
Henrik Boström5e56c592015-08-11 10:33:13 +0200563 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000564 PeerConnectionObserver* observer) = 0;
565
Henrik Boström5e56c592015-08-11 10:33:13 +0200566 // TODO(hbos): Remove below version after clients are updated to above method.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000567 // In latest W3C WebRTC draft, PC constructor will take RTCConfiguration,
568 // and not IceServers. RTCConfiguration is made up of ice servers and
569 // ice transport type.
570 // http://dev.w3.org/2011/webrtc/editor/webrtc.html
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000571 inline rtc::scoped_refptr<PeerConnectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 CreatePeerConnection(
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000573 const PeerConnectionInterface::IceServers& servers,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000574 const MediaConstraintsInterface* constraints,
575 PortAllocatorFactoryInterface* allocator_factory,
Henrik Boström5e56c592015-08-11 10:33:13 +0200576 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000577 PeerConnectionObserver* observer) {
578 PeerConnectionInterface::RTCConfiguration rtc_config;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000579 rtc_config.servers = servers;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000580 return CreatePeerConnection(rtc_config, constraints, allocator_factory,
Henrik Boström5e56c592015-08-11 10:33:13 +0200581 dtls_identity_store.Pass(), observer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000582 }
583
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000584 virtual rtc::scoped_refptr<MediaStreamInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000585 CreateLocalMediaStream(const std::string& label) = 0;
586
587 // Creates a AudioSourceInterface.
588 // |constraints| decides audio processing settings but can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000589 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000590 const MediaConstraintsInterface* constraints) = 0;
591
592 // Creates a VideoSourceInterface. The new source take ownership of
593 // |capturer|. |constraints| decides video resolution and frame rate but can
594 // be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000595 virtual rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000596 cricket::VideoCapturer* capturer,
597 const MediaConstraintsInterface* constraints) = 0;
598
599 // Creates a new local VideoTrack. The same |source| can be used in several
600 // tracks.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000601 virtual rtc::scoped_refptr<VideoTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000602 CreateVideoTrack(const std::string& label,
603 VideoSourceInterface* source) = 0;
604
605 // Creates an new AudioTrack. At the moment |source| can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000606 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607 CreateAudioTrack(const std::string& label,
608 AudioSourceInterface* source) = 0;
609
wu@webrtc.orga9890802013-12-13 00:21:03 +0000610 // Starts AEC dump using existing file. Takes ownership of |file| and passes
611 // it on to VoiceEngine (via other objects) immediately, which will take
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000612 // the ownerhip. If the operation fails, the file will be closed.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000613 // TODO(grunell): Remove when Chromium has started to use AEC in each source.
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000614 // http://crbug.com/264611.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000615 virtual bool StartAecDump(rtc::PlatformFile file) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000616
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000617 protected:
618 // Dtor and ctor protected as objects shouldn't be created or deleted via
619 // this interface.
620 PeerConnectionFactoryInterface() {}
621 ~PeerConnectionFactoryInterface() {} // NOLINT
622};
623
624// Create a new instance of PeerConnectionFactoryInterface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000625rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626CreatePeerConnectionFactory();
627
628// Create a new instance of PeerConnectionFactoryInterface.
629// Ownership of |factory|, |default_adm|, and optionally |encoder_factory| and
630// |decoder_factory| transferred to the returned factory.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000631rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632CreatePeerConnectionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000633 rtc::Thread* worker_thread,
634 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000635 AudioDeviceModule* default_adm,
636 cricket::WebRtcVideoEncoderFactory* encoder_factory,
637 cricket::WebRtcVideoDecoderFactory* decoder_factory);
638
639} // namespace webrtc
640
641#endif // TALK_APP_WEBRTC_PEERCONNECTIONINTERFACE_H_