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