Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #ifndef PC_PEER_CONNECTION_INTERNAL_H_ |
| 12 | #define PC_PEER_CONNECTION_INTERNAL_H_ |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 13 | |
| 14 | #include <map> |
| 15 | #include <memory> |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 16 | #include <optional> |
Steve Anton | 5dfde18 | 2018-02-06 18:34:40 | [diff] [blame] | 17 | #include <set> |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 18 | #include <string> |
| 19 | #include <vector> |
| 20 | |
Florent Castelli | f4673f9 | 2024-04-19 19:46:03 | [diff] [blame] | 21 | #include "api/audio/audio_device.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 22 | #include "api/peer_connection_interface.h" |
Niels Möller | 8366e17 | 2018-02-14 11:20:13 | [diff] [blame] | 23 | #include "call/call.h" |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 | [diff] [blame] | 24 | #include "pc/jsep_transport_controller.h" |
| 25 | #include "pc/peer_connection_message_handler.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 26 | #include "pc/rtp_transceiver.h" |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 | [diff] [blame] | 27 | #include "pc/rtp_transmission_manager.h" |
Taylor Brandstetter | 3a034e1 | 2020-07-09 22:32:34 | [diff] [blame] | 28 | #include "pc/sctp_data_channel.h" |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 29 | |
| 30 | namespace webrtc { |
| 31 | |
Harald Alvestrand | 67a68d5 | 2022-02-07 05:07:03 | [diff] [blame] | 32 | class DataChannelController; |
Henrik Boström | f785989 | 2022-07-04 12:36:37 | [diff] [blame] | 33 | class LegacyStatsCollector; |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 | [diff] [blame] | 34 | |
| 35 | // This interface defines the functions that are needed for |
| 36 | // SdpOfferAnswerHandler to access PeerConnection internal state. |
| 37 | class PeerConnectionSdpMethods { |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 38 | public: |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 | [diff] [blame] | 39 | virtual ~PeerConnectionSdpMethods() = default; |
| 40 | |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 41 | // The SDP session ID as defined by RFC 3264. |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 42 | virtual std::string session_id() const = 0; |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 43 | |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 | [diff] [blame] | 44 | // Returns true if the ICE restart flag above was set, and no ICE restart has |
| 45 | // occurred yet for this transport (by applying a local description with |
| 46 | // changed ufrag/password). If the transport has been deleted as a result of |
| 47 | // bundling, returns false. |
| 48 | virtual bool NeedsIceRestart(const std::string& content_name) const = 0; |
| 49 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 50 | virtual std::optional<std::string> sctp_mid() const = 0; |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 | [diff] [blame] | 51 | |
| 52 | // Functions below this comment are known to only be accessed |
| 53 | // from SdpOfferAnswerHandler. |
| 54 | // Return a pointer to the active configuration. |
| 55 | virtual const PeerConnectionInterface::RTCConfiguration* configuration() |
| 56 | const = 0; |
| 57 | |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 | [diff] [blame] | 58 | // Report the UMA metric BundleUsage for the given remote description. |
| 59 | virtual void ReportSdpBundleUsage( |
| 60 | const SessionDescriptionInterface& remote_description) = 0; |
| 61 | |
| 62 | virtual PeerConnectionMessageHandler* message_handler() = 0; |
| 63 | virtual RtpTransmissionManager* rtp_manager() = 0; |
| 64 | virtual const RtpTransmissionManager* rtp_manager() const = 0; |
| 65 | virtual bool dtls_enabled() const = 0; |
| 66 | virtual const PeerConnectionFactoryInterface::Options* options() const = 0; |
| 67 | |
| 68 | // Returns the CryptoOptions for this PeerConnection. This will always |
| 69 | // return the RTCConfiguration.crypto_options if set and will only default |
| 70 | // back to the PeerConnectionFactory settings if nothing was set. |
| 71 | virtual CryptoOptions GetCryptoOptions() = 0; |
Harald Alvestrand | bc32c56 | 2022-02-09 12:08:47 | [diff] [blame] | 72 | virtual JsepTransportController* transport_controller_s() = 0; |
| 73 | virtual JsepTransportController* transport_controller_n() = 0; |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 | [diff] [blame] | 74 | virtual DataChannelController* data_channel_controller() = 0; |
| 75 | virtual cricket::PortAllocator* port_allocator() = 0; |
Henrik Boström | f785989 | 2022-07-04 12:36:37 | [diff] [blame] | 76 | virtual LegacyStatsCollector* legacy_stats() = 0; |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 | [diff] [blame] | 77 | // Returns the observer. Will crash on CHECK if the observer is removed. |
| 78 | virtual PeerConnectionObserver* Observer() const = 0; |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 79 | virtual std::optional<rtc::SSLRole> GetSctpSslRole_n() = 0; |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 | [diff] [blame] | 80 | virtual PeerConnectionInterface::IceConnectionState |
| 81 | ice_connection_state_internal() = 0; |
| 82 | virtual void SetIceConnectionState( |
| 83 | PeerConnectionInterface::IceConnectionState new_state) = 0; |
| 84 | virtual void NoteUsageEvent(UsageEvent event) = 0; |
| 85 | virtual bool IsClosed() const = 0; |
| 86 | // Returns true if the PeerConnection is configured to use Unified Plan |
| 87 | // semantics for creating offers/answers and setting local/remote |
| 88 | // descriptions. If this is true the RtpTransceiver API will also be available |
| 89 | // to the user. If this is false, Plan B semantics are assumed. |
| 90 | // TODO(bugs.webrtc.org/8530): Flip the default to be Unified Plan once |
| 91 | // sufficient time has passed. |
| 92 | virtual bool IsUnifiedPlan() const = 0; |
| 93 | virtual bool ValidateBundleSettings( |
| 94 | const cricket::SessionDescription* desc, |
| 95 | const std::map<std::string, const cricket::ContentGroup*>& |
| 96 | bundle_groups_by_mid) = 0; |
| 97 | |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 | [diff] [blame] | 98 | // Internal implementation for AddTransceiver family of methods. If |
| 99 | // `fire_callback` is set, fires OnRenegotiationNeeded callback if successful. |
| 100 | virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> |
| 101 | AddTransceiver(cricket::MediaType media_type, |
| 102 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 103 | const RtpTransceiverInit& init, |
| 104 | bool fire_callback = true) = 0; |
| 105 | // Asynchronously calls SctpTransport::Start() on the network thread for |
| 106 | // `sctp_mid()` if set. Called as part of setting the local description. |
| 107 | virtual void StartSctpTransport(int local_port, |
| 108 | int remote_port, |
| 109 | int max_message_size) = 0; |
| 110 | |
| 111 | // Asynchronously adds a remote candidate on the network thread. |
| 112 | virtual void AddRemoteCandidate(const std::string& mid, |
| 113 | const cricket::Candidate& candidate) = 0; |
| 114 | |
| 115 | virtual Call* call_ptr() = 0; |
| 116 | // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by |
| 117 | // this session. |
| 118 | virtual bool SrtpRequired() const = 0; |
Tommi | 840cf78 | 2023-10-21 14:47:56 | [diff] [blame] | 119 | // Initializes the data channel transport for the peerconnection instance. |
| 120 | // This will have the effect that `sctp_mid()` and `sctp_transport_name()` |
| 121 | // will return a set value (even though it might be an empty string) and the |
| 122 | // dc transport will be initialized on the network thread. |
| 123 | virtual bool CreateDataChannelTransport(absl::string_view mid) = 0; |
| 124 | // Tears down the data channel transport state and clears the `sctp_mid()` and |
| 125 | // `sctp_transport_name()` properties. |
| 126 | virtual void DestroyDataChannelTransport(RTCError error) = 0; |
Jonas Oreland | 6c7f984 | 2022-04-19 15:24:10 | [diff] [blame] | 127 | virtual const FieldTrialsView& trials() const = 0; |
Philipp Hancke | 7baa63f | 2022-09-01 13:39:50 | [diff] [blame] | 128 | |
| 129 | virtual void ClearStatsCache() = 0; |
Harald Alvestrand | 5308652 | 2024-08-25 16:43:08 | [diff] [blame] | 130 | // Keeps track of assigned payload types and comes up with reasonable |
| 131 | // suggestions when new PTs need to be assigned. |
| 132 | virtual PayloadTypePicker& payload_type_picker() = 0; |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | // Functions defined in this class are called by other objects, |
| 136 | // but not by SdpOfferAnswerHandler. |
| 137 | class PeerConnectionInternal : public PeerConnectionInterface, |
Tommi | d2afbaf | 2023-03-02 09:51:16 | [diff] [blame] | 138 | public PeerConnectionSdpMethods { |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 | [diff] [blame] | 139 | public: |
Harald Alvestrand | 66c4036 | 2022-01-28 17:41:30 | [diff] [blame] | 140 | virtual rtc::Thread* network_thread() const = 0; |
| 141 | virtual rtc::Thread* worker_thread() const = 0; |
| 142 | |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 143 | // Returns true if we were the initial offerer. |
| 144 | virtual bool initial_offerer() const = 0; |
| 145 | |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 146 | virtual std::vector< |
| 147 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
Steve Anton | b886711 | 2018-02-13 18:07:54 | [diff] [blame] | 148 | GetTransceiversInternal() const = 0; |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 149 | |
Tomas Gunnarsson | 2e94de5 | 2020-06-16 14:54:10 | [diff] [blame] | 150 | // Call on the network thread to fetch stats for all the data channels. |
| 151 | // TODO(tommi): Make pure virtual after downstream updates. |
Taylor Brandstetter | 3a034e1 | 2020-07-09 22:32:34 | [diff] [blame] | 152 | virtual std::vector<DataChannelStats> GetDataChannelStats() const { |
Tomas Gunnarsson | 2e94de5 | 2020-06-16 14:54:10 | [diff] [blame] | 153 | return {}; |
| 154 | } |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 155 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 156 | virtual std::optional<std::string> sctp_transport_name() const = 0; |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 157 | |
Qingsi Wang | 72a43a1 | 2018-02-21 00:03:18 | [diff] [blame] | 158 | virtual cricket::CandidateStatsList GetPooledCandidateStats() const = 0; |
| 159 | |
Steve Anton | 5dfde18 | 2018-02-06 18:34:40 | [diff] [blame] | 160 | // Returns a map from transport name to transport stats for all given |
| 161 | // transport names. |
Tomas Gunnarsson | bfd9ba8 | 2021-04-18 09:55:57 | [diff] [blame] | 162 | // Must be called on the network thread. |
Steve Anton | 5dfde18 | 2018-02-06 18:34:40 | [diff] [blame] | 163 | virtual std::map<std::string, cricket::TransportStats> |
| 164 | GetTransportStatsByNames(const std::set<std::string>& transport_names) = 0; |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 165 | |
| 166 | virtual Call::Stats GetCallStats() = 0; |
| 167 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 168 | virtual std::optional<AudioDeviceModule::Stats> GetAudioDeviceStats() = 0; |
Fredrik Hernqvist | efbe753 | 2023-01-13 15:42:36 | [diff] [blame] | 169 | |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 170 | virtual bool GetLocalCertificate( |
| 171 | const std::string& transport_name, |
| 172 | rtc::scoped_refptr<rtc::RTCCertificate>* certificate) = 0; |
Taylor Brandstetter | c392866 | 2018-02-23 21:04:51 | [diff] [blame] | 173 | virtual std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain( |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 174 | const std::string& transport_name) = 0; |
| 175 | |
| 176 | // Returns true if there was an ICE restart initiated by the remote offer. |
| 177 | virtual bool IceRestartPending(const std::string& content_name) const = 0; |
| 178 | |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 179 | // Get SSL role for an arbitrary m= section (handles bundling correctly). |
| 180 | virtual bool GetSslRole(const std::string& content_name, |
| 181 | rtc::SSLRole* role) = 0; |
Harald Alvestrand | 5b84f38 | 2022-02-08 10:49:09 | [diff] [blame] | 182 | // Functions needed by DataChannelController |
| 183 | virtual void NoteDataAddedEvent() {} |
Tommi | d2afbaf | 2023-03-02 09:51:16 | [diff] [blame] | 184 | // Handler for sctp data channel state changes. |
Tommi | 5654898 | 2023-03-27 16:07:34 | [diff] [blame] | 185 | // The `channel_id` is the same unique identifier as used in |
| 186 | // `DataChannelStats::internal_id and |
| 187 | // `RTCDataChannelStats::data_channel_identifier`. |
Tommi | d2afbaf | 2023-03-02 09:51:16 | [diff] [blame] | 188 | virtual void OnSctpDataChannelStateChanged( |
Tommi | 5654898 | 2023-03-27 16:07:34 | [diff] [blame] | 189 | int channel_id, |
Tommi | d2afbaf | 2023-03-02 09:51:16 | [diff] [blame] | 190 | DataChannelInterface::DataState state) {} |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | } // namespace webrtc |
| 194 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 195 | #endif // PC_PEER_CONNECTION_INTERNAL_H_ |