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