tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

peer_configurer.cc (10396B)


      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 <cstdint>
     14 #include <memory>
     15 #include <optional>
     16 #include <string>
     17 #include <utility>
     18 #include <vector>
     19 
     20 #include "absl/strings/string_view.h"
     21 #include "api/async_dns_resolver.h"
     22 #include "api/audio/audio_mixer.h"
     23 #include "api/audio/audio_processing.h"
     24 #include "api/audio_codecs/audio_decoder_factory.h"
     25 #include "api/audio_codecs/audio_encoder_factory.h"
     26 #include "api/fec_controller.h"
     27 #include "api/field_trials.h"
     28 #include "api/ice_transport_interface.h"
     29 #include "api/neteq/neteq_factory.h"
     30 #include "api/peer_connection_interface.h"
     31 #include "api/rtc_event_log/rtc_event_log_factory_interface.h"
     32 #include "api/scoped_refptr.h"
     33 #include "api/test/create_peer_connection_quality_test_frame_generator.h"
     34 #include "api/test/frame_generator_interface.h"
     35 #include "api/test/pclf/media_configuration.h"
     36 #include "api/test/pclf/media_quality_test_params.h"
     37 #include "api/test/peer_network_dependencies.h"
     38 #include "api/transport/bitrate_settings.h"
     39 #include "api/transport/network_control.h"
     40 #include "api/video_codecs/video_decoder_factory.h"
     41 #include "api/video_codecs/video_encoder_factory.h"
     42 #include "p2p/base/port_allocator.h"
     43 #include "rtc_base/checks.h"
     44 #include "rtc_base/rtc_certificate_generator.h"
     45 #include "rtc_base/ssl_certificate.h"
     46 #include "test/create_test_field_trials.h"
     47 
     48 namespace webrtc {
     49 namespace webrtc_pc_e2e {
     50 
     51 PeerConfigurer::PeerConfigurer(PeerNetworkDependencies& network)
     52    : components_(std::make_unique<InjectableComponents>(
     53          network.network_thread(),
     54          network.ReleaseNetworkManager(),
     55          network.socket_factory())),
     56      params_(std::make_unique<Params>()),
     57      configurable_params_(std::make_unique<ConfigurableParams>()) {
     58  components_->pcf_dependencies->field_trials = CreateTestFieldTrialsPtr();
     59 }
     60 
     61 PeerConfigurer* PeerConfigurer::SetName(absl::string_view name) {
     62  params_->name = std::string(name);
     63  return this;
     64 }
     65 
     66 PeerConfigurer* PeerConfigurer::SetEventLogFactory(
     67    std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) {
     68  components_->pcf_dependencies->event_log_factory =
     69      std::move(event_log_factory);
     70  return this;
     71 }
     72 PeerConfigurer* PeerConfigurer::SetFecControllerFactory(
     73    std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory) {
     74  components_->pcf_dependencies->fec_controller_factory =
     75      std::move(fec_controller_factory);
     76  return this;
     77 }
     78 PeerConfigurer* PeerConfigurer::SetNetworkControllerFactory(
     79    std::unique_ptr<NetworkControllerFactoryInterface>
     80        network_controller_factory) {
     81  components_->pcf_dependencies->network_controller_factory =
     82      std::move(network_controller_factory);
     83  return this;
     84 }
     85 PeerConfigurer* PeerConfigurer::SetVideoEncoderFactory(
     86    std::unique_ptr<VideoEncoderFactory> video_encoder_factory) {
     87  components_->pcf_dependencies->video_encoder_factory =
     88      std::move(video_encoder_factory);
     89  return this;
     90 }
     91 PeerConfigurer* PeerConfigurer::SetVideoDecoderFactory(
     92    std::unique_ptr<VideoDecoderFactory> video_decoder_factory) {
     93  components_->pcf_dependencies->video_decoder_factory =
     94      std::move(video_decoder_factory);
     95  return this;
     96 }
     97 PeerConfigurer* PeerConfigurer::SetAudioEncoderFactory(
     98    scoped_refptr<AudioEncoderFactory> audio_encoder_factory) {
     99  components_->pcf_dependencies->audio_encoder_factory = audio_encoder_factory;
    100  return this;
    101 }
    102 PeerConfigurer* PeerConfigurer::SetAudioDecoderFactory(
    103    scoped_refptr<AudioDecoderFactory> audio_decoder_factory) {
    104  components_->pcf_dependencies->audio_decoder_factory = audio_decoder_factory;
    105  return this;
    106 }
    107 PeerConfigurer* PeerConfigurer::SetAsyncDnsResolverFactory(
    108    std::unique_ptr<AsyncDnsResolverFactoryInterface>
    109        async_dns_resolver_factory) {
    110  components_->pc_dependencies->async_dns_resolver_factory =
    111      std::move(async_dns_resolver_factory);
    112  return this;
    113 }
    114 PeerConfigurer* PeerConfigurer::SetRTCCertificateGenerator(
    115    std::unique_ptr<RTCCertificateGeneratorInterface> cert_generator) {
    116  components_->pc_dependencies->cert_generator = std::move(cert_generator);
    117  return this;
    118 }
    119 PeerConfigurer* PeerConfigurer::SetSSLCertificateVerifier(
    120    std::unique_ptr<SSLCertificateVerifier> tls_cert_verifier) {
    121  components_->pc_dependencies->tls_cert_verifier =
    122      std::move(tls_cert_verifier);
    123  return this;
    124 }
    125 
    126 PeerConfigurer* PeerConfigurer::AddVideoConfig(VideoConfig config) {
    127  video_sources_.push_back(
    128      CreateSquareFrameGenerator(config, /*type=*/std::nullopt));
    129  configurable_params_->video_configs.push_back(std::move(config));
    130  return this;
    131 }
    132 PeerConfigurer* PeerConfigurer::AddVideoConfig(
    133    VideoConfig config,
    134    std::unique_ptr<test::FrameGeneratorInterface> generator) {
    135  configurable_params_->video_configs.push_back(std::move(config));
    136  video_sources_.push_back(std::move(generator));
    137  return this;
    138 }
    139 PeerConfigurer* PeerConfigurer::AddVideoConfig(VideoConfig config,
    140                                               CapturingDeviceIndex index) {
    141  configurable_params_->video_configs.push_back(std::move(config));
    142  video_sources_.push_back(index);
    143  return this;
    144 }
    145 PeerConfigurer* PeerConfigurer::SetVideoSubscription(
    146    VideoSubscription subscription) {
    147  configurable_params_->video_subscription = std::move(subscription);
    148  return this;
    149 }
    150 PeerConfigurer* PeerConfigurer::SetVideoCodecs(
    151    std::vector<VideoCodecConfig> video_codecs) {
    152  params_->video_codecs = std::move(video_codecs);
    153  return this;
    154 }
    155 PeerConfigurer* PeerConfigurer::SetExtraVideoRtpHeaderExtensions(
    156    std::vector<std::string> extensions) {
    157  params_->extra_video_rtp_header_extensions = std::move(extensions);
    158  return this;
    159 }
    160 PeerConfigurer* PeerConfigurer::SetAudioConfig(AudioConfig config) {
    161  params_->audio_config = std::move(config);
    162  return this;
    163 }
    164 PeerConfigurer* PeerConfigurer::SetExtraAudioRtpHeaderExtensions(
    165    std::vector<std::string> extensions) {
    166  params_->extra_audio_rtp_header_extensions = std::move(extensions);
    167  return this;
    168 }
    169 PeerConfigurer* PeerConfigurer::SetUseUlpFEC(bool value) {
    170  params_->use_ulp_fec = value;
    171  return this;
    172 }
    173 PeerConfigurer* PeerConfigurer::SetUseFlexFEC(bool value) {
    174  params_->use_flex_fec = value;
    175  absl::string_view group = value ? "Enabled" : "Disabled";
    176  FieldTrials& field_trials = GetFieldTrials();
    177  field_trials.Set("WebRTC-FlexFEC-03-Advertised", group);
    178  field_trials.Set("WebRTC-FlexFEC-03", group);
    179  return this;
    180 }
    181 PeerConfigurer* PeerConfigurer::SetVideoEncoderBitrateMultiplier(
    182    double multiplier) {
    183  params_->video_encoder_bitrate_multiplier = multiplier;
    184  return this;
    185 }
    186 PeerConfigurer* PeerConfigurer::SetNetEqFactory(
    187    std::unique_ptr<NetEqFactory> neteq_factory) {
    188  components_->pcf_dependencies->neteq_factory = std::move(neteq_factory);
    189  return this;
    190 }
    191 PeerConfigurer* PeerConfigurer::SetAudioProcessing(
    192    std::unique_ptr<AudioProcessingBuilderInterface> audio_processing) {
    193  components_->pcf_dependencies->audio_processing = std::move(audio_processing);
    194  return this;
    195 }
    196 PeerConfigurer* PeerConfigurer::SetAudioMixer(
    197    scoped_refptr<AudioMixer> audio_mixer) {
    198  components_->pcf_dependencies->audio_mixer = audio_mixer;
    199  return this;
    200 }
    201 
    202 PeerConfigurer* PeerConfigurer::SetUseNetworkThreadAsWorkerThread() {
    203  components_->worker_thread = components_->network_thread;
    204  return this;
    205 }
    206 
    207 PeerConfigurer* PeerConfigurer::SetRtcEventLogPath(absl::string_view path) {
    208  params_->rtc_event_log_path = std::string(path);
    209  return this;
    210 }
    211 PeerConfigurer* PeerConfigurer::SetAecDumpPath(absl::string_view path) {
    212  params_->aec_dump_path = std::string(path);
    213  return this;
    214 }
    215 PeerConfigurer* PeerConfigurer::SetPCFOptions(
    216    PeerConnectionFactoryInterface::Options options) {
    217  params_->peer_connection_factory_options = std::move(options);
    218  return this;
    219 }
    220 PeerConfigurer* PeerConfigurer::SetRTCConfiguration(
    221    PeerConnectionInterface::RTCConfiguration configuration) {
    222  params_->rtc_configuration = std::move(configuration);
    223  return this;
    224 }
    225 PeerConfigurer* PeerConfigurer::SetRTCOfferAnswerOptions(
    226    PeerConnectionInterface::RTCOfferAnswerOptions options) {
    227  params_->rtc_offer_answer_options = std::move(options);
    228  return this;
    229 }
    230 PeerConfigurer* PeerConfigurer::SetBitrateSettings(
    231    BitrateSettings bitrate_settings) {
    232  params_->bitrate_settings = bitrate_settings;
    233  return this;
    234 }
    235 
    236 PeerConfigurer* PeerConfigurer::SetIceTransportFactory(
    237    std::unique_ptr<IceTransportFactory> factory) {
    238  components_->pc_dependencies->ice_transport_factory = std::move(factory);
    239  return this;
    240 }
    241 
    242 PeerConfigurer* PeerConfigurer::SetPortAllocatorExtraFlags(
    243    uint32_t extra_flags) {
    244  params_->port_allocator_flags =
    245      kDefaultPortAllocatorFlags | PORTALLOCATOR_DISABLE_TCP | extra_flags;
    246  return this;
    247 }
    248 
    249 PeerConfigurer* PeerConfigurer::SetPortAllocatorFlags(uint32_t flags) {
    250  params_->port_allocator_flags = flags;
    251  return this;
    252 }
    253 
    254 std::unique_ptr<InjectableComponents> PeerConfigurer::ReleaseComponents() {
    255  RTC_CHECK(components_);
    256  auto components = std::move(components_);
    257  components_ = nullptr;
    258  return components;
    259 }
    260 
    261 // Returns Params and transfer ownership to the caller.
    262 // Can be called once.
    263 std::unique_ptr<Params> PeerConfigurer::ReleaseParams() {
    264  RTC_CHECK(params_);
    265  auto params = std::move(params_);
    266  params_ = nullptr;
    267  return params;
    268 }
    269 
    270 // Returns ConfigurableParams and transfer ownership to the caller.
    271 // Can be called once.
    272 std::unique_ptr<ConfigurableParams>
    273 PeerConfigurer::ReleaseConfigurableParams() {
    274  RTC_CHECK(configurable_params_);
    275  auto configurable_params = std::move(configurable_params_);
    276  configurable_params_ = nullptr;
    277  return configurable_params;
    278 }
    279 
    280 // Returns video sources and transfer frame generators ownership to the
    281 // caller. Can be called once.
    282 std::vector<PeerConfigurer::VideoSource> PeerConfigurer::ReleaseVideoSources() {
    283  auto video_sources = std::move(video_sources_);
    284  video_sources_.clear();
    285  return video_sources;
    286 }
    287 
    288 }  // namespace webrtc_pc_e2e
    289 }  // namespace webrtc