Thanks to visit codestin.com
Credit goes to webrtc.googlesource.com

blob: 87b00dec9138b82375a95b72ae7d7c0d177eaaee [file] [log] [blame]
Harald Alvestrand98462622019-01-30 13:57:031/*
2 * Copyright 2019 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
11#ifndef API_ICE_TRANSPORT_INTERFACE_H_
12#define API_ICE_TRANSPORT_INTERFACE_H_
13
Qingsi Wang25ec8882019-11-15 20:33:0514#include <string>
15
Harald Alvestrand0ccfbd22021-04-08 07:25:0416#include "api/async_dns_resolver.h"
Danil Chapovalov63f79fe2025-08-22 14:07:3617#include "api/environment/environment.h"
Giovanni Ortuño Urquidie2cfc362025-06-13 21:23:3618#include "api/local_network_access_permission.h"
Harald Alvestrande8a2b3c2023-10-31 13:30:3019#include "api/ref_count.h"
Qingsi Wang25ec8882019-11-15 20:33:0520#include "api/rtc_event_log/rtc_event_log.h"
Harald Alvestrand98462622019-01-30 13:57:0321#include "api/scoped_refptr.h"
Harald Alvestrand98462622019-01-30 13:57:0322
Evan Shrubsole080cdac2025-03-20 09:34:4823namespace webrtc {
24
25class ActiveIceControllerFactoryInterface;
26class FieldTrialsView;
27class IceControllerFactoryInterface;
Harald Alvestrand98462622019-01-30 13:57:0328class IceTransportInternal;
Qingsi Wang25ec8882019-11-15 20:33:0529class PortAllocator;
Harald Alvestrand98462622019-01-30 13:57:0330
31// An ICE transport, as represented to the outside world.
32// This object is refcounted, and is therefore alive until the
33// last holder has released it.
Evan Shrubsole080cdac2025-03-20 09:34:4834class IceTransportInterface : public RefCountInterface {
Harald Alvestrand98462622019-01-30 13:57:0335 public:
36 // Accessor for the internal representation of an ICE transport.
37 // The returned object can only be safely used on the signalling thread.
38 // TODO(crbug.com/907849): Add API calls for the functions that have to
39 // be exposed to clients, and stop allowing access to the
Harald Alvestrand3d120662025-06-11 07:34:3940 // IceTransportInternal API.
Evan Shrubsole080cdac2025-03-20 09:34:4841 virtual IceTransportInternal* internal() = 0;
Harald Alvestrand98462622019-01-30 13:57:0342};
43
Danil Chapovalov63f79fe2025-08-22 14:07:3644class IceTransportInit final {
Qingsi Wang25ec8882019-11-15 20:33:0545 public:
Danil Chapovalov63f79fe2025-08-22 14:07:3646 explicit IceTransportInit(const Environment& env) : env_(env) {}
Qingsi Wang25ec8882019-11-15 20:33:0547 IceTransportInit(const IceTransportInit&) = delete;
48 IceTransportInit(IceTransportInit&&) = default;
49 IceTransportInit& operator=(const IceTransportInit&) = delete;
50 IceTransportInit& operator=(IceTransportInit&&) = default;
51
Evan Shrubsole080cdac2025-03-20 09:34:4852 PortAllocator* port_allocator() { return port_allocator_; }
53 void set_port_allocator(PortAllocator* port_allocator) {
Qingsi Wang25ec8882019-11-15 20:33:0554 port_allocator_ = port_allocator;
55 }
56
Harald Alvestrand0ccfbd22021-04-08 07:25:0457 AsyncDnsResolverFactoryInterface* async_dns_resolver_factory() {
58 return async_dns_resolver_factory_;
59 }
60 void set_async_dns_resolver_factory(
61 AsyncDnsResolverFactoryInterface* async_dns_resolver_factory) {
Harald Alvestrand0ccfbd22021-04-08 07:25:0462 async_dns_resolver_factory_ = async_dns_resolver_factory;
63 }
Qingsi Wang25ec8882019-11-15 20:33:0564
Giovanni Ortuño Urquidie2cfc362025-06-13 21:23:3665 LocalNetworkAccessPermissionFactoryInterface* lna_permission_factory() {
66 return lna_permission_factory_;
67 }
68
69 void set_lna_permission_factory(
70 LocalNetworkAccessPermissionFactoryInterface* lna_permission_factory) {
71 lna_permission_factory_ = lna_permission_factory;
72 }
73
Danil Chapovalov63f79fe2025-08-22 14:07:3674 RtcEventLog* event_log() { return &env_.event_log(); }
Qingsi Wang25ec8882019-11-15 20:33:0575
Jonas Oreland7ddc7d52022-03-16 11:21:5276 void set_ice_controller_factory(
Evan Shrubsole080cdac2025-03-20 09:34:4877 IceControllerFactoryInterface* ice_controller_factory) {
Jonas Oreland7ddc7d52022-03-16 11:21:5278 ice_controller_factory_ = ice_controller_factory;
79 }
Evan Shrubsole080cdac2025-03-20 09:34:4880 IceControllerFactoryInterface* ice_controller_factory() {
Jonas Oreland7ddc7d52022-03-16 11:21:5281 return ice_controller_factory_;
82 }
83
Sameer Vijaykar6fa8a752022-09-14 09:48:5484 // An active ICE controller actively manages the connection used by an ICE
85 // transport, in contrast with a legacy ICE controller that only picks the
86 // best connection to use or ping, and lets the transport decide when and
87 // whether to switch.
Sameer Vijaykar1adcde92022-09-16 13:04:3488 //
Emil Lundmark4e86aa02023-03-01 12:01:2189 // Which ICE controller is used is determined as follows:
Sameer Vijaykar1adcde92022-09-16 13:04:3490 //
Emil Lundmark4e86aa02023-03-01 12:01:2191 // 1. If an active ICE controller factory is supplied, it is used and
Sameer Vijaykar52dd1a52022-09-19 11:11:1192 // the legacy ICE controller factory is not used.
Emil Lundmark4e86aa02023-03-01 12:01:2193 // 2. If not, a default active ICE controller is used, wrapping over the
Sameer Vijaykar52dd1a52022-09-19 11:11:1194 // supplied or the default legacy ICE controller.
Sameer Vijaykar6fa8a752022-09-14 09:48:5495 void set_active_ice_controller_factory(
Evan Shrubsole080cdac2025-03-20 09:34:4896 ActiveIceControllerFactoryInterface* active_ice_controller_factory) {
Sameer Vijaykar6fa8a752022-09-14 09:48:5497 active_ice_controller_factory_ = active_ice_controller_factory;
98 }
Evan Shrubsole080cdac2025-03-20 09:34:4899 ActiveIceControllerFactoryInterface* active_ice_controller_factory() {
Sameer Vijaykar6fa8a752022-09-14 09:48:54100 return active_ice_controller_factory_;
101 }
102
Danil Chapovalov63f79fe2025-08-22 14:07:36103 const FieldTrialsView* field_trials() { return &env_.field_trials(); }
104
105 const Environment& env() { return env_; }
Jonas Oreland340cb5e2022-03-17 08:14:16106
Qingsi Wang25ec8882019-11-15 20:33:05107 private:
Danil Chapovalov63f79fe2025-08-22 14:07:36108 Environment env_;
Evan Shrubsole080cdac2025-03-20 09:34:48109 PortAllocator* port_allocator_ = nullptr;
Harald Alvestrand0ccfbd22021-04-08 07:25:04110 AsyncDnsResolverFactoryInterface* async_dns_resolver_factory_ = nullptr;
Giovanni Ortuño Urquidie2cfc362025-06-13 21:23:36111 LocalNetworkAccessPermissionFactoryInterface* lna_permission_factory_ =
112 nullptr;
Evan Shrubsole080cdac2025-03-20 09:34:48113 IceControllerFactoryInterface* ice_controller_factory_ = nullptr;
114 ActiveIceControllerFactoryInterface* active_ice_controller_factory_ = nullptr;
Harald Alvestrand0ccfbd22021-04-08 07:25:04115 // TODO(https://crbug.com/webrtc/12657): Redesign to have const members.
Qingsi Wang25ec8882019-11-15 20:33:05116};
117
118// TODO(qingsi): The factory interface is defined in this file instead of its
119// namesake file ice_transport_factory.h to avoid the extra dependency on p2p/
120// introduced there by the p2p/-dependent factory methods. Move the factory
121// methods to a different file or rename it.
122class IceTransportFactory {
123 public:
124 virtual ~IceTransportFactory() = default;
125 // As a refcounted object, the returned ICE transport may outlive the host
126 // construct into which its reference is given, e.g. a peer connection. As a
127 // result, the returned ICE transport should not hold references to any object
128 // that the transport does not own and that has a lifetime bound to the host
129 // construct. Also, assumptions on the thread safety of the returned transport
130 // should be clarified by implementations. For example, a peer connection
131 // requires the returned transport to be constructed and destroyed on the
132 // network thread and an ICE transport factory that intends to work with a
133 // peer connection should offer transports compatible with these assumptions.
Evan Shrubsoleee5ab342025-04-15 14:49:46134 virtual scoped_refptr<IceTransportInterface> CreateIceTransport(
Qingsi Wang25ec8882019-11-15 20:33:05135 const std::string& transport_name,
136 int component,
137 IceTransportInit init) = 0;
138};
139
Harald Alvestrand98462622019-01-30 13:57:03140} // namespace webrtc
141#endif // API_ICE_TRANSPORT_INTERFACE_H_