blob: f3c470726be999a7ad74044268b337e17ec27209 [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>
Florent Castelli8037fc62024-08-29 13:00:4016#include <optional>
Steve Anton5dfde182018-02-06 18:34:4017#include <set>
Steve Anton2d8609c2018-01-24 00:38:4618#include <string>
19#include <vector>
20
Florent Castellif4673f92024-04-19 19:46:0321#include "api/audio/audio_device.h"
Steve Anton10542f22019-01-11 17:11:0022#include "api/peer_connection_interface.h"
Niels Möller8366e172018-02-14 11:20:1323#include "call/call.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
Florent Castelli8037fc62024-08-29 13:00:4050 virtual std::optional<std::string> sctp_mid() const = 0;
Harald Alvestrand5b661302022-01-28 13:08:3451
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;
Florent Castelli8037fc62024-08-29 13:00:4079 virtual std::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
Harald Alvestrand5b661302022-01-28 13:08:3498 // Internal implementation for AddTransceiver family of methods. If
99 // `fire_callback` is set, fires OnRenegotiationNeeded callback if successful.
100 virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>
101 AddTransceiver(cricket::MediaType media_type,
102 rtc::scoped_refptr<MediaStreamTrackInterface> track,
103 const RtpTransceiverInit& init,
104 bool fire_callback = true) = 0;
105 // Asynchronously calls SctpTransport::Start() on the network thread for
106 // `sctp_mid()` if set. Called as part of setting the local description.
107 virtual void StartSctpTransport(int local_port,
108 int remote_port,
109 int max_message_size) = 0;
110
111 // Asynchronously adds a remote candidate on the network thread.
112 virtual void AddRemoteCandidate(const std::string& mid,
113 const cricket::Candidate& candidate) = 0;
114
115 virtual Call* call_ptr() = 0;
116 // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by
117 // this session.
118 virtual bool SrtpRequired() const = 0;
Tommi840cf782023-10-21 14:47:56119 // Initializes the data channel transport for the peerconnection instance.
120 // This will have the effect that `sctp_mid()` and `sctp_transport_name()`
121 // will return a set value (even though it might be an empty string) and the
122 // dc transport will be initialized on the network thread.
123 virtual bool CreateDataChannelTransport(absl::string_view mid) = 0;
124 // Tears down the data channel transport state and clears the `sctp_mid()` and
125 // `sctp_transport_name()` properties.
126 virtual void DestroyDataChannelTransport(RTCError error) = 0;
Jonas Oreland6c7f9842022-04-19 15:24:10127 virtual const FieldTrialsView& trials() const = 0;
Philipp Hancke7baa63f2022-09-01 13:39:50128
129 virtual void ClearStatsCache() = 0;
Harald Alvestrand53086522024-08-25 16:43:08130 // Keeps track of assigned payload types and comes up with reasonable
131 // suggestions when new PTs need to be assigned.
132 virtual PayloadTypePicker& payload_type_picker() = 0;
Harald Alvestrand5b661302022-01-28 13:08:34133};
134
135// Functions defined in this class are called by other objects,
136// but not by SdpOfferAnswerHandler.
137class PeerConnectionInternal : public PeerConnectionInterface,
Tommid2afbaf2023-03-02 09:51:16138 public PeerConnectionSdpMethods {
Harald Alvestrand5b661302022-01-28 13:08:34139 public:
Harald Alvestrand66c40362022-01-28 17:41:30140 virtual rtc::Thread* network_thread() const = 0;
141 virtual rtc::Thread* worker_thread() const = 0;
142
Steve Anton2d8609c2018-01-24 00:38:46143 // Returns true if we were the initial offerer.
144 virtual bool initial_offerer() const = 0;
145
Steve Anton2d8609c2018-01-24 00:38:46146 virtual std::vector<
147 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
Steve Antonb8867112018-02-13 18:07:54148 GetTransceiversInternal() const = 0;
Steve Anton2d8609c2018-01-24 00:38:46149
Tomas Gunnarsson2e94de52020-06-16 14:54:10150 // 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 22:32:34152 virtual std::vector<DataChannelStats> GetDataChannelStats() const {
Tomas Gunnarsson2e94de52020-06-16 14:54:10153 return {};
154 }
Steve Anton2d8609c2018-01-24 00:38:46155
Florent Castelli8037fc62024-08-29 13:00:40156 virtual std::optional<std::string> sctp_transport_name() const = 0;
Steve Anton2d8609c2018-01-24 00:38:46157
Qingsi Wang72a43a12018-02-21 00:03:18158 virtual cricket::CandidateStatsList GetPooledCandidateStats() const = 0;
159
Steve Anton5dfde182018-02-06 18:34:40160 // Returns a map from transport name to transport stats for all given
161 // transport names.
Tomas Gunnarssonbfd9ba82021-04-18 09:55:57162 // Must be called on the network thread.
Steve Anton5dfde182018-02-06 18:34:40163 virtual std::map<std::string, cricket::TransportStats>
164 GetTransportStatsByNames(const std::set<std::string>& transport_names) = 0;
Steve Anton2d8609c2018-01-24 00:38:46165
166 virtual Call::Stats GetCallStats() = 0;
167
Florent Castelli8037fc62024-08-29 13:00:40168 virtual std::optional<AudioDeviceModule::Stats> GetAudioDeviceStats() = 0;
Fredrik Hernqvistefbe7532023-01-13 15:42:36169
Steve Anton2d8609c2018-01-24 00:38:46170 virtual bool GetLocalCertificate(
171 const std::string& transport_name,
172 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) = 0;
Taylor Brandstetterc3928662018-02-23 21:04:51173 virtual std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Steve Anton2d8609c2018-01-24 00:38:46174 const std::string& transport_name) = 0;
175
176 // Returns true if there was an ICE restart initiated by the remote offer.
177 virtual bool IceRestartPending(const std::string& content_name) const = 0;
178
Steve Anton2d8609c2018-01-24 00:38:46179 // Get SSL role for an arbitrary m= section (handles bundling correctly).
180 virtual bool GetSslRole(const std::string& content_name,
181 rtc::SSLRole* role) = 0;
Harald Alvestrand5b84f382022-02-08 10:49:09182 // Functions needed by DataChannelController
183 virtual void NoteDataAddedEvent() {}
Tommid2afbaf2023-03-02 09:51:16184 // Handler for sctp data channel state changes.
Tommi56548982023-03-27 16:07:34185 // The `channel_id` is the same unique identifier as used in
186 // `DataChannelStats::internal_id and
187 // `RTCDataChannelStats::data_channel_identifier`.
Tommid2afbaf2023-03-02 09:51:16188 virtual void OnSctpDataChannelStateChanged(
Tommi56548982023-03-27 16:07:34189 int channel_id,
Tommid2afbaf2023-03-02 09:51:16190 DataChannelInterface::DataState state) {}
Steve Anton2d8609c2018-01-24 00:38:46191};
192
193} // namespace webrtc
194
Steve Anton10542f22019-01-11 17:11:00195#endif // PC_PEER_CONNECTION_INTERNAL_H_