Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [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 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
Florent Castelli | dcb9ffc | 2021-06-29 12:58:23 | [diff] [blame] | 16 | |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 | [diff] [blame] | 17 | #include <functional> |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 18 | #include <map> |
| 19 | #include <memory> |
| 20 | #include <set> |
| 21 | #include <string> |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 | [diff] [blame] | 24 | #include "absl/types/optional.h" |
Harald Alvestrand | 763f5a9 | 2020-10-22 10:39:40 | [diff] [blame] | 25 | #include "api/audio_options.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 | [diff] [blame] | 26 | #include "api/candidate.h" |
| 27 | #include "api/jsep.h" |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 28 | #include "api/jsep_ice_candidate.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 | [diff] [blame] | 29 | #include "api/media_stream_interface.h" |
| 30 | #include "api/media_types.h" |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 31 | #include "api/peer_connection_interface.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 | [diff] [blame] | 32 | #include "api/rtc_error.h" |
| 33 | #include "api/rtp_transceiver_direction.h" |
| 34 | #include "api/rtp_transceiver_interface.h" |
| 35 | #include "api/scoped_refptr.h" |
Artem Titov | d15a575 | 2021-02-10 13:31:24 | [diff] [blame] | 36 | #include "api/sequence_checker.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 | [diff] [blame] | 37 | #include "api/set_local_description_observer_interface.h" |
| 38 | #include "api/set_remote_description_observer_interface.h" |
Tomas Gunnarsson | 2efb8a5 | 2021-04-01 14:26:57 | [diff] [blame] | 39 | #include "api/uma_metrics.h" |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 40 | #include "api/video/video_bitrate_allocator_factory.h" |
Harald Alvestrand | 763f5a9 | 2020-10-22 10:39:40 | [diff] [blame] | 41 | #include "media/base/media_channel.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 | [diff] [blame] | 42 | #include "media/base/stream_params.h" |
| 43 | #include "p2p/base/port_allocator.h" |
Harald Alvestrand | 8e34419 | 2022-02-08 12:55:42 | [diff] [blame] | 44 | #include "pc/connection_context.h" |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 45 | #include "pc/data_channel_controller.h" |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 46 | #include "pc/jsep_transport_controller.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 | [diff] [blame] | 47 | #include "pc/media_session.h" |
| 48 | #include "pc/media_stream_observer.h" |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 49 | #include "pc/peer_connection_internal.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 | [diff] [blame] | 50 | #include "pc/rtp_receiver.h" |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 51 | #include "pc/rtp_transceiver.h" |
Harald Alvestrand | 763f5a9 | 2020-10-22 10:39:40 | [diff] [blame] | 52 | #include "pc/rtp_transmission_manager.h" |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 53 | #include "pc/sdp_state_provider.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 | [diff] [blame] | 54 | #include "pc/session_description.h" |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 55 | #include "pc/stream_collection.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 | [diff] [blame] | 56 | #include "pc/transceiver_list.h" |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 57 | #include "pc/webrtc_session_description_factory.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 | [diff] [blame] | 58 | #include "rtc_base/checks.h" |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 59 | #include "rtc_base/operations_chain.h" |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 60 | #include "rtc_base/ssl_stream_adapter.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 | [diff] [blame] | 61 | #include "rtc_base/thread.h" |
| 62 | #include "rtc_base/thread_annotations.h" |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 63 | #include "rtc_base/unique_id_generator.h" |
| 64 | #include "rtc_base/weak_ptr.h" |
| 65 | |
| 66 | namespace webrtc { |
| 67 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 68 | // SdpOfferAnswerHandler is a component |
| 69 | // of the PeerConnection object as defined |
| 70 | // by the PeerConnectionInterface API surface. |
| 71 | // The class is responsible for the following: |
| 72 | // - Parsing and interpreting SDP. |
| 73 | // - Generating offers and answers based on the current state. |
| 74 | // This class lives on the signaling thread. |
Niels Möller | 6189207 | 2022-06-23 11:14:22 | [diff] [blame] | 75 | class SdpOfferAnswerHandler : public SdpStateProvider { |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 76 | public: |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 77 | ~SdpOfferAnswerHandler(); |
| 78 | |
Harald Alvestrand | 9cd199d | 2020-10-27 07:10:43 | [diff] [blame] | 79 | // Creates an SdpOfferAnswerHandler. Modifies dependencies. |
| 80 | static std::unique_ptr<SdpOfferAnswerHandler> Create( |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 | [diff] [blame] | 81 | PeerConnectionSdpMethods* pc, |
Harald Alvestrand | 763f5a9 | 2020-10-22 10:39:40 | [diff] [blame] | 82 | const PeerConnectionInterface::RTCConfiguration& configuration, |
Harald Alvestrand | 66c4036 | 2022-01-28 17:41:30 | [diff] [blame] | 83 | PeerConnectionDependencies& dependencies, |
| 84 | ConnectionContext* context); |
Harald Alvestrand | 763f5a9 | 2020-10-22 10:39:40 | [diff] [blame] | 85 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 86 | void ResetSessionDescFactory() { |
| 87 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 88 | webrtc_session_desc_factory_.reset(); |
| 89 | } |
| 90 | const WebRtcSessionDescriptionFactory* webrtc_session_desc_factory() const { |
| 91 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 92 | return webrtc_session_desc_factory_.get(); |
| 93 | } |
| 94 | |
| 95 | // Change signaling state to Closed, and perform appropriate actions. |
| 96 | void Close(); |
| 97 | |
| 98 | // Called as part of destroying the owning PeerConnection. |
| 99 | void PrepareForShutdown(); |
| 100 | |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 101 | // Implementation of SdpStateProvider |
| 102 | PeerConnectionInterface::SignalingState signaling_state() const override; |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 103 | |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 104 | const SessionDescriptionInterface* local_description() const override; |
| 105 | const SessionDescriptionInterface* remote_description() const override; |
| 106 | const SessionDescriptionInterface* current_local_description() const override; |
| 107 | const SessionDescriptionInterface* current_remote_description() |
| 108 | const override; |
| 109 | const SessionDescriptionInterface* pending_local_description() const override; |
| 110 | const SessionDescriptionInterface* pending_remote_description() |
| 111 | const override; |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 112 | |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 113 | bool NeedsIceRestart(const std::string& content_name) const override; |
| 114 | bool IceRestartPending(const std::string& content_name) const override; |
| 115 | absl::optional<rtc::SSLRole> GetDtlsRole( |
| 116 | const std::string& mid) const override; |
Harald Alvestrand | d89ce53 | 2020-10-21 08:59:22 | [diff] [blame] | 117 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 118 | void RestartIce(); |
| 119 | |
| 120 | // JSEP01 |
| 121 | void CreateOffer( |
| 122 | CreateSessionDescriptionObserver* observer, |
| 123 | const PeerConnectionInterface::RTCOfferAnswerOptions& options); |
| 124 | void CreateAnswer( |
| 125 | CreateSessionDescriptionObserver* observer, |
| 126 | const PeerConnectionInterface::RTCOfferAnswerOptions& options); |
| 127 | |
| 128 | void SetLocalDescription( |
| 129 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 130 | rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer); |
| 131 | void SetLocalDescription( |
| 132 | rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer); |
| 133 | void SetLocalDescription(SetSessionDescriptionObserver* observer, |
| 134 | SessionDescriptionInterface* desc); |
| 135 | void SetLocalDescription(SetSessionDescriptionObserver* observer); |
| 136 | |
| 137 | void SetRemoteDescription( |
| 138 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 139 | rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer); |
| 140 | void SetRemoteDescription(SetSessionDescriptionObserver* observer, |
| 141 | SessionDescriptionInterface* desc); |
| 142 | |
| 143 | PeerConnectionInterface::RTCConfiguration GetConfiguration(); |
| 144 | RTCError SetConfiguration( |
| 145 | const PeerConnectionInterface::RTCConfiguration& configuration); |
| 146 | bool AddIceCandidate(const IceCandidateInterface* candidate); |
| 147 | void AddIceCandidate(std::unique_ptr<IceCandidateInterface> candidate, |
| 148 | std::function<void(RTCError)> callback); |
| 149 | bool RemoveIceCandidates(const std::vector<cricket::Candidate>& candidates); |
| 150 | // Adds a locally generated candidate to the local description. |
| 151 | void AddLocalIceCandidate(const JsepIceCandidate* candidate); |
| 152 | void RemoveLocalIceCandidates( |
| 153 | const std::vector<cricket::Candidate>& candidates); |
| 154 | bool ShouldFireNegotiationNeededEvent(uint32_t event_id); |
| 155 | |
Harald Alvestrand | 6f04b653 | 2020-10-09 11:42:17 | [diff] [blame] | 156 | bool AddStream(MediaStreamInterface* local_stream); |
| 157 | void RemoveStream(MediaStreamInterface* local_stream); |
| 158 | |
Tommi | 335d084 | 2023-03-25 09:56:18 | [diff] [blame] | 159 | absl::optional<bool> is_caller() const; |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 160 | bool HasNewIceCredentials(); |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 161 | void UpdateNegotiationNeeded(); |
Tommi | c61eee2 | 2023-03-22 07:25:38 | [diff] [blame] | 162 | void AllocateSctpSids(); |
Tommi | 335d084 | 2023-03-25 09:56:18 | [diff] [blame] | 163 | // Based on the negotiation state, guess what the SSLRole might be without |
| 164 | // directly getting the information from the transport. |
| 165 | // This is used for allocating stream ids for data channels. |
| 166 | // See also `InternalDataChannelInit::fallback_ssl_role`. |
| 167 | absl::optional<rtc::SSLRole> GuessSslRole() const; |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 168 | |
Tommi | 2919075 | 2023-10-21 14:50:09 | [diff] [blame] | 169 | // Destroys all media BaseChannels. |
| 170 | void DestroyMediaChannels(); |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 | [diff] [blame] | 171 | |
Harald Alvestrand | 6f04b653 | 2020-10-09 11:42:17 | [diff] [blame] | 172 | rtc::scoped_refptr<StreamCollectionInterface> local_streams(); |
| 173 | rtc::scoped_refptr<StreamCollectionInterface> remote_streams(); |
| 174 | |
Harald Alvestrand | bc32c56 | 2022-02-09 12:08:47 | [diff] [blame] | 175 | bool initial_offerer() { |
| 176 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 177 | if (initial_offerer_) { |
| 178 | return *initial_offerer_; |
| 179 | } |
| 180 | return false; |
| 181 | } |
| 182 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 183 | private: |
Tomas Gunnarsson | 1c7c09b | 2022-01-12 12:11:04 | [diff] [blame] | 184 | class RemoteDescriptionOperation; |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 185 | class ImplicitCreateSessionDescriptionObserver; |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 | [diff] [blame] | 186 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 187 | friend class ImplicitCreateSessionDescriptionObserver; |
| 188 | class SetSessionDescriptionObserverAdapter; |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 | [diff] [blame] | 189 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 190 | friend class SetSessionDescriptionObserverAdapter; |
| 191 | |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 | [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 | [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 | [diff] [blame] | 206 | // Only called by the Create() function. |
Harald Alvestrand | 66c4036 | 2022-01-28 17:41:30 | [diff] [blame] | 207 | explicit SdpOfferAnswerHandler(PeerConnectionSdpMethods* pc, |
| 208 | ConnectionContext* context); |
Harald Alvestrand | 9cd199d | 2020-10-27 07:10:43 | [diff] [blame] | 209 | // Called from the `Create()` function. Can only be called |
| 210 | // once. Modifies dependencies. |
| 211 | void Initialize( |
| 212 | const PeerConnectionInterface::RTCConfiguration& configuration, |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 213 | PeerConnectionDependencies& dependencies, |
| 214 | ConnectionContext* context); |
Harald Alvestrand | 9cd199d | 2020-10-27 07:10:43 | [diff] [blame] | 215 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 216 | rtc::Thread* signaling_thread() const; |
Harald Alvestrand | bc32c56 | 2022-02-09 12:08:47 | [diff] [blame] | 217 | rtc::Thread* network_thread() const; |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 218 | // Non-const versions of local_description()/remote_description(), for use |
| 219 | // internally. |
| 220 | SessionDescriptionInterface* mutable_local_description() |
| 221 | RTC_RUN_ON(signaling_thread()) { |
| 222 | return pending_local_description_ ? pending_local_description_.get() |
| 223 | : current_local_description_.get(); |
| 224 | } |
| 225 | SessionDescriptionInterface* mutable_remote_description() |
| 226 | RTC_RUN_ON(signaling_thread()) { |
| 227 | return pending_remote_description_ ? pending_remote_description_.get() |
| 228 | : current_remote_description_.get(); |
| 229 | } |
| 230 | |
| 231 | // Synchronous implementations of SetLocalDescription/SetRemoteDescription |
| 232 | // that return an RTCError instead of invoking a callback. |
| 233 | RTCError ApplyLocalDescription( |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 234 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 235 | const std::map<std::string, const cricket::ContentGroup*>& |
| 236 | bundle_groups_by_mid); |
Tomas Gunnarsson | 0dd7539 | 2022-01-17 18:19:56 | [diff] [blame] | 237 | void ApplyRemoteDescription( |
| 238 | std::unique_ptr<RemoteDescriptionOperation> operation); |
| 239 | |
| 240 | RTCError ReplaceRemoteDescription( |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 241 | std::unique_ptr<SessionDescriptionInterface> desc, |
Tomas Gunnarsson | 0dd7539 | 2022-01-17 18:19:56 | [diff] [blame] | 242 | SdpType sdp_type, |
| 243 | std::unique_ptr<SessionDescriptionInterface>* replaced_description) |
| 244 | RTC_RUN_ON(signaling_thread()); |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 245 | |
Tomas Gunnarsson | 651586c | 2022-01-07 18:33:12 | [diff] [blame] | 246 | // Part of ApplyRemoteDescription steps specific to Unified Plan. |
| 247 | void ApplyRemoteDescriptionUpdateTransceiverState(SdpType sdp_type); |
| 248 | |
Tomas Gunnarsson | b625edf | 2022-01-07 16:22:14 | [diff] [blame] | 249 | // Part of ApplyRemoteDescription steps specific to plan b. |
| 250 | void PlanBUpdateSendersAndReceivers( |
| 251 | const cricket::ContentInfo* audio_content, |
| 252 | const cricket::AudioContentDescription* audio_desc, |
| 253 | const cricket::ContentInfo* video_content, |
| 254 | const cricket::VideoContentDescription* video_desc); |
| 255 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 256 | // Implementation of the offer/answer exchange operations. These are chained |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 257 | // onto the `operations_chain_` when the public CreateOffer(), CreateAnswer(), |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 258 | // SetLocalDescription() and SetRemoteDescription() methods are invoked. |
| 259 | void DoCreateOffer( |
| 260 | const PeerConnectionInterface::RTCOfferAnswerOptions& options, |
| 261 | rtc::scoped_refptr<CreateSessionDescriptionObserver> observer); |
| 262 | void DoCreateAnswer( |
| 263 | const PeerConnectionInterface::RTCOfferAnswerOptions& options, |
| 264 | rtc::scoped_refptr<CreateSessionDescriptionObserver> observer); |
| 265 | void DoSetLocalDescription( |
| 266 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 267 | rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer); |
| 268 | void DoSetRemoteDescription( |
Tomas Gunnarsson | 1c7c09b | 2022-01-12 12:11:04 | [diff] [blame] | 269 | std::unique_ptr<RemoteDescriptionOperation> operation); |
| 270 | |
| 271 | // Called after a DoSetRemoteDescription operation completes. |
| 272 | void SetRemoteDescriptionPostProcess(bool was_answer) |
| 273 | RTC_RUN_ON(signaling_thread()); |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 274 | |
| 275 | // Update the state, signaling if necessary. |
| 276 | void ChangeSignalingState( |
| 277 | PeerConnectionInterface::SignalingState signaling_state); |
| 278 | |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 279 | RTCError UpdateSessionState( |
| 280 | SdpType type, |
| 281 | cricket::ContentSource source, |
| 282 | const cricket::SessionDescription* description, |
| 283 | const std::map<std::string, const cricket::ContentGroup*>& |
| 284 | bundle_groups_by_mid); |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 285 | |
| 286 | bool IsUnifiedPlan() const RTC_RUN_ON(signaling_thread()); |
| 287 | |
Harald Alvestrand | 763f5a9 | 2020-10-22 10:39:40 | [diff] [blame] | 288 | // Signals from MediaStreamObserver. |
| 289 | void OnAudioTrackAdded(AudioTrackInterface* track, |
| 290 | MediaStreamInterface* stream) |
| 291 | RTC_RUN_ON(signaling_thread()); |
| 292 | void OnAudioTrackRemoved(AudioTrackInterface* track, |
| 293 | MediaStreamInterface* stream) |
| 294 | RTC_RUN_ON(signaling_thread()); |
| 295 | void OnVideoTrackAdded(VideoTrackInterface* track, |
| 296 | MediaStreamInterface* stream) |
| 297 | RTC_RUN_ON(signaling_thread()); |
| 298 | void OnVideoTrackRemoved(VideoTrackInterface* track, |
| 299 | MediaStreamInterface* stream) |
| 300 | RTC_RUN_ON(signaling_thread()); |
| 301 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 302 | // | desc_type | is the type of the description that caused the rollback. |
| 303 | RTCError Rollback(SdpType desc_type); |
| 304 | void OnOperationsChainEmpty(); |
| 305 | |
| 306 | // Runs the algorithm **set the associated remote streams** specified in |
| 307 | // https://w3c.github.io/webrtc-pc/#set-associated-remote-streams. |
| 308 | void SetAssociatedRemoteStreams( |
| 309 | rtc::scoped_refptr<RtpReceiverInternal> receiver, |
| 310 | const std::vector<std::string>& stream_ids, |
| 311 | std::vector<rtc::scoped_refptr<MediaStreamInterface>>* added_streams, |
| 312 | std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams); |
| 313 | |
| 314 | bool CheckIfNegotiationIsNeeded(); |
| 315 | void GenerateNegotiationNeededEvent(); |
| 316 | // Helper method which verifies SDP. |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 317 | RTCError ValidateSessionDescription( |
| 318 | const SessionDescriptionInterface* sdesc, |
| 319 | cricket::ContentSource source, |
| 320 | const std::map<std::string, const cricket::ContentGroup*>& |
| 321 | bundle_groups_by_mid) RTC_RUN_ON(signaling_thread()); |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 322 | |
| 323 | // Updates the local RtpTransceivers according to the JSEP rules. Called as |
| 324 | // part of setting the local/remote description. |
| 325 | RTCError UpdateTransceiversAndDataChannels( |
| 326 | cricket::ContentSource source, |
| 327 | const SessionDescriptionInterface& new_session, |
| 328 | const SessionDescriptionInterface* old_local_description, |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 329 | const SessionDescriptionInterface* old_remote_description, |
| 330 | const std::map<std::string, const cricket::ContentGroup*>& |
| 331 | bundle_groups_by_mid); |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 332 | |
| 333 | // Associate the given transceiver according to the JSEP rules. |
| 334 | RTCErrorOr< |
| 335 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
| 336 | AssociateTransceiver(cricket::ContentSource source, |
| 337 | SdpType type, |
| 338 | size_t mline_index, |
| 339 | const cricket::ContentInfo& content, |
| 340 | const cricket::ContentInfo* old_local_content, |
| 341 | const cricket::ContentInfo* old_remote_content) |
| 342 | RTC_RUN_ON(signaling_thread()); |
| 343 | |
Harald Alvestrand | 8546666 | 2021-04-19 21:21:36 | [diff] [blame] | 344 | // Returns the media section in the given session description that is |
| 345 | // associated with the RtpTransceiver. Returns null if none found or this |
| 346 | // RtpTransceiver is not associated. Logic varies depending on the |
| 347 | // SdpSemantics specified in the configuration. |
| 348 | const cricket::ContentInfo* FindMediaSectionForTransceiver( |
| 349 | const RtpTransceiver* transceiver, |
| 350 | const SessionDescriptionInterface* sdesc) const; |
| 351 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 352 | // Either creates or destroys the transceiver's BaseChannel according to the |
| 353 | // given media section. |
| 354 | RTCError UpdateTransceiverChannel( |
| 355 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 356 | transceiver, |
| 357 | const cricket::ContentInfo& content, |
| 358 | const cricket::ContentGroup* bundle_group) RTC_RUN_ON(signaling_thread()); |
| 359 | |
| 360 | // Either creates or destroys the local data channel according to the given |
| 361 | // media section. |
Tommi | 840cf78 | 2023-10-21 14:47:56 | [diff] [blame] | 362 | RTCError UpdateDataChannelTransport(cricket::ContentSource source, |
| 363 | const cricket::ContentInfo& content, |
| 364 | const cricket::ContentGroup* bundle_group) |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 365 | RTC_RUN_ON(signaling_thread()); |
Harald Alvestrand | c06e374 | 2020-10-01 10:23:33 | [diff] [blame] | 366 | // Check if a call to SetLocalDescription is acceptable with a session |
| 367 | // description of the given type. |
| 368 | bool ExpectSetLocalDescription(SdpType type); |
| 369 | // Check if a call to SetRemoteDescription is acceptable with a session |
| 370 | // description of the given type. |
| 371 | bool ExpectSetRemoteDescription(SdpType type); |
| 372 | |
| 373 | // The offer/answer machinery assumes the media section MID is present and |
| 374 | // unique. To support legacy end points that do not supply a=mid lines, this |
| 375 | // method will modify the session description to add MIDs generated according |
| 376 | // to the SDP semantics. |
| 377 | void FillInMissingRemoteMids(cricket::SessionDescription* remote_description); |
| 378 | |
Niels Möller | be74b80 | 2022-03-18 13:10:15 | [diff] [blame] | 379 | // Returns an RtpTransceiver, if available, that can be used to receive the |
Harald Alvestrand | c06e374 | 2020-10-01 10:23:33 | [diff] [blame] | 380 | // given media type according to JSEP rules. |
| 381 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 382 | FindAvailableTransceiverToReceive(cricket::MediaType media_type) const; |
| 383 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 384 | // Returns a MediaSessionOptions struct with options decided by `options`, |
Harald Alvestrand | c06e374 | 2020-10-01 10:23:33 | [diff] [blame] | 385 | // the local MediaStreams and DataChannels. |
| 386 | void GetOptionsForOffer(const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 387 | offer_answer_options, |
| 388 | cricket::MediaSessionOptions* session_options); |
| 389 | void GetOptionsForPlanBOffer( |
| 390 | const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 391 | offer_answer_options, |
| 392 | cricket::MediaSessionOptions* session_options) |
| 393 | RTC_RUN_ON(signaling_thread()); |
| 394 | void GetOptionsForUnifiedPlanOffer( |
| 395 | const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 396 | offer_answer_options, |
| 397 | cricket::MediaSessionOptions* session_options) |
| 398 | RTC_RUN_ON(signaling_thread()); |
| 399 | |
| 400 | // Returns a MediaSessionOptions struct with options decided by |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 401 | // `constraints`, the local MediaStreams and DataChannels. |
Harald Alvestrand | c06e374 | 2020-10-01 10:23:33 | [diff] [blame] | 402 | void GetOptionsForAnswer(const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 403 | offer_answer_options, |
| 404 | cricket::MediaSessionOptions* session_options); |
| 405 | void GetOptionsForPlanBAnswer( |
| 406 | const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 407 | offer_answer_options, |
| 408 | cricket::MediaSessionOptions* session_options) |
| 409 | RTC_RUN_ON(signaling_thread()); |
| 410 | void GetOptionsForUnifiedPlanAnswer( |
| 411 | const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 412 | offer_answer_options, |
| 413 | cricket::MediaSessionOptions* session_options) |
| 414 | RTC_RUN_ON(signaling_thread()); |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 415 | |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 | [diff] [blame] | 416 | const char* SessionErrorToString(SessionError error) const; |
| 417 | std::string GetSessionErrorMsg(); |
| 418 | // Returns the last error in the session. See the enum above for details. |
| 419 | SessionError session_error() const { |
| 420 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 421 | return session_error_; |
| 422 | } |
| 423 | const std::string& session_error_desc() const { return session_error_desc_; } |
| 424 | |
| 425 | RTCError HandleLegacyOfferOptions( |
| 426 | const PeerConnectionInterface::RTCOfferAnswerOptions& options); |
| 427 | void RemoveRecvDirectionFromReceivingTransceiversOfType( |
| 428 | cricket::MediaType media_type) RTC_RUN_ON(signaling_thread()); |
| 429 | void AddUpToOneReceivingTransceiverOfType(cricket::MediaType media_type); |
| 430 | |
| 431 | std::vector< |
| 432 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
| 433 | GetReceivingTransceiversOfType(cricket::MediaType media_type) |
| 434 | RTC_RUN_ON(signaling_thread()); |
| 435 | |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 | [diff] [blame] | 436 | // Runs the algorithm specified in |
| 437 | // https://w3c.github.io/webrtc-pc/#process-remote-track-removal |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 | [diff] [blame] | 438 | // This method will update the following lists: |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 439 | // `remove_list` is the list of transceivers for which the receiving track is |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 | [diff] [blame] | 440 | // being removed. |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 441 | // `removed_streams` is the list of streams which no longer have a receiving |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 | [diff] [blame] | 442 | // track so should be removed. |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 | [diff] [blame] | 443 | void ProcessRemovalOfRemoteTrack( |
Harald Alvestrand | 8546666 | 2021-04-19 21:21:36 | [diff] [blame] | 444 | const rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 | [diff] [blame] | 445 | transceiver, |
| 446 | std::vector<rtc::scoped_refptr<RtpTransceiverInterface>>* remove_list, |
| 447 | std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams); |
| 448 | |
| 449 | void RemoveRemoteStreamsIfEmpty( |
| 450 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& |
| 451 | remote_streams, |
| 452 | std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams); |
| 453 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 454 | // Remove all local and remote senders of type `media_type`. |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 | [diff] [blame] | 455 | // Called when a media type is rejected (m-line set to port 0). |
| 456 | void RemoveSenders(cricket::MediaType media_type); |
| 457 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 458 | // Loops through the vector of `streams` and finds added and removed |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 | [diff] [blame] | 459 | // StreamParams since last time this method was called. |
| 460 | // For each new or removed StreamParam, OnLocalSenderSeen or |
| 461 | // OnLocalSenderRemoved is invoked. |
| 462 | void UpdateLocalSenders(const std::vector<cricket::StreamParams>& streams, |
| 463 | cricket::MediaType media_type); |
| 464 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 465 | // Makes sure a MediaStreamTrack is created for each StreamParam in `streams`, |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 | [diff] [blame] | 466 | // and existing MediaStreamTracks are removed if there is no corresponding |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 467 | // StreamParam. If `default_track_needed` is true, a default MediaStreamTrack |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 | [diff] [blame] | 468 | // is created if it doesn't exist; if false, it's removed if it exists. |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 469 | // `media_type` is the type of the `streams` and can be either audio or video. |
| 470 | // If a new MediaStream is created it is added to `new_streams`. |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 | [diff] [blame] | 471 | void UpdateRemoteSendersList( |
| 472 | const std::vector<cricket::StreamParams>& streams, |
| 473 | bool default_track_needed, |
| 474 | cricket::MediaType media_type, |
| 475 | StreamCollection* new_streams); |
| 476 | |
Taylor Brandstetter | d0acbd8 | 2021-01-25 21:44:55 | [diff] [blame] | 477 | // Enables media channels to allow sending of media. |
Harald Alvestrand | 48171ec | 2021-04-20 15:06:03 | [diff] [blame] | 478 | // This enables media to flow on all configured audio/video channels. |
Taylor Brandstetter | d0acbd8 | 2021-01-25 21:44:55 | [diff] [blame] | 479 | void EnableSending(); |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 | [diff] [blame] | 480 | // Push the media parts of the local or remote session description |
Harald Alvestrand | 8101e7b | 2022-05-23 14:57:47 | [diff] [blame] | 481 | // down to all of the channels, and start SCTP if needed. |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 482 | RTCError PushdownMediaDescription( |
| 483 | SdpType type, |
| 484 | cricket::ContentSource source, |
| 485 | const std::map<std::string, const cricket::ContentGroup*>& |
| 486 | bundle_groups_by_mid); |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 | [diff] [blame] | 487 | |
| 488 | RTCError PushdownTransportDescription(cricket::ContentSource source, |
| 489 | SdpType type); |
| 490 | // Helper function to remove stopped transceivers. |
| 491 | void RemoveStoppedTransceivers(); |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 492 | // Deletes the corresponding channel of contents that don't exist in `desc`. |
| 493 | // `desc` can be null. This means that all channels are deleted. |
Harald Alvestrand | a474fbf | 2020-10-01 16:47:23 | [diff] [blame] | 494 | void RemoveUnusedChannels(const cricket::SessionDescription* desc); |
| 495 | |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 | [diff] [blame] | 496 | // Finds remote MediaStreams without any tracks and removes them from |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 497 | // `remote_streams_` and notifies the observer that the MediaStreams no longer |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 | [diff] [blame] | 498 | // exist. |
| 499 | void UpdateEndedRemoteMediaStreams(); |
| 500 | |
Tomas Gunnarsson | 0dd7539 | 2022-01-17 18:19:56 | [diff] [blame] | 501 | // Uses all remote candidates in the currently set remote_description(). |
| 502 | // If no remote description is currently set (nullptr), the return value will |
| 503 | // be true. If `UseCandidate()` fails for any candidate in the remote |
| 504 | // description, the return value will be false. |
| 505 | bool UseCandidatesInRemoteDescription(); |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 506 | // Uses `candidate` in this session. |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 | [diff] [blame] | 507 | bool UseCandidate(const IceCandidateInterface* candidate); |
| 508 | // Returns true if we are ready to push down the remote candidate. |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 509 | // `remote_desc` is the new remote description, or NULL if the current remote |
| 510 | // description should be used. Output `valid` is true if the candidate media |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 | [diff] [blame] | 511 | // index is valid. |
| 512 | bool ReadyToUseRemoteCandidate(const IceCandidateInterface* candidate, |
| 513 | const SessionDescriptionInterface* remote_desc, |
| 514 | bool* valid); |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 | [diff] [blame] | 515 | |
| 516 | RTCErrorOr<const cricket::ContentInfo*> FindContentInfo( |
| 517 | const SessionDescriptionInterface* description, |
| 518 | const IceCandidateInterface* candidate) RTC_RUN_ON(signaling_thread()); |
| 519 | |
| 520 | // Functions for dealing with transports. |
| 521 | // Note that cricket code uses the term "channel" for what other code |
| 522 | // refers to as "transport". |
| 523 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 524 | // Allocates media channels based on the `desc`. If `desc` doesn't have |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 | [diff] [blame] | 525 | // the BUNDLE option, this method will disable BUNDLE in PortAllocator. |
| 526 | // This method will also delete any existing media channels before creating. |
| 527 | RTCError CreateChannels(const cricket::SessionDescription& desc); |
| 528 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 529 | // Generates MediaDescriptionOptions for the `session_opts` based on existing |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 | [diff] [blame] | 530 | // local description or remote description. |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 | [diff] [blame] | 531 | void GenerateMediaDescriptionOptions( |
| 532 | const SessionDescriptionInterface* session_desc, |
| 533 | RtpTransceiverDirection audio_direction, |
| 534 | RtpTransceiverDirection video_direction, |
| 535 | absl::optional<size_t>* audio_index, |
| 536 | absl::optional<size_t>* video_index, |
| 537 | absl::optional<size_t>* data_index, |
| 538 | cricket::MediaSessionOptions* session_options); |
| 539 | |
| 540 | // Generates the active MediaDescriptionOptions for the local data channel |
| 541 | // given the specified MID. |
| 542 | cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForActiveData( |
| 543 | const std::string& mid) const; |
| 544 | |
| 545 | // Generates the rejected MediaDescriptionOptions for the local data channel |
| 546 | // given the specified MID. |
| 547 | cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForRejectedData( |
| 548 | const std::string& mid) const; |
| 549 | |
Taylor Brandstetter | d0acbd8 | 2021-01-25 21:44:55 | [diff] [blame] | 550 | // Based on number of transceivers per media type, enabled or disable |
| 551 | // payload type based demuxing in the affected channels. |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 552 | bool UpdatePayloadTypeDemuxingState( |
| 553 | cricket::ContentSource source, |
| 554 | const std::map<std::string, const cricket::ContentGroup*>& |
| 555 | bundle_groups_by_mid); |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 | [diff] [blame] | 556 | |
Harald Alvestrand | 42b983a | 2021-10-19 21:50:01 | [diff] [blame] | 557 | // Updates the error state, signaling if necessary. |
| 558 | void SetSessionError(SessionError error, const std::string& error_desc); |
| 559 | |
| 560 | // Implements AddIceCandidate without reporting usage, but returns the |
| 561 | // particular success/error value that should be reported (and can be utilized |
| 562 | // for other purposes). |
| 563 | AddIceCandidateResult AddIceCandidateInternal( |
| 564 | const IceCandidateInterface* candidate); |
| 565 | |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 | [diff] [blame] | 566 | // ================================================================== |
| 567 | // Access to pc_ variables |
Harald Alvestrand | 35f4b4c | 2022-05-16 10:36:43 | [diff] [blame] | 568 | cricket::MediaEngineInterface* media_engine() const; |
Harald Alvestrand | e15fb15 | 2020-10-19 13:28:05 | [diff] [blame] | 569 | TransceiverList* transceivers(); |
| 570 | const TransceiverList* transceivers() const; |
Harald Alvestrand | bc9ca25 | 2020-10-05 13:08:41 | [diff] [blame] | 571 | DataChannelController* data_channel_controller(); |
| 572 | const DataChannelController* data_channel_controller() const; |
| 573 | cricket::PortAllocator* port_allocator(); |
| 574 | const cricket::PortAllocator* port_allocator() const; |
Harald Alvestrand | e15fb15 | 2020-10-19 13:28:05 | [diff] [blame] | 575 | RtpTransmissionManager* rtp_manager(); |
| 576 | const RtpTransmissionManager* rtp_manager() const; |
Harald Alvestrand | bc32c56 | 2022-02-09 12:08:47 | [diff] [blame] | 577 | JsepTransportController* transport_controller_s() |
| 578 | RTC_RUN_ON(signaling_thread()); |
| 579 | const JsepTransportController* transport_controller_s() const |
| 580 | RTC_RUN_ON(signaling_thread()); |
| 581 | JsepTransportController* transport_controller_n() |
| 582 | RTC_RUN_ON(network_thread()); |
| 583 | const JsepTransportController* transport_controller_n() const |
| 584 | RTC_RUN_ON(network_thread()); |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 585 | // =================================================================== |
Harald Alvestrand | 763f5a9 | 2020-10-22 10:39:40 | [diff] [blame] | 586 | const cricket::AudioOptions& audio_options() { return audio_options_; } |
| 587 | const cricket::VideoOptions& video_options() { return video_options_; } |
Harald Alvestrand | 8101e7b | 2022-05-23 14:57:47 | [diff] [blame] | 588 | bool ConfiguredForMedia() const; |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 589 | |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 | [diff] [blame] | 590 | PeerConnectionSdpMethods* const pc_; |
Harald Alvestrand | 66c4036 | 2022-01-28 17:41:30 | [diff] [blame] | 591 | ConnectionContext* const context_; |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 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 | 6f04b653 | 2020-10-09 11:42:17 | [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 | [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 | [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 | [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 | [diff] [blame] | 646 | uint32_t negotiation_needed_event_id_ RTC_GUARDED_BY(signaling_thread()) = 0; |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 647 | bool update_negotiation_needed_on_empty_chain_ |
| 648 | RTC_GUARDED_BY(signaling_thread()) = false; |
Henrik Boström | 4ea80f3 | 2021-06-09 08:29:50 | [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 | [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 | [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 | [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 | [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 | |
Harald Alvestrand | 763f5a9 | 2020-10-22 10:39:40 | [diff] [blame] | 672 | // A video bitrate allocator factory. |
| 673 | // This can be injected using the PeerConnectionDependencies, |
| 674 | // or else the CreateBuiltinVideoBitrateAllocatorFactory() will be called. |
| 675 | // Note that one can still choose to override this in a MediaEngine |
| 676 | // if one wants too. |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 677 | std::unique_ptr<VideoBitrateAllocatorFactory> video_bitrate_allocator_factory_ |
| 678 | RTC_GUARDED_BY(signaling_thread()); |
Harald Alvestrand | 763f5a9 | 2020-10-22 10:39:40 | [diff] [blame] | 679 | |
Harald Alvestrand | bc32c56 | 2022-02-09 12:08:47 | [diff] [blame] | 680 | // Whether we are the initial offerer on the association. This |
| 681 | // determines the SSL role. |
| 682 | absl::optional<bool> initial_offerer_ RTC_GUARDED_BY(signaling_thread()); |
| 683 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 | [diff] [blame] | 684 | rtc::WeakPtrFactory<SdpOfferAnswerHandler> weak_ptr_factory_ |
| 685 | RTC_GUARDED_BY(signaling_thread()); |
| 686 | }; |
| 687 | |
| 688 | } // namespace webrtc |
| 689 | |
| 690 | #endif // PC_SDP_OFFER_ANSWER_H_ |