Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 PC_SDP_OFFER_ANSWER_H_ |
| 12 | #define PC_SDP_OFFER_ANSWER_H_ |
| 13 | |
| 14 | #include <map> |
| 15 | #include <memory> |
| 16 | #include <set> |
| 17 | #include <string> |
| 18 | #include <utility> |
| 19 | #include <vector> |
| 20 | |
| 21 | #include "api/jsep_ice_candidate.h" |
| 22 | #include "api/peer_connection_interface.h" |
| 23 | #include "api/transport/data_channel_transport_interface.h" |
| 24 | #include "api/turn_customizer.h" |
| 25 | #include "pc/data_channel_controller.h" |
| 26 | #include "pc/ice_server_parsing.h" |
| 27 | #include "pc/jsep_transport_controller.h" |
| 28 | #include "pc/peer_connection_factory.h" |
| 29 | #include "pc/peer_connection_internal.h" |
| 30 | #include "pc/rtc_stats_collector.h" |
| 31 | #include "pc/rtp_sender.h" |
| 32 | #include "pc/rtp_transceiver.h" |
| 33 | #include "pc/sctp_transport.h" |
| 34 | #include "pc/stats_collector.h" |
| 35 | #include "pc/stream_collection.h" |
| 36 | #include "pc/webrtc_session_description_factory.h" |
| 37 | #include "rtc_base/experiments/field_trial_parser.h" |
| 38 | #include "rtc_base/operations_chain.h" |
| 39 | #include "rtc_base/race_checker.h" |
| 40 | #include "rtc_base/unique_id_generator.h" |
| 41 | #include "rtc_base/weak_ptr.h" |
| 42 | |
| 43 | namespace webrtc { |
| 44 | |
| 45 | class MediaStreamObserver; |
| 46 | class PeerConnection; |
| 47 | class VideoRtpReceiver; |
| 48 | class RtcEventLog; |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 +0000 | [diff] [blame] | 49 | class TransceiverList; |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 50 | |
| 51 | // SdpOfferAnswerHandler is a component |
| 52 | // of the PeerConnection object as defined |
| 53 | // by the PeerConnectionInterface API surface. |
| 54 | // The class is responsible for the following: |
| 55 | // - Parsing and interpreting SDP. |
| 56 | // - Generating offers and answers based on the current state. |
| 57 | // This class lives on the signaling thread. |
| 58 | class SdpOfferAnswerHandler { |
| 59 | public: |
| 60 | explicit SdpOfferAnswerHandler(PeerConnection* pc); |
| 61 | ~SdpOfferAnswerHandler(); |
| 62 | |
| 63 | void SetSessionDescFactory( |
| 64 | std::unique_ptr<WebRtcSessionDescriptionFactory> factory) { |
| 65 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 66 | webrtc_session_desc_factory_ = std::move(factory); |
| 67 | } |
| 68 | void ResetSessionDescFactory() { |
| 69 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 70 | webrtc_session_desc_factory_.reset(); |
| 71 | } |
| 72 | const WebRtcSessionDescriptionFactory* webrtc_session_desc_factory() const { |
| 73 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 74 | return webrtc_session_desc_factory_.get(); |
| 75 | } |
| 76 | |
| 77 | // Change signaling state to Closed, and perform appropriate actions. |
| 78 | void Close(); |
| 79 | |
| 80 | // Called as part of destroying the owning PeerConnection. |
| 81 | void PrepareForShutdown(); |
| 82 | |
| 83 | PeerConnectionInterface::SignalingState signaling_state() const; |
| 84 | |
| 85 | const SessionDescriptionInterface* local_description() const; |
| 86 | const SessionDescriptionInterface* remote_description() const; |
| 87 | const SessionDescriptionInterface* current_local_description() const; |
| 88 | const SessionDescriptionInterface* current_remote_description() const; |
| 89 | const SessionDescriptionInterface* pending_local_description() const; |
| 90 | const SessionDescriptionInterface* pending_remote_description() const; |
| 91 | |
| 92 | void RestartIce(); |
| 93 | |
| 94 | // JSEP01 |
| 95 | void CreateOffer( |
| 96 | CreateSessionDescriptionObserver* observer, |
| 97 | const PeerConnectionInterface::RTCOfferAnswerOptions& options); |
| 98 | void CreateAnswer( |
| 99 | CreateSessionDescriptionObserver* observer, |
| 100 | const PeerConnectionInterface::RTCOfferAnswerOptions& options); |
| 101 | |
| 102 | void SetLocalDescription( |
| 103 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 104 | rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer); |
| 105 | void SetLocalDescription( |
| 106 | rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer); |
| 107 | void SetLocalDescription(SetSessionDescriptionObserver* observer, |
| 108 | SessionDescriptionInterface* desc); |
| 109 | void SetLocalDescription(SetSessionDescriptionObserver* observer); |
| 110 | |
| 111 | void SetRemoteDescription( |
| 112 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 113 | rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer); |
| 114 | void SetRemoteDescription(SetSessionDescriptionObserver* observer, |
| 115 | SessionDescriptionInterface* desc); |
| 116 | |
| 117 | PeerConnectionInterface::RTCConfiguration GetConfiguration(); |
| 118 | RTCError SetConfiguration( |
| 119 | const PeerConnectionInterface::RTCConfiguration& configuration); |
| 120 | bool AddIceCandidate(const IceCandidateInterface* candidate); |
| 121 | void AddIceCandidate(std::unique_ptr<IceCandidateInterface> candidate, |
| 122 | std::function<void(RTCError)> callback); |
| 123 | bool RemoveIceCandidates(const std::vector<cricket::Candidate>& candidates); |
| 124 | // Adds a locally generated candidate to the local description. |
| 125 | void AddLocalIceCandidate(const JsepIceCandidate* candidate); |
| 126 | void RemoveLocalIceCandidates( |
| 127 | const std::vector<cricket::Candidate>& candidates); |
| 128 | bool ShouldFireNegotiationNeededEvent(uint32_t event_id); |
| 129 | |
Harald Alvestrand | 6f04b65 | 2020-10-09 11:42:17 +0000 | [diff] [blame] | 130 | bool AddStream(MediaStreamInterface* local_stream); |
| 131 | void RemoveStream(MediaStreamInterface* local_stream); |
| 132 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 133 | absl::optional<bool> is_caller(); |
| 134 | bool HasNewIceCredentials(); |
| 135 | bool IceRestartPending(const std::string& content_name) const; |
| 136 | void UpdateNegotiationNeeded(); |
Harald Alvestrand | 75b9ab6 | 2020-09-30 22:17:18 +0000 | [diff] [blame] | 137 | void SetHavePendingRtpDataChannel() { |
| 138 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 139 | have_pending_rtp_data_channel_ = true; |
| 140 | } |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 141 | |
Harald Alvestrand | c06e374 | 2020-10-01 10:23:33 +0000 | [diff] [blame] | 142 | // Returns the media section in the given session description that is |
| 143 | // associated with the RtpTransceiver. Returns null if none found or this |
| 144 | // RtpTransceiver is not associated. Logic varies depending on the |
| 145 | // SdpSemantics specified in the configuration. |
| 146 | const cricket::ContentInfo* FindMediaSectionForTransceiver( |
| 147 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 148 | transceiver, |
| 149 | const SessionDescriptionInterface* sdesc) const; |
| 150 | |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 +0000 | [diff] [blame] | 151 | // Destroys all BaseChannels and destroys the SCTP data channel, if present. |
| 152 | void DestroyAllChannels(); |
| 153 | |
Harald Alvestrand | 6f04b65 | 2020-10-09 11:42:17 +0000 | [diff] [blame] | 154 | rtc::scoped_refptr<StreamCollectionInterface> local_streams(); |
| 155 | rtc::scoped_refptr<StreamCollectionInterface> remote_streams(); |
| 156 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 157 | private: |
| 158 | class ImplicitCreateSessionDescriptionObserver; |
| 159 | friend class ImplicitCreateSessionDescriptionObserver; |
| 160 | class SetSessionDescriptionObserverAdapter; |
| 161 | friend class SetSessionDescriptionObserverAdapter; |
| 162 | |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 +0000 | [diff] [blame] | 163 | enum class SessionError { |
| 164 | kNone, // No error. |
| 165 | kContent, // Error in BaseChannel SetLocalContent/SetRemoteContent. |
| 166 | kTransport, // Error from the underlying transport. |
| 167 | }; |
| 168 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 169 | // Represents the [[LocalIceCredentialsToReplace]] internal slot in the spec. |
| 170 | // It makes the next CreateOffer() produce new ICE credentials even if |
| 171 | // RTCOfferAnswerOptions::ice_restart is false. |
| 172 | // https://w3c.github.io/webrtc-pc/#dfn-localufragstoreplace |
| 173 | // TODO(hbos): When JsepTransportController/JsepTransport supports rollback, |
| 174 | // move this type of logic to JsepTransportController/JsepTransport. |
| 175 | class LocalIceCredentialsToReplace; |
| 176 | |
| 177 | rtc::Thread* signaling_thread() const; |
| 178 | // Non-const versions of local_description()/remote_description(), for use |
| 179 | // internally. |
| 180 | SessionDescriptionInterface* mutable_local_description() |
| 181 | RTC_RUN_ON(signaling_thread()) { |
| 182 | return pending_local_description_ ? pending_local_description_.get() |
| 183 | : current_local_description_.get(); |
| 184 | } |
| 185 | SessionDescriptionInterface* mutable_remote_description() |
| 186 | RTC_RUN_ON(signaling_thread()) { |
| 187 | return pending_remote_description_ ? pending_remote_description_.get() |
| 188 | : current_remote_description_.get(); |
| 189 | } |
| 190 | |
| 191 | // Synchronous implementations of SetLocalDescription/SetRemoteDescription |
| 192 | // that return an RTCError instead of invoking a callback. |
| 193 | RTCError ApplyLocalDescription( |
| 194 | std::unique_ptr<SessionDescriptionInterface> desc); |
| 195 | RTCError ApplyRemoteDescription( |
| 196 | std::unique_ptr<SessionDescriptionInterface> desc); |
| 197 | |
| 198 | // Implementation of the offer/answer exchange operations. These are chained |
| 199 | // onto the |operations_chain_| when the public CreateOffer(), CreateAnswer(), |
| 200 | // SetLocalDescription() and SetRemoteDescription() methods are invoked. |
| 201 | void DoCreateOffer( |
| 202 | const PeerConnectionInterface::RTCOfferAnswerOptions& options, |
| 203 | rtc::scoped_refptr<CreateSessionDescriptionObserver> observer); |
| 204 | void DoCreateAnswer( |
| 205 | const PeerConnectionInterface::RTCOfferAnswerOptions& options, |
| 206 | rtc::scoped_refptr<CreateSessionDescriptionObserver> observer); |
| 207 | void DoSetLocalDescription( |
| 208 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 209 | rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer); |
| 210 | void DoSetRemoteDescription( |
| 211 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 212 | rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer); |
| 213 | |
| 214 | // Update the state, signaling if necessary. |
| 215 | void ChangeSignalingState( |
| 216 | PeerConnectionInterface::SignalingState signaling_state); |
| 217 | |
| 218 | RTCError UpdateSessionState(SdpType type, |
| 219 | cricket::ContentSource source, |
| 220 | const cricket::SessionDescription* description); |
| 221 | |
| 222 | bool IsUnifiedPlan() const RTC_RUN_ON(signaling_thread()); |
| 223 | |
| 224 | // | desc_type | is the type of the description that caused the rollback. |
| 225 | RTCError Rollback(SdpType desc_type); |
| 226 | void OnOperationsChainEmpty(); |
| 227 | |
| 228 | // Runs the algorithm **set the associated remote streams** specified in |
| 229 | // https://w3c.github.io/webrtc-pc/#set-associated-remote-streams. |
| 230 | void SetAssociatedRemoteStreams( |
| 231 | rtc::scoped_refptr<RtpReceiverInternal> receiver, |
| 232 | const std::vector<std::string>& stream_ids, |
| 233 | std::vector<rtc::scoped_refptr<MediaStreamInterface>>* added_streams, |
| 234 | std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams); |
| 235 | |
| 236 | bool CheckIfNegotiationIsNeeded(); |
| 237 | void GenerateNegotiationNeededEvent(); |
| 238 | // Helper method which verifies SDP. |
| 239 | RTCError ValidateSessionDescription(const SessionDescriptionInterface* sdesc, |
| 240 | cricket::ContentSource source) |
| 241 | RTC_RUN_ON(signaling_thread()); |
| 242 | |
| 243 | // Updates the local RtpTransceivers according to the JSEP rules. Called as |
| 244 | // part of setting the local/remote description. |
| 245 | RTCError UpdateTransceiversAndDataChannels( |
| 246 | cricket::ContentSource source, |
| 247 | const SessionDescriptionInterface& new_session, |
| 248 | const SessionDescriptionInterface* old_local_description, |
| 249 | const SessionDescriptionInterface* old_remote_description); |
| 250 | |
| 251 | // Associate the given transceiver according to the JSEP rules. |
| 252 | RTCErrorOr< |
| 253 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
| 254 | AssociateTransceiver(cricket::ContentSource source, |
| 255 | SdpType type, |
| 256 | size_t mline_index, |
| 257 | const cricket::ContentInfo& content, |
| 258 | const cricket::ContentInfo* old_local_content, |
| 259 | const cricket::ContentInfo* old_remote_content) |
| 260 | RTC_RUN_ON(signaling_thread()); |
| 261 | |
| 262 | // If the BUNDLE policy is max-bundle, then we know for sure that all |
| 263 | // transports will be bundled from the start. This method returns the BUNDLE |
| 264 | // group if that's the case, or null if BUNDLE will be negotiated later. An |
| 265 | // error is returned if max-bundle is specified but the session description |
| 266 | // does not have a BUNDLE group. |
| 267 | RTCErrorOr<const cricket::ContentGroup*> GetEarlyBundleGroup( |
| 268 | const cricket::SessionDescription& desc) const |
| 269 | RTC_RUN_ON(signaling_thread()); |
| 270 | |
| 271 | // Either creates or destroys the transceiver's BaseChannel according to the |
| 272 | // given media section. |
| 273 | RTCError UpdateTransceiverChannel( |
| 274 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 275 | transceiver, |
| 276 | const cricket::ContentInfo& content, |
| 277 | const cricket::ContentGroup* bundle_group) RTC_RUN_ON(signaling_thread()); |
| 278 | |
| 279 | // Either creates or destroys the local data channel according to the given |
| 280 | // media section. |
| 281 | RTCError UpdateDataChannel(cricket::ContentSource source, |
| 282 | const cricket::ContentInfo& content, |
| 283 | const cricket::ContentGroup* bundle_group) |
| 284 | RTC_RUN_ON(signaling_thread()); |
Harald Alvestrand | c06e374 | 2020-10-01 10:23:33 +0000 | [diff] [blame] | 285 | // Check if a call to SetLocalDescription is acceptable with a session |
| 286 | // description of the given type. |
| 287 | bool ExpectSetLocalDescription(SdpType type); |
| 288 | // Check if a call to SetRemoteDescription is acceptable with a session |
| 289 | // description of the given type. |
| 290 | bool ExpectSetRemoteDescription(SdpType type); |
| 291 | |
| 292 | // The offer/answer machinery assumes the media section MID is present and |
| 293 | // unique. To support legacy end points that do not supply a=mid lines, this |
| 294 | // method will modify the session description to add MIDs generated according |
| 295 | // to the SDP semantics. |
| 296 | void FillInMissingRemoteMids(cricket::SessionDescription* remote_description); |
| 297 | |
| 298 | // Returns an RtpTransciever, if available, that can be used to receive the |
| 299 | // given media type according to JSEP rules. |
| 300 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 301 | FindAvailableTransceiverToReceive(cricket::MediaType media_type) const; |
| 302 | |
| 303 | // Returns a MediaSessionOptions struct with options decided by |options|, |
| 304 | // the local MediaStreams and DataChannels. |
| 305 | void GetOptionsForOffer(const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 306 | offer_answer_options, |
| 307 | cricket::MediaSessionOptions* session_options); |
| 308 | void GetOptionsForPlanBOffer( |
| 309 | const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 310 | offer_answer_options, |
| 311 | cricket::MediaSessionOptions* session_options) |
| 312 | RTC_RUN_ON(signaling_thread()); |
| 313 | void GetOptionsForUnifiedPlanOffer( |
| 314 | const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 315 | offer_answer_options, |
| 316 | cricket::MediaSessionOptions* session_options) |
| 317 | RTC_RUN_ON(signaling_thread()); |
| 318 | |
| 319 | // Returns a MediaSessionOptions struct with options decided by |
| 320 | // |constraints|, the local MediaStreams and DataChannels. |
| 321 | void GetOptionsForAnswer(const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 322 | offer_answer_options, |
| 323 | cricket::MediaSessionOptions* session_options); |
| 324 | void GetOptionsForPlanBAnswer( |
| 325 | const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 326 | offer_answer_options, |
| 327 | cricket::MediaSessionOptions* session_options) |
| 328 | RTC_RUN_ON(signaling_thread()); |
| 329 | void GetOptionsForUnifiedPlanAnswer( |
| 330 | const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 331 | offer_answer_options, |
| 332 | cricket::MediaSessionOptions* session_options) |
| 333 | RTC_RUN_ON(signaling_thread()); |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 334 | |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 +0000 | [diff] [blame] | 335 | const char* SessionErrorToString(SessionError error) const; |
| 336 | std::string GetSessionErrorMsg(); |
| 337 | // Returns the last error in the session. See the enum above for details. |
| 338 | SessionError session_error() const { |
| 339 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 340 | return session_error_; |
| 341 | } |
| 342 | const std::string& session_error_desc() const { return session_error_desc_; } |
| 343 | |
| 344 | RTCError HandleLegacyOfferOptions( |
| 345 | const PeerConnectionInterface::RTCOfferAnswerOptions& options); |
| 346 | void RemoveRecvDirectionFromReceivingTransceiversOfType( |
| 347 | cricket::MediaType media_type) RTC_RUN_ON(signaling_thread()); |
| 348 | void AddUpToOneReceivingTransceiverOfType(cricket::MediaType media_type); |
| 349 | |
| 350 | std::vector< |
| 351 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
| 352 | GetReceivingTransceiversOfType(cricket::MediaType media_type) |
| 353 | RTC_RUN_ON(signaling_thread()); |
| 354 | |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 +0000 | [diff] [blame] | 355 | // Runs the algorithm specified in |
| 356 | // https://w3c.github.io/webrtc-pc/#process-remote-track-removal |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 +0000 | [diff] [blame] | 357 | // This method will update the following lists: |
| 358 | // |remove_list| is the list of transceivers for which the receiving track is |
| 359 | // being removed. |
| 360 | // |removed_streams| is the list of streams which no longer have a receiving |
| 361 | // track so should be removed. |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 +0000 | [diff] [blame] | 362 | void ProcessRemovalOfRemoteTrack( |
| 363 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 364 | transceiver, |
| 365 | std::vector<rtc::scoped_refptr<RtpTransceiverInterface>>* remove_list, |
| 366 | std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams); |
| 367 | |
| 368 | void RemoveRemoteStreamsIfEmpty( |
| 369 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& |
| 370 | remote_streams, |
| 371 | std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams); |
| 372 | |
| 373 | // Remove all local and remote senders of type |media_type|. |
| 374 | // Called when a media type is rejected (m-line set to port 0). |
| 375 | void RemoveSenders(cricket::MediaType media_type); |
| 376 | |
| 377 | // Loops through the vector of |streams| and finds added and removed |
| 378 | // StreamParams since last time this method was called. |
| 379 | // For each new or removed StreamParam, OnLocalSenderSeen or |
| 380 | // OnLocalSenderRemoved is invoked. |
| 381 | void UpdateLocalSenders(const std::vector<cricket::StreamParams>& streams, |
| 382 | cricket::MediaType media_type); |
| 383 | |
| 384 | // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|, |
| 385 | // and existing MediaStreamTracks are removed if there is no corresponding |
| 386 | // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack |
| 387 | // is created if it doesn't exist; if false, it's removed if it exists. |
| 388 | // |media_type| is the type of the |streams| and can be either audio or video. |
| 389 | // If a new MediaStream is created it is added to |new_streams|. |
| 390 | void UpdateRemoteSendersList( |
| 391 | const std::vector<cricket::StreamParams>& streams, |
| 392 | bool default_track_needed, |
| 393 | cricket::MediaType media_type, |
| 394 | StreamCollection* new_streams); |
| 395 | |
| 396 | // Enables media channels to allow sending of media. |
| 397 | // This enables media to flow on all configured audio/video channels and the |
| 398 | // RtpDataChannel. |
| 399 | void EnableSending(); |
| 400 | // Push the media parts of the local or remote session description |
| 401 | // down to all of the channels. |
| 402 | RTCError PushdownMediaDescription(SdpType type, |
| 403 | cricket::ContentSource source); |
| 404 | |
| 405 | RTCError PushdownTransportDescription(cricket::ContentSource source, |
| 406 | SdpType type); |
| 407 | // Helper function to remove stopped transceivers. |
| 408 | void RemoveStoppedTransceivers(); |
| 409 | // Deletes the corresponding channel of contents that don't exist in |desc|. |
| 410 | // |desc| can be null. This means that all channels are deleted. |
| 411 | void RemoveUnusedChannels(const cricket::SessionDescription* desc); |
| 412 | |
| 413 | // Report inferred negotiated SDP semantics from a local/remote answer to the |
| 414 | // UMA observer. |
| 415 | void ReportNegotiatedSdpSemantics(const SessionDescriptionInterface& answer); |
| 416 | |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 +0000 | [diff] [blame] | 417 | // Finds remote MediaStreams without any tracks and removes them from |
| 418 | // |remote_streams_| and notifies the observer that the MediaStreams no longer |
| 419 | // exist. |
| 420 | void UpdateEndedRemoteMediaStreams(); |
| 421 | |
| 422 | // Uses all remote candidates in |remote_desc| in this session. |
| 423 | bool UseCandidatesInSessionDescription( |
| 424 | const SessionDescriptionInterface* remote_desc); |
| 425 | // Uses |candidate| in this session. |
| 426 | bool UseCandidate(const IceCandidateInterface* candidate); |
| 427 | // Returns true if we are ready to push down the remote candidate. |
| 428 | // |remote_desc| is the new remote description, or NULL if the current remote |
| 429 | // description should be used. Output |valid| is true if the candidate media |
| 430 | // index is valid. |
| 431 | bool ReadyToUseRemoteCandidate(const IceCandidateInterface* candidate, |
| 432 | const SessionDescriptionInterface* remote_desc, |
| 433 | bool* valid); |
| 434 | void ReportRemoteIceCandidateAdded(const cricket::Candidate& candidate) |
| 435 | RTC_RUN_ON(signaling_thread()); |
| 436 | |
| 437 | RTCErrorOr<const cricket::ContentInfo*> FindContentInfo( |
| 438 | const SessionDescriptionInterface* description, |
| 439 | const IceCandidateInterface* candidate) RTC_RUN_ON(signaling_thread()); |
| 440 | |
| 441 | // Functions for dealing with transports. |
| 442 | // Note that cricket code uses the term "channel" for what other code |
| 443 | // refers to as "transport". |
| 444 | |
| 445 | // Allocates media channels based on the |desc|. If |desc| doesn't have |
| 446 | // the BUNDLE option, this method will disable BUNDLE in PortAllocator. |
| 447 | // This method will also delete any existing media channels before creating. |
| 448 | RTCError CreateChannels(const cricket::SessionDescription& desc); |
| 449 | |
| 450 | // Helper methods to create media channels. |
| 451 | cricket::VoiceChannel* CreateVoiceChannel(const std::string& mid); |
| 452 | cricket::VideoChannel* CreateVideoChannel(const std::string& mid); |
| 453 | bool CreateDataChannel(const std::string& mid); |
| 454 | |
| 455 | // Destroys and clears the BaseChannel associated with the given transceiver, |
| 456 | // if such channel is set. |
| 457 | void DestroyTransceiverChannel( |
| 458 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 459 | transceiver); |
| 460 | |
| 461 | // Destroys the RTP data channel transport and/or the SCTP data channel |
| 462 | // transport and clears it. |
| 463 | void DestroyDataChannelTransport(); |
| 464 | |
| 465 | // Destroys the given ChannelInterface. |
| 466 | // The channel cannot be accessed after this method is called. |
| 467 | void DestroyChannelInterface(cricket::ChannelInterface* channel); |
| 468 | // Generates MediaDescriptionOptions for the |session_opts| based on existing |
| 469 | // local description or remote description. |
| 470 | |
| 471 | void GenerateMediaDescriptionOptions( |
| 472 | const SessionDescriptionInterface* session_desc, |
| 473 | RtpTransceiverDirection audio_direction, |
| 474 | RtpTransceiverDirection video_direction, |
| 475 | absl::optional<size_t>* audio_index, |
| 476 | absl::optional<size_t>* video_index, |
| 477 | absl::optional<size_t>* data_index, |
| 478 | cricket::MediaSessionOptions* session_options); |
| 479 | |
| 480 | // Generates the active MediaDescriptionOptions for the local data channel |
| 481 | // given the specified MID. |
| 482 | cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForActiveData( |
| 483 | const std::string& mid) const; |
| 484 | |
| 485 | // Generates the rejected MediaDescriptionOptions for the local data channel |
| 486 | // given the specified MID. |
| 487 | cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForRejectedData( |
| 488 | const std::string& mid) const; |
| 489 | |
| 490 | const std::string GetTransportName(const std::string& content_name); |
| 491 | // Based on number of transceivers per media type, enabled or disable |
| 492 | // payload type based demuxing in the affected channels. |
| 493 | void UpdatePayloadTypeDemuxingState(cricket::ContentSource source); |
| 494 | |
| 495 | // ================================================================== |
| 496 | // Access to pc_ variables |
| 497 | cricket::ChannelManager* channel_manager() const; |
| 498 | TransceiverList& transceivers(); |
| 499 | const TransceiverList& transceivers() const; |
| 500 | JsepTransportController* transport_controller(); |
| 501 | DataChannelController* data_channel_controller(); |
| 502 | const DataChannelController* data_channel_controller() const; |
| 503 | cricket::PortAllocator* port_allocator(); |
| 504 | const cricket::PortAllocator* port_allocator() const; |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 505 | // =================================================================== |
| 506 | |
| 507 | PeerConnection* const pc_; |
| 508 | |
| 509 | std::unique_ptr<WebRtcSessionDescriptionFactory> webrtc_session_desc_factory_ |
| 510 | RTC_GUARDED_BY(signaling_thread()); |
| 511 | |
| 512 | std::unique_ptr<SessionDescriptionInterface> current_local_description_ |
| 513 | RTC_GUARDED_BY(signaling_thread()); |
| 514 | std::unique_ptr<SessionDescriptionInterface> pending_local_description_ |
| 515 | RTC_GUARDED_BY(signaling_thread()); |
| 516 | std::unique_ptr<SessionDescriptionInterface> current_remote_description_ |
| 517 | RTC_GUARDED_BY(signaling_thread()); |
| 518 | std::unique_ptr<SessionDescriptionInterface> pending_remote_description_ |
| 519 | RTC_GUARDED_BY(signaling_thread()); |
| 520 | |
| 521 | PeerConnectionInterface::SignalingState signaling_state_ |
| 522 | RTC_GUARDED_BY(signaling_thread()) = PeerConnectionInterface::kStable; |
| 523 | |
| 524 | // Whether this peer is the caller. Set when the local description is applied. |
| 525 | absl::optional<bool> is_caller_ RTC_GUARDED_BY(signaling_thread()); |
| 526 | |
Harald Alvestrand | 6f04b65 | 2020-10-09 11:42:17 +0000 | [diff] [blame] | 527 | // Streams added via AddStream. |
| 528 | const rtc::scoped_refptr<StreamCollection> local_streams_ |
| 529 | RTC_GUARDED_BY(signaling_thread()); |
| 530 | // Streams created as a result of SetRemoteDescription. |
| 531 | const rtc::scoped_refptr<StreamCollection> remote_streams_ |
| 532 | RTC_GUARDED_BY(signaling_thread()); |
| 533 | |
| 534 | std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_ |
| 535 | RTC_GUARDED_BY(signaling_thread()); |
| 536 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 537 | // The operations chain is used by the offer/answer exchange methods to ensure |
| 538 | // they are executed in the right order. For example, if |
| 539 | // SetRemoteDescription() is invoked while CreateOffer() is still pending, the |
| 540 | // SRD operation will not start until CreateOffer() has completed. See |
| 541 | // https://w3c.github.io/webrtc-pc/#dfn-operations-chain. |
| 542 | rtc::scoped_refptr<rtc::OperationsChain> operations_chain_ |
| 543 | RTC_GUARDED_BY(signaling_thread()); |
| 544 | |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 +0000 | [diff] [blame] | 545 | // One PeerConnection has only one RTCP CNAME. |
| 546 | // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9 |
| 547 | const std::string rtcp_cname_; |
| 548 | |
| 549 | // MIDs will be generated using this generator which will keep track of |
| 550 | // all the MIDs that have been seen over the life of the PeerConnection. |
| 551 | rtc::UniqueStringGenerator mid_generator_ RTC_GUARDED_BY(signaling_thread()); |
| 552 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 553 | // List of content names for which the remote side triggered an ICE restart. |
| 554 | std::set<std::string> pending_ice_restarts_ |
| 555 | RTC_GUARDED_BY(signaling_thread()); |
| 556 | |
| 557 | std::unique_ptr<LocalIceCredentialsToReplace> |
| 558 | local_ice_credentials_to_replace_ RTC_GUARDED_BY(signaling_thread()); |
| 559 | |
| 560 | bool remote_peer_supports_msid_ RTC_GUARDED_BY(signaling_thread()) = false; |
| 561 | bool is_negotiation_needed_ RTC_GUARDED_BY(signaling_thread()) = false; |
| 562 | uint32_t negotiation_needed_event_id_ = 0; |
| 563 | bool update_negotiation_needed_on_empty_chain_ |
| 564 | RTC_GUARDED_BY(signaling_thread()) = false; |
| 565 | |
| 566 | // In Unified Plan, if we encounter remote SDP that does not contain an a=msid |
| 567 | // line we create and use a stream with a random ID for our receivers. This is |
| 568 | // to support legacy endpoints that do not support the a=msid attribute (as |
| 569 | // opposed to streamless tracks with "a=msid:-"). |
| 570 | rtc::scoped_refptr<MediaStreamInterface> missing_msid_default_stream_ |
| 571 | RTC_GUARDED_BY(signaling_thread()); |
| 572 | |
Harald Alvestrand | 75b9ab6 | 2020-09-30 22:17:18 +0000 | [diff] [blame] | 573 | // Used when rolling back RTP data channels. |
| 574 | bool have_pending_rtp_data_channel_ RTC_GUARDED_BY(signaling_thread()) = |
| 575 | false; |
| 576 | |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 +0000 | [diff] [blame] | 577 | // Updates the error state, signaling if necessary. |
| 578 | void SetSessionError(SessionError error, const std::string& error_desc); |
| 579 | |
| 580 | SessionError session_error_ RTC_GUARDED_BY(signaling_thread()) = |
| 581 | SessionError::kNone; |
| 582 | std::string session_error_desc_ RTC_GUARDED_BY(signaling_thread()); |
| 583 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 584 | rtc::WeakPtrFactory<SdpOfferAnswerHandler> weak_ptr_factory_ |
| 585 | RTC_GUARDED_BY(signaling_thread()); |
| 586 | }; |
| 587 | |
| 588 | } // namespace webrtc |
| 589 | |
| 590 | #endif // PC_SDP_OFFER_ANSWER_H_ |