blob: 38a1fd10026469a2ec63c82dda56237e17223c5d [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/jsep_transport_controller.h"
23#include "pc/peer_connection_message_handler.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "pc/rtp_transceiver.h"
Harald Alvestrand5b661302022-01-28 13:08:34 +000025#include "pc/rtp_transmission_manager.h"
Taylor Brandstetter3a034e12020-07-09 15:32:34 -070026#include "pc/sctp_data_channel.h"
Steve Anton2d8609c2018-01-23 16:38:46 -080027
28namespace webrtc {
29
Harald Alvestrand67a68d52022-02-07 05:07:03 +000030class DataChannelController;
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,
Harald Alvestrand5b84f382022-02-08 10:49:09 +0000130 public PeerConnectionSdpMethods,
131 public sigslot::has_slots<> {
Harald Alvestrand5b661302022-01-28 13:08:34 +0000132 public:
Harald Alvestrand66c40362022-01-28 17:41:30 +0000133 virtual rtc::Thread* network_thread() const = 0;
134 virtual rtc::Thread* worker_thread() const = 0;
135
Steve Anton2d8609c2018-01-23 16:38:46 -0800136 // Returns true if we were the initial offerer.
137 virtual bool initial_offerer() const = 0;
138
Steve Anton2d8609c2018-01-23 16:38:46 -0800139 virtual std::vector<
140 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
Steve Antonb8867112018-02-13 10:07:54 -0800141 GetTransceiversInternal() const = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -0800142
Mirko Bonadeie0bc8d22022-02-08 07:41:25 +0000143 virtual sigslot::signal1<SctpDataChannel*>&
144 SignalSctpDataChannelCreated() = 0;
145
Tomas Gunnarsson2e94de52020-06-16 16:54:10 +0200146 // Call on the network thread to fetch stats for all the data channels.
147 // TODO(tommi): Make pure virtual after downstream updates.
Taylor Brandstetter3a034e12020-07-09 15:32:34 -0700148 virtual std::vector<DataChannelStats> GetDataChannelStats() const {
Tomas Gunnarsson2e94de52020-06-16 16:54:10 +0200149 return {};
150 }
Steve Anton2d8609c2018-01-23 16:38:46 -0800151
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200152 virtual absl::optional<std::string> sctp_transport_name() const = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -0800153
Qingsi Wang72a43a12018-02-20 16:03:18 -0800154 virtual cricket::CandidateStatsList GetPooledCandidateStats() const = 0;
155
Steve Anton5dfde182018-02-06 10:34:40 -0800156 // Returns a map from transport name to transport stats for all given
157 // transport names.
Tomas Gunnarssonbfd9ba82021-04-18 11:55:57 +0200158 // Must be called on the network thread.
Steve Anton5dfde182018-02-06 10:34:40 -0800159 virtual std::map<std::string, cricket::TransportStats>
160 GetTransportStatsByNames(const std::set<std::string>& transport_names) = 0;
Steve Anton2d8609c2018-01-23 16:38:46 -0800161
162 virtual Call::Stats GetCallStats() = 0;
163
164 virtual bool GetLocalCertificate(
165 const std::string& transport_name,
166 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) = 0;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800167 virtual std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Steve Anton2d8609c2018-01-23 16:38:46 -0800168 const std::string& transport_name) = 0;
169
170 // Returns true if there was an ICE restart initiated by the remote offer.
171 virtual bool IceRestartPending(const std::string& content_name) const = 0;
172
Steve Anton2d8609c2018-01-23 16:38:46 -0800173 // Get SSL role for an arbitrary m= section (handles bundling correctly).
174 virtual bool GetSslRole(const std::string& content_name,
175 rtc::SSLRole* role) = 0;
Harald Alvestrand5b84f382022-02-08 10:49:09 +0000176 // Functions needed by DataChannelController
177 virtual void NoteDataAddedEvent() {}
178 // Handler for the "channel closed" signal
179 virtual void OnSctpDataChannelClosed(DataChannelInterface* channel) {}
Steve Anton2d8609c2018-01-23 16:38:46 -0800180};
181
182} // namespace webrtc
183
Steve Anton10542f22019-01-11 09:11:00 -0800184#endif // PC_PEER_CONNECTION_INTERNAL_H_