| OLD | NEW |
| (Empty) |
| 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 <utility> | |
| 73 #include <vector> | |
| 74 | |
| 75 #include "talk/app/webrtc/datachannelinterface.h" | |
| 76 #include "talk/app/webrtc/dtlsidentitystore.h" | |
| 77 #include "talk/app/webrtc/dtlsidentitystore.h" | |
| 78 #include "talk/app/webrtc/dtmfsenderinterface.h" | |
| 79 #include "talk/app/webrtc/jsep.h" | |
| 80 #include "talk/app/webrtc/mediastreaminterface.h" | |
| 81 #include "talk/app/webrtc/rtpreceiverinterface.h" | |
| 82 #include "talk/app/webrtc/rtpsenderinterface.h" | |
| 83 #include "talk/app/webrtc/statstypes.h" | |
| 84 #include "talk/app/webrtc/umametrics.h" | |
| 85 #include "webrtc/base/fileutils.h" | |
| 86 #include "webrtc/base/network.h" | |
| 87 #include "webrtc/base/rtccertificate.h" | |
| 88 #include "webrtc/base/socketaddress.h" | |
| 89 #include "webrtc/base/sslstreamadapter.h" | |
| 90 #include "webrtc/p2p/base/portallocator.h" | |
| 91 | |
| 92 namespace rtc { | |
| 93 class SSLIdentity; | |
| 94 class Thread; | |
| 95 } | |
| 96 | |
| 97 namespace cricket { | |
| 98 class WebRtcVideoDecoderFactory; | |
| 99 class WebRtcVideoEncoderFactory; | |
| 100 } | |
| 101 | |
| 102 namespace webrtc { | |
| 103 class AudioDeviceModule; | |
| 104 class MediaConstraintsInterface; | |
| 105 | |
| 106 // MediaStream container interface. | |
| 107 class StreamCollectionInterface : public rtc::RefCountInterface { | |
| 108 public: | |
| 109 // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find. | |
| 110 virtual size_t count() = 0; | |
| 111 virtual MediaStreamInterface* at(size_t index) = 0; | |
| 112 virtual MediaStreamInterface* find(const std::string& label) = 0; | |
| 113 virtual MediaStreamTrackInterface* FindAudioTrack( | |
| 114 const std::string& id) = 0; | |
| 115 virtual MediaStreamTrackInterface* FindVideoTrack( | |
| 116 const std::string& id) = 0; | |
| 117 | |
| 118 protected: | |
| 119 // Dtor protected as objects shouldn't be deleted via this interface. | |
| 120 ~StreamCollectionInterface() {} | |
| 121 }; | |
| 122 | |
| 123 class StatsObserver : public rtc::RefCountInterface { | |
| 124 public: | |
| 125 virtual void OnComplete(const StatsReports& reports) = 0; | |
| 126 | |
| 127 protected: | |
| 128 virtual ~StatsObserver() {} | |
| 129 }; | |
| 130 | |
| 131 class MetricsObserverInterface : public rtc::RefCountInterface { | |
| 132 public: | |
| 133 | |
| 134 // |type| is the type of the enum counter to be incremented. |counter| | |
| 135 // is the particular counter in that type. |counter_max| is the next sequence | |
| 136 // number after the highest counter. | |
| 137 virtual void IncrementEnumCounter(PeerConnectionEnumCounterType type, | |
| 138 int counter, | |
| 139 int counter_max) {} | |
| 140 | |
| 141 // This is used to handle sparse counters like SSL cipher suites. | |
| 142 // TODO(guoweis): Remove the implementation once the dependency's interface | |
| 143 // definition is updated. | |
| 144 virtual void IncrementSparseEnumCounter(PeerConnectionEnumCounterType type, | |
| 145 int counter) { | |
| 146 IncrementEnumCounter(type, counter, 0 /* Ignored */); | |
| 147 } | |
| 148 | |
| 149 virtual void AddHistogramSample(PeerConnectionMetricsName type, | |
| 150 int value) = 0; | |
| 151 | |
| 152 protected: | |
| 153 virtual ~MetricsObserverInterface() {} | |
| 154 }; | |
| 155 | |
| 156 typedef MetricsObserverInterface UMAObserver; | |
| 157 | |
| 158 class PeerConnectionInterface : public rtc::RefCountInterface { | |
| 159 public: | |
| 160 // See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions . | |
| 161 enum SignalingState { | |
| 162 kStable, | |
| 163 kHaveLocalOffer, | |
| 164 kHaveLocalPrAnswer, | |
| 165 kHaveRemoteOffer, | |
| 166 kHaveRemotePrAnswer, | |
| 167 kClosed, | |
| 168 }; | |
| 169 | |
| 170 // TODO(bemasc): Remove IceState when callers are changed to | |
| 171 // IceConnection/GatheringState. | |
| 172 enum IceState { | |
| 173 kIceNew, | |
| 174 kIceGathering, | |
| 175 kIceWaiting, | |
| 176 kIceChecking, | |
| 177 kIceConnected, | |
| 178 kIceCompleted, | |
| 179 kIceFailed, | |
| 180 kIceClosed, | |
| 181 }; | |
| 182 | |
| 183 enum IceGatheringState { | |
| 184 kIceGatheringNew, | |
| 185 kIceGatheringGathering, | |
| 186 kIceGatheringComplete | |
| 187 }; | |
| 188 | |
| 189 enum IceConnectionState { | |
| 190 kIceConnectionNew, | |
| 191 kIceConnectionChecking, | |
| 192 kIceConnectionConnected, | |
| 193 kIceConnectionCompleted, | |
| 194 kIceConnectionFailed, | |
| 195 kIceConnectionDisconnected, | |
| 196 kIceConnectionClosed, | |
| 197 kIceConnectionMax, | |
| 198 }; | |
| 199 | |
| 200 struct IceServer { | |
| 201 // TODO(jbauch): Remove uri when all code using it has switched to urls. | |
| 202 std::string uri; | |
| 203 std::vector<std::string> urls; | |
| 204 std::string username; | |
| 205 std::string password; | |
| 206 }; | |
| 207 typedef std::vector<IceServer> IceServers; | |
| 208 | |
| 209 enum IceTransportsType { | |
| 210 // TODO(pthatcher): Rename these kTransporTypeXXX, but update | |
| 211 // Chromium at the same time. | |
| 212 kNone, | |
| 213 kRelay, | |
| 214 kNoHost, | |
| 215 kAll | |
| 216 }; | |
| 217 | |
| 218 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-08#section-4.1.1 | |
| 219 enum BundlePolicy { | |
| 220 kBundlePolicyBalanced, | |
| 221 kBundlePolicyMaxBundle, | |
| 222 kBundlePolicyMaxCompat | |
| 223 }; | |
| 224 | |
| 225 // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-09#section-4.1.1 | |
| 226 enum RtcpMuxPolicy { | |
| 227 kRtcpMuxPolicyNegotiate, | |
| 228 kRtcpMuxPolicyRequire, | |
| 229 }; | |
| 230 | |
| 231 enum TcpCandidatePolicy { | |
| 232 kTcpCandidatePolicyEnabled, | |
| 233 kTcpCandidatePolicyDisabled | |
| 234 }; | |
| 235 | |
| 236 enum ContinualGatheringPolicy { | |
| 237 GATHER_ONCE, | |
| 238 GATHER_CONTINUALLY | |
| 239 }; | |
| 240 | |
| 241 // TODO(hbos): Change into class with private data and public getters. | |
| 242 struct RTCConfiguration { | |
| 243 static const int kUndefined = -1; | |
| 244 // Default maximum number of packets in the audio jitter buffer. | |
| 245 static const int kAudioJitterBufferMaxPackets = 50; | |
| 246 // TODO(pthatcher): Rename this ice_transport_type, but update | |
| 247 // Chromium at the same time. | |
| 248 IceTransportsType type; | |
| 249 // TODO(pthatcher): Rename this ice_servers, but update Chromium | |
| 250 // at the same time. | |
| 251 IceServers servers; | |
| 252 BundlePolicy bundle_policy; | |
| 253 RtcpMuxPolicy rtcp_mux_policy; | |
| 254 TcpCandidatePolicy tcp_candidate_policy; | |
| 255 int audio_jitter_buffer_max_packets; | |
| 256 bool audio_jitter_buffer_fast_accelerate; | |
| 257 int ice_connection_receiving_timeout; // ms | |
| 258 int ice_backup_candidate_pair_ping_interval; // ms | |
| 259 ContinualGatheringPolicy continual_gathering_policy; | |
| 260 std::vector<rtc::scoped_refptr<rtc::RTCCertificate>> certificates; | |
| 261 bool disable_prerenderer_smoothing; | |
| 262 RTCConfiguration() | |
| 263 : type(kAll), | |
| 264 bundle_policy(kBundlePolicyBalanced), | |
| 265 rtcp_mux_policy(kRtcpMuxPolicyNegotiate), | |
| 266 tcp_candidate_policy(kTcpCandidatePolicyEnabled), | |
| 267 audio_jitter_buffer_max_packets(kAudioJitterBufferMaxPackets), | |
| 268 audio_jitter_buffer_fast_accelerate(false), | |
| 269 ice_connection_receiving_timeout(kUndefined), | |
| 270 ice_backup_candidate_pair_ping_interval(kUndefined), | |
| 271 continual_gathering_policy(GATHER_ONCE), | |
| 272 disable_prerenderer_smoothing(false) {} | |
| 273 }; | |
| 274 | |
| 275 struct RTCOfferAnswerOptions { | |
| 276 static const int kUndefined = -1; | |
| 277 static const int kMaxOfferToReceiveMedia = 1; | |
| 278 | |
| 279 // The default value for constraint offerToReceiveX:true. | |
| 280 static const int kOfferToReceiveMediaTrue = 1; | |
| 281 | |
| 282 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 | |
| 288 RTCOfferAnswerOptions() | |
| 289 : offer_to_receive_video(kUndefined), | |
| 290 offer_to_receive_audio(kUndefined), | |
| 291 voice_activity_detection(true), | |
| 292 ice_restart(false), | |
| 293 use_rtp_mux(true) {} | |
| 294 | |
| 295 RTCOfferAnswerOptions(int offer_to_receive_video, | |
| 296 int offer_to_receive_audio, | |
| 297 bool voice_activity_detection, | |
| 298 bool ice_restart, | |
| 299 bool use_rtp_mux) | |
| 300 : offer_to_receive_video(offer_to_receive_video), | |
| 301 offer_to_receive_audio(offer_to_receive_audio), | |
| 302 voice_activity_detection(voice_activity_detection), | |
| 303 ice_restart(ice_restart), | |
| 304 use_rtp_mux(use_rtp_mux) {} | |
| 305 }; | |
| 306 | |
| 307 // Used by GetStats to decide which stats to include in the stats reports. | |
| 308 // |kStatsOutputLevelStandard| includes the standard stats for Javascript API; | |
| 309 // |kStatsOutputLevelDebug| includes both the standard stats and additional | |
| 310 // stats for debugging purposes. | |
| 311 enum StatsOutputLevel { | |
| 312 kStatsOutputLevelStandard, | |
| 313 kStatsOutputLevelDebug, | |
| 314 }; | |
| 315 | |
| 316 // Accessor methods to active local streams. | |
| 317 virtual rtc::scoped_refptr<StreamCollectionInterface> | |
| 318 local_streams() = 0; | |
| 319 | |
| 320 // Accessor methods to remote streams. | |
| 321 virtual rtc::scoped_refptr<StreamCollectionInterface> | |
| 322 remote_streams() = 0; | |
| 323 | |
| 324 // Add a new MediaStream to be sent on this PeerConnection. | |
| 325 // Note that a SessionDescription negotiation is needed before the | |
| 326 // remote peer can receive the stream. | |
| 327 virtual bool AddStream(MediaStreamInterface* stream) = 0; | |
| 328 | |
| 329 // Remove a MediaStream from this PeerConnection. | |
| 330 // Note that a SessionDescription negotiation is need before the | |
| 331 // remote peer is notified. | |
| 332 virtual void RemoveStream(MediaStreamInterface* stream) = 0; | |
| 333 | |
| 334 // TODO(deadbeef): Make the following two methods pure virtual once | |
| 335 // implemented by all subclasses of PeerConnectionInterface. | |
| 336 // Add a new MediaStreamTrack to be sent on this PeerConnection. | |
| 337 // |streams| indicates which stream labels the track should be associated | |
| 338 // with. | |
| 339 virtual rtc::scoped_refptr<RtpSenderInterface> AddTrack( | |
| 340 MediaStreamTrackInterface* track, | |
| 341 std::vector<MediaStreamInterface*> streams) { | |
| 342 return nullptr; | |
| 343 } | |
| 344 | |
| 345 // Remove an RtpSender from this PeerConnection. | |
| 346 // Returns true on success. | |
| 347 virtual bool RemoveTrack(RtpSenderInterface* sender) { | |
| 348 return false; | |
| 349 } | |
| 350 | |
| 351 // Returns pointer to the created DtmfSender on success. | |
| 352 // Otherwise returns NULL. | |
| 353 virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender( | |
| 354 AudioTrackInterface* track) = 0; | |
| 355 | |
| 356 // TODO(deadbeef): Make these pure virtual once all subclasses implement them. | |
| 357 // |kind| must be "audio" or "video". | |
| 358 // |stream_id| is used to populate the msid attribute; if empty, one will | |
| 359 // be generated automatically. | |
| 360 virtual rtc::scoped_refptr<RtpSenderInterface> CreateSender( | |
| 361 const std::string& kind, | |
| 362 const std::string& stream_id) { | |
| 363 return rtc::scoped_refptr<RtpSenderInterface>(); | |
| 364 } | |
| 365 | |
| 366 virtual std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders() | |
| 367 const { | |
| 368 return std::vector<rtc::scoped_refptr<RtpSenderInterface>>(); | |
| 369 } | |
| 370 | |
| 371 virtual std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers() | |
| 372 const { | |
| 373 return std::vector<rtc::scoped_refptr<RtpReceiverInterface>>(); | |
| 374 } | |
| 375 | |
| 376 virtual bool GetStats(StatsObserver* observer, | |
| 377 MediaStreamTrackInterface* track, | |
| 378 StatsOutputLevel level) = 0; | |
| 379 | |
| 380 virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( | |
| 381 const std::string& label, | |
| 382 const DataChannelInit* config) = 0; | |
| 383 | |
| 384 virtual const SessionDescriptionInterface* local_description() const = 0; | |
| 385 virtual const SessionDescriptionInterface* remote_description() const = 0; | |
| 386 | |
| 387 // Create a new offer. | |
| 388 // The CreateSessionDescriptionObserver callback will be called when done. | |
| 389 virtual void CreateOffer(CreateSessionDescriptionObserver* observer, | |
| 390 const MediaConstraintsInterface* constraints) {} | |
| 391 | |
| 392 // TODO(jiayl): remove the default impl and the old interface when chromium | |
| 393 // code is updated. | |
| 394 virtual void CreateOffer(CreateSessionDescriptionObserver* observer, | |
| 395 const RTCOfferAnswerOptions& options) {} | |
| 396 | |
| 397 // Create an answer to an offer. | |
| 398 // The CreateSessionDescriptionObserver callback will be called when done. | |
| 399 virtual void CreateAnswer(CreateSessionDescriptionObserver* observer, | |
| 400 const MediaConstraintsInterface* constraints) = 0; | |
| 401 // Sets the local session description. | |
| 402 // JsepInterface takes the ownership of |desc| even if it fails. | |
| 403 // The |observer| callback will be called when done. | |
| 404 virtual void SetLocalDescription(SetSessionDescriptionObserver* observer, | |
| 405 SessionDescriptionInterface* desc) = 0; | |
| 406 // Sets the remote session description. | |
| 407 // JsepInterface takes the ownership of |desc| even if it fails. | |
| 408 // The |observer| callback will be called when done. | |
| 409 virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer, | |
| 410 SessionDescriptionInterface* desc) = 0; | |
| 411 // Restarts or updates the ICE Agent process of gathering local candidates | |
| 412 // and pinging remote candidates. | |
| 413 // TODO(deadbeef): Remove once Chrome is moved over to SetConfiguration. | |
| 414 virtual bool UpdateIce(const IceServers& configuration, | |
| 415 const MediaConstraintsInterface* constraints) { | |
| 416 return false; | |
| 417 } | |
| 418 // Sets the PeerConnection's global configuration to |config|. | |
| 419 // Any changes to STUN/TURN servers or ICE candidate policy will affect the | |
| 420 // next gathering phase, and cause the next call to createOffer to generate | |
| 421 // new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies | |
| 422 // cannot be changed with this method. | |
| 423 // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of | |
| 424 // PeerConnectionInterface implement it. | |
| 425 virtual bool SetConfiguration( | |
| 426 const PeerConnectionInterface::RTCConfiguration& config) { | |
| 427 return false; | |
| 428 } | |
| 429 // Provides a remote candidate to the ICE Agent. | |
| 430 // A copy of the |candidate| will be created and added to the remote | |
| 431 // description. So the caller of this method still has the ownership of the | |
| 432 // |candidate|. | |
| 433 // TODO(ronghuawu): Consider to change this so that the AddIceCandidate will | |
| 434 // take the ownership of the |candidate|. | |
| 435 virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0; | |
| 436 | |
| 437 virtual void RegisterUMAObserver(UMAObserver* observer) = 0; | |
| 438 | |
| 439 // Returns the current SignalingState. | |
| 440 virtual SignalingState signaling_state() = 0; | |
| 441 | |
| 442 // TODO(bemasc): Remove ice_state when callers are changed to | |
| 443 // IceConnection/GatheringState. | |
| 444 // Returns the current IceState. | |
| 445 virtual IceState ice_state() = 0; | |
| 446 virtual IceConnectionState ice_connection_state() = 0; | |
| 447 virtual IceGatheringState ice_gathering_state() = 0; | |
| 448 | |
| 449 // Terminates all media and closes the transport. | |
| 450 virtual void Close() = 0; | |
| 451 | |
| 452 protected: | |
| 453 // Dtor protected as objects shouldn't be deleted via this interface. | |
| 454 ~PeerConnectionInterface() {} | |
| 455 }; | |
| 456 | |
| 457 // PeerConnection callback interface. Application should implement these | |
| 458 // methods. | |
| 459 class PeerConnectionObserver { | |
| 460 public: | |
| 461 enum StateType { | |
| 462 kSignalingState, | |
| 463 kIceState, | |
| 464 }; | |
| 465 | |
| 466 // Triggered when the SignalingState changed. | |
| 467 virtual void OnSignalingChange( | |
| 468 PeerConnectionInterface::SignalingState new_state) = 0; | |
| 469 | |
| 470 // Triggered when media is received on a new stream from remote peer. | |
| 471 virtual void OnAddStream(MediaStreamInterface* stream) = 0; | |
| 472 | |
| 473 // Triggered when a remote peer close a stream. | |
| 474 virtual void OnRemoveStream(MediaStreamInterface* stream) = 0; | |
| 475 | |
| 476 // Triggered when a remote peer open a data channel. | |
| 477 virtual void OnDataChannel(DataChannelInterface* data_channel) = 0; | |
| 478 | |
| 479 // Triggered when renegotiation is needed, for example the ICE has restarted. | |
| 480 virtual void OnRenegotiationNeeded() = 0; | |
| 481 | |
| 482 // Called any time the IceConnectionState changes | |
| 483 virtual void OnIceConnectionChange( | |
| 484 PeerConnectionInterface::IceConnectionState new_state) = 0; | |
| 485 | |
| 486 // Called any time the IceGatheringState changes | |
| 487 virtual void OnIceGatheringChange( | |
| 488 PeerConnectionInterface::IceGatheringState new_state) = 0; | |
| 489 | |
| 490 // New Ice candidate have been found. | |
| 491 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0; | |
| 492 | |
| 493 // Called when the ICE connection receiving status changes. | |
| 494 virtual void OnIceConnectionReceivingChange(bool receiving) {} | |
| 495 | |
| 496 protected: | |
| 497 // Dtor protected as objects shouldn't be deleted via this interface. | |
| 498 ~PeerConnectionObserver() {} | |
| 499 }; | |
| 500 | |
| 501 // PeerConnectionFactoryInterface is the factory interface use for creating | |
| 502 // PeerConnection, MediaStream and media tracks. | |
| 503 // PeerConnectionFactoryInterface will create required libjingle threads, | |
| 504 // socket and network manager factory classes for networking. | |
| 505 // If an application decides to provide its own threads and network | |
| 506 // implementation of these classes it should use the alternate | |
| 507 // CreatePeerConnectionFactory method which accepts threads as input and use the | |
| 508 // CreatePeerConnection version that takes a PortAllocator as an | |
| 509 // argument. | |
| 510 class PeerConnectionFactoryInterface : public rtc::RefCountInterface { | |
| 511 public: | |
| 512 class Options { | |
| 513 public: | |
| 514 Options() | |
| 515 : disable_encryption(false), | |
| 516 disable_sctp_data_channels(false), | |
| 517 disable_network_monitor(false), | |
| 518 network_ignore_mask(rtc::kDefaultNetworkIgnoreMask), | |
| 519 ssl_max_version(rtc::SSL_PROTOCOL_DTLS_12) {} | |
| 520 bool disable_encryption; | |
| 521 bool disable_sctp_data_channels; | |
| 522 bool disable_network_monitor; | |
| 523 | |
| 524 // Sets the network types to ignore. For instance, calling this with | |
| 525 // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and | |
| 526 // loopback interfaces. | |
| 527 int network_ignore_mask; | |
| 528 | |
| 529 // Sets the maximum supported protocol version. The highest version | |
| 530 // supported by both ends will be used for the connection, i.e. if one | |
| 531 // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used. | |
| 532 rtc::SSLProtocolVersion ssl_max_version; | |
| 533 }; | |
| 534 | |
| 535 virtual void SetOptions(const Options& options) = 0; | |
| 536 | |
| 537 virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection( | |
| 538 const PeerConnectionInterface::RTCConfiguration& configuration, | |
| 539 const MediaConstraintsInterface* constraints, | |
| 540 rtc::scoped_ptr<cricket::PortAllocator> allocator, | |
| 541 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | |
| 542 PeerConnectionObserver* observer) = 0; | |
| 543 | |
| 544 virtual rtc::scoped_refptr<MediaStreamInterface> | |
| 545 CreateLocalMediaStream(const std::string& label) = 0; | |
| 546 | |
| 547 // Creates a AudioSourceInterface. | |
| 548 // |constraints| decides audio processing settings but can be NULL. | |
| 549 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource( | |
| 550 const MediaConstraintsInterface* constraints) = 0; | |
| 551 | |
| 552 // Creates a VideoSourceInterface. The new source take ownership of | |
| 553 // |capturer|. |constraints| decides video resolution and frame rate but can | |
| 554 // be NULL. | |
| 555 virtual rtc::scoped_refptr<VideoSourceInterface> CreateVideoSource( | |
| 556 cricket::VideoCapturer* capturer, | |
| 557 const MediaConstraintsInterface* constraints) = 0; | |
| 558 | |
| 559 // Creates a new local VideoTrack. The same |source| can be used in several | |
| 560 // tracks. | |
| 561 virtual rtc::scoped_refptr<VideoTrackInterface> | |
| 562 CreateVideoTrack(const std::string& label, | |
| 563 VideoSourceInterface* source) = 0; | |
| 564 | |
| 565 // Creates an new AudioTrack. At the moment |source| can be NULL. | |
| 566 virtual rtc::scoped_refptr<AudioTrackInterface> | |
| 567 CreateAudioTrack(const std::string& label, | |
| 568 AudioSourceInterface* source) = 0; | |
| 569 | |
| 570 // Starts AEC dump using existing file. Takes ownership of |file| and passes | |
| 571 // it on to VoiceEngine (via other objects) immediately, which will take | |
| 572 // the ownerhip. If the operation fails, the file will be closed. | |
| 573 // A maximum file size in bytes can be specified. When the file size limit is | |
| 574 // reached, logging is stopped automatically. If max_size_bytes is set to a | |
| 575 // value <= 0, no limit will be used, and logging will continue until the | |
| 576 // StopAecDump function is called. | |
| 577 virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) = 0; | |
| 578 | |
| 579 // Stops logging the AEC dump. | |
| 580 virtual void StopAecDump() = 0; | |
| 581 | |
| 582 // Starts RtcEventLog using existing file. Takes ownership of |file| and | |
| 583 // passes it on to VoiceEngine, which will take the ownership. If the | |
| 584 // operation fails the file will be closed. The logging will stop | |
| 585 // automatically after 10 minutes have passed, or when the StopRtcEventLog | |
| 586 // function is called. | |
| 587 // This function as well as the StopRtcEventLog don't really belong on this | |
| 588 // interface, this is a temporary solution until we move the logging object | |
| 589 // from inside voice engine to webrtc::Call, which will happen when the VoE | |
| 590 // restructuring effort is further along. | |
| 591 // TODO(ivoc): Move this into being: | |
| 592 // PeerConnection => MediaController => webrtc::Call. | |
| 593 virtual bool StartRtcEventLog(rtc::PlatformFile file) = 0; | |
| 594 | |
| 595 // Stops logging the RtcEventLog. | |
| 596 virtual void StopRtcEventLog() = 0; | |
| 597 | |
| 598 protected: | |
| 599 // Dtor and ctor protected as objects shouldn't be created or deleted via | |
| 600 // this interface. | |
| 601 PeerConnectionFactoryInterface() {} | |
| 602 ~PeerConnectionFactoryInterface() {} // NOLINT | |
| 603 }; | |
| 604 | |
| 605 // Create a new instance of PeerConnectionFactoryInterface. | |
| 606 rtc::scoped_refptr<PeerConnectionFactoryInterface> | |
| 607 CreatePeerConnectionFactory(); | |
| 608 | |
| 609 // Create a new instance of PeerConnectionFactoryInterface. | |
| 610 // Ownership of |factory|, |default_adm|, and optionally |encoder_factory| and | |
| 611 // |decoder_factory| transferred to the returned factory. | |
| 612 rtc::scoped_refptr<PeerConnectionFactoryInterface> | |
| 613 CreatePeerConnectionFactory( | |
| 614 rtc::Thread* worker_thread, | |
| 615 rtc::Thread* signaling_thread, | |
| 616 AudioDeviceModule* default_adm, | |
| 617 cricket::WebRtcVideoEncoderFactory* encoder_factory, | |
| 618 cricket::WebRtcVideoDecoderFactory* decoder_factory); | |
| 619 | |
| 620 } // namespace webrtc | |
| 621 | |
| 622 #endif // TALK_APP_WEBRTC_PEERCONNECTIONINTERFACE_H_ | |
| OLD | NEW |