blob: c91a44a1482a0376ec7b2cd577d8923cea1dca6f [file] [log] [blame]
Steve Anton2d8609c2018-01-24 00:38:461/*
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 17:11:0011#ifndef PC_PEER_CONNECTION_INTERNAL_H_
12#define PC_PEER_CONNECTION_INTERNAL_H_
Steve Anton2d8609c2018-01-24 00:38:4613
14#include <map>
15#include <memory>
Steve Anton5dfde182018-02-06 18:34:4016#include <set>
Steve Anton2d8609c2018-01-24 00:38:4617#include <string>
18#include <vector>
19
Fredrik Hernqvistefbe7532023-01-13 15:42:3620#include "absl/types/optional.h"
Steve Anton10542f22019-01-11 17:11:0021#include "api/peer_connection_interface.h"
Niels Möller8366e172018-02-14 11:20:1322#include "call/call.h"
Fredrik Hernqvistefbe7532023-01-13 15:42:3623#include "modules/audio_device/include/audio_device.h"
Harald Alvestrand5b661302022-01-28 13:08:3424#include "pc/jsep_transport_controller.h"
25#include "pc/peer_connection_message_handler.h"
Steve Anton10542f22019-01-11 17:11:0026#include "pc/rtp_transceiver.h"
Harald Alvestrand5b661302022-01-28 13:08:3427#include "pc/rtp_transmission_manager.h"
Taylor Brandstetter3a034e12020-07-09 22:32:3428#include "pc/sctp_data_channel.h"
Steve Anton2d8609c2018-01-24 00:38:4629
30namespace webrtc {
31
Harald Alvestrand67a68d52022-02-07 05:07:0332class DataChannelController;
Henrik Boströmf7859892022-07-04 12:36:3733class LegacyStatsCollector;
Harald Alvestrand5b661302022-01-28 13:08:3434
35// This interface defines the functions that are needed for
36// SdpOfferAnswerHandler to access PeerConnection internal state.
37class PeerConnectionSdpMethods {
Steve Anton2d8609c2018-01-24 00:38:4638 public:
Harald Alvestrand5b661302022-01-28 13:08:3439 virtual ~PeerConnectionSdpMethods() = default;
40
Steve Anton2d8609c2018-01-24 00:38:4641 // The SDP session ID as defined by RFC 3264.
Steve Antonbe5e2082018-01-24 23:29:1742 virtual std::string session_id() const = 0;
Steve Anton2d8609c2018-01-24 00:38:4643
Harald Alvestrand5b661302022-01-28 13:08:3444 // Returns true if the ICE restart flag above was set, and no ICE restart has
45 // occurred yet for this transport (by applying a local description with
46 // changed ufrag/password). If the transport has been deleted as a result of
47 // bundling, returns false.
48 virtual bool NeedsIceRestart(const std::string& content_name) const = 0;
49
50 virtual absl::optional<std::string> sctp_mid() const = 0;
51
52 // Functions below this comment are known to only be accessed
53 // from SdpOfferAnswerHandler.
54 // Return a pointer to the active configuration.
55 virtual const PeerConnectionInterface::RTCConfiguration* configuration()
56 const = 0;
57
Harald Alvestrand5b661302022-01-28 13:08:3458 // Report the UMA metric BundleUsage for the given remote description.
59 virtual void ReportSdpBundleUsage(
60 const SessionDescriptionInterface& remote_description) = 0;
61
62 virtual PeerConnectionMessageHandler* message_handler() = 0;
63 virtual RtpTransmissionManager* rtp_manager() = 0;
64 virtual const RtpTransmissionManager* rtp_manager() const = 0;
65 virtual bool dtls_enabled() const = 0;
66 virtual const PeerConnectionFactoryInterface::Options* options() const = 0;
67
68 // Returns the CryptoOptions for this PeerConnection. This will always
69 // return the RTCConfiguration.crypto_options if set and will only default
70 // back to the PeerConnectionFactory settings if nothing was set.
71 virtual CryptoOptions GetCryptoOptions() = 0;
Harald Alvestrandbc32c562022-02-09 12:08:4772 virtual JsepTransportController* transport_controller_s() = 0;
73 virtual JsepTransportController* transport_controller_n() = 0;
Harald Alvestrand5b661302022-01-28 13:08:3474 virtual DataChannelController* data_channel_controller() = 0;
75 virtual cricket::PortAllocator* port_allocator() = 0;
Henrik Boströmf7859892022-07-04 12:36:3776 virtual LegacyStatsCollector* legacy_stats() = 0;
Harald Alvestrand5b661302022-01-28 13:08:3477 // Returns the observer. Will crash on CHECK if the observer is removed.
78 virtual PeerConnectionObserver* Observer() const = 0;
Tommi335d0842023-03-25 09:56:1879 virtual absl::optional<rtc::SSLRole> GetSctpSslRole_n() = 0;
Harald Alvestrand5b661302022-01-28 13:08:3480 virtual PeerConnectionInterface::IceConnectionState
81 ice_connection_state_internal() = 0;
82 virtual void SetIceConnectionState(
83 PeerConnectionInterface::IceConnectionState new_state) = 0;
84 virtual void NoteUsageEvent(UsageEvent event) = 0;
85 virtual bool IsClosed() const = 0;
86 // Returns true if the PeerConnection is configured to use Unified Plan
87 // semantics for creating offers/answers and setting local/remote
88 // descriptions. If this is true the RtpTransceiver API will also be available
89 // to the user. If this is false, Plan B semantics are assumed.
90 // TODO(bugs.webrtc.org/8530): Flip the default to be Unified Plan once
91 // sufficient time has passed.
92 virtual bool IsUnifiedPlan() const = 0;
93 virtual bool ValidateBundleSettings(
94 const cricket::SessionDescription* desc,
95 const std::map<std::string, const cricket::ContentGroup*>&
96 bundle_groups_by_mid) = 0;
97
98 virtual absl::optional<std::string> GetDataMid() const = 0;
99 // Internal implementation for AddTransceiver family of methods. If
100 // `fire_callback` is set, fires OnRenegotiationNeeded callback if successful.
101 virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>
102 AddTransceiver(cricket::MediaType media_type,
103 rtc::scoped_refptr<MediaStreamTrackInterface> track,
104 const RtpTransceiverInit& init,
105 bool fire_callback = true) = 0;
106 // Asynchronously calls SctpTransport::Start() on the network thread for
107 // `sctp_mid()` if set. Called as part of setting the local description.
108 virtual void StartSctpTransport(int local_port,
109 int remote_port,
110 int max_message_size) = 0;
111
112 // Asynchronously adds a remote candidate on the network thread.
113 virtual void AddRemoteCandidate(const std::string& mid,
114 const cricket::Candidate& candidate) = 0;
115
116 virtual Call* call_ptr() = 0;
117 // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by
118 // this session.
119 virtual bool SrtpRequired() const = 0;
Tommiaa3c9f22023-04-18 10:19:19120 // Configures the data channel transport on the network thread.
121 // The return value will be unset if an error occurs. If the setup succeeded
122 // the return value will be set and contain the name of the transport
123 // (empty string if a name isn't available).
124 virtual absl::optional<std::string> SetupDataChannelTransport_n(
125 absl::string_view mid) = 0;
Tommib00d63c2023-04-12 17:49:53126 virtual void TeardownDataChannelTransport_n(RTCError error) = 0;
Tommiaa3c9f22023-04-18 10:19:19127 virtual void SetSctpDataInfo(absl::string_view mid,
128 absl::string_view transport_name) = 0;
129 virtual void ResetSctpDataInfo() = 0;
Jonas Oreland6c7f9842022-04-19 15:24:10130
131 virtual const FieldTrialsView& trials() const = 0;
Philipp Hancke7baa63f2022-09-01 13:39:50132
133 virtual void ClearStatsCache() = 0;
Harald Alvestrand5b661302022-01-28 13:08:34134};
135
136// Functions defined in this class are called by other objects,
137// but not by SdpOfferAnswerHandler.
138class PeerConnectionInternal : public PeerConnectionInterface,
Tommid2afbaf2023-03-02 09:51:16139 public PeerConnectionSdpMethods {
Harald Alvestrand5b661302022-01-28 13:08:34140 public:
Harald Alvestrand66c40362022-01-28 17:41:30141 virtual rtc::Thread* network_thread() const = 0;
142 virtual rtc::Thread* worker_thread() const = 0;
143
Steve Anton2d8609c2018-01-24 00:38:46144 // Returns true if we were the initial offerer.
145 virtual bool initial_offerer() const = 0;
146
Steve Anton2d8609c2018-01-24 00:38:46147 virtual std::vector<
148 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
Steve Antonb8867112018-02-13 18:07:54149 GetTransceiversInternal() const = 0;
Steve Anton2d8609c2018-01-24 00:38:46150
Tomas Gunnarsson2e94de52020-06-16 14:54:10151 // Call on the network thread to fetch stats for all the data channels.
152 // TODO(tommi): Make pure virtual after downstream updates.
Taylor Brandstetter3a034e12020-07-09 22:32:34153 virtual std::vector<DataChannelStats> GetDataChannelStats() const {
Tomas Gunnarsson2e94de52020-06-16 14:54:10154 return {};
155 }
Steve Anton2d8609c2018-01-24 00:38:46156
Danil Chapovalov66cadcc2018-06-19 14:47:43157 virtual absl::optional<std::string> sctp_transport_name() const = 0;
Steve Anton2d8609c2018-01-24 00:38:46158
Qingsi Wang72a43a12018-02-21 00:03:18159 virtual cricket::CandidateStatsList GetPooledCandidateStats() const = 0;
160
Steve Anton5dfde182018-02-06 18:34:40161 // Returns a map from transport name to transport stats for all given
162 // transport names.
Tomas Gunnarssonbfd9ba82021-04-18 09:55:57163 // Must be called on the network thread.
Steve Anton5dfde182018-02-06 18:34:40164 virtual std::map<std::string, cricket::TransportStats>
165 GetTransportStatsByNames(const std::set<std::string>& transport_names) = 0;
Steve Anton2d8609c2018-01-24 00:38:46166
167 virtual Call::Stats GetCallStats() = 0;
168
Fredrik Hernqvistefbe7532023-01-13 15:42:36169 virtual absl::optional<AudioDeviceModule::Stats> GetAudioDeviceStats() = 0;
170
Steve Anton2d8609c2018-01-24 00:38:46171 virtual bool GetLocalCertificate(
172 const std::string& transport_name,
173 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) = 0;
Taylor Brandstetterc3928662018-02-23 21:04:51174 virtual std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Steve Anton2d8609c2018-01-24 00:38:46175 const std::string& transport_name) = 0;
176
177 // Returns true if there was an ICE restart initiated by the remote offer.
178 virtual bool IceRestartPending(const std::string& content_name) const = 0;
179
Steve Anton2d8609c2018-01-24 00:38:46180 // Get SSL role for an arbitrary m= section (handles bundling correctly).
181 virtual bool GetSslRole(const std::string& content_name,
182 rtc::SSLRole* role) = 0;
Harald Alvestrand5b84f382022-02-08 10:49:09183 // Functions needed by DataChannelController
184 virtual void NoteDataAddedEvent() {}
Tommid2afbaf2023-03-02 09:51:16185 // Handler for sctp data channel state changes.
Tommi56548982023-03-27 16:07:34186 // The `channel_id` is the same unique identifier as used in
187 // `DataChannelStats::internal_id and
188 // `RTCDataChannelStats::data_channel_identifier`.
Tommid2afbaf2023-03-02 09:51:16189 virtual void OnSctpDataChannelStateChanged(
Tommi56548982023-03-27 16:07:34190 int channel_id,
Tommid2afbaf2023-03-02 09:51:16191 DataChannelInterface::DataState state) {}
Steve Anton2d8609c2018-01-24 00:38:46192};
193
194} // namespace webrtc
195
Steve Anton10542f22019-01-11 17:11:00196#endif // PC_PEER_CONNECTION_INTERNAL_H_