blob: 5d15ba327ef63854a072a2c922993d20344f666e [file] [log] [blame]
Artem Titov0d510522022-04-19 13:01:03 +02001/*
2 * Copyright 2022 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "api/test/peerconnection_quality_test_fixture.h"
12
Artem Titovbccb4522022-06-01 22:32:15 +020013#include <string>
14
Artem Titov0d510522022-04-19 13:01:03 +020015#include "absl/types/optional.h"
16#include "api/array_view.h"
Artem Titov7017a132022-04-20 20:57:56 +020017#include "rtc_base/checks.h"
Artem Titovbccb4522022-06-01 22:32:15 +020018#include "rtc_base/strings/string_builder.h"
Artem Titov72bc2e22022-08-02 14:03:03 +020019#include "test/testsupport/file_utils.h"
Artem Titov0d510522022-04-19 13:01:03 +020020
21namespace webrtc {
22namespace webrtc_pc_e2e {
Artem Titovbccb4522022-06-01 22:32:15 +020023namespace {
Artem Titov0d510522022-04-19 13:01:03 +020024
25using VideoCodecConfig = ::webrtc::webrtc_pc_e2e::
26 PeerConnectionE2EQualityTestFixture::VideoCodecConfig;
27using VideoSubscription = ::webrtc::webrtc_pc_e2e::
28 PeerConnectionE2EQualityTestFixture::VideoSubscription;
29
Artem Titovbccb4522022-06-01 22:32:15 +020030std::string SpecToString(
31 PeerConnectionE2EQualityTestFixture::VideoResolution::VideoResolution::Spec
32 spec) {
33 switch (spec) {
34 case PeerConnectionE2EQualityTestFixture::VideoResolution::Spec::kNone:
35 return "None";
36 case PeerConnectionE2EQualityTestFixture::VideoResolution::Spec::
37 kMaxFromSender:
38 return "MaxFromSender";
39 }
40}
41
42} // namespace
43
Artem Titov7017a132022-04-20 20:57:56 +020044PeerConnectionE2EQualityTestFixture::VideoResolution::VideoResolution(
Artem Titov0d510522022-04-19 13:01:03 +020045 size_t width,
46 size_t height,
47 int32_t fps)
48 : width_(width), height_(height), fps_(fps), spec_(Spec::kNone) {}
Artem Titov7017a132022-04-20 20:57:56 +020049PeerConnectionE2EQualityTestFixture::VideoResolution::VideoResolution(Spec spec)
Artem Titov0d510522022-04-19 13:01:03 +020050 : width_(0), height_(0), fps_(0), spec_(spec) {}
51
Artem Titov7017a132022-04-20 20:57:56 +020052bool PeerConnectionE2EQualityTestFixture::VideoResolution::operator==(
53 const VideoResolution& other) const {
Artem Titov0d510522022-04-19 13:01:03 +020054 if (spec_ != Spec::kNone && spec_ == other.spec_) {
55 // If there is some particular spec set, then it doesn't matter what
56 // values we have in other fields.
57 return true;
58 }
59 return width_ == other.width_ && height_ == other.height_ &&
60 fps_ == other.fps_ && spec_ == other.spec_;
61}
62
Artem Titovbccb4522022-06-01 22:32:15 +020063std::string PeerConnectionE2EQualityTestFixture::VideoResolution::ToString()
64 const {
65 rtc::StringBuilder out;
66 out << "{ width=" << width_ << ", height=" << height_ << ", fps=" << fps_
67 << ", spec=" << SpecToString(spec_) << " }";
68 return out.Release();
69}
70
Artem Titovfd8ed052022-06-01 14:11:14 +020071bool PeerConnectionE2EQualityTestFixture::VideoSubscription::operator==(
72 const VideoSubscription& other) const {
73 return default_resolution_ == other.default_resolution_ &&
74 peers_resolution_ == other.peers_resolution_;
75}
76
Artem Titov7017a132022-04-20 20:57:56 +020077absl::optional<PeerConnectionE2EQualityTestFixture::VideoResolution>
Artem Titov0d510522022-04-19 13:01:03 +020078PeerConnectionE2EQualityTestFixture::VideoSubscription::GetMaxResolution(
79 rtc::ArrayView<const VideoConfig> video_configs) {
Artem Titov7017a132022-04-20 20:57:56 +020080 std::vector<VideoResolution> resolutions;
Artem Titov83962d92022-04-20 19:26:08 +020081 for (const auto& video_config : video_configs) {
Artem Titov7017a132022-04-20 20:57:56 +020082 resolutions.push_back(video_config.GetResolution());
Artem Titov83962d92022-04-20 19:26:08 +020083 }
84 return GetMaxResolution(resolutions);
85}
86
Artem Titov7017a132022-04-20 20:57:56 +020087absl::optional<PeerConnectionE2EQualityTestFixture::VideoResolution>
Artem Titov83962d92022-04-20 19:26:08 +020088PeerConnectionE2EQualityTestFixture::VideoSubscription::GetMaxResolution(
Artem Titov7017a132022-04-20 20:57:56 +020089 rtc::ArrayView<const VideoResolution> resolutions) {
Artem Titov83962d92022-04-20 19:26:08 +020090 if (resolutions.empty()) {
Artem Titov0d510522022-04-19 13:01:03 +020091 return absl::nullopt;
92 }
93
Artem Titov7017a132022-04-20 20:57:56 +020094 VideoResolution max_resolution;
95 for (const VideoResolution& resolution : resolutions) {
Artem Titov83962d92022-04-20 19:26:08 +020096 if (max_resolution.width() < resolution.width()) {
97 max_resolution.set_width(resolution.width());
Artem Titov0d510522022-04-19 13:01:03 +020098 }
Artem Titov83962d92022-04-20 19:26:08 +020099 if (max_resolution.height() < resolution.height()) {
100 max_resolution.set_height(resolution.height());
Artem Titov0d510522022-04-19 13:01:03 +0200101 }
Artem Titov83962d92022-04-20 19:26:08 +0200102 if (max_resolution.fps() < resolution.fps()) {
103 max_resolution.set_fps(resolution.fps());
Artem Titov0d510522022-04-19 13:01:03 +0200104 }
105 }
106 return max_resolution;
107}
108
Artem Titov7c321922022-06-02 10:38:24 +0200109std::string PeerConnectionE2EQualityTestFixture::VideoSubscription::ToString()
110 const {
111 rtc::StringBuilder out;
112 out << "{ default_resolution_=[";
113 if (default_resolution_.has_value()) {
114 out << default_resolution_->ToString();
115 } else {
116 out << "undefined";
117 }
118 out << "], {";
119 for (const auto& [peer_name, resolution] : peers_resolution_) {
120 out << "[" << peer_name << ": " << resolution.ToString() << "], ";
121 }
122 out << "} }";
123 return out.Release();
124}
125
Artem Titov72bc2e22022-08-02 14:03:03 +0200126PeerConnectionE2EQualityTestFixture::VideoDumpOptions::VideoDumpOptions(
127 absl::string_view output_directory,
Artem Titovd2209252022-08-03 13:22:48 +0200128 int sampling_modulo,
129 bool export_frame_ids)
130 : output_directory_(output_directory),
131 sampling_modulo_(sampling_modulo),
132 export_frame_ids_(export_frame_ids) {
Artem Titov72bc2e22022-08-02 14:03:03 +0200133 RTC_CHECK_GT(sampling_modulo, 0);
134}
Artem Titovd2209252022-08-03 13:22:48 +0200135PeerConnectionE2EQualityTestFixture::VideoDumpOptions::VideoDumpOptions(
136 absl::string_view output_directory,
137 bool export_frame_ids)
138 : VideoDumpOptions(output_directory,
139 kDefaultSamplingModulo,
140 export_frame_ids) {}
Artem Titov72bc2e22022-08-02 14:03:03 +0200141
142std::string
143PeerConnectionE2EQualityTestFixture::VideoDumpOptions::GetInputDumpFileName(
144 absl::string_view stream_label) const {
145 rtc::StringBuilder file_name;
146 file_name << stream_label << ".y4m";
147 return test::JoinFilename(output_directory_, file_name.Release());
148}
149
Artem Titovd2209252022-08-03 13:22:48 +0200150absl::optional<std::string> PeerConnectionE2EQualityTestFixture::
151 VideoDumpOptions::GetInputFrameIdsDumpFileName(
152 absl::string_view stream_label) const {
153 if (!export_frame_ids_) {
154 return absl::nullopt;
155 }
156 return GetInputDumpFileName(stream_label) + ".frame_ids.txt";
157}
158
Artem Titov72bc2e22022-08-02 14:03:03 +0200159std::string
160PeerConnectionE2EQualityTestFixture::VideoDumpOptions::GetOutputDumpFileName(
161 absl::string_view stream_label,
162 absl::string_view receiver) const {
163 rtc::StringBuilder file_name;
164 file_name << stream_label << "_" << receiver << ".y4m";
165 return test::JoinFilename(output_directory_, file_name.Release());
166}
167
Artem Titovd2209252022-08-03 13:22:48 +0200168absl::optional<std::string> PeerConnectionE2EQualityTestFixture::
169 VideoDumpOptions::GetOutputFrameIdsDumpFileName(
170 absl::string_view stream_label,
171 absl::string_view receiver) const {
172 if (!export_frame_ids_) {
173 return absl::nullopt;
174 }
175 return GetOutputDumpFileName(stream_label, receiver) + ".frame_ids.txt";
176}
177
Artem Titov7017a132022-04-20 20:57:56 +0200178PeerConnectionE2EQualityTestFixture::VideoConfig::VideoConfig(
179 const VideoResolution& resolution)
180 : width(resolution.width()),
181 height(resolution.height()),
182 fps(resolution.fps()) {
183 RTC_CHECK(resolution.IsRegular());
184}
185
Artem Titov0d510522022-04-19 13:01:03 +0200186} // namespace webrtc_pc_e2e
187} // namespace webrtc