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