tor-browser

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

peer_configurer.h (10392B)


      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 #ifndef API_TEST_PCLF_PEER_CONFIGURER_H_
     11 #define API_TEST_PCLF_PEER_CONFIGURER_H_
     12 
     13 #include <cstdint>
     14 #include <memory>
     15 #include <string>
     16 #include <variant>
     17 #include <vector>
     18 
     19 #include "absl/strings/string_view.h"
     20 #include "api/async_dns_resolver.h"
     21 #include "api/audio/audio_mixer.h"
     22 #include "api/audio/audio_processing.h"
     23 #include "api/audio_codecs/audio_decoder_factory.h"
     24 #include "api/audio_codecs/audio_encoder_factory.h"
     25 #include "api/fec_controller.h"
     26 #include "api/field_trials.h"
     27 #include "api/ice_transport_interface.h"
     28 #include "api/neteq/neteq_factory.h"
     29 #include "api/peer_connection_interface.h"
     30 #include "api/rtc_event_log/rtc_event_log_factory_interface.h"
     31 #include "api/scoped_refptr.h"
     32 #include "api/test/frame_generator_interface.h"
     33 #include "api/test/pclf/media_configuration.h"
     34 #include "api/test/pclf/media_quality_test_params.h"
     35 #include "api/test/peer_network_dependencies.h"
     36 #include "api/transport/bitrate_settings.h"
     37 #include "api/transport/network_control.h"
     38 #include "api/video_codecs/video_decoder_factory.h"
     39 #include "api/video_codecs/video_encoder_factory.h"
     40 #include "rtc_base/rtc_certificate_generator.h"
     41 #include "rtc_base/ssl_certificate.h"
     42 
     43 namespace webrtc {
     44 namespace webrtc_pc_e2e {
     45 
     46 // This class is used to fully configure one peer inside a call.
     47 class PeerConfigurer {
     48 public:
     49  using VideoSource =
     50      std::variant<std::unique_ptr<test::FrameGeneratorInterface>,
     51                   CapturingDeviceIndex>;
     52 
     53  explicit PeerConfigurer(PeerNetworkDependencies& network);
     54 
     55  // Sets peer name that will be used to report metrics related to this peer.
     56  // If not set, some default name will be assigned. All names have to be
     57  // unique.
     58  PeerConfigurer* SetName(absl::string_view name);
     59 
     60  // The parameters of the following 7 methods will be passed to the
     61  // PeerConnectionFactoryInterface implementation that will be created for
     62  // this peer.
     63  PeerConfigurer* SetEventLogFactory(
     64      std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory);
     65  PeerConfigurer* SetFecControllerFactory(
     66      std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory);
     67  PeerConfigurer* SetNetworkControllerFactory(
     68      std::unique_ptr<NetworkControllerFactoryInterface>
     69          network_controller_factory);
     70  PeerConfigurer* SetVideoEncoderFactory(
     71      std::unique_ptr<VideoEncoderFactory> video_encoder_factory);
     72  PeerConfigurer* SetVideoDecoderFactory(
     73      std::unique_ptr<VideoDecoderFactory> video_decoder_factory);
     74  PeerConfigurer* SetAudioEncoderFactory(
     75      scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory);
     76  PeerConfigurer* SetAudioDecoderFactory(
     77      scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory);
     78  // Set a custom NetEqFactory to be used in the call.
     79  PeerConfigurer* SetNetEqFactory(std::unique_ptr<NetEqFactory> neteq_factory);
     80  PeerConfigurer* SetAudioProcessing(
     81      std::unique_ptr<AudioProcessingBuilderInterface> audio_processing);
     82  PeerConfigurer* SetAudioMixer(scoped_refptr<webrtc::AudioMixer> audio_mixer);
     83 
     84  // Forces the Peerconnection to use the network thread as the worker thread.
     85  // Ie, worker thread and the network thread is the same thread.
     86  PeerConfigurer* SetUseNetworkThreadAsWorkerThread();
     87 
     88  // The parameters of the following 4 methods will be passed to the
     89  // PeerConnectionInterface implementation that will be created for this
     90  // peer.
     91  PeerConfigurer* SetAsyncDnsResolverFactory(
     92      std::unique_ptr<webrtc::AsyncDnsResolverFactoryInterface>
     93          async_dns_resolver_factory);
     94  PeerConfigurer* SetRTCCertificateGenerator(
     95      std::unique_ptr<RTCCertificateGeneratorInterface> cert_generator);
     96  PeerConfigurer* SetSSLCertificateVerifier(
     97      std::unique_ptr<SSLCertificateVerifier> tls_cert_verifier);
     98  PeerConfigurer* SetIceTransportFactory(
     99      std::unique_ptr<IceTransportFactory> factory);
    100  // Flags to set on `webrtc::PortAllocator`. These flags will be added
    101  // to the webrtc::kDefaultPortAllocatorFlags with
    102  // webrtc::PORTALLOCATOR_DISABLE_TCP disabled. For possible values check
    103  // p2p/base/port_allocator.h.
    104  PeerConfigurer* SetPortAllocatorExtraFlags(uint32_t extra_flags);
    105  // Flags to set on `webrtc::PortAllocator`. These flags will override
    106  // the default ones that are presented on the port allocator.
    107  //
    108  // For possible values check p2p/base/port_allocator.h.
    109  //
    110  // IMPORTANT: if you use WebRTC Network Emulation
    111  // (api/test/network_emulation_manager.h) and set this field, remember to set
    112  // webrtc::PORTALLOCATOR_DISABLE_TCP to 0.
    113  PeerConfigurer* SetPortAllocatorFlags(uint32_t flags);
    114 
    115  // Add new video stream to the call that will be sent from this peer.
    116  // Default implementation of video frames generator will be used.
    117  PeerConfigurer* AddVideoConfig(VideoConfig config);
    118  // Add new video stream to the call that will be sent from this peer with
    119  // provided own implementation of video frames generator.
    120  PeerConfigurer* AddVideoConfig(
    121      VideoConfig config,
    122      std::unique_ptr<test::FrameGeneratorInterface> generator);
    123  // Add new video stream to the call that will be sent from this peer.
    124  // Capturing device with specified index will be used to get input video.
    125  PeerConfigurer* AddVideoConfig(VideoConfig config,
    126                                 CapturingDeviceIndex capturing_device_index);
    127  // Sets video subscription for the peer. By default subscription will
    128  // include all streams with `VideoSubscription::kSameAsSendStream`
    129  // resolution. To this behavior use this method.
    130  PeerConfigurer* SetVideoSubscription(VideoSubscription subscription);
    131  // Sets the list of video codecs used by the peer during the test. These
    132  // codecs will be negotiated in SDP during offer/answer exchange. The order
    133  // of these codecs during negotiation will be the same as in `video_codecs`.
    134  // Codecs have to be available in codecs list provided by peer connection to
    135  // be negotiated. If some of specified codecs won't be found, the test will
    136  // crash.
    137  PeerConfigurer* SetVideoCodecs(std::vector<VideoCodecConfig> video_codecs);
    138  // Sets a list of RTP header extensions which will be enforced on all video
    139  // streams added to this peer.
    140  PeerConfigurer* SetExtraVideoRtpHeaderExtensions(
    141      std::vector<std::string> extensions);
    142  // Sets the audio stream for the call from this peer. If this method won't
    143  // be invoked, this peer will send no audio.
    144  PeerConfigurer* SetAudioConfig(AudioConfig config);
    145  // Sets a list of RTP header extensions which will be enforced on all audio
    146  // streams added to this peer.
    147  PeerConfigurer* SetExtraAudioRtpHeaderExtensions(
    148      std::vector<std::string> extensions);
    149 
    150  // Set if ULP FEC should be used or not. False by default.
    151  PeerConfigurer* SetUseUlpFEC(bool value);
    152  // Set if Flex FEC should be used or not. False by default.
    153  // Client also must enable `enable_flex_fec_support` in the `RunParams` to
    154  // be able to use this feature.
    155  PeerConfigurer* SetUseFlexFEC(bool value);
    156  // Specifies how much video encoder target bitrate should be different than
    157  // target bitrate, provided by WebRTC stack. Must be greater than 0. Can be
    158  // used to emulate overshooting of video encoders. This multiplier will
    159  // be applied for all video encoder on both sides for all layers. Bitrate
    160  // estimated by WebRTC stack will be multiplied by this multiplier and then
    161  // provided into VideoEncoder::SetRates(...). 1.0 by default.
    162  PeerConfigurer* SetVideoEncoderBitrateMultiplier(double multiplier);
    163 
    164  // If is set, an RTCEventLog will be saved in that location and it will be
    165  // available for further analysis.
    166  PeerConfigurer* SetRtcEventLogPath(absl::string_view path);
    167  // If is set, an AEC dump will be saved in that location and it will be
    168  // available for further analysis.
    169  PeerConfigurer* SetAecDumpPath(absl::string_view path);
    170  PeerConfigurer* SetPCFOptions(
    171      PeerConnectionFactoryInterface::Options options);
    172  PeerConfigurer* SetRTCConfiguration(
    173      PeerConnectionInterface::RTCConfiguration configuration);
    174  PeerConfigurer* SetRTCOfferAnswerOptions(
    175      PeerConnectionInterface::RTCOfferAnswerOptions options);
    176  // Set bitrate parameters on PeerConnection. This constraints will be
    177  // applied to all summed RTP streams for this peer.
    178  PeerConfigurer* SetBitrateSettings(BitrateSettings bitrate_settings);
    179 
    180  // Appends field trials for this PeerConnection.
    181  PeerConfigurer* AddFieldTrials(const FieldTrials& field_trials) {
    182    GetFieldTrials().Merge(field_trials);
    183    return this;
    184  }
    185 
    186  // Returns InjectableComponents and transfer ownership to the caller.
    187  // Can be called once.
    188  std::unique_ptr<InjectableComponents> ReleaseComponents();
    189 
    190  // Returns Params and transfer ownership to the caller.
    191  // Can be called once.
    192  std::unique_ptr<Params> ReleaseParams();
    193 
    194  // Returns ConfigurableParams and transfer ownership to the caller.
    195  // Can be called once.
    196  std::unique_ptr<ConfigurableParams> ReleaseConfigurableParams();
    197 
    198  // Returns video sources and transfer frame generators ownership to the
    199  // caller. Can be called once.
    200  std::vector<VideoSource> ReleaseVideoSources();
    201 
    202  InjectableComponents* components() { return components_.get(); }
    203  Params* params() { return params_.get(); }
    204  ConfigurableParams* configurable_params() {
    205    return configurable_params_.get();
    206  }
    207  const Params& params() const { return *params_; }
    208  const ConfigurableParams& configurable_params() const {
    209    return *configurable_params_;
    210  }
    211  std::vector<VideoSource>* video_sources() { return &video_sources_; }
    212 
    213 private:
    214  FieldTrials& GetFieldTrials() {
    215    return *components_->pcf_dependencies->field_trials;
    216  }
    217 
    218  std::unique_ptr<InjectableComponents> components_;
    219  std::unique_ptr<Params> params_;
    220  std::unique_ptr<ConfigurableParams> configurable_params_;
    221  std::vector<VideoSource> video_sources_;
    222 };
    223 
    224 }  // namespace webrtc_pc_e2e
    225 }  // namespace webrtc
    226 
    227 #endif  // API_TEST_PCLF_PEER_CONFIGURER_H_