blob: 1085ff94b1099dab5bc74c5fd731ee9d17554cbc [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
Fredrik Hernqvistefbe7532023-01-13 16:42:36 +010020#include "absl/types/optional.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "api/peer_connection_interface.h"
Niels Möller8366e172018-02-14 12:20:13 +010022#include "call/call.h"
Fredrik Hernqvistefbe7532023-01-13 16:42:36 +010023#include "modules/audio_device/include/audio_device.h"
Harald Alvestrand5b661302022-01-28 13:08:34 +000024#include "pc/jsep_transport_controller.h"
25#include "pc/peer_connection_message_handler.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "pc/rtp_transceiver.h"
Harald Alvestrand5b661302022-01-28 13:08:34 +000027#include "pc/rtp_transmission_manager.h"
Taylor Brandstetter3a034e12020-07-09 15:32:34 -070028#include "pc/sctp_data_channel.h"
Steve Anton2d8609c2018-01-23 16:38:46 -080029
30namespace webrtc {
31
Harald Alvestrand67a68d52022-02-07 05:07:03 +000032class DataChannelController;
Henrik Boströmf7859892022-07-04 14:36:37 +020033class LegacyStatsCollector;
Harald Alvestrand5b661302022-01-28 13:08:34 +000034
35// This interface defines the functions that are needed for
36// SdpOfferAnswerHandler to access PeerConnection internal state.
37class PeerConnectionSdpMethods {
Steve Anton2d8609c2018-01-23 16:38:46 -080038 public:
Harald Alvestrand5b661302022-01-28 13:08:34 +000039 virtual ~PeerConnectionSdpMethods() = default;
40
Steve Anton2d8609c2018-01-23 16:38:46 -080041 // The SDP session ID as defined by RFC 3264.
Steve Antonbe5e2082018-01-24 15:29:17 -080042 virtual std::string session_id() const = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -080043
Harald Alvestrand5b661302022-01-28 13:08:34 +000044 // 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:34 +000058 // 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:47 +000072 virtual JsepTransportController* transport_controller_s() = 0;
73 virtual JsepTransportController* transport_controller_n() = 0;
Harald Alvestrand5b661302022-01-28 13:08:34 +000074 virtual DataChannelController* data_channel_controller() = 0;
75 virtual cricket::PortAllocator* port_allocator() = 0;
Henrik Boströmf7859892022-07-04 14:36:37 +020076 virtual LegacyStatsCollector* legacy_stats() = 0;
Harald Alvestrand5b661302022-01-28 13:08:34 +000077 // Returns the observer. Will crash on CHECK if the observer is removed.
78 virtual PeerConnectionObserver* Observer() const = 0;
79 virtual bool GetSctpSslRole(rtc::SSLRole* role) = 0;
80 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;
120 virtual bool SetupDataChannelTransport_n(const std::string& mid) = 0;
121 virtual void TeardownDataChannelTransport_n() = 0;
122 virtual void SetSctpDataMid(const std::string& mid) = 0;
123 virtual void ResetSctpDataMid() = 0;
Jonas Oreland6c7f9842022-04-19 17:24:10 +0200124
125 virtual const FieldTrialsView& trials() const = 0;
Philipp Hancke7baa63f2022-09-01 15:39:50 +0200126
127 virtual void ClearStatsCache() = 0;
Harald Alvestrand5b661302022-01-28 13:08:34 +0000128};
129
130// Functions defined in this class are called by other objects,
131// but not by SdpOfferAnswerHandler.
132class PeerConnectionInternal : public PeerConnectionInterface,
Harald Alvestrand5b84f382022-02-08 10:49:09 +0000133 public PeerConnectionSdpMethods,
134 public sigslot::has_slots<> {
Harald Alvestrand5b661302022-01-28 13:08:34 +0000135 public:
Harald Alvestrand66c40362022-01-28 17:41:30 +0000136 virtual rtc::Thread* network_thread() const = 0;
137 virtual rtc::Thread* worker_thread() const = 0;
138
Steve Anton2d8609c2018-01-23 16:38:46 -0800139 // Returns true if we were the initial offerer.
140 virtual bool initial_offerer() const = 0;
141
Steve Anton2d8609c2018-01-23 16:38:46 -0800142 virtual std::vector<
143 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
Steve Antonb8867112018-02-13 10:07:54 -0800144 GetTransceiversInternal() const = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -0800145
Mirko Bonadeie0bc8d22022-02-08 07:41:25 +0000146 virtual sigslot::signal1<SctpDataChannel*>&
147 SignalSctpDataChannelCreated() = 0;
148
Tomas Gunnarsson2e94de52020-06-16 16:54:10 +0200149 // Call on the network thread to fetch stats for all the data channels.
150 // TODO(tommi): Make pure virtual after downstream updates.
Taylor Brandstetter3a034e12020-07-09 15:32:34 -0700151 virtual std::vector<DataChannelStats> GetDataChannelStats() const {
Tomas Gunnarsson2e94de52020-06-16 16:54:10 +0200152 return {};
153 }
Steve Anton2d8609c2018-01-23 16:38:46 -0800154
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200155 virtual absl::optional<std::string> sctp_transport_name() const = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -0800156
Qingsi Wang72a43a12018-02-20 16:03:18 -0800157 virtual cricket::CandidateStatsList GetPooledCandidateStats() const = 0;
158
Steve Anton5dfde182018-02-06 10:34:40 -0800159 // Returns a map from transport name to transport stats for all given
160 // transport names.
Tomas Gunnarssonbfd9ba82021-04-18 11:55:57 +0200161 // Must be called on the network thread.
Steve Anton5dfde182018-02-06 10:34:40 -0800162 virtual std::map<std::string, cricket::TransportStats>
163 GetTransportStatsByNames(const std::set<std::string>& transport_names) = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -0800164
165 virtual Call::Stats GetCallStats() = 0;
166
Fredrik Hernqvistefbe7532023-01-13 16:42:36 +0100167 virtual absl::optional<AudioDeviceModule::Stats> GetAudioDeviceStats() = 0;
168
Steve Anton2d8609c2018-01-23 16:38:46 -0800169 virtual bool GetLocalCertificate(
170 const std::string& transport_name,
171 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) = 0;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800172 virtual std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Steve Anton2d8609c2018-01-23 16:38:46 -0800173 const std::string& transport_name) = 0;
174
175 // Returns true if there was an ICE restart initiated by the remote offer.
176 virtual bool IceRestartPending(const std::string& content_name) const = 0;
177
Steve Anton2d8609c2018-01-23 16:38:46 -0800178 // Get SSL role for an arbitrary m= section (handles bundling correctly).
179 virtual bool GetSslRole(const std::string& content_name,
180 rtc::SSLRole* role) = 0;
Harald Alvestrand5b84f382022-02-08 10:49:09 +0000181 // Functions needed by DataChannelController
182 virtual void NoteDataAddedEvent() {}
183 // Handler for the "channel closed" signal
184 virtual void OnSctpDataChannelClosed(DataChannelInterface* channel) {}
Steve Anton2d8609c2018-01-23 16:38:46 -0800185};
186
187} // namespace webrtc
188
Steve Anton10542f22019-01-11 09:11:00 -0800189#endif // PC_PEER_CONNECTION_INTERNAL_H_