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