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 11 #ifndef PC_PEER_CONNECTION_INTERNAL_H_ 12 #define PC_PEER_CONNECTION_INTERNAL_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 "call/call.h" 22 #include "pc/jsep_transport_controller.h" 23 #include "pc/peer_connection_message_handler.h" 24 #include "pc/rtp_transceiver.h" 25 #include "pc/rtp_transmission_manager.h" 26 #include "pc/sctp_data_channel.h" 27 28 namespace webrtc { 29 30 class DataChannelController; 31 class LegacyStatsCollector; 32 33 // This interface defines the functions that are needed for 34 // SdpOfferAnswerHandler to access PeerConnection internal state. 35 class PeerConnectionSdpMethods { 36 public: 37 virtual ~PeerConnectionSdpMethods() = default; 38 39 // The SDP session ID as defined by RFC 3264. 40 virtual std::string session_id() const = 0; 41 42 // Returns true if the ICE restart flag above was set, and no ICE restart has 43 // occurred yet for this transport (by applying a local description with 44 // changed ufrag/password). If the transport has been deleted as a result of 45 // bundling, returns false. 46 virtual bool NeedsIceRestart(const std::string& content_name) const = 0; 47 48 virtual absl::optional<std::string> sctp_mid() const = 0; 49 50 // Functions below this comment are known to only be accessed 51 // from SdpOfferAnswerHandler. 52 // Return a pointer to the active configuration. 53 virtual const PeerConnectionInterface::RTCConfiguration* configuration() 54 const = 0; 55 56 // Report the UMA metric BundleUsage for the given remote description. 57 virtual void ReportSdpBundleUsage( 58 const SessionDescriptionInterface& remote_description) = 0; 59 60 virtual PeerConnectionMessageHandler* message_handler() = 0; 61 virtual RtpTransmissionManager* rtp_manager() = 0; 62 virtual const RtpTransmissionManager* rtp_manager() const = 0; 63 virtual bool dtls_enabled() const = 0; 64 virtual const PeerConnectionFactoryInterface::Options* options() const = 0; 65 66 // Returns the CryptoOptions for this PeerConnection. This will always 67 // return the RTCConfiguration.crypto_options if set and will only default 68 // back to the PeerConnectionFactory settings if nothing was set. 69 virtual CryptoOptions GetCryptoOptions() = 0; 70 virtual JsepTransportController* transport_controller_s() = 0; 71 virtual JsepTransportController* transport_controller_n() = 0; 72 virtual DataChannelController* data_channel_controller() = 0; 73 virtual cricket::PortAllocator* port_allocator() = 0; 74 virtual LegacyStatsCollector* legacy_stats() = 0; 75 // Returns the observer. Will crash on CHECK if the observer is removed. 76 virtual PeerConnectionObserver* Observer() const = 0; 77 virtual bool GetSctpSslRole(rtc::SSLRole* role) = 0; 78 virtual PeerConnectionInterface::IceConnectionState 79 ice_connection_state_internal() = 0; 80 virtual void SetIceConnectionState( 81 PeerConnectionInterface::IceConnectionState new_state) = 0; 82 virtual void NoteUsageEvent(UsageEvent event) = 0; 83 virtual bool IsClosed() const = 0; 84 // Returns true if the PeerConnection is configured to use Unified Plan 85 // semantics for creating offers/answers and setting local/remote 86 // descriptions. If this is true the RtpTransceiver API will also be available 87 // to the user. If this is false, Plan B semantics are assumed. 88 // TODO(bugs.webrtc.org/8530): Flip the default to be Unified Plan once 89 // sufficient time has passed. 90 virtual bool IsUnifiedPlan() const = 0; 91 virtual bool ValidateBundleSettings( 92 const cricket::SessionDescription* desc, 93 const std::map<std::string, const cricket::ContentGroup*>& 94 bundle_groups_by_mid) = 0; 95 96 virtual absl::optional<std::string> GetDataMid() const = 0; 97 // Internal implementation for AddTransceiver family of methods. If 98 // `fire_callback` is set, fires OnRenegotiationNeeded callback if successful. 99 virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> 100 AddTransceiver(cricket::MediaType media_type, 101 rtc::scoped_refptr<MediaStreamTrackInterface> track, 102 const RtpTransceiverInit& init, 103 bool fire_callback = true) = 0; 104 // Asynchronously calls SctpTransport::Start() on the network thread for 105 // `sctp_mid()` if set. Called as part of setting the local description. 106 virtual void StartSctpTransport(int local_port, 107 int remote_port, 108 int max_message_size) = 0; 109 110 // Asynchronously adds a remote candidate on the network thread. 111 virtual void AddRemoteCandidate(const std::string& mid, 112 const cricket::Candidate& candidate) = 0; 113 114 virtual Call* call_ptr() = 0; 115 // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by 116 // this session. 117 virtual bool SrtpRequired() const = 0; 118 virtual bool SetupDataChannelTransport_n(const std::string& mid) = 0; 119 virtual void TeardownDataChannelTransport_n() = 0; 120 virtual void SetSctpDataMid(const std::string& mid) = 0; 121 virtual void ResetSctpDataMid() = 0; 122 123 virtual const FieldTrialsView& trials() const = 0; 124 125 virtual void ClearStatsCache() = 0; 126 }; 127 128 // Functions defined in this class are called by other objects, 129 // but not by SdpOfferAnswerHandler. 130 class PeerConnectionInternal : public PeerConnectionInterface, 131 public PeerConnectionSdpMethods, 132 public sigslot::has_slots<> { 133 public: 134 virtual rtc::Thread* network_thread() const = 0; 135 virtual rtc::Thread* worker_thread() const = 0; 136 137 // Returns true if we were the initial offerer. 138 virtual bool initial_offerer() const = 0; 139 140 virtual std::vector< 141 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> 142 GetTransceiversInternal() const = 0; 143 144 virtual sigslot::signal1<SctpDataChannel*>& 145 SignalSctpDataChannelCreated() = 0; 146 147 // Call on the network thread to fetch stats for all the data channels. 148 // TODO(tommi): Make pure virtual after downstream updates. GetDataChannelStats()149 virtual std::vector<DataChannelStats> GetDataChannelStats() const { 150 return {}; 151 } 152 153 virtual absl::optional<std::string> sctp_transport_name() const = 0; 154 155 virtual cricket::CandidateStatsList GetPooledCandidateStats() const = 0; 156 157 // Returns a map from transport name to transport stats for all given 158 // transport names. 159 // Must be called on the network thread. 160 virtual std::map<std::string, cricket::TransportStats> 161 GetTransportStatsByNames(const std::set<std::string>& transport_names) = 0; 162 163 virtual Call::Stats GetCallStats() = 0; 164 165 virtual bool GetLocalCertificate( 166 const std::string& transport_name, 167 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) = 0; 168 virtual std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain( 169 const std::string& transport_name) = 0; 170 171 // Returns true if there was an ICE restart initiated by the remote offer. 172 virtual bool IceRestartPending(const std::string& content_name) const = 0; 173 174 // Get SSL role for an arbitrary m= section (handles bundling correctly). 175 virtual bool GetSslRole(const std::string& content_name, 176 rtc::SSLRole* role) = 0; 177 // Functions needed by DataChannelController NoteDataAddedEvent()178 virtual void NoteDataAddedEvent() {} 179 // Handler for the "channel closed" signal OnSctpDataChannelClosed(DataChannelInterface * channel)180 virtual void OnSctpDataChannelClosed(DataChannelInterface* channel) {} 181 }; 182 183 } // namespace webrtc 184 185 #endif // PC_PEER_CONNECTION_INTERNAL_H_ 186