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