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