xref: /aosp_15_r20/external/webrtc/api/test/pclf/peer_configurer.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2022 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 #include "api/test/pclf/peer_configurer.h"
12 
13 #include <set>
14 
15 #include "absl/strings/string_view.h"
16 #include "api/test/pclf/media_configuration.h"
17 #include "api/test/pclf/media_quality_test_params.h"
18 #include "api/test/peer_network_dependencies.h"
19 
20 namespace webrtc {
21 namespace webrtc_pc_e2e {
22 
PeerConfigurer(const PeerNetworkDependencies & network_dependencies)23 PeerConfigurer::PeerConfigurer(
24     const PeerNetworkDependencies& network_dependencies)
25     : components_(std::make_unique<InjectableComponents>(
26           network_dependencies.network_thread,
27           network_dependencies.network_manager,
28           network_dependencies.packet_socket_factory)),
29       params_(std::make_unique<Params>()),
30       configurable_params_(std::make_unique<ConfigurableParams>()) {}
31 
SetName(absl::string_view name)32 PeerConfigurer* PeerConfigurer::SetName(absl::string_view name) {
33   params_->name = std::string(name);
34   return this;
35 }
36 
SetTaskQueueFactory(std::unique_ptr<TaskQueueFactory> task_queue_factory)37 PeerConfigurer* PeerConfigurer::SetTaskQueueFactory(
38     std::unique_ptr<TaskQueueFactory> task_queue_factory) {
39   components_->pcf_dependencies->task_queue_factory =
40       std::move(task_queue_factory);
41   return this;
42 }
SetCallFactory(std::unique_ptr<CallFactoryInterface> call_factory)43 PeerConfigurer* PeerConfigurer::SetCallFactory(
44     std::unique_ptr<CallFactoryInterface> call_factory) {
45   components_->pcf_dependencies->call_factory = std::move(call_factory);
46   return this;
47 }
SetEventLogFactory(std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory)48 PeerConfigurer* PeerConfigurer::SetEventLogFactory(
49     std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) {
50   components_->pcf_dependencies->event_log_factory =
51       std::move(event_log_factory);
52   return this;
53 }
SetFecControllerFactory(std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory)54 PeerConfigurer* PeerConfigurer::SetFecControllerFactory(
55     std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory) {
56   components_->pcf_dependencies->fec_controller_factory =
57       std::move(fec_controller_factory);
58   return this;
59 }
SetNetworkControllerFactory(std::unique_ptr<NetworkControllerFactoryInterface> network_controller_factory)60 PeerConfigurer* PeerConfigurer::SetNetworkControllerFactory(
61     std::unique_ptr<NetworkControllerFactoryInterface>
62         network_controller_factory) {
63   components_->pcf_dependencies->network_controller_factory =
64       std::move(network_controller_factory);
65   return this;
66 }
SetVideoEncoderFactory(std::unique_ptr<VideoEncoderFactory> video_encoder_factory)67 PeerConfigurer* PeerConfigurer::SetVideoEncoderFactory(
68     std::unique_ptr<VideoEncoderFactory> video_encoder_factory) {
69   components_->pcf_dependencies->video_encoder_factory =
70       std::move(video_encoder_factory);
71   return this;
72 }
SetVideoDecoderFactory(std::unique_ptr<VideoDecoderFactory> video_decoder_factory)73 PeerConfigurer* PeerConfigurer::SetVideoDecoderFactory(
74     std::unique_ptr<VideoDecoderFactory> video_decoder_factory) {
75   components_->pcf_dependencies->video_decoder_factory =
76       std::move(video_decoder_factory);
77   return this;
78 }
79 
SetAsyncResolverFactory(std::unique_ptr<webrtc::AsyncResolverFactory> async_resolver_factory)80 PeerConfigurer* PeerConfigurer::SetAsyncResolverFactory(
81     std::unique_ptr<webrtc::AsyncResolverFactory> async_resolver_factory) {
82   components_->pc_dependencies->async_resolver_factory =
83       std::move(async_resolver_factory);
84   return this;
85 }
SetRTCCertificateGenerator(std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator)86 PeerConfigurer* PeerConfigurer::SetRTCCertificateGenerator(
87     std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
88   components_->pc_dependencies->cert_generator = std::move(cert_generator);
89   return this;
90 }
SetSSLCertificateVerifier(std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier)91 PeerConfigurer* PeerConfigurer::SetSSLCertificateVerifier(
92     std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier) {
93   components_->pc_dependencies->tls_cert_verifier =
94       std::move(tls_cert_verifier);
95   return this;
96 }
97 
AddVideoConfig(VideoConfig config)98 PeerConfigurer* PeerConfigurer::AddVideoConfig(VideoConfig config) {
99   video_sources_.push_back(
100       CreateSquareFrameGenerator(config, /*type=*/absl::nullopt));
101   configurable_params_->video_configs.push_back(std::move(config));
102   return this;
103 }
AddVideoConfig(VideoConfig config,std::unique_ptr<test::FrameGeneratorInterface> generator)104 PeerConfigurer* PeerConfigurer::AddVideoConfig(
105     VideoConfig config,
106     std::unique_ptr<test::FrameGeneratorInterface> generator) {
107   configurable_params_->video_configs.push_back(std::move(config));
108   video_sources_.push_back(std::move(generator));
109   return this;
110 }
AddVideoConfig(VideoConfig config,CapturingDeviceIndex index)111 PeerConfigurer* PeerConfigurer::AddVideoConfig(VideoConfig config,
112                                                CapturingDeviceIndex index) {
113   configurable_params_->video_configs.push_back(std::move(config));
114   video_sources_.push_back(index);
115   return this;
116 }
SetVideoSubscription(VideoSubscription subscription)117 PeerConfigurer* PeerConfigurer::SetVideoSubscription(
118     VideoSubscription subscription) {
119   configurable_params_->video_subscription = std::move(subscription);
120   return this;
121 }
SetAudioConfig(AudioConfig config)122 PeerConfigurer* PeerConfigurer::SetAudioConfig(AudioConfig config) {
123   params_->audio_config = std::move(config);
124   return this;
125 }
SetUseUlpFEC(bool value)126 PeerConfigurer* PeerConfigurer::SetUseUlpFEC(bool value) {
127   params_->use_ulp_fec = value;
128   return this;
129 }
SetUseFlexFEC(bool value)130 PeerConfigurer* PeerConfigurer::SetUseFlexFEC(bool value) {
131   params_->use_flex_fec = value;
132   return this;
133 }
SetVideoEncoderBitrateMultiplier(double multiplier)134 PeerConfigurer* PeerConfigurer::SetVideoEncoderBitrateMultiplier(
135     double multiplier) {
136   params_->video_encoder_bitrate_multiplier = multiplier;
137   return this;
138 }
SetNetEqFactory(std::unique_ptr<NetEqFactory> neteq_factory)139 PeerConfigurer* PeerConfigurer::SetNetEqFactory(
140     std::unique_ptr<NetEqFactory> neteq_factory) {
141   components_->pcf_dependencies->neteq_factory = std::move(neteq_factory);
142   return this;
143 }
SetAudioProcessing(rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing)144 PeerConfigurer* PeerConfigurer::SetAudioProcessing(
145     rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing) {
146   components_->pcf_dependencies->audio_processing = audio_processing;
147   return this;
148 }
SetAudioMixer(rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer)149 PeerConfigurer* PeerConfigurer::SetAudioMixer(
150     rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer) {
151   components_->pcf_dependencies->audio_mixer = audio_mixer;
152   return this;
153 }
154 
SetUseNetworkThreadAsWorkerThread()155 PeerConfigurer* PeerConfigurer::SetUseNetworkThreadAsWorkerThread() {
156   components_->worker_thread = components_->network_thread;
157   return this;
158 }
159 
SetRtcEventLogPath(std::string path)160 PeerConfigurer* PeerConfigurer::SetRtcEventLogPath(std::string path) {
161   params_->rtc_event_log_path = std::move(path);
162   return this;
163 }
SetAecDumpPath(std::string path)164 PeerConfigurer* PeerConfigurer::SetAecDumpPath(std::string path) {
165   params_->aec_dump_path = std::move(path);
166   return this;
167 }
SetRTCConfiguration(PeerConnectionInterface::RTCConfiguration configuration)168 PeerConfigurer* PeerConfigurer::SetRTCConfiguration(
169     PeerConnectionInterface::RTCConfiguration configuration) {
170   params_->rtc_configuration = std::move(configuration);
171   return this;
172 }
SetRTCOfferAnswerOptions(PeerConnectionInterface::RTCOfferAnswerOptions options)173 PeerConfigurer* PeerConfigurer::SetRTCOfferAnswerOptions(
174     PeerConnectionInterface::RTCOfferAnswerOptions options) {
175   params_->rtc_offer_answer_options = std::move(options);
176   return this;
177 }
SetBitrateSettings(BitrateSettings bitrate_settings)178 PeerConfigurer* PeerConfigurer::SetBitrateSettings(
179     BitrateSettings bitrate_settings) {
180   params_->bitrate_settings = bitrate_settings;
181   return this;
182 }
SetVideoCodecs(std::vector<VideoCodecConfig> video_codecs)183 PeerConfigurer* PeerConfigurer::SetVideoCodecs(
184     std::vector<VideoCodecConfig> video_codecs) {
185   params_->video_codecs = std::move(video_codecs);
186   return this;
187 }
188 
SetIceTransportFactory(std::unique_ptr<IceTransportFactory> factory)189 PeerConfigurer* PeerConfigurer::SetIceTransportFactory(
190     std::unique_ptr<IceTransportFactory> factory) {
191   components_->pc_dependencies->ice_transport_factory = std::move(factory);
192   return this;
193 }
194 
SetPortAllocatorExtraFlags(uint32_t extra_flags)195 PeerConfigurer* PeerConfigurer::SetPortAllocatorExtraFlags(
196     uint32_t extra_flags) {
197   params_->port_allocator_extra_flags = extra_flags;
198   return this;
199 }
ReleaseComponents()200 std::unique_ptr<InjectableComponents> PeerConfigurer::ReleaseComponents() {
201   RTC_CHECK(components_);
202   auto components = std::move(components_);
203   components_ = nullptr;
204   return components;
205 }
206 
207 // Returns Params and transfer ownership to the caller.
208 // Can be called once.
ReleaseParams()209 std::unique_ptr<Params> PeerConfigurer::ReleaseParams() {
210   RTC_CHECK(params_);
211   auto params = std::move(params_);
212   params_ = nullptr;
213   return params;
214 }
215 
216 // Returns ConfigurableParams and transfer ownership to the caller.
217 // Can be called once.
218 std::unique_ptr<ConfigurableParams>
ReleaseConfigurableParams()219 PeerConfigurer::ReleaseConfigurableParams() {
220   RTC_CHECK(configurable_params_);
221   auto configurable_params = std::move(configurable_params_);
222   configurable_params_ = nullptr;
223   return configurable_params;
224 }
225 
226 // Returns video sources and transfer frame generators ownership to the
227 // caller. Can be called once.
ReleaseVideoSources()228 std::vector<PeerConfigurer::VideoSource> PeerConfigurer::ReleaseVideoSources() {
229   auto video_sources = std::move(video_sources_);
230   video_sources_.clear();
231   return video_sources;
232 }
233 
234 }  // namespace webrtc_pc_e2e
235 }  // namespace webrtc
236