| 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 PC_PEER_CONNECTION_H_ |
| 12 | #define PC_PEER_CONNECTION_H_ |
| 13 |
| 14 | #include <map> |
| 15 | #include <memory> |
| 16 | #include <set> |
| 17 | #include <string> |
| 18 | #include <utility> |
| 19 | #include <vector> |
| 20 |
| 21 | #include "api/peer_connection_interface.h" |
| 22 | #include "api/transport/data_channel_transport_interface.h" |
| 23 | #include "api/turn_customizer.h" |
| 24 | #include "pc/data_channel_controller.h" |
| 25 | #include "pc/ice_server_parsing.h" |
| 26 | #include "pc/jsep_transport_controller.h" |
| 27 | #include "pc/peer_connection_factory.h" |
| 28 | #include "pc/peer_connection_internal.h" |
| 29 | #include "pc/rtc_stats_collector.h" |
| 30 | #include "pc/rtp_sender.h" |
| 31 | #include "pc/rtp_transceiver.h" |
| 32 | #include "pc/sctp_transport.h" |
| 33 | #include "pc/stats_collector.h" |
| 34 | #include "pc/stream_collection.h" |
| 35 | #include "pc/webrtc_session_description_factory.h" |
| 36 | #include "rtc_base/experiments/field_trial_parser.h" |
| 37 | #include "rtc_base/operations_chain.h" |
| 38 | #include "rtc_base/race_checker.h" |
| 39 | #include "rtc_base/unique_id_generator.h" |
| 40 | #include "rtc_base/weak_ptr.h" |
| 41 |
| 42 | namespace webrtc { |
| 43 |
| 44 | class MediaStreamObserver; |
| 45 | class VideoRtpReceiver; |
| 46 | class RtcEventLog; |
| 47 |
| 48 | // PeerConnection is the implementation of the PeerConnection object as defined |
| 49 | // by the PeerConnectionInterface API surface. |
| 50 | // The class currently is solely responsible for the following: |
| 51 | // - Managing the session state machine (signaling state). |
| 52 | // - Creating and initializing lower-level objects, like PortAllocator and |
| 53 | // BaseChannels. |
| 54 | // - Owning and managing the life cycle of the RtpSender/RtpReceiver and track |
| 55 | // objects. |
| 56 | // - Tracking the current and pending local/remote session descriptions. |
| 57 | // The class currently is jointly responsible for the following: |
| 58 | // - Parsing and interpreting SDP. |
| 59 | // - Generating offers and answers based on the current state. |
| 60 | // - The ICE state machine. |
| 61 | // - Generating stats. |
| 62 | class PeerConnection : public PeerConnectionInternal, |
| 63 | public JsepTransportController::Observer, |
| 64 | public RtpSenderBase::SetStreamsObserver, |
| 65 | public rtc::MessageHandler, |
| 66 | public sigslot::has_slots<> { |
| 67 | public: |
| 68 | // A bit in the usage pattern is registered when its defining event occurs at |
| 69 | // least once. |
| 70 | enum class UsageEvent : int { |
| 71 | TURN_SERVER_ADDED = 0x01, |
| 72 | STUN_SERVER_ADDED = 0x02, |
| 73 | DATA_ADDED = 0x04, |
| 74 | AUDIO_ADDED = 0x08, |
| 75 | VIDEO_ADDED = 0x10, |
| 76 | // |SetLocalDescription| returns successfully. |
| 77 | SET_LOCAL_DESCRIPTION_SUCCEEDED = 0x20, |
| 78 | // |SetRemoteDescription| returns successfully. |
| 79 | SET_REMOTE_DESCRIPTION_SUCCEEDED = 0x40, |
| 80 | // A local candidate (with type host, server-reflexive, or relay) is |
| 81 | // collected. |
| 82 | CANDIDATE_COLLECTED = 0x80, |
| 83 | // A remote candidate is successfully added via |AddIceCandidate|. |
| 84 | ADD_ICE_CANDIDATE_SUCCEEDED = 0x100, |
| 85 | ICE_STATE_CONNECTED = 0x200, |
| 86 | CLOSE_CALLED = 0x400, |
| 87 | // A local candidate with private IP is collected. |
| 88 | PRIVATE_CANDIDATE_COLLECTED = 0x800, |
| 89 | // A remote candidate with private IP is added, either via AddiceCandidate |
| 90 | // or from the remote description. |
| 91 | REMOTE_PRIVATE_CANDIDATE_ADDED = 0x1000, |
| 92 | // A local mDNS candidate is collected. |
| 93 | MDNS_CANDIDATE_COLLECTED = 0x2000, |
| 94 | // A remote mDNS candidate is added, either via AddIceCandidate or from the |
| 95 | // remote description. |
| 96 | REMOTE_MDNS_CANDIDATE_ADDED = 0x4000, |
| 97 | // A local candidate with IPv6 address is collected. |
| 98 | IPV6_CANDIDATE_COLLECTED = 0x8000, |
| 99 | // A remote candidate with IPv6 address is added, either via AddIceCandidate |
| 100 | // or from the remote description. |
| 101 | REMOTE_IPV6_CANDIDATE_ADDED = 0x10000, |
| 102 | // A remote candidate (with type host, server-reflexive, or relay) is |
| 103 | // successfully added, either via AddIceCandidate or from the remote |
| 104 | // description. |
| 105 | REMOTE_CANDIDATE_ADDED = 0x20000, |
| 106 | // An explicit host-host candidate pair is selected, i.e. both the local and |
| 107 | // the remote candidates have the host type. This does not include candidate |
| 108 | // pairs formed with equivalent prflx remote candidates, e.g. a host-prflx |
| 109 | // pair where the prflx candidate has the same base as a host candidate of |
| 110 | // the remote peer. |
| 111 | DIRECT_CONNECTION_SELECTED = 0x40000, |
| 112 | MAX_VALUE = 0x80000, |
| 113 | }; |
| 114 |
| 115 | explicit PeerConnection(PeerConnectionFactory* factory, |
| 116 | std::unique_ptr<RtcEventLog> event_log, |
| 117 | std::unique_ptr<Call> call); |
| 118 |
| 119 | bool Initialize( |
| 120 | const PeerConnectionInterface::RTCConfiguration& configuration, |
| 121 | PeerConnectionDependencies dependencies); |
| 122 |
| 123 | rtc::scoped_refptr<StreamCollectionInterface> local_streams() override; |
| 124 | rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override; |
| 125 | bool AddStream(MediaStreamInterface* local_stream) override; |
| 126 | void RemoveStream(MediaStreamInterface* local_stream) override; |
| 127 |
| 128 | RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack( |
| 129 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 130 | const std::vector<std::string>& stream_ids) override; |
| 131 | bool RemoveTrack(RtpSenderInterface* sender) override; |
| 132 | RTCError RemoveTrackNew( |
| 133 | rtc::scoped_refptr<RtpSenderInterface> sender) override; |
| 134 |
| 135 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 136 | rtc::scoped_refptr<MediaStreamTrackInterface> track) override; |
| 137 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 138 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 139 | const RtpTransceiverInit& init) override; |
| 140 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 141 | cricket::MediaType media_type) override; |
| 142 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 143 | cricket::MediaType media_type, |
| 144 | const RtpTransceiverInit& init) override; |
| 145 |
| 146 | // Gets the DTLS SSL certificate associated with the audio transport on the |
| 147 | // remote side. This will become populated once the DTLS connection with the |
| 148 | // peer has been completed, as indicated by the ICE connection state |
| 149 | // transitioning to kIceConnectionCompleted. |
| 150 | // Note that this will be removed once we implement RTCDtlsTransport which |
| 151 | // has standardized method for getting this information. |
| 152 | // See https://www.w3.org/TR/webrtc/#rtcdtlstransport-interface |
| 153 | std::unique_ptr<rtc::SSLCertificate> GetRemoteAudioSSLCertificate(); |
| 154 |
| 155 | // Version of the above method that returns the full certificate chain. |
| 156 | std::unique_ptr<rtc::SSLCertChain> GetRemoteAudioSSLCertChain(); |
| 157 |
| 158 | rtc::scoped_refptr<RtpSenderInterface> CreateSender( |
| 159 | const std::string& kind, |
| 160 | const std::string& stream_id) override; |
| 161 |
| 162 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders() |
| 163 | const override; |
| 164 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers() |
| 165 | const override; |
| 166 | std::vector<rtc::scoped_refptr<RtpTransceiverInterface>> GetTransceivers() |
| 167 | const override; |
| 168 |
| 169 | rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( |
| 170 | const std::string& label, |
| 171 | const DataChannelInit* config) override; |
| 172 | // WARNING: LEGACY. See peerconnectioninterface.h |
| 173 | bool GetStats(StatsObserver* observer, |
| 174 | webrtc::MediaStreamTrackInterface* track, |
| 175 | StatsOutputLevel level) override; |
| 176 | // Spec-complaint GetStats(). See peerconnectioninterface.h |
| 177 | void GetStats(RTCStatsCollectorCallback* callback) override; |
| 178 | void GetStats( |
| 179 | rtc::scoped_refptr<RtpSenderInterface> selector, |
| 180 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override; |
| 181 | void GetStats( |
| 182 | rtc::scoped_refptr<RtpReceiverInterface> selector, |
| 183 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override; |
| 184 | void ClearStatsCache() override; |
| 185 |
| 186 | SignalingState signaling_state() override; |
| 187 |
| 188 | IceConnectionState ice_connection_state() override; |
| 189 | IceConnectionState standardized_ice_connection_state() override; |
| 190 | PeerConnectionState peer_connection_state() override; |
| 191 | IceGatheringState ice_gathering_state() override; |
| 192 | absl::optional<bool> can_trickle_ice_candidates() override; |
| 193 |
| 194 | const SessionDescriptionInterface* local_description() const override; |
| 195 | const SessionDescriptionInterface* remote_description() const override; |
| 196 | const SessionDescriptionInterface* current_local_description() const override; |
| 197 | const SessionDescriptionInterface* current_remote_description() |
| 198 | const override; |
| 199 | const SessionDescriptionInterface* pending_local_description() const override; |
| 200 | const SessionDescriptionInterface* pending_remote_description() |
| 201 | const override; |
| 202 |
| 203 | void RestartIce() override; |
| 204 |
| 205 | // JSEP01 |
| 206 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 207 | const RTCOfferAnswerOptions& options) override; |
| 208 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 209 | const RTCOfferAnswerOptions& options) override; |
| 210 |
| 211 | void SetLocalDescription( |
| 212 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 213 | rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer) |
| 214 | override; |
| 215 | void SetLocalDescription( |
| 216 | rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer) |
| 217 | override; |
| 218 | // TODO(https://crbug.com/webrtc/11798): Delete these methods in favor of the |
| 219 | // ones taking SetLocalDescriptionObserverInterface as argument. |
| 220 | void SetLocalDescription(SetSessionDescriptionObserver* observer, |
| 221 | SessionDescriptionInterface* desc) override; |
| 222 | void SetLocalDescription(SetSessionDescriptionObserver* observer) override; |
| 223 |
| 224 | void SetRemoteDescription( |
| 225 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 226 | rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer) |
| 227 | override; |
| 228 | // TODO(https://crbug.com/webrtc/11798): Delete this methods in favor of the |
| 229 | // ones taking SetRemoteDescriptionObserverInterface as argument. |
| 230 | void SetRemoteDescription(SetSessionDescriptionObserver* observer, |
| 231 | SessionDescriptionInterface* desc) override; |
| 232 |
| 233 | PeerConnectionInterface::RTCConfiguration GetConfiguration() override; |
| 234 | RTCError SetConfiguration( |
| 235 | const PeerConnectionInterface::RTCConfiguration& configuration) override; |
| 236 | bool AddIceCandidate(const IceCandidateInterface* candidate) override; |
| 237 | void AddIceCandidate(std::unique_ptr<IceCandidateInterface> candidate, |
| 238 | std::function<void(RTCError)> callback) override; |
| 239 | bool RemoveIceCandidates( |
| 240 | const std::vector<cricket::Candidate>& candidates) override; |
| 241 |
| 242 | RTCError SetBitrate(const BitrateSettings& bitrate) override; |
| 243 |
| 244 | void SetAudioPlayout(bool playout) override; |
| 245 | void SetAudioRecording(bool recording) override; |
| 246 |
| 247 | rtc::scoped_refptr<DtlsTransportInterface> LookupDtlsTransportByMid( |
| 248 | const std::string& mid) override; |
| 249 | rtc::scoped_refptr<DtlsTransport> LookupDtlsTransportByMidInternal( |
| 250 | const std::string& mid); |
| 251 |
| 252 | rtc::scoped_refptr<SctpTransportInterface> GetSctpTransport() const override; |
| 253 |
| 254 | void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) override; |
| 255 |
| 256 | bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output, |
| 257 | int64_t output_period_ms) override; |
| 258 | bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output) override; |
| 259 | void StopRtcEventLog() override; |
| 260 |
| 261 | void Close() override; |
| 262 |
| 263 | rtc::Thread* signaling_thread() const final { |
| 264 | return factory_->signaling_thread(); |
| 265 | } |
| 266 |
| 267 | // PeerConnectionInternal implementation. |
| 268 | rtc::Thread* network_thread() const final { |
| 269 | return factory_->network_thread(); |
| 270 | } |
| 271 | rtc::Thread* worker_thread() const final { return factory_->worker_thread(); } |
| 272 |
| 273 | std::string session_id() const override { |
| 274 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 275 | return session_id_; |
| 276 | } |
| 277 |
| 278 | bool initial_offerer() const override { |
| 279 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 280 | return transport_controller_ && transport_controller_->initial_offerer(); |
| 281 | } |
| 282 |
| 283 | std::vector< |
| 284 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
| 285 | GetTransceiversInternal() const override { |
| 286 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 287 | return transceivers_; |
| 288 | } |
| 289 |
| 290 | sigslot::signal1<RtpDataChannel*>& SignalRtpDataChannelCreated() override { |
| 291 | return data_channel_controller_.SignalRtpDataChannelCreated(); |
| 292 | } |
| 293 |
| 294 | sigslot::signal1<SctpDataChannel*>& SignalSctpDataChannelCreated() override { |
| 295 | return data_channel_controller_.SignalSctpDataChannelCreated(); |
| 296 | } |
| 297 |
| 298 | cricket::RtpDataChannel* rtp_data_channel() const override { |
| 299 | return data_channel_controller_.rtp_data_channel(); |
| 300 | } |
| 301 |
| 302 | std::vector<DataChannelStats> GetDataChannelStats() const override; |
| 303 |
| 304 | absl::optional<std::string> sctp_transport_name() const override; |
| 305 |
| 306 | cricket::CandidateStatsList GetPooledCandidateStats() const override; |
| 307 | std::map<std::string, std::string> GetTransportNamesByMid() const override; |
| 308 | std::map<std::string, cricket::TransportStats> GetTransportStatsByNames( |
| 309 | const std::set<std::string>& transport_names) override; |
| 310 | Call::Stats GetCallStats() override; |
| 311 |
| 312 | bool GetLocalCertificate( |
| 313 | const std::string& transport_name, |
| 314 | rtc::scoped_refptr<rtc::RTCCertificate>* certificate) override; |
| 315 | std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain( |
| 316 | const std::string& transport_name) override; |
| 317 | bool IceRestartPending(const std::string& content_name) const override; |
| 318 | bool NeedsIceRestart(const std::string& content_name) const override; |
| 319 | bool GetSslRole(const std::string& content_name, rtc::SSLRole* role) override; |
| 320 |
| 321 | // Functions needed by DataChannelController |
| 322 | void NoteDataAddedEvent() { NoteUsageEvent(UsageEvent::DATA_ADDED); } |
| 323 | // Returns the observer. Will crash on CHECK if the observer is removed. |
| 324 | PeerConnectionObserver* Observer() const; |
| 325 | bool IsClosed() const { |
| 326 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 327 | return signaling_state_ == PeerConnectionInterface::kClosed; |
| 328 | } |
| 329 | // Get current SSL role used by SCTP's underlying transport. |
| 330 | bool GetSctpSslRole(rtc::SSLRole* role); |
| 331 | // Handler for the "channel closed" signal |
| 332 | void OnSctpDataChannelClosed(DataChannelInterface* channel); |
| 333 |
| 334 | // Functions made public for testing. |
| 335 | void ReturnHistogramVeryQuicklyForTesting() { |
| 336 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 337 | return_histogram_very_quickly_ = true; |
| 338 | } |
| 339 | void RequestUsagePatternReportForTesting(); |
| 340 | absl::optional<std::string> sctp_mid() { |
| 341 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 342 | return sctp_mid_s_; |
| 343 | } |
| 344 |
| 345 | protected: |
| 346 | ~PeerConnection() override; |
| 347 |
| 348 | private: |
| 349 | class ImplicitCreateSessionDescriptionObserver; |
| 350 | friend class ImplicitCreateSessionDescriptionObserver; |
| 351 | class SetSessionDescriptionObserverAdapter; |
| 352 | friend class SetSessionDescriptionObserverAdapter; |
| 353 |
| 354 | // Represents the [[LocalIceCredentialsToReplace]] internal slot in the spec. |
| 355 | // It makes the next CreateOffer() produce new ICE credentials even if |
| 356 | // RTCOfferAnswerOptions::ice_restart is false. |
| 357 | // https://w3c.github.io/webrtc-pc/#dfn-localufragstoreplace |
| 358 | // TODO(hbos): When JsepTransportController/JsepTransport supports rollback, |
| 359 | // move this type of logic to JsepTransportController/JsepTransport. |
| 360 | class LocalIceCredentialsToReplace; |
| 361 |
| 362 | struct RtpSenderInfo { |
| 363 | RtpSenderInfo() : first_ssrc(0) {} |
| 364 | RtpSenderInfo(const std::string& stream_id, |
| 365 | const std::string sender_id, |
| 366 | uint32_t ssrc) |
| 367 | : stream_id(stream_id), sender_id(sender_id), first_ssrc(ssrc) {} |
| 368 | bool operator==(const RtpSenderInfo& other) { |
| 369 | return this->stream_id == other.stream_id && |
| 370 | this->sender_id == other.sender_id && |
| 371 | this->first_ssrc == other.first_ssrc; |
| 372 | } |
| 373 | std::string stream_id; |
| 374 | std::string sender_id; |
| 375 | // An RtpSender can have many SSRCs. The first one is used as a sort of ID |
| 376 | // for communicating with the lower layers. |
| 377 | uint32_t first_ssrc; |
| 378 | }; |
| 379 |
| 380 | // Captures partial state to be used for rollback. Applicable only in |
| 381 | // Unified Plan. |
| 382 | class TransceiverStableState { |
| 383 | public: |
| 384 | TransceiverStableState() {} |
| 385 | void set_newly_created(); |
| 386 | void SetMSectionIfUnset(absl::optional<std::string> mid, |
| 387 | absl::optional<size_t> mline_index); |
| 388 | void SetRemoteStreamIdsIfUnset(const std::vector<std::string>& ids); |
| 389 | absl::optional<std::string> mid() const { return mid_; } |
| 390 | absl::optional<size_t> mline_index() const { return mline_index_; } |
| 391 | absl::optional<std::vector<std::string>> remote_stream_ids() const { |
| 392 | return remote_stream_ids_; |
| 393 | } |
| 394 | bool has_m_section() const { return has_m_section_; } |
| 395 | bool newly_created() const { return newly_created_; } |
| 396 |
| 397 | private: |
| 398 | absl::optional<std::string> mid_; |
| 399 | absl::optional<size_t> mline_index_; |
| 400 | absl::optional<std::vector<std::string>> remote_stream_ids_; |
| 401 | // Indicates that mid value from stable state has been captured and |
| 402 | // that rollback has to restore the transceiver. Also protects against |
| 403 | // subsequent overwrites. |
| 404 | bool has_m_section_ = false; |
| 405 | // Indicates that the transceiver was created as part of applying a |
| 406 | // description to track potential need for removing transceiver during |
| 407 | // rollback. |
| 408 | bool newly_created_ = false; |
| 409 | }; |
| 410 |
| 411 | // Implements MessageHandler. |
| 412 | void OnMessage(rtc::Message* msg) override; |
| 413 |
| 414 | // Plan B helpers for getting the voice/video media channels for the single |
| 415 | // audio/video transceiver, if it exists. |
| 416 | cricket::VoiceMediaChannel* voice_media_channel() const |
| 417 | RTC_RUN_ON(signaling_thread()); |
| 418 | cricket::VideoMediaChannel* video_media_channel() const |
| 419 | RTC_RUN_ON(signaling_thread()); |
| 420 |
| 421 | std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>> |
| 422 | GetSendersInternal() const RTC_RUN_ON(signaling_thread()); |
| 423 | std::vector< |
| 424 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>> |
| 425 | GetReceiversInternal() const RTC_RUN_ON(signaling_thread()); |
| 426 |
| 427 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 428 | GetAudioTransceiver() const RTC_RUN_ON(signaling_thread()); |
| 429 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 430 | GetVideoTransceiver() const RTC_RUN_ON(signaling_thread()); |
| 431 |
| 432 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 433 | GetFirstAudioTransceiver() const RTC_RUN_ON(signaling_thread()); |
| 434 |
| 435 | // Implementation of the offer/answer exchange operations. These are chained |
| 436 | // onto the |operations_chain_| when the public CreateOffer(), CreateAnswer(), |
| 437 | // SetLocalDescription() and SetRemoteDescription() methods are invoked. |
| 438 | void DoCreateOffer( |
| 439 | const RTCOfferAnswerOptions& options, |
| 440 | rtc::scoped_refptr<CreateSessionDescriptionObserver> observer); |
| 441 | void DoCreateAnswer( |
| 442 | const RTCOfferAnswerOptions& options, |
| 443 | rtc::scoped_refptr<CreateSessionDescriptionObserver> observer); |
| 444 | void DoSetLocalDescription( |
| 445 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 446 | rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer); |
| 447 | void DoSetRemoteDescription( |
| 448 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 449 | rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer); |
| 450 |
| 451 | void CreateAudioReceiver(MediaStreamInterface* stream, |
| 452 | const RtpSenderInfo& remote_sender_info) |
| 453 | RTC_RUN_ON(signaling_thread()); |
| 454 |
| 455 | void CreateVideoReceiver(MediaStreamInterface* stream, |
| 456 | const RtpSenderInfo& remote_sender_info) |
| 457 | RTC_RUN_ON(signaling_thread()); |
| 458 | rtc::scoped_refptr<RtpReceiverInterface> RemoveAndStopReceiver( |
| 459 | const RtpSenderInfo& remote_sender_info) RTC_RUN_ON(signaling_thread()); |
| 460 |
| 461 | // May be called either by AddStream/RemoveStream, or when a track is |
| 462 | // added/removed from a stream previously added via AddStream. |
| 463 | void AddAudioTrack(AudioTrackInterface* track, MediaStreamInterface* stream) |
| 464 | RTC_RUN_ON(signaling_thread()); |
| 465 | void RemoveAudioTrack(AudioTrackInterface* track, |
| 466 | MediaStreamInterface* stream) |
| 467 | RTC_RUN_ON(signaling_thread()); |
| 468 | void AddVideoTrack(VideoTrackInterface* track, MediaStreamInterface* stream) |
| 469 | RTC_RUN_ON(signaling_thread()); |
| 470 | void RemoveVideoTrack(VideoTrackInterface* track, |
| 471 | MediaStreamInterface* stream) |
| 472 | RTC_RUN_ON(signaling_thread()); |
| 473 |
| 474 | // AddTrack implementation when Unified Plan is specified. |
| 475 | RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrackUnifiedPlan( |
| 476 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 477 | const std::vector<std::string>& stream_ids) |
| 478 | RTC_RUN_ON(signaling_thread()); |
| 479 | // AddTrack implementation when Plan B is specified. |
| 480 | RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrackPlanB( |
| 481 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 482 | const std::vector<std::string>& stream_ids) |
| 483 | RTC_RUN_ON(signaling_thread()); |
| 484 |
| 485 | // Returns the first RtpTransceiver suitable for a newly added track, if such |
| 486 | // transceiver is available. |
| 487 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 488 | FindFirstTransceiverForAddedTrack( |
| 489 | rtc::scoped_refptr<MediaStreamTrackInterface> track) |
| 490 | RTC_RUN_ON(signaling_thread()); |
| 491 |
| 492 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 493 | FindTransceiverBySender(rtc::scoped_refptr<RtpSenderInterface> sender) |
| 494 | RTC_RUN_ON(signaling_thread()); |
| 495 |
| 496 | // Internal implementation for AddTransceiver family of methods. If |
| 497 | // |fire_callback| is set, fires OnRenegotiationNeeded callback if successful. |
| 498 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 499 | cricket::MediaType media_type, |
| 500 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 501 | const RtpTransceiverInit& init, |
| 502 | bool fire_callback = true) RTC_RUN_ON(signaling_thread()); |
| 503 |
| 504 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> |
| 505 | CreateSender(cricket::MediaType media_type, |
| 506 | const std::string& id, |
| 507 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 508 | const std::vector<std::string>& stream_ids, |
| 509 | const std::vector<RtpEncodingParameters>& send_encodings); |
| 510 |
| 511 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>> |
| 512 | CreateReceiver(cricket::MediaType media_type, const std::string& receiver_id); |
| 513 |
| 514 | // Create a new RtpTransceiver of the given type and add it to the list of |
| 515 | // transceivers. |
| 516 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 517 | CreateAndAddTransceiver( |
| 518 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> sender, |
| 519 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>> |
| 520 | receiver) RTC_RUN_ON(signaling_thread()); |
| 521 |
| 522 | void SetIceConnectionState(IceConnectionState new_state) |
| 523 | RTC_RUN_ON(signaling_thread()); |
| 524 | void SetStandardizedIceConnectionState( |
| 525 | PeerConnectionInterface::IceConnectionState new_state) |
| 526 | RTC_RUN_ON(signaling_thread()); |
| 527 | void SetConnectionState( |
| 528 | PeerConnectionInterface::PeerConnectionState new_state) |
| 529 | RTC_RUN_ON(signaling_thread()); |
| 530 |
| 531 | // Called any time the IceGatheringState changes. |
| 532 | void OnIceGatheringChange(IceGatheringState new_state) |
| 533 | RTC_RUN_ON(signaling_thread()); |
| 534 | // New ICE candidate has been gathered. |
| 535 | void OnIceCandidate(std::unique_ptr<IceCandidateInterface> candidate) |
| 536 | RTC_RUN_ON(signaling_thread()); |
| 537 | // Gathering of an ICE candidate failed. |
| 538 | void OnIceCandidateError(const std::string& address, |
| 539 | int port, |
| 540 | const std::string& url, |
| 541 | int error_code, |
| 542 | const std::string& error_text) |
| 543 | RTC_RUN_ON(signaling_thread()); |
| 544 | // Some local ICE candidates have been removed. |
| 545 | void OnIceCandidatesRemoved(const std::vector<cricket::Candidate>& candidates) |
| 546 | RTC_RUN_ON(signaling_thread()); |
| 547 |
| 548 | void OnSelectedCandidatePairChanged( |
| 549 | const cricket::CandidatePairChangeEvent& event) |
| 550 | RTC_RUN_ON(signaling_thread()); |
| 551 |
| 552 | // Update the state, signaling if necessary. |
| 553 | void ChangeSignalingState(SignalingState signaling_state) |
| 554 | RTC_RUN_ON(signaling_thread()); |
| 555 |
| 556 | // Signals from MediaStreamObserver. |
| 557 | void OnAudioTrackAdded(AudioTrackInterface* track, |
| 558 | MediaStreamInterface* stream) |
| 559 | RTC_RUN_ON(signaling_thread()); |
| 560 | void OnAudioTrackRemoved(AudioTrackInterface* track, |
| 561 | MediaStreamInterface* stream) |
| 562 | RTC_RUN_ON(signaling_thread()); |
| 563 | void OnVideoTrackAdded(VideoTrackInterface* track, |
| 564 | MediaStreamInterface* stream) |
| 565 | RTC_RUN_ON(signaling_thread()); |
| 566 | void OnVideoTrackRemoved(VideoTrackInterface* track, |
| 567 | MediaStreamInterface* stream) |
| 568 | RTC_RUN_ON(signaling_thread()); |
| 569 |
| 570 | void PostSetSessionDescriptionSuccess( |
| 571 | SetSessionDescriptionObserver* observer); |
| 572 | void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer, |
| 573 | RTCError&& error); |
| 574 | void PostCreateSessionDescriptionFailure( |
| 575 | CreateSessionDescriptionObserver* observer, |
| 576 | RTCError error); |
| 577 |
| 578 | // Synchronous implementations of SetLocalDescription/SetRemoteDescription |
| 579 | // that return an RTCError instead of invoking a callback. |
| 580 | RTCError ApplyLocalDescription( |
| 581 | std::unique_ptr<SessionDescriptionInterface> desc); |
| 582 | RTCError ApplyRemoteDescription( |
| 583 | std::unique_ptr<SessionDescriptionInterface> desc); |
| 584 |
| 585 | // Updates the local RtpTransceivers according to the JSEP rules. Called as |
| 586 | // part of setting the local/remote description. |
| 587 | RTCError UpdateTransceiversAndDataChannels( |
| 588 | cricket::ContentSource source, |
| 589 | const SessionDescriptionInterface& new_session, |
| 590 | const SessionDescriptionInterface* old_local_description, |
| 591 | const SessionDescriptionInterface* old_remote_description) |
| 592 | RTC_RUN_ON(signaling_thread()); |
| 593 |
| 594 | // Either creates or destroys the transceiver's BaseChannel according to the |
| 595 | // given media section. |
| 596 | RTCError UpdateTransceiverChannel( |
| 597 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 598 | transceiver, |
| 599 | const cricket::ContentInfo& content, |
| 600 | const cricket::ContentGroup* bundle_group) RTC_RUN_ON(signaling_thread()); |
| 601 |
| 602 | // Either creates or destroys the local data channel according to the given |
| 603 | // media section. |
| 604 | RTCError UpdateDataChannel(cricket::ContentSource source, |
| 605 | const cricket::ContentInfo& content, |
| 606 | const cricket::ContentGroup* bundle_group) |
| 607 | RTC_RUN_ON(signaling_thread()); |
| 608 |
| 609 | // Associate the given transceiver according to the JSEP rules. |
| 610 | RTCErrorOr< |
| 611 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
| 612 | AssociateTransceiver(cricket::ContentSource source, |
| 613 | SdpType type, |
| 614 | size_t mline_index, |
| 615 | const cricket::ContentInfo& content, |
| 616 | const cricket::ContentInfo* old_local_content, |
| 617 | const cricket::ContentInfo* old_remote_content) |
| 618 | RTC_RUN_ON(signaling_thread()); |
| 619 |
| 620 | // Returns the RtpTransceiver, if found, that is associated to the given MID. |
| 621 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 622 | GetAssociatedTransceiver(const std::string& mid) const |
| 623 | RTC_RUN_ON(signaling_thread()); |
| 624 |
| 625 | // Returns the RtpTransceiver, if found, that was assigned to the given mline |
| 626 | // index in CreateOffer. |
| 627 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 628 | GetTransceiverByMLineIndex(size_t mline_index) const |
| 629 | RTC_RUN_ON(signaling_thread()); |
| 630 |
| 631 | // Returns an RtpTransciever, if available, that can be used to receive the |
| 632 | // given media type according to JSEP rules. |
| 633 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 634 | FindAvailableTransceiverToReceive(cricket::MediaType media_type) const |
| 635 | RTC_RUN_ON(signaling_thread()); |
| 636 |
| 637 | // Returns the media section in the given session description that is |
| 638 | // associated with the RtpTransceiver. Returns null if none found or this |
| 639 | // RtpTransceiver is not associated. Logic varies depending on the |
| 640 | // SdpSemantics specified in the configuration. |
| 641 | const cricket::ContentInfo* FindMediaSectionForTransceiver( |
| 642 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 643 | transceiver, |
| 644 | const SessionDescriptionInterface* sdesc) const |
| 645 | RTC_RUN_ON(signaling_thread()); |
| 646 |
| 647 | // Runs the algorithm **set the associated remote streams** specified in |
| 648 | // https://w3c.github.io/webrtc-pc/#set-associated-remote-streams. |
| 649 | void SetAssociatedRemoteStreams( |
| 650 | rtc::scoped_refptr<RtpReceiverInternal> receiver, |
| 651 | const std::vector<std::string>& stream_ids, |
| 652 | std::vector<rtc::scoped_refptr<MediaStreamInterface>>* added_streams, |
| 653 | std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams) |
| 654 | RTC_RUN_ON(signaling_thread()); |
| 655 |
| 656 | // Runs the algorithm **process the removal of a remote track** specified in |
| 657 | // the WebRTC specification. |
| 658 | // This method will update the following lists: |
| 659 | // |remove_list| is the list of transceivers for which the receiving track is |
| 660 | // being removed. |
| 661 | // |removed_streams| is the list of streams which no longer have a receiving |
| 662 | // track so should be removed. |
| 663 | // https://w3c.github.io/webrtc-pc/#process-remote-track-removal |
| 664 | void ProcessRemovalOfRemoteTrack( |
| 665 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 666 | transceiver, |
| 667 | std::vector<rtc::scoped_refptr<RtpTransceiverInterface>>* remove_list, |
| 668 | std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams) |
| 669 | RTC_RUN_ON(signaling_thread()); |
| 670 |
| 671 | void RemoveRemoteStreamsIfEmpty( |
| 672 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& |
| 673 | remote_streams, |
| 674 | std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams) |
| 675 | RTC_RUN_ON(signaling_thread()); |
| 676 |
| 677 | void OnNegotiationNeeded(); |
| 678 |
| 679 | // Returns a MediaSessionOptions struct with options decided by |options|, |
| 680 | // the local MediaStreams and DataChannels. |
| 681 | void GetOptionsForOffer(const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 682 | offer_answer_options, |
| 683 | cricket::MediaSessionOptions* session_options) |
| 684 | RTC_RUN_ON(signaling_thread()); |
| 685 | void GetOptionsForPlanBOffer( |
| 686 | const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 687 | offer_answer_options, |
| 688 | cricket::MediaSessionOptions* session_options) |
| 689 | RTC_RUN_ON(signaling_thread()); |
| 690 | void GetOptionsForUnifiedPlanOffer( |
| 691 | const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 692 | offer_answer_options, |
| 693 | cricket::MediaSessionOptions* session_options) |
| 694 | RTC_RUN_ON(signaling_thread()); |
| 695 |
| 696 | RTCError HandleLegacyOfferOptions(const RTCOfferAnswerOptions& options) |
| 697 | RTC_RUN_ON(signaling_thread()); |
| 698 | void RemoveRecvDirectionFromReceivingTransceiversOfType( |
| 699 | cricket::MediaType media_type) RTC_RUN_ON(signaling_thread()); |
| 700 | void AddUpToOneReceivingTransceiverOfType(cricket::MediaType media_type); |
| 701 | std::vector< |
| 702 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
| 703 | GetReceivingTransceiversOfType(cricket::MediaType media_type) |
| 704 | RTC_RUN_ON(signaling_thread()); |
| 705 |
| 706 | // Returns a MediaSessionOptions struct with options decided by |
| 707 | // |constraints|, the local MediaStreams and DataChannels. |
| 708 | void GetOptionsForAnswer(const RTCOfferAnswerOptions& offer_answer_options, |
| 709 | cricket::MediaSessionOptions* session_options) |
| 710 | RTC_RUN_ON(signaling_thread()); |
| 711 | void GetOptionsForPlanBAnswer( |
| 712 | const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 713 | offer_answer_options, |
| 714 | cricket::MediaSessionOptions* session_options) |
| 715 | RTC_RUN_ON(signaling_thread()); |
| 716 | void GetOptionsForUnifiedPlanAnswer( |
| 717 | const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 718 | offer_answer_options, |
| 719 | cricket::MediaSessionOptions* session_options) |
| 720 | RTC_RUN_ON(signaling_thread()); |
| 721 |
| 722 | // Generates MediaDescriptionOptions for the |session_opts| based on existing |
| 723 | // local description or remote description. |
| 724 | void GenerateMediaDescriptionOptions( |
| 725 | const SessionDescriptionInterface* session_desc, |
| 726 | RtpTransceiverDirection audio_direction, |
| 727 | RtpTransceiverDirection video_direction, |
| 728 | absl::optional<size_t>* audio_index, |
| 729 | absl::optional<size_t>* video_index, |
| 730 | absl::optional<size_t>* data_index, |
| 731 | cricket::MediaSessionOptions* session_options) |
| 732 | RTC_RUN_ON(signaling_thread()); |
| 733 |
| 734 | // Generates the active MediaDescriptionOptions for the local data channel |
| 735 | // given the specified MID. |
| 736 | cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForActiveData( |
| 737 | const std::string& mid) const RTC_RUN_ON(signaling_thread()); |
| 738 |
| 739 | // Generates the rejected MediaDescriptionOptions for the local data channel |
| 740 | // given the specified MID. |
| 741 | cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForRejectedData( |
| 742 | const std::string& mid) const RTC_RUN_ON(signaling_thread()); |
| 743 |
| 744 | // Returns the MID for the data section associated with either the |
| 745 | // RtpDataChannel or SCTP data channel, if it has been set. If no data |
| 746 | // channels are configured this will return nullopt. |
| 747 | absl::optional<std::string> GetDataMid() const RTC_RUN_ON(signaling_thread()); |
| 748 |
| 749 | // Remove all local and remote senders of type |media_type|. |
| 750 | // Called when a media type is rejected (m-line set to port 0). |
| 751 | void RemoveSenders(cricket::MediaType media_type) |
| 752 | RTC_RUN_ON(signaling_thread()); |
| 753 |
| 754 | // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|, |
| 755 | // and existing MediaStreamTracks are removed if there is no corresponding |
| 756 | // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack |
| 757 | // is created if it doesn't exist; if false, it's removed if it exists. |
| 758 | // |media_type| is the type of the |streams| and can be either audio or video. |
| 759 | // If a new MediaStream is created it is added to |new_streams|. |
| 760 | void UpdateRemoteSendersList( |
| 761 | const std::vector<cricket::StreamParams>& streams, |
| 762 | bool default_track_needed, |
| 763 | cricket::MediaType media_type, |
| 764 | StreamCollection* new_streams) RTC_RUN_ON(signaling_thread()); |
| 765 |
| 766 | // Triggered when a remote sender has been seen for the first time in a remote |
| 767 | // session description. It creates a remote MediaStreamTrackInterface |
| 768 | // implementation and triggers CreateAudioReceiver or CreateVideoReceiver. |
| 769 | void OnRemoteSenderAdded(const RtpSenderInfo& sender_info, |
| 770 | cricket::MediaType media_type) |
| 771 | RTC_RUN_ON(signaling_thread()); |
| 772 |
| 773 | // Triggered when a remote sender has been removed from a remote session |
| 774 | // description. It removes the remote sender with id |sender_id| from a remote |
| 775 | // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver. |
| 776 | void OnRemoteSenderRemoved(const RtpSenderInfo& sender_info, |
| 777 | cricket::MediaType media_type) |
| 778 | RTC_RUN_ON(signaling_thread()); |
| 779 |
| 780 | // Finds remote MediaStreams without any tracks and removes them from |
| 781 | // |remote_streams_| and notifies the observer that the MediaStreams no longer |
| 782 | // exist. |
| 783 | void UpdateEndedRemoteMediaStreams() RTC_RUN_ON(signaling_thread()); |
| 784 |
| 785 | // Loops through the vector of |streams| and finds added and removed |
| 786 | // StreamParams since last time this method was called. |
| 787 | // For each new or removed StreamParam, OnLocalSenderSeen or |
| 788 | // OnLocalSenderRemoved is invoked. |
| 789 | void UpdateLocalSenders(const std::vector<cricket::StreamParams>& streams, |
| 790 | cricket::MediaType media_type) |
| 791 | RTC_RUN_ON(signaling_thread()); |
| 792 |
| 793 | // Triggered when a local sender has been seen for the first time in a local |
| 794 | // session description. |
| 795 | // This method triggers CreateAudioSender or CreateVideoSender if the rtp |
| 796 | // streams in the local SessionDescription can be mapped to a MediaStreamTrack |
| 797 | // in a MediaStream in |local_streams_| |
| 798 | void OnLocalSenderAdded(const RtpSenderInfo& sender_info, |
| 799 | cricket::MediaType media_type) |
| 800 | RTC_RUN_ON(signaling_thread()); |
| 801 |
| 802 | // Triggered when a local sender has been removed from a local session |
| 803 | // description. |
| 804 | // This method triggers DestroyAudioSender or DestroyVideoSender if a stream |
| 805 | // has been removed from the local SessionDescription and the stream can be |
| 806 | // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|. |
| 807 | void OnLocalSenderRemoved(const RtpSenderInfo& sender_info, |
| 808 | cricket::MediaType media_type) |
| 809 | RTC_RUN_ON(signaling_thread()); |
| 810 |
| 811 | // Returns true if the PeerConnection is configured to use Unified Plan |
| 812 | // semantics for creating offers/answers and setting local/remote |
| 813 | // descriptions. If this is true the RtpTransceiver API will also be available |
| 814 | // to the user. If this is false, Plan B semantics are assumed. |
| 815 | // TODO(bugs.webrtc.org/8530): Flip the default to be Unified Plan once |
| 816 | // sufficient time has passed. |
| 817 | bool IsUnifiedPlan() const RTC_RUN_ON(signaling_thread()) { |
| 818 | return configuration_.sdp_semantics == SdpSemantics::kUnifiedPlan; |
| 819 | } |
| 820 |
| 821 | // The offer/answer machinery assumes the media section MID is present and |
| 822 | // unique. To support legacy end points that do not supply a=mid lines, this |
| 823 | // method will modify the session description to add MIDs generated according |
| 824 | // to the SDP semantics. |
| 825 | void FillInMissingRemoteMids(cricket::SessionDescription* remote_description) |
| 826 | RTC_RUN_ON(signaling_thread()); |
| 827 |
| 828 | // Return the RtpSender with the given track attached. |
| 829 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> |
| 830 | FindSenderForTrack(MediaStreamTrackInterface* track) const |
| 831 | RTC_RUN_ON(signaling_thread()); |
| 832 |
| 833 | // Return the RtpSender with the given id, or null if none exists. |
| 834 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> |
| 835 | FindSenderById(const std::string& sender_id) const |
| 836 | RTC_RUN_ON(signaling_thread()); |
| 837 |
| 838 | // Return the RtpReceiver with the given id, or null if none exists. |
| 839 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>> |
| 840 | FindReceiverById(const std::string& receiver_id) const |
| 841 | RTC_RUN_ON(signaling_thread()); |
| 842 |
| 843 | std::vector<RtpSenderInfo>* GetRemoteSenderInfos( |
| 844 | cricket::MediaType media_type); |
| 845 | std::vector<RtpSenderInfo>* GetLocalSenderInfos( |
| 846 | cricket::MediaType media_type); |
| 847 | const RtpSenderInfo* FindSenderInfo(const std::vector<RtpSenderInfo>& infos, |
| 848 | const std::string& stream_id, |
| 849 | const std::string sender_id) const; |
| 850 |
| 851 | // Returns the specified SCTP DataChannel in sctp_data_channels_, |
| 852 | // or nullptr if not found. |
| 853 | SctpDataChannel* FindDataChannelBySid(int sid) const |
| 854 | RTC_RUN_ON(signaling_thread()); |
| 855 |
| 856 | // Called when first configuring the port allocator. |
| 857 | struct InitializePortAllocatorResult { |
| 858 | bool enable_ipv6; |
| 859 | }; |
| 860 | InitializePortAllocatorResult InitializePortAllocator_n( |
| 861 | const cricket::ServerAddresses& stun_servers, |
| 862 | const std::vector<cricket::RelayServerConfig>& turn_servers, |
| 863 | const RTCConfiguration& configuration); |
| 864 | // Called when SetConfiguration is called to apply the supported subset |
| 865 | // of the configuration on the network thread. |
| 866 | bool ReconfigurePortAllocator_n( |
| 867 | const cricket::ServerAddresses& stun_servers, |
| 868 | const std::vector<cricket::RelayServerConfig>& turn_servers, |
| 869 | IceTransportsType type, |
| 870 | int candidate_pool_size, |
| 871 | PortPrunePolicy turn_port_prune_policy, |
| 872 | webrtc::TurnCustomizer* turn_customizer, |
| 873 | absl::optional<int> stun_candidate_keepalive_interval, |
| 874 | bool have_local_description); |
| 875 |
| 876 | // Starts output of an RTC event log to the given output object. |
| 877 | // This function should only be called from the worker thread. |
| 878 | bool StartRtcEventLog_w(std::unique_ptr<RtcEventLogOutput> output, |
| 879 | int64_t output_period_ms); |
| 880 |
| 881 | // Stops recording an RTC event log. |
| 882 | // This function should only be called from the worker thread. |
| 883 | void StopRtcEventLog_w(); |
| 884 |
| 885 | // Ensures the configuration doesn't have any parameters with invalid values, |
| 886 | // or values that conflict with other parameters. |
| 887 | // |
| 888 | // Returns RTCError::OK() if there are no issues. |
| 889 | RTCError ValidateConfiguration(const RTCConfiguration& config) const; |
| 890 |
| 891 | cricket::ChannelManager* channel_manager() const; |
| 892 |
| 893 | enum class SessionError { |
| 894 | kNone, // No error. |
| 895 | kContent, // Error in BaseChannel SetLocalContent/SetRemoteContent. |
| 896 | kTransport, // Error from the underlying transport. |
| 897 | }; |
| 898 |
| 899 | // Returns the last error in the session. See the enum above for details. |
| 900 | SessionError session_error() const RTC_RUN_ON(signaling_thread()) { |
| 901 | return session_error_; |
| 902 | } |
| 903 | const std::string& session_error_desc() const { return session_error_desc_; } |
| 904 |
| 905 | cricket::ChannelInterface* GetChannel(const std::string& content_name); |
| 906 |
| 907 | cricket::IceConfig ParseIceConfig( |
| 908 | const PeerConnectionInterface::RTCConfiguration& config) const; |
| 909 |
| 910 | cricket::DataChannelType data_channel_type() const; |
| 911 |
| 912 | // Called when an RTCCertificate is generated or retrieved by |
| 913 | // WebRTCSessionDescriptionFactory. Should happen before setLocalDescription. |
| 914 | void OnCertificateReady( |
| 915 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
| 916 | void OnDtlsSrtpSetupFailure(cricket::BaseChannel*, bool rtcp); |
| 917 |
| 918 | // Non-const versions of local_description()/remote_description(), for use |
| 919 | // internally. |
| 920 | SessionDescriptionInterface* mutable_local_description() |
| 921 | RTC_RUN_ON(signaling_thread()) { |
| 922 | return pending_local_description_ ? pending_local_description_.get() |
| 923 | : current_local_description_.get(); |
| 924 | } |
| 925 | SessionDescriptionInterface* mutable_remote_description() |
| 926 | RTC_RUN_ON(signaling_thread()) { |
| 927 | return pending_remote_description_ ? pending_remote_description_.get() |
| 928 | : current_remote_description_.get(); |
| 929 | } |
| 930 |
| 931 | // Updates the error state, signaling if necessary. |
| 932 | void SetSessionError(SessionError error, const std::string& error_desc); |
| 933 |
| 934 | RTCError UpdateSessionState(SdpType type, |
| 935 | cricket::ContentSource source, |
| 936 | const cricket::SessionDescription* description); |
| 937 | // Push the media parts of the local or remote session description |
| 938 | // down to all of the channels. |
| 939 | RTCError PushdownMediaDescription(SdpType type, cricket::ContentSource source) |
| 940 | RTC_RUN_ON(signaling_thread()); |
| 941 |
| 942 | RTCError PushdownTransportDescription(cricket::ContentSource source, |
| 943 | SdpType type); |
| 944 |
| 945 | // Returns true and the TransportInfo of the given |content_name| |
| 946 | // from |description|. Returns false if it's not available. |
| 947 | static bool GetTransportDescription( |
| 948 | const cricket::SessionDescription* description, |
| 949 | const std::string& content_name, |
| 950 | cricket::TransportDescription* info); |
| 951 |
| 952 | // Enables media channels to allow sending of media. |
| 953 | // This enables media to flow on all configured audio/video channels and the |
| 954 | // RtpDataChannel. |
| 955 | void EnableSending() RTC_RUN_ON(signaling_thread()); |
| 956 |
| 957 | // Destroys all BaseChannels and destroys the SCTP data channel, if present. |
| 958 | void DestroyAllChannels() RTC_RUN_ON(signaling_thread()); |
| 959 |
| 960 | // Returns the media index for a local ice candidate given the content name. |
| 961 | // Returns false if the local session description does not have a media |
| 962 | // content called |content_name|. |
| 963 | bool GetLocalCandidateMediaIndex(const std::string& content_name, |
| 964 | int* sdp_mline_index) |
| 965 | RTC_RUN_ON(signaling_thread()); |
| 966 | // Uses all remote candidates in |remote_desc| in this session. |
| 967 | bool UseCandidatesInSessionDescription( |
| 968 | const SessionDescriptionInterface* remote_desc) |
| 969 | RTC_RUN_ON(signaling_thread()); |
| 970 | // Uses |candidate| in this session. |
| 971 | bool UseCandidate(const IceCandidateInterface* candidate) |
| 972 | RTC_RUN_ON(signaling_thread()); |
| 973 | RTCErrorOr<const cricket::ContentInfo*> FindContentInfo( |
| 974 | const SessionDescriptionInterface* description, |
| 975 | const IceCandidateInterface* candidate) RTC_RUN_ON(signaling_thread()); |
| 976 | // Deletes the corresponding channel of contents that don't exist in |desc|. |
| 977 | // |desc| can be null. This means that all channels are deleted. |
| 978 | void RemoveUnusedChannels(const cricket::SessionDescription* desc) |
| 979 | RTC_RUN_ON(signaling_thread()); |
| 980 |
| 981 | // Allocates media channels based on the |desc|. If |desc| doesn't have |
| 982 | // the BUNDLE option, this method will disable BUNDLE in PortAllocator. |
| 983 | // This method will also delete any existing media channels before creating. |
| 984 | RTCError CreateChannels(const cricket::SessionDescription& desc) |
| 985 | RTC_RUN_ON(signaling_thread()); |
| 986 |
| 987 | // If the BUNDLE policy is max-bundle, then we know for sure that all |
| 988 | // transports will be bundled from the start. This method returns the BUNDLE |
| 989 | // group if that's the case, or null if BUNDLE will be negotiated later. An |
| 990 | // error is returned if max-bundle is specified but the session description |
| 991 | // does not have a BUNDLE group. |
| 992 | RTCErrorOr<const cricket::ContentGroup*> GetEarlyBundleGroup( |
| 993 | const cricket::SessionDescription& desc) const |
| 994 | RTC_RUN_ON(signaling_thread()); |
| 995 |
| 996 | // Helper methods to create media channels. |
| 997 | cricket::VoiceChannel* CreateVoiceChannel(const std::string& mid) |
| 998 | RTC_RUN_ON(signaling_thread()); |
| 999 | cricket::VideoChannel* CreateVideoChannel(const std::string& mid) |
| 1000 | RTC_RUN_ON(signaling_thread()); |
| 1001 | bool CreateDataChannel(const std::string& mid) RTC_RUN_ON(signaling_thread()); |
| 1002 |
| 1003 | bool SetupDataChannelTransport_n(const std::string& mid) |
| 1004 | RTC_RUN_ON(network_thread()); |
| 1005 | void TeardownDataChannelTransport_n() RTC_RUN_ON(network_thread()); |
| 1006 |
| 1007 | bool ValidateBundleSettings(const cricket::SessionDescription* desc); |
| 1008 | bool HasRtcpMuxEnabled(const cricket::ContentInfo* content); |
| 1009 | // Below methods are helper methods which verifies SDP. |
| 1010 | RTCError ValidateSessionDescription(const SessionDescriptionInterface* sdesc, |
| 1011 | cricket::ContentSource source) |
| 1012 | RTC_RUN_ON(signaling_thread()); |
| 1013 |
| 1014 | // Check if a call to SetLocalDescription is acceptable with a session |
| 1015 | // description of the given type. |
| 1016 | bool ExpectSetLocalDescription(SdpType type); |
| 1017 | // Check if a call to SetRemoteDescription is acceptable with a session |
| 1018 | // description of the given type. |
| 1019 | bool ExpectSetRemoteDescription(SdpType type); |
| 1020 | // Verifies a=setup attribute as per RFC 5763. |
| 1021 | bool ValidateDtlsSetupAttribute(const cricket::SessionDescription* desc, |
| 1022 | SdpType type); |
| 1023 |
| 1024 | // Returns true if we are ready to push down the remote candidate. |
| 1025 | // |remote_desc| is the new remote description, or NULL if the current remote |
| 1026 | // description should be used. Output |valid| is true if the candidate media |
| 1027 | // index is valid. |
| 1028 | bool ReadyToUseRemoteCandidate(const IceCandidateInterface* candidate, |
| 1029 | const SessionDescriptionInterface* remote_desc, |
| 1030 | bool* valid) RTC_RUN_ON(signaling_thread()); |
| 1031 |
| 1032 | // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by |
| 1033 | // this session. |
| 1034 | bool SrtpRequired() const RTC_RUN_ON(signaling_thread()); |
| 1035 |
| 1036 | // JsepTransportController signal handlers. |
| 1037 | void OnTransportControllerConnectionState(cricket::IceConnectionState state) |
| 1038 | RTC_RUN_ON(signaling_thread()); |
| 1039 | void OnTransportControllerGatheringState(cricket::IceGatheringState state) |
| 1040 | RTC_RUN_ON(signaling_thread()); |
| 1041 | void OnTransportControllerCandidatesGathered( |
| 1042 | const std::string& transport_name, |
| 1043 | const std::vector<cricket::Candidate>& candidates) |
| 1044 | RTC_RUN_ON(signaling_thread()); |
| 1045 | void OnTransportControllerCandidateError( |
| 1046 | const cricket::IceCandidateErrorEvent& event) |
| 1047 | RTC_RUN_ON(signaling_thread()); |
| 1048 | void OnTransportControllerCandidatesRemoved( |
| 1049 | const std::vector<cricket::Candidate>& candidates) |
| 1050 | RTC_RUN_ON(signaling_thread()); |
| 1051 | void OnTransportControllerCandidateChanged( |
| 1052 | const cricket::CandidatePairChangeEvent& event) |
| 1053 | RTC_RUN_ON(signaling_thread()); |
| 1054 | void OnTransportControllerDtlsHandshakeError(rtc::SSLHandshakeError error); |
| 1055 |
| 1056 | const char* SessionErrorToString(SessionError error) const; |
| 1057 | std::string GetSessionErrorMsg() RTC_RUN_ON(signaling_thread()); |
| 1058 |
| 1059 | // Report the UMA metric SdpFormatReceived for the given remote offer. |
| 1060 | void ReportSdpFormatReceived(const SessionDescriptionInterface& remote_offer); |
| 1061 |
| 1062 | // Report inferred negotiated SDP semantics from a local/remote answer to the |
| 1063 | // UMA observer. |
| 1064 | void ReportNegotiatedSdpSemantics(const SessionDescriptionInterface& answer); |
| 1065 |
| 1066 | // Invoked when TransportController connection completion is signaled. |
| 1067 | // Reports stats for all transports in use. |
| 1068 | void ReportTransportStats() RTC_RUN_ON(signaling_thread()); |
| 1069 |
| 1070 | // Gather the usage of IPv4/IPv6 as best connection. |
| 1071 | void ReportBestConnectionState(const cricket::TransportStats& stats); |
| 1072 |
| 1073 | void ReportNegotiatedCiphers(const cricket::TransportStats& stats, |
| 1074 | const std::set<cricket::MediaType>& media_types) |
| 1075 | RTC_RUN_ON(signaling_thread()); |
| 1076 | void ReportIceCandidateCollected(const cricket::Candidate& candidate) |
| 1077 | RTC_RUN_ON(signaling_thread()); |
| 1078 | void ReportRemoteIceCandidateAdded(const cricket::Candidate& candidate) |
| 1079 | RTC_RUN_ON(signaling_thread()); |
| 1080 |
| 1081 | void NoteUsageEvent(UsageEvent event); |
| 1082 | void ReportUsagePattern() const RTC_RUN_ON(signaling_thread()); |
| 1083 |
| 1084 | void OnSentPacket_w(const rtc::SentPacket& sent_packet); |
| 1085 |
| 1086 | const std::string GetTransportName(const std::string& content_name) |
| 1087 | RTC_RUN_ON(signaling_thread()); |
| 1088 |
| 1089 | // Functions for dealing with transports. |
| 1090 | // Note that cricket code uses the term "channel" for what other code |
| 1091 | // refers to as "transport". |
| 1092 |
| 1093 | // Destroys and clears the BaseChannel associated with the given transceiver, |
| 1094 | // if such channel is set. |
| 1095 | void DestroyTransceiverChannel( |
| 1096 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 1097 | transceiver); |
| 1098 |
| 1099 | // Destroys the RTP data channel transport and/or the SCTP data channel |
| 1100 | // transport and clears it. |
| 1101 | void DestroyDataChannelTransport() RTC_RUN_ON(signaling_thread()); |
| 1102 |
| 1103 | // Destroys the given ChannelInterface. |
| 1104 | // The channel cannot be accessed after this method is called. |
| 1105 | void DestroyChannelInterface(cricket::ChannelInterface* channel); |
| 1106 |
| 1107 | // JsepTransportController::Observer override. |
| 1108 | // |
| 1109 | // Called by |transport_controller_| when processing transport information |
| 1110 | // from a session description, and the mapping from m= sections to transports |
| 1111 | // changed (as a result of BUNDLE negotiation, or m= sections being |
| 1112 | // rejected). |
| 1113 | bool OnTransportChanged( |
| 1114 | const std::string& mid, |
| 1115 | RtpTransportInternal* rtp_transport, |
| 1116 | rtc::scoped_refptr<DtlsTransport> dtls_transport, |
| 1117 | DataChannelTransportInterface* data_channel_transport) override; |
| 1118 |
| 1119 | // RtpSenderBase::SetStreamsObserver override. |
| 1120 | void OnSetStreams() override; |
| 1121 |
| 1122 | // Returns the CryptoOptions for this PeerConnection. This will always |
| 1123 | // return the RTCConfiguration.crypto_options if set and will only default |
| 1124 | // back to the PeerConnectionFactory settings if nothing was set. |
| 1125 | CryptoOptions GetCryptoOptions() RTC_RUN_ON(signaling_thread()); |
| 1126 |
| 1127 | // Returns rtp transport, result can not be nullptr. |
| 1128 | RtpTransportInternal* GetRtpTransport(const std::string& mid) |
| 1129 | RTC_RUN_ON(signaling_thread()) { |
| 1130 | auto rtp_transport = transport_controller_->GetRtpTransport(mid); |
| 1131 | RTC_DCHECK(rtp_transport); |
| 1132 | return rtp_transport; |
| 1133 | } |
| 1134 |
| 1135 | void UpdateNegotiationNeeded(); |
| 1136 | bool CheckIfNegotiationIsNeeded(); |
| 1137 |
| 1138 | // | sdp_type | is the type of the SDP that caused the rollback. |
| 1139 | RTCError Rollback(SdpType sdp_type); |
| 1140 |
| 1141 | // Storing the factory as a scoped reference pointer ensures that the memory |
| 1142 | // in the PeerConnectionFactoryImpl remains available as long as the |
| 1143 | // PeerConnection is running. It is passed to PeerConnection as a raw pointer. |
| 1144 | // However, since the reference counting is done in the |
| 1145 | // PeerConnectionFactoryInterface all instances created using the raw pointer |
| 1146 | // will refer to the same reference count. |
| 1147 | const rtc::scoped_refptr<PeerConnectionFactory> factory_; |
| 1148 | PeerConnectionObserver* observer_ RTC_GUARDED_BY(signaling_thread()) = |
| 1149 | nullptr; |
| 1150 |
| 1151 | // The EventLog needs to outlive |call_| (and any other object that uses it). |
| 1152 | std::unique_ptr<RtcEventLog> event_log_ RTC_GUARDED_BY(worker_thread()); |
| 1153 |
| 1154 | // Points to the same thing as `event_log_`. Since it's const, we may read the |
| 1155 | // pointer (but not touch the object) from any thread. |
| 1156 | RtcEventLog* const event_log_ptr_ RTC_PT_GUARDED_BY(worker_thread()); |
| 1157 |
| 1158 | // The operations chain is used by the offer/answer exchange methods to ensure |
| 1159 | // they are executed in the right order. For example, if |
| 1160 | // SetRemoteDescription() is invoked while CreateOffer() is still pending, the |
| 1161 | // SRD operation will not start until CreateOffer() has completed. See |
| 1162 | // https://w3c.github.io/webrtc-pc/#dfn-operations-chain. |
| 1163 | rtc::scoped_refptr<rtc::OperationsChain> operations_chain_ |
| 1164 | RTC_GUARDED_BY(signaling_thread()); |
| 1165 |
| 1166 | SignalingState signaling_state_ RTC_GUARDED_BY(signaling_thread()) = kStable; |
| 1167 | IceConnectionState ice_connection_state_ RTC_GUARDED_BY(signaling_thread()) = |
| 1168 | kIceConnectionNew; |
| 1169 | PeerConnectionInterface::IceConnectionState standardized_ice_connection_state_ |
| 1170 | RTC_GUARDED_BY(signaling_thread()) = kIceConnectionNew; |
| 1171 | PeerConnectionInterface::PeerConnectionState connection_state_ |
| 1172 | RTC_GUARDED_BY(signaling_thread()) = PeerConnectionState::kNew; |
| 1173 |
| 1174 | IceGatheringState ice_gathering_state_ RTC_GUARDED_BY(signaling_thread()) = |
| 1175 | kIceGatheringNew; |
| 1176 | PeerConnectionInterface::RTCConfiguration configuration_ |
| 1177 | RTC_GUARDED_BY(signaling_thread()); |
| 1178 |
| 1179 | // TODO(zstein): |async_resolver_factory_| can currently be nullptr if it |
| 1180 | // is not injected. It should be required once chromium supplies it. |
| 1181 | std::unique_ptr<AsyncResolverFactory> async_resolver_factory_ |
| 1182 | RTC_GUARDED_BY(signaling_thread()); |
| 1183 | std::unique_ptr<cricket::PortAllocator> |
| 1184 | port_allocator_; // TODO(bugs.webrtc.org/9987): Accessed on both |
| 1185 | // signaling and network thread. |
| 1186 | std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory_; |
| 1187 | std::unique_ptr<webrtc::IceTransportFactory> |
| 1188 | ice_transport_factory_; // TODO(bugs.webrtc.org/9987): Accessed on the |
| 1189 | // signaling thread but the underlying raw |
| 1190 | // pointer is given to |
| 1191 | // |jsep_transport_controller_| and used on the |
| 1192 | // network thread. |
| 1193 | std::unique_ptr<rtc::SSLCertificateVerifier> |
| 1194 | tls_cert_verifier_; // TODO(bugs.webrtc.org/9987): Accessed on both |
| 1195 | // signaling and network thread. |
| 1196 |
| 1197 | // One PeerConnection has only one RTCP CNAME. |
| 1198 | // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9 |
| 1199 | const std::string rtcp_cname_; |
| 1200 |
| 1201 | // Streams added via AddStream. |
| 1202 | const rtc::scoped_refptr<StreamCollection> local_streams_ |
| 1203 | RTC_GUARDED_BY(signaling_thread()); |
| 1204 | // Streams created as a result of SetRemoteDescription. |
| 1205 | const rtc::scoped_refptr<StreamCollection> remote_streams_ |
| 1206 | RTC_GUARDED_BY(signaling_thread()); |
| 1207 |
| 1208 | std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_ |
| 1209 | RTC_GUARDED_BY(signaling_thread()); |
| 1210 |
| 1211 | // These lists store sender info seen in local/remote descriptions. |
| 1212 | std::vector<RtpSenderInfo> remote_audio_sender_infos_ |
| 1213 | RTC_GUARDED_BY(signaling_thread()); |
| 1214 | std::vector<RtpSenderInfo> remote_video_sender_infos_ |
| 1215 | RTC_GUARDED_BY(signaling_thread()); |
| 1216 | std::vector<RtpSenderInfo> local_audio_sender_infos_ |
| 1217 | RTC_GUARDED_BY(signaling_thread()); |
| 1218 | std::vector<RtpSenderInfo> local_video_sender_infos_ |
| 1219 | RTC_GUARDED_BY(signaling_thread()); |
| 1220 |
| 1221 | bool remote_peer_supports_msid_ RTC_GUARDED_BY(signaling_thread()) = false; |
| 1222 |
| 1223 | // The unique_ptr belongs to the worker thread, but the Call object manages |
| 1224 | // its own thread safety. |
| 1225 | std::unique_ptr<Call> call_ RTC_GUARDED_BY(worker_thread()); |
| 1226 |
| 1227 | rtc::AsyncInvoker rtcp_invoker_ RTC_GUARDED_BY(network_thread()); |
| 1228 |
| 1229 | // Points to the same thing as `call_`. Since it's const, we may read the |
| 1230 | // pointer from any thread. |
| 1231 | Call* const call_ptr_; |
| 1232 |
| 1233 | std::unique_ptr<StatsCollector> stats_ |
| 1234 | RTC_GUARDED_BY(signaling_thread()); // A pointer is passed to senders_ |
| 1235 | rtc::scoped_refptr<RTCStatsCollector> stats_collector_ |
| 1236 | RTC_GUARDED_BY(signaling_thread()); |
| 1237 | // Holds changes made to transceivers during applying descriptors for |
| 1238 | // potential rollback. Gets cleared once signaling state goes to stable. |
| 1239 | std::map<rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>, |
| 1240 | TransceiverStableState> |
| 1241 | transceiver_stable_states_by_transceivers_; |
| 1242 | // Used when rolling back RTP data channels. |
| 1243 | bool have_pending_rtp_data_channel_ RTC_GUARDED_BY(signaling_thread()) = |
| 1244 | false; |
| 1245 | // Holds remote stream ids for transceivers from stable state. |
| 1246 | std::map<rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>, |
| 1247 | std::vector<std::string>> |
| 1248 | remote_stream_ids_by_transceivers_; |
| 1249 | std::vector< |
| 1250 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
| 1251 | transceivers_; // TODO(bugs.webrtc.org/9987): Accessed on both signaling |
| 1252 | // and network thread. |
| 1253 |
| 1254 | // In Unified Plan, if we encounter remote SDP that does not contain an a=msid |
| 1255 | // line we create and use a stream with a random ID for our receivers. This is |
| 1256 | // to support legacy endpoints that do not support the a=msid attribute (as |
| 1257 | // opposed to streamless tracks with "a=msid:-"). |
| 1258 | rtc::scoped_refptr<MediaStreamInterface> missing_msid_default_stream_ |
| 1259 | RTC_GUARDED_BY(signaling_thread()); |
| 1260 | // MIDs will be generated using this generator which will keep track of |
| 1261 | // all the MIDs that have been seen over the life of the PeerConnection. |
| 1262 | rtc::UniqueStringGenerator mid_generator_ RTC_GUARDED_BY(signaling_thread()); |
| 1263 |
| 1264 | SessionError session_error_ RTC_GUARDED_BY(signaling_thread()) = |
| 1265 | SessionError::kNone; |
| 1266 | std::string session_error_desc_ RTC_GUARDED_BY(signaling_thread()); |
| 1267 |
| 1268 | std::string session_id_ RTC_GUARDED_BY(signaling_thread()); |
| 1269 |
| 1270 | std::unique_ptr<JsepTransportController> |
| 1271 | transport_controller_; // TODO(bugs.webrtc.org/9987): Accessed on both |
| 1272 | // signaling and network thread. |
| 1273 | std::unique_ptr<cricket::SctpTransportInternalFactory> |
| 1274 | sctp_factory_; // TODO(bugs.webrtc.org/9987): Accessed on both |
| 1275 | // signaling and network thread. |
| 1276 |
| 1277 | // |sctp_mid_| is the content name (MID) in SDP. |
| 1278 | // Note: this is used as the data channel MID by both SCTP and data channel |
| 1279 | // transports. It is set when either transport is initialized and unset when |
| 1280 | // both transports are deleted. |
| 1281 | // There is one copy on the signaling thread and another copy on the |
| 1282 | // networking thread. Changes are always initiated from the signaling |
| 1283 | // thread, but applied first on the networking thread via an invoke(). |
| 1284 | absl::optional<std::string> sctp_mid_s_ RTC_GUARDED_BY(signaling_thread()); |
| 1285 | absl::optional<std::string> sctp_mid_n_ RTC_GUARDED_BY(network_thread()); |
| 1286 |
| 1287 | // Whether this peer is the caller. Set when the local description is applied. |
| 1288 | absl::optional<bool> is_caller_ RTC_GUARDED_BY(signaling_thread()); |
| 1289 |
| 1290 |
| 1291 |
| 1292 | std::unique_ptr<SessionDescriptionInterface> current_local_description_ |
| 1293 | RTC_GUARDED_BY(signaling_thread()); |
| 1294 | std::unique_ptr<SessionDescriptionInterface> pending_local_description_ |
| 1295 | RTC_GUARDED_BY(signaling_thread()); |
| 1296 | std::unique_ptr<SessionDescriptionInterface> current_remote_description_ |
| 1297 | RTC_GUARDED_BY(signaling_thread()); |
| 1298 | std::unique_ptr<SessionDescriptionInterface> pending_remote_description_ |
| 1299 | RTC_GUARDED_BY(signaling_thread()); |
| 1300 | bool dtls_enabled_ RTC_GUARDED_BY(signaling_thread()) = false; |
| 1301 |
| 1302 | // List of content names for which the remote side triggered an ICE restart. |
| 1303 | std::set<std::string> pending_ice_restarts_ |
| 1304 | RTC_GUARDED_BY(signaling_thread()); |
| 1305 |
| 1306 | std::unique_ptr<WebRtcSessionDescriptionFactory> webrtc_session_desc_factory_ |
| 1307 | RTC_GUARDED_BY(signaling_thread()); |
| 1308 |
| 1309 | // Member variables for caching global options. |
| 1310 | cricket::AudioOptions audio_options_ RTC_GUARDED_BY(signaling_thread()); |
| 1311 | cricket::VideoOptions video_options_ RTC_GUARDED_BY(signaling_thread()); |
| 1312 |
| 1313 | int usage_event_accumulator_ RTC_GUARDED_BY(signaling_thread()) = 0; |
| 1314 | bool return_histogram_very_quickly_ RTC_GUARDED_BY(signaling_thread()) = |
| 1315 | false; |
| 1316 |
| 1317 | // This object should be used to generate any SSRC that is not explicitly |
| 1318 | // specified by the user (or by the remote party). |
| 1319 | // The generator is not used directly, instead it is passed on to the |
| 1320 | // channel manager and the session description factory. |
| 1321 | rtc::UniqueRandomIdGenerator ssrc_generator_ |
| 1322 | RTC_GUARDED_BY(signaling_thread()); |
| 1323 |
| 1324 | // A video bitrate allocator factory. |
| 1325 | // This can injected using the PeerConnectionDependencies, |
| 1326 | // or else the CreateBuiltinVideoBitrateAllocatorFactory() will be called. |
| 1327 | // Note that one can still choose to override this in a MediaEngine |
| 1328 | // if one wants too. |
| 1329 | std::unique_ptr<webrtc::VideoBitrateAllocatorFactory> |
| 1330 | video_bitrate_allocator_factory_; |
| 1331 |
| 1332 | std::unique_ptr<LocalIceCredentialsToReplace> |
| 1333 | local_ice_credentials_to_replace_ RTC_GUARDED_BY(signaling_thread()); |
| 1334 | bool is_negotiation_needed_ RTC_GUARDED_BY(signaling_thread()) = false; |
| 1335 |
| 1336 | DataChannelController data_channel_controller_; |
| 1337 | rtc::WeakPtrFactory<PeerConnection> weak_ptr_factory_ |
| 1338 | RTC_GUARDED_BY(signaling_thread()); |
| 1339 | }; |
| 1340 |
| 1341 | } // namespace webrtc |
| 1342 |
| 1343 | #endif // PC_PEER_CONNECTION_H_ |
| 1344 |