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