1 /* 2 * Copyright (c) 2019 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 TEST_PC_E2E_PEER_CONFIGURER_H_ 11 #define TEST_PC_E2E_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/call/call_factory_interface.h" 21 #include "api/fec_controller.h" 22 #include "api/rtc_event_log/rtc_event_log_factory_interface.h" 23 #include "api/task_queue/task_queue_factory.h" 24 #include "api/test/create_peer_connection_quality_test_frame_generator.h" 25 #include "api/test/peerconnection_quality_test_fixture.h" 26 #include "api/transport/network_control.h" 27 #include "api/video_codecs/video_decoder_factory.h" 28 #include "api/video_codecs/video_encoder_factory.h" 29 #include "rtc_base/network.h" 30 #include "rtc_base/rtc_certificate_generator.h" 31 #include "rtc_base/ssl_certificate.h" 32 #include "rtc_base/thread.h" 33 #include "test/pc/e2e/peer_connection_quality_test_params.h" 34 35 namespace webrtc { 36 namespace webrtc_pc_e2e { 37 38 class PeerConfigurerImpl final 39 : public PeerConnectionE2EQualityTestFixture::PeerConfigurer { 40 public: 41 using VideoSource = 42 absl::variant<std::unique_ptr<test::FrameGeneratorInterface>, 43 PeerConnectionE2EQualityTestFixture::CapturingDeviceIndex>; 44 PeerConfigurerImpl(rtc::Thread * network_thread,rtc::NetworkManager * network_manager)45 PeerConfigurerImpl(rtc::Thread* network_thread, 46 rtc::NetworkManager* network_manager) 47 : components_(std::make_unique<InjectableComponents>(network_thread, 48 network_manager)), 49 params_(std::make_unique<Params>()) {} 50 SetName(absl::string_view name)51 PeerConfigurer* SetName(absl::string_view name) override { 52 params_->name = std::string(name); 53 return this; 54 } 55 56 // Implementation of PeerConnectionE2EQualityTestFixture::PeerConfigurer. SetTaskQueueFactory(std::unique_ptr<TaskQueueFactory> task_queue_factory)57 PeerConfigurer* SetTaskQueueFactory( 58 std::unique_ptr<TaskQueueFactory> task_queue_factory) override { 59 components_->pcf_dependencies->task_queue_factory = 60 std::move(task_queue_factory); 61 return this; 62 } SetCallFactory(std::unique_ptr<CallFactoryInterface> call_factory)63 PeerConfigurer* SetCallFactory( 64 std::unique_ptr<CallFactoryInterface> call_factory) override { 65 components_->pcf_dependencies->call_factory = std::move(call_factory); 66 return this; 67 } SetEventLogFactory(std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory)68 PeerConfigurer* SetEventLogFactory( 69 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) override { 70 components_->pcf_dependencies->event_log_factory = 71 std::move(event_log_factory); 72 return this; 73 } SetFecControllerFactory(std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory)74 PeerConfigurer* SetFecControllerFactory( 75 std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory) 76 override { 77 components_->pcf_dependencies->fec_controller_factory = 78 std::move(fec_controller_factory); 79 return this; 80 } SetNetworkControllerFactory(std::unique_ptr<NetworkControllerFactoryInterface> network_controller_factory)81 PeerConfigurer* SetNetworkControllerFactory( 82 std::unique_ptr<NetworkControllerFactoryInterface> 83 network_controller_factory) override { 84 components_->pcf_dependencies->network_controller_factory = 85 std::move(network_controller_factory); 86 return this; 87 } SetVideoEncoderFactory(std::unique_ptr<VideoEncoderFactory> video_encoder_factory)88 PeerConfigurer* SetVideoEncoderFactory( 89 std::unique_ptr<VideoEncoderFactory> video_encoder_factory) override { 90 components_->pcf_dependencies->video_encoder_factory = 91 std::move(video_encoder_factory); 92 return this; 93 } SetVideoDecoderFactory(std::unique_ptr<VideoDecoderFactory> video_decoder_factory)94 PeerConfigurer* SetVideoDecoderFactory( 95 std::unique_ptr<VideoDecoderFactory> video_decoder_factory) override { 96 components_->pcf_dependencies->video_decoder_factory = 97 std::move(video_decoder_factory); 98 return this; 99 } 100 SetAsyncResolverFactory(std::unique_ptr<webrtc::AsyncResolverFactory> async_resolver_factory)101 PeerConfigurer* SetAsyncResolverFactory( 102 std::unique_ptr<webrtc::AsyncResolverFactory> async_resolver_factory) 103 override { 104 components_->pc_dependencies->async_resolver_factory = 105 std::move(async_resolver_factory); 106 return this; 107 } SetRTCCertificateGenerator(std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator)108 PeerConfigurer* SetRTCCertificateGenerator( 109 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) 110 override { 111 components_->pc_dependencies->cert_generator = std::move(cert_generator); 112 return this; 113 } SetSSLCertificateVerifier(std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier)114 PeerConfigurer* SetSSLCertificateVerifier( 115 std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier) override { 116 components_->pc_dependencies->tls_cert_verifier = 117 std::move(tls_cert_verifier); 118 return this; 119 } 120 AddVideoConfig(PeerConnectionE2EQualityTestFixture::VideoConfig config)121 PeerConfigurer* AddVideoConfig( 122 PeerConnectionE2EQualityTestFixture::VideoConfig config) override { 123 video_sources_.push_back( 124 CreateSquareFrameGenerator(config, /*type=*/absl::nullopt)); 125 params_->video_configs.push_back(std::move(config)); 126 return this; 127 } AddVideoConfig(PeerConnectionE2EQualityTestFixture::VideoConfig config,std::unique_ptr<test::FrameGeneratorInterface> generator)128 PeerConfigurer* AddVideoConfig( 129 PeerConnectionE2EQualityTestFixture::VideoConfig config, 130 std::unique_ptr<test::FrameGeneratorInterface> generator) override { 131 params_->video_configs.push_back(std::move(config)); 132 video_sources_.push_back(std::move(generator)); 133 return this; 134 } AddVideoConfig(PeerConnectionE2EQualityTestFixture::VideoConfig config,PeerConnectionE2EQualityTestFixture::CapturingDeviceIndex index)135 PeerConfigurer* AddVideoConfig( 136 PeerConnectionE2EQualityTestFixture::VideoConfig config, 137 PeerConnectionE2EQualityTestFixture::CapturingDeviceIndex index) 138 override { 139 params_->video_configs.push_back(std::move(config)); 140 video_sources_.push_back(index); 141 return this; 142 } SetAudioConfig(PeerConnectionE2EQualityTestFixture::AudioConfig config)143 PeerConfigurer* SetAudioConfig( 144 PeerConnectionE2EQualityTestFixture::AudioConfig config) override { 145 params_->audio_config = std::move(config); 146 return this; 147 } SetNetEqFactory(std::unique_ptr<NetEqFactory> neteq_factory)148 PeerConfigurer* SetNetEqFactory( 149 std::unique_ptr<NetEqFactory> neteq_factory) override { 150 components_->pcf_dependencies->neteq_factory = std::move(neteq_factory); 151 return this; 152 } SetRtcEventLogPath(std::string path)153 PeerConfigurer* SetRtcEventLogPath(std::string path) override { 154 params_->rtc_event_log_path = std::move(path); 155 return this; 156 } SetAecDumpPath(std::string path)157 PeerConfigurer* SetAecDumpPath(std::string path) override { 158 params_->aec_dump_path = std::move(path); 159 return this; 160 } SetRTCConfiguration(PeerConnectionInterface::RTCConfiguration configuration)161 PeerConfigurer* SetRTCConfiguration( 162 PeerConnectionInterface::RTCConfiguration configuration) override { 163 params_->rtc_configuration = std::move(configuration); 164 return this; 165 } SetBitrateSettings(BitrateSettings bitrate_settings)166 PeerConfigurer* SetBitrateSettings( 167 BitrateSettings bitrate_settings) override { 168 params_->bitrate_settings = bitrate_settings; 169 return this; 170 } 171 SetIceTransportFactory(std::unique_ptr<IceTransportFactory> factory)172 PeerConfigurer* SetIceTransportFactory( 173 std::unique_ptr<IceTransportFactory> factory) override { 174 components_->pc_dependencies->ice_transport_factory = std::move(factory); 175 return this; 176 } 177 // Implementation of PeerConnectionE2EQualityTestFixture::PeerConfigurer end. 178 components()179 InjectableComponents* components() { return components_.get(); } params()180 Params* params() { return params_.get(); } video_sources()181 std::vector<VideoSource>* video_sources() { return &video_sources_; } 182 183 // Returns InjectableComponents and transfer ownership to the caller. 184 // Can be called once. ReleaseComponents()185 std::unique_ptr<InjectableComponents> ReleaseComponents() { 186 RTC_CHECK(components_); 187 auto components = std::move(components_); 188 components_ = nullptr; 189 return components; 190 } 191 // Returns Params and transfer ownership to the caller. 192 // Can be called once. ReleaseParams()193 std::unique_ptr<Params> ReleaseParams() { 194 RTC_CHECK(params_); 195 auto params = std::move(params_); 196 params_ = nullptr; 197 return params; 198 } 199 // Returns video sources and transfer frame generators ownership to the 200 // caller. Can be called once. ReleaseVideoSources()201 std::vector<VideoSource> ReleaseVideoSources() { 202 auto video_sources = std::move(video_sources_); 203 video_sources_.clear(); 204 return video_sources; 205 } 206 207 private: 208 std::unique_ptr<InjectableComponents> components_; 209 std::unique_ptr<Params> params_; 210 std::vector<VideoSource> video_sources_; 211 }; 212 213 // Set missing params to default values if it is required: 214 // * Generate video stream labels if some of them are missing 215 // * Generate audio stream labels if some of them are missing 216 // * Set video source generation mode if it is not specified 217 // * Video codecs under test 218 void SetDefaultValuesForMissingParams( 219 PeerConnectionE2EQualityTestFixture::RunParams* run_params, 220 std::vector<std::unique_ptr<PeerConfigurerImpl>>* peers); 221 // Validate peer's parameters, also ensure uniqueness of all video stream 222 // labels. 223 void ValidateParams( 224 const PeerConnectionE2EQualityTestFixture::RunParams& run_params, 225 const std::vector<std::unique_ptr<PeerConfigurerImpl>>& peers); 226 227 } // namespace webrtc_pc_e2e 228 } // namespace webrtc 229 230 #endif // TEST_PC_E2E_PEER_CONFIGURER_H_ 231