henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2012, Google Inc. |
| 4 | * |
| 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.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 79 | #include "talk/app/webrtc/umametrics.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 80 | #include "webrtc/base/fileutils.h" |
| 81 | #include "webrtc/base/socketaddress.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 83 | namespace rtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | class Thread; |
| 85 | } |
| 86 | |
| 87 | namespace cricket { |
| 88 | class PortAllocator; |
| 89 | class WebRtcVideoDecoderFactory; |
| 90 | class WebRtcVideoEncoderFactory; |
| 91 | } |
| 92 | |
| 93 | namespace webrtc { |
| 94 | class AudioDeviceModule; |
| 95 | class MediaConstraintsInterface; |
| 96 | |
| 97 | // MediaStream container interface. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 98 | class StreamCollectionInterface : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 99 | public: |
| 100 | // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find. |
| 101 | virtual size_t count() = 0; |
| 102 | virtual MediaStreamInterface* at(size_t index) = 0; |
| 103 | virtual MediaStreamInterface* find(const std::string& label) = 0; |
| 104 | virtual MediaStreamTrackInterface* FindAudioTrack( |
| 105 | const std::string& id) = 0; |
| 106 | virtual MediaStreamTrackInterface* FindVideoTrack( |
| 107 | const std::string& id) = 0; |
| 108 | |
| 109 | protected: |
| 110 | // Dtor protected as objects shouldn't be deleted via this interface. |
| 111 | ~StreamCollectionInterface() {} |
| 112 | }; |
| 113 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 114 | class StatsObserver : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 115 | public: |
henrike@webrtc.org | 185636c | 2014-07-25 18:44:42 +0000 | [diff] [blame] | 116 | virtual void OnComplete(const std::vector<StatsReport>& reports) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 117 | |
| 118 | protected: |
| 119 | virtual ~StatsObserver() {} |
| 120 | }; |
| 121 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 122 | class UMAObserver : public rtc::RefCountInterface { |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 123 | public: |
mallinath@webrtc.org | d37bcfa | 2014-05-12 23:10:18 +0000 | [diff] [blame] | 124 | virtual void IncrementCounter(PeerConnectionUMAMetricsCounter type) = 0; |
| 125 | virtual void AddHistogramSample(PeerConnectionUMAMetricsName type, |
| 126 | int value) = 0; |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 127 | |
| 128 | protected: |
| 129 | virtual ~UMAObserver() {} |
| 130 | }; |
| 131 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 132 | class PeerConnectionInterface : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 133 | public: |
| 134 | // See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions . |
| 135 | enum SignalingState { |
| 136 | kStable, |
| 137 | kHaveLocalOffer, |
| 138 | kHaveLocalPrAnswer, |
| 139 | kHaveRemoteOffer, |
| 140 | kHaveRemotePrAnswer, |
| 141 | kClosed, |
| 142 | }; |
| 143 | |
| 144 | // TODO(bemasc): Remove IceState when callers are changed to |
| 145 | // IceConnection/GatheringState. |
| 146 | enum IceState { |
| 147 | kIceNew, |
| 148 | kIceGathering, |
| 149 | kIceWaiting, |
| 150 | kIceChecking, |
| 151 | kIceConnected, |
| 152 | kIceCompleted, |
| 153 | kIceFailed, |
| 154 | kIceClosed, |
| 155 | }; |
| 156 | |
| 157 | enum IceGatheringState { |
| 158 | kIceGatheringNew, |
| 159 | kIceGatheringGathering, |
| 160 | kIceGatheringComplete |
| 161 | }; |
| 162 | |
| 163 | enum IceConnectionState { |
| 164 | kIceConnectionNew, |
| 165 | kIceConnectionChecking, |
| 166 | kIceConnectionConnected, |
| 167 | kIceConnectionCompleted, |
| 168 | kIceConnectionFailed, |
| 169 | kIceConnectionDisconnected, |
| 170 | kIceConnectionClosed, |
| 171 | }; |
| 172 | |
| 173 | struct IceServer { |
| 174 | std::string uri; |
| 175 | std::string username; |
| 176 | std::string password; |
| 177 | }; |
| 178 | typedef std::vector<IceServer> IceServers; |
| 179 | |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 180 | enum IceTransportsType { |
| 181 | kNone, |
| 182 | kRelay, |
| 183 | kNoHost, |
| 184 | kAll |
| 185 | }; |
| 186 | |
| 187 | struct RTCConfiguration { |
| 188 | IceTransportsType type; |
| 189 | IceServers servers; |
| 190 | |
| 191 | RTCConfiguration() : type(kAll) {} |
| 192 | explicit RTCConfiguration(IceTransportsType type) : type(type) {} |
| 193 | }; |
| 194 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame^] | 195 | struct RTCOfferAnswerOptions { |
| 196 | static const int kUndefined = -1; |
| 197 | static const int kMaxOfferToReceiveMedia = 1; |
| 198 | |
| 199 | // The default value for constraint offerToReceiveX:true. |
| 200 | static const int kOfferToReceiveMediaTrue = 1; |
| 201 | |
| 202 | int offer_to_receive_video; |
| 203 | int offer_to_receive_audio; |
| 204 | bool voice_activity_detection; |
| 205 | bool ice_restart; |
| 206 | bool use_rtp_mux; |
| 207 | |
| 208 | RTCOfferAnswerOptions() |
| 209 | : offer_to_receive_video(kUndefined), |
| 210 | offer_to_receive_audio(kUndefined), |
| 211 | voice_activity_detection(true), |
| 212 | ice_restart(false), |
| 213 | use_rtp_mux(true) {} |
| 214 | |
| 215 | RTCOfferAnswerOptions(int offer_to_receive_video, |
| 216 | int offer_to_receive_audio, |
| 217 | bool voice_activity_detection, |
| 218 | bool ice_restart, |
| 219 | bool use_rtp_mux) |
| 220 | : offer_to_receive_video(offer_to_receive_video), |
| 221 | offer_to_receive_audio(offer_to_receive_audio), |
| 222 | voice_activity_detection(voice_activity_detection), |
| 223 | ice_restart(ice_restart), |
| 224 | use_rtp_mux(use_rtp_mux) {} |
| 225 | }; |
| 226 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 227 | // Used by GetStats to decide which stats to include in the stats reports. |
| 228 | // |kStatsOutputLevelStandard| includes the standard stats for Javascript API; |
| 229 | // |kStatsOutputLevelDebug| includes both the standard stats and additional |
| 230 | // stats for debugging purposes. |
| 231 | enum StatsOutputLevel { |
| 232 | kStatsOutputLevelStandard, |
| 233 | kStatsOutputLevelDebug, |
| 234 | }; |
| 235 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 236 | // Accessor methods to active local streams. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 237 | virtual rtc::scoped_refptr<StreamCollectionInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 238 | local_streams() = 0; |
| 239 | |
| 240 | // Accessor methods to remote streams. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 241 | virtual rtc::scoped_refptr<StreamCollectionInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 242 | remote_streams() = 0; |
| 243 | |
| 244 | // Add a new MediaStream to be sent on this PeerConnection. |
| 245 | // Note that a SessionDescription negotiation is needed before the |
| 246 | // remote peer can receive the stream. |
| 247 | virtual bool AddStream(MediaStreamInterface* stream, |
| 248 | const MediaConstraintsInterface* constraints) = 0; |
| 249 | |
| 250 | // Remove a MediaStream from this PeerConnection. |
| 251 | // Note that a SessionDescription negotiation is need before the |
| 252 | // remote peer is notified. |
| 253 | virtual void RemoveStream(MediaStreamInterface* stream) = 0; |
| 254 | |
| 255 | // Returns pointer to the created DtmfSender on success. |
| 256 | // Otherwise returns NULL. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 257 | virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 258 | AudioTrackInterface* track) = 0; |
| 259 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 260 | virtual bool GetStats(StatsObserver* observer, |
| 261 | MediaStreamTrackInterface* track, |
| 262 | StatsOutputLevel level) = 0; |
| 263 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 264 | virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 265 | const std::string& label, |
| 266 | const DataChannelInit* config) = 0; |
| 267 | |
| 268 | virtual const SessionDescriptionInterface* local_description() const = 0; |
| 269 | virtual const SessionDescriptionInterface* remote_description() const = 0; |
| 270 | |
| 271 | // Create a new offer. |
| 272 | // The CreateSessionDescriptionObserver callback will be called when done. |
| 273 | virtual void CreateOffer(CreateSessionDescriptionObserver* observer, |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame^] | 274 | const MediaConstraintsInterface* constraints) {} |
| 275 | |
| 276 | // TODO(jiayl): remove the default impl and the old interface when chromium |
| 277 | // code is updated. |
| 278 | virtual void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 279 | const RTCOfferAnswerOptions& options) {} |
| 280 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 281 | // Create an answer to an offer. |
| 282 | // The CreateSessionDescriptionObserver callback will be called when done. |
| 283 | virtual void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 284 | const MediaConstraintsInterface* constraints) = 0; |
| 285 | // Sets the local session description. |
| 286 | // JsepInterface takes the ownership of |desc| even if it fails. |
| 287 | // The |observer| callback will be called when done. |
| 288 | virtual void SetLocalDescription(SetSessionDescriptionObserver* observer, |
| 289 | SessionDescriptionInterface* desc) = 0; |
| 290 | // Sets the remote session description. |
| 291 | // JsepInterface takes the ownership of |desc| even if it fails. |
| 292 | // The |observer| callback will be called when done. |
| 293 | virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer, |
| 294 | SessionDescriptionInterface* desc) = 0; |
| 295 | // Restarts or updates the ICE Agent process of gathering local candidates |
| 296 | // and pinging remote candidates. |
| 297 | virtual bool UpdateIce(const IceServers& configuration, |
| 298 | const MediaConstraintsInterface* constraints) = 0; |
| 299 | // Provides a remote candidate to the ICE Agent. |
| 300 | // A copy of the |candidate| will be created and added to the remote |
| 301 | // description. So the caller of this method still has the ownership of the |
| 302 | // |candidate|. |
| 303 | // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will |
| 304 | // take the ownership of the |candidate|. |
| 305 | virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0; |
| 306 | |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 307 | virtual void RegisterUMAObserver(UMAObserver* observer) = 0; |
| 308 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 309 | // Returns the current SignalingState. |
| 310 | virtual SignalingState signaling_state() = 0; |
| 311 | |
| 312 | // TODO(bemasc): Remove ice_state when callers are changed to |
| 313 | // IceConnection/GatheringState. |
| 314 | // Returns the current IceState. |
| 315 | virtual IceState ice_state() = 0; |
| 316 | virtual IceConnectionState ice_connection_state() = 0; |
| 317 | virtual IceGatheringState ice_gathering_state() = 0; |
| 318 | |
| 319 | // Terminates all media and closes the transport. |
| 320 | virtual void Close() = 0; |
| 321 | |
| 322 | protected: |
| 323 | // Dtor protected as objects shouldn't be deleted via this interface. |
| 324 | ~PeerConnectionInterface() {} |
| 325 | }; |
| 326 | |
| 327 | // PeerConnection callback interface. Application should implement these |
| 328 | // methods. |
| 329 | class PeerConnectionObserver { |
| 330 | public: |
| 331 | enum StateType { |
| 332 | kSignalingState, |
| 333 | kIceState, |
| 334 | }; |
| 335 | |
| 336 | virtual void OnError() = 0; |
| 337 | |
| 338 | // Triggered when the SignalingState changed. |
| 339 | virtual void OnSignalingChange( |
| 340 | PeerConnectionInterface::SignalingState new_state) {} |
| 341 | |
| 342 | // Triggered when SignalingState or IceState have changed. |
| 343 | // TODO(bemasc): Remove once callers transition to OnSignalingChange. |
| 344 | virtual void OnStateChange(StateType state_changed) {} |
| 345 | |
| 346 | // Triggered when media is received on a new stream from remote peer. |
| 347 | virtual void OnAddStream(MediaStreamInterface* stream) = 0; |
| 348 | |
| 349 | // Triggered when a remote peer close a stream. |
| 350 | virtual void OnRemoveStream(MediaStreamInterface* stream) = 0; |
| 351 | |
| 352 | // Triggered when a remote peer open a data channel. |
| 353 | // TODO(perkj): Make pure virtual. |
| 354 | virtual void OnDataChannel(DataChannelInterface* data_channel) {} |
| 355 | |
mallinath@webrtc.org | 0d92ef6 | 2014-01-22 02:21:22 +0000 | [diff] [blame] | 356 | // Triggered when renegotiation is needed, for example the ICE has restarted. |
fischman@webrtc.org | d7568a0 | 2014-01-13 22:04:12 +0000 | [diff] [blame] | 357 | virtual void OnRenegotiationNeeded() = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 358 | |
| 359 | // Called any time the IceConnectionState changes |
| 360 | virtual void OnIceConnectionChange( |
| 361 | PeerConnectionInterface::IceConnectionState new_state) {} |
| 362 | |
| 363 | // Called any time the IceGatheringState changes |
| 364 | virtual void OnIceGatheringChange( |
| 365 | PeerConnectionInterface::IceGatheringState new_state) {} |
| 366 | |
| 367 | // New Ice candidate have been found. |
| 368 | virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0; |
| 369 | |
| 370 | // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange. |
| 371 | // All Ice candidates have been found. |
| 372 | virtual void OnIceComplete() {} |
| 373 | |
| 374 | protected: |
| 375 | // Dtor protected as objects shouldn't be deleted via this interface. |
| 376 | ~PeerConnectionObserver() {} |
| 377 | }; |
| 378 | |
| 379 | // Factory class used for creating cricket::PortAllocator that is used |
| 380 | // for ICE negotiation. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 381 | class PortAllocatorFactoryInterface : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 382 | public: |
| 383 | struct StunConfiguration { |
| 384 | StunConfiguration(const std::string& address, int port) |
| 385 | : server(address, port) {} |
| 386 | // STUN server address and port. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 387 | rtc::SocketAddress server; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 388 | }; |
| 389 | |
| 390 | struct TurnConfiguration { |
| 391 | TurnConfiguration(const std::string& address, |
| 392 | int port, |
| 393 | const std::string& username, |
| 394 | const std::string& password, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 395 | const std::string& transport_type, |
| 396 | bool secure) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 397 | : server(address, port), |
| 398 | username(username), |
| 399 | password(password), |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 400 | transport_type(transport_type), |
| 401 | secure(secure) {} |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 402 | rtc::SocketAddress server; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 403 | std::string username; |
| 404 | std::string password; |
| 405 | std::string transport_type; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 406 | bool secure; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 407 | }; |
| 408 | |
| 409 | virtual cricket::PortAllocator* CreatePortAllocator( |
| 410 | const std::vector<StunConfiguration>& stun_servers, |
| 411 | const std::vector<TurnConfiguration>& turn_configurations) = 0; |
| 412 | |
| 413 | protected: |
| 414 | PortAllocatorFactoryInterface() {} |
| 415 | ~PortAllocatorFactoryInterface() {} |
| 416 | }; |
| 417 | |
| 418 | // Used to receive callbacks of DTLS identity requests. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 419 | class DTLSIdentityRequestObserver : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 420 | public: |
| 421 | virtual void OnFailure(int error) = 0; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 422 | virtual void OnSuccess(const std::string& der_cert, |
| 423 | const std::string& der_private_key) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 424 | protected: |
| 425 | virtual ~DTLSIdentityRequestObserver() {} |
| 426 | }; |
| 427 | |
| 428 | class DTLSIdentityServiceInterface { |
| 429 | public: |
| 430 | // Asynchronously request a DTLS identity, including a self-signed certificate |
| 431 | // and the private key used to sign the certificate, from the identity store |
| 432 | // for the given identity name. |
| 433 | // DTLSIdentityRequestObserver::OnSuccess will be called with the identity if |
| 434 | // the request succeeded; DTLSIdentityRequestObserver::OnFailure will be |
| 435 | // called with an error code if the request failed. |
| 436 | // |
| 437 | // Only one request can be made at a time. If a second request is called |
| 438 | // before the first one completes, RequestIdentity will abort and return |
| 439 | // false. |
| 440 | // |
| 441 | // |identity_name| is an internal name selected by the client to identify an |
| 442 | // identity within an origin. E.g. an web site may cache the certificates used |
| 443 | // to communicate with differnent peers under different identity names. |
| 444 | // |
| 445 | // |common_name| is the common name used to generate the certificate. If the |
| 446 | // certificate already exists in the store, |common_name| is ignored. |
| 447 | // |
| 448 | // |observer| is the object to receive success or failure callbacks. |
| 449 | // |
| 450 | // Returns true if either OnFailure or OnSuccess will be called. |
| 451 | virtual bool RequestIdentity( |
| 452 | const std::string& identity_name, |
| 453 | const std::string& common_name, |
| 454 | DTLSIdentityRequestObserver* observer) = 0; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 455 | |
| 456 | virtual ~DTLSIdentityServiceInterface() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 457 | }; |
| 458 | |
| 459 | // PeerConnectionFactoryInterface is the factory interface use for creating |
| 460 | // PeerConnection, MediaStream and media tracks. |
| 461 | // PeerConnectionFactoryInterface will create required libjingle threads, |
| 462 | // socket and network manager factory classes for networking. |
| 463 | // If an application decides to provide its own threads and network |
| 464 | // implementation of these classes it should use the alternate |
| 465 | // CreatePeerConnectionFactory method which accepts threads as input and use the |
| 466 | // CreatePeerConnection version that takes a PortAllocatorFactoryInterface as |
| 467 | // argument. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 468 | class PeerConnectionFactoryInterface : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 469 | public: |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 470 | class Options { |
| 471 | public: |
| 472 | Options() : |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 473 | disable_encryption(false), |
| 474 | disable_sctp_data_channels(false) { |
| 475 | } |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 476 | bool disable_encryption; |
| 477 | bool disable_sctp_data_channels; |
| 478 | }; |
| 479 | |
| 480 | virtual void SetOptions(const Options& options) = 0; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 481 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 482 | virtual rtc::scoped_refptr<PeerConnectionInterface> |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 483 | CreatePeerConnection( |
| 484 | const PeerConnectionInterface::RTCConfiguration& configuration, |
| 485 | const MediaConstraintsInterface* constraints, |
| 486 | PortAllocatorFactoryInterface* allocator_factory, |
| 487 | DTLSIdentityServiceInterface* dtls_identity_service, |
| 488 | PeerConnectionObserver* observer) = 0; |
| 489 | |
| 490 | // TODO(mallinath) : Remove below versions after clients are updated |
| 491 | // to above method. |
| 492 | // In latest W3C WebRTC draft, PC constructor will take RTCConfiguration, |
| 493 | // and not IceServers. RTCConfiguration is made up of ice servers and |
| 494 | // ice transport type. |
| 495 | // http://dev.w3.org/2011/webrtc/editor/webrtc.html |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 496 | inline rtc::scoped_refptr<PeerConnectionInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 497 | CreatePeerConnection( |
| 498 | const PeerConnectionInterface::IceServers& configuration, |
| 499 | const MediaConstraintsInterface* constraints, |
| 500 | PortAllocatorFactoryInterface* allocator_factory, |
| 501 | DTLSIdentityServiceInterface* dtls_identity_service, |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 502 | PeerConnectionObserver* observer) { |
| 503 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 504 | rtc_config.servers = configuration; |
| 505 | return CreatePeerConnection(rtc_config, constraints, allocator_factory, |
| 506 | dtls_identity_service, observer); |
| 507 | } |
| 508 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 509 | virtual rtc::scoped_refptr<MediaStreamInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 510 | CreateLocalMediaStream(const std::string& label) = 0; |
| 511 | |
| 512 | // Creates a AudioSourceInterface. |
| 513 | // |constraints| decides audio processing settings but can be NULL. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 514 | virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 515 | const MediaConstraintsInterface* constraints) = 0; |
| 516 | |
| 517 | // Creates a VideoSourceInterface. The new source take ownership of |
| 518 | // |capturer|. |constraints| decides video resolution and frame rate but can |
| 519 | // be NULL. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 520 | virtual rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 521 | cricket::VideoCapturer* capturer, |
| 522 | const MediaConstraintsInterface* constraints) = 0; |
| 523 | |
| 524 | // Creates a new local VideoTrack. The same |source| can be used in several |
| 525 | // tracks. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 526 | virtual rtc::scoped_refptr<VideoTrackInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 527 | CreateVideoTrack(const std::string& label, |
| 528 | VideoSourceInterface* source) = 0; |
| 529 | |
| 530 | // Creates an new AudioTrack. At the moment |source| can be NULL. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 531 | virtual rtc::scoped_refptr<AudioTrackInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 532 | CreateAudioTrack(const std::string& label, |
| 533 | AudioSourceInterface* source) = 0; |
| 534 | |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 535 | // Starts AEC dump using existing file. Takes ownership of |file| and passes |
| 536 | // it on to VoiceEngine (via other objects) immediately, which will take |
wu@webrtc.org | a8910d2 | 2014-01-23 22:12:45 +0000 | [diff] [blame] | 537 | // the ownerhip. If the operation fails, the file will be closed. |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 538 | // TODO(grunell): Remove when Chromium has started to use AEC in each source. |
wu@webrtc.org | a8910d2 | 2014-01-23 22:12:45 +0000 | [diff] [blame] | 539 | // http://crbug.com/264611. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 540 | virtual bool StartAecDump(rtc::PlatformFile file) = 0; |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 541 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 542 | protected: |
| 543 | // Dtor and ctor protected as objects shouldn't be created or deleted via |
| 544 | // this interface. |
| 545 | PeerConnectionFactoryInterface() {} |
| 546 | ~PeerConnectionFactoryInterface() {} // NOLINT |
| 547 | }; |
| 548 | |
| 549 | // Create a new instance of PeerConnectionFactoryInterface. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 550 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 551 | CreatePeerConnectionFactory(); |
| 552 | |
| 553 | // Create a new instance of PeerConnectionFactoryInterface. |
| 554 | // Ownership of |factory|, |default_adm|, and optionally |encoder_factory| and |
| 555 | // |decoder_factory| transferred to the returned factory. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 556 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 557 | CreatePeerConnectionFactory( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 558 | rtc::Thread* worker_thread, |
| 559 | rtc::Thread* signaling_thread, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 560 | AudioDeviceModule* default_adm, |
| 561 | cricket::WebRtcVideoEncoderFactory* encoder_factory, |
| 562 | cricket::WebRtcVideoDecoderFactory* decoder_factory); |
| 563 | |
| 564 | } // namespace webrtc |
| 565 | |
| 566 | #endif // TALK_APP_WEBRTC_PEERCONNECTIONINTERFACE_H_ |