blob: dc8204521bc69a779bb505b53f11aa7e91f563bb [file] [log] [blame]
Steve Anton2d8609c2018-01-23 16:38:46 -08001/*
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 Anton10542f22019-01-11 09:11:00 -080011#ifndef PC_PEER_CONNECTION_INTERNAL_H_
12#define PC_PEER_CONNECTION_INTERNAL_H_
Steve Anton2d8609c2018-01-23 16:38:46 -080013
14#include <map>
15#include <memory>
Steve Anton5dfde182018-02-06 10:34:40 -080016#include <set>
Steve Anton2d8609c2018-01-23 16:38:46 -080017#include <string>
18#include <vector>
19
Steve Anton10542f22019-01-11 09:11:00 -080020#include "api/peer_connection_interface.h"
Niels Möller8366e172018-02-14 12:20:13 +010021#include "call/call.h"
Harald Alvestrand5b661302022-01-28 13:08:34 +000022#include "pc/data_channel_controller.h"
23#include "pc/jsep_transport_controller.h"
24#include "pc/peer_connection_message_handler.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "pc/rtp_transceiver.h"
Harald Alvestrand5b661302022-01-28 13:08:34 +000026#include "pc/rtp_transmission_manager.h"
Taylor Brandstetter3a034e12020-07-09 15:32:34 -070027#include "pc/sctp_data_channel.h"
Steve Anton2d8609c2018-01-23 16:38:46 -080028
29namespace webrtc {
30
Harald Alvestrand5b661302022-01-28 13:08:34 +000031class StatsCollector;
32
33// This interface defines the functions that are needed for
34// SdpOfferAnswerHandler to access PeerConnection internal state.
35class PeerConnectionSdpMethods {
Steve Anton2d8609c2018-01-23 16:38:46 -080036 public:
Harald Alvestrand5b661302022-01-28 13:08:34 +000037 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 Anton2d8609c2018-01-23 16:38:46 -080043 virtual rtc::Thread* network_thread() const = 0;
44 virtual rtc::Thread* worker_thread() const = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -080045
46 // The SDP session ID as defined by RFC 3264.
Steve Antonbe5e2082018-01-24 15:29:17 -080047 virtual std::string session_id() const = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -080048
Harald Alvestrand5b661302022-01-28 13:08:34 +000049 // 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.
137class PeerConnectionInternal : public PeerConnectionInterface,
138 public PeerConnectionSdpMethods {
139 public:
Steve Anton2d8609c2018-01-23 16:38:46 -0800140 // Returns true if we were the initial offerer.
141 virtual bool initial_offerer() const = 0;
142
Steve Anton2d8609c2018-01-23 16:38:46 -0800143 virtual std::vector<
144 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
Steve Antonb8867112018-02-13 10:07:54 -0800145 GetTransceiversInternal() const = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -0800146
Taylor Brandstetter3a034e12020-07-09 15:32:34 -0700147 virtual sigslot::signal1<SctpDataChannel*>&
148 SignalSctpDataChannelCreated() = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -0800149
Tomas Gunnarsson2e94de52020-06-16 16:54:10 +0200150 // Call on the network thread to fetch stats for all the data channels.
151 // TODO(tommi): Make pure virtual after downstream updates.
Taylor Brandstetter3a034e12020-07-09 15:32:34 -0700152 virtual std::vector<DataChannelStats> GetDataChannelStats() const {
Tomas Gunnarsson2e94de52020-06-16 16:54:10 +0200153 return {};
154 }
Steve Anton2d8609c2018-01-23 16:38:46 -0800155
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200156 virtual absl::optional<std::string> sctp_transport_name() const = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -0800157
Qingsi Wang72a43a12018-02-20 16:03:18 -0800158 virtual cricket::CandidateStatsList GetPooledCandidateStats() const = 0;
159
Steve Anton5dfde182018-02-06 10:34:40 -0800160 // Returns a map from transport name to transport stats for all given
161 // transport names.
Tomas Gunnarssonbfd9ba82021-04-18 11:55:57 +0200162 // Must be called on the network thread.
Steve Anton5dfde182018-02-06 10:34:40 -0800163 virtual std::map<std::string, cricket::TransportStats>
164 GetTransportStatsByNames(const std::set<std::string>& transport_names) = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -0800165
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 Brandstetterc3928662018-02-23 13:04:51 -0800171 virtual std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Steve Anton2d8609c2018-01-23 16:38:46 -0800172 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 Anton2d8609c2018-01-23 16:38:46 -0800177 // 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 Anton10542f22019-01-11 09:11:00 -0800184#endif // PC_PEER_CONNECTION_INTERNAL_H_