| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #ifndef WEBRTC_API_WEBRTCSESSION_H_ | |
| 12 #define WEBRTC_API_WEBRTCSESSION_H_ | |
| 13 | |
| 14 #include <memory> | |
| 15 #include <set> | |
| 16 #include <string> | |
| 17 #include <vector> | |
| 18 | |
| 19 #include "webrtc/api/datachannel.h" | |
| 20 #include "webrtc/api/dtmfsender.h" | |
| 21 #include "webrtc/api/mediacontroller.h" | |
| 22 #include "webrtc/api/peerconnectioninterface.h" | |
| 23 #include "webrtc/api/statstypes.h" | |
| 24 #include "webrtc/base/constructormagic.h" | |
| 25 #include "webrtc/base/optional.h" | |
| 26 #include "webrtc/base/sigslot.h" | |
| 27 #include "webrtc/base/sslidentity.h" | |
| 28 #include "webrtc/base/thread.h" | |
| 29 #include "webrtc/media/base/mediachannel.h" | |
| 30 #include "webrtc/p2p/base/candidate.h" | |
| 31 #include "webrtc/p2p/base/transportcontroller.h" | |
| 32 #include "webrtc/pc/mediasession.h" | |
| 33 | |
| 34 #ifdef HAVE_QUIC | |
| 35 #include "webrtc/api/quicdatatransport.h" | |
| 36 #endif // HAVE_QUIC | |
| 37 | |
| 38 namespace cricket { | |
| 39 | |
| 40 class ChannelManager; | |
| 41 class RtpDataChannel; | |
| 42 class SctpTransportInternal; | |
| 43 class SctpTransportInternalFactory; | |
| 44 class StatsReport; | |
| 45 class VideoChannel; | |
| 46 class VoiceChannel; | |
| 47 | |
| 48 #ifdef HAVE_QUIC | |
| 49 class QuicTransportChannel; | |
| 50 #endif // HAVE_QUIC | |
| 51 | |
| 52 } // namespace cricket | |
| 53 | |
| 54 namespace webrtc { | |
| 55 | |
| 56 class IceRestartAnswerLatch; | |
| 57 class JsepIceCandidate; | |
| 58 class MediaStreamSignaling; | |
| 59 class WebRtcSessionDescriptionFactory; | |
| 60 | |
| 61 extern const char kBundleWithoutRtcpMux[]; | |
| 62 extern const char kCreateChannelFailed[]; | |
| 63 extern const char kInvalidCandidates[]; | |
| 64 extern const char kInvalidSdp[]; | |
| 65 extern const char kMlineMismatch[]; | |
| 66 extern const char kPushDownTDFailed[]; | |
| 67 extern const char kSdpWithoutDtlsFingerprint[]; | |
| 68 extern const char kSdpWithoutSdesCrypto[]; | |
| 69 extern const char kSdpWithoutIceUfragPwd[]; | |
| 70 extern const char kSdpWithoutSdesAndDtlsDisabled[]; | |
| 71 extern const char kSessionError[]; | |
| 72 extern const char kSessionErrorDesc[]; | |
| 73 extern const char kDtlsSrtpSetupFailureRtp[]; | |
| 74 extern const char kDtlsSrtpSetupFailureRtcp[]; | |
| 75 extern const char kEnableBundleFailed[]; | |
| 76 | |
| 77 // Maximum number of received video streams that will be processed by webrtc | |
| 78 // even if they are not signalled beforehand. | |
| 79 extern const int kMaxUnsignalledRecvStreams; | |
| 80 | |
| 81 // ICE state callback interface. | |
| 82 class IceObserver { | |
| 83 public: | |
| 84 IceObserver() {} | |
| 85 // Called any time the IceConnectionState changes | |
| 86 // TODO(honghaiz): Change the name to OnIceConnectionStateChange so as to | |
| 87 // conform to the w3c standard. | |
| 88 virtual void OnIceConnectionChange( | |
| 89 PeerConnectionInterface::IceConnectionState new_state) {} | |
| 90 // Called any time the IceGatheringState changes | |
| 91 virtual void OnIceGatheringChange( | |
| 92 PeerConnectionInterface::IceGatheringState new_state) {} | |
| 93 // New Ice candidate have been found. | |
| 94 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0; | |
| 95 | |
| 96 // Some local ICE candidates have been removed. | |
| 97 virtual void OnIceCandidatesRemoved( | |
| 98 const std::vector<cricket::Candidate>& candidates) = 0; | |
| 99 | |
| 100 // Called whenever the state changes between receiving and not receiving. | |
| 101 virtual void OnIceConnectionReceivingChange(bool receiving) {} | |
| 102 | |
| 103 protected: | |
| 104 ~IceObserver() {} | |
| 105 | |
| 106 private: | |
| 107 RTC_DISALLOW_COPY_AND_ASSIGN(IceObserver); | |
| 108 }; | |
| 109 | |
| 110 // Statistics for all the transports of the session. | |
| 111 typedef std::map<std::string, cricket::TransportStats> TransportStatsMap; | |
| 112 typedef std::map<std::string, std::string> ProxyTransportMap; | |
| 113 | |
| 114 // TODO(pthatcher): Think of a better name for this. We already have | |
| 115 // a TransportStats in transport.h. Perhaps TransportsStats? | |
| 116 struct SessionStats { | |
| 117 ProxyTransportMap proxy_to_transport; | |
| 118 TransportStatsMap transport_stats; | |
| 119 }; | |
| 120 | |
| 121 struct ChannelNamePair { | |
| 122 ChannelNamePair( | |
| 123 const std::string& content_name, const std::string& transport_name) | |
| 124 : content_name(content_name), transport_name(transport_name) {} | |
| 125 std::string content_name; | |
| 126 std::string transport_name; | |
| 127 }; | |
| 128 | |
| 129 struct ChannelNamePairs { | |
| 130 rtc::Optional<ChannelNamePair> voice; | |
| 131 rtc::Optional<ChannelNamePair> video; | |
| 132 rtc::Optional<ChannelNamePair> data; | |
| 133 }; | |
| 134 | |
| 135 // A WebRtcSession manages general session state. This includes negotiation | |
| 136 // of both the application-level and network-level protocols: the former | |
| 137 // defines what will be sent and the latter defines how it will be sent. Each | |
| 138 // network-level protocol is represented by a Transport object. Each Transport | |
| 139 // participates in the network-level negotiation. The individual streams of | |
| 140 // packets are represented by TransportChannels. The application-level protocol | |
| 141 // is represented by SessionDecription objects. | |
| 142 class WebRtcSession : | |
| 143 | |
| 144 public DtmfProviderInterface, | |
| 145 public DataChannelProviderInterface, | |
| 146 public sigslot::has_slots<> { | |
| 147 public: | |
| 148 enum State { | |
| 149 STATE_INIT = 0, | |
| 150 STATE_SENTOFFER, // Sent offer, waiting for answer. | |
| 151 STATE_RECEIVEDOFFER, // Received an offer. Need to send answer. | |
| 152 STATE_SENTPRANSWER, // Sent provisional answer. Need to send answer. | |
| 153 STATE_RECEIVEDPRANSWER, // Received provisional answer, waiting for answer. | |
| 154 STATE_INPROGRESS, // Offer/answer exchange completed. | |
| 155 STATE_CLOSED, // Close() was called. | |
| 156 }; | |
| 157 | |
| 158 enum Error { | |
| 159 ERROR_NONE = 0, // no error | |
| 160 ERROR_CONTENT = 1, // channel errors in SetLocalContent/SetRemoteContent | |
| 161 ERROR_TRANSPORT = 2, // transport error of some kind | |
| 162 }; | |
| 163 | |
| 164 // |sctp_factory| may be null, in which case SCTP is treated as unsupported. | |
| 165 WebRtcSession( | |
| 166 webrtc::MediaControllerInterface* media_controller, | |
| 167 rtc::Thread* network_thread, | |
| 168 rtc::Thread* worker_thread, | |
| 169 rtc::Thread* signaling_thread, | |
| 170 cricket::PortAllocator* port_allocator, | |
| 171 std::unique_ptr<cricket::TransportController> transport_controller, | |
| 172 std::unique_ptr<cricket::SctpTransportInternalFactory> sctp_factory); | |
| 173 virtual ~WebRtcSession(); | |
| 174 | |
| 175 // These are const to allow them to be called from const methods. | |
| 176 rtc::Thread* network_thread() const { return network_thread_; } | |
| 177 rtc::Thread* worker_thread() const { return worker_thread_; } | |
| 178 rtc::Thread* signaling_thread() const { return signaling_thread_; } | |
| 179 | |
| 180 // The ID of this session. | |
| 181 const std::string& id() const { return sid_; } | |
| 182 | |
| 183 bool Initialize( | |
| 184 const PeerConnectionFactoryInterface::Options& options, | |
| 185 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, | |
| 186 const PeerConnectionInterface::RTCConfiguration& rtc_configuration); | |
| 187 // Deletes the voice, video and data channel and changes the session state | |
| 188 // to STATE_CLOSED. | |
| 189 void Close(); | |
| 190 | |
| 191 // Returns true if we were the initial offerer. | |
| 192 bool initial_offerer() const { return initial_offerer_; } | |
| 193 | |
| 194 // Returns the current state of the session. See the enum above for details. | |
| 195 // Each time the state changes, we will fire this signal. | |
| 196 State state() const { return state_; } | |
| 197 sigslot::signal2<WebRtcSession*, State> SignalState; | |
| 198 | |
| 199 // Returns the last error in the session. See the enum above for details. | |
| 200 Error error() const { return error_; } | |
| 201 const std::string& error_desc() const { return error_desc_; } | |
| 202 | |
| 203 void RegisterIceObserver(IceObserver* observer) { | |
| 204 ice_observer_ = observer; | |
| 205 } | |
| 206 | |
| 207 // Exposed for stats collecting. | |
| 208 virtual cricket::VoiceChannel* voice_channel() { | |
| 209 return voice_channel_.get(); | |
| 210 } | |
| 211 virtual cricket::VideoChannel* video_channel() { | |
| 212 return video_channel_.get(); | |
| 213 } | |
| 214 // Only valid when using deprecated RTP data channels. | |
| 215 virtual cricket::RtpDataChannel* rtp_data_channel() { | |
| 216 return rtp_data_channel_.get(); | |
| 217 } | |
| 218 virtual rtc::Optional<std::string> sctp_content_name() const { | |
| 219 return sctp_content_name_; | |
| 220 } | |
| 221 virtual rtc::Optional<std::string> sctp_transport_name() const { | |
| 222 return sctp_transport_name_; | |
| 223 } | |
| 224 | |
| 225 cricket::BaseChannel* GetChannel(const std::string& content_name); | |
| 226 | |
| 227 cricket::SecurePolicy SdesPolicy() const; | |
| 228 | |
| 229 // Get current SSL role used by SCTP's underlying transport. | |
| 230 bool GetSctpSslRole(rtc::SSLRole* role); | |
| 231 // Get SSL role for an arbitrary m= section (handles bundling correctly). | |
| 232 // TODO(deadbeef): This is only used internally by the session description | |
| 233 // factory, it shouldn't really be public). | |
| 234 bool GetSslRole(const std::string& content_name, rtc::SSLRole* role); | |
| 235 | |
| 236 void CreateOffer( | |
| 237 CreateSessionDescriptionObserver* observer, | |
| 238 const PeerConnectionInterface::RTCOfferAnswerOptions& options, | |
| 239 const cricket::MediaSessionOptions& session_options); | |
| 240 void CreateAnswer(CreateSessionDescriptionObserver* observer, | |
| 241 const cricket::MediaSessionOptions& session_options); | |
| 242 // The ownership of |desc| will be transferred after this call. | |
| 243 bool SetLocalDescription(SessionDescriptionInterface* desc, | |
| 244 std::string* err_desc); | |
| 245 // The ownership of |desc| will be transferred after this call. | |
| 246 bool SetRemoteDescription(SessionDescriptionInterface* desc, | |
| 247 std::string* err_desc); | |
| 248 | |
| 249 bool ProcessIceMessage(const IceCandidateInterface* ice_candidate); | |
| 250 | |
| 251 bool RemoveRemoteIceCandidates( | |
| 252 const std::vector<cricket::Candidate>& candidates); | |
| 253 | |
| 254 cricket::IceConfig ParseIceConfig( | |
| 255 const PeerConnectionInterface::RTCConfiguration& config) const; | |
| 256 | |
| 257 void SetIceConfig(const cricket::IceConfig& ice_config); | |
| 258 | |
| 259 // Start gathering candidates for any new transports, or transports doing an | |
| 260 // ICE restart. | |
| 261 void MaybeStartGathering(); | |
| 262 | |
| 263 const SessionDescriptionInterface* local_description() const { | |
| 264 return pending_local_description_ ? pending_local_description_.get() | |
| 265 : current_local_description_.get(); | |
| 266 } | |
| 267 const SessionDescriptionInterface* remote_description() const { | |
| 268 return pending_remote_description_ ? pending_remote_description_.get() | |
| 269 : current_remote_description_.get(); | |
| 270 } | |
| 271 const SessionDescriptionInterface* current_local_description() const { | |
| 272 return current_local_description_.get(); | |
| 273 } | |
| 274 const SessionDescriptionInterface* current_remote_description() const { | |
| 275 return current_remote_description_.get(); | |
| 276 } | |
| 277 const SessionDescriptionInterface* pending_local_description() const { | |
| 278 return pending_local_description_.get(); | |
| 279 } | |
| 280 const SessionDescriptionInterface* pending_remote_description() const { | |
| 281 return pending_remote_description_.get(); | |
| 282 } | |
| 283 | |
| 284 // Get the id used as a media stream track's "id" field from ssrc. | |
| 285 virtual bool GetLocalTrackIdBySsrc(uint32_t ssrc, std::string* track_id); | |
| 286 virtual bool GetRemoteTrackIdBySsrc(uint32_t ssrc, std::string* track_id); | |
| 287 | |
| 288 // Implements DtmfProviderInterface. | |
| 289 bool CanInsertDtmf(const std::string& track_id) override; | |
| 290 bool InsertDtmf(const std::string& track_id, | |
| 291 int code, int duration) override; | |
| 292 sigslot::signal0<>* GetOnDestroyedSignal() override; | |
| 293 | |
| 294 // Implements DataChannelProviderInterface. | |
| 295 bool SendData(const cricket::SendDataParams& params, | |
| 296 const rtc::CopyOnWriteBuffer& payload, | |
| 297 cricket::SendDataResult* result) override; | |
| 298 bool ConnectDataChannel(DataChannel* webrtc_data_channel) override; | |
| 299 void DisconnectDataChannel(DataChannel* webrtc_data_channel) override; | |
| 300 void AddSctpDataStream(int sid) override; | |
| 301 void RemoveSctpDataStream(int sid) override; | |
| 302 bool ReadyToSendData() const override; | |
| 303 | |
| 304 // Returns stats for all channels of all transports. | |
| 305 // This avoids exposing the internal structures used to track them. | |
| 306 // The parameterless version creates |ChannelNamePairs| from |voice_channel|, | |
| 307 // |video_channel| and |voice_channel| if available - this requires it to be | |
| 308 // called on the signaling thread - and invokes the other |GetStats|. The | |
| 309 // other |GetStats| can be invoked on any thread; if not invoked on the | |
| 310 // network thread a thread hop will happen. | |
| 311 std::unique_ptr<SessionStats> GetStats_s(); | |
| 312 virtual std::unique_ptr<SessionStats> GetStats( | |
| 313 const ChannelNamePairs& channel_name_pairs); | |
| 314 | |
| 315 // virtual so it can be mocked in unit tests | |
| 316 virtual bool GetLocalCertificate( | |
| 317 const std::string& transport_name, | |
| 318 rtc::scoped_refptr<rtc::RTCCertificate>* certificate); | |
| 319 | |
| 320 // Caller owns returned certificate | |
| 321 virtual std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate( | |
| 322 const std::string& transport_name); | |
| 323 | |
| 324 cricket::DataChannelType data_channel_type() const; | |
| 325 | |
| 326 // Returns true if there was an ICE restart initiated by the remote offer. | |
| 327 bool IceRestartPending(const std::string& content_name) const; | |
| 328 | |
| 329 // Set the "needs-ice-restart" flag as described in JSEP. After the flag is | |
| 330 // set, offers should generate new ufrags/passwords until an ICE restart | |
| 331 // occurs. | |
| 332 void SetNeedsIceRestartFlag(); | |
| 333 // Returns true if the ICE restart flag above was set, and no ICE restart has | |
| 334 // occurred yet for this transport (by applying a local description with | |
| 335 // changed ufrag/password). If the transport has been deleted as a result of | |
| 336 // bundling, returns false. | |
| 337 bool NeedsIceRestart(const std::string& content_name) const; | |
| 338 | |
| 339 // Called when an RTCCertificate is generated or retrieved by | |
| 340 // WebRTCSessionDescriptionFactory. Should happen before setLocalDescription. | |
| 341 void OnCertificateReady( | |
| 342 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); | |
| 343 void OnDtlsSrtpSetupFailure(cricket::BaseChannel*, bool rtcp); | |
| 344 | |
| 345 // For unit test. | |
| 346 bool waiting_for_certificate_for_testing() const; | |
| 347 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate_for_testing(); | |
| 348 | |
| 349 void set_metrics_observer( | |
| 350 webrtc::MetricsObserverInterface* metrics_observer) { | |
| 351 metrics_observer_ = metrics_observer; | |
| 352 transport_controller_->SetMetricsObserver(metrics_observer); | |
| 353 } | |
| 354 | |
| 355 // Called when voice_channel_, video_channel_ and | |
| 356 // rtp_data_channel_/sctp_transport_ are created and destroyed. As a result | |
| 357 // of, for example, setting a new description. | |
| 358 sigslot::signal0<> SignalVoiceChannelCreated; | |
| 359 sigslot::signal0<> SignalVoiceChannelDestroyed; | |
| 360 sigslot::signal0<> SignalVideoChannelCreated; | |
| 361 sigslot::signal0<> SignalVideoChannelDestroyed; | |
| 362 sigslot::signal0<> SignalDataChannelCreated; | |
| 363 sigslot::signal0<> SignalDataChannelDestroyed; | |
| 364 // Called when the whole session is destroyed. | |
| 365 sigslot::signal0<> SignalDestroyed; | |
| 366 | |
| 367 // Called when a valid data channel OPEN message is received. | |
| 368 // std::string represents the data channel label. | |
| 369 sigslot::signal2<const std::string&, const InternalDataChannelInit&> | |
| 370 SignalDataChannelOpenMessage; | |
| 371 #ifdef HAVE_QUIC | |
| 372 QuicDataTransport* quic_data_transport() { | |
| 373 return quic_data_transport_.get(); | |
| 374 } | |
| 375 #endif // HAVE_QUIC | |
| 376 | |
| 377 private: | |
| 378 // Indicates the type of SessionDescription in a call to SetLocalDescription | |
| 379 // and SetRemoteDescription. | |
| 380 enum Action { | |
| 381 kOffer, | |
| 382 kPrAnswer, | |
| 383 kAnswer, | |
| 384 }; | |
| 385 | |
| 386 // Non-const versions of local_description()/remote_description(), for use | |
| 387 // internally. | |
| 388 SessionDescriptionInterface* mutable_local_description() { | |
| 389 return pending_local_description_ ? pending_local_description_.get() | |
| 390 : current_local_description_.get(); | |
| 391 } | |
| 392 SessionDescriptionInterface* mutable_remote_description() { | |
| 393 return pending_remote_description_ ? pending_remote_description_.get() | |
| 394 : current_remote_description_.get(); | |
| 395 } | |
| 396 | |
| 397 // Log session state. | |
| 398 void LogState(State old_state, State new_state); | |
| 399 | |
| 400 // Updates the state, signaling if necessary. | |
| 401 virtual void SetState(State state); | |
| 402 | |
| 403 // Updates the error state, signaling if necessary. | |
| 404 // TODO(ronghuawu): remove the SetError method that doesn't take |error_desc|. | |
| 405 virtual void SetError(Error error, const std::string& error_desc); | |
| 406 | |
| 407 bool UpdateSessionState(Action action, cricket::ContentSource source, | |
| 408 std::string* err_desc); | |
| 409 static Action GetAction(const std::string& type); | |
| 410 // Push the media parts of the local or remote session description | |
| 411 // down to all of the channels. | |
| 412 bool PushdownMediaDescription(cricket::ContentAction action, | |
| 413 cricket::ContentSource source, | |
| 414 std::string* error_desc); | |
| 415 bool PushdownSctpParameters_n(cricket::ContentSource source); | |
| 416 | |
| 417 bool PushdownTransportDescription(cricket::ContentSource source, | |
| 418 cricket::ContentAction action, | |
| 419 std::string* error_desc); | |
| 420 | |
| 421 // Helper methods to push local and remote transport descriptions. | |
| 422 bool PushdownLocalTransportDescription( | |
| 423 const cricket::SessionDescription* sdesc, | |
| 424 cricket::ContentAction action, | |
| 425 std::string* error_desc); | |
| 426 bool PushdownRemoteTransportDescription( | |
| 427 const cricket::SessionDescription* sdesc, | |
| 428 cricket::ContentAction action, | |
| 429 std::string* error_desc); | |
| 430 | |
| 431 // Returns true and the TransportInfo of the given |content_name| | |
| 432 // from |description|. Returns false if it's not available. | |
| 433 static bool GetTransportDescription( | |
| 434 const cricket::SessionDescription* description, | |
| 435 const std::string& content_name, | |
| 436 cricket::TransportDescription* info); | |
| 437 | |
| 438 // Returns the name of the transport channel when BUNDLE is enabled, or | |
| 439 // nullptr if the channel is not part of any bundle. | |
| 440 const std::string* GetBundleTransportName( | |
| 441 const cricket::ContentInfo* content, | |
| 442 const cricket::ContentGroup* bundle); | |
| 443 | |
| 444 // Cause all the BaseChannels in the bundle group to have the same | |
| 445 // transport channel. | |
| 446 bool EnableBundle(const cricket::ContentGroup& bundle); | |
| 447 | |
| 448 // Enables media channels to allow sending of media. | |
| 449 void EnableChannels(); | |
| 450 // Returns the media index for a local ice candidate given the content name. | |
| 451 // Returns false if the local session description does not have a media | |
| 452 // content called |content_name|. | |
| 453 bool GetLocalCandidateMediaIndex(const std::string& content_name, | |
| 454 int* sdp_mline_index); | |
| 455 // Uses all remote candidates in |remote_desc| in this session. | |
| 456 bool UseCandidatesInSessionDescription( | |
| 457 const SessionDescriptionInterface* remote_desc); | |
| 458 // Uses |candidate| in this session. | |
| 459 bool UseCandidate(const IceCandidateInterface* candidate); | |
| 460 // Deletes the corresponding channel of contents that don't exist in |desc|. | |
| 461 // |desc| can be null. This means that all channels are deleted. | |
| 462 void RemoveUnusedChannels(const cricket::SessionDescription* desc); | |
| 463 | |
| 464 // Allocates media channels based on the |desc|. If |desc| doesn't have | |
| 465 // the BUNDLE option, this method will disable BUNDLE in PortAllocator. | |
| 466 // This method will also delete any existing media channels before creating. | |
| 467 bool CreateChannels(const cricket::SessionDescription* desc); | |
| 468 | |
| 469 // Helper methods to create media channels. | |
| 470 bool CreateVoiceChannel(const cricket::ContentInfo* content, | |
| 471 const std::string* bundle_transport); | |
| 472 bool CreateVideoChannel(const cricket::ContentInfo* content, | |
| 473 const std::string* bundle_transport); | |
| 474 bool CreateDataChannel(const cricket::ContentInfo* content, | |
| 475 const std::string* bundle_transport); | |
| 476 | |
| 477 std::unique_ptr<SessionStats> GetStats_n( | |
| 478 const ChannelNamePairs& channel_name_pairs); | |
| 479 | |
| 480 bool CreateSctpTransport_n(const std::string& content_name, | |
| 481 const std::string& transport_name); | |
| 482 // For bundling. | |
| 483 void ChangeSctpTransport_n(const std::string& transport_name); | |
| 484 void DestroySctpTransport_n(); | |
| 485 // SctpTransport signal handlers. Needed to marshal signals from the network | |
| 486 // to signaling thread. | |
| 487 void OnSctpTransportReadyToSendData_n(); | |
| 488 // This may be called with "false" if the direction of the m= section causes | |
| 489 // us to tear down the SCTP connection. | |
| 490 void OnSctpTransportReadyToSendData_s(bool ready); | |
| 491 void OnSctpTransportDataReceived_n(const cricket::ReceiveDataParams& params, | |
| 492 const rtc::CopyOnWriteBuffer& payload); | |
| 493 // Beyond just firing the signal to the signaling thread, listens to SCTP | |
| 494 // CONTROL messages on unused SIDs and processes them as OPEN messages. | |
| 495 void OnSctpTransportDataReceived_s(const cricket::ReceiveDataParams& params, | |
| 496 const rtc::CopyOnWriteBuffer& payload); | |
| 497 void OnSctpStreamClosedRemotely_n(int sid); | |
| 498 | |
| 499 std::string BadStateErrMsg(State state); | |
| 500 void SetIceConnectionState(PeerConnectionInterface::IceConnectionState state); | |
| 501 void SetIceConnectionReceiving(bool receiving); | |
| 502 | |
| 503 bool ValidateBundleSettings(const cricket::SessionDescription* desc); | |
| 504 bool HasRtcpMuxEnabled(const cricket::ContentInfo* content); | |
| 505 // Below methods are helper methods which verifies SDP. | |
| 506 bool ValidateSessionDescription(const SessionDescriptionInterface* sdesc, | |
| 507 cricket::ContentSource source, | |
| 508 std::string* err_desc); | |
| 509 | |
| 510 // Check if a call to SetLocalDescription is acceptable with |action|. | |
| 511 bool ExpectSetLocalDescription(Action action); | |
| 512 // Check if a call to SetRemoteDescription is acceptable with |action|. | |
| 513 bool ExpectSetRemoteDescription(Action action); | |
| 514 // Verifies a=setup attribute as per RFC 5763. | |
| 515 bool ValidateDtlsSetupAttribute(const cricket::SessionDescription* desc, | |
| 516 Action action); | |
| 517 | |
| 518 // Returns true if we are ready to push down the remote candidate. | |
| 519 // |remote_desc| is the new remote description, or NULL if the current remote | |
| 520 // description should be used. Output |valid| is true if the candidate media | |
| 521 // index is valid. | |
| 522 bool ReadyToUseRemoteCandidate(const IceCandidateInterface* candidate, | |
| 523 const SessionDescriptionInterface* remote_desc, | |
| 524 bool* valid); | |
| 525 | |
| 526 // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by | |
| 527 // this session. | |
| 528 bool SrtpRequired() const; | |
| 529 | |
| 530 // TransportController signal handlers. | |
| 531 void OnTransportControllerConnectionState(cricket::IceConnectionState state); | |
| 532 void OnTransportControllerReceiving(bool receiving); | |
| 533 void OnTransportControllerGatheringState(cricket::IceGatheringState state); | |
| 534 void OnTransportControllerCandidatesGathered( | |
| 535 const std::string& transport_name, | |
| 536 const std::vector<cricket::Candidate>& candidates); | |
| 537 void OnTransportControllerCandidatesRemoved( | |
| 538 const std::vector<cricket::Candidate>& candidates); | |
| 539 void OnTransportControllerDtlsHandshakeError(rtc::SSLHandshakeError error); | |
| 540 | |
| 541 std::string GetSessionErrorMsg(); | |
| 542 | |
| 543 // Invoked when TransportController connection completion is signaled. | |
| 544 // Reports stats for all transports in use. | |
| 545 void ReportTransportStats(); | |
| 546 | |
| 547 // Gather the usage of IPv4/IPv6 as best connection. | |
| 548 void ReportBestConnectionState(const cricket::TransportStats& stats); | |
| 549 | |
| 550 void ReportNegotiatedCiphers(const cricket::TransportStats& stats); | |
| 551 | |
| 552 void OnSentPacket_w(const rtc::SentPacket& sent_packet); | |
| 553 | |
| 554 const std::string GetTransportName(const std::string& content_name); | |
| 555 | |
| 556 void DestroyRtcpTransport_n(const std::string& transport_name); | |
| 557 void DestroyVideoChannel(); | |
| 558 void DestroyVoiceChannel(); | |
| 559 void DestroyDataChannel(); | |
| 560 | |
| 561 rtc::Thread* const network_thread_; | |
| 562 rtc::Thread* const worker_thread_; | |
| 563 rtc::Thread* const signaling_thread_; | |
| 564 | |
| 565 State state_ = STATE_INIT; | |
| 566 Error error_ = ERROR_NONE; | |
| 567 std::string error_desc_; | |
| 568 | |
| 569 const std::string sid_; | |
| 570 bool initial_offerer_ = false; | |
| 571 | |
| 572 const std::unique_ptr<cricket::TransportController> transport_controller_; | |
| 573 const std::unique_ptr<cricket::SctpTransportInternalFactory> sctp_factory_; | |
| 574 MediaControllerInterface* media_controller_; | |
| 575 std::unique_ptr<cricket::VoiceChannel> voice_channel_; | |
| 576 std::unique_ptr<cricket::VideoChannel> video_channel_; | |
| 577 // |rtp_data_channel_| is used if in RTP data channel mode, |sctp_transport_| | |
| 578 // when using SCTP. | |
| 579 std::unique_ptr<cricket::RtpDataChannel> rtp_data_channel_; | |
| 580 | |
| 581 std::unique_ptr<cricket::SctpTransportInternal> sctp_transport_; | |
| 582 // |sctp_transport_name_| keeps track of what DTLS transport the SCTP | |
| 583 // transport is using (which can change due to bundling). | |
| 584 rtc::Optional<std::string> sctp_transport_name_; | |
| 585 // |sctp_content_name_| is the content name (MID) in SDP. | |
| 586 rtc::Optional<std::string> sctp_content_name_; | |
| 587 // Value cached on signaling thread. Only updated when SctpReadyToSendData | |
| 588 // fires on the signaling thread. | |
| 589 bool sctp_ready_to_send_data_ = false; | |
| 590 // Same as signals provided by SctpTransport, but these are guaranteed to | |
| 591 // fire on the signaling thread, whereas SctpTransport fires on the networking | |
| 592 // thread. | |
| 593 // |sctp_invoker_| is used so that any signals queued on the signaling thread | |
| 594 // from the network thread are immediately discarded if the SctpTransport is | |
| 595 // destroyed (due to m= section being rejected). | |
| 596 // TODO(deadbeef): Use a proxy object to ensure that method calls/signals | |
| 597 // are marshalled to the right thread. Could almost use proxy.h for this, | |
| 598 // but it doesn't have a mechanism for marshalling sigslot::signals | |
| 599 std::unique_ptr<rtc::AsyncInvoker> sctp_invoker_; | |
| 600 sigslot::signal1<bool> SignalSctpReadyToSendData; | |
| 601 sigslot::signal2<const cricket::ReceiveDataParams&, | |
| 602 const rtc::CopyOnWriteBuffer&> | |
| 603 SignalSctpDataReceived; | |
| 604 sigslot::signal1<int> SignalSctpStreamClosedRemotely; | |
| 605 | |
| 606 cricket::ChannelManager* channel_manager_; | |
| 607 IceObserver* ice_observer_; | |
| 608 PeerConnectionInterface::IceConnectionState ice_connection_state_; | |
| 609 bool ice_connection_receiving_; | |
| 610 std::unique_ptr<SessionDescriptionInterface> current_local_description_; | |
| 611 std::unique_ptr<SessionDescriptionInterface> pending_local_description_; | |
| 612 std::unique_ptr<SessionDescriptionInterface> current_remote_description_; | |
| 613 std::unique_ptr<SessionDescriptionInterface> pending_remote_description_; | |
| 614 // If the remote peer is using a older version of implementation. | |
| 615 bool older_version_remote_peer_; | |
| 616 bool dtls_enabled_; | |
| 617 // Specifies which kind of data channel is allowed. This is controlled | |
| 618 // by the chrome command-line flag and constraints: | |
| 619 // 1. If chrome command-line switch 'enable-sctp-data-channels' is enabled, | |
| 620 // constraint kEnableDtlsSrtp is true, and constaint kEnableRtpDataChannels is | |
| 621 // not set or false, SCTP is allowed (DCT_SCTP); | |
| 622 // 2. If constraint kEnableRtpDataChannels is true, RTP is allowed (DCT_RTP); | |
| 623 // 3. If both 1&2 are false, data channel is not allowed (DCT_NONE). | |
| 624 // The data channel type could be DCT_QUIC if the QUIC data channel is | |
| 625 // enabled. | |
| 626 cricket::DataChannelType data_channel_type_; | |
| 627 // List of content names for which the remote side triggered an ICE restart. | |
| 628 std::set<std::string> pending_ice_restarts_; | |
| 629 | |
| 630 std::unique_ptr<WebRtcSessionDescriptionFactory> webrtc_session_desc_factory_; | |
| 631 | |
| 632 // Member variables for caching global options. | |
| 633 cricket::AudioOptions audio_options_; | |
| 634 cricket::VideoOptions video_options_; | |
| 635 MetricsObserverInterface* metrics_observer_; | |
| 636 | |
| 637 // Declares the bundle policy for the WebRTCSession. | |
| 638 PeerConnectionInterface::BundlePolicy bundle_policy_; | |
| 639 | |
| 640 // Declares the RTCP mux policy for the WebRTCSession. | |
| 641 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy_; | |
| 642 | |
| 643 bool received_first_video_packet_ = false; | |
| 644 bool received_first_audio_packet_ = false; | |
| 645 | |
| 646 #ifdef HAVE_QUIC | |
| 647 std::unique_ptr<QuicDataTransport> quic_data_transport_; | |
| 648 #endif // HAVE_QUIC | |
| 649 | |
| 650 RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcSession); | |
| 651 }; | |
| 652 } // namespace webrtc | |
| 653 | |
| 654 #endif // WEBRTC_API_WEBRTCSESSION_H_ | |
| OLD | NEW |