xref: /aosp_15_r20/external/webrtc/pc/peer_connection_sdp_methods.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright 2022 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_PEER_CONNECTION_SDP_METHODS_H_
12*d9f75844SAndroid Build Coastguard Worker #define PC_PEER_CONNECTION_SDP_METHODS_H_
13*d9f75844SAndroid Build Coastguard Worker 
14*d9f75844SAndroid Build Coastguard Worker #include <map>
15*d9f75844SAndroid Build Coastguard Worker #include <memory>
16*d9f75844SAndroid Build Coastguard Worker #include <set>
17*d9f75844SAndroid Build Coastguard Worker #include <string>
18*d9f75844SAndroid Build Coastguard Worker #include <vector>
19*d9f75844SAndroid Build Coastguard Worker 
20*d9f75844SAndroid Build Coastguard Worker #include "api/peer_connection_interface.h"
21*d9f75844SAndroid Build Coastguard Worker #include "pc/jsep_transport_controller.h"
22*d9f75844SAndroid Build Coastguard Worker #include "pc/peer_connection_message_handler.h"
23*d9f75844SAndroid Build Coastguard Worker #include "pc/sctp_data_channel.h"
24*d9f75844SAndroid Build Coastguard Worker #include "pc/usage_pattern.h"
25*d9f75844SAndroid Build Coastguard Worker 
26*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
27*d9f75844SAndroid Build Coastguard Worker 
28*d9f75844SAndroid Build Coastguard Worker class DataChannelController;
29*d9f75844SAndroid Build Coastguard Worker class RtpTransmissionManager;
30*d9f75844SAndroid Build Coastguard Worker class StatsCollector;
31*d9f75844SAndroid Build Coastguard Worker 
32*d9f75844SAndroid Build Coastguard Worker // This interface defines the functions that are needed for
33*d9f75844SAndroid Build Coastguard Worker // SdpOfferAnswerHandler to access PeerConnection internal state.
34*d9f75844SAndroid Build Coastguard Worker class PeerConnectionSdpMethods {
35*d9f75844SAndroid Build Coastguard Worker  public:
36*d9f75844SAndroid Build Coastguard Worker   virtual ~PeerConnectionSdpMethods() = default;
37*d9f75844SAndroid Build Coastguard Worker 
38*d9f75844SAndroid Build Coastguard Worker   // The SDP session ID as defined by RFC 3264.
39*d9f75844SAndroid Build Coastguard Worker   virtual std::string session_id() const = 0;
40*d9f75844SAndroid Build Coastguard Worker 
41*d9f75844SAndroid Build Coastguard Worker   // Returns true if the ICE restart flag above was set, and no ICE restart has
42*d9f75844SAndroid Build Coastguard Worker   // occurred yet for this transport (by applying a local description with
43*d9f75844SAndroid Build Coastguard Worker   // changed ufrag/password). If the transport has been deleted as a result of
44*d9f75844SAndroid Build Coastguard Worker   // bundling, returns false.
45*d9f75844SAndroid Build Coastguard Worker   virtual bool NeedsIceRestart(const std::string& content_name) const = 0;
46*d9f75844SAndroid Build Coastguard Worker 
47*d9f75844SAndroid Build Coastguard Worker   virtual absl::optional<std::string> sctp_mid() const = 0;
48*d9f75844SAndroid Build Coastguard Worker 
49*d9f75844SAndroid Build Coastguard Worker   // Functions below this comment are known to only be accessed
50*d9f75844SAndroid Build Coastguard Worker   // from SdpOfferAnswerHandler.
51*d9f75844SAndroid Build Coastguard Worker   // Return a pointer to the active configuration.
52*d9f75844SAndroid Build Coastguard Worker   virtual const PeerConnectionInterface::RTCConfiguration* configuration()
53*d9f75844SAndroid Build Coastguard Worker       const = 0;
54*d9f75844SAndroid Build Coastguard Worker 
55*d9f75844SAndroid Build Coastguard Worker   // Report the UMA metric SdpFormatReceived for the given remote description.
56*d9f75844SAndroid Build Coastguard Worker   virtual void ReportSdpFormatReceived(
57*d9f75844SAndroid Build Coastguard Worker       const SessionDescriptionInterface& remote_description) = 0;
58*d9f75844SAndroid Build Coastguard Worker 
59*d9f75844SAndroid Build Coastguard Worker   // Report the UMA metric BundleUsage for the given remote description.
60*d9f75844SAndroid Build Coastguard Worker   virtual void ReportSdpBundleUsage(
61*d9f75844SAndroid Build Coastguard Worker       const SessionDescriptionInterface& remote_description) = 0;
62*d9f75844SAndroid Build Coastguard Worker 
63*d9f75844SAndroid Build Coastguard Worker   virtual PeerConnectionMessageHandler* message_handler() = 0;
64*d9f75844SAndroid Build Coastguard Worker   virtual RtpTransmissionManager* rtp_manager() = 0;
65*d9f75844SAndroid Build Coastguard Worker   virtual const RtpTransmissionManager* rtp_manager() const = 0;
66*d9f75844SAndroid Build Coastguard Worker   virtual bool dtls_enabled() const = 0;
67*d9f75844SAndroid Build Coastguard Worker   virtual const PeerConnectionFactoryInterface::Options* options() const = 0;
68*d9f75844SAndroid Build Coastguard Worker 
69*d9f75844SAndroid Build Coastguard Worker   // Returns the CryptoOptions for this PeerConnection. This will always
70*d9f75844SAndroid Build Coastguard Worker   // return the RTCConfiguration.crypto_options if set and will only default
71*d9f75844SAndroid Build Coastguard Worker   // back to the PeerConnectionFactory settings if nothing was set.
72*d9f75844SAndroid Build Coastguard Worker   virtual CryptoOptions GetCryptoOptions() = 0;
73*d9f75844SAndroid Build Coastguard Worker   virtual JsepTransportController* transport_controller_s() = 0;
74*d9f75844SAndroid Build Coastguard Worker   virtual JsepTransportController* transport_controller_n() = 0;
75*d9f75844SAndroid Build Coastguard Worker   virtual DataChannelController* data_channel_controller() = 0;
76*d9f75844SAndroid Build Coastguard Worker   virtual cricket::PortAllocator* port_allocator() = 0;
77*d9f75844SAndroid Build Coastguard Worker   virtual StatsCollector* stats() = 0;
78*d9f75844SAndroid Build Coastguard Worker   // Returns the observer. Will crash on CHECK if the observer is removed.
79*d9f75844SAndroid Build Coastguard Worker   virtual PeerConnectionObserver* Observer() const = 0;
80*d9f75844SAndroid Build Coastguard Worker   virtual bool GetSctpSslRole(rtc::SSLRole* role) = 0;
81*d9f75844SAndroid Build Coastguard Worker   virtual PeerConnectionInterface::IceConnectionState
82*d9f75844SAndroid Build Coastguard Worker   ice_connection_state_internal() = 0;
83*d9f75844SAndroid Build Coastguard Worker   virtual void SetIceConnectionState(
84*d9f75844SAndroid Build Coastguard Worker       PeerConnectionInterface::IceConnectionState new_state) = 0;
85*d9f75844SAndroid Build Coastguard Worker   virtual void NoteUsageEvent(UsageEvent event) = 0;
86*d9f75844SAndroid Build Coastguard Worker   virtual bool IsClosed() const = 0;
87*d9f75844SAndroid Build Coastguard Worker   // Returns true if the PeerConnection is configured to use Unified Plan
88*d9f75844SAndroid Build Coastguard Worker   // semantics for creating offers/answers and setting local/remote
89*d9f75844SAndroid Build Coastguard Worker   // descriptions. If this is true the RtpTransceiver API will also be available
90*d9f75844SAndroid Build Coastguard Worker   // to the user. If this is false, Plan B semantics are assumed.
91*d9f75844SAndroid Build Coastguard Worker   // TODO(bugs.webrtc.org/8530): Flip the default to be Unified Plan once
92*d9f75844SAndroid Build Coastguard Worker   // sufficient time has passed.
93*d9f75844SAndroid Build Coastguard Worker   virtual bool IsUnifiedPlan() const = 0;
94*d9f75844SAndroid Build Coastguard Worker   virtual bool ValidateBundleSettings(
95*d9f75844SAndroid Build Coastguard Worker       const cricket::SessionDescription* desc,
96*d9f75844SAndroid Build Coastguard Worker       const std::map<std::string, const cricket::ContentGroup*>&
97*d9f75844SAndroid Build Coastguard Worker           bundle_groups_by_mid) = 0;
98*d9f75844SAndroid Build Coastguard Worker 
99*d9f75844SAndroid Build Coastguard Worker   virtual absl::optional<std::string> GetDataMid() const = 0;
100*d9f75844SAndroid Build Coastguard Worker   // Internal implementation for AddTransceiver family of methods. If
101*d9f75844SAndroid Build Coastguard Worker   // `fire_callback` is set, fires OnRenegotiationNeeded callback if successful.
102*d9f75844SAndroid Build Coastguard Worker   virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>
103*d9f75844SAndroid Build Coastguard Worker   AddTransceiver(cricket::MediaType media_type,
104*d9f75844SAndroid Build Coastguard Worker                  rtc::scoped_refptr<MediaStreamTrackInterface> track,
105*d9f75844SAndroid Build Coastguard Worker                  const RtpTransceiverInit& init,
106*d9f75844SAndroid Build Coastguard Worker                  bool fire_callback = true) = 0;
107*d9f75844SAndroid Build Coastguard Worker   // Asynchronously calls SctpTransport::Start() on the network thread for
108*d9f75844SAndroid Build Coastguard Worker   // `sctp_mid()` if set. Called as part of setting the local description.
109*d9f75844SAndroid Build Coastguard Worker   virtual void StartSctpTransport(int local_port,
110*d9f75844SAndroid Build Coastguard Worker                                   int remote_port,
111*d9f75844SAndroid Build Coastguard Worker                                   int max_message_size) = 0;
112*d9f75844SAndroid Build Coastguard Worker 
113*d9f75844SAndroid Build Coastguard Worker   // Asynchronously adds a remote candidate on the network thread.
114*d9f75844SAndroid Build Coastguard Worker   virtual void AddRemoteCandidate(const std::string& mid,
115*d9f75844SAndroid Build Coastguard Worker                                   const cricket::Candidate& candidate) = 0;
116*d9f75844SAndroid Build Coastguard Worker 
117*d9f75844SAndroid Build Coastguard Worker   virtual Call* call_ptr() = 0;
118*d9f75844SAndroid Build Coastguard Worker   // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by
119*d9f75844SAndroid Build Coastguard Worker   // this session.
120*d9f75844SAndroid Build Coastguard Worker   virtual bool SrtpRequired() const = 0;
121*d9f75844SAndroid Build Coastguard Worker   virtual bool SetupDataChannelTransport_n(const std::string& mid) = 0;
122*d9f75844SAndroid Build Coastguard Worker   virtual void TeardownDataChannelTransport_n() = 0;
123*d9f75844SAndroid Build Coastguard Worker   virtual void SetSctpDataMid(const std::string& mid) = 0;
124*d9f75844SAndroid Build Coastguard Worker   virtual void ResetSctpDataMid() = 0;
125*d9f75844SAndroid Build Coastguard Worker 
126*d9f75844SAndroid Build Coastguard Worker   virtual const FieldTrialsView& trials() const = 0;
127*d9f75844SAndroid Build Coastguard Worker };
128*d9f75844SAndroid Build Coastguard Worker 
129*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc
130*d9f75844SAndroid Build Coastguard Worker 
131*d9f75844SAndroid Build Coastguard Worker #endif  // PC_PEER_CONNECTION_SDP_METHODS_H_
132