blob: 3e4cb556fb5f51826734c719a5cf3f6e46bc36e8 [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"
75#include "talk/app/webrtc/dtmfsenderinterface.h"
76#include "talk/app/webrtc/jsep.h"
77#include "talk/app/webrtc/mediastreaminterface.h"
78#include "talk/app/webrtc/statstypes.h"
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +000079#include "talk/app/webrtc/umametrics.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000080#include "webrtc/base/fileutils.h"
phoglund@webrtc.org006521d2015-02-12 09:23:59 +000081#include "webrtc/base/network.h"
Joachim Bauch04e5b492015-05-29 09:40:39 +020082#include "webrtc/base/sslstreamadapter.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000083#include "webrtc/base/socketaddress.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000085namespace rtc {
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000086class SSLIdentity;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087class Thread;
88}
89
90namespace cricket {
91class PortAllocator;
92class WebRtcVideoDecoderFactory;
93class WebRtcVideoEncoderFactory;
94}
95
96namespace webrtc {
97class AudioDeviceModule;
98class MediaConstraintsInterface;
99
100// MediaStream container interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000101class StreamCollectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102 public:
103 // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find.
104 virtual size_t count() = 0;
105 virtual MediaStreamInterface* at(size_t index) = 0;
106 virtual MediaStreamInterface* find(const std::string& label) = 0;
107 virtual MediaStreamTrackInterface* FindAudioTrack(
108 const std::string& id) = 0;
109 virtual MediaStreamTrackInterface* FindVideoTrack(
110 const std::string& id) = 0;
111
112 protected:
113 // Dtor protected as objects shouldn't be deleted via this interface.
114 ~StreamCollectionInterface() {}
115};
116
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000117class StatsObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118 public:
tommi@webrtc.orge2e199b2014-12-15 13:22:54 +0000119 virtual void OnComplete(const StatsReports& reports) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120
121 protected:
122 virtual ~StatsObserver() {}
123};
124
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000125class MetricsObserverInterface : public rtc::RefCountInterface {
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000126 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000127 virtual void IncrementCounter(PeerConnectionMetricsCounter type) = 0;
128 virtual void AddHistogramSample(PeerConnectionMetricsName type,
mallinath@webrtc.orgd37bcfa2014-05-12 23:10:18 +0000129 int value) = 0;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000130
131 protected:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000132 virtual ~MetricsObserverInterface() {}
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000133};
134
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000135typedef MetricsObserverInterface UMAObserver;
136
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000137class PeerConnectionInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138 public:
139 // See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions .
140 enum SignalingState {
141 kStable,
142 kHaveLocalOffer,
143 kHaveLocalPrAnswer,
144 kHaveRemoteOffer,
145 kHaveRemotePrAnswer,
146 kClosed,
147 };
148
149 // TODO(bemasc): Remove IceState when callers are changed to
150 // IceConnection/GatheringState.
151 enum IceState {
152 kIceNew,
153 kIceGathering,
154 kIceWaiting,
155 kIceChecking,
156 kIceConnected,
157 kIceCompleted,
158 kIceFailed,
159 kIceClosed,
160 };
161
162 enum IceGatheringState {
163 kIceGatheringNew,
164 kIceGatheringGathering,
165 kIceGatheringComplete
166 };
167
168 enum IceConnectionState {
169 kIceConnectionNew,
170 kIceConnectionChecking,
171 kIceConnectionConnected,
172 kIceConnectionCompleted,
173 kIceConnectionFailed,
174 kIceConnectionDisconnected,
175 kIceConnectionClosed,
176 };
177
178 struct IceServer {
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200179 // TODO(jbauch): Remove uri when all code using it has switched to urls.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180 std::string uri;
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200181 std::vector<std::string> urls;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182 std::string username;
183 std::string password;
184 };
185 typedef std::vector<IceServer> IceServers;
186
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000187 enum IceTransportsType {
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000188 // TODO(pthatcher): Rename these kTransporTypeXXX, but update
189 // Chromium at the same time.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000190 kNone,
191 kRelay,
192 kNoHost,
193 kAll
194 };
195
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000196 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-08#section-4.1.1
197 enum BundlePolicy {
198 kBundlePolicyBalanced,
199 kBundlePolicyMaxBundle,
200 kBundlePolicyMaxCompat
201 };
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000202
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700203 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-09#section-4.1.1
204 enum RtcpMuxPolicy {
205 kRtcpMuxPolicyNegotiate,
206 kRtcpMuxPolicyRequire,
207 };
208
Jiayang Liucac1b382015-04-30 12:35:24 -0700209 enum TcpCandidatePolicy {
210 kTcpCandidatePolicyEnabled,
211 kTcpCandidatePolicyDisabled
212 };
213
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000214 struct RTCConfiguration {
215 // TODO(pthatcher): Rename this ice_transport_type, but update
216 // Chromium at the same time.
217 IceTransportsType type;
218 // TODO(pthatcher): Rename this ice_servers, but update Chromium
219 // at the same time.
220 IceServers servers;
221 BundlePolicy bundle_policy;
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700222 RtcpMuxPolicy rtcp_mux_policy;
Jiayang Liucac1b382015-04-30 12:35:24 -0700223 TcpCandidatePolicy tcp_candidate_policy;
Henrik Lundin64dad832015-05-11 12:44:23 +0200224 int audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200225 bool audio_jitter_buffer_fast_accelerate;
pthatcher@webrtc.orgfd630a52015-01-14 23:19:06 +0000226
Jiayang Liucac1b382015-04-30 12:35:24 -0700227 RTCConfiguration()
228 : type(kAll),
229 bundle_policy(kBundlePolicyBalanced),
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700230 rtcp_mux_policy(kRtcpMuxPolicyNegotiate),
Henrik Lundin64dad832015-05-11 12:44:23 +0200231 tcp_candidate_policy(kTcpCandidatePolicyEnabled),
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200232 audio_jitter_buffer_max_packets(50),
233 audio_jitter_buffer_fast_accelerate(false) {}
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000234 };
235
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000236 struct RTCOfferAnswerOptions {
237 static const int kUndefined = -1;
238 static const int kMaxOfferToReceiveMedia = 1;
239
240 // The default value for constraint offerToReceiveX:true.
241 static const int kOfferToReceiveMediaTrue = 1;
242
243 int offer_to_receive_video;
244 int offer_to_receive_audio;
245 bool voice_activity_detection;
246 bool ice_restart;
247 bool use_rtp_mux;
248
249 RTCOfferAnswerOptions()
250 : offer_to_receive_video(kUndefined),
251 offer_to_receive_audio(kUndefined),
252 voice_activity_detection(true),
253 ice_restart(false),
254 use_rtp_mux(true) {}
255
256 RTCOfferAnswerOptions(int offer_to_receive_video,
257 int offer_to_receive_audio,
258 bool voice_activity_detection,
259 bool ice_restart,
260 bool use_rtp_mux)
261 : offer_to_receive_video(offer_to_receive_video),
262 offer_to_receive_audio(offer_to_receive_audio),
263 voice_activity_detection(voice_activity_detection),
264 ice_restart(ice_restart),
265 use_rtp_mux(use_rtp_mux) {}
266 };
267
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000268 // Used by GetStats to decide which stats to include in the stats reports.
269 // |kStatsOutputLevelStandard| includes the standard stats for Javascript API;
270 // |kStatsOutputLevelDebug| includes both the standard stats and additional
271 // stats for debugging purposes.
272 enum StatsOutputLevel {
273 kStatsOutputLevelStandard,
274 kStatsOutputLevelDebug,
275 };
276
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 // Accessor methods to active local streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000278 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279 local_streams() = 0;
280
281 // Accessor methods to remote streams.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000282 virtual rtc::scoped_refptr<StreamCollectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283 remote_streams() = 0;
284
285 // Add a new MediaStream to be sent on this PeerConnection.
286 // Note that a SessionDescription negotiation is needed before the
287 // remote peer can receive the stream.
perkj@webrtc.orgfd0efb62014-11-06 12:16:36 +0000288 virtual bool AddStream(MediaStreamInterface* stream) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289
290 // Remove a MediaStream from this PeerConnection.
291 // Note that a SessionDescription negotiation is need before the
292 // remote peer is notified.
293 virtual void RemoveStream(MediaStreamInterface* stream) = 0;
294
295 // Returns pointer to the created DtmfSender on success.
296 // Otherwise returns NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000297 virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298 AudioTrackInterface* track) = 0;
299
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000300 virtual bool GetStats(StatsObserver* observer,
301 MediaStreamTrackInterface* track,
302 StatsOutputLevel level) = 0;
303
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000304 virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 const std::string& label,
306 const DataChannelInit* config) = 0;
307
308 virtual const SessionDescriptionInterface* local_description() const = 0;
309 virtual const SessionDescriptionInterface* remote_description() const = 0;
310
311 // Create a new offer.
312 // The CreateSessionDescriptionObserver callback will be called when done.
313 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000314 const MediaConstraintsInterface* constraints) {}
315
316 // TODO(jiayl): remove the default impl and the old interface when chromium
317 // code is updated.
318 virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
319 const RTCOfferAnswerOptions& options) {}
320
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321 // Create an answer to an offer.
322 // The CreateSessionDescriptionObserver callback will be called when done.
323 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
324 const MediaConstraintsInterface* constraints) = 0;
325 // Sets the local session description.
326 // JsepInterface takes the ownership of |desc| even if it fails.
327 // The |observer| callback will be called when done.
328 virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
329 SessionDescriptionInterface* desc) = 0;
330 // Sets the remote session description.
331 // JsepInterface takes the ownership of |desc| even if it fails.
332 // The |observer| callback will be called when done.
333 virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
334 SessionDescriptionInterface* desc) = 0;
335 // Restarts or updates the ICE Agent process of gathering local candidates
336 // and pinging remote candidates.
337 virtual bool UpdateIce(const IceServers& configuration,
338 const MediaConstraintsInterface* constraints) = 0;
339 // Provides a remote candidate to the ICE Agent.
340 // A copy of the |candidate| will be created and added to the remote
341 // description. So the caller of this method still has the ownership of the
342 // |candidate|.
343 // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will
344 // take the ownership of the |candidate|.
345 virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
346
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000347 virtual void RegisterUMAObserver(UMAObserver* observer) = 0;
348
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 // Returns the current SignalingState.
350 virtual SignalingState signaling_state() = 0;
351
352 // TODO(bemasc): Remove ice_state when callers are changed to
353 // IceConnection/GatheringState.
354 // Returns the current IceState.
355 virtual IceState ice_state() = 0;
356 virtual IceConnectionState ice_connection_state() = 0;
357 virtual IceGatheringState ice_gathering_state() = 0;
358
359 // Terminates all media and closes the transport.
360 virtual void Close() = 0;
361
362 protected:
363 // Dtor protected as objects shouldn't be deleted via this interface.
364 ~PeerConnectionInterface() {}
365};
366
367// PeerConnection callback interface. Application should implement these
368// methods.
369class PeerConnectionObserver {
370 public:
371 enum StateType {
372 kSignalingState,
373 kIceState,
374 };
375
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376 // Triggered when the SignalingState changed.
377 virtual void OnSignalingChange(
378 PeerConnectionInterface::SignalingState new_state) {}
379
380 // Triggered when SignalingState or IceState have changed.
381 // TODO(bemasc): Remove once callers transition to OnSignalingChange.
382 virtual void OnStateChange(StateType state_changed) {}
383
384 // Triggered when media is received on a new stream from remote peer.
385 virtual void OnAddStream(MediaStreamInterface* stream) = 0;
386
387 // Triggered when a remote peer close a stream.
388 virtual void OnRemoveStream(MediaStreamInterface* stream) = 0;
389
390 // Triggered when a remote peer open a data channel.
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000391 virtual void OnDataChannel(DataChannelInterface* data_channel) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392
mallinath@webrtc.org0d92ef62014-01-22 02:21:22 +0000393 // Triggered when renegotiation is needed, for example the ICE has restarted.
fischman@webrtc.orgd7568a02014-01-13 22:04:12 +0000394 virtual void OnRenegotiationNeeded() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000395
396 // Called any time the IceConnectionState changes
397 virtual void OnIceConnectionChange(
398 PeerConnectionInterface::IceConnectionState new_state) {}
399
400 // Called any time the IceGatheringState changes
401 virtual void OnIceGatheringChange(
402 PeerConnectionInterface::IceGatheringState new_state) {}
403
404 // New Ice candidate have been found.
405 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
406
407 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
408 // All Ice candidates have been found.
409 virtual void OnIceComplete() {}
410
411 protected:
412 // Dtor protected as objects shouldn't be deleted via this interface.
413 ~PeerConnectionObserver() {}
414};
415
416// Factory class used for creating cricket::PortAllocator that is used
417// for ICE negotiation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000418class PortAllocatorFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419 public:
420 struct StunConfiguration {
421 StunConfiguration(const std::string& address, int port)
422 : server(address, port) {}
423 // STUN server address and port.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000424 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425 };
426
427 struct TurnConfiguration {
428 TurnConfiguration(const std::string& address,
429 int port,
430 const std::string& username,
431 const std::string& password,
wu@webrtc.org91053e72013-08-10 07:18:04 +0000432 const std::string& transport_type,
433 bool secure)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434 : server(address, port),
435 username(username),
436 password(password),
wu@webrtc.org91053e72013-08-10 07:18:04 +0000437 transport_type(transport_type),
438 secure(secure) {}
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000439 rtc::SocketAddress server;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440 std::string username;
441 std::string password;
442 std::string transport_type;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000443 bool secure;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000444 };
445
446 virtual cricket::PortAllocator* CreatePortAllocator(
447 const std::vector<StunConfiguration>& stun_servers,
448 const std::vector<TurnConfiguration>& turn_configurations) = 0;
449
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000450 // TODO(phoglund): Make pure virtual when Chrome's factory implements this.
451 // After this method is called, the port allocator should consider loopback
452 // network interfaces as well.
453 virtual void SetNetworkIgnoreMask(int network_ignore_mask) {
454 }
455
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000456 protected:
457 PortAllocatorFactoryInterface() {}
458 ~PortAllocatorFactoryInterface() {}
459};
460
461// Used to receive callbacks of DTLS identity requests.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000462class DTLSIdentityRequestObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463 public:
464 virtual void OnFailure(int error) = 0;
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +0000465 // TODO(jiayl): Unify the OnSuccess method once Chrome code is updated.
wu@webrtc.org91053e72013-08-10 07:18:04 +0000466 virtual void OnSuccess(const std::string& der_cert,
467 const std::string& der_private_key) = 0;
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +0000468 // |identity| is a scoped_ptr because rtc::SSLIdentity is not copyable and the
469 // client has to get the ownership of the object to make use of it.
470 virtual void OnSuccessWithIdentityObj(
471 rtc::scoped_ptr<rtc::SSLIdentity> identity) = 0;
472
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000473 protected:
474 virtual ~DTLSIdentityRequestObserver() {}
475};
476
477class DTLSIdentityServiceInterface {
478 public:
479 // Asynchronously request a DTLS identity, including a self-signed certificate
480 // and the private key used to sign the certificate, from the identity store
481 // for the given identity name.
482 // DTLSIdentityRequestObserver::OnSuccess will be called with the identity if
483 // the request succeeded; DTLSIdentityRequestObserver::OnFailure will be
484 // called with an error code if the request failed.
485 //
486 // Only one request can be made at a time. If a second request is called
487 // before the first one completes, RequestIdentity will abort and return
488 // false.
489 //
490 // |identity_name| is an internal name selected by the client to identify an
491 // identity within an origin. E.g. an web site may cache the certificates used
492 // to communicate with differnent peers under different identity names.
493 //
494 // |common_name| is the common name used to generate the certificate. If the
495 // certificate already exists in the store, |common_name| is ignored.
496 //
497 // |observer| is the object to receive success or failure callbacks.
498 //
499 // Returns true if either OnFailure or OnSuccess will be called.
500 virtual bool RequestIdentity(
501 const std::string& identity_name,
502 const std::string& common_name,
503 DTLSIdentityRequestObserver* observer) = 0;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000504
505 virtual ~DTLSIdentityServiceInterface() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000506};
507
508// PeerConnectionFactoryInterface is the factory interface use for creating
509// PeerConnection, MediaStream and media tracks.
510// PeerConnectionFactoryInterface will create required libjingle threads,
511// socket and network manager factory classes for networking.
512// If an application decides to provide its own threads and network
513// implementation of these classes it should use the alternate
514// CreatePeerConnectionFactory method which accepts threads as input and use the
515// CreatePeerConnection version that takes a PortAllocatorFactoryInterface as
516// argument.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000517class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000518 public:
wu@webrtc.org97077a32013-10-25 21:18:33 +0000519 class Options {
520 public:
521 Options() :
wu@webrtc.org97077a32013-10-25 21:18:33 +0000522 disable_encryption(false),
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000523 disable_sctp_data_channels(false),
Joachim Bauch04e5b492015-05-29 09:40:39 +0200524 network_ignore_mask(rtc::kDefaultNetworkIgnoreMask),
525 ssl_max_version(rtc::SSL_PROTOCOL_DTLS_10) {
wu@webrtc.org97077a32013-10-25 21:18:33 +0000526 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000527 bool disable_encryption;
528 bool disable_sctp_data_channels;
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000529
530 // Sets the network types to ignore. For instance, calling this with
531 // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
532 // loopback interfaces.
533 int network_ignore_mask;
Joachim Bauch04e5b492015-05-29 09:40:39 +0200534
535 // Sets the maximum supported protocol version. The highest version
536 // supported by both ends will be used for the connection, i.e. if one
537 // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used.
538 rtc::SSLProtocolVersion ssl_max_version;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000539 };
540
541 virtual void SetOptions(const Options& options) = 0;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000542
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +0000543 // This method takes the ownership of |dtls_identity_service|.
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,
549 DTLSIdentityServiceInterface* dtls_identity_service,
550 PeerConnectionObserver* observer) = 0;
551
552 // TODO(mallinath) : Remove below versions after clients are updated
553 // to above method.
554 // In latest W3C WebRTC draft, PC constructor will take RTCConfiguration,
555 // and not IceServers. RTCConfiguration is made up of ice servers and
556 // ice transport type.
557 // http://dev.w3.org/2011/webrtc/editor/webrtc.html
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000558 inline rtc::scoped_refptr<PeerConnectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000559 CreatePeerConnection(
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000560 const PeerConnectionInterface::IceServers& servers,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 const MediaConstraintsInterface* constraints,
562 PortAllocatorFactoryInterface* allocator_factory,
563 DTLSIdentityServiceInterface* dtls_identity_service,
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000564 PeerConnectionObserver* observer) {
565 PeerConnectionInterface::RTCConfiguration rtc_config;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000566 rtc_config.servers = servers;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000567 return CreatePeerConnection(rtc_config, constraints, allocator_factory,
568 dtls_identity_service, observer);
569 }
570
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000571 virtual rtc::scoped_refptr<MediaStreamInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 CreateLocalMediaStream(const std::string& label) = 0;
573
574 // Creates a AudioSourceInterface.
575 // |constraints| decides audio processing settings but can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000576 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000577 const MediaConstraintsInterface* constraints) = 0;
578
579 // Creates a VideoSourceInterface. The new source take ownership of
580 // |capturer|. |constraints| decides video resolution and frame rate but can
581 // be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000582 virtual rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583 cricket::VideoCapturer* capturer,
584 const MediaConstraintsInterface* constraints) = 0;
585
586 // Creates a new local VideoTrack. The same |source| can be used in several
587 // tracks.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000588 virtual rtc::scoped_refptr<VideoTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000589 CreateVideoTrack(const std::string& label,
590 VideoSourceInterface* source) = 0;
591
592 // Creates an new AudioTrack. At the moment |source| can be NULL.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000593 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000594 CreateAudioTrack(const std::string& label,
595 AudioSourceInterface* source) = 0;
596
wu@webrtc.orga9890802013-12-13 00:21:03 +0000597 // Starts AEC dump using existing file. Takes ownership of |file| and passes
598 // it on to VoiceEngine (via other objects) immediately, which will take
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000599 // the ownerhip. If the operation fails, the file will be closed.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000600 // TODO(grunell): Remove when Chromium has started to use AEC in each source.
wu@webrtc.orga8910d22014-01-23 22:12:45 +0000601 // http://crbug.com/264611.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000602 virtual bool StartAecDump(rtc::PlatformFile file) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000603
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000604 protected:
605 // Dtor and ctor protected as objects shouldn't be created or deleted via
606 // this interface.
607 PeerConnectionFactoryInterface() {}
608 ~PeerConnectionFactoryInterface() {} // NOLINT
609};
610
611// Create a new instance of PeerConnectionFactoryInterface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000612rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000613CreatePeerConnectionFactory();
614
615// Create a new instance of PeerConnectionFactoryInterface.
616// Ownership of |factory|, |default_adm|, and optionally |encoder_factory| and
617// |decoder_factory| transferred to the returned factory.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000618rtc::scoped_refptr<PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000619CreatePeerConnectionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000620 rtc::Thread* worker_thread,
621 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622 AudioDeviceModule* default_adm,
623 cricket::WebRtcVideoEncoderFactory* encoder_factory,
624 cricket::WebRtcVideoDecoderFactory* decoder_factory);
625
626} // namespace webrtc
627
628#endif // TALK_APP_WEBRTC_PEERCONNECTIONINTERFACE_H_