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 <titovartem@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Jeremy Leconte <jleconte@google.com>
Cr-Commit-Position: refs/heads/main@{#38551}
This commit is contained in:
Jeremy Leconte
2022-11-04 08:32:18 +01:00
committed by WebRTC LUCI CQ
parent 1d490cb4bf
commit d16f290e41
13 changed files with 585 additions and 397 deletions

64
api/test/pclf/BUILD.gn Normal file
View File

@ -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" ]
}

13
api/test/pclf/DEPS Normal file
View File

@ -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",
],
}

View File

@ -0,0 +1,162 @@
/*
* 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_MEDIA_QUALITY_TEST_PARAMS_H_
#define API_TEST_PCLF_MEDIA_QUALITY_TEST_PARAMS_H_
#include <cstddef>
#include <memory>
#include <string>
#include <vector>
#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/field_trials_view.h"
#include "api/rtc_event_log/rtc_event_log_factory_interface.h"
#include "api/task_queue/task_queue_factory.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 "p2p/base/port_allocator.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 {
// Contains most part from PeerConnectionFactoryDependencies. Also all fields
// are optional and defaults will be provided by fixture implementation if
// any will be omitted.
//
// Separate class was introduced to clarify which components can be
// overridden. For example worker and signaling threads will be provided by
// fixture implementation. The same is applicable to the media engine. So user
// can override only some parts of media engine like video encoder/decoder
// factories.
struct PeerConnectionFactoryComponents {
std::unique_ptr<TaskQueueFactory> task_queue_factory;
std::unique_ptr<CallFactoryInterface> call_factory;
std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory;
std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory;
std::unique_ptr<NetworkControllerFactoryInterface> network_controller_factory;
std::unique_ptr<NetEqFactory> neteq_factory;
// Will be passed to MediaEngineInterface, that will be used in
// PeerConnectionFactory.
std::unique_ptr<VideoEncoderFactory> video_encoder_factory;
std::unique_ptr<VideoDecoderFactory> video_decoder_factory;
std::unique_ptr<FieldTrialsView> trials;
rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing;
rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer;
};
// Contains most parts from PeerConnectionDependencies. Also all fields are
// optional and defaults will be provided by fixture implementation if any
// will be omitted.
//
// Separate class was introduced to clarify which components can be
// overridden. For example observer, which is required to
// PeerConnectionDependencies, will be provided by fixture implementation,
// so client can't inject its own. Also only network manager can be overridden
// inside port allocator.
struct PeerConnectionComponents {
PeerConnectionComponents(rtc::NetworkManager* network_manager,
rtc::PacketSocketFactory* packet_socket_factory)
: network_manager(network_manager),
packet_socket_factory(packet_socket_factory) {
RTC_CHECK(network_manager);
}
rtc::NetworkManager* const network_manager;
rtc::PacketSocketFactory* const packet_socket_factory;
std::unique_ptr<webrtc::AsyncResolverFactory> async_resolver_factory;
std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier;
std::unique_ptr<IceTransportFactory> ice_transport_factory;
};
// Contains all components, that can be overridden in peer connection. Also
// has a network thread, that will be used to communicate with another peers.
struct InjectableComponents {
InjectableComponents(rtc::Thread* network_thread,
rtc::NetworkManager* network_manager,
rtc::PacketSocketFactory* packet_socket_factory)
: network_thread(network_thread),
worker_thread(nullptr),
pcf_dependencies(std::make_unique<PeerConnectionFactoryComponents>()),
pc_dependencies(
std::make_unique<PeerConnectionComponents>(network_manager,
packet_socket_factory)) {
RTC_CHECK(network_thread);
}
rtc::Thread* const network_thread;
rtc::Thread* worker_thread;
std::unique_ptr<PeerConnectionFactoryComponents> pcf_dependencies;
std::unique_ptr<PeerConnectionComponents> pc_dependencies;
};
// Contains information about call media streams (up to 1 audio stream and
// unlimited amount of video streams) and rtc configuration, that will be used
// to set up peer connection.
struct Params {
// Peer name. If empty - default one will be set by the fixture.
absl::optional<std::string> name;
// If `audio_config` is set audio stream will be configured
absl::optional<PeerConnectionE2EQualityTestFixture::AudioConfig> audio_config;
// Flags to set on `cricket::PortAllocator`. These flags will be added
// to the default ones that are presented on the port allocator.
uint32_t port_allocator_extra_flags = cricket::kDefaultPortAllocatorFlags;
// If `rtc_event_log_path` is set, an RTCEventLog will be saved in that
// location and it will be available for further analysis.
absl::optional<std::string> rtc_event_log_path;
// If `aec_dump_path` is set, an AEC dump will be saved in that location and
// it will be available for further analysis.
absl::optional<std::string> aec_dump_path;
bool use_ulp_fec = false;
bool use_flex_fec = false;
// Specifies how much video encoder target bitrate should be different than
// target bitrate, provided by WebRTC stack. Must be greater then 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(...).
double video_encoder_bitrate_multiplier = 1.0;
PeerConnectionInterface::RTCConfiguration rtc_configuration;
PeerConnectionInterface::RTCOfferAnswerOptions rtc_offer_answer_options;
BitrateSettings bitrate_settings;
std::vector<PeerConnectionE2EQualityTestFixture::VideoCodecConfig>
video_codecs;
};
// Contains parameters that maybe changed by test writer during the test call.
struct ConfigurableParams {
// If `video_configs` is empty - no video should be added to the test call.
std::vector<PeerConnectionE2EQualityTestFixture::VideoConfig> video_configs;
PeerConnectionE2EQualityTestFixture::VideoSubscription video_subscription =
PeerConnectionE2EQualityTestFixture::VideoSubscription()
.SubscribeToAllPeers();
};
} // namespace webrtc_pc_e2e
} // namespace webrtc
#endif // API_TEST_PCLF_MEDIA_QUALITY_TEST_PARAMS_H_

View File

@ -0,0 +1,423 @@
/*
* 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.
*/
#include "api/test/pclf/peer_configurer.h"
#include <set>
#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"
#include "test/testsupport/file_utils.h"
namespace webrtc {
namespace webrtc_pc_e2e {
namespace {
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
constexpr absl::string_view kDefaultNames[] = {"alice", "bob", "charlie",
"david", "erin", "frank"};
} // namespace
PeerConfigurerImpl::PeerConfigurerImpl(
const PeerNetworkDependencies& network_dependencies)
: components_(std::make_unique<InjectableComponents>(
network_dependencies.network_thread,
network_dependencies.network_manager,
network_dependencies.packet_socket_factory)),
params_(std::make_unique<Params>()),
configurable_params_(std::make_unique<ConfigurableParams>()) {}
PeerConfigurer* PeerConfigurerImpl::SetName(absl::string_view name) {
params_->name = std::string(name);
return this;
}
PeerConfigurer* PeerConfigurerImpl::SetTaskQueueFactory(
std::unique_ptr<TaskQueueFactory> task_queue_factory) {
components_->pcf_dependencies->task_queue_factory =
std::move(task_queue_factory);
return this;
}
PeerConfigurer* PeerConfigurerImpl::SetCallFactory(
std::unique_ptr<CallFactoryInterface> call_factory) {
components_->pcf_dependencies->call_factory = std::move(call_factory);
return this;
}
PeerConfigurer* PeerConfigurerImpl::SetEventLogFactory(
std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) {
components_->pcf_dependencies->event_log_factory =
std::move(event_log_factory);
return this;
}
PeerConfigurer* PeerConfigurerImpl::SetFecControllerFactory(
std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory) {
components_->pcf_dependencies->fec_controller_factory =
std::move(fec_controller_factory);
return this;
}
PeerConfigurer* PeerConfigurerImpl::SetNetworkControllerFactory(
std::unique_ptr<NetworkControllerFactoryInterface>
network_controller_factory) {
components_->pcf_dependencies->network_controller_factory =
std::move(network_controller_factory);
return this;
}
PeerConfigurer* PeerConfigurerImpl::SetVideoEncoderFactory(
std::unique_ptr<VideoEncoderFactory> video_encoder_factory) {
components_->pcf_dependencies->video_encoder_factory =
std::move(video_encoder_factory);
return this;
}
PeerConfigurer* PeerConfigurerImpl::SetVideoDecoderFactory(
std::unique_ptr<VideoDecoderFactory> video_decoder_factory) {
components_->pcf_dependencies->video_decoder_factory =
std::move(video_decoder_factory);
return this;
}
PeerConfigurer* PeerConfigurerImpl::SetAsyncResolverFactory(
std::unique_ptr<webrtc::AsyncResolverFactory> async_resolver_factory) {
components_->pc_dependencies->async_resolver_factory =
std::move(async_resolver_factory);
return this;
}
PeerConfigurer* PeerConfigurerImpl::SetRTCCertificateGenerator(
std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
components_->pc_dependencies->cert_generator = std::move(cert_generator);
return this;
}
PeerConfigurer* PeerConfigurerImpl::SetSSLCertificateVerifier(
std::unique_ptr<rtc::SSLCertificateVerifier> 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<test::FrameGeneratorInterface> 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<NetEqFactory> neteq_factory) {
components_->pcf_dependencies->neteq_factory = std::move(neteq_factory);
return this;
}
PeerConfigurer* PeerConfigurerImpl::SetAudioProcessing(
rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing) {
components_->pcf_dependencies->audio_processing = audio_processing;
return this;
}
PeerConfigurer* PeerConfigurerImpl::SetAudioMixer(
rtc::scoped_refptr<webrtc::AudioMixer> 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<PeerConnectionE2EQualityTestFixture::VideoCodecConfig>
video_codecs) {
params_->video_codecs = std::move(video_codecs);
return this;
}
PeerConfigurer* PeerConfigurerImpl::SetIceTransportFactory(
std::unique_ptr<IceTransportFactory> 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<InjectableComponents> 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<Params> 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<ConfigurableParams>
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::VideoSource>
PeerConfigurerImpl::ReleaseVideoSources() {
auto video_sources = std::move(video_sources_);
video_sources_.clear();
return video_sources;
}
DefaultNamesProvider::DefaultNamesProvider(
absl::string_view prefix,
rtc::ArrayView<const absl::string_view> default_names)
: prefix_(prefix), default_names_(default_names) {}
void DefaultNamesProvider::MaybeSetName(absl::optional<std::string>& name) {
if (name.has_value()) {
known_names_.insert(name.value());
} else {
name = GenerateName();
}
}
std::string DefaultNamesProvider::GenerateName() {
std::string name;
do {
name = GenerateNameInternal();
} while (!known_names_.insert(name).second);
return name;
}
std::string DefaultNamesProvider::GenerateNameInternal() {
if (counter_ < default_names_.size()) {
return std::string(default_names_[counter_++]);
}
return prefix_ + std::to_string(counter_++);
}
PeerParamsPreprocessor::PeerParamsPreprocessor()
: peer_names_provider_("peer_", kDefaultNames) {}
void PeerParamsPreprocessor::SetDefaultValuesForMissingParams(
PeerConfigurerImpl& peer) {
Params* params = peer.params();
ConfigurableParams* configurable_params = peer.configurable_params();
peer_names_provider_.MaybeSetName(params->name);
DefaultNamesProvider video_stream_names_provider(*params->name +
"_auto_video_stream_label_");
for (VideoConfig& config : configurable_params->video_configs) {
video_stream_names_provider.MaybeSetName(config.stream_label);
}
if (params->audio_config) {
DefaultNamesProvider audio_stream_names_provider(
*params->name + "_auto_audio_stream_label_");
audio_stream_names_provider.MaybeSetName(
params->audio_config->stream_label);
}
if (params->video_codecs.empty()) {
params->video_codecs.push_back(
PeerConnectionE2EQualityTestFixture::VideoCodecConfig(
cricket::kVp8CodecName));
}
}
void PeerParamsPreprocessor::ValidateParams(const PeerConfigurerImpl& peer) {
const Params& p = peer.params();
RTC_CHECK_GT(p.video_encoder_bitrate_multiplier, 0.0);
// Each peer should at least support 1 video codec.
RTC_CHECK_GE(p.video_codecs.size(), 1);
{
RTC_CHECK(p.name);
bool inserted = peer_names_.insert(p.name.value()).second;
RTC_CHECK(inserted) << "Duplicate name=" << p.name.value();
}
// Validate that all video stream labels are unique and sync groups are
// valid.
for (const VideoConfig& video_config :
peer.configurable_params().video_configs) {
RTC_CHECK(video_config.stream_label);
bool inserted =
video_labels_.insert(video_config.stream_label.value()).second;
RTC_CHECK(inserted) << "Duplicate video_config.stream_label="
<< video_config.stream_label.value();
// TODO(bugs.webrtc.org/4762): remove this check after synchronization of
// more than two streams is supported.
if (video_config.sync_group.has_value()) {
bool sync_group_inserted =
video_sync_groups_.insert(video_config.sync_group.value()).second;
RTC_CHECK(sync_group_inserted)
<< "Sync group shouldn't consist of more than two streams (one "
"video and one audio). Duplicate video_config.sync_group="
<< video_config.sync_group.value();
}
if (video_config.simulcast_config) {
if (!video_config.encoding_params.empty()) {
RTC_CHECK_EQ(video_config.simulcast_config->simulcast_streams_count,
video_config.encoding_params.size())
<< "|encoding_params| have to be specified for each simulcast "
<< "stream in |video_config|.";
}
} else {
RTC_CHECK_LE(video_config.encoding_params.size(), 1)
<< "|encoding_params| has multiple values but simulcast is not "
"enabled.";
}
if (video_config.emulated_sfu_config) {
if (video_config.simulcast_config &&
video_config.emulated_sfu_config->target_layer_index) {
RTC_CHECK_LT(*video_config.emulated_sfu_config->target_layer_index,
video_config.simulcast_config->simulcast_streams_count);
}
if (!video_config.encoding_params.empty()) {
bool is_svc = false;
for (const auto& encoding_param : video_config.encoding_params) {
if (!encoding_param.scalability_mode)
continue;
absl::optional<ScalabilityMode> scalability_mode =
ScalabilityModeFromString(*encoding_param.scalability_mode);
RTC_CHECK(scalability_mode) << "Unknown scalability_mode requested";
absl::optional<ScalableVideoController::StreamLayersConfig>
stream_layers_config =
ScalabilityStructureConfig(*scalability_mode);
is_svc |= stream_layers_config->num_spatial_layers > 1;
RTC_CHECK(stream_layers_config->num_spatial_layers == 1 ||
video_config.encoding_params.size() == 1)
<< "Can't enable SVC modes with multiple spatial layers ("
<< stream_layers_config->num_spatial_layers
<< " layers) or simulcast ("
<< video_config.encoding_params.size() << " layers)";
if (video_config.emulated_sfu_config->target_layer_index) {
RTC_CHECK_LT(*video_config.emulated_sfu_config->target_layer_index,
stream_layers_config->num_spatial_layers);
}
}
if (!is_svc && video_config.emulated_sfu_config->target_layer_index) {
RTC_CHECK_LT(*video_config.emulated_sfu_config->target_layer_index,
video_config.encoding_params.size());
}
}
}
}
if (p.audio_config) {
bool inserted =
audio_labels_.insert(p.audio_config->stream_label.value()).second;
RTC_CHECK(inserted) << "Duplicate audio_config.stream_label="
<< p.audio_config->stream_label.value();
// TODO(bugs.webrtc.org/4762): remove this check after synchronization of
// more than two streams is supported.
if (p.audio_config->sync_group.has_value()) {
bool sync_group_inserted =
audio_sync_groups_.insert(p.audio_config->sync_group.value()).second;
RTC_CHECK(sync_group_inserted)
<< "Sync group shouldn't consist of more than two streams (one "
"video and one audio). Duplicate audio_config.sync_group="
<< p.audio_config->sync_group.value();
}
// Check that if mode input file name specified only if mode is kFile.
if (p.audio_config.value().mode == AudioConfig::Mode::kGenerated) {
RTC_CHECK(!p.audio_config.value().input_file_name);
}
if (p.audio_config.value().mode == AudioConfig::Mode::kFile) {
RTC_CHECK(p.audio_config.value().input_file_name);
RTC_CHECK(
test::FileExists(p.audio_config.value().input_file_name.value()))
<< p.audio_config.value().input_file_name.value() << " doesn't exist";
}
}
}
} // namespace webrtc_pc_e2e
} // namespace webrtc

View File

@ -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 <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
#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<std::unique_ptr<test::FrameGeneratorInterface>,
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<InjectableComponents>(network_thread,
network_manager,
packet_socket_factory)),
params_(std::make_unique<Params>()),
configurable_params_(std::make_unique<ConfigurableParams>()) {}
// 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<TaskQueueFactory> task_queue_factory) override;
PeerConfigurer* SetCallFactory(
std::unique_ptr<CallFactoryInterface> call_factory) override;
PeerConfigurer* SetEventLogFactory(
std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) override;
PeerConfigurer* SetFecControllerFactory(
std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory)
override;
PeerConfigurer* SetNetworkControllerFactory(
std::unique_ptr<NetworkControllerFactoryInterface>
network_controller_factory) override;
PeerConfigurer* SetVideoEncoderFactory(
std::unique_ptr<VideoEncoderFactory> video_encoder_factory) override;
PeerConfigurer* SetVideoDecoderFactory(
std::unique_ptr<VideoDecoderFactory> video_decoder_factory) override;
// Set a custom NetEqFactory to be used in the call.
PeerConfigurer* SetNetEqFactory(
std::unique_ptr<NetEqFactory> neteq_factory) override;
PeerConfigurer* SetAudioProcessing(
rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing) override;
PeerConfigurer* SetAudioMixer(
rtc::scoped_refptr<webrtc::AudioMixer> 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<webrtc::AsyncResolverFactory> async_resolver_factory)
override;
PeerConfigurer* SetRTCCertificateGenerator(
std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator)
override;
PeerConfigurer* SetSSLCertificateVerifier(
std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier) override;
PeerConfigurer* SetIceTransportFactory(
std::unique_ptr<IceTransportFactory> 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<test::FrameGeneratorInterface> 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<PeerConnectionE2EQualityTestFixture::VideoCodecConfig>
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<InjectableComponents> ReleaseComponents();
// Returns Params and transfer ownership to the caller.
// Can be called once.
std::unique_ptr<Params> ReleaseParams();
// Returns ConfigurableParams and transfer ownership to the caller.
// Can be called once.
std::unique_ptr<ConfigurableParams> ReleaseConfigurableParams();
// Returns video sources and transfer frame generators ownership to the
// caller. Can be called once.
std::vector<VideoSource> 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<VideoSource>* video_sources() { return &video_sources_; }
private:
std::unique_ptr<InjectableComponents> components_;
std::unique_ptr<Params> params_;
std::unique_ptr<ConfigurableParams> configurable_params_;
std::vector<VideoSource> 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<const absl::string_view> default_names = {});
void MaybeSetName(absl::optional<std::string>& name);
private:
std::string GenerateName();
std::string GenerateNameInternal();
const std::string prefix_;
const rtc::ArrayView<const absl::string_view> default_names_;
std::set<std::string> 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<std::string> peer_names_;
std::set<std::string> video_labels_;
std::set<std::string> audio_labels_;
std::set<std::string> video_sync_groups_;
std::set<std::string> audio_sync_groups_;
};
} // namespace webrtc_pc_e2e
} // namespace webrtc
#endif // API_TEST_PCLF_PEER_CONFIGURER_H_