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