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