summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/api/test/pclf
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/libwebrtc/api/test/pclf')
-rw-r--r--third_party/libwebrtc/api/test/pclf/BUILD.gn114
-rw-r--r--third_party/libwebrtc/api/test/pclf/DEPS13
-rw-r--r--third_party/libwebrtc/api/test/pclf/media_configuration.cc314
-rw-r--r--third_party/libwebrtc/api/test/pclf/media_configuration.h484
-rw-r--r--third_party/libwebrtc/api/test/pclf/media_quality_test_params.h189
-rw-r--r--third_party/libwebrtc/api/test/pclf/peer_configurer.cc245
-rw-r--r--third_party/libwebrtc/api/test/pclf/peer_configurer.h200
7 files changed, 1559 insertions, 0 deletions
diff --git a/third_party/libwebrtc/api/test/pclf/BUILD.gn b/third_party/libwebrtc/api/test/pclf/BUILD.gn
new file mode 100644
index 0000000000..0526478e8b
--- /dev/null
+++ b/third_party/libwebrtc/api/test/pclf/BUILD.gn
@@ -0,0 +1,114 @@
+# 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_source_set("media_configuration") {
+ visibility = [ "*" ]
+ testonly = true
+ sources = [
+ "media_configuration.cc",
+ "media_configuration.h",
+ ]
+
+ deps = [
+ "../..:array_view",
+ "../..:audio_options_api",
+ "../..:audio_quality_analyzer_api",
+ "../..:callfactory_api",
+ "../..:fec_controller_api",
+ "../..:frame_generator_api",
+ "../..:function_view",
+ "../..:libjingle_peerconnection_api",
+ "../..:media_stream_interface",
+ "../..:packet_socket_factory",
+ "../..:peer_network_dependencies",
+ "../..:rtp_parameters",
+ "../..:simulated_network_api",
+ "../..:stats_observer_interface",
+ "../..:track_id_stream_info_map",
+ "../..:video_quality_analyzer_api",
+ "../../../modules/audio_processing:api",
+ "../../../rtc_base:checks",
+ "../../../rtc_base:network",
+ "../../../rtc_base:rtc_certificate_generator",
+ "../../../rtc_base:ssl",
+ "../../../rtc_base:stringutils",
+ "../../../rtc_base:threading",
+ "../../../test:fileutils",
+ "../../../test:video_test_support",
+ "../../../test/pc/e2e/analyzer/video:video_dumping",
+ "../../audio:audio_mixer_api",
+ "../../rtc_event_log",
+ "../../task_queue",
+ "../../transport:network_control",
+ "../../units:time_delta",
+ "../../video_codecs:video_codecs_api",
+ "../video:video_frame_writer",
+ ]
+ absl_deps = [
+ "//third_party/abseil-cpp/absl/memory",
+ "//third_party/abseil-cpp/absl/strings",
+ "//third_party/abseil-cpp/absl/types:optional",
+ ]
+}
+
+rtc_library("media_quality_test_params") {
+ visibility = [ "*" ]
+ testonly = true
+ sources = [ "media_quality_test_params.h" ]
+
+ deps = [
+ ":media_configuration",
+ "../../../api:callfactory_api",
+ "../../../api:fec_controller_api",
+ "../../../api:field_trials_view",
+ "../../../api:libjingle_peerconnection_api",
+ "../../../api:packet_socket_factory",
+ "../../../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:network",
+ "../../../rtc_base:rtc_certificate_generator",
+ "../../../rtc_base:ssl",
+ "../../../rtc_base:threading",
+ ]
+}
+
+rtc_library("peer_configurer") {
+ visibility = [ "*" ]
+ testonly = true
+ sources = [
+ "peer_configurer.cc",
+ "peer_configurer.h",
+ ]
+ deps = [
+ ":media_configuration",
+ ":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_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",
+ "../../../rtc_base:network",
+ "../../../rtc_base:rtc_certificate_generator",
+ "../../../rtc_base:ssl",
+ "../../../rtc_base:threading",
+ ]
+ absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
+}
diff --git a/third_party/libwebrtc/api/test/pclf/DEPS b/third_party/libwebrtc/api/test/pclf/DEPS
new file mode 100644
index 0000000000..60cc0aeeb3
--- /dev/null
+++ b/third_party/libwebrtc/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/third_party/libwebrtc/api/test/pclf/media_configuration.cc b/third_party/libwebrtc/api/test/pclf/media_configuration.cc
new file mode 100644
index 0000000000..56b9e52e01
--- /dev/null
+++ b/third_party/libwebrtc/api/test/pclf/media_configuration.cc
@@ -0,0 +1,314 @@
+/*
+ * Copyright 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/media_configuration.h"
+
+#include <string>
+#include <utility>
+
+#include "absl/strings/string_view.h"
+#include "absl/types/optional.h"
+#include "api/array_view.h"
+#include "api/test/video/video_frame_writer.h"
+#include "rtc_base/checks.h"
+#include "rtc_base/strings/string_builder.h"
+#include "test/pc/e2e/analyzer/video/video_dumping.h"
+#include "test/testsupport/file_utils.h"
+#include "test/testsupport/video_frame_writer.h"
+
+namespace webrtc {
+namespace webrtc_pc_e2e {
+namespace {
+
+std::string SpecToString(VideoResolution::Spec spec) {
+ switch (spec) {
+ case VideoResolution::Spec::kNone:
+ return "None";
+ case VideoResolution::Spec::kMaxFromSender:
+ return "MaxFromSender";
+ }
+}
+
+void AppendResolution(const VideoResolution& resolution,
+ rtc::StringBuilder& builder) {
+ builder << "_" << resolution.width() << "x" << resolution.height() << "_"
+ << resolution.fps();
+}
+
+} // namespace
+
+ScreenShareConfig::ScreenShareConfig(TimeDelta slide_change_interval)
+ : slide_change_interval(slide_change_interval) {
+ RTC_CHECK_GT(slide_change_interval.ms(), 0);
+}
+VideoSimulcastConfig::VideoSimulcastConfig(int simulcast_streams_count)
+ : simulcast_streams_count(simulcast_streams_count) {
+ RTC_CHECK_GT(simulcast_streams_count, 1);
+}
+EmulatedSFUConfig::EmulatedSFUConfig(int target_layer_index)
+ : target_layer_index(target_layer_index) {
+ RTC_CHECK_GE(target_layer_index, 0);
+}
+
+EmulatedSFUConfig::EmulatedSFUConfig(absl::optional<int> target_layer_index,
+ absl::optional<int> target_temporal_index)
+ : target_layer_index(target_layer_index),
+ target_temporal_index(target_temporal_index) {
+ RTC_CHECK_GE(target_temporal_index.value_or(0), 0);
+ if (target_temporal_index)
+ RTC_CHECK_GE(*target_temporal_index, 0);
+}
+
+VideoResolution::VideoResolution(size_t width, size_t height, int32_t fps)
+ : width_(width), height_(height), fps_(fps), spec_(Spec::kNone) {}
+VideoResolution::VideoResolution(Spec spec)
+ : width_(0), height_(0), fps_(0), spec_(spec) {}
+
+bool VideoResolution::operator==(const VideoResolution& other) const {
+ if (spec_ != Spec::kNone && spec_ == other.spec_) {
+ // If there is some particular spec set, then it doesn't matter what
+ // values we have in other fields.
+ return true;
+ }
+ return width_ == other.width_ && height_ == other.height_ &&
+ fps_ == other.fps_ && spec_ == other.spec_;
+}
+bool VideoResolution::operator!=(const VideoResolution& other) const {
+ return !(*this == other);
+}
+
+bool VideoResolution::IsRegular() const {
+ return spec_ == Spec::kNone;
+}
+std::string VideoResolution::ToString() const {
+ rtc::StringBuilder out;
+ out << "{ width=" << width_ << ", height=" << height_ << ", fps=" << fps_
+ << ", spec=" << SpecToString(spec_) << " }";
+ return out.Release();
+}
+
+VideoDumpOptions::VideoDumpOptions(
+ absl::string_view output_directory,
+ int sampling_modulo,
+ bool export_frame_ids,
+ std::function<std::unique_ptr<test::VideoFrameWriter>(
+ absl::string_view file_name_prefix,
+ const VideoResolution& resolution)> video_frame_writer_factory)
+ : output_directory_(output_directory),
+ sampling_modulo_(sampling_modulo),
+ export_frame_ids_(export_frame_ids),
+ video_frame_writer_factory_(video_frame_writer_factory) {
+ RTC_CHECK_GT(sampling_modulo, 0);
+}
+
+VideoDumpOptions::VideoDumpOptions(absl::string_view output_directory,
+ bool export_frame_ids)
+ : VideoDumpOptions(output_directory,
+ kDefaultSamplingModulo,
+ export_frame_ids) {}
+
+std::unique_ptr<test::VideoFrameWriter>
+VideoDumpOptions::CreateInputDumpVideoFrameWriter(
+ absl::string_view stream_label,
+ const VideoResolution& resolution) const {
+ std::unique_ptr<test::VideoFrameWriter> writer = video_frame_writer_factory_(
+ GetInputDumpFileName(stream_label, resolution), resolution);
+ absl::optional<std::string> frame_ids_file =
+ GetInputFrameIdsDumpFileName(stream_label, resolution);
+ if (frame_ids_file.has_value()) {
+ writer = CreateVideoFrameWithIdsWriter(std::move(writer), *frame_ids_file);
+ }
+ return writer;
+}
+
+std::unique_ptr<test::VideoFrameWriter>
+VideoDumpOptions::CreateOutputDumpVideoFrameWriter(
+ absl::string_view stream_label,
+ absl::string_view receiver,
+ const VideoResolution& resolution) const {
+ std::unique_ptr<test::VideoFrameWriter> writer = video_frame_writer_factory_(
+ GetOutputDumpFileName(stream_label, receiver, resolution), resolution);
+ absl::optional<std::string> frame_ids_file =
+ GetOutputFrameIdsDumpFileName(stream_label, receiver, resolution);
+ if (frame_ids_file.has_value()) {
+ writer = CreateVideoFrameWithIdsWriter(std::move(writer), *frame_ids_file);
+ }
+ return writer;
+}
+
+std::unique_ptr<test::VideoFrameWriter>
+VideoDumpOptions::Y4mVideoFrameWriterFactory(
+ absl::string_view file_name_prefix,
+ const VideoResolution& resolution) {
+ return std::make_unique<test::Y4mVideoFrameWriterImpl>(
+ std::string(file_name_prefix) + ".y4m", resolution.width(),
+ resolution.height(), resolution.fps());
+}
+
+std::string VideoDumpOptions::GetInputDumpFileName(
+ absl::string_view stream_label,
+ const VideoResolution& resolution) const {
+ rtc::StringBuilder file_name;
+ file_name << stream_label;
+ AppendResolution(resolution, file_name);
+ return test::JoinFilename(output_directory_, file_name.Release());
+}
+
+absl::optional<std::string> VideoDumpOptions::GetInputFrameIdsDumpFileName(
+ absl::string_view stream_label,
+ const VideoResolution& resolution) const {
+ if (!export_frame_ids_) {
+ return absl::nullopt;
+ }
+ return GetInputDumpFileName(stream_label, resolution) + ".frame_ids.txt";
+}
+
+std::string VideoDumpOptions::GetOutputDumpFileName(
+ absl::string_view stream_label,
+ absl::string_view receiver,
+ const VideoResolution& resolution) const {
+ rtc::StringBuilder file_name;
+ file_name << stream_label << "_" << receiver;
+ AppendResolution(resolution, file_name);
+ return test::JoinFilename(output_directory_, file_name.Release());
+}
+
+absl::optional<std::string> VideoDumpOptions::GetOutputFrameIdsDumpFileName(
+ absl::string_view stream_label,
+ absl::string_view receiver,
+ const VideoResolution& resolution) const {
+ if (!export_frame_ids_) {
+ return absl::nullopt;
+ }
+ return GetOutputDumpFileName(stream_label, receiver, resolution) +
+ ".frame_ids.txt";
+}
+
+std::string VideoDumpOptions::ToString() const {
+ rtc::StringBuilder out;
+ out << "{ output_directory_=" << output_directory_
+ << ", sampling_modulo_=" << sampling_modulo_
+ << ", export_frame_ids_=" << export_frame_ids_ << " }";
+ return out.Release();
+}
+
+VideoConfig::VideoConfig(const VideoResolution& resolution)
+ : width(resolution.width()),
+ height(resolution.height()),
+ fps(resolution.fps()) {
+ RTC_CHECK(resolution.IsRegular());
+}
+VideoConfig::VideoConfig(size_t width, size_t height, int32_t fps)
+ : width(width), height(height), fps(fps) {}
+VideoConfig::VideoConfig(std::string stream_label,
+ size_t width,
+ size_t height,
+ int32_t fps)
+ : width(width),
+ height(height),
+ fps(fps),
+ stream_label(std::move(stream_label)) {}
+
+AudioConfig::AudioConfig(std::string stream_label)
+ : stream_label(std::move(stream_label)) {}
+
+VideoCodecConfig::VideoCodecConfig(std::string name)
+ : name(std::move(name)), required_params() {}
+VideoCodecConfig::VideoCodecConfig(
+ std::string name,
+ std::map<std::string, std::string> required_params)
+ : name(std::move(name)), required_params(std::move(required_params)) {}
+
+absl::optional<VideoResolution> VideoSubscription::GetMaxResolution(
+ rtc::ArrayView<const VideoConfig> video_configs) {
+ std::vector<VideoResolution> resolutions;
+ for (const auto& video_config : video_configs) {
+ resolutions.push_back(video_config.GetResolution());
+ }
+ return GetMaxResolution(resolutions);
+}
+
+absl::optional<VideoResolution> VideoSubscription::GetMaxResolution(
+ rtc::ArrayView<const VideoResolution> resolutions) {
+ if (resolutions.empty()) {
+ return absl::nullopt;
+ }
+
+ VideoResolution max_resolution;
+ for (const VideoResolution& resolution : resolutions) {
+ if (max_resolution.width() < resolution.width()) {
+ max_resolution.set_width(resolution.width());
+ }
+ if (max_resolution.height() < resolution.height()) {
+ max_resolution.set_height(resolution.height());
+ }
+ if (max_resolution.fps() < resolution.fps()) {
+ max_resolution.set_fps(resolution.fps());
+ }
+ }
+ return max_resolution;
+}
+
+bool VideoSubscription::operator==(const VideoSubscription& other) const {
+ return default_resolution_ == other.default_resolution_ &&
+ peers_resolution_ == other.peers_resolution_;
+}
+bool VideoSubscription::operator!=(const VideoSubscription& other) const {
+ return !(*this == other);
+}
+
+VideoSubscription& VideoSubscription::SubscribeToPeer(
+ absl::string_view peer_name,
+ VideoResolution resolution) {
+ peers_resolution_[std::string(peer_name)] = resolution;
+ return *this;
+}
+
+VideoSubscription& VideoSubscription::SubscribeToAllPeers(
+ VideoResolution resolution) {
+ default_resolution_ = resolution;
+ return *this;
+}
+
+absl::optional<VideoResolution> VideoSubscription::GetResolutionForPeer(
+ absl::string_view peer_name) const {
+ auto it = peers_resolution_.find(std::string(peer_name));
+ if (it == peers_resolution_.end()) {
+ return default_resolution_;
+ }
+ return it->second;
+}
+
+std::vector<std::string> VideoSubscription::GetSubscribedPeers() const {
+ std::vector<std::string> subscribed_streams;
+ subscribed_streams.reserve(peers_resolution_.size());
+ for (const auto& entry : peers_resolution_) {
+ subscribed_streams.push_back(entry.first);
+ }
+ return subscribed_streams;
+}
+
+std::string VideoSubscription::ToString() const {
+ rtc::StringBuilder out;
+ out << "{ default_resolution_=[";
+ if (default_resolution_.has_value()) {
+ out << default_resolution_->ToString();
+ } else {
+ out << "undefined";
+ }
+ out << "], {";
+ for (const auto& [peer_name, resolution] : peers_resolution_) {
+ out << "[" << peer_name << ": " << resolution.ToString() << "], ";
+ }
+ out << "} }";
+ return out.Release();
+}
+} // namespace webrtc_pc_e2e
+} // namespace webrtc
diff --git a/third_party/libwebrtc/api/test/pclf/media_configuration.h b/third_party/libwebrtc/api/test/pclf/media_configuration.h
new file mode 100644
index 0000000000..8e841a265b
--- /dev/null
+++ b/third_party/libwebrtc/api/test/pclf/media_configuration.h
@@ -0,0 +1,484 @@
+/*
+ * 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_CONFIGURATION_H_
+#define API_TEST_PCLF_MEDIA_CONFIGURATION_H_
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <functional>
+#include <map>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "absl/memory/memory.h"
+#include "absl/strings/string_view.h"
+#include "absl/types/optional.h"
+#include "api/array_view.h"
+#include "api/async_resolver_factory.h"
+#include "api/audio/audio_mixer.h"
+#include "api/audio_options.h"
+#include "api/call/call_factory_interface.h"
+#include "api/fec_controller.h"
+#include "api/function_view.h"
+#include "api/media_stream_interface.h"
+#include "api/peer_connection_interface.h"
+#include "api/rtc_event_log/rtc_event_log_factory_interface.h"
+#include "api/rtp_parameters.h"
+#include "api/task_queue/task_queue_factory.h"
+#include "api/test/audio_quality_analyzer_interface.h"
+#include "api/test/frame_generator_interface.h"
+#include "api/test/peer_network_dependencies.h"
+#include "api/test/simulated_network.h"
+#include "api/test/stats_observer_interface.h"
+#include "api/test/track_id_stream_info_map.h"
+#include "api/test/video/video_frame_writer.h"
+#include "api/test/video_quality_analyzer_interface.h"
+#include "api/transport/network_control.h"
+#include "api/units/time_delta.h"
+#include "api/video_codecs/video_decoder_factory.h"
+#include "api/video_codecs/video_encoder.h"
+#include "api/video_codecs/video_encoder_factory.h"
+#include "modules/audio_processing/include/audio_processing.h"
+#include "rtc_base/checks.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 {
+
+constexpr size_t kDefaultSlidesWidth = 1850;
+constexpr size_t kDefaultSlidesHeight = 1110;
+
+// The index of required capturing device in OS provided list of video
+// devices. On Linux and Windows the list will be obtained via
+// webrtc::VideoCaptureModule::DeviceInfo, on Mac OS via
+// [RTCCameraVideoCapturer captureDevices].
+enum class CapturingDeviceIndex : size_t {};
+
+// Contains parameters for screen share scrolling.
+//
+// If scrolling is enabled, then it will be done by putting sliding window
+// on source video and moving this window from top left corner to the
+// bottom right corner of the picture.
+//
+// In such case source dimensions must be greater or equal to the sliding
+// window dimensions. So `source_width` and `source_height` are the dimensions
+// of the source frame, while `VideoConfig::width` and `VideoConfig::height`
+// are the dimensions of the sliding window.
+//
+// Because `source_width` and `source_height` are dimensions of the source
+// frame, they have to be width and height of videos from
+// `ScreenShareConfig::slides_yuv_file_names`.
+//
+// Because scrolling have to be done on single slide it also requires, that
+// `duration` must be less or equal to
+// `ScreenShareConfig::slide_change_interval`.
+struct ScrollingParams {
+ // Duration of scrolling.
+ TimeDelta duration;
+ // Width of source slides video.
+ size_t source_width = kDefaultSlidesWidth;
+ // Height of source slides video.
+ size_t source_height = kDefaultSlidesHeight;
+};
+
+// Contains screen share video stream properties.
+struct ScreenShareConfig {
+ explicit ScreenShareConfig(TimeDelta slide_change_interval);
+
+ // Shows how long one slide should be presented on the screen during
+ // slide generation.
+ TimeDelta slide_change_interval;
+ // If true, slides will be generated programmatically. No scrolling params
+ // will be applied in such case.
+ bool generate_slides = false;
+ // If present scrolling will be applied. Please read extra requirement on
+ // `slides_yuv_file_names` for scrolling.
+ absl::optional<ScrollingParams> scrolling_params;
+ // Contains list of yuv files with slides.
+ //
+ // If empty, default set of slides will be used. In such case
+ // `VideoConfig::width` must be equal to `kDefaultSlidesWidth` and
+ // `VideoConfig::height` must be equal to `kDefaultSlidesHeight` or if
+ // `scrolling_params` are specified, then `ScrollingParams::source_width`
+ // must be equal to `kDefaultSlidesWidth` and
+ // `ScrollingParams::source_height` must be equal to `kDefaultSlidesHeight`.
+ std::vector<std::string> slides_yuv_file_names;
+};
+
+// Config for Vp8 simulcast or non-standard Vp9 SVC testing.
+//
+// To configure standard SVC setting, use `scalability_mode` in the
+// `encoding_params` array.
+// This configures Vp9 SVC by requesting simulcast layers, the request is
+// internally converted to a request for SVC layers.
+//
+// SVC support is limited:
+// During SVC testing there is no SFU, so framework will try to emulate SFU
+// behavior in regular p2p call. Because of it there are such limitations:
+// * if `target_spatial_index` is not equal to the highest spatial layer
+// then no packet/frame drops are allowed.
+//
+// If there will be any drops, that will affect requested layer, then
+// WebRTC SVC implementation will continue decoding only the highest
+// available layer and won't restore lower layers, so analyzer won't
+// receive required data which will cause wrong results or test failures.
+struct VideoSimulcastConfig {
+ explicit VideoSimulcastConfig(int simulcast_streams_count);
+
+ // Specified amount of simulcast streams/SVC layers, depending on which
+ // encoder is used.
+ int simulcast_streams_count;
+};
+
+// Configuration for the emulated Selective Forward Unit (SFU)
+//
+// The framework can optionally filter out frames that are decoded
+// using an emulated SFU.
+// When using simulcast or SVC, it's not always desirable to receive
+// all frames. In a real world call, a SFU will only forward a subset
+// of the frames.
+// The emulated SFU is not able to change its configuration dynamically,
+// if adaptation happens during the call, layers may be dropped and the
+// analyzer won't receive the required data which will cause wrong results or
+// test failures.
+struct EmulatedSFUConfig {
+ EmulatedSFUConfig() = default;
+ explicit EmulatedSFUConfig(int target_layer_index);
+ EmulatedSFUConfig(absl::optional<int> target_layer_index,
+ absl::optional<int> target_temporal_index);
+
+ // Specifies simulcast or spatial index of the video stream to analyze.
+ // There are 2 cases:
+ // 1. simulcast encoding is used:
+ // in such case `target_layer_index` will specify the index of
+ // simulcast stream, that should be analyzed. Other streams will be
+ // dropped.
+ // 2. SVC encoding is used:
+ // in such case `target_layer_index` will specify the top interesting
+ // spatial layer and all layers below, including target one will be
+ // processed. All layers above target one will be dropped.
+ // If not specified then all streams will be received and analyzed.
+ // When set, it instructs the framework to create an emulated Selective
+ // Forwarding Unit (SFU) that will propagate only the requested layers.
+ absl::optional<int> target_layer_index;
+ // Specifies the index of the maximum temporal unit to keep.
+ // If not specified then all temporal layers will be received and analyzed.
+ // When set, it instructs the framework to create an emulated Selective
+ // Forwarding Unit (SFU) that will propagate only up to the requested layer.
+ absl::optional<int> target_temporal_index;
+};
+
+class VideoResolution {
+ public:
+ // Determines special resolutions, which can't be expressed in terms of
+ // width, height and fps.
+ enum class Spec {
+ // No extra spec set. It describes a regular resolution described by
+ // width, height and fps.
+ kNone,
+ // Describes resolution which contains max value among all sender's
+ // video streams in each dimension (width, height, fps).
+ kMaxFromSender
+ };
+
+ VideoResolution(size_t width, size_t height, int32_t fps);
+ explicit VideoResolution(Spec spec = Spec::kNone);
+
+ bool operator==(const VideoResolution& other) const;
+ bool operator!=(const VideoResolution& other) const;
+
+ size_t width() const { return width_; }
+ void set_width(size_t width) { width_ = width; }
+ size_t height() const { return height_; }
+ void set_height(size_t height) { height_ = height; }
+ int32_t fps() const { return fps_; }
+ void set_fps(int32_t fps) { fps_ = fps; }
+
+ // Returns if it is a regular resolution or not. The resolution is regular
+ // if it's spec is `Spec::kNone`.
+ bool IsRegular() const;
+
+ std::string ToString() const;
+
+ private:
+ size_t width_ = 0;
+ size_t height_ = 0;
+ int32_t fps_ = 0;
+ Spec spec_ = Spec::kNone;
+};
+
+class VideoDumpOptions {
+ public:
+ static constexpr int kDefaultSamplingModulo = 1;
+
+ // output_directory - the output directory where stream will be dumped. The
+ // output files' names will be constructed as
+ // <stream_name>_<receiver_name>_<resolution>.<extension> for output dumps
+ // and <stream_name>_<resolution>.<extension> for input dumps.
+ // By default <extension> is "y4m". Resolution is in the format
+ // <width>x<height>_<fps>.
+ // sampling_modulo - the module for the video frames to be dumped. Modulo
+ // equals X means every Xth frame will be written to the dump file. The
+ // value must be greater than 0. (Default: 1)
+ // export_frame_ids - specifies if frame ids should be exported together
+ // with content of the stream. If true, an output file with the same name as
+ // video dump and suffix ".frame_ids.txt" will be created. It will contain
+ // the frame ids in the same order as original frames in the output
+ // file with stream content. File will contain one frame id per line.
+ // (Default: false)
+ // `video_frame_writer_factory` - factory function to create a video frame
+ // writer for input and output video files. (Default: Y4M video writer
+ // factory).
+ explicit VideoDumpOptions(
+ absl::string_view output_directory,
+ int sampling_modulo = kDefaultSamplingModulo,
+ bool export_frame_ids = false,
+ std::function<std::unique_ptr<test::VideoFrameWriter>(
+ absl::string_view file_name_prefix,
+ const VideoResolution& resolution)> video_frame_writer_factory =
+ Y4mVideoFrameWriterFactory);
+ VideoDumpOptions(absl::string_view output_directory, bool export_frame_ids);
+
+ VideoDumpOptions(const VideoDumpOptions&) = default;
+ VideoDumpOptions& operator=(const VideoDumpOptions&) = default;
+ VideoDumpOptions(VideoDumpOptions&&) = default;
+ VideoDumpOptions& operator=(VideoDumpOptions&&) = default;
+
+ std::string output_directory() const { return output_directory_; }
+ int sampling_modulo() const { return sampling_modulo_; }
+ bool export_frame_ids() const { return export_frame_ids_; }
+
+ std::unique_ptr<test::VideoFrameWriter> CreateInputDumpVideoFrameWriter(
+ absl::string_view stream_label,
+ const VideoResolution& resolution) const;
+
+ std::unique_ptr<test::VideoFrameWriter> CreateOutputDumpVideoFrameWriter(
+ absl::string_view stream_label,
+ absl::string_view receiver,
+ const VideoResolution& resolution) const;
+
+ std::string ToString() const;
+
+ private:
+ static std::unique_ptr<test::VideoFrameWriter> Y4mVideoFrameWriterFactory(
+ absl::string_view file_name_prefix,
+ const VideoResolution& resolution);
+ std::string GetInputDumpFileName(absl::string_view stream_label,
+ const VideoResolution& resolution) const;
+ // Returns file name for input frame ids dump if `export_frame_ids()` is
+ // true, absl::nullopt otherwise.
+ absl::optional<std::string> GetInputFrameIdsDumpFileName(
+ absl::string_view stream_label,
+ const VideoResolution& resolution) const;
+ std::string GetOutputDumpFileName(absl::string_view stream_label,
+ absl::string_view receiver,
+ const VideoResolution& resolution) const;
+ // Returns file name for output frame ids dump if `export_frame_ids()` is
+ // true, absl::nullopt otherwise.
+ absl::optional<std::string> GetOutputFrameIdsDumpFileName(
+ absl::string_view stream_label,
+ absl::string_view receiver,
+ const VideoResolution& resolution) const;
+
+ std::string output_directory_;
+ int sampling_modulo_ = 1;
+ bool export_frame_ids_ = false;
+ std::function<std::unique_ptr<test::VideoFrameWriter>(
+ absl::string_view file_name_prefix,
+ const VideoResolution& resolution)>
+ video_frame_writer_factory_;
+};
+
+// Contains properties of single video stream.
+struct VideoConfig {
+ explicit VideoConfig(const VideoResolution& resolution);
+ VideoConfig(size_t width, size_t height, int32_t fps);
+ VideoConfig(std::string stream_label,
+ size_t width,
+ size_t height,
+ int32_t fps);
+
+ // Video stream width.
+ size_t width;
+ // Video stream height.
+ size_t height;
+ int32_t fps;
+ VideoResolution GetResolution() const {
+ return VideoResolution(width, height, fps);
+ }
+
+ // Have to be unique among all specified configs for all peers in the call.
+ // Will be auto generated if omitted.
+ absl::optional<std::string> stream_label;
+ // Will be set for current video track. If equals to kText or kDetailed -
+ // screencast in on.
+ absl::optional<VideoTrackInterface::ContentHint> content_hint;
+ // If presented video will be transfered in simulcast/SVC mode depending on
+ // which encoder is used.
+ //
+ // Simulcast is supported only from 1st added peer. For VP8 simulcast only
+ // without RTX is supported so it will be automatically disabled for all
+ // simulcast tracks. For VP9 simulcast enables VP9 SVC mode and support RTX,
+ // but only on non-lossy networks. See more in documentation to
+ // VideoSimulcastConfig.
+ absl::optional<VideoSimulcastConfig> simulcast_config;
+ // Configuration for the emulated Selective Forward Unit (SFU).
+ absl::optional<EmulatedSFUConfig> emulated_sfu_config;
+ // Encoding parameters for both singlecast and per simulcast layer.
+ // If singlecast is used, if not empty, a single value can be provided.
+ // If simulcast is used, if not empty, `encoding_params` size have to be
+ // equal to `simulcast_config.simulcast_streams_count`. Will be used to set
+ // transceiver send encoding params for each layer.
+ // RtpEncodingParameters::rid may be changed by fixture implementation to
+ // ensure signaling correctness.
+ std::vector<RtpEncodingParameters> encoding_params;
+ // Count of temporal layers for video stream. This value will be set into
+ // each RtpEncodingParameters of RtpParameters of corresponding
+ // RtpSenderInterface for this video stream.
+ absl::optional<int> temporal_layers_count;
+ // If specified defines how input should be dumped. It is actually one of
+ // the test's output file, which contains copy of what was captured during
+ // the test for this video stream on sender side. It is useful when
+ // generator is used as input.
+ absl::optional<VideoDumpOptions> input_dump_options;
+ // If specified defines how output should be dumped on the receiver side for
+ // this stream. The produced files contain what was rendered for this video
+ // stream on receiver side per each receiver.
+ absl::optional<VideoDumpOptions> output_dump_options;
+ // If set to true uses fixed frame rate while dumping output video to the
+ // file. Requested `VideoSubscription::fps()` will be used as frame rate.
+ bool output_dump_use_fixed_framerate = false;
+ // If true will display input and output video on the user's screen.
+ bool show_on_screen = false;
+ // If specified, determines a sync group to which this video stream belongs.
+ // According to bugs.webrtc.org/4762 WebRTC supports synchronization only
+ // for pair of single audio and single video stream.
+ absl::optional<std::string> sync_group;
+ // If specified, it will be set into RtpParameters of corresponding
+ // RtpSenderInterface for this video stream.
+ // Note that this setting takes precedence over `content_hint`.
+ absl::optional<DegradationPreference> degradation_preference;
+};
+
+// Contains properties for audio in the call.
+struct AudioConfig {
+ enum Mode {
+ kGenerated,
+ kFile,
+ };
+
+ AudioConfig() = default;
+ explicit AudioConfig(std::string stream_label);
+
+ // Have to be unique among all specified configs for all peers in the call.
+ // Will be auto generated if omitted.
+ absl::optional<std::string> stream_label;
+ Mode mode = kGenerated;
+ // Have to be specified only if mode = kFile
+ absl::optional<std::string> input_file_name;
+ // If specified the input stream will be also copied to specified file.
+ absl::optional<std::string> input_dump_file_name;
+ // If specified the output stream will be copied to specified file.
+ absl::optional<std::string> output_dump_file_name;
+
+ // Audio options to use.
+ cricket::AudioOptions audio_options;
+ // Sampling frequency of input audio data (from file or generated).
+ int sampling_frequency_in_hz = 48000;
+ // If specified, determines a sync group to which this audio stream belongs.
+ // According to bugs.webrtc.org/4762 WebRTC supports synchronization only
+ // for pair of single audio and single video stream.
+ absl::optional<std::string> sync_group;
+};
+
+struct VideoCodecConfig {
+ explicit VideoCodecConfig(std::string name);
+ VideoCodecConfig(std::string name,
+ std::map<std::string, std::string> required_params);
+ // Next two fields are used to specify concrete video codec, that should be
+ // used in the test. Video code will be negotiated in SDP during offer/
+ // answer exchange.
+ // Video codec name. You can find valid names in
+ // media/base/media_constants.h
+ std::string name;
+ // Map of parameters, that have to be specified on SDP codec. Each parameter
+ // is described by key and value. Codec parameters will match the specified
+ // map if and only if for each key from `required_params` there will be
+ // a parameter with name equal to this key and parameter value will be equal
+ // to the value from `required_params` for this key.
+ // If empty then only name will be used to match the codec.
+ std::map<std::string, std::string> required_params;
+};
+
+// Subscription to the remote video streams. It declares which remote stream
+// peer should receive and in which resolution (width x height x fps).
+class VideoSubscription {
+ public:
+ // Returns the resolution constructed as maximum from all resolution
+ // dimensions: width, height and fps.
+ static absl::optional<VideoResolution> GetMaxResolution(
+ rtc::ArrayView<const VideoConfig> video_configs);
+ static absl::optional<VideoResolution> GetMaxResolution(
+ rtc::ArrayView<const VideoResolution> resolutions);
+
+ bool operator==(const VideoSubscription& other) const;
+ bool operator!=(const VideoSubscription& other) const;
+
+ // Subscribes receiver to all streams sent by the specified peer with
+ // specified resolution. It will override any resolution that was used in
+ // `SubscribeToAll` independently from methods call order.
+ VideoSubscription& SubscribeToPeer(
+ absl::string_view peer_name,
+ VideoResolution resolution =
+ VideoResolution(VideoResolution::Spec::kMaxFromSender));
+
+ // Subscribes receiver to the all sent streams with specified resolution.
+ // If any stream was subscribed to with `SubscribeTo` method that will
+ // override resolution passed to this function independently from methods
+ // call order.
+ VideoSubscription& SubscribeToAllPeers(
+ VideoResolution resolution =
+ VideoResolution(VideoResolution::Spec::kMaxFromSender));
+
+ // Returns resolution for specific sender. If no specific resolution was
+ // set for this sender, then will return resolution used for all streams.
+ // If subscription doesn't subscribe to all streams, `absl::nullopt` will be
+ // returned.
+ absl::optional<VideoResolution> GetResolutionForPeer(
+ absl::string_view peer_name) const;
+
+ // Returns a maybe empty list of senders for which peer explicitly
+ // subscribed to with specific resolution.
+ std::vector<std::string> GetSubscribedPeers() const;
+
+ std::string ToString() const;
+
+ private:
+ absl::optional<VideoResolution> default_resolution_ = absl::nullopt;
+ std::map<std::string, VideoResolution> peers_resolution_;
+};
+
+// Contains configuration for echo emulator.
+struct EchoEmulationConfig {
+ // Delay which represents the echo path delay, i.e. how soon rendered signal
+ // should reach capturer.
+ TimeDelta echo_delay = TimeDelta::Millis(50);
+};
+
+} // namespace webrtc_pc_e2e
+} // namespace webrtc
+
+#endif // API_TEST_PCLF_MEDIA_CONFIGURATION_H_
diff --git a/third_party/libwebrtc/api/test/pclf/media_quality_test_params.h b/third_party/libwebrtc/api/test/pclf/media_quality_test_params.h
new file mode 100644
index 0000000000..3377d31f68
--- /dev/null
+++ b/third_party/libwebrtc/api/test/pclf/media_quality_test_params.h
@@ -0,0 +1,189 @@
+/*
+ * 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/pclf/media_configuration.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<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<VideoCodecConfig> video_codecs;
+
+ // A list of RTP header extensions which will be enforced on all video streams
+ // added to this peer.
+ std::vector<std::string> extra_video_rtp_header_extensions;
+ // A list of RTP header extensions which will be enforced on all audio streams
+ // added to this peer.
+ std::vector<std::string> extra_audio_rtp_header_extensions;
+};
+
+// 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<VideoConfig> video_configs;
+
+ VideoSubscription video_subscription =
+ VideoSubscription().SubscribeToAllPeers();
+};
+
+// Contains parameters, that describe how long framework should run quality
+// test.
+struct RunParams {
+ explicit RunParams(TimeDelta run_duration) : run_duration(run_duration) {}
+
+ // Specifies how long the test should be run. This time shows how long
+ // the media should flow after connection was established and before
+ // it will be shut downed.
+ TimeDelta run_duration;
+
+ // If set to true peers will be able to use Flex FEC, otherwise they won't
+ // be able to negotiate it even if it's enabled on per peer level.
+ bool enable_flex_fec_support = false;
+ // If true will set conference mode in SDP media section for all video
+ // tracks for all peers.
+ bool use_conference_mode = false;
+ // If specified echo emulation will be done, by mixing the render audio into
+ // the capture signal. In such case input signal will be reduced by half to
+ // avoid saturation or compression in the echo path simulation.
+ absl::optional<EchoEmulationConfig> echo_emulation_config;
+};
+
+} // namespace webrtc_pc_e2e
+} // namespace webrtc
+
+#endif // API_TEST_PCLF_MEDIA_QUALITY_TEST_PARAMS_H_
diff --git a/third_party/libwebrtc/api/test/pclf/peer_configurer.cc b/third_party/libwebrtc/api/test/pclf/peer_configurer.cc
new file mode 100644
index 0000000000..2203a4c4f0
--- /dev/null
+++ b/third_party/libwebrtc/api/test/pclf/peer_configurer.cc
@@ -0,0 +1,245 @@
+/*
+ * 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/pclf/media_configuration.h"
+#include "api/test/pclf/media_quality_test_params.h"
+#include "api/test/peer_network_dependencies.h"
+
+namespace webrtc {
+namespace webrtc_pc_e2e {
+
+PeerConfigurer::PeerConfigurer(
+ 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* PeerConfigurer::SetName(absl::string_view name) {
+ params_->name = std::string(name);
+ return this;
+}
+
+PeerConfigurer* PeerConfigurer::SetTaskQueueFactory(
+ std::unique_ptr<TaskQueueFactory> task_queue_factory) {
+ components_->pcf_dependencies->task_queue_factory =
+ std::move(task_queue_factory);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetCallFactory(
+ std::unique_ptr<CallFactoryInterface> call_factory) {
+ components_->pcf_dependencies->call_factory = std::move(call_factory);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetEventLogFactory(
+ std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) {
+ components_->pcf_dependencies->event_log_factory =
+ std::move(event_log_factory);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetFecControllerFactory(
+ std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory) {
+ components_->pcf_dependencies->fec_controller_factory =
+ std::move(fec_controller_factory);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetNetworkControllerFactory(
+ std::unique_ptr<NetworkControllerFactoryInterface>
+ network_controller_factory) {
+ components_->pcf_dependencies->network_controller_factory =
+ std::move(network_controller_factory);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetVideoEncoderFactory(
+ std::unique_ptr<VideoEncoderFactory> video_encoder_factory) {
+ components_->pcf_dependencies->video_encoder_factory =
+ std::move(video_encoder_factory);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetVideoDecoderFactory(
+ std::unique_ptr<VideoDecoderFactory> video_decoder_factory) {
+ components_->pcf_dependencies->video_decoder_factory =
+ std::move(video_decoder_factory);
+ return this;
+}
+
+PeerConfigurer* PeerConfigurer::SetAsyncResolverFactory(
+ std::unique_ptr<webrtc::AsyncResolverFactory> async_resolver_factory) {
+ components_->pc_dependencies->async_resolver_factory =
+ std::move(async_resolver_factory);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetRTCCertificateGenerator(
+ std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
+ components_->pc_dependencies->cert_generator = std::move(cert_generator);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetSSLCertificateVerifier(
+ std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier) {
+ components_->pc_dependencies->tls_cert_verifier =
+ std::move(tls_cert_verifier);
+ return this;
+}
+
+PeerConfigurer* PeerConfigurer::AddVideoConfig(VideoConfig config) {
+ video_sources_.push_back(
+ CreateSquareFrameGenerator(config, /*type=*/absl::nullopt));
+ configurable_params_->video_configs.push_back(std::move(config));
+ return this;
+}
+PeerConfigurer* PeerConfigurer::AddVideoConfig(
+ 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* PeerConfigurer::AddVideoConfig(VideoConfig config,
+ CapturingDeviceIndex index) {
+ configurable_params_->video_configs.push_back(std::move(config));
+ video_sources_.push_back(index);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetVideoSubscription(
+ VideoSubscription subscription) {
+ configurable_params_->video_subscription = std::move(subscription);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetVideoCodecs(
+ std::vector<VideoCodecConfig> video_codecs) {
+ params_->video_codecs = std::move(video_codecs);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetExtraVideoRtpHeaderExtensions(
+ std::vector<std::string> extensions) {
+ params_->extra_video_rtp_header_extensions = std::move(extensions);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetAudioConfig(AudioConfig config) {
+ params_->audio_config = std::move(config);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetExtraAudioRtpHeaderExtensions(
+ std::vector<std::string> extensions) {
+ params_->extra_audio_rtp_header_extensions = std::move(extensions);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetUseUlpFEC(bool value) {
+ params_->use_ulp_fec = value;
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetUseFlexFEC(bool value) {
+ params_->use_flex_fec = value;
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetVideoEncoderBitrateMultiplier(
+ double multiplier) {
+ params_->video_encoder_bitrate_multiplier = multiplier;
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetNetEqFactory(
+ std::unique_ptr<NetEqFactory> neteq_factory) {
+ components_->pcf_dependencies->neteq_factory = std::move(neteq_factory);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetAudioProcessing(
+ rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing) {
+ components_->pcf_dependencies->audio_processing = audio_processing;
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetAudioMixer(
+ rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer) {
+ components_->pcf_dependencies->audio_mixer = audio_mixer;
+ return this;
+}
+
+PeerConfigurer* PeerConfigurer::SetUseNetworkThreadAsWorkerThread() {
+ components_->worker_thread = components_->network_thread;
+ return this;
+}
+
+PeerConfigurer* PeerConfigurer::SetRtcEventLogPath(std::string path) {
+ params_->rtc_event_log_path = std::move(path);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetAecDumpPath(std::string path) {
+ params_->aec_dump_path = std::move(path);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetRTCConfiguration(
+ PeerConnectionInterface::RTCConfiguration configuration) {
+ params_->rtc_configuration = std::move(configuration);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetRTCOfferAnswerOptions(
+ PeerConnectionInterface::RTCOfferAnswerOptions options) {
+ params_->rtc_offer_answer_options = std::move(options);
+ return this;
+}
+PeerConfigurer* PeerConfigurer::SetBitrateSettings(
+ BitrateSettings bitrate_settings) {
+ params_->bitrate_settings = bitrate_settings;
+ return this;
+}
+
+PeerConfigurer* PeerConfigurer::SetIceTransportFactory(
+ std::unique_ptr<IceTransportFactory> factory) {
+ components_->pc_dependencies->ice_transport_factory = std::move(factory);
+ return this;
+}
+
+PeerConfigurer* PeerConfigurer::SetPortAllocatorExtraFlags(
+ uint32_t extra_flags) {
+ params_->port_allocator_extra_flags = extra_flags;
+ return this;
+}
+std::unique_ptr<InjectableComponents> PeerConfigurer::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> PeerConfigurer::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>
+PeerConfigurer::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<PeerConfigurer::VideoSource> PeerConfigurer::ReleaseVideoSources() {
+ auto video_sources = std::move(video_sources_);
+ video_sources_.clear();
+ return video_sources;
+}
+
+} // namespace webrtc_pc_e2e
+} // namespace webrtc
diff --git a/third_party/libwebrtc/api/test/pclf/peer_configurer.h b/third_party/libwebrtc/api/test/pclf/peer_configurer.h
new file mode 100644
index 0000000000..996dc5cd89
--- /dev/null
+++ b/third_party/libwebrtc/api/test/pclf/peer_configurer.h
@@ -0,0 +1,200 @@
+/*
+ * 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 <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_configuration.h"
+#include "api/test/pclf/media_quality_test_params.h"
+#include "api/test/peer_network_dependencies.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 PeerConfigurer {
+ public:
+ using VideoSource =
+ absl::variant<std::unique_ptr<test::FrameGeneratorInterface>,
+ CapturingDeviceIndex>;
+
+ explicit PeerConfigurer(const PeerNetworkDependencies& network_dependencies);
+
+ // 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);
+
+ // 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);
+ PeerConfigurer* SetCallFactory(
+ std::unique_ptr<CallFactoryInterface> call_factory);
+ PeerConfigurer* SetEventLogFactory(
+ std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory);
+ PeerConfigurer* SetFecControllerFactory(
+ std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory);
+ PeerConfigurer* SetNetworkControllerFactory(
+ std::unique_ptr<NetworkControllerFactoryInterface>
+ network_controller_factory);
+ PeerConfigurer* SetVideoEncoderFactory(
+ std::unique_ptr<VideoEncoderFactory> video_encoder_factory);
+ PeerConfigurer* SetVideoDecoderFactory(
+ std::unique_ptr<VideoDecoderFactory> video_decoder_factory);
+ // Set a custom NetEqFactory to be used in the call.
+ PeerConfigurer* SetNetEqFactory(std::unique_ptr<NetEqFactory> neteq_factory);
+ PeerConfigurer* SetAudioProcessing(
+ rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing);
+ PeerConfigurer* SetAudioMixer(
+ rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer);
+
+ // 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();
+
+ // 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);
+ PeerConfigurer* SetRTCCertificateGenerator(
+ std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator);
+ PeerConfigurer* SetSSLCertificateVerifier(
+ std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier);
+ PeerConfigurer* SetIceTransportFactory(
+ std::unique_ptr<IceTransportFactory> factory);
+ // 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);
+
+ // 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(VideoConfig config);
+ // Add new video stream to the call that will be sent from this peer with
+ // provided own implementation of video frames generator.
+ PeerConfigurer* AddVideoConfig(
+ VideoConfig config,
+ std::unique_ptr<test::FrameGeneratorInterface> generator);
+ // 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(VideoConfig config,
+ CapturingDeviceIndex capturing_device_index);
+ // Sets video subscription for the peer. By default subscription will
+ // include all streams with `VideoSubscription::kSameAsSendStream`
+ // resolution. To this behavior use this method.
+ PeerConfigurer* SetVideoSubscription(VideoSubscription subscription);
+ // Sets 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<VideoCodecConfig> video_codecs);
+ // Sets a list of RTP header extensions which will be enforced on all video
+ // streams added to this peer.
+ PeerConfigurer* SetExtraVideoRtpHeaderExtensions(
+ std::vector<std::string> extensions);
+ // Sets the audio stream for the call from this peer. If this method won't
+ // be invoked, this peer will send no audio.
+ PeerConfigurer* SetAudioConfig(AudioConfig config);
+ // Sets a list of RTP header extensions which will be enforced on all audio
+ // streams added to this peer.
+ PeerConfigurer* SetExtraAudioRtpHeaderExtensions(
+ std::vector<std::string> extensions);
+
+ // Set if ULP FEC should be used or not. False by default.
+ PeerConfigurer* SetUseUlpFEC(bool value);
+ // 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);
+ // 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);
+
+ // If is set, an RTCEventLog will be saved in that location and it will be
+ // available for further analysis.
+ PeerConfigurer* SetRtcEventLogPath(std::string path);
+ // 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);
+ PeerConfigurer* SetRTCConfiguration(
+ PeerConnectionInterface::RTCConfiguration configuration);
+ PeerConfigurer* SetRTCOfferAnswerOptions(
+ PeerConnectionInterface::RTCOfferAnswerOptions options);
+ // Set bitrate parameters on PeerConnection. This constraints will be
+ // applied to all summed RTP streams for this peer.
+ PeerConfigurer* SetBitrateSettings(BitrateSettings bitrate_settings);
+
+ // 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_;
+};
+
+} // namespace webrtc_pc_e2e
+} // namespace webrtc
+
+#endif // API_TEST_PCLF_PEER_CONFIGURER_H_