xref: /aosp_15_r20/external/webrtc/api/test/pclf/peer_configurer.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker #ifndef API_TEST_PCLF_PEER_CONFIGURER_H_
11*d9f75844SAndroid Build Coastguard Worker #define API_TEST_PCLF_PEER_CONFIGURER_H_
12*d9f75844SAndroid Build Coastguard Worker 
13*d9f75844SAndroid Build Coastguard Worker #include <memory>
14*d9f75844SAndroid Build Coastguard Worker #include <string>
15*d9f75844SAndroid Build Coastguard Worker #include <utility>
16*d9f75844SAndroid Build Coastguard Worker #include <vector>
17*d9f75844SAndroid Build Coastguard Worker 
18*d9f75844SAndroid Build Coastguard Worker #include "absl/strings/string_view.h"
19*d9f75844SAndroid Build Coastguard Worker #include "api/async_resolver_factory.h"
20*d9f75844SAndroid Build Coastguard Worker #include "api/audio/audio_mixer.h"
21*d9f75844SAndroid Build Coastguard Worker #include "api/call/call_factory_interface.h"
22*d9f75844SAndroid Build Coastguard Worker #include "api/fec_controller.h"
23*d9f75844SAndroid Build Coastguard Worker #include "api/rtc_event_log/rtc_event_log_factory_interface.h"
24*d9f75844SAndroid Build Coastguard Worker #include "api/task_queue/task_queue_factory.h"
25*d9f75844SAndroid Build Coastguard Worker #include "api/test/create_peer_connection_quality_test_frame_generator.h"
26*d9f75844SAndroid Build Coastguard Worker #include "api/test/pclf/media_configuration.h"
27*d9f75844SAndroid Build Coastguard Worker #include "api/test/pclf/media_quality_test_params.h"
28*d9f75844SAndroid Build Coastguard Worker #include "api/test/peer_network_dependencies.h"
29*d9f75844SAndroid Build Coastguard Worker #include "api/transport/network_control.h"
30*d9f75844SAndroid Build Coastguard Worker #include "api/video_codecs/video_decoder_factory.h"
31*d9f75844SAndroid Build Coastguard Worker #include "api/video_codecs/video_encoder_factory.h"
32*d9f75844SAndroid Build Coastguard Worker #include "modules/audio_processing/include/audio_processing.h"
33*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/network.h"
34*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/rtc_certificate_generator.h"
35*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/ssl_certificate.h"
36*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/thread.h"
37*d9f75844SAndroid Build Coastguard Worker 
38*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
39*d9f75844SAndroid Build Coastguard Worker namespace webrtc_pc_e2e {
40*d9f75844SAndroid Build Coastguard Worker 
41*d9f75844SAndroid Build Coastguard Worker // This class is used to fully configure one peer inside a call.
42*d9f75844SAndroid Build Coastguard Worker class PeerConfigurer {
43*d9f75844SAndroid Build Coastguard Worker  public:
44*d9f75844SAndroid Build Coastguard Worker   using VideoSource =
45*d9f75844SAndroid Build Coastguard Worker       absl::variant<std::unique_ptr<test::FrameGeneratorInterface>,
46*d9f75844SAndroid Build Coastguard Worker                     CapturingDeviceIndex>;
47*d9f75844SAndroid Build Coastguard Worker 
48*d9f75844SAndroid Build Coastguard Worker   explicit PeerConfigurer(const PeerNetworkDependencies& network_dependencies);
49*d9f75844SAndroid Build Coastguard Worker 
50*d9f75844SAndroid Build Coastguard Worker   // Sets peer name that will be used to report metrics related to this peer.
51*d9f75844SAndroid Build Coastguard Worker   // If not set, some default name will be assigned. All names have to be
52*d9f75844SAndroid Build Coastguard Worker   // unique.
53*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetName(absl::string_view name);
54*d9f75844SAndroid Build Coastguard Worker 
55*d9f75844SAndroid Build Coastguard Worker   // The parameters of the following 9 methods will be passed to the
56*d9f75844SAndroid Build Coastguard Worker   // PeerConnectionFactoryInterface implementation that will be created for
57*d9f75844SAndroid Build Coastguard Worker   // this peer.
58*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetTaskQueueFactory(
59*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<TaskQueueFactory> task_queue_factory);
60*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetCallFactory(
61*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<CallFactoryInterface> call_factory);
62*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetEventLogFactory(
63*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory);
64*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetFecControllerFactory(
65*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory);
66*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetNetworkControllerFactory(
67*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<NetworkControllerFactoryInterface>
68*d9f75844SAndroid Build Coastguard Worker           network_controller_factory);
69*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetVideoEncoderFactory(
70*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<VideoEncoderFactory> video_encoder_factory);
71*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetVideoDecoderFactory(
72*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<VideoDecoderFactory> video_decoder_factory);
73*d9f75844SAndroid Build Coastguard Worker   // Set a custom NetEqFactory to be used in the call.
74*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetNetEqFactory(std::unique_ptr<NetEqFactory> neteq_factory);
75*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetAudioProcessing(
76*d9f75844SAndroid Build Coastguard Worker       rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing);
77*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetAudioMixer(
78*d9f75844SAndroid Build Coastguard Worker       rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer);
79*d9f75844SAndroid Build Coastguard Worker 
80*d9f75844SAndroid Build Coastguard Worker   // Forces the Peerconnection to use the network thread as the worker thread.
81*d9f75844SAndroid Build Coastguard Worker   // Ie, worker thread and the network thread is the same thread.
82*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetUseNetworkThreadAsWorkerThread();
83*d9f75844SAndroid Build Coastguard Worker 
84*d9f75844SAndroid Build Coastguard Worker   // The parameters of the following 4 methods will be passed to the
85*d9f75844SAndroid Build Coastguard Worker   // PeerConnectionInterface implementation that will be created for this
86*d9f75844SAndroid Build Coastguard Worker   // peer.
87*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetAsyncResolverFactory(
88*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<webrtc::AsyncResolverFactory> async_resolver_factory);
89*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetRTCCertificateGenerator(
90*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator);
91*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetSSLCertificateVerifier(
92*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier);
93*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetIceTransportFactory(
94*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<IceTransportFactory> factory);
95*d9f75844SAndroid Build Coastguard Worker   // Flags to set on `cricket::PortAllocator`. These flags will be added
96*d9f75844SAndroid Build Coastguard Worker   // to the default ones that are presented on the port allocator.
97*d9f75844SAndroid Build Coastguard Worker   // For possible values check p2p/base/port_allocator.h.
98*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetPortAllocatorExtraFlags(uint32_t extra_flags);
99*d9f75844SAndroid Build Coastguard Worker 
100*d9f75844SAndroid Build Coastguard Worker   // Add new video stream to the call that will be sent from this peer.
101*d9f75844SAndroid Build Coastguard Worker   // Default implementation of video frames generator will be used.
102*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* AddVideoConfig(VideoConfig config);
103*d9f75844SAndroid Build Coastguard Worker   // Add new video stream to the call that will be sent from this peer with
104*d9f75844SAndroid Build Coastguard Worker   // provided own implementation of video frames generator.
105*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* AddVideoConfig(
106*d9f75844SAndroid Build Coastguard Worker       VideoConfig config,
107*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<test::FrameGeneratorInterface> generator);
108*d9f75844SAndroid Build Coastguard Worker   // Add new video stream to the call that will be sent from this peer.
109*d9f75844SAndroid Build Coastguard Worker   // Capturing device with specified index will be used to get input video.
110*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* AddVideoConfig(VideoConfig config,
111*d9f75844SAndroid Build Coastguard Worker                                  CapturingDeviceIndex capturing_device_index);
112*d9f75844SAndroid Build Coastguard Worker   // Sets video subscription for the peer. By default subscription will
113*d9f75844SAndroid Build Coastguard Worker   // include all streams with `VideoSubscription::kSameAsSendStream`
114*d9f75844SAndroid Build Coastguard Worker   // resolution. To this behavior use this method.
115*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetVideoSubscription(VideoSubscription subscription);
116*d9f75844SAndroid Build Coastguard Worker   // Set the list of video codecs used by the peer during the test. These
117*d9f75844SAndroid Build Coastguard Worker   // codecs will be negotiated in SDP during offer/answer exchange. The order
118*d9f75844SAndroid Build Coastguard Worker   // of these codecs during negotiation will be the same as in `video_codecs`.
119*d9f75844SAndroid Build Coastguard Worker   // Codecs have to be available in codecs list provided by peer connection to
120*d9f75844SAndroid Build Coastguard Worker   // be negotiated. If some of specified codecs won't be found, the test will
121*d9f75844SAndroid Build Coastguard Worker   // crash.
122*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetVideoCodecs(std::vector<VideoCodecConfig> video_codecs);
123*d9f75844SAndroid Build Coastguard Worker   // Set the audio stream for the call from this peer. If this method won't
124*d9f75844SAndroid Build Coastguard Worker   // be invoked, this peer will send no audio.
125*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetAudioConfig(AudioConfig config);
126*d9f75844SAndroid Build Coastguard Worker 
127*d9f75844SAndroid Build Coastguard Worker   // Set if ULP FEC should be used or not. False by default.
128*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetUseUlpFEC(bool value);
129*d9f75844SAndroid Build Coastguard Worker   // Set if Flex FEC should be used or not. False by default.
130*d9f75844SAndroid Build Coastguard Worker   // Client also must enable `enable_flex_fec_support` in the `RunParams` to
131*d9f75844SAndroid Build Coastguard Worker   // be able to use this feature.
132*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetUseFlexFEC(bool value);
133*d9f75844SAndroid Build Coastguard Worker   // Specifies how much video encoder target bitrate should be different than
134*d9f75844SAndroid Build Coastguard Worker   // target bitrate, provided by WebRTC stack. Must be greater than 0. Can be
135*d9f75844SAndroid Build Coastguard Worker   // used to emulate overshooting of video encoders. This multiplier will
136*d9f75844SAndroid Build Coastguard Worker   // be applied for all video encoder on both sides for all layers. Bitrate
137*d9f75844SAndroid Build Coastguard Worker   // estimated by WebRTC stack will be multiplied by this multiplier and then
138*d9f75844SAndroid Build Coastguard Worker   // provided into VideoEncoder::SetRates(...). 1.0 by default.
139*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetVideoEncoderBitrateMultiplier(double multiplier);
140*d9f75844SAndroid Build Coastguard Worker 
141*d9f75844SAndroid Build Coastguard Worker   // If is set, an RTCEventLog will be saved in that location and it will be
142*d9f75844SAndroid Build Coastguard Worker   // available for further analysis.
143*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetRtcEventLogPath(std::string path);
144*d9f75844SAndroid Build Coastguard Worker   // If is set, an AEC dump will be saved in that location and it will be
145*d9f75844SAndroid Build Coastguard Worker   // available for further analysis.
146*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetAecDumpPath(std::string path);
147*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetRTCConfiguration(
148*d9f75844SAndroid Build Coastguard Worker       PeerConnectionInterface::RTCConfiguration configuration);
149*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetRTCOfferAnswerOptions(
150*d9f75844SAndroid Build Coastguard Worker       PeerConnectionInterface::RTCOfferAnswerOptions options);
151*d9f75844SAndroid Build Coastguard Worker   // Set bitrate parameters on PeerConnection. This constraints will be
152*d9f75844SAndroid Build Coastguard Worker   // applied to all summed RTP streams for this peer.
153*d9f75844SAndroid Build Coastguard Worker   PeerConfigurer* SetBitrateSettings(BitrateSettings bitrate_settings);
154*d9f75844SAndroid Build Coastguard Worker 
155*d9f75844SAndroid Build Coastguard Worker   // Returns InjectableComponents and transfer ownership to the caller.
156*d9f75844SAndroid Build Coastguard Worker   // Can be called once.
157*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<InjectableComponents> ReleaseComponents();
158*d9f75844SAndroid Build Coastguard Worker 
159*d9f75844SAndroid Build Coastguard Worker   // Returns Params and transfer ownership to the caller.
160*d9f75844SAndroid Build Coastguard Worker   // Can be called once.
161*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<Params> ReleaseParams();
162*d9f75844SAndroid Build Coastguard Worker 
163*d9f75844SAndroid Build Coastguard Worker   // Returns ConfigurableParams and transfer ownership to the caller.
164*d9f75844SAndroid Build Coastguard Worker   // Can be called once.
165*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<ConfigurableParams> ReleaseConfigurableParams();
166*d9f75844SAndroid Build Coastguard Worker 
167*d9f75844SAndroid Build Coastguard Worker   // Returns video sources and transfer frame generators ownership to the
168*d9f75844SAndroid Build Coastguard Worker   // caller. Can be called once.
169*d9f75844SAndroid Build Coastguard Worker   std::vector<VideoSource> ReleaseVideoSources();
170*d9f75844SAndroid Build Coastguard Worker 
components()171*d9f75844SAndroid Build Coastguard Worker   InjectableComponents* components() { return components_.get(); }
params()172*d9f75844SAndroid Build Coastguard Worker   Params* params() { return params_.get(); }
configurable_params()173*d9f75844SAndroid Build Coastguard Worker   ConfigurableParams* configurable_params() {
174*d9f75844SAndroid Build Coastguard Worker     return configurable_params_.get();
175*d9f75844SAndroid Build Coastguard Worker   }
params()176*d9f75844SAndroid Build Coastguard Worker   const Params& params() const { return *params_; }
configurable_params()177*d9f75844SAndroid Build Coastguard Worker   const ConfigurableParams& configurable_params() const {
178*d9f75844SAndroid Build Coastguard Worker     return *configurable_params_;
179*d9f75844SAndroid Build Coastguard Worker   }
video_sources()180*d9f75844SAndroid Build Coastguard Worker   std::vector<VideoSource>* video_sources() { return &video_sources_; }
181*d9f75844SAndroid Build Coastguard Worker 
182*d9f75844SAndroid Build Coastguard Worker  private:
183*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<InjectableComponents> components_;
184*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<Params> params_;
185*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<ConfigurableParams> configurable_params_;
186*d9f75844SAndroid Build Coastguard Worker   std::vector<VideoSource> video_sources_;
187*d9f75844SAndroid Build Coastguard Worker };
188*d9f75844SAndroid Build Coastguard Worker 
189*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc_pc_e2e
190*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc
191*d9f75844SAndroid Build Coastguard Worker 
192*d9f75844SAndroid Build Coastguard Worker #endif  // API_TEST_PCLF_PEER_CONFIGURER_H_
193