From d16f290e414d5eb7d2d3cc7c858fffdb3b66cb5a Mon Sep 17 00:00:00 2001 From: Jeremy Leconte Date: Fri, 4 Nov 2022 08:32:18 +0100 Subject: [PATCH] Move PeerConfigurerImpl to the test public api. End goal is to remove PeerConnectionE2EQualityTestFixture::PeerConfigurer interface. Change-Id: I4a6aa0ab1fb5a0d6f85154159b7da16de9b53059 Bug: webrtc:14627 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/281501 Reviewed-by: Artem Titov Reviewed-by: Harald Alvestrand Commit-Queue: Jeremy Leconte Cr-Commit-Position: refs/heads/main@{#38551} --- api/test/pclf/BUILD.gn | 64 ++++ api/test/pclf/DEPS | 13 + .../test/pclf/media_quality_test_params.h | 8 +- .../e2e => api/test/pclf}/peer_configurer.cc | 222 +++++++++++- api/test/pclf/peer_configurer.h | 264 ++++++++++++++ test/pc/e2e/BUILD.gn | 65 +--- test/pc/e2e/media/media_helper.h | 2 +- test/pc/e2e/peer_configurer.h | 325 +----------------- test/pc/e2e/peer_connection_quality_test.cc | 5 +- test/pc/e2e/peer_connection_quality_test.h | 4 +- test/pc/e2e/test_peer.h | 4 +- test/pc/e2e/test_peer_factory.cc | 2 +- test/pc/e2e/test_peer_factory.h | 4 +- 13 files changed, 585 insertions(+), 397 deletions(-) create mode 100644 api/test/pclf/BUILD.gn create mode 100644 api/test/pclf/DEPS rename test/pc/e2e/peer_connection_quality_test_params.h => api/test/pclf/media_quality_test_params.h (96%) rename {test/pc/e2e => api/test/pclf}/peer_configurer.cc (50%) create mode 100644 api/test/pclf/peer_configurer.h diff --git a/api/test/pclf/BUILD.gn b/api/test/pclf/BUILD.gn new file mode 100644 index 0000000000..1d6b995a39 --- /dev/null +++ b/api/test/pclf/BUILD.gn @@ -0,0 +1,64 @@ +# Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. + +import("../../../webrtc.gni") + +rtc_library("media_quality_test_params") { + visibility = [ "*" ] + testonly = true + sources = [ "media_quality_test_params.h" ] + + deps = [ + "../../../api:callfactory_api", + "../../../api:fec_controller_api", + "../../../api:field_trials_view", + "../../../api:libjingle_peerconnection_api", + "../../../api:packet_socket_factory", + "../../../api:peer_connection_quality_test_fixture_api", + "../../../api/audio:audio_mixer_api", + "../../../api/rtc_event_log", + "../../../api/task_queue", + "../../../api/transport:network_control", + "../../../api/video_codecs:video_codecs_api", + "../../../modules/audio_processing:api", + "../../../p2p:rtc_p2p", + "../../../rtc_base", + "../../../rtc_base:threading", + ] +} + +rtc_library("peer_configurer") { + visibility = [ "*" ] + testonly = true + sources = [ + "peer_configurer.cc", + "peer_configurer.h", + ] + deps = [ + ":media_quality_test_params", + "../../../api:callfactory_api", + "../../../api:create_peer_connection_quality_test_frame_generator", + "../../../api:fec_controller_api", + "../../../api:packet_socket_factory", + "../../../api:peer_connection_quality_test_fixture_api", + "../../../api:peer_network_dependencies", + "../../../api/audio:audio_mixer_api", + "../../../api/rtc_event_log", + "../../../api/task_queue", + "../../../api/transport:network_control", + "../../../api/video_codecs:video_codecs_api", + "../../../modules/audio_processing:api", + "../../../modules/video_coding/svc:scalability_mode_util", + "../../../modules/video_coding/svc:scalability_structures", + "../../../rtc_base", + "../../../rtc_base:macromagic", + "../../../rtc_base:threading", + "../../../test:fileutils", + ] + absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] +} diff --git a/api/test/pclf/DEPS b/api/test/pclf/DEPS new file mode 100644 index 0000000000..60cc0aeeb3 --- /dev/null +++ b/api/test/pclf/DEPS @@ -0,0 +1,13 @@ +specific_include_rules = { + ".*": [ + "+modules/audio_processing/include/audio_processing.h", + "+rtc_base/checks.h", + "+rtc_base/network.h", + "+rtc_base/rtc_certificate_generator.h", + "+rtc_base/ssl_certificate.h", + "+rtc_base/thread.h", + ], + "media_quality_test_params\.h": [ + "+p2p/base/port_allocator.h", + ], +} diff --git a/test/pc/e2e/peer_connection_quality_test_params.h b/api/test/pclf/media_quality_test_params.h similarity index 96% rename from test/pc/e2e/peer_connection_quality_test_params.h rename to api/test/pclf/media_quality_test_params.h index 221f6b3f7f..0f8bec1d66 100644 --- a/test/pc/e2e/peer_connection_quality_test_params.h +++ b/api/test/pclf/media_quality_test_params.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -7,8 +7,8 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ -#ifndef TEST_PC_E2E_PEER_CONNECTION_QUALITY_TEST_PARAMS_H_ -#define TEST_PC_E2E_PEER_CONNECTION_QUALITY_TEST_PARAMS_H_ +#ifndef API_TEST_PCLF_MEDIA_QUALITY_TEST_PARAMS_H_ +#define API_TEST_PCLF_MEDIA_QUALITY_TEST_PARAMS_H_ #include #include @@ -159,4 +159,4 @@ struct ConfigurableParams { } // namespace webrtc_pc_e2e } // namespace webrtc -#endif // TEST_PC_E2E_PEER_CONNECTION_QUALITY_TEST_PARAMS_H_ +#endif // API_TEST_PCLF_MEDIA_QUALITY_TEST_PARAMS_H_ diff --git a/test/pc/e2e/peer_configurer.cc b/api/test/pclf/peer_configurer.cc similarity index 50% rename from test/pc/e2e/peer_configurer.cc rename to api/test/pclf/peer_configurer.cc index 9a51bbff37..c404908d20 100644 --- a/test/pc/e2e/peer_configurer.cc +++ b/api/test/pclf/peer_configurer.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -8,11 +8,12 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "test/pc/e2e/peer_configurer.h" +#include "api/test/pclf/peer_configurer.h" #include #include "absl/strings/string_view.h" +#include "api/test/peer_network_dependencies.h" #include "modules/video_coding/svc/create_scalability_structure.h" #include "modules/video_coding/svc/scalability_mode_util.h" #include "rtc_base/arraysize.h" @@ -26,6 +27,7 @@ using AudioConfig = PeerConnectionE2EQualityTestFixture::AudioConfig; using VideoConfig = PeerConnectionE2EQualityTestFixture::VideoConfig; using RunParams = PeerConnectionE2EQualityTestFixture::RunParams; using VideoCodecConfig = PeerConnectionE2EQualityTestFixture::VideoCodecConfig; +using PeerConfigurer = PeerConnectionE2EQualityTestFixture::PeerConfigurer; // List of default names of generic participants according to // https://en.wikipedia.org/wiki/Alice_and_Bob @@ -34,6 +36,222 @@ constexpr absl::string_view kDefaultNames[] = {"alice", "bob", "charlie", } // namespace +PeerConfigurerImpl::PeerConfigurerImpl( + const PeerNetworkDependencies& network_dependencies) + : components_(std::make_unique( + network_dependencies.network_thread, + network_dependencies.network_manager, + network_dependencies.packet_socket_factory)), + params_(std::make_unique()), + configurable_params_(std::make_unique()) {} + +PeerConfigurer* PeerConfigurerImpl::SetName(absl::string_view name) { + params_->name = std::string(name); + return this; +} + +PeerConfigurer* PeerConfigurerImpl::SetTaskQueueFactory( + std::unique_ptr task_queue_factory) { + components_->pcf_dependencies->task_queue_factory = + std::move(task_queue_factory); + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetCallFactory( + std::unique_ptr call_factory) { + components_->pcf_dependencies->call_factory = std::move(call_factory); + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetEventLogFactory( + std::unique_ptr event_log_factory) { + components_->pcf_dependencies->event_log_factory = + std::move(event_log_factory); + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetFecControllerFactory( + std::unique_ptr fec_controller_factory) { + components_->pcf_dependencies->fec_controller_factory = + std::move(fec_controller_factory); + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetNetworkControllerFactory( + std::unique_ptr + network_controller_factory) { + components_->pcf_dependencies->network_controller_factory = + std::move(network_controller_factory); + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetVideoEncoderFactory( + std::unique_ptr video_encoder_factory) { + components_->pcf_dependencies->video_encoder_factory = + std::move(video_encoder_factory); + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetVideoDecoderFactory( + std::unique_ptr video_decoder_factory) { + components_->pcf_dependencies->video_decoder_factory = + std::move(video_decoder_factory); + return this; +} + +PeerConfigurer* PeerConfigurerImpl::SetAsyncResolverFactory( + std::unique_ptr async_resolver_factory) { + components_->pc_dependencies->async_resolver_factory = + std::move(async_resolver_factory); + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetRTCCertificateGenerator( + std::unique_ptr cert_generator) { + components_->pc_dependencies->cert_generator = std::move(cert_generator); + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetSSLCertificateVerifier( + std::unique_ptr tls_cert_verifier) { + components_->pc_dependencies->tls_cert_verifier = + std::move(tls_cert_verifier); + return this; +} + +PeerConfigurer* PeerConfigurerImpl::AddVideoConfig( + PeerConnectionE2EQualityTestFixture::VideoConfig config) { + video_sources_.push_back( + CreateSquareFrameGenerator(config, /*type=*/absl::nullopt)); + configurable_params_->video_configs.push_back(std::move(config)); + return this; +} +PeerConfigurer* PeerConfigurerImpl::AddVideoConfig( + PeerConnectionE2EQualityTestFixture::VideoConfig config, + std::unique_ptr generator) { + configurable_params_->video_configs.push_back(std::move(config)); + video_sources_.push_back(std::move(generator)); + return this; +} +PeerConfigurer* PeerConfigurerImpl::AddVideoConfig( + PeerConnectionE2EQualityTestFixture::VideoConfig config, + PeerConnectionE2EQualityTestFixture::CapturingDeviceIndex index) { + configurable_params_->video_configs.push_back(std::move(config)); + video_sources_.push_back(index); + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetVideoSubscription( + PeerConnectionE2EQualityTestFixture::VideoSubscription subscription) { + configurable_params_->video_subscription = std::move(subscription); + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetAudioConfig( + PeerConnectionE2EQualityTestFixture::AudioConfig config) { + params_->audio_config = std::move(config); + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetUseUlpFEC(bool value) { + params_->use_ulp_fec = value; + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetUseFlexFEC(bool value) { + params_->use_flex_fec = value; + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetVideoEncoderBitrateMultiplier( + double multiplier) { + params_->video_encoder_bitrate_multiplier = multiplier; + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetNetEqFactory( + std::unique_ptr neteq_factory) { + components_->pcf_dependencies->neteq_factory = std::move(neteq_factory); + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetAudioProcessing( + rtc::scoped_refptr audio_processing) { + components_->pcf_dependencies->audio_processing = audio_processing; + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetAudioMixer( + rtc::scoped_refptr audio_mixer) { + components_->pcf_dependencies->audio_mixer = audio_mixer; + return this; +} + +PeerConfigurer* PeerConfigurerImpl::SetUseNetworkThreadAsWorkerThread() { + components_->worker_thread = components_->network_thread; + return this; +} + +PeerConfigurer* PeerConfigurerImpl::SetRtcEventLogPath(std::string path) { + params_->rtc_event_log_path = std::move(path); + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetAecDumpPath(std::string path) { + params_->aec_dump_path = std::move(path); + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetRTCConfiguration( + PeerConnectionInterface::RTCConfiguration configuration) { + params_->rtc_configuration = std::move(configuration); + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetRTCOfferAnswerOptions( + PeerConnectionInterface::RTCOfferAnswerOptions options) { + params_->rtc_offer_answer_options = std::move(options); + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetBitrateSettings( + BitrateSettings bitrate_settings) { + params_->bitrate_settings = bitrate_settings; + return this; +} +PeerConfigurer* PeerConfigurerImpl::SetVideoCodecs( + std::vector + video_codecs) { + params_->video_codecs = std::move(video_codecs); + return this; +} + +PeerConfigurer* PeerConfigurerImpl::SetIceTransportFactory( + std::unique_ptr factory) { + components_->pc_dependencies->ice_transport_factory = std::move(factory); + return this; +} + +PeerConfigurer* PeerConfigurerImpl::SetPortAllocatorExtraFlags( + uint32_t extra_flags) { + params_->port_allocator_extra_flags = extra_flags; + return this; +} +std::unique_ptr PeerConfigurerImpl::ReleaseComponents() { + RTC_CHECK(components_); + auto components = std::move(components_); + components_ = nullptr; + return components; +} + +// Returns Params and transfer ownership to the caller. +// Can be called once. +std::unique_ptr PeerConfigurerImpl::ReleaseParams() { + RTC_CHECK(params_); + auto params = std::move(params_); + params_ = nullptr; + return params; +} + +// Returns ConfigurableParams and transfer ownership to the caller. +// Can be called once. +std::unique_ptr +PeerConfigurerImpl::ReleaseConfigurableParams() { + RTC_CHECK(configurable_params_); + auto configurable_params = std::move(configurable_params_); + configurable_params_ = nullptr; + return configurable_params; +} + +// Returns video sources and transfer frame generators ownership to the +// caller. Can be called once. +std::vector +PeerConfigurerImpl::ReleaseVideoSources() { + auto video_sources = std::move(video_sources_); + video_sources_.clear(); + return video_sources; +} + DefaultNamesProvider::DefaultNamesProvider( absl::string_view prefix, rtc::ArrayView default_names) diff --git a/api/test/pclf/peer_configurer.h b/api/test/pclf/peer_configurer.h new file mode 100644 index 0000000000..1c23b1b02c --- /dev/null +++ b/api/test/pclf/peer_configurer.h @@ -0,0 +1,264 @@ +/* + * Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +#ifndef API_TEST_PCLF_PEER_CONFIGURER_H_ +#define API_TEST_PCLF_PEER_CONFIGURER_H_ + +#include +#include +#include +#include +#include + +#include "absl/strings/string_view.h" +#include "api/async_resolver_factory.h" +#include "api/audio/audio_mixer.h" +#include "api/call/call_factory_interface.h" +#include "api/fec_controller.h" +#include "api/rtc_event_log/rtc_event_log_factory_interface.h" +#include "api/task_queue/task_queue_factory.h" +#include "api/test/create_peer_connection_quality_test_frame_generator.h" +#include "api/test/pclf/media_quality_test_params.h" +#include "api/test/peer_network_dependencies.h" +#include "api/test/peerconnection_quality_test_fixture.h" +#include "api/transport/network_control.h" +#include "api/video_codecs/video_decoder_factory.h" +#include "api/video_codecs/video_encoder_factory.h" +#include "modules/audio_processing/include/audio_processing.h" +#include "rtc_base/network.h" +#include "rtc_base/rtc_certificate_generator.h" +#include "rtc_base/ssl_certificate.h" +#include "rtc_base/thread.h" + +namespace webrtc { +namespace webrtc_pc_e2e { + +// This class is used to fully configure one peer inside a call. +class PeerConfigurerImpl final + : public PeerConnectionE2EQualityTestFixture::PeerConfigurer { + public: + using VideoSource = + absl::variant, + PeerConnectionE2EQualityTestFixture::CapturingDeviceIndex>; + + explicit PeerConfigurerImpl( + const PeerNetworkDependencies& network_dependencies); + + PeerConfigurerImpl(rtc::Thread* network_thread, + rtc::NetworkManager* network_manager, + rtc::PacketSocketFactory* packet_socket_factory) + : components_( + std::make_unique(network_thread, + network_manager, + packet_socket_factory)), + params_(std::make_unique()), + configurable_params_(std::make_unique()) {} + + // Sets peer name that will be used to report metrics related to this peer. + // If not set, some default name will be assigned. All names have to be + // unique. + PeerConfigurer* SetName(absl::string_view name) override; + + // The parameters of the following 9 methods will be passed to the + // PeerConnectionFactoryInterface implementation that will be created for + // this peer. + PeerConfigurer* SetTaskQueueFactory( + std::unique_ptr task_queue_factory) override; + PeerConfigurer* SetCallFactory( + std::unique_ptr call_factory) override; + PeerConfigurer* SetEventLogFactory( + std::unique_ptr event_log_factory) override; + PeerConfigurer* SetFecControllerFactory( + std::unique_ptr fec_controller_factory) + override; + PeerConfigurer* SetNetworkControllerFactory( + std::unique_ptr + network_controller_factory) override; + PeerConfigurer* SetVideoEncoderFactory( + std::unique_ptr video_encoder_factory) override; + PeerConfigurer* SetVideoDecoderFactory( + std::unique_ptr video_decoder_factory) override; + // Set a custom NetEqFactory to be used in the call. + PeerConfigurer* SetNetEqFactory( + std::unique_ptr neteq_factory) override; + PeerConfigurer* SetAudioProcessing( + rtc::scoped_refptr audio_processing) override; + PeerConfigurer* SetAudioMixer( + rtc::scoped_refptr audio_mixer) override; + + // Forces the Peerconnection to use the network thread as the worker thread. + // Ie, worker thread and the network thread is the same thread. + PeerConfigurer* SetUseNetworkThreadAsWorkerThread() override; + + // The parameters of the following 4 methods will be passed to the + // PeerConnectionInterface implementation that will be created for this + // peer. + PeerConfigurer* SetAsyncResolverFactory( + std::unique_ptr async_resolver_factory) + override; + PeerConfigurer* SetRTCCertificateGenerator( + std::unique_ptr cert_generator) + override; + PeerConfigurer* SetSSLCertificateVerifier( + std::unique_ptr tls_cert_verifier) override; + PeerConfigurer* SetIceTransportFactory( + std::unique_ptr factory) override; + // Flags to set on `cricket::PortAllocator`. These flags will be added + // to the default ones that are presented on the port allocator. + // For possible values check p2p/base/port_allocator.h. + PeerConfigurer* SetPortAllocatorExtraFlags(uint32_t extra_flags) override; + + // Add new video stream to the call that will be sent from this peer. + // Default implementation of video frames generator will be used. + PeerConfigurer* AddVideoConfig( + PeerConnectionE2EQualityTestFixture::VideoConfig config) override; + // Add new video stream to the call that will be sent from this peer with + // provided own implementation of video frames generator. + PeerConfigurer* AddVideoConfig( + PeerConnectionE2EQualityTestFixture::VideoConfig config, + std::unique_ptr generator) override; + // Add new video stream to the call that will be sent from this peer. + // Capturing device with specified index will be used to get input video. + PeerConfigurer* AddVideoConfig( + PeerConnectionE2EQualityTestFixture::VideoConfig config, + PeerConnectionE2EQualityTestFixture::CapturingDeviceIndex + capturing_device_index) override; + // Sets video subscription for the peer. By default subscription will + // include all streams with `VideoSubscription::kSameAsSendStream` + // resolution. To override this behavior use this method. + PeerConfigurer* SetVideoSubscription( + PeerConnectionE2EQualityTestFixture::VideoSubscription subscription) + override; + // Set the list of video codecs used by the peer during the test. These + // codecs will be negotiated in SDP during offer/answer exchange. The order + // of these codecs during negotiation will be the same as in `video_codecs`. + // Codecs have to be available in codecs list provided by peer connection to + // be negotiated. If some of specified codecs won't be found, the test will + // crash. + PeerConfigurer* SetVideoCodecs( + std::vector + video_codecs) override; + // Set the audio stream for the call from this peer. If this method won't + // be invoked, this peer will send no audio. + PeerConfigurer* SetAudioConfig( + PeerConnectionE2EQualityTestFixture::AudioConfig config) override; + + // Set if ULP FEC should be used or not. False by default. + PeerConfigurer* SetUseUlpFEC(bool value) override; + // Set if Flex FEC should be used or not. False by default. + // Client also must enable `enable_flex_fec_support` in the `RunParams` to + // be able to use this feature. + PeerConfigurer* SetUseFlexFEC(bool value) override; + // Specifies how much video encoder target bitrate should be different than + // target bitrate, provided by WebRTC stack. Must be greater than 0. Can be + // used to emulate overshooting of video encoders. This multiplier will + // be applied for all video encoder on both sides for all layers. Bitrate + // estimated by WebRTC stack will be multiplied by this multiplier and then + // provided into VideoEncoder::SetRates(...). 1.0 by default. + PeerConfigurer* SetVideoEncoderBitrateMultiplier(double multiplier) override; + + // If is set, an RTCEventLog will be saved in that location and it will be + // available for further analysis. + PeerConfigurer* SetRtcEventLogPath(std::string path) override; + // If is set, an AEC dump will be saved in that location and it will be + // available for further analysis. + PeerConfigurer* SetAecDumpPath(std::string path) override; + PeerConfigurer* SetRTCConfiguration( + PeerConnectionInterface::RTCConfiguration configuration) override; + PeerConfigurer* SetRTCOfferAnswerOptions( + PeerConnectionInterface::RTCOfferAnswerOptions options) override; + // Set bitrate parameters on PeerConnection. This constraints will be + // applied to all summed RTP streams for this peer. + PeerConfigurer* SetBitrateSettings(BitrateSettings bitrate_settings) override; + + // Returns InjectableComponents and transfer ownership to the caller. + // Can be called once. + std::unique_ptr ReleaseComponents(); + + // Returns Params and transfer ownership to the caller. + // Can be called once. + std::unique_ptr ReleaseParams(); + + // Returns ConfigurableParams and transfer ownership to the caller. + // Can be called once. + std::unique_ptr ReleaseConfigurableParams(); + + // Returns video sources and transfer frame generators ownership to the + // caller. Can be called once. + std::vector ReleaseVideoSources(); + + InjectableComponents* components() { return components_.get(); } + Params* params() { return params_.get(); } + ConfigurableParams* configurable_params() { + return configurable_params_.get(); + } + const Params& params() const { return *params_; } + const ConfigurableParams& configurable_params() const { + return *configurable_params_; + } + std::vector* video_sources() { return &video_sources_; } + + private: + std::unique_ptr components_; + std::unique_ptr params_; + std::unique_ptr configurable_params_; + std::vector video_sources_; +}; + +class DefaultNamesProvider { + public: + // Caller have to ensure that default names array will outlive names provider + // instance. + explicit DefaultNamesProvider( + absl::string_view prefix, + rtc::ArrayView default_names = {}); + + void MaybeSetName(absl::optional& name); + + private: + std::string GenerateName(); + + std::string GenerateNameInternal(); + + const std::string prefix_; + const rtc::ArrayView default_names_; + + std::set known_names_; + size_t counter_ = 0; +}; + +class PeerParamsPreprocessor { + public: + PeerParamsPreprocessor(); + + // Set missing params to default values if it is required: + // * Generate video stream labels if some of them are missing + // * Generate audio stream labels if some of them are missing + // * Set video source generation mode if it is not specified + // * Video codecs under test + void SetDefaultValuesForMissingParams(PeerConfigurerImpl& peer); + + // Validate peer's parameters, also ensure uniqueness of all video stream + // labels. + void ValidateParams(const PeerConfigurerImpl& peer); + + private: + DefaultNamesProvider peer_names_provider_; + + std::set peer_names_; + std::set video_labels_; + std::set audio_labels_; + std::set video_sync_groups_; + std::set audio_sync_groups_; +}; + +} // namespace webrtc_pc_e2e +} // namespace webrtc + +#endif // API_TEST_PCLF_PEER_CONFIGURER_H_ diff --git a/test/pc/e2e/BUILD.gn b/test/pc/e2e/BUILD.gn index abefc203b5..5e3ac05b50 100644 --- a/test/pc/e2e/BUILD.gn +++ b/test/pc/e2e/BUILD.gn @@ -71,30 +71,6 @@ if (!build_with_chromium) { } } - rtc_library("peer_connection_quality_test_params") { - visibility = [ "*" ] - testonly = true - sources = [ "peer_connection_quality_test_params.h" ] - - deps = [ - "../../../api:callfactory_api", - "../../../api:fec_controller_api", - "../../../api:field_trials_view", - "../../../api:libjingle_peerconnection_api", - "../../../api:packet_socket_factory", - "../../../api:peer_connection_quality_test_fixture_api", - "../../../api/audio:audio_mixer_api", - "../../../api/rtc_event_log", - "../../../api/task_queue", - "../../../api/transport:network_control", - "../../../api/video_codecs:video_codecs_api", - "../../../modules/audio_processing:api", - "../../../p2p:rtc_p2p", - "../../../rtc_base", - "../../../rtc_base:threading", - ] - } - rtc_library("encoded_image_data_injector_api") { visibility = [ "*" ] testonly = true @@ -333,8 +309,6 @@ if (!build_with_chromium) { "test_peer.h", ] deps = [ - ":peer_configurer", - ":peer_connection_quality_test_params", ":stats_provider", "../../../api:frame_generator_api", "../../../api:function_view", @@ -343,6 +317,8 @@ if (!build_with_chromium) { "../../../api:scoped_refptr", "../../../api:sequence_checker", "../../../api/task_queue:pending_task_safety_flag", + "../../../api/test/pclf:media_quality_test_params", + "../../../api/test/pclf:peer_configurer", "../../../modules/audio_processing:api", "../../../pc:peerconnection_wrapper", "../../../rtc_base:logging", @@ -365,8 +341,6 @@ if (!build_with_chromium) { ] deps = [ ":echo_emulation", - ":peer_configurer", - ":peer_connection_quality_test_params", ":quality_analyzing_video_encoder", ":test_peer", ":video_quality_analyzer_injection_helper", @@ -376,6 +350,8 @@ if (!build_with_chromium) { "../../../api:time_controller", "../../../api/rtc_event_log:rtc_event_log_factory", "../../../api/task_queue:default_task_queue_factory", + "../../../api/test/pclf:media_quality_test_params", + "../../../api/test/pclf:peer_configurer", "../../../api/transport:field_trial_based_config", "../../../api/video_codecs:builtin_video_decoder_factory", "../../../api/video_codecs:builtin_video_encoder_factory", @@ -402,7 +378,6 @@ if (!build_with_chromium) { "media/test_video_capturer_video_track_source.h", ] deps = [ - ":peer_configurer", ":test_peer", ":video_quality_analyzer_injection_helper", "../..:fileutils", @@ -412,6 +387,7 @@ if (!build_with_chromium) { "../../../api:frame_generator_api", "../../../api:media_stream_interface", "../../../api:peer_connection_quality_test_fixture_api", + "../../../api/test/pclf:peer_configurer", "../../../api/video:video_frame", "../../../pc:session_description", "../../../pc:video_track_source", @@ -422,31 +398,8 @@ if (!build_with_chromium) { rtc_library("peer_configurer") { visibility = [ "*" ] testonly = true - sources = [ - "peer_configurer.cc", - "peer_configurer.h", - ] - deps = [ - ":peer_connection_quality_test_params", - "../..:fileutils", - "../../../api:callfactory_api", - "../../../api:create_peer_connection_quality_test_frame_generator", - "../../../api:fec_controller_api", - "../../../api:packet_socket_factory", - "../../../api:peer_connection_quality_test_fixture_api", - "../../../api/audio:audio_mixer_api", - "../../../api/rtc_event_log", - "../../../api/task_queue", - "../../../api/transport:network_control", - "../../../api/video_codecs:video_codecs_api", - "../../../modules/audio_processing:api", - "../../../modules/video_coding/svc:scalability_mode_util", - "../../../modules/video_coding/svc:scalability_structures", - "../../../rtc_base", - "../../../rtc_base:macromagic", - "../../../rtc_base:threading", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] + sources = [ "peer_configurer.h" ] + deps = [ "../../../api/test/pclf:peer_configurer" ] } rtc_library("test_activities_executor") { @@ -489,8 +442,6 @@ if (!build_with_chromium) { ":default_video_quality_analyzer", ":media_helper", ":metric_metadata_keys", - ":peer_configurer", - ":peer_connection_quality_test_params", ":sdp_changer", ":single_process_encoded_image_data_injector", ":stats_poller", @@ -515,6 +466,8 @@ if (!build_with_chromium) { "../../../api/task_queue", "../../../api/test/metrics:metric", "../../../api/test/metrics:metrics_logger", + "../../../api/test/pclf:media_quality_test_params", + "../../../api/test/pclf:peer_configurer", "../../../api/units:time_delta", "../../../api/units:timestamp", "../../../pc:pc_test_utils", diff --git a/test/pc/e2e/media/media_helper.h b/test/pc/e2e/media/media_helper.h index 4e977e3002..42ee7f117a 100644 --- a/test/pc/e2e/media/media_helper.h +++ b/test/pc/e2e/media/media_helper.h @@ -15,10 +15,10 @@ #include #include "api/test/frame_generator_interface.h" +#include "api/test/pclf/peer_configurer.h" #include "api/test/peerconnection_quality_test_fixture.h" #include "test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.h" #include "test/pc/e2e/media/test_video_capturer_video_track_source.h" -#include "test/pc/e2e/peer_configurer.h" #include "test/pc/e2e/test_peer.h" namespace webrtc { diff --git a/test/pc/e2e/peer_configurer.h b/test/pc/e2e/peer_configurer.h index 9bdc2a165d..be8410b220 100644 --- a/test/pc/e2e/peer_configurer.h +++ b/test/pc/e2e/peer_configurer.h @@ -10,329 +10,6 @@ #ifndef TEST_PC_E2E_PEER_CONFIGURER_H_ #define TEST_PC_E2E_PEER_CONFIGURER_H_ -#include -#include -#include -#include - -#include "absl/strings/string_view.h" -#include "api/async_resolver_factory.h" -#include "api/audio/audio_mixer.h" -#include "api/call/call_factory_interface.h" -#include "api/fec_controller.h" -#include "api/rtc_event_log/rtc_event_log_factory_interface.h" -#include "api/task_queue/task_queue_factory.h" -#include "api/test/create_peer_connection_quality_test_frame_generator.h" -#include "api/test/peerconnection_quality_test_fixture.h" -#include "api/transport/network_control.h" -#include "api/video_codecs/video_decoder_factory.h" -#include "api/video_codecs/video_encoder_factory.h" -#include "modules/audio_processing/include/audio_processing.h" -#include "rtc_base/network.h" -#include "rtc_base/rtc_certificate_generator.h" -#include "rtc_base/ssl_certificate.h" -#include "rtc_base/thread.h" -#include "test/pc/e2e/peer_connection_quality_test_params.h" - -namespace webrtc { -namespace webrtc_pc_e2e { - -class PeerConfigurerImpl final - : public PeerConnectionE2EQualityTestFixture::PeerConfigurer { - public: - using VideoSource = - absl::variant, - PeerConnectionE2EQualityTestFixture::CapturingDeviceIndex>; - - PeerConfigurerImpl(rtc::Thread* network_thread, - rtc::NetworkManager* network_manager, - rtc::PacketSocketFactory* packet_socket_factory) - : components_( - std::make_unique(network_thread, - network_manager, - packet_socket_factory)), - params_(std::make_unique()), - configurable_params_(std::make_unique()) {} - - PeerConfigurer* SetName(absl::string_view name) override { - params_->name = std::string(name); - return this; - } - - // Implementation of PeerConnectionE2EQualityTestFixture::PeerConfigurer. - PeerConfigurer* SetTaskQueueFactory( - std::unique_ptr task_queue_factory) override { - components_->pcf_dependencies->task_queue_factory = - std::move(task_queue_factory); - return this; - } - PeerConfigurer* SetCallFactory( - std::unique_ptr call_factory) override { - components_->pcf_dependencies->call_factory = std::move(call_factory); - return this; - } - PeerConfigurer* SetEventLogFactory( - std::unique_ptr event_log_factory) override { - components_->pcf_dependencies->event_log_factory = - std::move(event_log_factory); - return this; - } - PeerConfigurer* SetFecControllerFactory( - std::unique_ptr fec_controller_factory) - override { - components_->pcf_dependencies->fec_controller_factory = - std::move(fec_controller_factory); - return this; - } - PeerConfigurer* SetNetworkControllerFactory( - std::unique_ptr - network_controller_factory) override { - components_->pcf_dependencies->network_controller_factory = - std::move(network_controller_factory); - return this; - } - PeerConfigurer* SetVideoEncoderFactory( - std::unique_ptr video_encoder_factory) override { - components_->pcf_dependencies->video_encoder_factory = - std::move(video_encoder_factory); - return this; - } - PeerConfigurer* SetVideoDecoderFactory( - std::unique_ptr video_decoder_factory) override { - components_->pcf_dependencies->video_decoder_factory = - std::move(video_decoder_factory); - return this; - } - - PeerConfigurer* SetAsyncResolverFactory( - std::unique_ptr async_resolver_factory) - override { - components_->pc_dependencies->async_resolver_factory = - std::move(async_resolver_factory); - return this; - } - PeerConfigurer* SetRTCCertificateGenerator( - std::unique_ptr cert_generator) - override { - components_->pc_dependencies->cert_generator = std::move(cert_generator); - return this; - } - PeerConfigurer* SetSSLCertificateVerifier( - std::unique_ptr tls_cert_verifier) override { - components_->pc_dependencies->tls_cert_verifier = - std::move(tls_cert_verifier); - return this; - } - - PeerConfigurer* AddVideoConfig( - PeerConnectionE2EQualityTestFixture::VideoConfig config) override { - video_sources_.push_back( - CreateSquareFrameGenerator(config, /*type=*/absl::nullopt)); - configurable_params_->video_configs.push_back(std::move(config)); - return this; - } - PeerConfigurer* AddVideoConfig( - PeerConnectionE2EQualityTestFixture::VideoConfig config, - std::unique_ptr generator) override { - configurable_params_->video_configs.push_back(std::move(config)); - video_sources_.push_back(std::move(generator)); - return this; - } - PeerConfigurer* AddVideoConfig( - PeerConnectionE2EQualityTestFixture::VideoConfig config, - PeerConnectionE2EQualityTestFixture::CapturingDeviceIndex index) - override { - configurable_params_->video_configs.push_back(std::move(config)); - video_sources_.push_back(index); - return this; - } - PeerConfigurer* SetVideoSubscription( - PeerConnectionE2EQualityTestFixture::VideoSubscription subscription) - override { - configurable_params_->video_subscription = std::move(subscription); - return this; - } - PeerConfigurer* SetAudioConfig( - PeerConnectionE2EQualityTestFixture::AudioConfig config) override { - params_->audio_config = std::move(config); - return this; - } - PeerConfigurer* SetUseUlpFEC(bool value) override { - params_->use_ulp_fec = value; - return this; - } - PeerConfigurer* SetUseFlexFEC(bool value) override { - params_->use_flex_fec = value; - return this; - } - PeerConfigurer* SetVideoEncoderBitrateMultiplier(double multiplier) override { - params_->video_encoder_bitrate_multiplier = multiplier; - return this; - } - PeerConfigurer* SetNetEqFactory( - std::unique_ptr neteq_factory) override { - components_->pcf_dependencies->neteq_factory = std::move(neteq_factory); - return this; - } - PeerConfigurer* SetAudioProcessing( - rtc::scoped_refptr audio_processing) override { - components_->pcf_dependencies->audio_processing = audio_processing; - return this; - } - PeerConfigurer* SetAudioMixer( - rtc::scoped_refptr audio_mixer) override { - components_->pcf_dependencies->audio_mixer = audio_mixer; - return this; - } - - virtual PeerConfigurer* SetUseNetworkThreadAsWorkerThread() override { - components_->worker_thread = components_->network_thread; - return this; - } - - PeerConfigurer* SetRtcEventLogPath(std::string path) override { - params_->rtc_event_log_path = std::move(path); - return this; - } - PeerConfigurer* SetAecDumpPath(std::string path) override { - params_->aec_dump_path = std::move(path); - return this; - } - PeerConfigurer* SetRTCConfiguration( - PeerConnectionInterface::RTCConfiguration configuration) override { - params_->rtc_configuration = std::move(configuration); - return this; - } - PeerConfigurer* SetRTCOfferAnswerOptions( - PeerConnectionInterface::RTCOfferAnswerOptions options) override { - params_->rtc_offer_answer_options = std::move(options); - return this; - } - PeerConfigurer* SetBitrateSettings( - BitrateSettings bitrate_settings) override { - params_->bitrate_settings = bitrate_settings; - return this; - } - PeerConfigurer* SetVideoCodecs( - std::vector - video_codecs) override { - params_->video_codecs = std::move(video_codecs); - return this; - } - - PeerConfigurer* SetIceTransportFactory( - std::unique_ptr factory) override { - components_->pc_dependencies->ice_transport_factory = std::move(factory); - return this; - } - - PeerConfigurer* SetPortAllocatorExtraFlags(uint32_t extra_flags) override { - params_->port_allocator_extra_flags = extra_flags; - return this; - } - // Implementation of PeerConnectionE2EQualityTestFixture::PeerConfigurer end. - - InjectableComponents* components() { return components_.get(); } - Params* params() { return params_.get(); } - ConfigurableParams* configurable_params() { - return configurable_params_.get(); - } - const Params& params() const { return *params_; } - const ConfigurableParams& configurable_params() const { - return *configurable_params_; - } - std::vector* video_sources() { return &video_sources_; } - - // Returns InjectableComponents and transfer ownership to the caller. - // Can be called once. - std::unique_ptr ReleaseComponents() { - RTC_CHECK(components_); - auto components = std::move(components_); - components_ = nullptr; - return components; - } - - // Returns Params and transfer ownership to the caller. - // Can be called once. - std::unique_ptr ReleaseParams() { - RTC_CHECK(params_); - auto params = std::move(params_); - params_ = nullptr; - return params; - } - - // Returns ConfigurableParams and transfer ownership to the caller. - // Can be called once. - std::unique_ptr ReleaseConfigurableParams() { - RTC_CHECK(configurable_params_); - auto configurable_params = std::move(configurable_params_); - configurable_params_ = nullptr; - return configurable_params; - } - - // Returns video sources and transfer frame generators ownership to the - // caller. Can be called once. - std::vector ReleaseVideoSources() { - auto video_sources = std::move(video_sources_); - video_sources_.clear(); - return video_sources; - } - - private: - std::unique_ptr components_; - std::unique_ptr params_; - std::unique_ptr configurable_params_; - std::vector video_sources_; -}; - -class DefaultNamesProvider { - public: - // Caller have to ensure that default names array will outlive names provider - // instance. - explicit DefaultNamesProvider( - absl::string_view prefix, - rtc::ArrayView default_names = {}); - - void MaybeSetName(absl::optional& name); - - private: - std::string GenerateName(); - - std::string GenerateNameInternal(); - - const std::string prefix_; - const rtc::ArrayView default_names_; - - std::set known_names_; - size_t counter_ = 0; -}; - -class PeerParamsPreprocessor { - public: - PeerParamsPreprocessor(); - - // Set missing params to default values if it is required: - // * Generate video stream labels if some of them are missing - // * Generate audio stream labels if some of them are missing - // * Set video source generation mode if it is not specified - // * Video codecs under test - void SetDefaultValuesForMissingParams(PeerConfigurerImpl& peer); - - // Validate peer's parameters, also ensure uniqueness of all video stream - // labels. - void ValidateParams(const PeerConfigurerImpl& peer); - - private: - DefaultNamesProvider peer_names_provider_; - - std::set peer_names_; - std::set video_labels_; - std::set audio_labels_; - std::set video_sync_groups_; - std::set audio_sync_groups_; -}; - -} // namespace webrtc_pc_e2e -} // namespace webrtc +#include "api/test/pclf/peer_configurer.h" #endif // TEST_PC_E2E_PEER_CONFIGURER_H_ diff --git a/test/pc/e2e/peer_connection_quality_test.cc b/test/pc/e2e/peer_connection_quality_test.cc index 997ae8b8e6..dd685dbf5a 100644 --- a/test/pc/e2e/peer_connection_quality_test.cc +++ b/test/pc/e2e/peer_connection_quality_test.cc @@ -197,9 +197,8 @@ void PeerConnectionE2EQualityTest::AddQualityMetricsReporter( PeerConnectionE2EQualityTest::PeerHandle* PeerConnectionE2EQualityTest::AddPeer( const PeerNetworkDependencies& network_dependencies, rtc::FunctionView configurer) { - peer_configurations_.push_back(std::make_unique( - network_dependencies.network_thread, network_dependencies.network_manager, - network_dependencies.packet_socket_factory)); + peer_configurations_.push_back( + std::make_unique(network_dependencies)); configurer(peer_configurations_.back().get()); peer_handles_.push_back(PeerHandleImpl()); return &peer_handles_.back(); diff --git a/test/pc/e2e/peer_connection_quality_test.h b/test/pc/e2e/peer_connection_quality_test.h index ddada4b391..22c3bbe5da 100644 --- a/test/pc/e2e/peer_connection_quality_test.h +++ b/test/pc/e2e/peer_connection_quality_test.h @@ -19,6 +19,8 @@ #include "api/task_queue/task_queue_factory.h" #include "api/test/audio_quality_analyzer_interface.h" #include "api/test/metrics/metrics_logger.h" +#include "api/test/pclf/media_quality_test_params.h" +#include "api/test/pclf/peer_configurer.h" #include "api/test/peerconnection_quality_test_fixture.h" #include "api/test/time_controller.h" #include "api/units/time_delta.h" @@ -32,8 +34,6 @@ #include "test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.h" #include "test/pc/e2e/analyzer_helper.h" #include "test/pc/e2e/media/media_helper.h" -#include "test/pc/e2e/peer_configurer.h" -#include "test/pc/e2e/peer_connection_quality_test_params.h" #include "test/pc/e2e/sdp/sdp_changer.h" #include "test/pc/e2e/test_activities_executor.h" #include "test/pc/e2e/test_peer.h" diff --git a/test/pc/e2e/test_peer.h b/test/pc/e2e/test_peer.h index 02e5528a6c..57bfba165a 100644 --- a/test/pc/e2e/test_peer.h +++ b/test/pc/e2e/test_peer.h @@ -22,12 +22,12 @@ #include "api/set_remote_description_observer_interface.h" #include "api/task_queue/pending_task_safety_flag.h" #include "api/test/frame_generator_interface.h" +#include "api/test/pclf/media_quality_test_params.h" +#include "api/test/pclf/peer_configurer.h" #include "api/test/peerconnection_quality_test_fixture.h" #include "pc/peer_connection_wrapper.h" #include "rtc_base/logging.h" #include "rtc_base/synchronization/mutex.h" -#include "test/pc/e2e/peer_configurer.h" -#include "test/pc/e2e/peer_connection_quality_test_params.h" #include "test/pc/e2e/stats_provider.h" namespace webrtc { diff --git a/test/pc/e2e/test_peer_factory.cc b/test/pc/e2e/test_peer_factory.cc index aa9a731cba..72455f1d29 100644 --- a/test/pc/e2e/test_peer_factory.cc +++ b/test/pc/e2e/test_peer_factory.cc @@ -15,6 +15,7 @@ #include "absl/strings/string_view.h" #include "api/task_queue/default_task_queue_factory.h" #include "api/test/create_time_controller.h" +#include "api/test/pclf/peer_configurer.h" #include "api/test/time_controller.h" #include "api/transport/field_trial_based_config.h" #include "api/video_codecs/builtin_video_decoder_factory.h" @@ -26,7 +27,6 @@ #include "rtc_base/thread.h" #include "test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.h" #include "test/pc/e2e/echo/echo_emulation.h" -#include "test/pc/e2e/peer_configurer.h" #include "test/testsupport/copy_to_file_audio_capturer.h" namespace webrtc { diff --git a/test/pc/e2e/test_peer_factory.h b/test/pc/e2e/test_peer_factory.h index 8d78e2f8d9..e1abd0dff0 100644 --- a/test/pc/e2e/test_peer_factory.h +++ b/test/pc/e2e/test_peer_factory.h @@ -18,13 +18,13 @@ #include "absl/strings/string_view.h" #include "api/rtc_event_log/rtc_event_log_factory.h" +#include "api/test/pclf/media_quality_test_params.h" +#include "api/test/pclf/peer_configurer.h" #include "api/test/peerconnection_quality_test_fixture.h" #include "api/test/time_controller.h" #include "modules/audio_device/include/test_audio_device.h" #include "rtc_base/task_queue.h" #include "test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.h" -#include "test/pc/e2e/peer_configurer.h" -#include "test/pc/e2e/peer_connection_quality_test_params.h" #include "test/pc/e2e/test_peer.h" namespace webrtc {