Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [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 09:11:00 -0800 | [diff] [blame] | 11 | #ifndef PC_PEER_CONNECTION_INTERNAL_H_ |
| 12 | #define PC_PEER_CONNECTION_INTERNAL_H_ |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 13 | |
| 14 | #include <map> |
| 15 | #include <memory> |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [diff] [blame] | 16 | #include <set> |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 17 | #include <string> |
| 18 | #include <vector> |
| 19 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 20 | #include "api/peer_connection_interface.h" |
Niels Möller | 8366e17 | 2018-02-14 12:20:13 +0100 | [diff] [blame] | 21 | #include "call/call.h" |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 22 | #include "pc/data_channel_controller.h" |
| 23 | #include "pc/jsep_transport_controller.h" |
| 24 | #include "pc/peer_connection_message_handler.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 25 | #include "pc/rtp_transceiver.h" |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 26 | #include "pc/rtp_transmission_manager.h" |
Taylor Brandstetter | 3a034e1 | 2020-07-09 15:32:34 -0700 | [diff] [blame] | 27 | #include "pc/sctp_data_channel.h" |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 28 | |
| 29 | namespace webrtc { |
| 30 | |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 31 | class StatsCollector; |
| 32 | |
| 33 | // This interface defines the functions that are needed for |
| 34 | // SdpOfferAnswerHandler to access PeerConnection internal state. |
| 35 | class PeerConnectionSdpMethods { |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 36 | public: |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 37 | virtual ~PeerConnectionSdpMethods() = default; |
| 38 | |
| 39 | // NOTE - signaling_thread() is a member of PeerConnectionInterface, |
| 40 | // so we have to use a different name for this function as long as |
| 41 | // PeerConnection is a subclass of PeerConnectionSdpMethods. |
| 42 | virtual rtc::Thread* signaling_thread_internal() const = 0; |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 43 | virtual rtc::Thread* network_thread() const = 0; |
| 44 | virtual rtc::Thread* worker_thread() const = 0; |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 45 | |
| 46 | // The SDP session ID as defined by RFC 3264. |
Steve Anton | be5e208 | 2018-01-24 15:29:17 -0800 | [diff] [blame] | 47 | virtual std::string session_id() const = 0; |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 48 | |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 49 | // Returns true if the ICE restart flag above was set, and no ICE restart has |
| 50 | // occurred yet for this transport (by applying a local description with |
| 51 | // changed ufrag/password). If the transport has been deleted as a result of |
| 52 | // bundling, returns false. |
| 53 | virtual bool NeedsIceRestart(const std::string& content_name) const = 0; |
| 54 | |
| 55 | virtual absl::optional<std::string> sctp_mid() const = 0; |
| 56 | |
| 57 | // Functions below this comment are known to only be accessed |
| 58 | // from SdpOfferAnswerHandler. |
| 59 | // Return a pointer to the active configuration. |
| 60 | virtual const PeerConnectionInterface::RTCConfiguration* configuration() |
| 61 | const = 0; |
| 62 | |
| 63 | // Report the UMA metric SdpFormatReceived for the given remote description. |
| 64 | virtual void ReportSdpFormatReceived( |
| 65 | const SessionDescriptionInterface& remote_description) = 0; |
| 66 | |
| 67 | // Report the UMA metric BundleUsage for the given remote description. |
| 68 | virtual void ReportSdpBundleUsage( |
| 69 | const SessionDescriptionInterface& remote_description) = 0; |
| 70 | |
| 71 | virtual PeerConnectionMessageHandler* message_handler() = 0; |
| 72 | virtual RtpTransmissionManager* rtp_manager() = 0; |
| 73 | virtual const RtpTransmissionManager* rtp_manager() const = 0; |
| 74 | virtual bool dtls_enabled() const = 0; |
| 75 | virtual const PeerConnectionFactoryInterface::Options* options() const = 0; |
| 76 | |
| 77 | // Returns the CryptoOptions for this PeerConnection. This will always |
| 78 | // return the RTCConfiguration.crypto_options if set and will only default |
| 79 | // back to the PeerConnectionFactory settings if nothing was set. |
| 80 | virtual CryptoOptions GetCryptoOptions() = 0; |
| 81 | virtual cricket::ChannelManager* channel_manager() = 0; |
| 82 | virtual JsepTransportController* transport_controller() = 0; |
| 83 | virtual DataChannelController* data_channel_controller() = 0; |
| 84 | virtual cricket::PortAllocator* port_allocator() = 0; |
| 85 | virtual StatsCollector* stats() = 0; |
| 86 | // Returns the observer. Will crash on CHECK if the observer is removed. |
| 87 | virtual PeerConnectionObserver* Observer() const = 0; |
| 88 | virtual bool GetSctpSslRole(rtc::SSLRole* role) = 0; |
| 89 | virtual PeerConnectionInterface::IceConnectionState |
| 90 | ice_connection_state_internal() = 0; |
| 91 | virtual void SetIceConnectionState( |
| 92 | PeerConnectionInterface::IceConnectionState new_state) = 0; |
| 93 | virtual void NoteUsageEvent(UsageEvent event) = 0; |
| 94 | virtual bool IsClosed() const = 0; |
| 95 | // Returns true if the PeerConnection is configured to use Unified Plan |
| 96 | // semantics for creating offers/answers and setting local/remote |
| 97 | // descriptions. If this is true the RtpTransceiver API will also be available |
| 98 | // to the user. If this is false, Plan B semantics are assumed. |
| 99 | // TODO(bugs.webrtc.org/8530): Flip the default to be Unified Plan once |
| 100 | // sufficient time has passed. |
| 101 | virtual bool IsUnifiedPlan() const = 0; |
| 102 | virtual bool ValidateBundleSettings( |
| 103 | const cricket::SessionDescription* desc, |
| 104 | const std::map<std::string, const cricket::ContentGroup*>& |
| 105 | bundle_groups_by_mid) = 0; |
| 106 | |
| 107 | virtual absl::optional<std::string> GetDataMid() const = 0; |
| 108 | // Internal implementation for AddTransceiver family of methods. If |
| 109 | // `fire_callback` is set, fires OnRenegotiationNeeded callback if successful. |
| 110 | virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> |
| 111 | AddTransceiver(cricket::MediaType media_type, |
| 112 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 113 | const RtpTransceiverInit& init, |
| 114 | bool fire_callback = true) = 0; |
| 115 | // Asynchronously calls SctpTransport::Start() on the network thread for |
| 116 | // `sctp_mid()` if set. Called as part of setting the local description. |
| 117 | virtual void StartSctpTransport(int local_port, |
| 118 | int remote_port, |
| 119 | int max_message_size) = 0; |
| 120 | |
| 121 | // Asynchronously adds a remote candidate on the network thread. |
| 122 | virtual void AddRemoteCandidate(const std::string& mid, |
| 123 | const cricket::Candidate& candidate) = 0; |
| 124 | |
| 125 | virtual Call* call_ptr() = 0; |
| 126 | // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by |
| 127 | // this session. |
| 128 | virtual bool SrtpRequired() const = 0; |
| 129 | virtual bool SetupDataChannelTransport_n(const std::string& mid) = 0; |
| 130 | virtual void TeardownDataChannelTransport_n() = 0; |
| 131 | virtual void SetSctpDataMid(const std::string& mid) = 0; |
| 132 | virtual void ResetSctpDataMid() = 0; |
| 133 | }; |
| 134 | |
| 135 | // Functions defined in this class are called by other objects, |
| 136 | // but not by SdpOfferAnswerHandler. |
| 137 | class PeerConnectionInternal : public PeerConnectionInterface, |
| 138 | public PeerConnectionSdpMethods { |
| 139 | public: |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 140 | // Returns true if we were the initial offerer. |
| 141 | virtual bool initial_offerer() const = 0; |
| 142 | |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 143 | virtual std::vector< |
| 144 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 145 | GetTransceiversInternal() const = 0; |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 146 | |
Taylor Brandstetter | 3a034e1 | 2020-07-09 15:32:34 -0700 | [diff] [blame] | 147 | virtual sigslot::signal1<SctpDataChannel*>& |
| 148 | SignalSctpDataChannelCreated() = 0; |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 149 | |
Tomas Gunnarsson | 2e94de5 | 2020-06-16 16:54:10 +0200 | [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 15:32:34 -0700 | [diff] [blame] | 152 | virtual std::vector<DataChannelStats> GetDataChannelStats() const { |
Tomas Gunnarsson | 2e94de5 | 2020-06-16 16:54:10 +0200 | [diff] [blame] | 153 | return {}; |
| 154 | } |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 155 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 156 | virtual absl::optional<std::string> sctp_transport_name() const = 0; |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 157 | |
Qingsi Wang | 72a43a1 | 2018-02-20 16:03:18 -0800 | [diff] [blame] | 158 | virtual cricket::CandidateStatsList GetPooledCandidateStats() const = 0; |
| 159 | |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [diff] [blame] | 160 | // Returns a map from transport name to transport stats for all given |
| 161 | // transport names. |
Tomas Gunnarsson | bfd9ba8 | 2021-04-18 11:55:57 +0200 | [diff] [blame] | 162 | // Must be called on the network thread. |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [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-23 16:38:46 -0800 | [diff] [blame] | 165 | |
| 166 | virtual Call::Stats GetCallStats() = 0; |
| 167 | |
| 168 | virtual bool GetLocalCertificate( |
| 169 | const std::string& transport_name, |
| 170 | rtc::scoped_refptr<rtc::RTCCertificate>* certificate) = 0; |
Taylor Brandstetter | c392866 | 2018-02-23 13:04:51 -0800 | [diff] [blame] | 171 | virtual std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain( |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 172 | const std::string& transport_name) = 0; |
| 173 | |
| 174 | // Returns true if there was an ICE restart initiated by the remote offer. |
| 175 | virtual bool IceRestartPending(const std::string& content_name) const = 0; |
| 176 | |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 177 | // Get SSL role for an arbitrary m= section (handles bundling correctly). |
| 178 | virtual bool GetSslRole(const std::string& content_name, |
| 179 | rtc::SSLRole* role) = 0; |
| 180 | }; |
| 181 | |
| 182 | } // namespace webrtc |
| 183 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 184 | #endif // PC_PEER_CONNECTION_INTERNAL_H_ |