blob: 266ce238c04d72530c6460d019fc4bd11c4a4f56 [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
Steve Anton2d8609c2018-01-23 16:38:46 -080039 // The SDP session ID as defined by RFC 3264.
Steve Antonbe5e2082018-01-24 15:29:17 -080040 virtual std::string session_id() const = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -080041
Harald Alvestrand5b661302022-01-28 13:08:34 +000042 // 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 SdpFormatReceived for the given remote description.
57 virtual void ReportSdpFormatReceived(
58 const SessionDescriptionInterface& remote_description) = 0;
59
60 // Report the UMA metric BundleUsage for the given remote description.
61 virtual void ReportSdpBundleUsage(
62 const SessionDescriptionInterface& remote_description) = 0;
63
64 virtual PeerConnectionMessageHandler* message_handler() = 0;
65 virtual RtpTransmissionManager* rtp_manager() = 0;
66 virtual const RtpTransmissionManager* rtp_manager() const = 0;
67 virtual bool dtls_enabled() const = 0;
68 virtual const PeerConnectionFactoryInterface::Options* options() const = 0;
69
70 // Returns the CryptoOptions for this PeerConnection. This will always
71 // return the RTCConfiguration.crypto_options if set and will only default
72 // back to the PeerConnectionFactory settings if nothing was set.
73 virtual CryptoOptions GetCryptoOptions() = 0;
Harald Alvestrand5b661302022-01-28 13:08:34 +000074 virtual JsepTransportController* transport_controller() = 0;
75 virtual DataChannelController* data_channel_controller() = 0;
76 virtual cricket::PortAllocator* port_allocator() = 0;
77 virtual StatsCollector* stats() = 0;
78 // Returns the observer. Will crash on CHECK if the observer is removed.
79 virtual PeerConnectionObserver* Observer() const = 0;
80 virtual bool GetSctpSslRole(rtc::SSLRole* role) = 0;
81 virtual PeerConnectionInterface::IceConnectionState
82 ice_connection_state_internal() = 0;
83 virtual void SetIceConnectionState(
84 PeerConnectionInterface::IceConnectionState new_state) = 0;
85 virtual void NoteUsageEvent(UsageEvent event) = 0;
86 virtual bool IsClosed() const = 0;
87 // Returns true if the PeerConnection is configured to use Unified Plan
88 // semantics for creating offers/answers and setting local/remote
89 // descriptions. If this is true the RtpTransceiver API will also be available
90 // to the user. If this is false, Plan B semantics are assumed.
91 // TODO(bugs.webrtc.org/8530): Flip the default to be Unified Plan once
92 // sufficient time has passed.
93 virtual bool IsUnifiedPlan() const = 0;
94 virtual bool ValidateBundleSettings(
95 const cricket::SessionDescription* desc,
96 const std::map<std::string, const cricket::ContentGroup*>&
97 bundle_groups_by_mid) = 0;
98
99 virtual absl::optional<std::string> GetDataMid() const = 0;
100 // Internal implementation for AddTransceiver family of methods. If
101 // `fire_callback` is set, fires OnRenegotiationNeeded callback if successful.
102 virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>
103 AddTransceiver(cricket::MediaType media_type,
104 rtc::scoped_refptr<MediaStreamTrackInterface> track,
105 const RtpTransceiverInit& init,
106 bool fire_callback = true) = 0;
107 // Asynchronously calls SctpTransport::Start() on the network thread for
108 // `sctp_mid()` if set. Called as part of setting the local description.
109 virtual void StartSctpTransport(int local_port,
110 int remote_port,
111 int max_message_size) = 0;
112
113 // Asynchronously adds a remote candidate on the network thread.
114 virtual void AddRemoteCandidate(const std::string& mid,
115 const cricket::Candidate& candidate) = 0;
116
117 virtual Call* call_ptr() = 0;
118 // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by
119 // this session.
120 virtual bool SrtpRequired() const = 0;
121 virtual bool SetupDataChannelTransport_n(const std::string& mid) = 0;
122 virtual void TeardownDataChannelTransport_n() = 0;
123 virtual void SetSctpDataMid(const std::string& mid) = 0;
124 virtual void ResetSctpDataMid() = 0;
125};
126
127// Functions defined in this class are called by other objects,
128// but not by SdpOfferAnswerHandler.
129class PeerConnectionInternal : public PeerConnectionInterface,
130 public PeerConnectionSdpMethods {
131 public:
Harald Alvestrand66c40362022-01-28 17:41:30 +0000132 virtual rtc::Thread* network_thread() const = 0;
133 virtual rtc::Thread* worker_thread() const = 0;
134
Steve Anton2d8609c2018-01-23 16:38:46 -0800135 // Returns true if we were the initial offerer.
136 virtual bool initial_offerer() const = 0;
137
Steve Anton2d8609c2018-01-23 16:38:46 -0800138 virtual std::vector<
139 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
Steve Antonb8867112018-02-13 10:07:54 -0800140 GetTransceiversInternal() const = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -0800141
Taylor Brandstetter3a034e12020-07-09 15:32:34 -0700142 virtual sigslot::signal1<SctpDataChannel*>&
143 SignalSctpDataChannelCreated() = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -0800144
Tomas Gunnarsson2e94de52020-06-16 16:54:10 +0200145 // Call on the network thread to fetch stats for all the data channels.
146 // TODO(tommi): Make pure virtual after downstream updates.
Taylor Brandstetter3a034e12020-07-09 15:32:34 -0700147 virtual std::vector<DataChannelStats> GetDataChannelStats() const {
Tomas Gunnarsson2e94de52020-06-16 16:54:10 +0200148 return {};
149 }
Steve Anton2d8609c2018-01-23 16:38:46 -0800150
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200151 virtual absl::optional<std::string> sctp_transport_name() const = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -0800152
Qingsi Wang72a43a12018-02-20 16:03:18 -0800153 virtual cricket::CandidateStatsList GetPooledCandidateStats() const = 0;
154
Steve Anton5dfde182018-02-06 10:34:40 -0800155 // Returns a map from transport name to transport stats for all given
156 // transport names.
Tomas Gunnarssonbfd9ba82021-04-18 11:55:57 +0200157 // Must be called on the network thread.
Steve Anton5dfde182018-02-06 10:34:40 -0800158 virtual std::map<std::string, cricket::TransportStats>
159 GetTransportStatsByNames(const std::set<std::string>& transport_names) = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -0800160
161 virtual Call::Stats GetCallStats() = 0;
162
163 virtual bool GetLocalCertificate(
164 const std::string& transport_name,
165 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) = 0;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800166 virtual std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Steve Anton2d8609c2018-01-23 16:38:46 -0800167 const std::string& transport_name) = 0;
168
169 // Returns true if there was an ICE restart initiated by the remote offer.
170 virtual bool IceRestartPending(const std::string& content_name) const = 0;
171
Steve Anton2d8609c2018-01-23 16:38:46 -0800172 // Get SSL role for an arbitrary m= section (handles bundling correctly).
173 virtual bool GetSslRole(const std::string& content_name,
174 rtc::SSLRole* role) = 0;
175};
176
177} // namespace webrtc
178
Steve Anton10542f22019-01-11 09:11:00 -0800179#endif // PC_PEER_CONNECTION_INTERNAL_H_